< prev index next >

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

Print this page
rev 55237 : javadoc changes


  88     }
  89 
  90     abstract Mask<Integer> bTest(Vector<Integer> v, FBinTest f);
  91 
  92     // Foreach
  93 
  94     interface FUnCon {
  95         void apply(int i, int a);
  96     }
  97 
  98     abstract void forEach(FUnCon f);
  99 
 100     abstract void forEach(Mask<Integer> 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 IntVector zero(IntSpecies 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(IntSpecies, 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 IntVector fromByteArray(IntSpecies 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<IntVector>) species.boxType(), int.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                                          IntBuffer tb = bbc.asIntBuffer();
 146                                          return ((IntSpecies)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(IntSpecies, 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 IntVector fromByteArray(IntSpecies species, byte[] a, int ix, Mask<Integer> 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 IntVector fromArray(IntSpecies species, int[] a, int i){
 197         Objects.requireNonNull(a);
 198         i = VectorIntrinsics.checkIndex(i, a.length, species.length());
 199         return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
 200                                      a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET,
 201                                      a, i, species,
 202                                      (c, idx, s) -> ((IntSpecies)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 IntVector fromArray(IntSpecies species, int[] a, int i, Mask<Integer> 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     @ForceInline
 249     @SuppressWarnings("unchecked")
 250     public static IntVector fromArray(IntSpecies species, int[] a, int i, int[] indexMap, int j) {
 251         Objects.requireNonNull(a);
 252         Objects.requireNonNull(indexMap);
 253 
 254 
 255         // Index vector: vix[0:n] = k -> i + indexMap[j + i]
 256         IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i);
 257 
 258         vix = VectorIntrinsics.checkIndex(vix, a.length);
 259 
 260         return VectorIntrinsics.loadWithMap((Class<IntVector>) species.boxType(), int.class, species.length(),
 261                                             species.indexSpecies().vectorType(), a, Unsafe.ARRAY_INT_BASE_OFFSET, vix,
 262                                             a, i, indexMap, j, species,
 263                                            (c, idx, iMap, idy, s) -> ((IntSpecies)s).op(n -> c[idx + iMap[idy+n]]));
 264         }
 265 
 266     /**
 267      * Loads a vector from an array using indexes obtained from an index
 268      * map and using a mask.
 269      * <p>
 270      * For each vector lane, where {@code N} is the vector lane index,
 271      * if the mask lane at index {@code N} is set then the array element at
 272      * index {@code i + indexMap[j + N]} is placed into the resulting vector
 273      * at lane index {@code N}.
 274      *

 275      * @param a the array
 276      * @param i the offset into the array, may be negative if relative
 277      * indexes in the index map compensate to produce a value within the
 278      * array bounds

 279      * @param indexMap the index map
 280      * @param j the offset into the index map
 281      * @return the vector loaded from an array
 282      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 283      * {@code j > indexMap.length - this.length()},
 284      * or for any vector lane index {@code N} where the mask at lane
 285      * {@code N} is set the result of {@code i + indexMap[j + N]} is
 286      * {@code < 0} or {@code >= a.length}
 287      */
 288     @ForceInline
 289     @SuppressWarnings("unchecked")
 290     public static IntVector fromArray(IntSpecies species, int[] a, int i, Mask<Integer> m, int[] indexMap, int j) {
 291         // @@@ This can result in out of bounds errors for unset mask lanes
 292         return zero(species).blend(fromArray(species, a, i, indexMap, j), m);
 293     }
 294 
 295 
 296     /**
 297      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 298      * offset into the byte buffer.
 299      * <p>
 300      * Bytes are composed into primitive lane elements according to the
 301      * native byte order of the underlying platform.
 302      * <p>
 303      * This method behaves as if it returns the result of calling the
 304      * byte buffer, offset, and mask accepting
 305      * {@link #fromByteBuffer(IntSpecies, ByteBuffer, int, Mask)} method} as follows:
 306      * <pre>{@code
 307      *   return this.fromByteBuffer(b, i, this.maskAllTrue())
 308      * }</pre>
 309      *

 310      * @param bb the byte buffer
 311      * @param ix the offset into the byte buffer
 312      * @return a vector loaded from a byte buffer
 313      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 314      * or {@code > b.limit()},
 315      * or if there are fewer than
 316      * {@code this.length() * this.elementSize() / Byte.SIZE} bytes
 317      * remaining in the byte buffer from the given offset
 318      */
 319     @ForceInline
 320     @SuppressWarnings("unchecked")
 321     public static IntVector fromByteBuffer(IntSpecies species, ByteBuffer bb, int ix) {
 322         if (bb.order() != ByteOrder.nativeOrder()) {
 323             throw new IllegalArgumentException();
 324         }
 325         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE);
 326         return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
 327                                      U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
 328                                      bb, ix, species,
 329                                      (c, idx, s) -> {


 341      * {@link java.nio.Buffer buffer} for the primitive element type,
 342      * according to the native byte order of the underlying platform, and
 343      * the returned vector is loaded with a mask from a primitive array
 344      * obtained from the primitive buffer.
 345      * The following pseudocode expresses the behaviour, where
 346      * {@coce EBuffer} is the primitive buffer type, {@code e} is the
 347      * primitive element type, and {@code ESpecies<S>} is the primitive
 348      * species for {@code e}:
 349      * <pre>{@code
 350      * EBuffer eb = b.duplicate().
 351      *     order(ByteOrder.nativeOrder()).position(i).
 352      *     asEBuffer();
 353      * e[] es = new e[this.length()];
 354      * for (int n = 0; n < t.length; n++) {
 355      *     if (m.isSet(n))
 356      *         es[n] = eb.get(n);
 357      * }
 358      * Vector<E> r = ((ESpecies<S>)this).fromArray(es, 0, m);
 359      * }</pre>
 360      *

 361      * @param bb the byte buffer
 362      * @param ix the offset into the byte buffer

 363      * @return a vector loaded from a byte buffer
 364      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 365      * or {@code > b.limit()},
 366      * for any vector lane index {@code N} where the mask at lane {@code N}
 367      * is set
 368      * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)}
 369      */
 370     @ForceInline
 371     public static IntVector fromByteBuffer(IntSpecies species, ByteBuffer bb, int ix, Mask<Integer> m) {
 372         return zero(species).blend(fromByteBuffer(species, bb, ix), m);
 373     }
 374 













 375     @ForceInline
 376     public static Mask<Integer> maskFromValues(IntSpecies species, boolean... bits) {
 377         if (species.boxType() == IntMaxVector.class)
 378             return new IntMaxVector.IntMaxMask(bits);
 379         switch (species.bitSize()) {
 380             case 64: return new Int64Vector.Int64Mask(bits);
 381             case 128: return new Int128Vector.Int128Mask(bits);
 382             case 256: return new Int256Vector.Int256Mask(bits);
 383             case 512: return new Int512Vector.Int512Mask(bits);
 384             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 385         }
 386     }
 387 
 388     // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
 389     static Mask<Integer> trueMask(IntSpecies species) {
 390         if (species.boxType() == IntMaxVector.class)
 391             return IntMaxVector.IntMaxMask.TRUE_MASK;
 392         switch (species.bitSize()) {
 393             case 64: return Int64Vector.Int64Mask.TRUE_MASK;
 394             case 128: return Int128Vector.Int128Mask.TRUE_MASK;
 395             case 256: return Int256Vector.Int256Mask.TRUE_MASK;
 396             case 512: return Int512Vector.Int512Mask.TRUE_MASK;
 397             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 398         }
 399     }
 400 
 401     static Mask<Integer> falseMask(IntSpecies species) {
 402         if (species.boxType() == IntMaxVector.class)
 403             return IntMaxVector.IntMaxMask.FALSE_MASK;
 404         switch (species.bitSize()) {
 405             case 64: return Int64Vector.Int64Mask.FALSE_MASK;
 406             case 128: return Int128Vector.Int128Mask.FALSE_MASK;
 407             case 256: return Int256Vector.Int256Mask.FALSE_MASK;
 408             case 512: return Int512Vector.Int512Mask.FALSE_MASK;
 409             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 410         }
 411     }
 412 














 413     @ForceInline
 414     @SuppressWarnings("unchecked")
 415     public static Mask<Integer> maskFromArray(IntSpecies species, boolean[] bits, int ix) {
 416         Objects.requireNonNull(bits);
 417         ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length());
 418         return VectorIntrinsics.load((Class<Mask<Integer>>) species.maskType(), int.class, species.length(),
 419                                      bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
 420                                      bits, ix, species,
 421                                      (c, idx, s) -> (Mask<Integer>) ((IntSpecies)s).opm(n -> c[idx + n]));
 422     }
 423 






 424     @ForceInline
 425     @SuppressWarnings("unchecked")
 426     public static Mask<Integer> maskAllTrue(IntSpecies species) {
 427         return VectorIntrinsics.broadcastCoerced((Class<Mask<Integer>>) species.maskType(), int.class, species.length(),
 428                                                  (int)-1,  species,
 429                                                  ((z, s) -> trueMask((IntSpecies)s)));
 430     }
 431 






 432     @ForceInline
 433     @SuppressWarnings("unchecked")
 434     public static Mask<Integer> maskAllFalse(IntSpecies species) {
 435         return VectorIntrinsics.broadcastCoerced((Class<Mask<Integer>>) species.maskType(), int.class, species.length(),
 436                                                  0, species, 
 437                                                  ((z, s) -> falseMask((IntSpecies)s)));
 438     }
 439 
























 440     @ForceInline
 441     public static Shuffle<Integer> shuffle(IntSpecies species, IntUnaryOperator f) {
 442         if (species.boxType() == IntMaxVector.class)
 443             return new IntMaxVector.IntMaxShuffle(f);
 444         switch (species.bitSize()) {
 445             case 64: return new Int64Vector.Int64Shuffle(f);
 446             case 128: return new Int128Vector.Int128Shuffle(f);
 447             case 256: return new Int256Vector.Int256Shuffle(f);
 448             case 512: return new Int512Vector.Int512Shuffle(f);
 449             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 450         }
 451     }
 452 













 453     @ForceInline
 454     public static Shuffle<Integer> shuffleIota(IntSpecies species) {
 455         if (species.boxType() == IntMaxVector.class)
 456             return new IntMaxVector.IntMaxShuffle(AbstractShuffle.IDENTITY);
 457         switch (species.bitSize()) {
 458             case 64: return new Int64Vector.Int64Shuffle(AbstractShuffle.IDENTITY);
 459             case 128: return new Int128Vector.Int128Shuffle(AbstractShuffle.IDENTITY);
 460             case 256: return new Int256Vector.Int256Shuffle(AbstractShuffle.IDENTITY);
 461             case 512: return new Int512Vector.Int512Shuffle(AbstractShuffle.IDENTITY);
 462             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 463         }
 464     }
 465 
















 466     @ForceInline
 467     public static Shuffle<Integer> shuffleFromValues(IntSpecies species, int... ixs) {
 468         if (species.boxType() == IntMaxVector.class)
 469             return new IntMaxVector.IntMaxShuffle(ixs);
 470         switch (species.bitSize()) {
 471             case 64: return new Int64Vector.Int64Shuffle(ixs);
 472             case 128: return new Int128Vector.Int128Shuffle(ixs);
 473             case 256: return new Int256Vector.Int256Shuffle(ixs);
 474             case 512: return new Int512Vector.Int512Shuffle(ixs);
 475             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 476         }
 477     }
 478 















 479     @ForceInline
 480     public static Shuffle<Integer> shuffleFromArray(IntSpecies species, int[] ixs, int i) {
 481         if (species.boxType() == IntMaxVector.class)
 482             return new IntMaxVector.IntMaxShuffle(ixs, i);
 483         switch (species.bitSize()) {
 484             case 64: return new Int64Vector.Int64Shuffle(ixs, i);
 485             case 128: return new Int128Vector.Int128Shuffle(ixs, i);
 486             case 256: return new Int256Vector.Int256Shuffle(ixs, i);
 487             case 512: return new Int512Vector.Int512Shuffle(ixs, i);
 488             default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
 489         }
 490     }
 491 
 492 
 493     // Ops
 494 
 495     @Override
 496     public abstract IntVector add(Vector<Integer> v);
 497 
 498     /**


1001      * broadcast of an input scalar.
1002      * <p>
1003      * This is a vector binary operation where the primitive logical right shift
1004      * operation ({@code >>>}) is applied to lane elements.
1005      *
1006      * @param s the input scalar; the number of the bits to right shift
1007      * @return the result of logically right shifting this vector by the
1008      * broadcast of an input scalar
1009      */
1010     public abstract IntVector shiftR(int s);
1011 
1012     /**
1013      * Logically right shifts (or unsigned right shifts) this vector by the
1014      * broadcast of an input scalar, selecting lane elements controlled by a
1015      * mask.
1016      * <p>
1017      * This is a vector binary operation where the primitive logical right shift
1018      * operation ({@code >>>}) is applied to lane elements.
1019      *
1020      * @param s the input scalar; the number of the bits to right shift

1021      * @return the result of logically right shifting this vector by the
1022      * broadcast of an input scalar
1023      */
1024     public abstract IntVector shiftR(int s, Mask<Integer> m);
1025 
1026     /**
1027      * Logically right shifts (or unsigned right shifts) this vector by an
1028      * input vector.
1029      * <p>
1030      * This is a vector binary operation where the primitive logical right shift
1031      * operation ({@code >>>}) is applied to lane elements.
1032      *
1033      * @param v the input vector
1034      * @return the result of logically right shifting this vector by the
1035      * input vector
1036      */
1037     public abstract IntVector shiftR(Vector<Integer> v);
1038 
1039     /**
1040      * Logically right shifts (or unsigned right shifts) this vector by an


1182      */
1183     @ForceInline
1184     public final IntVector rotateR(int s, Mask<Integer> m) {
1185         return shiftR(s, m).or(shiftL(-s, m), m);
1186     }
1187 
1188     @Override
1189     public abstract void intoByteArray(byte[] a, int ix);
1190 
1191     @Override
1192     public abstract void intoByteArray(byte[] a, int ix, Mask<Integer> m);
1193 
1194     @Override
1195     public abstract void intoByteBuffer(ByteBuffer bb, int ix);
1196 
1197     @Override
1198     public abstract void intoByteBuffer(ByteBuffer bb, int ix, Mask<Integer> m);
1199 
1200 
1201     // Type specific horizontal reductions
1202 
1203     /**
1204      * Adds all lane elements of this vector.
1205      * <p>
1206      * This is an associative vector reduction operation where the addition
1207      * operation ({@code +}) is applied to lane elements,
1208      * and the identity value is {@code 0}.
1209      *
1210      * @return the addition of all the lane elements of this vector
1211      */
1212     public abstract int addAll();
1213 
1214     /**
1215      * Adds all lane elements of this vector, selecting lane elements
1216      * controlled by a mask.
1217      * <p>
1218      * This is an associative vector reduction operation where the addition
1219      * operation ({@code +}) is applied to lane elements,
1220      * and the identity value is {@code 0}.
1221      *
1222      * @param m the mask controlling lane selection
1223      * @return the addition of all the lane elements of this vector
1224      */
1225     public abstract int addAll(Mask<Integer> m);
1226 
1227     /**
1228      * Subtracts all lane elements of this vector.
1229      * <p>
1230      * This is an associative vector reduction operation where the subtraction
1231      * operation ({@code -}) is applied to lane elements,
1232      * and the identity value is {@code 0}.
1233      *
1234      * @return the subtraction of all the lane elements of this vector
1235      */
1236     public abstract int subAll();
1237 
1238     /**
1239      * Subtracts all lane elements of this vector, selecting lane elements
1240      * controlled by a mask.
1241      * <p>
1242      * This is an associative vector reduction operation where the subtraction
1243      * operation ({@code -}) is applied to lane elements,
1244      * and the identity value is {@code 0}.
1245      *
1246      * @param m the mask controlling lane selection
1247      * @return the subtraction of all the lane elements of this vector
1248      */
1249     public abstract int subAll(Mask<Integer> m);
1250 
1251     /**
1252      * Multiplies all lane elements of this vector.
1253      * <p>
1254      * This is an associative vector reduction operation where the
1255      * multiplication operation ({@code *}) is applied to lane elements,
1256      * and the identity value is {@code 1}.
1257      *
1258      * @return the multiplication of all the lane elements of this vector
1259      */
1260     public abstract int mulAll();
1261 
1262     /**
1263      * Multiplies all lane elements of this vector, selecting lane elements
1264      * controlled by a mask.
1265      * <p>
1266      * This is an associative vector reduction operation where the
1267      * multiplication operation ({@code *}) is applied to lane elements,
1268      * and the identity value is {@code 1}.
1269      *
1270      * @param m the mask controlling lane selection
1271      * @return the multiplication of all the lane elements of this vector
1272      */
1273     public abstract int mulAll(Mask<Integer> m);
1274 
1275     /**
1276      * Returns the minimum lane element of this vector.
1277      * <p>
1278      * This is an associative vector reduction operation where the operation
1279      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1280      * and the identity value is {@link Integer#MAX_VALUE}.

1281      *
1282      * @return the minimum lane element of this vector
1283      */
1284     public abstract int minAll();
1285 
1286     /**
1287      * Returns the minimum lane element of this vector, selecting lane elements
1288      * controlled by a mask.
1289      * <p>
1290      * This is an associative vector reduction operation where the operation
1291      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1292      * and the identity value is {@link Integer#MAX_VALUE}.

1293      *
1294      * @param m the mask controlling lane selection
1295      * @return the minimum lane element of this vector
1296      */
1297     public abstract int minAll(Mask<Integer> m);
1298 
1299     /**
1300      * Returns the maximum lane element of this vector.
1301      * <p>
1302      * This is an associative vector reduction operation where the operation
1303      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1304      * and the identity value is {@link Integer#MIN_VALUE}.

1305      *
1306      * @return the maximum lane element of this vector
1307      */
1308     public abstract int maxAll();
1309 
1310     /**
1311      * Returns the maximum lane element of this vector, selecting lane elements
1312      * controlled by a mask.
1313      * <p>
1314      * This is an associative vector reduction operation where the operation
1315      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1316      * and the identity value is {@link Integer#MIN_VALUE}.

1317      *
1318      * @param m the mask controlling lane selection
1319      * @return the maximum lane element of this vector
1320      */
1321     public abstract int maxAll(Mask<Integer> m);
1322 
1323     /**
1324      * Logically ORs all lane elements of this vector.
1325      * <p>
1326      * This is an associative vector reduction operation where the logical OR
1327      * operation ({@code |}) is applied to lane elements,
1328      * and the identity value is {@code 0}.
1329      *
1330      * @return the logical OR all the lane elements of this vector
1331      */
1332     public abstract int orAll();
1333 
1334     /**
1335      * Logically ORs all lane elements of this vector, selecting lane elements
1336      * controlled by a mask.


1563 
1564         /**
1565          * Returns a vector where the first lane element is set to the primtive
1566          * value {@code e}, all other lane elements are set to the default
1567          * value.
1568          *
1569          * @param e the value
1570          * @return a vector where the first lane element is set to the primitive
1571          * value {@code e}
1572          */
1573         @ForceInline
1574         public final IntVector single(int e) {
1575             return zero().with(0, e);
1576         }
1577 
1578         /**
1579          * Returns a vector where each lane element is set to a randomly
1580          * generated primitive value.
1581          *
1582          * The semantics are equivalent to calling
1583          * {@link (int)ThreadLocalRandom#nextInt() }
1584          *
1585          * @return a vector where each lane elements is set to a randomly
1586          * generated primitive value
1587          */
1588         public IntVector random() {
1589             ThreadLocalRandom r = ThreadLocalRandom.current();
1590             return op(i -> r.nextInt());
1591         }
1592 
1593         /**
1594          * Returns a vector where each lane element is set to a given
1595          * primitive value.
1596          * <p>
1597          * For each vector lane, where {@code N} is the vector lane index, the
1598          * the primitive value at index {@code N} is placed into the resulting
1599          * vector at lane index {@code N}.
1600          *
1601          * @param es the given primitive values
1602          * @return a vector where each lane element is set to a given primitive
1603          * value




  88     }
  89 
  90     abstract Mask<Integer> bTest(Vector<Integer> v, FBinTest f);
  91 
  92     // Foreach
  93 
  94     interface FUnCon {
  95         void apply(int i, int a);
  96     }
  97 
  98     abstract void forEach(FUnCon f);
  99 
 100     abstract void forEach(Mask<Integer> 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 IntVector zero(IntSpecies 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(IntSpecies, 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 IntVector fromByteArray(IntSpecies 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<IntVector>) species.boxType(), int.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                                          IntBuffer tb = bbc.asIntBuffer();
 148                                          return ((IntSpecies)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(IntSpecies, 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 IntVector fromByteArray(IntSpecies species, byte[] a, int ix, Mask<Integer> 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 IntVector fromArray(IntSpecies species, int[] a, int i){
 201         Objects.requireNonNull(a);
 202         i = VectorIntrinsics.checkIndex(i, a.length, species.length());
 203         return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
 204                                      a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET,
 205                                      a, i, species,
 206                                      (c, idx, s) -> ((IntSpecies)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 IntVector fromArray(IntSpecies species, int[] a, int i, Mask<Integer> 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     @ForceInline
 255     @SuppressWarnings("unchecked")
 256     public static IntVector fromArray(IntSpecies species, int[] a, int i, int[] indexMap, int j) {
 257         Objects.requireNonNull(a);
 258         Objects.requireNonNull(indexMap);
 259 
 260 
 261         // Index vector: vix[0:n] = k -> i + indexMap[j + i]
 262         IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i);
 263 
 264         vix = VectorIntrinsics.checkIndex(vix, a.length);
 265 
 266         return VectorIntrinsics.loadWithMap((Class<IntVector>) species.boxType(), int.class, species.length(),
 267                                             species.indexSpecies().vectorType(), a, Unsafe.ARRAY_INT_BASE_OFFSET, vix,
 268                                             a, i, indexMap, j, species,
 269                                            (c, idx, iMap, idy, s) -> ((IntSpecies)s).op(n -> c[idx + iMap[idy+n]]));
 270         }
 271 
 272     /**
 273      * Loads a vector from an array using indexes obtained from an index
 274      * map and using a mask.
 275      * <p>
 276      * For each vector lane, where {@code N} is the vector lane index,
 277      * if the mask lane at index {@code N} is set then the array element at
 278      * index {@code i + indexMap[j + N]} is placed into the resulting vector
 279      * at lane index {@code N}.
 280      *
 281      * @param species species of desired vector
 282      * @param a the array
 283      * @param i the offset into the array, may be negative if relative
 284      * indexes in the index map compensate to produce a value within the
 285      * array bounds
 286      * @param m the mask
 287      * @param indexMap the index map
 288      * @param j the offset into the index map
 289      * @return the vector loaded from an array
 290      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 291      * {@code j > indexMap.length - this.length()},
 292      * or for any vector lane index {@code N} where the mask at lane
 293      * {@code N} is set the result of {@code i + indexMap[j + N]} is
 294      * {@code < 0} or {@code >= a.length}
 295      */
 296     @ForceInline
 297     @SuppressWarnings("unchecked")
 298     public static IntVector fromArray(IntSpecies species, int[] a, int i, Mask<Integer> m, int[] indexMap, int j) {
 299         // @@@ This can result in out of bounds errors for unset mask lanes
 300         return zero(species).blend(fromArray(species, a, i, indexMap, j), m);
 301     }
 302 
 303 
 304     /**
 305      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 306      * offset into the byte buffer.
 307      * <p>
 308      * Bytes are composed into primitive lane elements according to the
 309      * native byte order of the underlying platform.
 310      * <p>
 311      * This method behaves as if it returns the result of calling the
 312      * byte buffer, offset, and mask accepting
 313      * {@link #fromByteBuffer(IntSpecies, ByteBuffer, int, Mask)} method} as follows:
 314      * <pre>{@code
 315      *   return this.fromByteBuffer(b, i, this.maskAllTrue())
 316      * }</pre>
 317      *
 318      * @param species species of desired vector
 319      * @param bb the byte buffer
 320      * @param ix the offset into the byte buffer
 321      * @return a vector loaded from a byte buffer
 322      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 323      * or {@code > b.limit()},
 324      * or if there are fewer than
 325      * {@code this.length() * this.elementSize() / Byte.SIZE} bytes
 326      * remaining in the byte buffer from the given offset
 327      */
 328     @ForceInline
 329     @SuppressWarnings("unchecked")
 330     public static IntVector fromByteBuffer(IntSpecies species, ByteBuffer bb, int ix) {
 331         if (bb.order() != ByteOrder.nativeOrder()) {
 332             throw new IllegalArgumentException();
 333         }
 334         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE);
 335         return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
 336                                      U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
 337                                      bb, ix, species,
 338                                      (c, idx, s) -> {


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


1119      * broadcast of an input scalar.
1120      * <p>
1121      * This is a vector binary operation where the primitive logical right shift
1122      * operation ({@code >>>}) is applied to lane elements.
1123      *
1124      * @param s the input scalar; the number of the bits to right shift
1125      * @return the result of logically right shifting this vector by the
1126      * broadcast of an input scalar
1127      */
1128     public abstract IntVector shiftR(int s);
1129 
1130     /**
1131      * Logically right shifts (or unsigned right shifts) this vector by the
1132      * broadcast of an input scalar, selecting lane elements controlled by a
1133      * mask.
1134      * <p>
1135      * This is a vector binary operation where the primitive logical right shift
1136      * operation ({@code >>>}) is applied to lane elements.
1137      *
1138      * @param s the input scalar; the number of the bits to right shift
1139      * @param m the mask controlling lane selection
1140      * @return the result of logically right shifting this vector by the
1141      * broadcast of an input scalar
1142      */
1143     public abstract IntVector shiftR(int s, Mask<Integer> m);
1144 
1145     /**
1146      * Logically right shifts (or unsigned right shifts) this vector by an
1147      * input vector.
1148      * <p>
1149      * This is a vector binary operation where the primitive logical right shift
1150      * operation ({@code >>>}) is applied to lane elements.
1151      *
1152      * @param v the input vector
1153      * @return the result of logically right shifting this vector by the
1154      * input vector
1155      */
1156     public abstract IntVector shiftR(Vector<Integer> v);
1157 
1158     /**
1159      * Logically right shifts (or unsigned right shifts) this vector by an


1301      */
1302     @ForceInline
1303     public final IntVector rotateR(int s, Mask<Integer> m) {
1304         return shiftR(s, m).or(shiftL(-s, m), m);
1305     }
1306 
1307     @Override
1308     public abstract void intoByteArray(byte[] a, int ix);
1309 
1310     @Override
1311     public abstract void intoByteArray(byte[] a, int ix, Mask<Integer> m);
1312 
1313     @Override
1314     public abstract void intoByteBuffer(ByteBuffer bb, int ix);
1315 
1316     @Override
1317     public abstract void intoByteBuffer(ByteBuffer bb, int ix, Mask<Integer> m);
1318 
1319 
1320     // Type specific horizontal reductions

1321     /**
1322      * Adds all lane elements of this vector.
1323      * <p>
1324      * This is an associative vector reduction operation where the addition
1325      * operation ({@code +}) is applied to lane elements,
1326      * and the identity value is {@code 0}.
1327      *
1328      * @return the addition of all the lane elements of this vector
1329      */
1330     public abstract int addAll();
1331 
1332     /**
1333      * Adds all lane elements of this vector, selecting lane elements
1334      * controlled by a mask.
1335      * <p>
1336      * This is an associative vector reduction operation where the addition
1337      * operation ({@code +}) is applied to lane elements,
1338      * and the identity value is {@code 0}.
1339      *
1340      * @param m the mask controlling lane selection
1341      * @return the addition of the selected lane elements of this vector
1342      */
1343     public abstract int addAll(Mask<Integer> m);
1344 
1345     /**
























1346      * Multiplies all lane elements of this vector.
1347      * <p>
1348      * This is an associative vector reduction operation where the
1349      * multiplication operation ({@code *}) is applied to lane elements,
1350      * and the identity value is {@code 1}.
1351      *
1352      * @return the multiplication of all the lane elements of this vector
1353      */
1354     public abstract int mulAll();
1355 
1356     /**
1357      * Multiplies all lane elements of this vector, selecting lane elements
1358      * controlled by a mask.
1359      * <p>
1360      * This is an associative vector reduction operation where the
1361      * multiplication operation ({@code *}) is applied to lane elements,
1362      * and the identity value is {@code 1}.
1363      *
1364      * @param m the mask controlling lane selection
1365      * @return the multiplication of all the lane elements of this vector
1366      */
1367     public abstract int mulAll(Mask<Integer> m);
1368 
1369     /**
1370      * Returns the minimum lane element of this vector.
1371      * <p>
1372      * This is an associative vector reduction operation where the operation
1373      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1374      * and the identity value is
1375      * {@link Integer#MAX_VALUE}.
1376      *
1377      * @return the minimum lane element of this vector
1378      */
1379     public abstract int minAll();
1380 
1381     /**
1382      * Returns the minimum lane element of this vector, selecting lane elements
1383      * controlled by a mask.
1384      * <p>
1385      * This is an associative vector reduction operation where the operation
1386      * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
1387      * and the identity value is
1388      * {@link Integer#MAX_VALUE}.
1389      *
1390      * @param m the mask controlling lane selection
1391      * @return the minimum lane element of this vector
1392      */
1393     public abstract int minAll(Mask<Integer> m);
1394 
1395     /**
1396      * Returns the maximum lane element of this vector.
1397      * <p>
1398      * This is an associative vector reduction operation where the operation
1399      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1400      * and the identity value is
1401      * {@link Integer#MIN_VALUE}.
1402      *
1403      * @return the maximum lane element of this vector
1404      */
1405     public abstract int maxAll();
1406 
1407     /**
1408      * Returns the maximum lane element of this vector, selecting lane elements
1409      * controlled by a mask.
1410      * <p>
1411      * This is an associative vector reduction operation where the operation
1412      * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
1413      * and the identity value is
1414      * {@link Integer#MIN_VALUE}.
1415      *
1416      * @param m the mask controlling lane selection
1417      * @return the maximum lane element of this vector
1418      */
1419     public abstract int maxAll(Mask<Integer> m);
1420 
1421     /**
1422      * Logically ORs all lane elements of this vector.
1423      * <p>
1424      * This is an associative vector reduction operation where the logical OR
1425      * operation ({@code |}) is applied to lane elements,
1426      * and the identity value is {@code 0}.
1427      *
1428      * @return the logical OR all the lane elements of this vector
1429      */
1430     public abstract int orAll();
1431 
1432     /**
1433      * Logically ORs all lane elements of this vector, selecting lane elements
1434      * controlled by a mask.


1661 
1662         /**
1663          * Returns a vector where the first lane element is set to the primtive
1664          * value {@code e}, all other lane elements are set to the default
1665          * value.
1666          *
1667          * @param e the value
1668          * @return a vector where the first lane element is set to the primitive
1669          * value {@code e}
1670          */
1671         @ForceInline
1672         public final IntVector single(int e) {
1673             return zero().with(0, e);
1674         }
1675 
1676         /**
1677          * Returns a vector where each lane element is set to a randomly
1678          * generated primitive value.
1679          *
1680          * The semantics are equivalent to calling
1681          * {@code (int)ThreadLocalRandom#nextInt()}.
1682          *
1683          * @return a vector where each lane elements is set to a randomly
1684          * generated primitive value
1685          */
1686         public IntVector random() {
1687             ThreadLocalRandom r = ThreadLocalRandom.current();
1688             return op(i -> r.nextInt());
1689         }
1690 
1691         /**
1692          * Returns a vector where each lane element is set to a given
1693          * primitive value.
1694          * <p>
1695          * For each vector lane, where {@code N} is the vector lane index, the
1696          * the primitive value at index {@code N} is placed into the resulting
1697          * vector at lane index {@code N}.
1698          *
1699          * @param es the given primitive values
1700          * @return a vector where each lane element is set to a given primitive
1701          * value


< prev index next >