1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have
  23  * questions.
  24  */
  25 package jdk.incubator.vector;
  26 
  27 import java.nio.ByteBuffer;
  28 import java.nio.ByteOrder;
  29 import java.nio.ShortBuffer;
  30 import java.nio.ReadOnlyBufferException;
  31 import java.util.Arrays;
  32 import java.util.Objects;
  33 import java.util.function.IntUnaryOperator;
  34 
  35 import jdk.internal.misc.Unsafe;
  36 import jdk.internal.vm.annotation.ForceInline;
  37 import static jdk.incubator.vector.VectorIntrinsics.*;
  38 
  39 @SuppressWarnings("cast")
  40 final class ShortMaxVector extends ShortVector {
  41     static final ShortMaxSpecies SPECIES = new ShortMaxSpecies();
  42 
  43     static final ShortMaxVector ZERO = new ShortMaxVector();
  44 
  45     static final int LENGTH = SPECIES.length();
  46 
  47     private final short[] vec; // Don't access directly, use getElements() instead.
  48 
  49     private short[] getElements() {
  50         return VectorIntrinsics.maybeRebox(this).vec;
  51     }
  52 
  53     ShortMaxVector() {
  54         vec = new short[SPECIES.length()];
  55     }
  56 
  57     ShortMaxVector(short[] v) {
  58         vec = v;
  59     }
  60 
  61     @Override
  62     public int length() { return LENGTH; }
  63 
  64     // Unary operator
  65 
  66     @Override
  67     ShortMaxVector uOp(FUnOp f) {
  68         short[] vec = getElements();
  69         short[] res = new short[length()];
  70         for (int i = 0; i < length(); i++) {
  71             res[i] = f.apply(i, vec[i]);
  72         }
  73         return new ShortMaxVector(res);
  74     }
  75 
  76     @Override
  77     ShortMaxVector uOp(Mask<Short> o, FUnOp f) {
  78         short[] vec = getElements();
  79         short[] res = new short[length()];
  80         boolean[] mbits = ((ShortMaxMask)o).getBits();
  81         for (int i = 0; i < length(); i++) {
  82             res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
  83         }
  84         return new ShortMaxVector(res);
  85     }
  86 
  87     // Binary operator
  88 
  89     @Override
  90     ShortMaxVector bOp(Vector<Short> o, FBinOp f) {
  91         short[] res = new short[length()];
  92         short[] vec1 = this.getElements();
  93         short[] vec2 = ((ShortMaxVector)o).getElements();
  94         for (int i = 0; i < length(); i++) {
  95             res[i] = f.apply(i, vec1[i], vec2[i]);
  96         }
  97         return new ShortMaxVector(res);
  98     }
  99 
 100     @Override
 101     ShortMaxVector bOp(Vector<Short> o1, Mask<Short> o2, FBinOp f) {
 102         short[] res = new short[length()];
 103         short[] vec1 = this.getElements();
 104         short[] vec2 = ((ShortMaxVector)o1).getElements();
 105         boolean[] mbits = ((ShortMaxMask)o2).getBits();
 106         for (int i = 0; i < length(); i++) {
 107             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
 108         }
 109         return new ShortMaxVector(res);
 110     }
 111 
 112     // Trinary operator
 113 
 114     @Override
 115     ShortMaxVector tOp(Vector<Short> o1, Vector<Short> o2, FTriOp f) {
 116         short[] res = new short[length()];
 117         short[] vec1 = this.getElements();
 118         short[] vec2 = ((ShortMaxVector)o1).getElements();
 119         short[] vec3 = ((ShortMaxVector)o2).getElements();
 120         for (int i = 0; i < length(); i++) {
 121             res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
 122         }
 123         return new ShortMaxVector(res);
 124     }
 125 
 126     @Override
 127     ShortMaxVector tOp(Vector<Short> o1, Vector<Short> o2, Mask<Short> o3, FTriOp f) {
 128         short[] res = new short[length()];
 129         short[] vec1 = getElements();
 130         short[] vec2 = ((ShortMaxVector)o1).getElements();
 131         short[] vec3 = ((ShortMaxVector)o2).getElements();
 132         boolean[] mbits = ((ShortMaxMask)o3).getBits();
 133         for (int i = 0; i < length(); i++) {
 134             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
 135         }
 136         return new ShortMaxVector(res);
 137     }
 138 
 139     @Override
 140     short rOp(short v, FBinOp f) {
 141         short[] vec = getElements();
 142         for (int i = 0; i < length(); i++) {
 143             v = f.apply(i, v, vec[i]);
 144         }
 145         return v;
 146     }
 147 
 148     @Override
 149     @ForceInline
 150     public <F> Vector<F> cast(Species<F> s) {
 151         Objects.requireNonNull(s);
 152         if (s.length() != LENGTH)
 153             throw new IllegalArgumentException("Vector length this species length differ");
 154 
 155         return VectorIntrinsics.cast(
 156             ShortMaxVector.class,
 157             short.class, LENGTH,
 158             s.vectorType(),
 159             s.elementType(), LENGTH,
 160             this, s,
 161             (species, vector) -> vector.castDefault(species)
 162         );
 163     }
 164 
 165     @SuppressWarnings("unchecked")
 166     @ForceInline
 167     private <F> Vector<F> castDefault(Species<F> s) {
 168         int limit = s.length();
 169 
 170         Class<?> stype = s.elementType();
 171         if (stype == byte.class) {
 172             byte[] a = new byte[limit];
 173             for (int i = 0; i < limit; i++) {
 174                 a[i] = (byte) this.get(i);
 175             }
 176             return (Vector) ByteVector.fromArray((ByteVector.ByteSpecies) s, a, 0);
 177         } else if (stype == short.class) {
 178             short[] a = new short[limit];
 179             for (int i = 0; i < limit; i++) {
 180                 a[i] = (short) this.get(i);
 181             }
 182             return (Vector) ShortVector.fromArray((ShortVector.ShortSpecies) s, a, 0);
 183         } else if (stype == int.class) {
 184             int[] a = new int[limit];
 185             for (int i = 0; i < limit; i++) {
 186                 a[i] = (int) this.get(i);
 187             }
 188             return (Vector) IntVector.fromArray((IntVector.IntSpecies) s, a, 0);
 189         } else if (stype == long.class) {
 190             long[] a = new long[limit];
 191             for (int i = 0; i < limit; i++) {
 192                 a[i] = (long) this.get(i);
 193             }
 194             return (Vector) LongVector.fromArray((LongVector.LongSpecies) s, a, 0);
 195         } else if (stype == float.class) {
 196             float[] a = new float[limit];
 197             for (int i = 0; i < limit; i++) {
 198                 a[i] = (float) this.get(i);
 199             }
 200             return (Vector) FloatVector.fromArray((FloatVector.FloatSpecies) s, a, 0);
 201         } else if (stype == double.class) {
 202             double[] a = new double[limit];
 203             for (int i = 0; i < limit; i++) {
 204                 a[i] = (double) this.get(i);
 205             }
 206             return (Vector) DoubleVector.fromArray((DoubleVector.DoubleSpecies) s, a, 0);
 207         } else {
 208             throw new UnsupportedOperationException("Bad lane type for casting.");
 209         }
 210     }
 211 
 212     @Override
 213     @ForceInline
 214     @SuppressWarnings("unchecked")
 215     public <F> Vector<F> reinterpret(Species<F> s) {
 216         Objects.requireNonNull(s);
 217 
 218         if(s.elementType().equals(short.class)) {
 219             return (Vector<F>) reshape((Species<Short>)s);
 220         }
 221         if(s.bitSize() == bitSize()) {
 222             return reinterpretType(s);
 223         }
 224 
 225         return defaultReinterpret(s);
 226     }
 227 
 228     @ForceInline
 229     private <F> Vector<F> reinterpretType(Species<F> s) {
 230         Objects.requireNonNull(s);
 231 
 232         Class<?> stype = s.elementType();
 233         if (stype == byte.class) {
 234             return VectorIntrinsics.reinterpret(
 235                 ShortMaxVector.class,
 236                 short.class, LENGTH,
 237                 ByteMaxVector.class,
 238                 byte.class, ByteMaxVector.LENGTH,
 239                 this, s,
 240                 (species, vector) -> vector.defaultReinterpret(species)
 241             );
 242         } else if (stype == short.class) {
 243             return VectorIntrinsics.reinterpret(
 244                 ShortMaxVector.class,
 245                 short.class, LENGTH,
 246                 ShortMaxVector.class,
 247                 short.class, ShortMaxVector.LENGTH,
 248                 this, s,
 249                 (species, vector) -> vector.defaultReinterpret(species)
 250             );
 251         } else if (stype == int.class) {
 252             return VectorIntrinsics.reinterpret(
 253                 ShortMaxVector.class,
 254                 short.class, LENGTH,
 255                 IntMaxVector.class,
 256                 int.class, IntMaxVector.LENGTH,
 257                 this, s,
 258                 (species, vector) -> vector.defaultReinterpret(species)
 259             );
 260         } else if (stype == long.class) {
 261             return VectorIntrinsics.reinterpret(
 262                 ShortMaxVector.class,
 263                 short.class, LENGTH,
 264                 LongMaxVector.class,
 265                 long.class, LongMaxVector.LENGTH,
 266                 this, s,
 267                 (species, vector) -> vector.defaultReinterpret(species)
 268             );
 269         } else if (stype == float.class) {
 270             return VectorIntrinsics.reinterpret(
 271                 ShortMaxVector.class,
 272                 short.class, LENGTH,
 273                 FloatMaxVector.class,
 274                 float.class, FloatMaxVector.LENGTH,
 275                 this, s,
 276                 (species, vector) -> vector.defaultReinterpret(species)
 277             );
 278         } else if (stype == double.class) {
 279             return VectorIntrinsics.reinterpret(
 280                 ShortMaxVector.class,
 281                 short.class, LENGTH,
 282                 DoubleMaxVector.class,
 283                 double.class, DoubleMaxVector.LENGTH,
 284                 this, s,
 285                 (species, vector) -> vector.defaultReinterpret(species)
 286             );
 287         } else {
 288             throw new UnsupportedOperationException("Bad lane type for casting.");
 289         }
 290     }
 291 
 292     @Override
 293     @ForceInline
 294     public ShortVector reshape(Species<Short> s) {
 295         Objects.requireNonNull(s);
 296         if (s.bitSize() == 64 && (s instanceof Short64Vector.Short64Species)) {
 297             Short64Vector.Short64Species ts = (Short64Vector.Short64Species)s;
 298             return VectorIntrinsics.reinterpret(
 299                 ShortMaxVector.class,
 300                 short.class, LENGTH,
 301                 Short64Vector.class,
 302                 short.class, Short64Vector.LENGTH,
 303                 this, ts,
 304                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 305             );
 306         } else if (s.bitSize() == 128 && (s instanceof Short128Vector.Short128Species)) {
 307             Short128Vector.Short128Species ts = (Short128Vector.Short128Species)s;
 308             return VectorIntrinsics.reinterpret(
 309                 ShortMaxVector.class,
 310                 short.class, LENGTH,
 311                 Short128Vector.class,
 312                 short.class, Short128Vector.LENGTH,
 313                 this, ts,
 314                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 315             );
 316         } else if (s.bitSize() == 256 && (s instanceof Short256Vector.Short256Species)) {
 317             Short256Vector.Short256Species ts = (Short256Vector.Short256Species)s;
 318             return VectorIntrinsics.reinterpret(
 319                 ShortMaxVector.class,
 320                 short.class, LENGTH,
 321                 Short256Vector.class,
 322                 short.class, Short256Vector.LENGTH,
 323                 this, ts,
 324                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 325             );
 326         } else if (s.bitSize() == 512 && (s instanceof Short512Vector.Short512Species)) {
 327             Short512Vector.Short512Species ts = (Short512Vector.Short512Species)s;
 328             return VectorIntrinsics.reinterpret(
 329                 ShortMaxVector.class,
 330                 short.class, LENGTH,
 331                 Short512Vector.class,
 332                 short.class, Short512Vector.LENGTH,
 333                 this, ts,
 334                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 335             );
 336         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 337                 && (s.bitSize() % 128 == 0) && (s instanceof ShortMaxVector.ShortMaxSpecies)) {
 338             ShortMaxVector.ShortMaxSpecies ts = (ShortMaxVector.ShortMaxSpecies)s;
 339             return VectorIntrinsics.reinterpret(
 340                 ShortMaxVector.class,
 341                 short.class, LENGTH,
 342                 ShortMaxVector.class,
 343                 short.class, ShortMaxVector.LENGTH,
 344                 this, ts,
 345                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 346             );
 347         } else {
 348             throw new InternalError("Unimplemented size");
 349         }
 350     }
 351 
 352     // Binary operations with scalars
 353 
 354     @Override
 355     @ForceInline
 356     public ShortVector add(short o) {
 357         return add(SPECIES.broadcast(o));
 358     }
 359 
 360     @Override
 361     @ForceInline
 362     public ShortVector add(short o, Mask<Short> m) {
 363         return add(SPECIES.broadcast(o), m);
 364     }
 365 
 366     @Override
 367     @ForceInline
 368     public ShortVector sub(short o) {
 369         return sub(SPECIES.broadcast(o));
 370     }
 371 
 372     @Override
 373     @ForceInline
 374     public ShortVector sub(short o, Mask<Short> m) {
 375         return sub(SPECIES.broadcast(o), m);
 376     }
 377 
 378     @Override
 379     @ForceInline
 380     public ShortVector mul(short o) {
 381         return mul(SPECIES.broadcast(o));
 382     }
 383 
 384     @Override
 385     @ForceInline
 386     public ShortVector mul(short o, Mask<Short> m) {
 387         return mul(SPECIES.broadcast(o), m);
 388     }
 389 
 390     @Override
 391     @ForceInline
 392     public ShortVector min(short o) {
 393         return min(SPECIES.broadcast(o));
 394     }
 395 
 396     @Override
 397     @ForceInline
 398     public ShortVector max(short o) {
 399         return max(SPECIES.broadcast(o));
 400     }
 401 
 402     @Override
 403     @ForceInline
 404     public Mask<Short> equal(short o) {
 405         return equal(SPECIES.broadcast(o));
 406     }
 407 
 408     @Override
 409     @ForceInline
 410     public Mask<Short> notEqual(short o) {
 411         return notEqual(SPECIES.broadcast(o));
 412     }
 413 
 414     @Override
 415     @ForceInline
 416     public Mask<Short> lessThan(short o) {
 417         return lessThan(SPECIES.broadcast(o));
 418     }
 419 
 420     @Override
 421     @ForceInline
 422     public Mask<Short> lessThanEq(short o) {
 423         return lessThanEq(SPECIES.broadcast(o));
 424     }
 425 
 426     @Override
 427     @ForceInline
 428     public Mask<Short> greaterThan(short o) {
 429         return greaterThan(SPECIES.broadcast(o));
 430     }
 431 
 432     @Override
 433     @ForceInline
 434     public Mask<Short> greaterThanEq(short o) {
 435         return greaterThanEq(SPECIES.broadcast(o));
 436     }
 437 
 438     @Override
 439     @ForceInline
 440     public ShortVector blend(short o, Mask<Short> m) {
 441         return blend(SPECIES.broadcast(o), m);
 442     }
 443 
 444 
 445     @Override
 446     @ForceInline
 447     public ShortVector and(short o) {
 448         return and(SPECIES.broadcast(o));
 449     }
 450 
 451     @Override
 452     @ForceInline
 453     public ShortVector and(short o, Mask<Short> m) {
 454         return and(SPECIES.broadcast(o), m);
 455     }
 456 
 457     @Override
 458     @ForceInline
 459     public ShortVector or(short o) {
 460         return or(SPECIES.broadcast(o));
 461     }
 462 
 463     @Override
 464     @ForceInline
 465     public ShortVector or(short o, Mask<Short> m) {
 466         return or(SPECIES.broadcast(o), m);
 467     }
 468 
 469     @Override
 470     @ForceInline
 471     public ShortVector xor(short o) {
 472         return xor(SPECIES.broadcast(o));
 473     }
 474 
 475     @Override
 476     @ForceInline
 477     public ShortVector xor(short o, Mask<Short> m) {
 478         return xor(SPECIES.broadcast(o), m);
 479     }
 480 
 481     @Override
 482     @ForceInline
 483     public ShortMaxVector neg() {
 484         return (ShortMaxVector)zero(SPECIES).sub(this);
 485     }
 486 
 487     // Unary operations
 488 
 489     @ForceInline
 490     @Override
 491     public ShortMaxVector neg(Mask<Short> m) {
 492         return blend(neg(), m);
 493     }
 494 
 495     @Override
 496     @ForceInline
 497     public ShortMaxVector abs() {
 498         return VectorIntrinsics.unaryOp(
 499             VECTOR_OP_ABS, ShortMaxVector.class, short.class, LENGTH,
 500             this,
 501             v1 -> v1.uOp((i, a) -> (short) Math.abs(a)));
 502     }
 503 
 504     @ForceInline
 505     @Override
 506     public ShortMaxVector abs(Mask<Short> m) {
 507         return blend(abs(), m);
 508     }
 509 
 510 
 511     @Override
 512     @ForceInline
 513     public ShortMaxVector not() {
 514         return VectorIntrinsics.unaryOp(
 515             VECTOR_OP_NOT, ShortMaxVector.class, short.class, LENGTH,
 516             this,
 517             v1 -> v1.uOp((i, a) -> (short) ~a));
 518     }
 519 
 520     @ForceInline
 521     @Override
 522     public ShortMaxVector not(Mask<Short> m) {
 523         return blend(not(), m);
 524     }
 525     // Binary operations
 526 
 527     @Override
 528     @ForceInline
 529     public ShortMaxVector add(Vector<Short> o) {
 530         Objects.requireNonNull(o);
 531         ShortMaxVector v = (ShortMaxVector)o;
 532         return VectorIntrinsics.binaryOp(
 533             VECTOR_OP_ADD, ShortMaxVector.class, short.class, LENGTH,
 534             this, v,
 535             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a + b)));
 536     }
 537 
 538     @Override
 539     @ForceInline
 540     public ShortMaxVector add(Vector<Short> v, Mask<Short> m) {
 541         return blend(add(v), m);
 542     }
 543 
 544     @Override
 545     @ForceInline
 546     public ShortMaxVector sub(Vector<Short> o) {
 547         Objects.requireNonNull(o);
 548         ShortMaxVector v = (ShortMaxVector)o;
 549         return VectorIntrinsics.binaryOp(
 550             VECTOR_OP_SUB, ShortMaxVector.class, short.class, LENGTH,
 551             this, v,
 552             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a - b)));
 553     }
 554 
 555     @Override
 556     @ForceInline
 557     public ShortMaxVector sub(Vector<Short> v, Mask<Short> m) {
 558         return blend(sub(v), m);
 559     }
 560 
 561     @Override
 562     @ForceInline
 563     public ShortMaxVector mul(Vector<Short> o) {
 564         Objects.requireNonNull(o);
 565         ShortMaxVector v = (ShortMaxVector)o;
 566         return VectorIntrinsics.binaryOp(
 567             VECTOR_OP_MUL, ShortMaxVector.class, short.class, LENGTH,
 568             this, v,
 569             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a * b)));
 570     }
 571 
 572     @Override
 573     @ForceInline
 574     public ShortMaxVector mul(Vector<Short> v, Mask<Short> m) {
 575         return blend(mul(v), m);
 576     }
 577 
 578     @Override
 579     @ForceInline
 580     public ShortMaxVector min(Vector<Short> o) {
 581         Objects.requireNonNull(o);
 582         ShortMaxVector v = (ShortMaxVector)o;
 583         return (ShortMaxVector) VectorIntrinsics.binaryOp(
 584             VECTOR_OP_MIN, ShortMaxVector.class, short.class, LENGTH,
 585             this, v,
 586             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short) Math.min(a, b)));
 587     }
 588 
 589     @Override
 590     @ForceInline
 591     public ShortMaxVector min(Vector<Short> v, Mask<Short> m) {
 592         return blend(min(v), m);
 593     }
 594 
 595     @Override
 596     @ForceInline
 597     public ShortMaxVector max(Vector<Short> o) {
 598         Objects.requireNonNull(o);
 599         ShortMaxVector v = (ShortMaxVector)o;
 600         return VectorIntrinsics.binaryOp(
 601             VECTOR_OP_MAX, ShortMaxVector.class, short.class, LENGTH,
 602             this, v,
 603             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short) Math.max(a, b)));
 604         }
 605 
 606     @Override
 607     @ForceInline
 608     public ShortMaxVector max(Vector<Short> v, Mask<Short> m) {
 609         return blend(max(v), m);
 610     }
 611 
 612     @Override
 613     @ForceInline
 614     public ShortMaxVector and(Vector<Short> o) {
 615         Objects.requireNonNull(o);
 616         ShortMaxVector v = (ShortMaxVector)o;
 617         return VectorIntrinsics.binaryOp(
 618             VECTOR_OP_AND, ShortMaxVector.class, short.class, LENGTH,
 619             this, v,
 620             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a & b)));
 621     }
 622 
 623     @Override
 624     @ForceInline
 625     public ShortMaxVector or(Vector<Short> o) {
 626         Objects.requireNonNull(o);
 627         ShortMaxVector v = (ShortMaxVector)o;
 628         return VectorIntrinsics.binaryOp(
 629             VECTOR_OP_OR, ShortMaxVector.class, short.class, LENGTH,
 630             this, v,
 631             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a | b)));
 632     }
 633 
 634     @Override
 635     @ForceInline
 636     public ShortMaxVector xor(Vector<Short> o) {
 637         Objects.requireNonNull(o);
 638         ShortMaxVector v = (ShortMaxVector)o;
 639         return VectorIntrinsics.binaryOp(
 640             VECTOR_OP_XOR, ShortMaxVector.class, short.class, LENGTH,
 641             this, v,
 642             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a ^ b)));
 643     }
 644 
 645     @Override
 646     @ForceInline
 647     public ShortMaxVector and(Vector<Short> v, Mask<Short> m) {
 648         return blend(and(v), m);
 649     }
 650 
 651     @Override
 652     @ForceInline
 653     public ShortMaxVector or(Vector<Short> v, Mask<Short> m) {
 654         return blend(or(v), m);
 655     }
 656 
 657     @Override
 658     @ForceInline
 659     public ShortMaxVector xor(Vector<Short> v, Mask<Short> m) {
 660         return blend(xor(v), m);
 661     }
 662 
 663     @Override
 664     @ForceInline
 665     public ShortMaxVector shiftL(int s) {
 666         return VectorIntrinsics.broadcastInt(
 667             VECTOR_OP_LSHIFT, ShortMaxVector.class, short.class, LENGTH,
 668             this, s,
 669             (v, i) -> v.uOp((__, a) -> (short) (a << (i & 15))));
 670     }
 671 
 672     @Override
 673     @ForceInline
 674     public ShortMaxVector shiftL(int s, Mask<Short> m) {
 675         return blend(shiftL(s), m);
 676     }
 677 
 678     @Override
 679     @ForceInline
 680     public ShortMaxVector shiftR(int s) {
 681         return VectorIntrinsics.broadcastInt(
 682             VECTOR_OP_URSHIFT, ShortMaxVector.class, short.class, LENGTH,
 683             this, s,
 684             (v, i) -> v.uOp((__, a) -> (short) ((a & 0xFFFF) >>> (i & 15))));
 685     }
 686 
 687     @Override
 688     @ForceInline
 689     public ShortMaxVector shiftR(int s, Mask<Short> m) {
 690         return blend(shiftR(s), m);
 691     }
 692 
 693     @Override
 694     @ForceInline
 695     public ShortMaxVector aShiftR(int s) {
 696         return VectorIntrinsics.broadcastInt(
 697             VECTOR_OP_RSHIFT, ShortMaxVector.class, short.class, LENGTH,
 698             this, s,
 699             (v, i) -> v.uOp((__, a) -> (short) (a >> (i & 15))));
 700     }
 701 
 702     @Override
 703     @ForceInline
 704     public ShortMaxVector aShiftR(int s, Mask<Short> m) {
 705         return blend(aShiftR(s), m);
 706     }
 707     // Ternary operations
 708 
 709 
 710     // Type specific horizontal reductions
 711 
 712     @Override
 713     @ForceInline
 714     public short addAll() {
 715         return (short) VectorIntrinsics.reductionCoerced(
 716             VECTOR_OP_ADD, ShortMaxVector.class, short.class, LENGTH,
 717             this,
 718             v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a + b)));
 719     }
 720 
 721     @Override
 722     @ForceInline
 723     public short andAll() {
 724         return (short) VectorIntrinsics.reductionCoerced(
 725             VECTOR_OP_AND, ShortMaxVector.class, short.class, LENGTH,
 726             this,
 727             v -> (long) v.rOp((short) -1, (i, a, b) -> (short) (a & b)));
 728     }
 729 
 730     @Override
 731     @ForceInline
 732     public short andAll(Mask<Short> m) {
 733         return SPECIES.broadcast((short) -1).blend(this, m).andAll();
 734     }
 735 
 736     @Override
 737     @ForceInline
 738     public short minAll() {
 739         return (short) VectorIntrinsics.reductionCoerced(
 740             VECTOR_OP_MIN, ShortMaxVector.class, short.class, LENGTH,
 741             this,
 742             v -> (long) v.rOp(Short.MAX_VALUE , (i, a, b) -> (short) Math.min(a, b)));
 743     }
 744 
 745     @Override
 746     @ForceInline
 747     public short maxAll() {
 748         return (short) VectorIntrinsics.reductionCoerced(
 749             VECTOR_OP_MAX, ShortMaxVector.class, short.class, LENGTH,
 750             this,
 751             v -> (long) v.rOp(Short.MIN_VALUE , (i, a, b) -> (short) Math.max(a, b)));
 752     }
 753 
 754     @Override
 755     @ForceInline
 756     public short mulAll() {
 757         return (short) VectorIntrinsics.reductionCoerced(
 758             VECTOR_OP_MUL, ShortMaxVector.class, short.class, LENGTH,
 759             this,
 760             v -> (long) v.rOp((short) 1, (i, a, b) -> (short) (a * b)));
 761     }
 762 
 763     @Override
 764     @ForceInline
 765     public short orAll() {
 766         return (short) VectorIntrinsics.reductionCoerced(
 767             VECTOR_OP_OR, ShortMaxVector.class, short.class, LENGTH,
 768             this,
 769             v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a | b)));
 770     }
 771 
 772     @Override
 773     @ForceInline
 774     public short orAll(Mask<Short> m) {
 775         return SPECIES.broadcast((short) 0).blend(this, m).orAll();
 776     }
 777 
 778     @Override
 779     @ForceInline
 780     public short xorAll() {
 781         return (short) VectorIntrinsics.reductionCoerced(
 782             VECTOR_OP_XOR, ShortMaxVector.class, short.class, LENGTH,
 783             this,
 784             v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a ^ b)));
 785     }
 786 
 787     @Override
 788     @ForceInline
 789     public short xorAll(Mask<Short> m) {
 790         return SPECIES.broadcast((short) 0).blend(this, m).xorAll();
 791     }
 792 
 793 
 794     @Override
 795     @ForceInline
 796     public short addAll(Mask<Short> m) {
 797         return SPECIES.broadcast((short) 0).blend(this, m).addAll();
 798     }
 799 
 800 
 801     @Override
 802     @ForceInline
 803     public short mulAll(Mask<Short> m) {
 804         return SPECIES.broadcast((short) 1).blend(this, m).mulAll();
 805     }
 806 
 807     @Override
 808     @ForceInline
 809     public short minAll(Mask<Short> m) {
 810         return SPECIES.broadcast(Short.MAX_VALUE).blend(this, m).minAll();
 811     }
 812 
 813     @Override
 814     @ForceInline
 815     public short maxAll(Mask<Short> m) {
 816         return SPECIES.broadcast(Short.MIN_VALUE).blend(this, m).maxAll();
 817     }
 818 
 819     @Override
 820     @ForceInline
 821     public Shuffle<Short> toShuffle() {
 822         short[] a = toArray();
 823         int[] sa = new int[a.length];
 824         for (int i = 0; i < a.length; i++) {
 825             sa[i] = (int) a[i];
 826         }
 827         return ShortVector.shuffleFromArray(SPECIES, sa, 0);
 828     }
 829 
 830     // Memory operations
 831 
 832     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE);
 833     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
 834 
 835     @Override
 836     @ForceInline
 837     public void intoArray(short[] a, int ix) {
 838         Objects.requireNonNull(a);
 839         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 840         intoArrayWithoutCheck(a, ix);
 841     }
 842 
 843     @ForceInline
 844     private void intoArrayWithoutCheck(short[] a, int ix) {
 845         VectorIntrinsics.store(ShortMaxVector.class, short.class, LENGTH,
 846                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
 847                                this,
 848                                a, ix,
 849                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 850     }
 851 
 852     @Override
 853     @ForceInline
 854     public final void intoArray(short[] a, int ax, Mask<Short> m) {
 855         Objects.requireNonNull(a);
 856         if (ax + LENGTH <= a.length) {
 857             ShortVector oldVal = ShortVector.fromArrayWithoutCheck(SPECIES, a, ax);
 858             ShortVector newVal = oldVal.blend(this, m);
 859             ((ShortMaxVector)newVal).intoArrayWithoutCheck(a, ax);
 860         } else {
 861             forEach(m, (i, e) -> a[ax + i] = e);
 862         }
 863     }
 864 
 865     @Override
 866     @ForceInline
 867     public void intoByteArray(byte[] a, int ix) {
 868         Objects.requireNonNull(a);
 869         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
 870         VectorIntrinsics.store(ShortMaxVector.class, short.class, LENGTH,
 871                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 872                                this,
 873                                a, ix,
 874                                (c, idx, v) -> {
 875                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
 876                                    ShortBuffer tb = bbc.asShortBuffer();
 877                                    v.forEach((i, e) -> tb.put(e));
 878                                });
 879     }
 880 
 881     @Override
 882     @ForceInline
 883     public final void intoByteArray(byte[] a, int ix, Mask<Short> m) {
 884         ShortMaxVector oldVal = (ShortMaxVector) ShortVector.fromByteArray(SPECIES, a, ix);
 885         ShortMaxVector newVal = oldVal.blend(this, m);
 886         newVal.intoByteArray(a, ix);
 887     }
 888 
 889     @Override
 890     @ForceInline
 891     public void intoByteBuffer(ByteBuffer bb, int ix) {
 892         if (bb.order() != ByteOrder.nativeOrder()) {
 893             throw new IllegalArgumentException();
 894         }
 895         if (bb.isReadOnly()) {
 896             throw new ReadOnlyBufferException();
 897         }
 898         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
 899         VectorIntrinsics.store(ShortMaxVector.class, short.class, LENGTH,
 900                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
 901                                this,
 902                                bb, ix,
 903                                (c, idx, v) -> {
 904                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 905                                    ShortBuffer tb = bbc.asShortBuffer();
 906                                    v.forEach((i, e) -> tb.put(e));
 907                                });
 908     }
 909 
 910     @Override
 911     @ForceInline
 912     public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Short> m) {
 913         ShortMaxVector oldVal = (ShortMaxVector) ShortVector.fromByteBuffer(SPECIES, bb, ix);
 914         ShortMaxVector newVal = oldVal.blend(this, m);
 915         newVal.intoByteBuffer(bb, ix);
 916     }
 917 
 918     //
 919 
 920     @Override
 921     public String toString() {
 922         return Arrays.toString(getElements());
 923     }
 924 
 925     @Override
 926     public boolean equals(Object o) {
 927         if (this == o) return true;
 928         if (o == null || this.getClass() != o.getClass()) return false;
 929 
 930         ShortMaxVector that = (ShortMaxVector) o;
 931         return this.equal(that).allTrue();
 932     }
 933 
 934     @Override
 935     public int hashCode() {
 936         return Arrays.hashCode(vec);
 937     }
 938 
 939     // Binary test
 940 
 941     @Override
 942     ShortMaxMask bTest(Vector<Short> o, FBinTest f) {
 943         short[] vec1 = getElements();
 944         short[] vec2 = ((ShortMaxVector)o).getElements();
 945         boolean[] bits = new boolean[length()];
 946         for (int i = 0; i < length(); i++){
 947             bits[i] = f.apply(i, vec1[i], vec2[i]);
 948         }
 949         return new ShortMaxMask(bits);
 950     }
 951 
 952     // Comparisons
 953 
 954     @Override
 955     @ForceInline
 956     public ShortMaxMask equal(Vector<Short> o) {
 957         Objects.requireNonNull(o);
 958         ShortMaxVector v = (ShortMaxVector)o;
 959 
 960         return VectorIntrinsics.compare(
 961             BT_eq, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
 962             this, v,
 963             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
 964     }
 965 
 966     @Override
 967     @ForceInline
 968     public ShortMaxMask notEqual(Vector<Short> o) {
 969         Objects.requireNonNull(o);
 970         ShortMaxVector v = (ShortMaxVector)o;
 971 
 972         return VectorIntrinsics.compare(
 973             BT_ne, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
 974             this, v,
 975             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
 976     }
 977 
 978     @Override
 979     @ForceInline
 980     public ShortMaxMask lessThan(Vector<Short> o) {
 981         Objects.requireNonNull(o);
 982         ShortMaxVector v = (ShortMaxVector)o;
 983 
 984         return VectorIntrinsics.compare(
 985             BT_lt, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
 986             this, v,
 987             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
 988     }
 989 
 990     @Override
 991     @ForceInline
 992     public ShortMaxMask lessThanEq(Vector<Short> o) {
 993         Objects.requireNonNull(o);
 994         ShortMaxVector v = (ShortMaxVector)o;
 995 
 996         return VectorIntrinsics.compare(
 997             BT_le, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
 998             this, v,
 999             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1000     }
1001 
1002     @Override
1003     @ForceInline
1004     public ShortMaxMask greaterThan(Vector<Short> o) {
1005         Objects.requireNonNull(o);
1006         ShortMaxVector v = (ShortMaxVector)o;
1007 
1008         return (ShortMaxMask) VectorIntrinsics.compare(
1009             BT_gt, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
1010             this, v,
1011             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1012     }
1013 
1014     @Override
1015     @ForceInline
1016     public ShortMaxMask greaterThanEq(Vector<Short> o) {
1017         Objects.requireNonNull(o);
1018         ShortMaxVector v = (ShortMaxVector)o;
1019 
1020         return VectorIntrinsics.compare(
1021             BT_ge, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
1022             this, v,
1023             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1024     }
1025 
1026     // Foreach
1027 
1028     @Override
1029     void forEach(FUnCon f) {
1030         short[] vec = getElements();
1031         for (int i = 0; i < length(); i++) {
1032             f.apply(i, vec[i]);
1033         }
1034     }
1035 
1036     @Override
1037     void forEach(Mask<Short> o, FUnCon f) {
1038         boolean[] mbits = ((ShortMaxMask)o).getBits();
1039         forEach((i, a) -> {
1040             if (mbits[i]) { f.apply(i, a); }
1041         });
1042     }
1043 
1044 
1045 
1046     @Override
1047     public ShortMaxVector rotateEL(int j) {
1048         short[] vec = getElements();
1049         short[] res = new short[length()];
1050         for (int i = 0; i < length(); i++){
1051             res[(j + i) % length()] = vec[i];
1052         }
1053         return new ShortMaxVector(res);
1054     }
1055 
1056     @Override
1057     public ShortMaxVector rotateER(int j) {
1058         short[] vec = getElements();
1059         short[] res = new short[length()];
1060         for (int i = 0; i < length(); i++){
1061             int z = i - j;
1062             if(j < 0) {
1063                 res[length() + z] = vec[i];
1064             } else {
1065                 res[z] = vec[i];
1066             }
1067         }
1068         return new ShortMaxVector(res);
1069     }
1070 
1071     @Override
1072     public ShortMaxVector shiftEL(int j) {
1073         short[] vec = getElements();
1074         short[] res = new short[length()];
1075         for (int i = 0; i < length() - j; i++) {
1076             res[i] = vec[i + j];
1077         }
1078         return new ShortMaxVector(res);
1079     }
1080 
1081     @Override
1082     public ShortMaxVector shiftER(int j) {
1083         short[] vec = getElements();
1084         short[] res = new short[length()];
1085         for (int i = 0; i < length() - j; i++){
1086             res[i + j] = vec[i];
1087         }
1088         return new ShortMaxVector(res);
1089     }
1090 
1091     @Override
1092     @ForceInline
1093     public ShortMaxVector rearrange(Vector<Short> v,
1094                                   Shuffle<Short> s, Mask<Short> m) {
1095         return this.rearrange(s).blend(v.rearrange(s), m);
1096     }
1097 
1098     @Override
1099     @ForceInline
1100     public ShortMaxVector rearrange(Shuffle<Short> o1) {
1101         Objects.requireNonNull(o1);
1102         ShortMaxShuffle s =  (ShortMaxShuffle)o1;
1103 
1104         return VectorIntrinsics.rearrangeOp(
1105             ShortMaxVector.class, ShortMaxShuffle.class, short.class, LENGTH,
1106             this, s,
1107             (v1, s_) -> v1.uOp((i, a) -> {
1108                 int ei = s_.getElement(i);
1109                 return v1.get(ei);
1110             }));
1111     }
1112 
1113     @Override
1114     @ForceInline
1115     public ShortMaxVector blend(Vector<Short> o1, Mask<Short> o2) {
1116         Objects.requireNonNull(o1);
1117         Objects.requireNonNull(o2);
1118         ShortMaxVector v = (ShortMaxVector)o1;
1119         ShortMaxMask   m = (ShortMaxMask)o2;
1120 
1121         return VectorIntrinsics.blend(
1122             ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
1123             this, v, m,
1124             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1125     }
1126 
1127     // Accessors
1128 
1129     @Override
1130     public short get(int i) {
1131         if (i < 0 || i >= LENGTH) {
1132             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1133         }
1134         return (short) VectorIntrinsics.extract(
1135                                 ShortMaxVector.class, short.class, LENGTH,
1136                                 this, i,
1137                                 (vec, ix) -> {
1138                                     short[] vecarr = vec.getElements();
1139                                     return (long)vecarr[ix];
1140                                 });
1141     }
1142 
1143     @Override
1144     public ShortMaxVector with(int i, short e) {
1145         if (i < 0 || i >= LENGTH) {
1146             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1147         }
1148         return VectorIntrinsics.insert(
1149                                 ShortMaxVector.class, short.class, LENGTH,
1150                                 this, i, (long)e,
1151                                 (v, ix, bits) -> {
1152                                     short[] res = v.getElements().clone();
1153                                     res[ix] = (short)bits;
1154                                     return new ShortMaxVector(res);
1155                                 });
1156     }
1157 
1158     // Mask
1159 
1160     static final class ShortMaxMask extends AbstractMask<Short> {
1161         static final ShortMaxMask TRUE_MASK = new ShortMaxMask(true);
1162         static final ShortMaxMask FALSE_MASK = new ShortMaxMask(false);
1163 
1164         private final boolean[] bits; // Don't access directly, use getBits() instead.
1165 
1166         public ShortMaxMask(boolean[] bits) {
1167             this(bits, 0);
1168         }
1169 
1170         public ShortMaxMask(boolean[] bits, int offset) {
1171             boolean[] a = new boolean[species().length()];
1172             for (int i = 0; i < a.length; i++) {
1173                 a[i] = bits[offset + i];
1174             }
1175             this.bits = a;
1176         }
1177 
1178         public ShortMaxMask(boolean val) {
1179             boolean[] bits = new boolean[species().length()];
1180             Arrays.fill(bits, val);
1181             this.bits = bits;
1182         }
1183 
1184         boolean[] getBits() {
1185             return VectorIntrinsics.maybeRebox(this).bits;
1186         }
1187 
1188         @Override
1189         ShortMaxMask uOp(MUnOp f) {
1190             boolean[] res = new boolean[species().length()];
1191             boolean[] bits = getBits();
1192             for (int i = 0; i < species().length(); i++) {
1193                 res[i] = f.apply(i, bits[i]);
1194             }
1195             return new ShortMaxMask(res);
1196         }
1197 
1198         @Override
1199         ShortMaxMask bOp(Mask<Short> o, MBinOp f) {
1200             boolean[] res = new boolean[species().length()];
1201             boolean[] bits = getBits();
1202             boolean[] mbits = ((ShortMaxMask)o).getBits();
1203             for (int i = 0; i < species().length(); i++) {
1204                 res[i] = f.apply(i, bits[i], mbits[i]);
1205             }
1206             return new ShortMaxMask(res);
1207         }
1208 
1209         @Override
1210         public ShortMaxSpecies species() {
1211             return SPECIES;
1212         }
1213 
1214         @Override
1215         public ShortMaxVector toVector() {
1216             short[] res = new short[species().length()];
1217             boolean[] bits = getBits();
1218             for (int i = 0; i < species().length(); i++) {
1219                 // -1 will result in the most significant bit being set in
1220                 // addition to some or all other bits
1221                 res[i] = (short) (bits[i] ? -1 : 0);
1222             }
1223             return new ShortMaxVector(res);
1224         }
1225 
1226         // Unary operations
1227 
1228         @Override
1229         @ForceInline
1230         public ShortMaxMask not() {
1231             return (ShortMaxMask) VectorIntrinsics.unaryOp(
1232                                              VECTOR_OP_NOT, ShortMaxMask.class, short.class, LENGTH,
1233                                              this,
1234                                              (m1) -> m1.uOp((i, a) -> !a));
1235         }
1236 
1237         // Binary operations
1238 
1239         @Override
1240         @ForceInline
1241         public ShortMaxMask and(Mask<Short> o) {
1242             Objects.requireNonNull(o);
1243             ShortMaxMask m = (ShortMaxMask)o;
1244             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, ShortMaxMask.class, short.class, LENGTH,
1245                                              this, m,
1246                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1247         }
1248 
1249         @Override
1250         @ForceInline
1251         public ShortMaxMask or(Mask<Short> o) {
1252             Objects.requireNonNull(o);
1253             ShortMaxMask m = (ShortMaxMask)o;
1254             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, ShortMaxMask.class, short.class, LENGTH,
1255                                              this, m,
1256                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1257         }
1258 
1259         // Reductions
1260 
1261         @Override
1262         @ForceInline
1263         public boolean anyTrue() {
1264             return VectorIntrinsics.test(BT_ne, ShortMaxMask.class, short.class, LENGTH,
1265                                          this, this,
1266                                          (m, __) -> anyTrueHelper(((ShortMaxMask)m).getBits()));
1267         }
1268 
1269         @Override
1270         @ForceInline
1271         public boolean allTrue() {
1272             return VectorIntrinsics.test(BT_overflow, ShortMaxMask.class, short.class, LENGTH,
1273                                          this, ShortVector.maskAllTrue(species()),
1274                                          (m, __) -> allTrueHelper(((ShortMaxMask)m).getBits()));
1275         }
1276     }
1277 
1278     // Shuffle
1279 
1280     static final class ShortMaxShuffle extends AbstractShuffle<Short> {
1281         ShortMaxShuffle(byte[] reorder) {
1282             super(reorder);
1283         }
1284 
1285         public ShortMaxShuffle(int[] reorder) {
1286             super(reorder);
1287         }
1288 
1289         public ShortMaxShuffle(int[] reorder, int i) {
1290             super(reorder, i);
1291         }
1292 
1293         public ShortMaxShuffle(IntUnaryOperator f) {
1294             super(f);
1295         }
1296 
1297         @Override
1298         public ShortMaxSpecies species() {
1299             return SPECIES;
1300         }
1301 
1302         @Override
1303         public ShortVector toVector() {
1304             short[] va = new short[SPECIES.length()];
1305             for (int i = 0; i < va.length; i++) {
1306               va[i] = (short) getElement(i);
1307             }
1308             return ShortVector.fromArray(SPECIES, va, 0);
1309         }
1310 
1311         @Override
1312         public ShortMaxShuffle rearrange(Vector.Shuffle<Short> o) {
1313             ShortMaxShuffle s = (ShortMaxShuffle) o;
1314             byte[] r = new byte[reorder.length];
1315             for (int i = 0; i < reorder.length; i++) {
1316                 r[i] = reorder[s.reorder[i]];
1317             }
1318             return new ShortMaxShuffle(r);
1319         }
1320     }
1321 
1322     // Species
1323 
1324     @Override
1325     public ShortMaxSpecies species() {
1326         return SPECIES;
1327     }
1328 
1329     static final class ShortMaxSpecies extends ShortSpecies {
1330         static final int BIT_SIZE = Shape.S_Max_BIT.bitSize();
1331 
1332         static final int LENGTH = BIT_SIZE / Short.SIZE;
1333 
1334         @Override
1335         public String toString() {
1336            StringBuilder sb = new StringBuilder("Shape[");
1337            sb.append(bitSize()).append(" bits, ");
1338            sb.append(length()).append(" ").append(short.class.getSimpleName()).append("s x ");
1339            sb.append(elementSize()).append(" bits");
1340            sb.append("]");
1341            return sb.toString();
1342         }
1343 
1344         @Override
1345         @ForceInline
1346         public int bitSize() {
1347             return BIT_SIZE;
1348         }
1349 
1350         @Override
1351         @ForceInline
1352         public int length() {
1353             return LENGTH;
1354         }
1355 
1356         @Override
1357         @ForceInline
1358         public Class<Short> elementType() {
1359             return short.class;
1360         }
1361 
1362         @Override
1363         @ForceInline
1364         public Class<?> boxType() {
1365             return ShortMaxVector.class;
1366         }
1367 
1368         @Override
1369         @ForceInline
1370         public Class<?> maskType() {
1371             return ShortMaxMask.class;
1372         }
1373 
1374         @Override
1375         @ForceInline
1376         public int elementSize() {
1377             return Short.SIZE;
1378         }
1379 
1380         @Override
1381         @ForceInline
1382         @SuppressWarnings("unchecked")
1383         Class<?> vectorType() {
1384             return ShortMaxVector.class;
1385         }
1386 
1387         @Override
1388         @ForceInline
1389         public Shape shape() {
1390             return Shape.S_Max_BIT;
1391         }
1392 
1393         @Override
1394         ShortMaxVector op(FOp f) {
1395             short[] res = new short[length()];
1396             for (int i = 0; i < length(); i++) {
1397                 res[i] = f.apply(i);
1398             }
1399             return new ShortMaxVector(res);
1400         }
1401 
1402         @Override
1403         ShortMaxVector op(Mask<Short> o, FOp f) {
1404             short[] res = new short[length()];
1405             boolean[] mbits = ((ShortMaxMask)o).getBits();
1406             for (int i = 0; i < length(); i++) {
1407                 if (mbits[i]) {
1408                     res[i] = f.apply(i);
1409                 }
1410             }
1411             return new ShortMaxVector(res);
1412         }
1413 
1414         @Override
1415         ShortMaxMask opm(FOpm f) {
1416             boolean[] res = new boolean[length()];
1417             for (int i = 0; i < length(); i++) {
1418                 res[i] = (boolean)f.apply(i);
1419             }
1420             return new ShortMaxMask(res);
1421         }
1422 
1423         // Factories
1424 
1425         @Override
1426         @ForceInline
1427         public ShortMaxVector zero() {
1428             return VectorIntrinsics.broadcastCoerced(ShortMaxVector.class, short.class, LENGTH,
1429                                                      0, SPECIES,
1430                                                      ((bits, s) -> ((ShortMaxSpecies)s).op(i -> (short)bits)));
1431         }
1432 
1433         @Override
1434         @ForceInline
1435         public ShortMaxVector broadcast(short e) {
1436             return VectorIntrinsics.broadcastCoerced(
1437                 ShortMaxVector.class, short.class, LENGTH,
1438                 e, SPECIES,
1439                 ((bits, s) -> ((ShortMaxSpecies)s).op(i -> (short)bits)));
1440         }
1441 
1442         @Override
1443         @ForceInline
1444         public ShortMaxVector scalars(short... es) {
1445             Objects.requireNonNull(es);
1446             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1447             return VectorIntrinsics.load(ShortMaxVector.class, short.class, LENGTH,
1448                                          es, Unsafe.ARRAY_SHORT_BASE_OFFSET,
1449                                          es, ix, SPECIES,
1450                                          (c, idx, s) -> ((ShortMaxSpecies)s).op(n -> c[idx + n]));
1451         }
1452 
1453         @Override
1454         @ForceInline
1455         public <E> ShortMaxMask cast(Mask<E> m) {
1456             if (m.length() != LENGTH)
1457                 throw new IllegalArgumentException("Mask length this species length differ");
1458             return new ShortMaxMask(m.toArray());
1459         }
1460 
1461         @Override
1462         @ForceInline
1463         public <E> ShortMaxShuffle cast(Shuffle<E> s) {
1464             if (s.length() != LENGTH)
1465                 throw new IllegalArgumentException("Shuffle length this species length differ");
1466             return new ShortMaxShuffle(s.toArray());
1467         }
1468     }
1469 }