< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java

Print this page
rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level


  39 
  40 /**
  41  * A specialized {@link Vector} representing an ordered immutable sequence of
  42  * {@code short} values.
  43  */
  44 @SuppressWarnings("cast")
  45 public abstract class ShortVector extends Vector<Short> {
  46 
  47     ShortVector() {}
  48 
  49     private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE);
  50 
  51     // Unary operator
  52 
  53     interface FUnOp {
  54         short apply(int i, short a);
  55     }
  56 
  57     abstract ShortVector uOp(FUnOp f);
  58 
  59     abstract ShortVector uOp(Mask<Short> m, FUnOp f);
  60 
  61     // Binary operator
  62 
  63     interface FBinOp {
  64         short apply(int i, short a, short b);
  65     }
  66 
  67     abstract ShortVector bOp(Vector<Short> v, FBinOp f);
  68 
  69     abstract ShortVector bOp(Vector<Short> v, Mask<Short> m, FBinOp f);
  70 
  71     // Trinary operator
  72 
  73     interface FTriOp {
  74         short apply(int i, short a, short b, short c);
  75     }
  76 
  77     abstract ShortVector tOp(Vector<Short> v1, Vector<Short> v2, FTriOp f);
  78 
  79     abstract ShortVector tOp(Vector<Short> v1, Vector<Short> v2, Mask<Short> m, FTriOp f);
  80 
  81     // Reduction operator
  82 
  83     abstract short rOp(short v, FBinOp f);
  84 
  85     // Binary test
  86 
  87     interface FBinTest {
  88         boolean apply(int i, short a, short b);
  89     }
  90 
  91     abstract Mask<Short> bTest(Vector<Short> v, FBinTest f);
  92 
  93     // Foreach
  94 
  95     interface FUnCon {
  96         void apply(int i, short a);
  97     }
  98 
  99     abstract void forEach(FUnCon f);
 100 
 101     abstract void forEach(Mask<Short> m, FUnCon f);
 102 
 103     // Static factories
 104 
 105     /**
 106      * Returns a vector where all lane elements are set to the default
 107      * primitive value.
 108      *
 109      * @param species species of desired vector
 110      * @return a zero vector of given species
 111      */
 112     @ForceInline
 113     @SuppressWarnings("unchecked")
 114     public static ShortVector zero(Species<Short> species) {
 115         return VectorIntrinsics.broadcastCoerced((Class<ShortVector>) species.boxType(), short.class, species.length(),
 116                                                  0, species,
 117                                                  ((bits, s) -> ((ShortSpecies)s).op(i -> (short)bits)));
 118     }
 119 
 120     /**
 121      * Loads a vector from a byte array starting at an offset.
 122      * <p>
 123      * Bytes are composed into primitive lane elements according to the
 124      * native byte order of the underlying platform
 125      * <p>
 126      * This method behaves as if it returns the result of calling the
 127      * byte buffer, offset, and mask accepting
 128      * {@link #fromByteBuffer(Species<Short>, ByteBuffer, int, Mask) method} as follows:
 129      * <pre>{@code
 130      * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue());
 131      * }</pre>
 132      *
 133      * @param species species of desired vector
 134      * @param a the byte array
 135      * @param ix the offset into the array
 136      * @return a vector loaded from a byte array
 137      * @throws IndexOutOfBoundsException if {@code i < 0} or
 138      * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
 139      */
 140     @ForceInline
 141     @SuppressWarnings("unchecked")
 142     public static ShortVector fromByteArray(Species<Short> species, byte[] a, int ix) {
 143         Objects.requireNonNull(a);
 144         ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE);
 145         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 146                                      a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 147                                      a, ix, species,
 148                                      (c, idx, s) -> {
 149                                          ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
 150                                          ShortBuffer tb = bbc.asShortBuffer();
 151                                          return ((ShortSpecies)s).op(i -> tb.get());
 152                                      });
 153     }
 154 
 155     /**
 156      * Loads a vector from a byte array starting at an offset and using a
 157      * mask.
 158      * <p>
 159      * Bytes are composed into primitive lane elements according to the
 160      * native byte order of the underlying platform.
 161      * <p>
 162      * This method behaves as if it returns the result of calling the
 163      * byte buffer, offset, and mask accepting
 164      * {@link #fromByteBuffer(Species<Short>, ByteBuffer, int, Mask) method} as follows:
 165      * <pre>{@code
 166      * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m);
 167      * }</pre>
 168      *
 169      * @param species species of desired vector
 170      * @param a the byte array
 171      * @param ix the offset into the array
 172      * @param m the mask
 173      * @return a vector loaded from a byte array
 174      * @throws IndexOutOfBoundsException if {@code i < 0} or
 175      * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
 176      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 177      * or {@code > a.length},
 178      * for any vector lane index {@code N} where the mask at lane {@code N}
 179      * is set
 180      * {@code i >= a.length - (N * this.elementSize() / Byte.SIZE)}
 181      */
 182     @ForceInline
 183     public static ShortVector fromByteArray(Species<Short> species, byte[] a, int ix, Mask<Short> m) {
 184         return zero(species).blend(fromByteArray(species, a, ix), m);
 185     }
 186 
 187     /**
 188      * Loads a vector from an array starting at offset.
 189      * <p>
 190      * For each vector lane, where {@code N} is the vector lane index, the
 191      * array element at index {@code i + N} is placed into the
 192      * resulting vector at lane index {@code N}.
 193      *
 194      * @param species species of desired vector
 195      * @param a the array
 196      * @param i the offset into the array
 197      * @return the vector loaded from an array
 198      * @throws IndexOutOfBoundsException if {@code i < 0}, or
 199      * {@code i > a.length - this.length()}
 200      */
 201     @ForceInline
 202     @SuppressWarnings("unchecked")
 203     public static ShortVector fromArray(Species<Short> species, short[] a, int i){
 204         Objects.requireNonNull(a);
 205         i = VectorIntrinsics.checkIndex(i, a.length, species.length());
 206         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 207                                      a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
 208                                      a, i, species,
 209                                      (c, idx, s) -> ((ShortSpecies)s).op(n -> c[idx + n]));
 210     }
 211 
 212 
 213     /**
 214      * Loads a vector from an array starting at offset and using a mask.
 215      * <p>
 216      * For each vector lane, where {@code N} is the vector lane index,
 217      * if the mask lane at index {@code N} is set then the array element at
 218      * index {@code i + N} is placed into the resulting vector at lane index
 219      * {@code N}, otherwise the default element value is placed into the
 220      * resulting vector at lane index {@code N}.
 221      *
 222      * @param species species of desired vector
 223      * @param a the array
 224      * @param i the offset into the array
 225      * @param m the mask
 226      * @return the vector loaded from an array
 227      * @throws IndexOutOfBoundsException if {@code i < 0}, or
 228      * for any vector lane index {@code N} where the mask at lane {@code N}
 229      * is set {@code i > a.length - N}
 230      */
 231     @ForceInline
 232     public static ShortVector fromArray(Species<Short> species, short[] a, int i, Mask<Short> m) {
 233         return zero(species).blend(fromArray(species, a, i), m);
 234     }
 235 
 236     /**
 237      * Loads a vector from an array using indexes obtained from an index
 238      * map.
 239      * <p>
 240      * For each vector lane, where {@code N} is the vector lane index, the
 241      * array element at index {@code i + indexMap[j + N]} is placed into the
 242      * resulting vector at lane index {@code N}.
 243      *
 244      * @param species species of desired vector
 245      * @param a the array
 246      * @param i the offset into the array, may be negative if relative
 247      * indexes in the index map compensate to produce a value within the
 248      * array bounds
 249      * @param indexMap the index map
 250      * @param j the offset into the index map
 251      * @return the vector loaded from an array
 252      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 253      * {@code j > indexMap.length - this.length()},
 254      * or for any vector lane index {@code N} the result of
 255      * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
 256      */
 257     public static ShortVector fromArray(Species<Short> species, short[] a, int i, int[] indexMap, int j) {
 258         return ((ShortSpecies)species).op(n -> a[i + indexMap[j + n]]);
 259     }
 260     /**
 261      * Loads a vector from an array using indexes obtained from an index
 262      * map and using a mask.
 263      * <p>
 264      * For each vector lane, where {@code N} is the vector lane index,
 265      * if the mask lane at index {@code N} is set then the array element at
 266      * index {@code i + indexMap[j + N]} is placed into the resulting vector
 267      * at lane index {@code N}.
 268      *
 269      * @param species species of desired vector
 270      * @param a the array
 271      * @param i the offset into the array, may be negative if relative
 272      * indexes in the index map compensate to produce a value within the
 273      * array bounds
 274      * @param m the mask
 275      * @param indexMap the index map
 276      * @param j the offset into the index map
 277      * @return the vector loaded from an array
 278      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 279      * {@code j > indexMap.length - this.length()},
 280      * or for any vector lane index {@code N} where the mask at lane
 281      * {@code N} is set the result of {@code i + indexMap[j + N]} is
 282      * {@code < 0} or {@code >= a.length}
 283      */
 284     public static ShortVector fromArray(Species<Short> species, short[] a, int i, Mask<Short> m, int[] indexMap, int j) {
 285         return ((ShortSpecies)species).op(m, n -> a[i + indexMap[j + n]]);
 286     }
 287 
 288     /**
 289      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 290      * offset into the byte buffer.
 291      * <p>
 292      * Bytes are composed into primitive lane elements according to the
 293      * native byte order of the underlying platform.
 294      * <p>
 295      * This method behaves as if it returns the result of calling the
 296      * byte buffer, offset, and mask accepting
 297      * {@link #fromByteBuffer(Species<Short>, ByteBuffer, int, Mask)} method} as follows:
 298      * <pre>{@code
 299      *   return this.fromByteBuffer(b, i, this.maskAllTrue())
 300      * }</pre>
 301      *
 302      * @param species species of desired vector
 303      * @param bb the byte buffer
 304      * @param ix the offset into the byte buffer
 305      * @return a vector loaded from a byte buffer
 306      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 307      * or {@code > b.limit()},
 308      * or if there are fewer than
 309      * {@code this.length() * this.elementSize() / Byte.SIZE} bytes
 310      * remaining in the byte buffer from the given offset
 311      */
 312     @ForceInline
 313     @SuppressWarnings("unchecked")
 314     public static ShortVector fromByteBuffer(Species<Short> species, ByteBuffer bb, int ix) {
 315         if (bb.order() != ByteOrder.nativeOrder()) {
 316             throw new IllegalArgumentException();
 317         }
 318         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE);
 319         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 320                                      U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
 321                                      bb, ix, species,
 322                                      (c, idx, s) -> {
 323                                          ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 324                                          ShortBuffer tb = bbc.asShortBuffer();
 325                                          return ((ShortSpecies)s).op(i -> tb.get());
 326                                      });
 327     }
 328 
 329     /**
 330      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 331      * offset into the byte buffer and using a mask.
 332      * <p>
 333      * This method behaves as if the byte buffer is viewed as a primitive
 334      * {@link java.nio.Buffer buffer} for the primitive element type,


 346      * e[] es = new e[this.length()];
 347      * for (int n = 0; n < t.length; n++) {
 348      *     if (m.isSet(n))
 349      *         es[n] = eb.get(n);
 350      * }
 351      * Vector<E> r = ((ESpecies<S>)this).fromArray(es, 0, m);
 352      * }</pre>
 353      *
 354      * @param species species of desired vector
 355      * @param bb the byte buffer
 356      * @param ix the offset into the byte buffer
 357      * @param m the mask
 358      * @return a vector loaded from a byte buffer
 359      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 360      * or {@code > b.limit()},
 361      * for any vector lane index {@code N} where the mask at lane {@code N}
 362      * is set
 363      * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)}
 364      */
 365     @ForceInline
 366     public static ShortVector fromByteBuffer(Species<Short> species, ByteBuffer bb, int ix, Mask<Short> m) {
 367         return zero(species).blend(fromByteBuffer(species, bb, ix), m);
 368     }
 369 
 370     /**
 371      * Returns a vector where all lane elements are set to the primitive
 372      * value {@code e}.
 373      *
 374      * @param s species of the desired vector
 375      * @param e the value
 376      * @return a vector of vector where all lane elements are set to
 377      * the primitive value {@code e}
 378      */
 379     @ForceInline
 380     @SuppressWarnings("unchecked")
 381     public static ShortVector broadcast(Species<Short> s, short e) {
 382         return VectorIntrinsics.broadcastCoerced(
 383             (Class<ShortVector>) s.boxType(), short.class, s.length(),
 384             e, s,
 385             ((bits, sp) -> ((ShortSpecies)sp).op(i -> (short)bits)));
 386     }
 387 
 388     /**
 389      * Returns a vector where each lane element is set to a given
 390      * primitive value.
 391      * <p>
 392      * For each vector lane, where {@code N} is the vector lane index, the
 393      * the primitive value at index {@code N} is placed into the resulting
 394      * vector at lane index {@code N}.
 395      *
 396      * @param s species of the desired vector
 397      * @param es the given primitive values
 398      * @return a vector where each lane element is set to a given primitive
 399      * value
 400      * @throws IndexOutOfBoundsException if {@code es.length < this.length()}
 401      */
 402     @ForceInline
 403     @SuppressWarnings("unchecked")
 404     public static ShortVector scalars(Species<Short> s, short... es) {
 405         Objects.requireNonNull(es);
 406         int ix = VectorIntrinsics.checkIndex(0, es.length, s.length());
 407         return VectorIntrinsics.load((Class<ShortVector>) s.boxType(), short.class, s.length(),
 408                                      es, Unsafe.ARRAY_SHORT_BASE_OFFSET,
 409                                      es, ix, s,
 410                                      (c, idx, sp) -> ((ShortSpecies)sp).op(n -> c[idx + n]));
 411     }
 412 
 413     /**
 414      * Returns a vector where the first lane element is set to the primtive
 415      * value {@code e}, all other lane elements are set to the default
 416      * value.
 417      *
 418      * @param s species of the desired vector
 419      * @param e the value
 420      * @return a vector where the first lane element is set to the primitive
 421      * value {@code e}
 422      */
 423     @ForceInline
 424     public static final ShortVector single(Species<Short> s, short e) {
 425         return zero(s).with(0, e);
 426     }
 427 
 428     /**
 429      * Returns a vector where each lane element is set to a randomly
 430      * generated primitive value.
 431      *
 432      * The semantics are equivalent to calling
 433      * (short){@link ThreadLocalRandom#nextInt()}
 434      *
 435      * @param s species of the desired vector
 436      * @return a vector where each lane elements is set to a randomly
 437      * generated primitive value
 438      */
 439     public static ShortVector random(Species<Short> s) {
 440         ThreadLocalRandom r = ThreadLocalRandom.current();
 441         return ((ShortSpecies)s).op(i -> (short) r.nextInt());
 442     }
 443 
 444     /**
 445      * Returns a mask where each lane is set or unset according to given
 446      * {@code boolean} values
 447      * <p>
 448      * For each mask lane, where {@code N} is the mask lane index,
 449      * if the given {@code boolean} value at index {@code N} is {@code true}
 450      * then the mask lane at index {@code N} is set, otherwise it is unset.
 451      *
 452      * @param species mask species
 453      * @param bits the given {@code boolean} values
 454      * @return a mask where each lane is set or unset according to the given {@code boolean} value
 455      * @throws IndexOutOfBoundsException if {@code bits.length < species.length()}
 456      */
 457     @ForceInline
 458     public static Mask<Short> maskFromValues(Species<Short> species, boolean... bits) {
 459         if (species.boxType() == ShortMaxVector.class)
 460             return new ShortMaxVector.ShortMaxMask(bits);
 461         switch (species.bitSize()) {
 462             case 64: return new Short64Vector.Short64Mask(bits);
 463             case 128: return new Short128Vector.Short128Mask(bits);
 464             case 256: return new Short256Vector.Short256Mask(bits);
 465             case 512: return new Short512Vector.Short512Mask(bits);
 466             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 467         }
 468     }
 469 
 470     // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
 471     static Mask<Short> trueMask(Species<Short> species) {
 472         if (species.boxType() == ShortMaxVector.class)
 473             return ShortMaxVector.ShortMaxMask.TRUE_MASK;
 474         switch (species.bitSize()) {
 475             case 64: return Short64Vector.Short64Mask.TRUE_MASK;
 476             case 128: return Short128Vector.Short128Mask.TRUE_MASK;
 477             case 256: return Short256Vector.Short256Mask.TRUE_MASK;
 478             case 512: return Short512Vector.Short512Mask.TRUE_MASK;
 479             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 480         }
 481     }
 482 
 483     static Mask<Short> falseMask(Species<Short> species) {
 484         if (species.boxType() == ShortMaxVector.class)
 485             return ShortMaxVector.ShortMaxMask.FALSE_MASK;
 486         switch (species.bitSize()) {
 487             case 64: return Short64Vector.Short64Mask.FALSE_MASK;
 488             case 128: return Short128Vector.Short128Mask.FALSE_MASK;
 489             case 256: return Short256Vector.Short256Mask.FALSE_MASK;
 490             case 512: return Short512Vector.Short512Mask.FALSE_MASK;
 491             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 492         }
 493     }
 494 
 495     /**
 496      * Loads a mask from a {@code boolean} array starting at an offset.
 497      * <p>
 498      * For each mask lane, where {@code N} is the mask lane index,
 499      * if the array element at index {@code ix + N} is {@code true} then the
 500      * mask lane at index {@code N} is set, otherwise it is unset.
 501      *
 502      * @param species mask species
 503      * @param bits the {@code boolean} array
 504      * @param ix the offset into the array
 505      * @return the mask loaded from a {@code boolean} array
 506      * @throws IndexOutOfBoundsException if {@code ix < 0}, or
 507      * {@code ix > bits.length - species.length()}
 508      */
 509     @ForceInline
 510     @SuppressWarnings("unchecked")
 511     public static Mask<Short> maskFromArray(Species<Short> species, boolean[] bits, int ix) {
 512         Objects.requireNonNull(bits);
 513         ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length());
 514         return VectorIntrinsics.load((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 515                                      bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
 516                                      bits, ix, species,
 517                                      (c, idx, s) -> (Mask<Short>) ((ShortSpecies)s).opm(n -> c[idx + n]));
 518     }
 519 
 520     /**
 521      * Returns a mask where all lanes are set.
 522      *
 523      * @param species mask species
 524      * @return a mask where all lanes are set
 525      */
 526     @ForceInline
 527     @SuppressWarnings("unchecked")
 528     public static Mask<Short> maskAllTrue(Species<Short> species) {
 529         return VectorIntrinsics.broadcastCoerced((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 530                                                  (short)-1,  species,
 531                                                  ((z, s) -> trueMask(s)));
 532     }
 533 
 534     /**
 535      * Returns a mask where all lanes are unset.
 536      *
 537      * @param species mask species
 538      * @return a mask where all lanes are unset
 539      */
 540     @ForceInline
 541     @SuppressWarnings("unchecked")
 542     public static Mask<Short> maskAllFalse(Species<Short> species) {
 543         return VectorIntrinsics.broadcastCoerced((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 544                                                  0, species, 
 545                                                  ((z, s) -> falseMask(s)));
 546     }
 547 
 548     /**
 549      * Returns a shuffle of mapped indexes where each lane element is
 550      * the result of applying a mapping function to the corresponding lane
 551      * index.
 552      * <p>
 553      * Care should be taken to ensure Shuffle values produced from this
 554      * method are consumed as constants to ensure optimal generation of
 555      * code.  For example, values held in static final fields or values
 556      * held in loop constant local variables.
 557      * <p>
 558      * This method behaves as if a shuffle is created from an array of
 559      * mapped indexes as follows:
 560      * <pre>{@code
 561      *   int[] a = new int[species.length()];
 562      *   for (int i = 0; i < a.length; i++) {
 563      *       a[i] = f.applyAsInt(i);
 564      *   }
 565      *   return this.shuffleFromValues(a);
 566      * }</pre>
 567      *
 568      * @param species shuffle species
 569      * @param f the lane index mapping function
 570      * @return a shuffle of mapped indexes
 571      */
 572     @ForceInline
 573     public static Shuffle<Short> shuffle(Species<Short> species, IntUnaryOperator f) {
 574         if (species.boxType() == ShortMaxVector.class)
 575             return new ShortMaxVector.ShortMaxShuffle(f);
 576         switch (species.bitSize()) {
 577             case 64: return new Short64Vector.Short64Shuffle(f);
 578             case 128: return new Short128Vector.Short128Shuffle(f);
 579             case 256: return new Short256Vector.Short256Shuffle(f);
 580             case 512: return new Short512Vector.Short512Shuffle(f);
 581             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 582         }
 583     }
 584 
 585     /**
 586      * Returns a shuffle where each lane element is the value of its
 587      * corresponding lane index.
 588      * <p>
 589      * This method behaves as if a shuffle is created from an identity
 590      * index mapping function as follows:
 591      * <pre>{@code
 592      *   return this.shuffle(i -> i);
 593      * }</pre>
 594      *
 595      * @param species shuffle species
 596      * @return a shuffle of lane indexes
 597      */
 598     @ForceInline
 599     public static Shuffle<Short> shuffleIota(Species<Short> species) {
 600         if (species.boxType() == ShortMaxVector.class)
 601             return new ShortMaxVector.ShortMaxShuffle(AbstractShuffle.IDENTITY);
 602         switch (species.bitSize()) {
 603             case 64: return new Short64Vector.Short64Shuffle(AbstractShuffle.IDENTITY);
 604             case 128: return new Short128Vector.Short128Shuffle(AbstractShuffle.IDENTITY);
 605             case 256: return new Short256Vector.Short256Shuffle(AbstractShuffle.IDENTITY);
 606             case 512: return new Short512Vector.Short512Shuffle(AbstractShuffle.IDENTITY);
 607             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 608         }
 609     }
 610 
 611     /**
 612      * Returns a shuffle where each lane element is set to a given
 613      * {@code int} value logically AND'ed by the species length minus one.
 614      * <p>
 615      * For each shuffle lane, where {@code N} is the shuffle lane index, the
 616      * the {@code int} value at index {@code N} logically AND'ed by
 617      * {@code species.length() - 1} is placed into the resulting shuffle at
 618      * lane index {@code N}.
 619      *
 620      * @param species shuffle species
 621      * @param ixs the given {@code int} values
 622      * @return a shuffle where each lane element is set to a given
 623      * {@code int} value
 624      * @throws IndexOutOfBoundsException if the number of int values is
 625      * {@code < species.length()}
 626      */
 627     @ForceInline
 628     public static Shuffle<Short> shuffleFromValues(Species<Short> species, int... ixs) {
 629         if (species.boxType() == ShortMaxVector.class)
 630             return new ShortMaxVector.ShortMaxShuffle(ixs);
 631         switch (species.bitSize()) {
 632             case 64: return new Short64Vector.Short64Shuffle(ixs);
 633             case 128: return new Short128Vector.Short128Shuffle(ixs);
 634             case 256: return new Short256Vector.Short256Shuffle(ixs);
 635             case 512: return new Short512Vector.Short512Shuffle(ixs);
 636             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 637         }
 638     }
 639 
 640     /**
 641      * Loads a shuffle from an {@code int} array starting at an offset.
 642      * <p>
 643      * For each shuffle lane, where {@code N} is the shuffle lane index, the
 644      * array element at index {@code i + N} logically AND'ed by
 645      * {@code species.length() - 1} is placed into the resulting shuffle at lane
 646      * index {@code N}.
 647      *
 648      * @param species shuffle species
 649      * @param ixs the {@code int} array
 650      * @param i the offset into the array
 651      * @return a shuffle loaded from the {@code int} array
 652      * @throws IndexOutOfBoundsException if {@code i < 0}, or
 653      * {@code i > a.length - species.length()}
 654      */
 655     @ForceInline
 656     public static Shuffle<Short> shuffleFromArray(Species<Short> species, int[] ixs, int i) {
 657         if (species.boxType() == ShortMaxVector.class)
 658             return new ShortMaxVector.ShortMaxShuffle(ixs, i);
 659         switch (species.bitSize()) {
 660             case 64: return new Short64Vector.Short64Shuffle(ixs, i);
 661             case 128: return new Short128Vector.Short128Shuffle(ixs, i);
 662             case 256: return new Short256Vector.Short256Shuffle(ixs, i);
 663             case 512: return new Short512Vector.Short512Shuffle(ixs, i);
 664             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 665         }
 666     }
 667 
 668     // Ops
 669 
 670     @Override
 671     public abstract ShortVector add(Vector<Short> v);
 672 
 673     /**
 674      * Adds this vector to the broadcast of an input scalar.
 675      * <p>
 676      * This is a vector binary operation where the primitive addition operation
 677      * ({@code +}) is applied to lane elements.
 678      *
 679      * @param s the input scalar
 680      * @return the result of adding this vector to the broadcast of an input
 681      * scalar
 682      */
 683     public abstract ShortVector add(short s);
 684 
 685     @Override
 686     public abstract ShortVector add(Vector<Short> v, Mask<Short> m);
 687 
 688     /**
 689      * Adds this vector to broadcast of an input scalar,
 690      * selecting lane elements controlled by a mask.
 691      * <p>
 692      * This is a vector binary operation where the primitive addition operation
 693      * ({@code +}) is applied to lane elements.
 694      *
 695      * @param s the input scalar
 696      * @param m the mask controlling lane selection
 697      * @return the result of adding this vector to the broadcast of an input
 698      * scalar
 699      */
 700     public abstract ShortVector add(short s, Mask<Short> m);
 701 
 702     @Override
 703     public abstract ShortVector sub(Vector<Short> v);
 704 
 705     /**
 706      * Subtracts the broadcast of an input scalar from this vector.
 707      * <p>
 708      * This is a vector binary operation where the primitive subtraction
 709      * operation ({@code -}) is applied to lane elements.
 710      *
 711      * @param s the input scalar
 712      * @return the result of subtracting the broadcast of an input
 713      * scalar from this vector
 714      */
 715     public abstract ShortVector sub(short s);
 716 
 717     @Override
 718     public abstract ShortVector sub(Vector<Short> v, Mask<Short> m);
 719 
 720     /**
 721      * Subtracts the broadcast of an input scalar from this vector, selecting
 722      * lane elements controlled by a mask.
 723      * <p>
 724      * This is a vector binary operation where the primitive subtraction
 725      * operation ({@code -}) is applied to lane elements.
 726      *
 727      * @param s the input scalar
 728      * @param m the mask controlling lane selection
 729      * @return the result of subtracting the broadcast of an input
 730      * scalar from this vector
 731      */
 732     public abstract ShortVector sub(short s, Mask<Short> m);
 733 
 734     @Override
 735     public abstract ShortVector mul(Vector<Short> v);
 736 
 737     /**
 738      * Multiplies this vector with the broadcast of an input scalar.
 739      * <p>
 740      * This is a vector binary operation where the primitive multiplication
 741      * operation ({@code *}) is applied to lane elements.
 742      *
 743      * @param s the input scalar
 744      * @return the result of multiplying this vector with the broadcast of an
 745      * input scalar
 746      */
 747     public abstract ShortVector mul(short s);
 748 
 749     @Override
 750     public abstract ShortVector mul(Vector<Short> v, Mask<Short> m);
 751 
 752     /**
 753      * Multiplies this vector with the broadcast of an input scalar, selecting
 754      * lane elements controlled by a mask.
 755      * <p>
 756      * This is a vector binary operation where the primitive multiplication
 757      * operation ({@code *}) is applied to lane elements.
 758      *
 759      * @param s the input scalar
 760      * @param m the mask controlling lane selection
 761      * @return the result of multiplying this vector with the broadcast of an
 762      * input scalar
 763      */
 764     public abstract ShortVector mul(short s, Mask<Short> m);
 765 
 766     @Override
 767     public abstract ShortVector neg();
 768 
 769     @Override
 770     public abstract ShortVector neg(Mask<Short> m);
 771 
 772     @Override
 773     public abstract ShortVector abs();
 774 
 775     @Override
 776     public abstract ShortVector abs(Mask<Short> m);
 777 
 778     @Override
 779     public abstract ShortVector min(Vector<Short> v);
 780 
 781     @Override
 782     public abstract ShortVector min(Vector<Short> v, Mask<Short> m);
 783 
 784     /**
 785      * Returns the minimum of this vector and the broadcast of an input scalar.
 786      * <p>
 787      * This is a vector binary operation where the operation
 788      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements.
 789      *
 790      * @param s the input scalar
 791      * @return the minimum of this vector and the broadcast of an input scalar
 792      */
 793     public abstract ShortVector min(short s);
 794 
 795     @Override
 796     public abstract ShortVector max(Vector<Short> v);
 797 
 798     @Override
 799     public abstract ShortVector max(Vector<Short> v, Mask<Short> m);
 800 
 801     /**
 802      * Returns the maximum of this vector and the broadcast of an input scalar.
 803      * <p>
 804      * This is a vector binary operation where the operation
 805      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements.
 806      *
 807      * @param s the input scalar
 808      * @return the maximum of this vector and the broadcast of an input scalar
 809      */
 810     public abstract ShortVector max(short s);
 811 
 812     @Override
 813     public abstract Mask<Short> equal(Vector<Short> v);
 814 
 815     /**
 816      * Tests if this vector is equal to the broadcast of an input scalar.
 817      * <p>
 818      * This is a vector binary test operation where the primitive equals
 819      * operation ({@code ==}) is applied to lane elements.
 820      *
 821      * @param s the input scalar
 822      * @return the result mask of testing if this vector is equal to the
 823      * broadcast of an input scalar
 824      */
 825     public abstract Mask<Short> equal(short s);
 826 
 827     @Override
 828     public abstract Mask<Short> notEqual(Vector<Short> v);
 829 
 830     /**
 831      * Tests if this vector is not equal to the broadcast of an input scalar.
 832      * <p>
 833      * This is a vector binary test operation where the primitive not equals
 834      * operation ({@code !=}) is applied to lane elements.
 835      *
 836      * @param s the input scalar
 837      * @return the result mask of testing if this vector is not equal to the
 838      * broadcast of an input scalar
 839      */
 840     public abstract Mask<Short> notEqual(short s);
 841 
 842     @Override
 843     public abstract Mask<Short> lessThan(Vector<Short> v);
 844 
 845     /**
 846      * Tests if this vector is less than the broadcast of an input scalar.
 847      * <p>
 848      * This is a vector binary test operation where the primitive less than
 849      * operation ({@code <}) is applied to lane elements.
 850      *
 851      * @param s the input scalar
 852      * @return the mask result of testing if this vector is less than the
 853      * broadcast of an input scalar
 854      */
 855     public abstract Mask<Short> lessThan(short s);
 856 
 857     @Override
 858     public abstract Mask<Short> lessThanEq(Vector<Short> v);
 859 
 860     /**
 861      * Tests if this vector is less or equal to the broadcast of an input scalar.
 862      * <p>
 863      * This is a vector binary test operation where the primitive less than
 864      * or equal to operation ({@code <=}) is applied to lane elements.
 865      *
 866      * @param s the input scalar
 867      * @return the mask result of testing if this vector is less than or equal
 868      * to the broadcast of an input scalar
 869      */
 870     public abstract Mask<Short> lessThanEq(short s);
 871 
 872     @Override
 873     public abstract Mask<Short> greaterThan(Vector<Short> v);
 874 
 875     /**
 876      * Tests if this vector is greater than the broadcast of an input scalar.
 877      * <p>
 878      * This is a vector binary test operation where the primitive greater than
 879      * operation ({@code >}) is applied to lane elements.
 880      *
 881      * @param s the input scalar
 882      * @return the mask result of testing if this vector is greater than the
 883      * broadcast of an input scalar
 884      */
 885     public abstract Mask<Short> greaterThan(short s);
 886 
 887     @Override
 888     public abstract Mask<Short> greaterThanEq(Vector<Short> v);
 889 
 890     /**
 891      * Tests if this vector is greater than or equal to the broadcast of an
 892      * input scalar.
 893      * <p>
 894      * This is a vector binary test operation where the primitive greater than
 895      * or equal to operation ({@code >=}) is applied to lane elements.
 896      *
 897      * @param s the input scalar
 898      * @return the mask result of testing if this vector is greater than or
 899      * equal to the broadcast of an input scalar
 900      */
 901     public abstract Mask<Short> greaterThanEq(short s);
 902 
 903     @Override
 904     public abstract ShortVector blend(Vector<Short> v, Mask<Short> m);
 905 
 906     /**
 907      * Blends the lane elements of this vector with those of the broadcast of an
 908      * input scalar, selecting lanes controlled by a mask.
 909      * <p>
 910      * For each lane of the mask, at lane index {@code N}, if the mask lane
 911      * is set then the lane element at {@code N} from the input vector is
 912      * selected and placed into the resulting vector at {@code N},
 913      * otherwise the the lane element at {@code N} from this input vector is
 914      * selected and placed into the resulting vector at {@code N}.
 915      *
 916      * @param s the input scalar
 917      * @param m the mask controlling lane selection
 918      * @return the result of blending the lane elements of this vector with
 919      * those of the broadcast of an input scalar
 920      */
 921     public abstract ShortVector blend(short s, Mask<Short> m);
 922 
 923     @Override
 924     public abstract ShortVector rearrange(Vector<Short> v,
 925                                                       Shuffle<Short> s, Mask<Short> m);
 926 
 927     @Override
 928     public abstract ShortVector rearrange(Shuffle<Short> m);
 929 
 930     @Override
 931     public abstract ShortVector reshape(Species<Short> s);
 932 
 933     @Override
 934     public abstract ShortVector rotateEL(int i);
 935 
 936     @Override
 937     public abstract ShortVector rotateER(int i);
 938 
 939     @Override
 940     public abstract ShortVector shiftEL(int i);
 941 
 942     @Override
 943     public abstract ShortVector shiftER(int i);
 944 
 945 
 946 
 947     /**
 948      * Bitwise ANDs this vector with an input vector.
 949      * <p>
 950      * This is a vector binary operation where the primitive bitwise AND
 951      * operation ({@code &}) is applied to lane elements.


 961      * This is a vector binary operation where the primitive bitwise AND
 962      * operation ({@code &}) is applied to lane elements.
 963      *
 964      * @param s the input scalar
 965      * @return the bitwise AND of this vector with the broadcast of an input
 966      * scalar
 967      */
 968     public abstract ShortVector and(short s);
 969 
 970     /**
 971      * Bitwise ANDs this vector with an input vector, selecting lane elements
 972      * controlled by a mask.
 973      * <p>
 974      * This is a vector binary operation where the primitive bitwise AND
 975      * operation ({@code &}) is applied to lane elements.
 976      *
 977      * @param v the input vector
 978      * @param m the mask controlling lane selection
 979      * @return the bitwise AND of this vector with the input vector
 980      */
 981     public abstract ShortVector and(Vector<Short> v, Mask<Short> m);
 982 
 983     /**
 984      * Bitwise ANDs this vector with the broadcast of an input scalar, selecting
 985      * lane elements controlled by a mask.
 986      * <p>
 987      * This is a vector binary operation where the primitive bitwise AND
 988      * operation ({@code &}) is applied to lane elements.
 989      *
 990      * @param s the input scalar
 991      * @param m the mask controlling lane selection
 992      * @return the bitwise AND of this vector with the broadcast of an input
 993      * scalar
 994      */
 995     public abstract ShortVector and(short s, Mask<Short> m);
 996 
 997     /**
 998      * Bitwise ORs this vector with an input vector.
 999      * <p>
1000      * This is a vector binary operation where the primitive bitwise OR
1001      * operation ({@code |}) is applied to lane elements.
1002      *
1003      * @param v the input vector
1004      * @return the bitwise OR of this vector with the input vector
1005      */
1006     public abstract ShortVector or(Vector<Short> v);
1007 
1008     /**
1009      * Bitwise ORs this vector with the broadcast of an input scalar.
1010      * <p>
1011      * This is a vector binary operation where the primitive bitwise OR
1012      * operation ({@code |}) is applied to lane elements.
1013      *
1014      * @param s the input scalar
1015      * @return the bitwise OR of this vector with the broadcast of an input
1016      * scalar
1017      */
1018     public abstract ShortVector or(short s);
1019 
1020     /**
1021      * Bitwise ORs this vector with an input vector, selecting lane elements
1022      * controlled by a mask.
1023      * <p>
1024      * This is a vector binary operation where the primitive bitwise OR
1025      * operation ({@code |}) is applied to lane elements.
1026      *
1027      * @param v the input vector
1028      * @param m the mask controlling lane selection
1029      * @return the bitwise OR of this vector with the input vector
1030      */
1031     public abstract ShortVector or(Vector<Short> v, Mask<Short> m);
1032 
1033     /**
1034      * Bitwise ORs this vector with the broadcast of an input scalar, selecting
1035      * lane elements controlled by a mask.
1036      * <p>
1037      * This is a vector binary operation where the primitive bitwise OR
1038      * operation ({@code |}) is applied to lane elements.
1039      *
1040      * @param s the input scalar
1041      * @param m the mask controlling lane selection
1042      * @return the bitwise OR of this vector with the broadcast of an input
1043      * scalar
1044      */
1045     public abstract ShortVector or(short s, Mask<Short> m);
1046 
1047     /**
1048      * Bitwise XORs this vector with an input vector.
1049      * <p>
1050      * This is a vector binary operation where the primitive bitwise XOR
1051      * operation ({@code ^}) is applied to lane elements.
1052      *
1053      * @param v the input vector
1054      * @return the bitwise XOR of this vector with the input vector
1055      */
1056     public abstract ShortVector xor(Vector<Short> v);
1057 
1058     /**
1059      * Bitwise XORs this vector with the broadcast of an input scalar.
1060      * <p>
1061      * This is a vector binary operation where the primitive bitwise XOR
1062      * operation ({@code ^}) is applied to lane elements.
1063      *
1064      * @param s the input scalar
1065      * @return the bitwise XOR of this vector with the broadcast of an input
1066      * scalar
1067      */
1068     public abstract ShortVector xor(short s);
1069 
1070     /**
1071      * Bitwise XORs this vector with an input vector, selecting lane elements
1072      * controlled by a mask.
1073      * <p>
1074      * This is a vector binary operation where the primitive bitwise XOR
1075      * operation ({@code ^}) is applied to lane elements.
1076      *
1077      * @param v the input vector
1078      * @param m the mask controlling lane selection
1079      * @return the bitwise XOR of this vector with the input vector
1080      */
1081     public abstract ShortVector xor(Vector<Short> v, Mask<Short> m);
1082 
1083     /**
1084      * Bitwise XORs this vector with the broadcast of an input scalar, selecting
1085      * lane elements controlled by a mask.
1086      * <p>
1087      * This is a vector binary operation where the primitive bitwise XOR
1088      * operation ({@code ^}) is applied to lane elements.
1089      *
1090      * @param s the input scalar
1091      * @param m the mask controlling lane selection
1092      * @return the bitwise XOR of this vector with the broadcast of an input
1093      * scalar
1094      */
1095     public abstract ShortVector xor(short s, Mask<Short> m);
1096 
1097     /**
1098      * Bitwise NOTs this vector.
1099      * <p>
1100      * This is a vector unary operation where the primitive bitwise NOT
1101      * operation ({@code ~}) is applied to lane elements.
1102      *
1103      * @return the bitwise NOT of this vector
1104      */
1105     public abstract ShortVector not();
1106 
1107     /**
1108      * Bitwise NOTs this vector, selecting lane elements controlled by a mask.
1109      * <p>
1110      * This is a vector unary operation where the primitive bitwise NOT
1111      * operation ({@code ~}) is applied to lane elements.
1112      *
1113      * @param m the mask controlling lane selection
1114      * @return the bitwise NOT of this vector
1115      */
1116     public abstract ShortVector not(Mask<Short> m);
1117 
1118     /**
1119      * Logically left shifts this vector by the broadcast of an input scalar.
1120      * <p>
1121      * This is a vector binary operation where the primitive logical left shift
1122      * operation ({@code <<}) is applied to lane elements to left shift the
1123      * element by shift value as specified by the input scalar. Only the 4
1124      * lowest-order bits of shift value are used. It is as if the shift value
1125      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1126      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1127      *
1128      * @param s the input scalar; the number of the bits to left shift
1129      * @return the result of logically left shifting left this vector by the
1130      * broadcast of an input scalar
1131      */
1132     public abstract ShortVector shiftL(int s);
1133 
1134     /**
1135      * Logically left shifts this vector by the broadcast of an input scalar,
1136      * selecting lane elements controlled by a mask.
1137      * <p>
1138      * This is a vector binary operation where the primitive logical left shift
1139      * operation ({@code <<}) is applied to lane elements to left shift the
1140      * element by shift value as specified by the input scalar. Only the 4
1141      * lowest-order bits of shift value are used. It is as if the shift value
1142      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1143      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1144      *
1145      * @param s the input scalar; the number of the bits to left shift
1146      * @param m the mask controlling lane selection
1147      * @return the result of logically left shifting left this vector by the
1148      * broadcast of an input scalar
1149      */
1150     public abstract ShortVector shiftL(int s, Mask<Short> m);
1151 
1152 
1153     // logical, or unsigned, shift right
1154 
1155      /**
1156      * Logically right shifts (or unsigned right shifts) this vector by the
1157      * broadcast of an input scalar.
1158      * <p>
1159      * This is a vector binary operation where the primitive logical right shift
1160      * operation ({@code >>>}) is applied to lane elements to logically right shift the
1161      * element by shift value as specified by the input scalar. Only the 4
1162      * lowest-order bits of shift value are used. It is as if the shift value
1163      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1164      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1165      *
1166      * @param s the input scalar; the number of the bits to right shift
1167      * @return the result of logically right shifting this vector by the
1168      * broadcast of an input scalar
1169      */
1170     public abstract ShortVector shiftR(int s);
1171 
1172      /**
1173      * Logically right shifts (or unsigned right shifts) this vector by the
1174      * broadcast of an input scalar, selecting lane elements controlled by a
1175      * mask.
1176      * <p>
1177      * This is a vector binary operation where the primitive logical right shift
1178      * operation ({@code >>>}) is applied to lane elements to logically right shift the
1179      * element by shift value as specified by the input scalar. Only the 4
1180      * lowest-order bits of shift value are used. It is as if the shift value
1181      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1182      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1183      *
1184      * @param s the input scalar; the number of the bits to right shift
1185      * @param m the mask controlling lane selection
1186      * @return the result of logically right shifting this vector by the
1187      * broadcast of an input scalar
1188      */
1189     public abstract ShortVector shiftR(int s, Mask<Short> m);
1190 
1191 
1192     /**
1193      * Arithmetically right shifts (or signed right shifts) this vector by the
1194      * broadcast of an input scalar.
1195      * <p>
1196      * This is a vector binary operation where the primitive arithmetic right
1197      * shift operation ({@code >>}) is applied to lane elements  to arithmetically
1198      * right shift the element by shift value as specified by the input scalar.
1199      * Only the 4 lowest-order bits of shift value are used. It is as if the shift
1200      * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1201      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1202      *
1203      * @param s the input scalar; the number of the bits to right shift
1204      * @return the result of arithmetically right shifting this vector by the
1205      * broadcast of an input scalar
1206      */
1207     public abstract ShortVector aShiftR(int s);
1208 
1209     /**
1210      * Arithmetically right shifts (or signed right shifts) this vector by the
1211      * broadcast of an input scalar, selecting lane elements controlled by a
1212      * mask.
1213      * <p>
1214      * This is a vector binary operation where the primitive arithmetic right
1215      * shift operation ({@code >>}) is applied to lane elements  to arithmetically
1216      * right shift the element by shift value as specified by the input scalar.
1217      * Only the 4 lowest-order bits of shift value are used. It is as if the shift
1218      * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1219      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1220      *
1221      * @param s the input scalar; the number of the bits to right shift
1222      * @param m the mask controlling lane selection
1223      * @return the result of arithmetically right shifting this vector by the
1224      * broadcast of an input scalar
1225      */
1226     public abstract ShortVector aShiftR(int s, Mask<Short> m);
1227 
1228 
1229     @Override
1230     public abstract void intoByteArray(byte[] a, int ix);
1231 
1232     @Override
1233     public abstract void intoByteArray(byte[] a, int ix, Mask<Short> m);
1234 
1235     @Override
1236     public abstract void intoByteBuffer(ByteBuffer bb, int ix);
1237 
1238     @Override
1239     public abstract void intoByteBuffer(ByteBuffer bb, int ix, Mask<Short> m);
1240 
1241 
1242     // Type specific horizontal reductions
1243     /**
1244      * Adds all lane elements of this vector.
1245      * <p>
1246      * This is an associative vector reduction operation where the addition
1247      * operation ({@code +}) is applied to lane elements,
1248      * and the identity value is {@code 0}.
1249      *
1250      * @return the addition of all the lane elements of this vector
1251      */
1252     public abstract short addAll();
1253 
1254     /**
1255      * Adds all lane elements of this vector, selecting lane elements
1256      * controlled by a mask.
1257      * <p>
1258      * This is an associative vector reduction operation where the addition
1259      * operation ({@code +}) is applied to lane elements,
1260      * and the identity value is {@code 0}.
1261      *
1262      * @param m the mask controlling lane selection
1263      * @return the addition of the selected lane elements of this vector
1264      */
1265     public abstract short addAll(Mask<Short> m);
1266 
1267     /**
1268      * Multiplies all lane elements of this vector.
1269      * <p>
1270      * This is an associative vector reduction operation where the
1271      * multiplication operation ({@code *}) is applied to lane elements,
1272      * and the identity value is {@code 1}.
1273      *
1274      * @return the multiplication of all the lane elements of this vector
1275      */
1276     public abstract short mulAll();
1277 
1278     /**
1279      * Multiplies all lane elements of this vector, selecting lane elements
1280      * controlled by a mask.
1281      * <p>
1282      * This is an associative vector reduction operation where the
1283      * multiplication operation ({@code *}) is applied to lane elements,
1284      * and the identity value is {@code 1}.
1285      *
1286      * @param m the mask controlling lane selection
1287      * @return the multiplication of all the lane elements of this vector
1288      */
1289     public abstract short mulAll(Mask<Short> m);
1290 
1291     /**
1292      * Returns the minimum lane element of this vector.
1293      * <p>
1294      * This is an associative vector reduction operation where the operation
1295      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1296      * and the identity value is
1297      * {@link Short#MAX_VALUE}.
1298      *
1299      * @return the minimum lane element of this vector
1300      */
1301     public abstract short minAll();
1302 
1303     /**
1304      * Returns the minimum lane element of this vector, selecting lane elements
1305      * controlled by a mask.
1306      * <p>
1307      * This is an associative vector reduction operation where the operation
1308      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1309      * and the identity value is
1310      * {@link Short#MAX_VALUE}.
1311      *
1312      * @param m the mask controlling lane selection
1313      * @return the minimum lane element of this vector
1314      */
1315     public abstract short minAll(Mask<Short> m);
1316 
1317     /**
1318      * Returns the maximum lane element of this vector.
1319      * <p>
1320      * This is an associative vector reduction operation where the operation
1321      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1322      * and the identity value is
1323      * {@link Short#MIN_VALUE}.
1324      *
1325      * @return the maximum lane element of this vector
1326      */
1327     public abstract short maxAll();
1328 
1329     /**
1330      * Returns the maximum lane element of this vector, selecting lane elements
1331      * controlled by a mask.
1332      * <p>
1333      * This is an associative vector reduction operation where the operation
1334      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1335      * and the identity value is
1336      * {@link Short#MIN_VALUE}.
1337      *
1338      * @param m the mask controlling lane selection
1339      * @return the maximum lane element of this vector
1340      */
1341     public abstract short maxAll(Mask<Short> m);
1342 
1343     /**
1344      * Logically ORs all lane elements of this vector.
1345      * <p>
1346      * This is an associative vector reduction operation where the logical OR
1347      * operation ({@code |}) is applied to lane elements,
1348      * and the identity value is {@code 0}.
1349      *
1350      * @return the logical OR all the lane elements of this vector
1351      */
1352     public abstract short orAll();
1353 
1354     /**
1355      * Logically ORs all lane elements of this vector, selecting lane elements
1356      * controlled by a mask.
1357      * <p>
1358      * This is an associative vector reduction operation where the logical OR
1359      * operation ({@code |}) is applied to lane elements,
1360      * and the identity value is {@code 0}.
1361      *
1362      * @param m the mask controlling lane selection
1363      * @return the logical OR all the lane elements of this vector
1364      */
1365     public abstract short orAll(Mask<Short> m);
1366 
1367     /**
1368      * Logically ANDs all lane elements of this vector.
1369      * <p>
1370      * This is an associative vector reduction operation where the logical AND
1371      * operation ({@code |}) is applied to lane elements,
1372      * and the identity value is {@code -1}.
1373      *
1374      * @return the logical AND all the lane elements of this vector
1375      */
1376     public abstract short andAll();
1377 
1378     /**
1379      * Logically ANDs all lane elements of this vector, selecting lane elements
1380      * controlled by a mask.
1381      * <p>
1382      * This is an associative vector reduction operation where the logical AND
1383      * operation ({@code |}) is applied to lane elements,
1384      * and the identity value is {@code -1}.
1385      *
1386      * @param m the mask controlling lane selection
1387      * @return the logical AND all the lane elements of this vector
1388      */
1389     public abstract short andAll(Mask<Short> m);
1390 
1391     /**
1392      * Logically XORs all lane elements of this vector.
1393      * <p>
1394      * This is an associative vector reduction operation where the logical XOR
1395      * operation ({@code ^}) is applied to lane elements,
1396      * and the identity value is {@code 0}.
1397      *
1398      * @return the logical XOR all the lane elements of this vector
1399      */
1400     public abstract short xorAll();
1401 
1402     /**
1403      * Logically XORs all lane elements of this vector, selecting lane elements
1404      * controlled by a mask.
1405      * <p>
1406      * This is an associative vector reduction operation where the logical XOR
1407      * operation ({@code ^}) is applied to lane elements,
1408      * and the identity value is {@code 0}.
1409      *
1410      * @param m the mask controlling lane selection
1411      * @return the logical XOR all the lane elements of this vector
1412      */
1413     public abstract short xorAll(Mask<Short> m);
1414 
1415     // Type specific accessors
1416 
1417     /**
1418      * Gets the lane element at lane index {@code i}
1419      *
1420      * @param i the lane index
1421      * @return the lane element at lane index {@code i}
1422      * @throws IllegalArgumentException if the index is is out of range
1423      * ({@code < 0 || >= length()})
1424      */
1425     public abstract short get(int i);
1426 
1427     /**
1428      * Replaces the lane element of this vector at lane index {@code i} with
1429      * value {@code e}.
1430      * <p>
1431      * This is a cross-lane operation and behaves as if it returns the result
1432      * of blending this vector with an input vector that is the result of
1433      * broadcasting {@code e} and a mask that has only one lane set at lane


1475      * @param i the offset into the array
1476      * @throws IndexOutOfBoundsException if {@code i < 0}, or
1477      * {@code i > a.length - this.length()}
1478      */
1479     public abstract void intoArray(short[] a, int i);
1480 
1481     /**
1482      * Stores this vector into an array starting at offset and using a mask.
1483      * <p>
1484      * For each vector lane, where {@code N} is the vector lane index,
1485      * if the mask lane at index {@code N} is set then the lane element at
1486      * index {@code N} is stored into the array index {@code i + N}.
1487      *
1488      * @param a the array
1489      * @param i the offset into the array
1490      * @param m the mask
1491      * @throws IndexOutOfBoundsException if {@code i < 0}, or
1492      * for any vector lane index {@code N} where the mask at lane {@code N}
1493      * is set {@code i >= a.length - N}
1494      */
1495     public abstract void intoArray(short[] a, int i, Mask<Short> m);
1496 
1497     /**
1498      * Stores this vector into an array using indexes obtained from an index
1499      * map.
1500      * <p>
1501      * For each vector lane, where {@code N} is the vector lane index, the
1502      * lane element at index {@code N} is stored into the array at index
1503      * {@code i + indexMap[j + N]}.
1504      *
1505      * @param a the array
1506      * @param i the offset into the array, may be negative if relative
1507      * indexes in the index map compensate to produce a value within the
1508      * array bounds
1509      * @param indexMap the index map
1510      * @param j the offset into the index map
1511      * @throws IndexOutOfBoundsException if {@code j < 0}, or
1512      * {@code j > indexMap.length - this.length()},
1513      * or for any vector lane index {@code N} the result of
1514      * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
1515      */


1522      * map and using a mask.
1523      * <p>
1524      * For each vector lane, where {@code N} is the vector lane index,
1525      * if the mask lane at index {@code N} is set then the lane element at
1526      * index {@code N} is stored into the array at index
1527      * {@code i + indexMap[j + N]}.
1528      *
1529      * @param a the array
1530      * @param i the offset into the array, may be negative if relative
1531      * indexes in the index map compensate to produce a value within the
1532      * array bounds
1533      * @param m the mask
1534      * @param indexMap the index map
1535      * @param j the offset into the index map
1536      * @throws IndexOutOfBoundsException if {@code j < 0}, or
1537      * {@code j > indexMap.length - this.length()},
1538      * or for any vector lane index {@code N} where the mask at lane
1539      * {@code N} is set the result of {@code i + indexMap[j + N]} is
1540      * {@code < 0} or {@code >= a.length}
1541      */
1542     public void intoArray(short[] a, int i, Mask<Short> m, int[] indexMap, int j) {
1543         forEach(m, (n, e) -> a[i + indexMap[j + n]] = e);
1544     }
1545     // Species
1546 
1547     @Override
1548     public abstract Species<Short> species();
1549 
1550     /**
1551      * Class representing {@link ShortVector}'s of the same {@link Vector.Shape Shape}.
1552      */
1553     static final class ShortSpecies extends Vector.AbstractSpecies<Short> {
1554         final Function<short[], ShortVector> vectorFactory;
1555         final Function<boolean[], Vector.Mask<Short>> maskFactory;
1556 
1557         private ShortSpecies(Vector.Shape shape,
1558                           Class<?> boxType,
1559                           Class<?> maskType,
1560                           Function<short[], ShortVector> vectorFactory,
1561                           Function<boolean[], Vector.Mask<Short>> maskFactory) {
1562             super(shape, short.class, Short.SIZE, boxType, maskType);



1563             this.vectorFactory = vectorFactory;
1564             this.maskFactory = maskFactory;
1565         }
1566 
1567         interface FOp {
1568             short apply(int i);
1569         }
1570 
1571         interface FOpm {
1572             boolean apply(int i);
1573         }
1574 
1575         ShortVector op(FOp f) {
1576             short[] res = new short[length()];
1577             for (int i = 0; i < length(); i++) {
1578                 res[i] = f.apply(i);
1579             }
1580             return vectorFactory.apply(res);
1581         }
1582 
1583         ShortVector op(Vector.Mask<Short> o, FOp f) {
1584             short[] res = new short[length()];
1585             boolean[] mbits = ((AbstractMask<Short>)o).getBits();
1586             for (int i = 0; i < length(); i++) {
1587                 if (mbits[i]) {
1588                     res[i] = f.apply(i);
1589                 }
1590             }
1591             return vectorFactory.apply(res);
1592         }
1593 
1594         Vector.Mask<Short> opm(IntVector.IntSpecies.FOpm f) {
1595             boolean[] res = new boolean[length()];
1596             for (int i = 0; i < length(); i++) {
1597                 res[i] = (boolean)f.apply(i);
1598             }
1599             return maskFactory.apply(res);
1600         }
1601     }
1602 
1603     /**
1604      * Finds the preferred species for an element type of {@code short}.
1605      * <p>
1606      * A preferred species is a species chosen by the platform that has a
1607      * shape of maximal bit size.  A preferred species for different element
1608      * types will have the same shape, and therefore vectors, masks, and
1609      * shuffles created from such species will be shape compatible.
1610      *
1611      * @return the preferred species for an element type of {@code short}
1612      */
1613     private static ShortSpecies preferredSpecies() {
1614         return (ShortSpecies) Species.ofPreferred(short.class);
1615     }
1616 
1617     /**
1618      * Finds a species for an element type of {@code short} and shape.
1619      *
1620      * @param s the shape
1621      * @return a species for an element type of {@code short} and shape
1622      * @throws IllegalArgumentException if no such species exists for the shape
1623      */
1624     static ShortSpecies species(Vector.Shape s) {
1625         Objects.requireNonNull(s);
1626         switch (s) {
1627             case S_64_BIT: return (ShortSpecies) SPECIES_64;
1628             case S_128_BIT: return (ShortSpecies) SPECIES_128;
1629             case S_256_BIT: return (ShortSpecies) SPECIES_256;
1630             case S_512_BIT: return (ShortSpecies) SPECIES_512;
1631             case S_Max_BIT: return (ShortSpecies) SPECIES_MAX;
1632             default: throw new IllegalArgumentException("Bad shape: " + s);
1633         }
1634     }
1635 
1636     /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_64_BIT Shape.S_64_BIT}. */
1637     public static final Species<Short> SPECIES_64 = new ShortSpecies(Shape.S_64_BIT, Short64Vector.class, Short64Vector.Short64Mask.class,
1638                                                                      Short64Vector::new, Short64Vector.Short64Mask::new);
1639 
1640     /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_128_BIT Shape.S_128_BIT}. */
1641     public static final Species<Short> SPECIES_128 = new ShortSpecies(Shape.S_128_BIT, Short128Vector.class, Short128Vector.Short128Mask.class,
1642                                                                       Short128Vector::new, Short128Vector.Short128Mask::new);
1643 
1644     /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_256_BIT Shape.S_256_BIT}. */
1645     public static final Species<Short> SPECIES_256 = new ShortSpecies(Shape.S_256_BIT, Short256Vector.class, Short256Vector.Short256Mask.class,
1646                                                                       Short256Vector::new, Short256Vector.Short256Mask::new);
1647 
1648     /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_512_BIT Shape.S_512_BIT}. */
1649     public static final Species<Short> SPECIES_512 = new ShortSpecies(Shape.S_512_BIT, Short512Vector.class, Short512Vector.Short512Mask.class,
1650                                                                       Short512Vector::new, Short512Vector.Short512Mask::new);
1651 
1652     /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_Max_BIT Shape.S_Max_BIT}. */
1653     public static final Species<Short> SPECIES_MAX = new ShortSpecies(Shape.S_Max_BIT, ShortMaxVector.class, ShortMaxVector.ShortMaxMask.class,
1654                                                                       ShortMaxVector::new, ShortMaxVector.ShortMaxMask::new);





