< prev index next >

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

Print this page
rev 55237 : javadoc changes


  88     }
  89 
  90     abstract Mask<Short> bTest(Vector<Short> v, FBinTest f);
  91 
  92     // Foreach
  93 
  94     interface FUnCon {
  95         void apply(int i, short a);
  96     }
  97 
  98     abstract void forEach(FUnCon f);
  99 
 100     abstract void forEach(Mask<Short> m, FUnCon f);
 101 
 102     // Static factories
 103 
 104     /**
 105      * Returns a vector where all lane elements are set to the default
 106      * primitive value.
 107      *
 108      * @return a zero vector

 109      */
 110     @ForceInline
 111     @SuppressWarnings("unchecked")
 112     public static ShortVector zero(ShortSpecies species) {
 113         return species.zero();
 114     }
 115 
 116     /**
 117      * Loads a vector from a byte array starting at an offset.
 118      * <p>
 119      * Bytes are composed into primitive lane elements according to the
 120      * native byte order of the underlying platform
 121      * <p>
 122      * This method behaves as if it returns the result of calling the
 123      * byte buffer, offset, and mask accepting
 124      * {@link #fromByteBuffer(ShortSpecies, ByteBuffer, int, Mask) method} as follows:
 125      * <pre>{@code
 126      * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue());
 127      * }</pre>
 128      *

 129      * @param a the byte array
 130      * @param ix the offset into the array
 131      * @return a vector loaded from a byte array
 132      * @throws IndexOutOfBoundsException if {@code i < 0} or
 133      * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
 134      */
 135     @ForceInline
 136     @SuppressWarnings("unchecked")
 137     public static ShortVector fromByteArray(ShortSpecies species, byte[] a, int ix) {
 138         Objects.requireNonNull(a);
 139         ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE);
 140         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 141                                      a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 142                                      a, ix, species,
 143                                      (c, idx, s) -> {
 144                                          ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
 145                                          ShortBuffer tb = bbc.asShortBuffer();
 146                                          return ((ShortSpecies)s).op(i -> tb.get());
 147                                      });
 148     }
 149 
 150     /**
 151      * Loads a vector from a byte array starting at an offset and using a
 152      * mask.
 153      * <p>
 154      * Bytes are composed into primitive lane elements according to the
 155      * native byte order of the underlying platform.
 156      * <p>
 157      * This method behaves as if it returns the result of calling the
 158      * byte buffer, offset, and mask accepting
 159      * {@link #fromByteBuffer(ShortSpecies, ByteBuffer, int, Mask) method} as follows:
 160      * <pre>{@code
 161      * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m);
 162      * }</pre>
 163      *

 164      * @param a the byte array
 165      * @param ix the offset into the array
 166      * @param m the mask
 167      * @return a vector loaded from a byte array
 168      * @throws IndexOutOfBoundsException if {@code i < 0} or
 169      * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
 170      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 171      * or {@code > a.length},
 172      * for any vector lane index {@code N} where the mask at lane {@code N}
 173      * is set
 174      * {@code i >= a.length - (N * this.elementSize() / Byte.SIZE)}
 175      */
 176     @ForceInline
 177     public static ShortVector fromByteArray(ShortSpecies species, byte[] a, int ix, Mask<Short> m) {
 178         return zero(species).blend(fromByteArray(species, a, ix), m);
 179     }
 180 
 181     /**
 182      * Loads a vector from an array starting at offset.
 183      * <p>
 184      * For each vector lane, where {@code N} is the vector lane index, the
 185      * array element at index {@code i + N} is placed into the
 186      * resulting vector at lane index {@code N}.
 187      *

 188      * @param a the array
 189      * @param i the offset into the array
 190      * @return the vector loaded from an array
 191      * @throws IndexOutOfBoundsException if {@code i < 0}, or
 192      * {@code i > a.length - this.length()}
 193      */
 194     @ForceInline
 195     @SuppressWarnings("unchecked")
 196     public static ShortVector fromArray(ShortSpecies species, short[] a, int i){
 197         Objects.requireNonNull(a);
 198         i = VectorIntrinsics.checkIndex(i, a.length, species.length());
 199         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 200                                      a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
 201                                      a, i, species,
 202                                      (c, idx, s) -> ((ShortSpecies)s).op(n -> c[idx + n]));
 203     }
 204 
 205 
 206     /**
 207      * Loads a vector from an array starting at offset and using a mask.
 208      * <p>
 209      * For each vector lane, where {@code N} is the vector lane index,
 210      * if the mask lane at index {@code N} is set then the array element at
 211      * index {@code i + N} is placed into the resulting vector at lane index
 212      * {@code N}, otherwise the default element value is placed into the
 213      * resulting vector at lane index {@code N}.
 214      *

 215      * @param a the array
 216      * @param i the offset into the array
 217      * @param m the mask
 218      * @return the vector loaded from an array
 219      * @throws IndexOutOfBoundsException if {@code i < 0}, or
 220      * for any vector lane index {@code N} where the mask at lane {@code N}
 221      * is set {@code i > a.length - N}
 222      */
 223     @ForceInline
 224     public static ShortVector fromArray(ShortSpecies species, short[] a, int i, Mask<Short> m) {
 225         return zero(species).blend(fromArray(species, a, i), m);
 226     }
 227 
 228     /**
 229      * Loads a vector from an array using indexes obtained from an index
 230      * map.
 231      * <p>
 232      * For each vector lane, where {@code N} is the vector lane index, the
 233      * array element at index {@code i + indexMap[j + N]} is placed into the
 234      * resulting vector at lane index {@code N}.
 235      *

 236      * @param a the array
 237      * @param i the offset into the array, may be negative if relative
 238      * indexes in the index map compensate to produce a value within the
 239      * array bounds
 240      * @param indexMap the index map
 241      * @param j the offset into the index map
 242      * @return the vector loaded from an array
 243      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 244      * {@code j > indexMap.length - this.length()},
 245      * or for any vector lane index {@code N} the result of
 246      * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
 247      */
 248     public static ShortVector fromArray(ShortSpecies species, short[] a, int i, int[] indexMap, int j) {
 249         return species.op(n -> a[i + indexMap[j + n]]);
 250     }
 251     /**
 252      * Loads a vector from an array using indexes obtained from an index
 253      * map and using a mask.
 254      * <p>
 255      * For each vector lane, where {@code N} is the vector lane index,
 256      * if the mask lane at index {@code N} is set then the array element at
 257      * index {@code i + indexMap[j + N]} is placed into the resulting vector
 258      * at lane index {@code N}.
 259      *

 260      * @param a the array
 261      * @param i the offset into the array, may be negative if relative
 262      * indexes in the index map compensate to produce a value within the
 263      * array bounds

 264      * @param indexMap the index map
 265      * @param j the offset into the index map
 266      * @return the vector loaded from an array
 267      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 268      * {@code j > indexMap.length - this.length()},
 269      * or for any vector lane index {@code N} where the mask at lane
 270      * {@code N} is set the result of {@code i + indexMap[j + N]} is
 271      * {@code < 0} or {@code >= a.length}
 272      */
 273     public static ShortVector fromArray(ShortSpecies species, short[] a, int i, Mask<Short> m, int[] indexMap, int j) {
 274         return species.op(m, n -> a[i + indexMap[j + n]]);
 275     }
 276 
 277     /**
 278      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 279      * offset into the byte buffer.
 280      * <p>
 281      * Bytes are composed into primitive lane elements according to the
 282      * native byte order of the underlying platform.
 283      * <p>
 284      * This method behaves as if it returns the result of calling the
 285      * byte buffer, offset, and mask accepting
 286      * {@link #fromByteBuffer(ShortSpecies, ByteBuffer, int, Mask)} method} as follows:
 287      * <pre>{@code
 288      *   return this.fromByteBuffer(b, i, this.maskAllTrue())
 289      * }</pre>
 290      *

 291      * @param bb the byte buffer
 292      * @param ix the offset into the byte buffer
 293      * @return a vector loaded from a byte buffer
 294      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 295      * or {@code > b.limit()},
 296      * or if there are fewer than
 297      * {@code this.length() * this.elementSize() / Byte.SIZE} bytes
 298      * remaining in the byte buffer from the given offset
 299      */
 300     @ForceInline
 301     @SuppressWarnings("unchecked")
 302     public static ShortVector fromByteBuffer(ShortSpecies species, ByteBuffer bb, int ix) {
 303         if (bb.order() != ByteOrder.nativeOrder()) {
 304             throw new IllegalArgumentException();
 305         }
 306         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE);
 307         return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
 308                                      U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
 309                                      bb, ix, species,
 310                                      (c, idx, s) -> {


 322      * {@link java.nio.Buffer buffer} for the primitive element type,
 323      * according to the native byte order of the underlying platform, and
 324      * the returned vector is loaded with a mask from a primitive array
 325      * obtained from the primitive buffer.
 326      * The following pseudocode expresses the behaviour, where
 327      * {@coce EBuffer} is the primitive buffer type, {@code e} is the
 328      * primitive element type, and {@code ESpecies<S>} is the primitive
 329      * species for {@code e}:
 330      * <pre>{@code
 331      * EBuffer eb = b.duplicate().
 332      *     order(ByteOrder.nativeOrder()).position(i).
 333      *     asEBuffer();
 334      * e[] es = new e[this.length()];
 335      * for (int n = 0; n < t.length; n++) {
 336      *     if (m.isSet(n))
 337      *         es[n] = eb.get(n);
 338      * }
 339      * Vector<E> r = ((ESpecies<S>)this).fromArray(es, 0, m);
 340      * }</pre>
 341      *

 342      * @param bb the byte buffer
 343      * @param ix the offset into the byte buffer

 344      * @return a vector loaded from a byte buffer
 345      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 346      * or {@code > b.limit()},
 347      * for any vector lane index {@code N} where the mask at lane {@code N}
 348      * is set
 349      * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)}
 350      */
 351     @ForceInline
 352     public static ShortVector fromByteBuffer(ShortSpecies species, ByteBuffer bb, int ix, Mask<Short> m) {
 353         return zero(species).blend(fromByteBuffer(species, bb, ix), m);
 354     }
 355 













 356     @ForceInline
 357     public static Mask<Short> maskFromValues(ShortSpecies species, boolean... bits) {
 358         if (species.boxType() == ShortMaxVector.class)
 359             return new ShortMaxVector.ShortMaxMask(bits);
 360         switch (species.bitSize()) {
 361             case 64: return new Short64Vector.Short64Mask(bits);
 362             case 128: return new Short128Vector.Short128Mask(bits);
 363             case 256: return new Short256Vector.Short256Mask(bits);
 364             case 512: return new Short512Vector.Short512Mask(bits);
 365             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 366         }
 367     }
 368 
 369     // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
 370     static Mask<Short> trueMask(ShortSpecies species) {
 371         if (species.boxType() == ShortMaxVector.class)
 372             return ShortMaxVector.ShortMaxMask.TRUE_MASK;
 373         switch (species.bitSize()) {
 374             case 64: return Short64Vector.Short64Mask.TRUE_MASK;
 375             case 128: return Short128Vector.Short128Mask.TRUE_MASK;
 376             case 256: return Short256Vector.Short256Mask.TRUE_MASK;
 377             case 512: return Short512Vector.Short512Mask.TRUE_MASK;
 378             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 379         }
 380     }
 381 
 382     static Mask<Short> falseMask(ShortSpecies species) {
 383         if (species.boxType() == ShortMaxVector.class)
 384             return ShortMaxVector.ShortMaxMask.FALSE_MASK;
 385         switch (species.bitSize()) {
 386             case 64: return Short64Vector.Short64Mask.FALSE_MASK;
 387             case 128: return Short128Vector.Short128Mask.FALSE_MASK;
 388             case 256: return Short256Vector.Short256Mask.FALSE_MASK;
 389             case 512: return Short512Vector.Short512Mask.FALSE_MASK;
 390             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 391         }
 392     }
 393 














 394     @ForceInline
 395     @SuppressWarnings("unchecked")
 396     public static Mask<Short> maskFromArray(ShortSpecies species, boolean[] bits, int ix) {
 397         Objects.requireNonNull(bits);
 398         ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length());
 399         return VectorIntrinsics.load((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 400                                      bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
 401                                      bits, ix, species,
 402                                      (c, idx, s) -> (Mask<Short>) ((ShortSpecies)s).opm(n -> c[idx + n]));
 403     }
 404 






 405     @ForceInline
 406     @SuppressWarnings("unchecked")
 407     public static Mask<Short> maskAllTrue(ShortSpecies species) {
 408         return VectorIntrinsics.broadcastCoerced((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 409                                                  (short)-1,  species,
 410                                                  ((z, s) -> trueMask((ShortSpecies)s)));
 411     }
 412 






 413     @ForceInline
 414     @SuppressWarnings("unchecked")
 415     public static Mask<Short> maskAllFalse(ShortSpecies species) {
 416         return VectorIntrinsics.broadcastCoerced((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 417                                                  0, species, 
 418                                                  ((z, s) -> falseMask((ShortSpecies)s)));
 419     }
 420 
























 421     @ForceInline
 422     public static Shuffle<Short> shuffle(ShortSpecies species, IntUnaryOperator f) {
 423         if (species.boxType() == ShortMaxVector.class)
 424             return new ShortMaxVector.ShortMaxShuffle(f);
 425         switch (species.bitSize()) {
 426             case 64: return new Short64Vector.Short64Shuffle(f);
 427             case 128: return new Short128Vector.Short128Shuffle(f);
 428             case 256: return new Short256Vector.Short256Shuffle(f);
 429             case 512: return new Short512Vector.Short512Shuffle(f);
 430             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 431         }
 432     }
 433 













 434     @ForceInline
 435     public static Shuffle<Short> shuffleIota(ShortSpecies species) {
 436         if (species.boxType() == ShortMaxVector.class)
 437             return new ShortMaxVector.ShortMaxShuffle(AbstractShuffle.IDENTITY);
 438         switch (species.bitSize()) {
 439             case 64: return new Short64Vector.Short64Shuffle(AbstractShuffle.IDENTITY);
 440             case 128: return new Short128Vector.Short128Shuffle(AbstractShuffle.IDENTITY);
 441             case 256: return new Short256Vector.Short256Shuffle(AbstractShuffle.IDENTITY);
 442             case 512: return new Short512Vector.Short512Shuffle(AbstractShuffle.IDENTITY);
 443             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 444         }
 445     }
 446 
















 447     @ForceInline
 448     public static Shuffle<Short> shuffleFromValues(ShortSpecies species, int... ixs) {
 449         if (species.boxType() == ShortMaxVector.class)
 450             return new ShortMaxVector.ShortMaxShuffle(ixs);
 451         switch (species.bitSize()) {
 452             case 64: return new Short64Vector.Short64Shuffle(ixs);
 453             case 128: return new Short128Vector.Short128Shuffle(ixs);
 454             case 256: return new Short256Vector.Short256Shuffle(ixs);
 455             case 512: return new Short512Vector.Short512Shuffle(ixs);
 456             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 457         }
 458     }
 459 















 460     @ForceInline
 461     public static Shuffle<Short> shuffleFromArray(ShortSpecies species, int[] ixs, int i) {
 462         if (species.boxType() == ShortMaxVector.class)
 463             return new ShortMaxVector.ShortMaxShuffle(ixs, i);
 464         switch (species.bitSize()) {
 465             case 64: return new Short64Vector.Short64Shuffle(ixs, i);
 466             case 128: return new Short128Vector.Short128Shuffle(ixs, i);
 467             case 256: return new Short256Vector.Short256Shuffle(ixs, i);
 468             case 512: return new Short512Vector.Short512Shuffle(ixs, i);
 469             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 470         }
 471     }
 472 
 473 
 474     // Ops
 475 
 476     @Override
 477     public abstract ShortVector add(Vector<Short> v);
 478 
 479     /**


 911     public abstract ShortVector not();
 912 
 913     /**
 914      * Bitwise NOTs this vector, selecting lane elements controlled by a mask.
 915      * <p>
 916      * This is a vector unary operation where the primitive bitwise NOT
 917      * operation ({@code ~}) is applied to lane elements.
 918      *
 919      * @param m the mask controlling lane selection
 920      * @return the bitwise NOT of this vector
 921      */
 922     public abstract ShortVector not(Mask<Short> m);
 923 
 924     /**
 925      * Logically left shifts this vector by the broadcast of an input scalar.
 926      * <p>
 927      * This is a vector binary operation where the primitive logical left shift
 928      * operation ({@code <<}) is applied to lane elements to left shift the
 929      * element by shift value as specified by the input scalar. Only the 4
 930      * lowest-order bits of shift value are used. It is as if the shift value
 931      * were subjected to a bitwise logical AND operator & with the mask value 0xF.
 932      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 933      *
 934      * @param s the input scalar; the number of the bits to left shift
 935      * @return the result of logically left shifting left this vector by the
 936      * broadcast of an input scalar
 937      */
 938     public abstract ShortVector shiftL(int s);
 939 
 940     /**
 941      * Logically left shifts this vector by the broadcast of an input scalar,
 942      * selecting lane elements controlled by a mask.
 943      * <p>
 944      * This is a vector binary operation where the primitive logical left shift
 945      * operation ({@code <<}) is applied to lane elements to left shift the
 946      * element by shift value as specified by the input scalar. Only the 4
 947      * lowest-order bits of shift value are used. It is as if the shift value
 948      * were subjected to a bitwise logical AND operator & with the mask value 0xF.
 949      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 950      *
 951      * @param s the input scalar; the number of the bits to left shift
 952      * @param m the mask controlling lane selection
 953      * @return the result of logically left shifting left this vector by the
 954      * broadcast of an input scalar
 955      */
 956     public abstract ShortVector shiftL(int s, Mask<Short> m);
 957 
 958 
 959     // logical, or unsigned, shift right
 960 
 961      /**
 962      * Logically right shifts (or unsigned right shifts) this vector by the
 963      * broadcast of an input scalar.
 964      * <p>
 965      * This is a vector binary operation where the primitive logical right shift
 966      * operation ({@code >>>}) is applied to lane elements to logically right shift the
 967      * element by shift value as specified by the input scalar. Only the 4
 968      * lowest-order bits of shift value are used. It is as if the shift value
 969      * were subjected to a bitwise logical AND operator & with the mask value 0xF.
 970      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 971      *
 972      * @param s the input scalar; the number of the bits to right shift
 973      * @return the result of logically right shifting this vector by the
 974      * broadcast of an input scalar
 975      */
 976     public abstract ShortVector shiftR(int s);
 977 
 978      /**
 979      * Logically right shifts (or unsigned right shifts) this vector by the
 980      * broadcast of an input scalar, selecting lane elements controlled by a
 981      * mask.
 982      * <p>
 983      * This is a vector binary operation where the primitive logical right shift
 984      * operation ({@code >>>}) is applied to lane elements to logically right shift the
 985      * element by shift value as specified by the input scalar. Only the 4
 986      * lowest-order bits of shift value are used. It is as if the shift value
 987      * were subjected to a bitwise logical AND operator & with the mask value 0xF.
 988      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
 989      *
 990      * @param s the input scalar; the number of the bits to right shift

 991      * @return the result of logically right shifting this vector by the
 992      * broadcast of an input scalar
 993      */
 994     public abstract ShortVector shiftR(int s, Mask<Short> m);
 995 
 996 
 997     /**
 998      * Arithmetically right shifts (or signed right shifts) this vector by the
 999      * broadcast of an input scalar.
1000      * <p>
1001      * This is a vector binary operation where the primitive arithmetic right
1002      * shift operation ({@code >>}) is applied to lane elements  to arithmetically
1003      * right shift the element by shift value as specified by the input scalar.
1004      * Only the 4 lowest-order bits of shift value are used. It is as if the shift
1005      * value were subjected to a bitwise logical AND operator & with the mask value 0xF.
1006      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1007      *
1008      * @param s the input scalar; the number of the bits to right shift
1009      * @return the result of arithmetically right shifting this vector by the
1010      * broadcast of an input scalar
1011      */
1012     public abstract ShortVector aShiftR(int s);
1013 
1014     /**
1015      * Arithmetically right shifts (or signed right shifts) this vector by the
1016      * broadcast of an input scalar, selecting lane elements controlled by a
1017      * mask.
1018      * <p>
1019      * This is a vector binary operation where the primitive arithmetic right
1020      * shift operation ({@code >>}) is applied to lane elements  to arithmetically
1021      * right shift the element by shift value as specified by the input scalar.
1022      * Only the 4 lowest-order bits of shift value are used. It is as if the shift
1023      * value were subjected to a bitwise logical AND operator & with the mask value 0xF.
1024      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1025      *
1026      * @param s the input scalar; the number of the bits to right shift
1027      * @param m the mask controlling lane selection
1028      * @return the result of arithmetically right shifting this vector by the
1029      * broadcast of an input scalar
1030      */
1031     public abstract ShortVector aShiftR(int s, Mask<Short> m);
1032 
1033 
1034     @Override
1035     public abstract void intoByteArray(byte[] a, int ix);
1036 
1037     @Override
1038     public abstract void intoByteArray(byte[] a, int ix, Mask<Short> m);
1039 
1040     @Override
1041     public abstract void intoByteBuffer(ByteBuffer bb, int ix);
1042 
1043     @Override
1044     public abstract void intoByteBuffer(ByteBuffer bb, int ix, Mask<Short> m);
1045 
1046 
1047     // Type specific horizontal reductions
1048 
1049     /**
1050      * Adds all lane elements of this vector.
1051      * <p>
1052      * This is an associative vector reduction operation where the addition
1053      * operation ({@code +}) is applied to lane elements,
1054      * and the identity value is {@code 0}.
1055      *
1056      * @return the addition of all the lane elements of this vector
1057      */
1058     public abstract short addAll();
1059 
1060     /**
1061      * Adds all lane elements of this vector, selecting lane elements
1062      * controlled by a mask.
1063      * <p>
1064      * This is an associative vector reduction operation where the addition
1065      * operation ({@code +}) is applied to lane elements,
1066      * and the identity value is {@code 0}.
1067      *
1068      * @param m the mask controlling lane selection
1069      * @return the addition of all the lane elements of this vector
1070      */
1071     public abstract short addAll(Mask<Short> m);
1072 
1073     /**
1074      * Subtracts all lane elements of this vector.
1075      * <p>
1076      * This is an associative vector reduction operation where the subtraction
1077      * operation ({@code -}) is applied to lane elements,
1078      * and the identity value is {@code 0}.
1079      *
1080      * @return the subtraction of all the lane elements of this vector
1081      */
1082     public abstract short subAll();
1083 
1084     /**
1085      * Subtracts all lane elements of this vector, selecting lane elements
1086      * controlled by a mask.
1087      * <p>
1088      * This is an associative vector reduction operation where the subtraction
1089      * operation ({@code -}) is applied to lane elements,
1090      * and the identity value is {@code 0}.
1091      *
1092      * @param m the mask controlling lane selection
1093      * @return the subtraction of all the lane elements of this vector
1094      */
1095     public abstract short subAll(Mask<Short> m);
1096 
1097     /**
1098      * Multiplies all lane elements of this vector.
1099      * <p>
1100      * This is an associative vector reduction operation where the
1101      * multiplication operation ({@code *}) is applied to lane elements,
1102      * and the identity value is {@code 1}.
1103      *
1104      * @return the multiplication of all the lane elements of this vector
1105      */
1106     public abstract short mulAll();
1107 
1108     /**
1109      * Multiplies all lane elements of this vector, selecting lane elements
1110      * controlled by a mask.
1111      * <p>
1112      * This is an associative vector reduction operation where the
1113      * multiplication operation ({@code *}) is applied to lane elements,
1114      * and the identity value is {@code 1}.
1115      *
1116      * @param m the mask controlling lane selection
1117      * @return the multiplication of all the lane elements of this vector
1118      */
1119     public abstract short mulAll(Mask<Short> m);
1120 
1121     /**
1122      * Returns the minimum lane element of this vector.
1123      * <p>
1124      * This is an associative vector reduction operation where the operation
1125      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1126      * and the identity value is {@link Short#MAX_VALUE}.

1127      *
1128      * @return the minimum lane element of this vector
1129      */
1130     public abstract short minAll();
1131 
1132     /**
1133      * Returns the minimum lane element of this vector, selecting lane elements
1134      * controlled by a mask.
1135      * <p>
1136      * This is an associative vector reduction operation where the operation
1137      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1138      * and the identity value is {@link Short#MAX_VALUE}.

1139      *
1140      * @param m the mask controlling lane selection
1141      * @return the minimum lane element of this vector
1142      */
1143     public abstract short minAll(Mask<Short> m);
1144 
1145     /**
1146      * Returns the maximum lane element of this vector.
1147      * <p>
1148      * This is an associative vector reduction operation where the operation
1149      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1150      * and the identity value is {@link Short#MIN_VALUE}.

1151      *
1152      * @return the maximum lane element of this vector
1153      */
1154     public abstract short maxAll();
1155 
1156     /**
1157      * Returns the maximum lane element of this vector, selecting lane elements
1158      * controlled by a mask.
1159      * <p>
1160      * This is an associative vector reduction operation where the operation
1161      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1162      * and the identity value is {@link Short#MIN_VALUE}.

1163      *
1164      * @param m the mask controlling lane selection
1165      * @return the maximum lane element of this vector
1166      */
1167     public abstract short maxAll(Mask<Short> m);
1168 
1169     /**
1170      * Logically ORs all lane elements of this vector.
1171      * <p>
1172      * This is an associative vector reduction operation where the logical OR
1173      * operation ({@code |}) is applied to lane elements,
1174      * and the identity value is {@code 0}.
1175      *
1176      * @return the logical OR all the lane elements of this vector
1177      */
1178     public abstract short orAll();
1179 
1180     /**
1181      * Logically ORs all lane elements of this vector, selecting lane elements
1182      * controlled by a mask.


1412 
1413         /**
1414          * Returns a vector where the first lane element is set to the primtive
1415          * value {@code e}, all other lane elements are set to the default
1416          * value.
1417          *
1418          * @param e the value
1419          * @return a vector where the first lane element is set to the primitive
1420          * value {@code e}
1421          */
1422         @ForceInline
1423         public final ShortVector single(short e) {
1424             return zero().with(0, e);
1425         }
1426 
1427         /**
1428          * Returns a vector where each lane element is set to a randomly
1429          * generated primitive value.
1430          *
1431          * The semantics are equivalent to calling
1432          * {@link (short)ThreadLocalRandom#nextInt() }
1433          *
1434          * @return a vector where each lane elements is set to a randomly
1435          * generated primitive value
1436          */
1437         public ShortVector random() {
1438             ThreadLocalRandom r = ThreadLocalRandom.current();
1439             return op(i -> (short) r.nextInt());
1440         }
1441 
1442         /**
1443          * Returns a vector where each lane element is set to a given
1444          * primitive value.
1445          * <p>
1446          * For each vector lane, where {@code N} is the vector lane index, the
1447          * the primitive value at index {@code N} is placed into the resulting
1448          * vector at lane index {@code N}.
1449          *
1450          * @param es the given primitive values
1451          * @return a vector where each lane element is set to a given primitive
1452          * value




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


 331      * {@link java.nio.Buffer buffer} for the primitive element type,
 332      * according to the native byte order of the underlying platform, and
 333      * the returned vector is loaded with a mask from a primitive array
 334      * obtained from the primitive buffer.
 335      * The following pseudocode expresses the behaviour, where
 336      * {@coce EBuffer} is the primitive buffer type, {@code e} is the
 337      * primitive element type, and {@code ESpecies<S>} is the primitive
 338      * species for {@code e}:
 339      * <pre>{@code
 340      * EBuffer eb = b.duplicate().
 341      *     order(ByteOrder.nativeOrder()).position(i).
 342      *     asEBuffer();
 343      * e[] es = new e[this.length()];
 344      * for (int n = 0; n < t.length; n++) {
 345      *     if (m.isSet(n))
 346      *         es[n] = eb.get(n);
 347      * }
 348      * Vector<E> r = ((ESpecies<S>)this).fromArray(es, 0, m);
 349      * }</pre>
 350      *
 351      * @param species species of desired vector
 352      * @param bb the byte buffer
 353      * @param ix the offset into the byte buffer
 354      * @param m the mask
 355      * @return a vector loaded from a byte buffer
 356      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 357      * or {@code > b.limit()},
 358      * for any vector lane index {@code N} where the mask at lane {@code N}
 359      * is set
 360      * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)}
 361      */
 362     @ForceInline
 363     public static ShortVector fromByteBuffer(ShortSpecies species, ByteBuffer bb, int ix, Mask<Short> m) {
 364         return zero(species).blend(fromByteBuffer(species, bb, ix), m);
 365     }
 366 
 367     /**
 368      * Returns a mask where each lane is set or unset according to given
 369      * {@code boolean} values
 370      * <p>
 371      * For each mask lane, where {@code N} is the mask lane index,
 372      * if the given {@code boolean} value at index {@code N} is {@code true}
 373      * then the mask lane at index {@code N} is set, otherwise it is unset.
 374      *
 375      * @param species mask species
 376      * @param bits the given {@code boolean} values
 377      * @return a mask where each lane is set or unset according to the given {@code boolean} value
 378      * @throws IndexOutOfBoundsException if {@code bits.length < species.length()}
 379      */
 380     @ForceInline
 381     public static Mask<Short> maskFromValues(ShortSpecies species, boolean... bits) {
 382         if (species.boxType() == ShortMaxVector.class)
 383             return new ShortMaxVector.ShortMaxMask(bits);
 384         switch (species.bitSize()) {
 385             case 64: return new Short64Vector.Short64Mask(bits);
 386             case 128: return new Short128Vector.Short128Mask(bits);
 387             case 256: return new Short256Vector.Short256Mask(bits);
 388             case 512: return new Short512Vector.Short512Mask(bits);
 389             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 390         }
 391     }
 392 
 393     // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
 394     static Mask<Short> trueMask(ShortSpecies species) {
 395         if (species.boxType() == ShortMaxVector.class)
 396             return ShortMaxVector.ShortMaxMask.TRUE_MASK;
 397         switch (species.bitSize()) {
 398             case 64: return Short64Vector.Short64Mask.TRUE_MASK;
 399             case 128: return Short128Vector.Short128Mask.TRUE_MASK;
 400             case 256: return Short256Vector.Short256Mask.TRUE_MASK;
 401             case 512: return Short512Vector.Short512Mask.TRUE_MASK;
 402             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 403         }
 404     }
 405 
 406     static Mask<Short> falseMask(ShortSpecies species) {
 407         if (species.boxType() == ShortMaxVector.class)
 408             return ShortMaxVector.ShortMaxMask.FALSE_MASK;
 409         switch (species.bitSize()) {
 410             case 64: return Short64Vector.Short64Mask.FALSE_MASK;
 411             case 128: return Short128Vector.Short128Mask.FALSE_MASK;
 412             case 256: return Short256Vector.Short256Mask.FALSE_MASK;
 413             case 512: return Short512Vector.Short512Mask.FALSE_MASK;
 414             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 415         }
 416     }
 417 
 418     /**
 419      * Loads a mask from a {@code boolean} array starting at an offset.
 420      * <p>
 421      * For each mask lane, where {@code N} is the mask lane index,
 422      * if the array element at index {@code i + N} is {@code true} then the
 423      * mask lane at index {@code N} is set, otherwise it is unset.
 424      *
 425      * @param species mask species
 426      * @param bits the {@code boolean} array
 427      * @param ix the offset into the array
 428      * @return the mask loaded from a {@code boolean} array
 429      * @throws IndexOutOfBoundsException if {@code ix < 0}, or
 430      * {@code ix > bits.length - species.length()}
 431      */
 432     @ForceInline
 433     @SuppressWarnings("unchecked")
 434     public static Mask<Short> maskFromArray(ShortSpecies species, boolean[] bits, int ix) {
 435         Objects.requireNonNull(bits);
 436         ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length());
 437         return VectorIntrinsics.load((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 438                                      bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
 439                                      bits, ix, species,
 440                                      (c, idx, s) -> (Mask<Short>) ((ShortSpecies)s).opm(n -> c[idx + n]));
 441     }
 442 
 443     /**
 444      * Returns a mask where all lanes are a set.
 445      *
 446      * @param species mask species
 447      * @return a mask where all lanes are a set
 448      */
 449     @ForceInline
 450     @SuppressWarnings("unchecked")
 451     public static Mask<Short> maskAllTrue(ShortSpecies species) {
 452         return VectorIntrinsics.broadcastCoerced((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 453                                                  (short)-1,  species,
 454                                                  ((z, s) -> trueMask((ShortSpecies)s)));
 455     }
 456 
 457     /**
 458      * Returns a mask where all lanes are a unset.
 459      *
 460      * @param species mask species
 461      * @return a mask where all lanes are a unset
 462      */
 463     @ForceInline
 464     @SuppressWarnings("unchecked")
 465     public static Mask<Short> maskAllFalse(ShortSpecies species) {
 466         return VectorIntrinsics.broadcastCoerced((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
 467                                                  0, species, 
 468                                                  ((z, s) -> falseMask((ShortSpecies)s)));
 469     }
 470 
 471     /**
 472      * Returns a shuffle of mapped indexes where each lane element is
 473      * the result of applying a mapping function to the corresponding lane
 474      * index.
 475      * <p>
 476      * Care should be taken to ensure Shuffle values produced from this
 477      * method are consumed as constants to ensure optimal generation of
 478      * code.  For example, values held in static final fields or values
 479      * held in loop constant local variables.
 480      * <p>
 481      * This method behaves as if a shuffle is created from an array of
 482      * mapped indexes as follows:
 483      * <pre>{@code
 484      *   int[] a = new int[species.length()];
 485      *   for (int i = 0; i < a.length; i++) {
 486      *       a[i] = f.applyAsInt(i);
 487      *   }
 488      *   return this.shuffleFromValues(a);
 489      * }</pre>
 490      *
 491      * @param species shuffle species
 492      * @param f the lane index mapping function
 493      * @return a shuffle of mapped indexes
 494      */
 495     @ForceInline
 496     public static Shuffle<Short> shuffle(ShortSpecies species, IntUnaryOperator f) {
 497         if (species.boxType() == ShortMaxVector.class)
 498             return new ShortMaxVector.ShortMaxShuffle(f);
 499         switch (species.bitSize()) {
 500             case 64: return new Short64Vector.Short64Shuffle(f);
 501             case 128: return new Short128Vector.Short128Shuffle(f);
 502             case 256: return new Short256Vector.Short256Shuffle(f);
 503             case 512: return new Short512Vector.Short512Shuffle(f);
 504             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 505         }
 506     }
 507 
 508     /**
 509      * Returns a shuffle where each lane element is the value of its
 510      * corresponding lane index.
 511      * <p>
 512      * This method behaves as if a shuffle is created from an identity
 513      * index mapping function as follows:
 514      * <pre>{@code
 515      *   return this.shuffle(i -> i);
 516      * }</pre>
 517      *
 518      * @param species shuffle species
 519      * @return a shuffle of lane indexes
 520      */
 521     @ForceInline
 522     public static Shuffle<Short> shuffleIota(ShortSpecies species) {
 523         if (species.boxType() == ShortMaxVector.class)
 524             return new ShortMaxVector.ShortMaxShuffle(AbstractShuffle.IDENTITY);
 525         switch (species.bitSize()) {
 526             case 64: return new Short64Vector.Short64Shuffle(AbstractShuffle.IDENTITY);
 527             case 128: return new Short128Vector.Short128Shuffle(AbstractShuffle.IDENTITY);
 528             case 256: return new Short256Vector.Short256Shuffle(AbstractShuffle.IDENTITY);
 529             case 512: return new Short512Vector.Short512Shuffle(AbstractShuffle.IDENTITY);
 530             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 531         }
 532     }
 533 
 534     /**
 535      * Returns a shuffle where each lane element is set to a given
 536      * {@code int} value logically AND'ed by the species length minus one.
 537      * <p>
 538      * For each shuffle lane, where {@code N} is the shuffle lane index, the
 539      * the {@code int} value at index {@code N} logically AND'ed by
 540      * {@code species.length() - 1} is placed into the resulting shuffle at
 541      * lane index {@code N}.
 542      *
 543      * @param species shuffle species
 544      * @param ixs the given {@code int} values
 545      * @return a shuffle where each lane element is set to a given
 546      * {@code int} value
 547      * @throws IndexOutOfBoundsException if the number of int values is
 548      * {@code < species.length()}
 549      */
 550     @ForceInline
 551     public static Shuffle<Short> shuffleFromValues(ShortSpecies species, int... ixs) {
 552         if (species.boxType() == ShortMaxVector.class)
 553             return new ShortMaxVector.ShortMaxShuffle(ixs);
 554         switch (species.bitSize()) {
 555             case 64: return new Short64Vector.Short64Shuffle(ixs);
 556             case 128: return new Short128Vector.Short128Shuffle(ixs);
 557             case 256: return new Short256Vector.Short256Shuffle(ixs);
 558             case 512: return new Short512Vector.Short512Shuffle(ixs);
 559             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 560         }
 561     }
 562 
 563     /**
 564      * Loads a shuffle from an {@code int} array starting at an offset.
 565      * <p>
 566      * For each shuffle lane, where {@code N} is the shuffle lane index, the
 567      * array element at index {@code i + N} logically AND'ed by
 568      * {@code species.length() - 1} is placed into the resulting shuffle at lane
 569      * index {@code N}.
 570      *
 571      * @param species shuffle species
 572      * @param ixs the {@code int} array
 573      * @param i the offset into the array
 574      * @return a shuffle loaded from the {@code int} array
 575      * @throws IndexOutOfBoundsException if {@code i < 0}, or
 576      * {@code i > a.length - species.length()}
 577      */
 578     @ForceInline
 579     public static Shuffle<Short> shuffleFromArray(ShortSpecies species, int[] ixs, int i) {
 580         if (species.boxType() == ShortMaxVector.class)
 581             return new ShortMaxVector.ShortMaxShuffle(ixs, i);
 582         switch (species.bitSize()) {
 583             case 64: return new Short64Vector.Short64Shuffle(ixs, i);
 584             case 128: return new Short128Vector.Short128Shuffle(ixs, i);
 585             case 256: return new Short256Vector.Short256Shuffle(ixs, i);
 586             case 512: return new Short512Vector.Short512Shuffle(ixs, i);
 587             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 588         }
 589     }
 590 
 591 
 592     // Ops
 593 
 594     @Override
 595     public abstract ShortVector add(Vector<Short> v);
 596 
 597     /**


1029     public abstract ShortVector not();
1030 
1031     /**
1032      * Bitwise NOTs this vector, selecting lane elements controlled by a mask.
1033      * <p>
1034      * This is a vector unary operation where the primitive bitwise NOT
1035      * operation ({@code ~}) is applied to lane elements.
1036      *
1037      * @param m the mask controlling lane selection
1038      * @return the bitwise NOT of this vector
1039      */
1040     public abstract ShortVector not(Mask<Short> m);
1041 
1042     /**
1043      * Logically left shifts this vector by the broadcast of an input scalar.
1044      * <p>
1045      * This is a vector binary operation where the primitive logical left shift
1046      * operation ({@code <<}) is applied to lane elements to left shift the
1047      * element by shift value as specified by the input scalar. Only the 4
1048      * lowest-order bits of shift value are used. It is as if the shift value
1049      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1050      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1051      *
1052      * @param s the input scalar; the number of the bits to left shift
1053      * @return the result of logically left shifting left this vector by the
1054      * broadcast of an input scalar
1055      */
1056     public abstract ShortVector shiftL(int s);
1057 
1058     /**
1059      * Logically left shifts this vector by the broadcast of an input scalar,
1060      * selecting lane elements controlled by a mask.
1061      * <p>
1062      * This is a vector binary operation where the primitive logical left shift
1063      * operation ({@code <<}) is applied to lane elements to left shift the
1064      * element by shift value as specified by the input scalar. Only the 4
1065      * lowest-order bits of shift value are used. It is as if the shift value
1066      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1067      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1068      *
1069      * @param s the input scalar; the number of the bits to left shift
1070      * @param m the mask controlling lane selection
1071      * @return the result of logically left shifting left this vector by the
1072      * broadcast of an input scalar
1073      */
1074     public abstract ShortVector shiftL(int s, Mask<Short> m);
1075 
1076 
1077     // logical, or unsigned, shift right
1078 
1079      /**
1080      * Logically right shifts (or unsigned right shifts) this vector by the
1081      * broadcast of an input scalar.
1082      * <p>
1083      * This is a vector binary operation where the primitive logical right shift
1084      * operation ({@code >>>}) is applied to lane elements to logically right shift the
1085      * element by shift value as specified by the input scalar. Only the 4
1086      * lowest-order bits of shift value are used. It is as if the shift value
1087      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1088      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1089      *
1090      * @param s the input scalar; the number of the bits to right shift
1091      * @return the result of logically right shifting this vector by the
1092      * broadcast of an input scalar
1093      */
1094     public abstract ShortVector shiftR(int s);
1095 
1096      /**
1097      * Logically right shifts (or unsigned right shifts) this vector by the
1098      * broadcast of an input scalar, selecting lane elements controlled by a
1099      * mask.
1100      * <p>
1101      * This is a vector binary operation where the primitive logical right shift
1102      * operation ({@code >>>}) is applied to lane elements to logically right shift the
1103      * element by shift value as specified by the input scalar. Only the 4
1104      * lowest-order bits of shift value are used. It is as if the shift value
1105      * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1106      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1107      *
1108      * @param s the input scalar; the number of the bits to right shift
1109      * @param m the mask controlling lane selection
1110      * @return the result of logically right shifting this vector by the
1111      * broadcast of an input scalar
1112      */
1113     public abstract ShortVector shiftR(int s, Mask<Short> m);
1114 
1115 
1116     /**
1117      * Arithmetically right shifts (or signed right shifts) this vector by the
1118      * broadcast of an input scalar.
1119      * <p>
1120      * This is a vector binary operation where the primitive arithmetic right
1121      * shift operation ({@code >>}) is applied to lane elements  to arithmetically
1122      * right shift the element by shift value as specified by the input scalar.
1123      * Only the 4 lowest-order bits of shift value are used. It is as if the shift
1124      * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF.
1125      * The shift distance actually used is therefore always in the range 0 to 15, inclusive.
1126      *
1127      * @param s the input scalar; the number of the bits to right shift
1128      * @return the result of arithmetically right shifting this vector by the
1129      * broadcast of an input scalar
1130      */
1131     public abstract ShortVector aShiftR(int s);
1132 
1133     /**
1134      * Arithmetically right shifts (or signed right shifts) this vector by the
1135      * broadcast of an input scalar, selecting lane elements controlled by a
1136      * mask.
1137      * <p>
1138      * This is a vector binary operation where the primitive arithmetic right
1139      * shift operation ({@code >>}) is applied to lane elements  to arithmetically
1140      * right shift the element by shift value as specified by the input scalar.
1141      * Only the 4 lowest-order bits of shift value are used. It is as if the shift
1142      * value 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 right shift
1146      * @param m the mask controlling lane selection
1147      * @return the result of arithmetically right shifting this vector by the
1148      * broadcast of an input scalar
1149      */
1150     public abstract ShortVector aShiftR(int s, Mask<Short> m);
1151 
1152 
1153     @Override
1154     public abstract void intoByteArray(byte[] a, int ix);
1155 
1156     @Override
1157     public abstract void intoByteArray(byte[] a, int ix, Mask<Short> m);
1158 
1159     @Override
1160     public abstract void intoByteBuffer(ByteBuffer bb, int ix);
1161 
1162     @Override
1163     public abstract void intoByteBuffer(ByteBuffer bb, int ix, Mask<Short> m);
1164 
1165 
1166     // Type specific horizontal reductions

1167     /**
1168      * Adds all lane elements of this vector.
1169      * <p>
1170      * This is an associative vector reduction operation where the addition
1171      * operation ({@code +}) is applied to lane elements,
1172      * and the identity value is {@code 0}.
1173      *
1174      * @return the addition of all the lane elements of this vector
1175      */
1176     public abstract short addAll();
1177 
1178     /**
1179      * Adds 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 addition
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 addition of the selected lane elements of this vector
1188      */
1189     public abstract short addAll(Mask<Short> m);
1190 
1191     /**
























1192      * Multiplies all lane elements of this vector.
1193      * <p>
1194      * This is an associative vector reduction operation where the
1195      * multiplication operation ({@code *}) is applied to lane elements,
1196      * and the identity value is {@code 1}.
1197      *
1198      * @return the multiplication of all the lane elements of this vector
1199      */
1200     public abstract short mulAll();
1201 
1202     /**
1203      * Multiplies all lane elements of this vector, selecting lane elements
1204      * controlled by a mask.
1205      * <p>
1206      * This is an associative vector reduction operation where the
1207      * multiplication operation ({@code *}) is applied to lane elements,
1208      * and the identity value is {@code 1}.
1209      *
1210      * @param m the mask controlling lane selection
1211      * @return the multiplication of all the lane elements of this vector
1212      */
1213     public abstract short mulAll(Mask<Short> m);
1214 
1215     /**
1216      * Returns the minimum lane element of this vector.
1217      * <p>
1218      * This is an associative vector reduction operation where the operation
1219      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1220      * and the identity value is
1221      * {@link Short#MAX_VALUE}.
1222      *
1223      * @return the minimum lane element of this vector
1224      */
1225     public abstract short minAll();
1226 
1227     /**
1228      * Returns the minimum lane element of this vector, selecting lane elements
1229      * controlled by a mask.
1230      * <p>
1231      * This is an associative vector reduction operation where the operation
1232      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1233      * and the identity value is
1234      * {@link Short#MAX_VALUE}.
1235      *
1236      * @param m the mask controlling lane selection
1237      * @return the minimum lane element of this vector
1238      */
1239     public abstract short minAll(Mask<Short> m);
1240 
1241     /**
1242      * Returns the maximum lane element of this vector.
1243      * <p>
1244      * This is an associative vector reduction operation where the operation
1245      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1246      * and the identity value is
1247      * {@link Short#MIN_VALUE}.
1248      *
1249      * @return the maximum lane element of this vector
1250      */
1251     public abstract short maxAll();
1252 
1253     /**
1254      * Returns the maximum lane element of this vector, selecting lane elements
1255      * controlled by a mask.
1256      * <p>
1257      * This is an associative vector reduction operation where the operation
1258      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1259      * and the identity value is
1260      * {@link Short#MIN_VALUE}.
1261      *
1262      * @param m the mask controlling lane selection
1263      * @return the maximum lane element of this vector
1264      */
1265     public abstract short maxAll(Mask<Short> m);
1266 
1267     /**
1268      * Logically ORs all lane elements of this vector.
1269      * <p>
1270      * This is an associative vector reduction operation where the logical OR
1271      * operation ({@code |}) is applied to lane elements,
1272      * and the identity value is {@code 0}.
1273      *
1274      * @return the logical OR all the lane elements of this vector
1275      */
1276     public abstract short orAll();
1277 
1278     /**
1279      * Logically ORs all lane elements of this vector, selecting lane elements
1280      * controlled by a mask.


1510 
1511         /**
1512          * Returns a vector where the first lane element is set to the primtive
1513          * value {@code e}, all other lane elements are set to the default
1514          * value.
1515          *
1516          * @param e the value
1517          * @return a vector where the first lane element is set to the primitive
1518          * value {@code e}
1519          */
1520         @ForceInline
1521         public final ShortVector single(short e) {
1522             return zero().with(0, e);
1523         }
1524 
1525         /**
1526          * Returns a vector where each lane element is set to a randomly
1527          * generated primitive value.
1528          *
1529          * The semantics are equivalent to calling
1530          * {@code (short)ThreadLocalRandom#nextInt()}.
1531          *
1532          * @return a vector where each lane elements is set to a randomly
1533          * generated primitive value
1534          */
1535         public ShortVector random() {
1536             ThreadLocalRandom r = ThreadLocalRandom.current();
1537             return op(i -> (short) r.nextInt());
1538         }
1539 
1540         /**
1541          * Returns a vector where each lane element is set to a given
1542          * primitive value.
1543          * <p>
1544          * For each vector lane, where {@code N} is the vector lane index, the
1545          * the primitive value at index {@code N} is placed into the resulting
1546          * vector at lane index {@code N}.
1547          *
1548          * @param es the given primitive values
1549          * @return a vector where each lane element is set to a given primitive
1550          * value


< prev index next >