1655 
1656     /**
1657      * Preferred species for {@link ShortVector}s.
1658      * A preferred species is a species of maximal bit size for the platform.
1659      */
1660     public static final Species<Short> SPECIES_PREFERRED = (Species<Short>) preferredSpecies();
1661 }


  39 
  40 /**
  41  * A specialized {@link Vector} representing an ordered immutable sequence of
  42  * {@code short} values.
  43  */
  44 @SuppressWarnings("cast")
  45 public abstract class ShortVector extends Vector<Short> {
  46 
  47     ShortVector() {}
  48 
  49     private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE);
  50 
  51     // Unary operator
  52 
  53     interface FUnOp {
  54         short apply(int i, short a);
  55     }
  56 
  57     abstract ShortVector uOp(FUnOp f);
  58 
  59     abstract ShortVector uOp(VectorMask<Short> m, FUnOp f);
  60 
  61     // Binary operator
  62 
  63     interface FBinOp {
  64         short apply(int i, short a, short b);
  65     }
  66 
  67     abstract ShortVector bOp(Vector<Short> v, FBinOp f);
  68 
  69     abstract ShortVector bOp(Vector<Short> v, VectorMask<Short> m, FBinOp f);
  70 
  71     // Trinary operator
  72 
  73     interface FTriOp {
  74         short apply(int i, short a, short b, short c);
  75     }
  76 
  77     abstract ShortVector tOp(Vector<Short> v1, Vector<Short> v2, FTriOp f);
  78 
  79     abstract ShortVector tOp(Vector<Short> v1, Vector<Short> v2, VectorMask<Short> m, FTriOp f);
  80 
  81     // Reduction operator
  82 
  83     abstract short rOp(short v, FBinOp f);
  84 
  85     // Binary test
  86 
  87     interface FBinTest {
  88         boolean apply(int i, short a, short b);
  89     }
  90 
  91     abstract VectorMask<Short> bTest(Vector<Short> v, FBinTest f);
  92 
  93     // Foreach
  94 
  95     interface FUnCon {
  96         void apply(int i, short a);
  97     }
  98 
  99     abstract void forEach(FUnCon f);
 100 
 101     abstract void forEach(VectorMask<Short> m, FUnCon f);
 102 
 103     // Static factories
 104 
 105     /**
 106      * Returns a vector where all lane elements are set to the default
 107      * primitive value.
 108      *
 109      * @param species species of desired vector
 110      * @return a zero vector of given species
 111      */
 112     @ForceInline
 113     @SuppressWarnings("unchecked")
 114     public static ShortVector zero(VectorSpecies<Short> species) {
 115         return VectorIntrinsics.broadcastCoerced((Class<ShortVector>) species.boxType(), short.class, species.length(),
 116                                                  0, species,
 117                                                  ((bits, s) -> ((ShortSpecies)s).op(i -> (short)bits)));
 118     }
 119 
 120     /**
 121      * Loads a vector from a byte array starting at an offset.
 122      * <p>
 123      * Bytes are composed into primitive lane elements according to the
 124      * native byte order of the underlying platform
 125      * <p>
 126      * This method behaves as if it returns the result of calling the
 127      * byte buffer, offset, and mask accepting
 128      * {@link #fromByteBuffer(VectorSpecies<Short>, ByteBuffer, int, VectorMask) method} as follows:
 129      * <pre>{@code
 130      * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue());
 131      * }</pre>
 132      *
 133      * @param species species of desired vector
 134      * @param a the byte array
 135      * @param ix the offset into the array
 136      * @return a vector loaded from a byte array
 137      * @throws IndexOutOfBoundsException if {@code i < 0} or
 138      * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
 139      */
 140     @ForceInline
 141     @SuppressWarnings("unchecked")
 142     public static ShortVector fromByteArray(VectorSpecies<Short> species, byte[] a, int ix) {
 143         Objects.requireNonNull(a);
 144         ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE);
 145         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 146                                      a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 147                                      a, ix, species,
 148                                      (c, idx, s) -> {
 149                                          ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
 150                                          ShortBuffer tb = bbc.asShortBuffer();
 151                                          return ((ShortSpecies)s).op(i -> tb.get());
 152                                      });
 153     }
 154 
 155     /**
 156      * Loads a vector from a byte array starting at an offset and using a
 157      * mask.
 158      * <p>
 159      * Bytes are composed into primitive lane elements according to the
 160      * native byte order of the underlying platform.
 161      * <p>
 162      * This method behaves as if it returns the result of calling the
 163      * byte buffer, offset, and mask accepting
 164      * {@link #fromByteBuffer(VectorSpecies<Short>, ByteBuffer, int, VectorMask) method} as follows:
 165      * <pre>{@code
 166      * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m);
 167      * }</pre>
 168      *
 169      * @param species species of desired vector
 170      * @param a the byte array
 171      * @param ix the offset into the array
 172      * @param m the mask
 173      * @return a vector loaded from a byte array
 174      * @throws IndexOutOfBoundsException if {@code i < 0} or
 175      * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
 176      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 177      * or {@code > a.length},
 178      * for any vector lane index {@code N} where the mask at lane {@code N}
 179      * is set
 180      * {@code i >= a.length - (N * this.elementSize() / Byte.SIZE)}
 181      */
 182     @ForceInline
 183     public static ShortVector fromByteArray(VectorSpecies<Short> species, byte[] a, int ix, VectorMask<Short> m) {
 184         return zero(species).blend(fromByteArray(species, a, ix), m);
 185     }
 186 
 187     /**
 188      * Loads a vector from an array starting at offset.
 189      * <p>
 190      * For each vector lane, where {@code N} is the vector lane index, the
 191      * array element at index {@code i + N} is placed into the
 192      * resulting vector at lane index {@code N}.
 193      *
 194      * @param species species of desired vector
 195      * @param a the array
 196      * @param i the offset into the array
 197      * @return the vector loaded from an array
 198      * @throws IndexOutOfBoundsException if {@code i < 0}, or
 199      * {@code i > a.length - this.length()}
 200      */
 201     @ForceInline
 202     @SuppressWarnings("unchecked")
 203     public static ShortVector fromArray(VectorSpecies<Short> species, short[] a, int i){
 204         Objects.requireNonNull(a);
 205         i = VectorIntrinsics.checkIndex(i, a.length, species.length());
 206         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 207                                      a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
 208                                      a, i, species,
 209                                      (c, idx, s) -> ((ShortSpecies)s).op(n -> c[idx + n]));
 210     }
 211 
 212 
 213     /**
 214      * Loads a vector from an array starting at offset and using a mask.
 215      * <p>
 216      * For each vector lane, where {@code N} is the vector lane index,
 217      * if the mask lane at index {@code N} is set then the array element at
 218      * index {@code i + N} is placed into the resulting vector at lane index
 219      * {@code N}, otherwise the default element value is placed into the
 220      * resulting vector at lane index {@code N}.
 221      *
 222      * @param species species of desired vector
 223      * @param a the array
 224      * @param i the offset into the array
 225      * @param m the mask
 226      * @return the vector loaded from an array
 227      * @throws IndexOutOfBoundsException if {@code i < 0}, or
 228      * for any vector lane index {@code N} where the mask at lane {@code N}
 229      * is set {@code i > a.length - N}
 230      */
 231     @ForceInline
 232     public static ShortVector fromArray(VectorSpecies<Short> species, short[] a, int i, VectorMask<Short> m) {
 233         return zero(species).blend(fromArray(species, a, i), m);
 234     }
 235 
 236     /**
 237      * Loads a vector from an array using indexes obtained from an index
 238      * map.
 239      * <p>
 240      * For each vector lane, where {@code N} is the vector lane index, the
 241      * array element at index {@code i + indexMap[j + N]} is placed into the
 242      * resulting vector at lane index {@code N}.
 243      *
 244      * @param species species of desired vector
 245      * @param a the array
 246      * @param i the offset into the array, may be negative if relative
 247      * indexes in the index map compensate to produce a value within the
 248      * array bounds
 249      * @param indexMap the index map
 250      * @param j the offset into the index map
 251      * @return the vector loaded from an array
 252      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 253      * {@code j > indexMap.length - this.length()},
 254      * or for any vector lane index {@code N} the result of
 255      * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
 256      */
 257     public static ShortVector fromArray(VectorSpecies<Short> species, short[] a, int i, int[] indexMap, int j) {
 258         return ((ShortSpecies)species).op(n -> a[i + indexMap[j + n]]);
 259     }
 260     /**
 261      * Loads a vector from an array using indexes obtained from an index
 262      * map and using a mask.
 263      * <p>
 264      * For each vector lane, where {@code N} is the vector lane index,
 265      * if the mask lane at index {@code N} is set then the array element at
 266      * index {@code i + indexMap[j + N]} is placed into the resulting vector
 267      * at lane index {@code N}.
 268      *
 269      * @param species species of desired vector
 270      * @param a the array
 271      * @param i the offset into the array, may be negative if relative
 272      * indexes in the index map compensate to produce a value within the
 273      * array bounds
 274      * @param m the mask
 275      * @param indexMap the index map
 276      * @param j the offset into the index map
 277      * @return the vector loaded from an array
 278      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 279      * {@code j > indexMap.length - this.length()},
 280      * or for any vector lane index {@code N} where the mask at lane
 281      * {@code N} is set the result of {@code i + indexMap[j + N]} is
 282      * {@code < 0} or {@code >= a.length}
 283      */
 284     public static ShortVector fromArray(VectorSpecies<Short> species, short[] a, int i, VectorMask<Short> m, int[] indexMap, int j) {
 285         return ((ShortSpecies)species).op(m, n -> a[i + indexMap[j + n]]);
 286     }
 287 
 288     /**
 289      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 290      * offset into the byte buffer.
 291      * <p>
 292      * Bytes are composed into primitive lane elements according to the
 293      * native byte order of the underlying platform.
 294      * <p>
 295      * This method behaves as if it returns the result of calling the
 296      * byte buffer, offset, and mask accepting
 297      * {@link #fromByteBuffer(VectorSpecies<Short>, ByteBuffer, int, VectorMask)} method} as follows:
 298      * <pre>{@code
 299      *   return this.fromByteBuffer(b, i, this.maskAllTrue())
 300      * }</pre>
 301      *
 302      * @param species species of desired vector
 303      * @param bb the byte buffer
 304      * @param ix the offset into the byte buffer
 305      * @return a vector loaded from a byte buffer
 306      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 307      * or {@code > b.limit()},
 308      * or if there are fewer than
 309      * {@code this.length() * this.elementSize() / Byte.SIZE} bytes
 310      * remaining in the byte buffer from the given offset
 311      */
 312     @ForceInline
 313     @SuppressWarnings("unchecked")
 314     public static ShortVector fromByteBuffer(VectorSpecies<Short> species, ByteBuffer bb, int ix) {
 315         if (bb.order() != ByteOrder.nativeOrder()) {
 316             throw new IllegalArgumentException();
 317         }
 318         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE);
 319         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 320                                      U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
 321                                      bb, ix, species,
 322                                      (c, idx, s) -> {
 323                                          ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 324                                          ShortBuffer tb = bbc.asShortBuffer();
 325                                          return ((ShortSpecies)s).op(i -> tb.get());
 326                                      });
 327     }
 328 
 329     /**
 330      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 331      * offset into the byte buffer and using a mask.
 332      * <p>
 333      * This method behaves as if the byte buffer is viewed as a primitive
 334      * {@link java.nio.Buffer buffer} for the primitive element type,


 346      * e[] es = new e[this.length()];
 347      * for (int n = 0; n < t.length; n++) {
 348      *     if (m.isSet(n))
 349      *         es[n] = eb.get(n);
 350      * }
 351      * Vector<E> r = ((ESpecies<S>)this).fromArray(es, 0, m);
 352      * }</pre>
 353      *
 354      * @param species species of desired vector
 355      * @param bb the byte buffer
 356      * @param ix the offset into the byte buffer
 357      * @param m the mask
 358      * @return a vector loaded from a byte buffer
 359      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 360      * or {@code > b.limit()},
 361      * for any vector lane index {@code N} where the mask at lane {@code N}
 362      * is set
 363      * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)}
 364      */
 365     @ForceInline
 366     public static ShortVector fromByteBuffer(VectorSpecies<Short> species, ByteBuffer bb, int ix, VectorMask<Short> m) {
 367         return zero(species).blend(fromByteBuffer(species, bb, ix), m);
 368     }
 369 
 370     /**
 371      * Returns a vector where all lane elements are set to the primitive
 372      * value {@code e}.
 373      *
 374      * @param s species of the desired vector
 375      * @param e the value
 376      * @return a vector of vector where all lane elements are set to
 377      * the primitive value {@code e}
 378      */
 379     @ForceInline
 380     @SuppressWarnings("unchecked")
 381     public static ShortVector broadcast(VectorSpecies<Short> s, short e) {
 382         return VectorIntrinsics.broadcastCoerced(
 383             (Class<ShortVector>) s.boxType(), short.class, s.length(),
 384             e, s,
 385             ((bits, sp) -> ((ShortSpecies)sp).op(i -> (short)bits)));
 386     }
 387 
 388     /**
 389      * Returns a vector where each lane element is set to a given
 390      * primitive value.
 391      * <p>
 392      * For each vector lane, where {@code N} is the vector lane index, the
 393      * the primitive value at index {@code N} is placed into the resulting
 394      * vector at lane index {@code N}.
 395      *
 396      * @param s species of the desired vector
 397      * @param es the given primitive values
 398      * @return a vector where each lane element is set to a given primitive
 399      * value
 400      * @throws IndexOutOfBoundsException if {@code es.length < this.length()}
 401      */
 402     @ForceInline
 403     @SuppressWarnings("unchecked")
 404     public static ShortVector scalars(VectorSpecies<Short> s, short... es) {
 405         Objects.requireNonNull(es);
 406         int ix = VectorIntrinsics.checkIndex(0, es.length, s.length());
 407         return VectorIntrinsics.load((Class<ShortVector>) s.boxType(), short.class, s.length(),
 408                                      es, Unsafe.ARRAY_SHORT_BASE_OFFSET,
 409                                      es, ix, s,
 410                                      (c, idx, sp) -> ((ShortSpecies)sp).op(n -> c[idx + n]));
 411     }
 412 
 413     /**
 414      * Returns a vector where the first lane element is set to the primtive
 415      * value {@code e}, all other lane elements are set to the default
 416      * value.
 417      *
 418      * @param s species of the desired vector
 419      * @param e the value
 420      * @return a vector where the first lane element is set to the primitive
 421      * value {@code e}
 422      */
 423     @ForceInline
 424     public static final ShortVector single(VectorSpecies<Short> s, short e) {
 425         return zero(s).with(0, e);
 426     }
 427 
 428     /**
 429      * Returns a vector where each lane element is set to a randomly
 430      * generated primitive value.
 431      *
 432      * The semantics are equivalent to calling
 433      * (short){@link ThreadLocalRandom#nextInt()}
 434      *
 435      * @param s species of the desired vector
 436      * @return a vector where each lane elements is set to a randomly
 437      * generated primitive value
 438      */
 439     public static ShortVector random(VectorSpecies<Short> s) {
 440         ThreadLocalRandom r = ThreadLocalRandom.current();
 441         return ((ShortSpecies)s).op(i -> (short) r.nextInt());
 442     }
 443 
































































































































































































































 444     // Ops
 445 
 446     @Override
 447     public abstract ShortVector add(Vector<Short> v);
 448 
 449     /**
 450      * Adds this vector to the broadcast of an input scalar.
 451      * <p>
 452      * This is a vector binary operation where the primitive addition operation
 453      * ({@code +}) is applied to lane elements.
 454      *
 455      * @param s the input scalar
 456      * @return the result of adding this vector to the broadcast of an input
 457      * scalar
 458      */
 459     public abstract ShortVector add(short s);
 460 
 461     @Override
 462     public abstract ShortVector add(Vector<Short> v, VectorMask<Short> m);
 463 
 464     /**
 465      * Adds this vector to broadcast of an input scalar,
 466      * selecting lane elements controlled by a mask.
 467      * <p>
 468      * This is a vector binary operation where the primitive addition operation
 469      * ({@code +}) is applied to lane elements.
 470      *
 471      * @param s the input scalar
 472      * @param m the mask controlling lane selection
 473      * @return the result of adding this vector to the broadcast of an input
 474      * scalar
 475      */
 476     public abstract ShortVector add(short s, VectorMask<Short> m);
 477 
 478     @Override
 479     public abstract ShortVector sub(Vector<Short> v);
 480 
 481     /**
 482      * Subtracts the broadcast of an input scalar from this vector.
 483      * <p>
 484      * This is a vector binary operation where the primitive subtraction
 485      * operation ({@code -}) is applied to lane elements.
 486      *
 487      * @param s the input scalar
 488      * @return the result of subtracting the broadcast of an input
 489      * scalar from this vector
 490      */
 491     public abstract ShortVector sub(short s);
 492 
 493     @Override
 494     public abstract ShortVector sub(Vector<Short> v, VectorMask<Short> m);
 495 
 496     /**
 497      * Subtracts the broadcast of an input scalar from this vector, selecting
 498      * lane elements controlled by a mask.
 499      * <p>
 500      * This is a vector binary operation where the primitive subtraction
 501      * operation ({@code -}) is applied to lane elements.
 502      *
 503      * @param s the input scalar
 504      * @param m the mask controlling lane selection
 505      * @return the result of subtracting the broadcast of an input
 506      * scalar from this vector
 507      */
 508     public abstract ShortVector sub(short s, VectorMask<Short> m);
 509 
 510     @Override
 511     public abstract ShortVector mul(Vector<Short> v);
 512 
 513     /**
 514      * Multiplies this vector with the broadcast of an input scalar.
 515      * <p>
 516      * This is a vector binary operation where the primitive multiplication
 517      * operation ({@code *}) is applied to lane elements.
 518      *
 519      * @param s the input scalar
 520      * @return the result of multiplying this vector with the broadcast of an
 521      * input scalar
 522      */
 523     public abstract ShortVector mul(short s);
 524 
 525     @Override
 526     public abstract ShortVector mul(Vector<Short> v, VectorMask<Short> m);
 527 
 528     /**
 529      * Multiplies this vector with the broadcast of an input scalar, selecting
 530      * lane elements controlled by a mask.
 531      * <p>
 532      * This is a vector binary operation where the primitive multiplication
 533      * operation ({@code *}) is applied to lane elements.
 534      *
 535      * @param s the input scalar
 536      * @param m the mask controlling lane selection
 537      * @return the result of multiplying this vector with the broadcast of an
 538      * input scalar
 539      */
 540     public abstract ShortVector mul(short s, VectorMask<Short> m);
 541 
 542     @Override
 543     public abstract ShortVector neg();
 544 
 545     @Override
 546     public abstract ShortVector neg(VectorMask<Short> m);
 547 
 548     @Override
 549     public abstract ShortVector abs();
 550 
 551     @Override
 552     public abstract ShortVector abs(VectorMask<Short> m);
 553 
 554     @Override
 555     public abstract ShortVector min(Vector<Short> v);
 556 
 557     @Override
 558     public abstract ShortVector min(Vector<Short> v, VectorMask<Short> m);
 559 
 560     /**
 561      * Returns the minimum of this vector and the broadcast of an input scalar.
 562      * <p>
 563      * This is a vector binary operation where the operation
 564      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements.
 565      *
 566      * @param s the input scalar
 567      * @return the minimum of this vector and the broadcast of an input scalar
 568      */
 569     public abstract ShortVector min(short s);
 570 
 571     @Override
 572     public abstract ShortVector max(Vector<Short> v);
 573 
 574     @Override
 575     public abstract ShortVector max(Vector<Short> v, VectorMask<Short> m);
 576 
 577     /**
 578      * Returns the maximum of this vector and the broadcast of an input scalar.
 579      * <p>
 580      * This is a vector binary operation where the operation
 581      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements.
 582      *
 583      * @param s the input scalar
 584      * @return the maximum of this vector and the broadcast of an input scalar
 585      */
 586     public abstract ShortVector max(short s);
 587 
 588     @Override
 589     public abstract VectorMask<Short> equal(Vector<Short> v);
 590 
 591     /**
 592      * Tests if this vector is equal to the broadcast of an input scalar.
 593      * <p>
 594      * This is a vector binary test operation where the primitive equals
 595      * operation ({@code ==}) is applied to lane elements.
 596      *
 597      * @param s the input scalar
 598      * @return the result mask of testing if this vector is equal to the
 599      * broadcast of an input scalar
 600      */
 601     public abstract VectorMask<Short> equal(short s);
 602 
 603     @Override
 604     public abstract VectorMask<Short> notEqual(Vector<Short> v);
 605 
 606     /**
 607      * Tests if this vector is not equal to the broadcast of an input scalar.
 608      * <p>
 609      * This is a vector binary test operation where the primitive not equals
 610      * operation ({@code !=}) is applied to lane elements.
 611      *
 612      * @param s the input scalar
 613      * @return the result mask of testing if this vector is not equal to the
 614      * broadcast of an input scalar
 615      */
 616     public abstract VectorMask<Short> notEqual(short s);
 617 
 618     @Override
 619     public abstract VectorMask<Short> lessThan(Vector<Short> v);
 620 
 621     /**
 622      * Tests if this vector is less than the broadcast of an input scalar.
 623      * <p>
 624      * This is a vector binary test operation where the primitive less than
 625      * operation ({@code <}) is applied to lane elements.
 626      *
 627      * @param s the input scalar
 628      * @return the mask result of testing if this vector is less than the
 629      * broadcast of an input scalar
 630      */
 631     public abstract VectorMask<Short> lessThan(short s);
 632 
 633     @Override
 634     public abstract VectorMask<Short> lessThanEq(Vector<Short> v);
 635 
 636     /**
 637      * Tests if this vector is less or equal to the broadcast of an input scalar.
 638      * <p>
 639      * This is a vector binary test operation where the primitive less than
 640      * or equal to operation ({@code <=}) is applied to lane elements.
 641      *
 642      * @param s the input scalar
 643      * @return the mask result of testing if this vector is less than or equal
 644      * to the broadcast of an input scalar
 645      */
 646     public abstract VectorMask<Short> lessThanEq(short s);
 647 
 648     @Override
 649     public abstract VectorMask<Short> greaterThan(Vector<Short> v);
 650 
 651     /**
 652      * Tests if this vector is greater than the broadcast of an input scalar.
 653      * <p>
 654      * This is a vector binary test operation where the primitive greater than
 655      * operation ({@code >}) is applied to lane elements.
 656      *
 657      * @param s the input scalar
 658      * @return the mask result of testing if this vector is greater than the
 659      * broadcast of an input scalar
 660      */
 661     public abstract VectorMask<Short> greaterThan(short s);
 662 
 663     @Override
 664     public abstract VectorMask<Short> greaterThanEq(Vector<Short> v);
 665 
 666     /**
 667      * Tests if this vector is greater than or equal to the broadcast of an
 668      * input scalar.
 669      * <p>
 670      * This is a vector binary test operation where the primitive greater than
 671      * or equal to operation ({@code >=}) is applied to lane elements.
 672      *
 673      * @param s the input scalar
 674      * @return the mask result of testing if this vector is greater than or
 675      * equal to the broadcast of an input scalar
 676      */
 677     public abstract VectorMask<Short> greaterThanEq(short s);
 678 
 679     @Override
 680     public abstract ShortVector blend(Vector<Short> v, VectorMask<Short> m);
 681 
 682     /**
 683      * Blends the lane elements of this vector with those of the broadcast of an
 684      * input scalar, selecting lanes controlled by a mask.
 685      * <p>
 686      * For each lane of the mask, at lane index {@code N}, if the mask lane
 687      * is set then the lane element at {@code N} from the input vector is
 688      * selected and placed into the resulting vector at {@code N},
 689      * otherwise the the lane element at {@code N} from this input vector is
 690      * selected and placed into the resulting vector at {@code N}.
 691      *
 692      * @param s the input scalar
 693      * @param m the mask controlling lane selection
 694      * @return the result of blending the lane elements of this vector with
 695      * those of the broadcast of an input scalar
 696      */
 697     public abstract ShortVector blend(short s, VectorMask<Short> m);
 698 
 699     @Override
 700     public abstract ShortVector rearrange(Vector<Short> v,
 701                                                       VectorShuffle<Short> s, VectorMask<Short> m);
 702 
 703     @Override
 704     public abstract ShortVector rearrange(VectorShuffle<Short> m);
 705 
 706     @Override
 707     public abstract ShortVector reshape(VectorSpecies<Short> s);
 708 
 709     @Override
 710     public abstract ShortVector rotateEL(int i);
 711 
 712     @Override
 713     public abstract ShortVector rotateER(int i);
 714 
 715     @Override
 716     public abstract ShortVector shiftEL(int i);
 717 
 718     @Override
 719     public abstract ShortVector shiftER(int i);
 720 
 721 
 722 
 723     /**
 724      * Bitwise ANDs this vector with an input vector.
 725      * <p>
 726      * This is a vector binary operation where the primitive bitwise AND
 727      * operation ({@code &}) is applied to lane elements.


 737      * This is a vector binary operation where the primitive bitwise AND
 738      * operation ({@code &}) is applied to lane elements.
 739      *
 740      * @param s the input scalar
 741      * @return the bitwise AND of this vector with the broadcast of an input
 742      * scalar
 743      */
 744     public abstract ShortVector and(short s);
 745 
 746     /**
 747      * Bitwise ANDs this vector with an input vector, selecting lane elements
 748      * controlled by a mask.
 749      * <p>
 750      * This is a vector binary operation where the primitive bitwise AND
 751      * operation ({@code &}) is applied to lane elements.
 752      *
 753      * @param v the input vector
 754      * @param m the mask controlling lane selection
 755      * @return the bitwise AND of this vector with the input vector
 756      */
 757     public abstract ShortVector and(Vector<Short> v, VectorMask<Short> m);
 758 
 759     /**
 760      * Bitwise ANDs this vector with the broadcast of an input scalar, selecting
 761      * lane elements controlled by a mask.
 762      * <p>
 763      * This is a vector binary operation where the primitive bitwise AND
 764      * operation ({@code &}) is applied to lane elements.
 765      *
 766      * @param s the input scalar
 767      * @param m the mask controlling lane selection
 768      * @return the bitwise AND of this vector with the broadcast of an input
 769      * scalar
 770      */
 771     public abstract ShortVector and(short s, VectorMask<Short> m);
 772 
 773     /**
 774      * Bitwise ORs this vector with an input vector.
 775      * <p>
 776      * This is a vector binary operation where the primitive bitwise OR
 777      * operation ({@code |}) is applied to lane elements.
 778      *
 779      * @param v the input vector
 780      * @return the bitwise OR of this vector with the input vector
 781      */
 782     public abstract ShortVector or(Vector<Short> v);
 783 
 784     /**
 785      * Bitwise ORs this vector with the broadcast of an input scalar.
 786      * <p>
 787      * This is a vector binary operation where the primitive bitwise OR
 788      * operation ({@code |}) is applied to lane elements.
 789      *
 790      * @param s the input scalar
 791      * @return the bitwise OR of this vector with the broadcast of an input
 792      * scalar
 793      */
 794     public abstract ShortVector or(short s);
 795 
 796     /**
 797      * Bitwise ORs this vector with an input vector, selecting lane elements
 798      * controlled by a mask.
 799      * <p>
 800      * This is a vector binary operation where the primitive bitwise OR
 801      * operation ({@code |}) is applied to lane elements.
 802      *
 803      * @param v the input vector
 804      * @param m the mask controlling lane selection
 805      * @return the bitwise OR of this vector with the input vector
 806      */
 807     public abstract ShortVector or(Vector<Short> v, VectorMask<Short> m);
 808 
 809     /**
 810      * Bitwise ORs this vector with the broadcast of an input scalar, selecting
 811      * lane elements controlled by a mask.
 812      * <p>
 813      * This is a vector binary operation where the primitive bitwise OR
 814      * operation ({@code |}) is applied to lane elements.
 815      *
 816      * @param s the input scalar
 817      * @param m the mask controlling lane selection
 818      * @return the bitwise OR of this vector with the broadcast of an input
 819      * scalar
 820      */
 821     public abstract ShortVector or(short s, VectorMask<Short> m);
 822 
 823     /**
 824      * Bitwise XORs this vector with an input vector.
 825      * <p>
 826      * This is a vector binary operation where the primitive bitwise XOR
 827      * operation ({@code ^}) is applied to lane elements.
 828      *
 829      * @param v the input vector
 830      * @return the bitwise XOR of this vector with the input vector
 831      */
 832     public abstract ShortVector xor(Vector<Short> v);
 833 
 834     /**
 835      * Bitwise XORs this vector with the broadcast of an input scalar.
 836      * <p>
 837      * This is a vector binary operation where the primitive bitwise XOR
 838      * operation ({@code ^}) is applied to lane elements.
 839      *
 840      * @param s the input scalar
 841      * @return the bitwise XOR of this vector with the broadcast of an input
 842      * scalar
 843      */
 844     public abstract ShortVector xor(short s);
 845 
 846     /**
 847      * Bitwise XORs this vector with an input vector, selecting lane elements
 848      * controlled by a mask.
 849      * <p>
 850      * This is a vector binary operation where the primitive bitwise XOR
 851      * operation ({@code ^}) is applied to lane elements.
 852      *
 853      * @param v the input vector
 854      * @param m the mask controlling lane selection
 855      * @return the bitwise XOR of this vector with the input vector
 856      */
 857     public abstract ShortVector xor(Vector<Short> v, VectorMask<Short> m);
 858 
 859     /**
 860      * Bitwise XORs this vector with the broadcast of an input scalar, selecting
 861      * lane elements controlled by a mask.
 862      * <p>
 863      * This is a vector binary operation where the primitive bitwise XOR
 864      * operation ({@code ^}) is applied to lane elements.
 865      *
 866      * @param s the input scalar
 867      * @param m the mask controlling lane selection
 868      * @return the bitwise XOR of this vector with the broadcast of an input
 869      * scalar
 870      */
 871     public abstract ShortVector xor(short s, VectorMask<Short> m);
 872 
 873     /**
 874      * Bitwise NOTs this vector.
 875      * <p>
 876      * This is a vector unary operation where the primitive bitwise NOT
 877      * operation ({@code ~}) is applied to lane elements.
 878      *
 879      * @return the bitwise NOT of this vector
 880      */
 881     public abstract ShortVector not();
 882 
 883     /**
 884      * Bitwise NOTs this vector, selecting lane elements controlled by a mask.
 885      * <p>
 886      * This is a vector unary operation where the primitive bitwise NOT
 887      * operation ({@code ~}) is applied to lane elements.
 888      *
 889      * @param m the mask controlling lane selection
 890      * @return the bitwise NOT of this vector
 891      */
 892     public abstract ShortVector not(VectorMask<Short> m);
 893 
 894     /**
 895      * Logically left shifts this vector by the broadcast of an input scalar.
 896      * <p>
 897      * This is a vector binary operation where the primitive logical left shift
 898      * operation ({@code <<}) is applied to lane elements to left shift the
 899      * element by shift value as specified by the input scalar. Only the 4
 900      * lowest-order bits of shift value are used. It is as if the shift value
 901      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
 902      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 903      *
 904      * @param s the input scalar; the number of the bits to left shift
 905      * @return the result of logically left shifting left this vector by the
 906      * broadcast of an input scalar
 907      */
 908     public abstract ShortVector shiftL(int s);
 909 
 910     /**
 911      * Logically left shifts this vector by the broadcast of an input scalar,
 912      * selecting lane elements controlled by a mask.
 913      * <p>
 914      * This is a vector binary operation where the primitive logical left shift
 915      * operation ({@code <<}) is applied to lane elements to left shift the
 916      * element by shift value as specified by the input scalar. Only the 4
 917      * lowest-order bits of shift value are used. It is as if the shift value
 918      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
 919      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 920      *
 921      * @param s the input scalar; the number of the bits to left shift
 922      * @param m the mask controlling lane selection
 923      * @return the result of logically left shifting left this vector by the
 924      * broadcast of an input scalar
 925      */
 926     public abstract ShortVector shiftL(int s, VectorMask<Short> m);
 927 
 928 
 929     // logical, or unsigned, shift right
 930 
 931      /**
 932      * Logically right shifts (or unsigned right shifts) this vector by the
 933      * broadcast of an input scalar.
 934      * <p>
 935      * This is a vector binary operation where the primitive logical right shift
 936      * operation ({@code >>>}) is applied to lane elements to logically right shift the
 937      * element by shift value as specified by the input scalar. Only the 4
 938      * lowest-order bits of shift value are used. It is as if the shift value
 939      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
 940      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 941      *
 942      * @param s the input scalar; the number of the bits to right shift
 943      * @return the result of logically right shifting this vector by the
 944      * broadcast of an input scalar
 945      */
 946     public abstract ShortVector shiftR(int s);
 947 
 948      /**
 949      * Logically right shifts (or unsigned right shifts) this vector by the
 950      * broadcast of an input scalar, selecting lane elements controlled by a
 951      * mask.
 952      * <p>
 953      * This is a vector binary operation where the primitive logical right shift
 954      * operation ({@code >>>}) is applied to lane elements to logically right shift the
 955      * element by shift value as specified by the input scalar. Only the 4
 956      * lowest-order bits of shift value are used. It is as if the shift value
 957      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
 958      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 959      *
 960      * @param s the input scalar; the number of the bits to right shift
 961      * @param m the mask controlling lane selection
 962      * @return the result of logically right shifting this vector by the
 963      * broadcast of an input scalar
 964      */
 965     public abstract ShortVector shiftR(int s, VectorMask<Short> m);
 966 
 967 
 968     /**
 969      * Arithmetically right shifts (or signed right shifts) this vector by the
 970      * broadcast of an input scalar.
 971      * <p>
 972      * This is a vector binary operation where the primitive arithmetic right
 973      * shift operation ({@code >>}) is applied to lane elements  to arithmetically
 974      * right shift the element by shift value as specified by the input scalar.
 975      * Only the 4 lowest-order bits of shift value are used. It is as if the shift
 976      * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
 977      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 978      *
 979      * @param s the input scalar; the number of the bits to right shift
 980      * @return the result of arithmetically right shifting this vector by the
 981      * broadcast of an input scalar
 982      */
 983     public abstract ShortVector aShiftR(int s);
 984 
 985     /**
 986      * Arithmetically right shifts (or signed right shifts) this vector by the
 987      * broadcast of an input scalar, selecting lane elements controlled by a
 988      * mask.
 989      * <p>
 990      * This is a vector binary operation where the primitive arithmetic right
 991      * shift operation ({@code >>}) is applied to lane elements  to arithmetically
 992      * right shift the element by shift value as specified by the input scalar.
 993      * Only the 4 lowest-order bits of shift value are used. It is as if the shift
 994      * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
 995      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 996      *
 997      * @param s the input scalar; the number of the bits to right shift
 998      * @param m the mask controlling lane selection
 999      * @return the result of arithmetically right shifting this vector by the
1000      * broadcast of an input scalar
1001      */
1002     public abstract ShortVector aShiftR(int s, VectorMask<Short> m);
1003 
1004 
1005     @Override
1006     public abstract void intoByteArray(byte[] a, int ix);
1007 
1008     @Override
1009     public abstract void intoByteArray(byte[] a, int ix, VectorMask<Short> m);
1010 
1011     @Override
1012     public abstract void intoByteBuffer(ByteBuffer bb, int ix);
1013 
1014     @Override
1015     public abstract void intoByteBuffer(ByteBuffer bb, int ix, VectorMask<Short> m);
1016 
1017 
1018     // Type specific horizontal reductions
1019     /**
1020      * Adds all lane elements of this vector.
1021      * <p>
1022      * This is an associative vector reduction operation where the addition
1023      * operation ({@code +}) is applied to lane elements,
1024      * and the identity value is {@code 0}.
1025      *
1026      * @return the addition of all the lane elements of this vector
1027      */
1028     public abstract short addAll();
1029 
1030     /**
1031      * Adds all lane elements of this vector, selecting lane elements
1032      * controlled by a mask.
1033      * <p>
1034      * This is an associative vector reduction operation where the addition
1035      * operation ({@code +}) is applied to lane elements,
1036      * and the identity value is {@code 0}.
1037      *
1038      * @param m the mask controlling lane selection
1039      * @return the addition of the selected lane elements of this vector
1040      */
1041     public abstract short addAll(VectorMask<Short> m);
1042 
1043     /**
1044      * Multiplies all lane elements of this vector.
1045      * <p>
1046      * This is an associative vector reduction operation where the
1047      * multiplication operation ({@code *}) is applied to lane elements,
1048      * and the identity value is {@code 1}.
1049      *
1050      * @return the multiplication of all the lane elements of this vector
1051      */
1052     public abstract short mulAll();
1053 
1054     /**
1055      * Multiplies all lane elements of this vector, selecting lane elements
1056      * controlled by a mask.
1057      * <p>
1058      * This is an associative vector reduction operation where the
1059      * multiplication operation ({@code *}) is applied to lane elements,
1060      * and the identity value is {@code 1}.
1061      *
1062      * @param m the mask controlling lane selection
1063      * @return the multiplication of all the lane elements of this vector
1064      */
1065     public abstract short mulAll(VectorMask<Short> m);
1066 
1067     /**
1068      * Returns the minimum lane element of this vector.
1069      * <p>
1070      * This is an associative vector reduction operation where the operation
1071      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1072      * and the identity value is
1073      * {@link Short#MAX_VALUE}.
1074      *
1075      * @return the minimum lane element of this vector
1076      */
1077     public abstract short minAll();
1078 
1079     /**
1080      * Returns the minimum lane element of this vector, selecting lane elements
1081      * controlled by a mask.
1082      * <p>
1083      * This is an associative vector reduction operation where the operation
1084      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1085      * and the identity value is
1086      * {@link Short#MAX_VALUE}.
1087      *
1088      * @param m the mask controlling lane selection
1089      * @return the minimum lane element of this vector
1090      */
1091     public abstract short minAll(VectorMask<Short> m);
1092 
1093     /**
1094      * Returns the maximum lane element of this vector.
1095      * <p>
1096      * This is an associative vector reduction operation where the operation
1097      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1098      * and the identity value is
1099      * {@link Short#MIN_VALUE}.
1100      *
1101      * @return the maximum lane element of this vector
1102      */
1103     public abstract short maxAll();
1104 
1105     /**
1106      * Returns the maximum lane element of this vector, selecting lane elements
1107      * controlled by a mask.
1108      * <p>
1109      * This is an associative vector reduction operation where the operation
1110      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1111      * and the identity value is
1112      * {@link Short#MIN_VALUE}.
1113      *
1114      * @param m the mask controlling lane selection
1115      * @return the maximum lane element of this vector
1116      */
1117     public abstract short maxAll(VectorMask<Short> m);
1118 
1119     /**
1120      * Logically ORs all lane elements of this vector.
1121      * <p>
1122      * This is an associative vector reduction operation where the logical OR
1123      * operation ({@code |}) is applied to lane elements,
1124      * and the identity value is {@code 0}.
1125      *
1126      * @return the logical OR all the lane elements of this vector
1127      */
1128     public abstract short orAll();
1129 
1130     /**
1131      * Logically ORs all lane elements of this vector, selecting lane elements
1132      * controlled by a mask.
1133      * <p>
1134      * This is an associative vector reduction operation where the logical OR
1135      * operation ({@code |}) is applied to lane elements,
1136      * and the identity value is {@code 0}.
1137      *
1138      * @param m the mask controlling lane selection
1139      * @return the logical OR all the lane elements of this vector
1140      */
1141     public abstract short orAll(VectorMask<Short> m);
1142 
1143     /**
1144      * Logically ANDs all lane elements of this vector.
1145      * <p>
1146      * This is an associative vector reduction operation where the logical AND
1147      * operation ({@code |}) is applied to lane elements,
1148      * and the identity value is {@code -1}.
1149      *
1150      * @return the logical AND all the lane elements of this vector
1151      */
1152     public abstract short andAll();
1153 
1154     /**
1155      * Logically ANDs all lane elements of this vector, selecting lane elements
1156      * controlled by a mask.
1157      * <p>
1158      * This is an associative vector reduction operation where the logical AND
1159      * operation ({@code |}) is applied to lane elements,
1160      * and the identity value is {@code -1}.
1161      *
1162      * @param m the mask controlling lane selection
1163      * @return the logical AND all the lane elements of this vector
1164      */
1165     public abstract short andAll(VectorMask<Short> m);
1166 
1167     /**
1168      * Logically XORs all lane elements of this vector.
1169      * <p>
1170      * This is an associative vector reduction operation where the logical XOR
1171      * operation ({@code ^}) is applied to lane elements,
1172      * and the identity value is {@code 0}.
1173      *
1174      * @return the logical XOR all the lane elements of this vector
1175      */
1176     public abstract short xorAll();
1177 
1178     /**
1179      * Logically XORs all lane elements of this vector, selecting lane elements
1180      * controlled by a mask.
1181      * <p>
1182      * This is an associative vector reduction operation where the logical XOR
1183      * operation ({@code ^}) is applied to lane elements,
1184      * and the identity value is {@code 0}.
1185      *
1186      * @param m the mask controlling lane selection
1187      * @return the logical XOR all the lane elements of this vector
1188      */
1189     public abstract short xorAll(VectorMask<Short> m);
1190 
1191     // Type specific accessors
1192 
1193     /**
1194      * Gets the lane element at lane index {@code i}
1195      *
1196      * @param i the lane index
1197      * @return the lane element at lane index {@code i}
1198      * @throws IllegalArgumentException if the index is is out of range
1199      * ({@code < 0 || >= length()})
1200      */
1201     public abstract short get(int i);
1202 
1203     /**
1204      * Replaces the lane element of this vector at lane index {@code i} with
1205      * value {@code e}.
1206      * <p>
1207      * This is a cross-lane operation and behaves as if it returns the result
1208      * of blending this vector with an input vector that is the result of
1209      * broadcasting {@code e} and a mask that has only one lane set at lane


1251      * @param i the offset into the array
1252      * @throws IndexOutOfBoundsException if {@code i < 0}, or
1253      * {@code i > a.length - this.length()}
1254      */
1255     public abstract void intoArray(short[] a, int i);
1256 
1257     /**
1258      * Stores this vector into an array starting at offset and using a mask.
1259      * <p>
1260      * For each vector lane, where {@code N} is the vector lane index,
1261      * if the mask lane at index {@code N} is set then the lane element at
1262      * index {@code N} is stored into the array index {@code i + N}.
1263      *
1264      * @param a the array
1265      * @param i the offset into the array
1266      * @param m the mask
1267      * @throws IndexOutOfBoundsException if {@code i < 0}, or
1268      * for any vector lane index {@code N} where the mask at lane {@code N}
1269      * is set {@code i >= a.length - N}
1270      */
1271     public abstract void intoArray(short[] a, int i, VectorMask<Short> m);
1272 
1273     /**
1274      * Stores this vector into an array using indexes obtained from an index
1275      * map.
1276      * <p>
1277      * For each vector lane, where {@code N} is the vector lane index, the
1278      * lane element at index {@code N} is stored into the array at index
1279      * {@code i + indexMap[j + N]}.
1280      *
1281      * @param a the array
1282      * @param i the offset into the array, may be negative if relative
1283      * indexes in the index map compensate to produce a value within the
1284      * array bounds
1285      * @param indexMap the index map
1286      * @param j the offset into the index map
1287      * @throws IndexOutOfBoundsException if {@code j < 0}, or
1288      * {@code j > indexMap.length - this.length()},
1289      * or for any vector lane index {@code N} the result of
1290      * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
1291      */


1298      * map and using a mask.
1299      * <p>
1300      * For each vector lane, where {@code N} is the vector lane index,
1301      * if the mask lane at index {@code N} is set then the lane element at
1302      * index {@code N} is stored into the array at index
1303      * {@code i + indexMap[j + N]}.
1304      *
1305      * @param a the array
1306      * @param i the offset into the array, may be negative if relative
1307      * indexes in the index map compensate to produce a value within the
1308      * array bounds
1309      * @param m the mask
1310      * @param indexMap the index map
1311      * @param j the offset into the index map
1312      * @throws IndexOutOfBoundsException if {@code j < 0}, or
1313      * {@code j > indexMap.length - this.length()},
1314      * or for any vector lane index {@code N} where the mask at lane
1315      * {@code N} is set the result of {@code i + indexMap[j + N]} is
1316      * {@code < 0} or {@code >= a.length}
1317      */
1318     public void intoArray(short[] a, int i, VectorMask<Short> m, int[] indexMap, int j) {
1319         forEach(m, (n, e) -> a[i + indexMap[j + n]] = e);
1320     }
1321     // Species
1322 
1323     @Override
1324     public abstract VectorSpecies<Short> species();
1325 
1326     /**
1327      * Class representing {@link ShortVector}'s of the same {@link VectorShape VectorShape}.
1328      */
1329     static final class ShortSpecies extends AbstractSpecies<Short> {
1330         final Function<short[], ShortVector> vectorFactory;

1331 
1332         private ShortSpecies(VectorShape shape,
1333                           Class<?> boxType,
1334                           Class<?> maskType,
1335                           Function<short[], ShortVector> vectorFactory,
1336                           Function<boolean[], VectorMask<Short>> maskFactory,
1337                           Function<IntUnaryOperator, VectorShuffle<Short>> shuffleFromArrayFactory,
1338                           fShuffleFromArray<Short> shuffleFromOpFactory) {
1339             super(shape, short.class, Short.SIZE, boxType, maskType, maskFactory,
1340                   shuffleFromArrayFactory, shuffleFromOpFactory);
1341             this.vectorFactory = vectorFactory;

1342         }
1343 
1344         interface FOp {
1345             short apply(int i);
1346         }
1347 




1348         ShortVector op(FOp f) {
1349             short[] res = new short[length()];
1350             for (int i = 0; i < length(); i++) {
1351                 res[i] = f.apply(i);
1352             }
1353             return vectorFactory.apply(res);
1354         }
1355 
1356         ShortVector op(VectorMask<Short> o, FOp f) {
1357             short[] res = new short[length()];
1358             boolean[] mbits = ((AbstractMask<Short>)o).getBits();
1359             for (int i = 0; i < length(); i++) {
1360                 if (mbits[i]) {
1361                     res[i] = f.apply(i);
1362                 }
1363             }
1364             return vectorFactory.apply(res);
1365         }








1366     }
1367 
1368     /**
1369      * Finds the preferred species for an element type of {@code short}.
1370      * <p>
1371      * A preferred species is a species chosen by the platform that has a
1372      * shape of maximal bit size.  A preferred species for different element
1373      * types will have the same shape, and therefore vectors, masks, and
1374      * shuffles created from such species will be shape compatible.
1375      *
1376      * @return the preferred species for an element type of {@code short}
1377      */
1378     private static ShortSpecies preferredSpecies() {
1379         return (ShortSpecies) VectorSpecies.ofPreferred(short.class);
1380     }
1381 
1382     /**
1383      * Finds a species for an element type of {@code short} and shape.
1384      *
1385      * @param s the shape
1386      * @return a species for an element type of {@code short} and shape
1387      * @throws IllegalArgumentException if no such species exists for the shape
1388      */
1389     static ShortSpecies species(VectorShape s) {
1390         Objects.requireNonNull(s);
1391         switch (s) {
1392             case S_64_BIT: return (ShortSpecies) SPECIES_64;
1393             case S_128_BIT: return (ShortSpecies) SPECIES_128;
1394             case S_256_BIT: return (ShortSpecies) SPECIES_256;
1395             case S_512_BIT: return (ShortSpecies) SPECIES_512;
1396             case S_Max_BIT: return (ShortSpecies) SPECIES_MAX;
1397             default: throw new IllegalArgumentException("Bad shape: " + s);
1398         }
1399     }
1400 
1401     /** Species representing {@link ShortVector}s of {@link VectorShape#S_64_BIT VectorShape.S_64_BIT}. */
1402     public static final VectorSpecies<Short> SPECIES_64 = new ShortSpecies(VectorShape.S_64_BIT, Short64Vector.class, Short64Vector.Short64Mask.class,
1403                                                                      Short64Vector::new, Short64Vector.Short64Mask::new,
1404                                                                      Short64Vector.Short64Shuffle::new, Short64Vector.Short64Shuffle::new);
1405 
1406     /** Species representing {@link ShortVector}s of {@link VectorShape#S_128_BIT VectorShape.S_128_BIT}. */
1407     public static final VectorSpecies<Short> SPECIES_128 = new ShortSpecies(VectorShape.S_128_BIT, Short128Vector.class, Short128Vector.Short128Mask.class,
1408                                                                       Short128Vector::new, Short128Vector.Short128Mask::new,
1409                                                                       Short128Vector.Short128Shuffle::new, Short128Vector.Short128Shuffle::new);
1410 
1411     /** Species representing {@link ShortVector}s of {@link VectorShape#S_256_BIT VectorShape.S_256_BIT}. */
1412     public static final VectorSpecies<Short> SPECIES_256 = new ShortSpecies(VectorShape.S_256_BIT, Short256Vector.class, Short256Vector.Short256Mask.class,
1413                                                                       Short256Vector::new, Short256Vector.Short256Mask::new,
1414                                                                       Short256Vector.Short256Shuffle::new, Short256Vector.Short256Shuffle::new);
1415 
1416     /** Species representing {@link ShortVector}s of {@link VectorShape#S_512_BIT VectorShape.S_512_BIT}. */
1417     public static final VectorSpecies<Short> SPECIES_512 = new ShortSpecies(VectorShape.S_512_BIT, Short512Vector.class, Short512Vector.Short512Mask.class,
1418                                                                       Short512Vector::new, Short512Vector.Short512Mask::new,
1419                                                                       Short512Vector.Short512Shuffle::new, Short512Vector.Short512Shuffle::new);
1420 
1421     /** Species representing {@link ShortVector}s of {@link VectorShape#S_Max_BIT VectorShape.S_Max_BIT}. */
1422     public static final VectorSpecies<Short> SPECIES_MAX = new ShortSpecies(VectorShape.S_Max_BIT, ShortMaxVector.class, ShortMaxVector.ShortMaxMask.class,
1423                                                                       ShortMaxVector::new, ShortMaxVector.ShortMaxMask::new,
1424                                                                       ShortMaxVector.ShortMaxShuffle::new, ShortMaxVector.ShortMaxShuffle::new);
1425 
1426     /**
1427      * Preferred species for {@link ShortVector}s.
1428      * A preferred species is a species of maximal bit size for the platform.
1429      */
1430     public static final VectorSpecies<Short> SPECIES_PREFERRED = (VectorSpecies<Short>) preferredSpecies();
1431 }
< prev index next >