< prev index next >

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

Print this page




  95     interface FUnCon {
  96         void apply(int i, int a);
  97     }
  98 
  99     abstract void forEach(FUnCon f);
 100 
 101     abstract void forEach(VectorMask<Integer> m, FUnCon f);
 102 
 103     // Static factories
 104 
 105     /**
 106      * Returns a vector where all lane elements are set to the default
 107      * primitive value.
 108      *
 109      * @param species species of desired vector
 110      * @return a zero vector of given species
 111      */
 112     @ForceInline
 113     @SuppressWarnings("unchecked")
 114     public static IntVector zero(VectorSpecies<Integer> species) {
 115         return VectorIntrinsics.broadcastCoerced((Class<IntVector>) species.boxType(), int.class, species.length(),
 116                                                  0, species,
 117                                                  ((bits, s) -> ((IntSpecies)s).op(i -> (int)bits)));
 118     }
 119 
 120     /**
 121      * Loads a vector from a byte array starting at an offset.
 122      * <p>
 123      * Bytes are composed into primitive lane elements according to the
 124      * native byte order of the underlying platform
 125      * <p>
 126      * This method behaves as if it returns the result of calling the
 127      * byte buffer, offset, and mask accepting
 128      * {@link #fromByteBuffer(VectorSpecies, ByteBuffer, int, VectorMask) method} as follows:
 129      * <pre>{@code
 130      * return fromByteBuffer(species, ByteBuffer.wrap(a), offset, VectorMask.allTrue());
 131      * }</pre>
 132      *
 133      * @param species species of desired vector
 134      * @param a the byte array
 135      * @param offset the offset into the array
 136      * @return a vector loaded from a byte array
 137      * @throws IndexOutOfBoundsException if {@code i < 0} or
 138      * {@code offset > a.length - (species.length() * species.elementSize() / Byte.SIZE)}
 139      */
 140     @ForceInline
 141     @SuppressWarnings("unchecked")
 142     public static IntVector fromByteArray(VectorSpecies<Integer> species, byte[] a, int offset) {
 143         Objects.requireNonNull(a);
 144         offset = VectorIntrinsics.checkIndex(offset, a.length, species.bitSize() / Byte.SIZE);
 145         return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
 146                                      a, ((long) offset) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 147                                      a, offset, species,
 148                                      (c, idx, s) -> {
 149                                          ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
 150                                          IntBuffer tb = bbc.asIntBuffer();
 151                                          return ((IntSpecies)s).op(i -> tb.get());
 152                                      });
 153     }
 154 
 155     /**
 156      * Loads a vector from a byte array starting at an offset and using a
 157      * mask.
 158      * <p>
 159      * Bytes are composed into primitive lane elements according to the
 160      * native byte order of the underlying platform.
 161      * <p>
 162      * This method behaves as if it returns the result of calling the
 163      * byte buffer, offset, and mask accepting
 164      * {@link #fromByteBuffer(VectorSpecies, ByteBuffer, int, VectorMask) method} as follows:
 165      * <pre>{@code


 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 offset + 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 offset the offset into the array
 194      * @return the vector loaded from an array
 195      * @throws IndexOutOfBoundsException if {@code offset < 0}, or
 196      * {@code offset > a.length - species.length()}
 197      */
 198     @ForceInline
 199     @SuppressWarnings("unchecked")
 200     public static IntVector fromArray(VectorSpecies<Integer> species, int[] a, int offset){
 201         Objects.requireNonNull(a);
 202         offset = VectorIntrinsics.checkIndex(offset, a.length, species.length());
 203         return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
 204                                      a, (((long) offset) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET,
 205                                      a, offset, 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 offset + 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 offset the offset into the array
 222      * @param m the mask
 223      * @return the vector loaded from an array


 246      * @param indexMap the index map
 247      * @param i_offset the offset into the index map
 248      * @return the vector loaded from an array
 249      * @throws IndexOutOfBoundsException if {@code i_offset < 0}, or
 250      * {@code i_offset > indexMap.length - species.length()},
 251      * or for any vector lane index {@code N} the result of
 252      * {@code a_offset + indexMap[i_offset + N]} is {@code < 0} or {@code >= a.length}
 253      */
 254     @ForceInline
 255     @SuppressWarnings("unchecked")
 256     public static IntVector fromArray(VectorSpecies<Integer> species, int[] a, int a_offset, int[] indexMap, int i_offset) {
 257         Objects.requireNonNull(a);
 258         Objects.requireNonNull(indexMap);
 259 
 260 
 261         // Index vector: vix[0:n] = k -> a_offset + indexMap[i_offset + k]
 262         IntVector vix = IntVector.fromArray(IntVector.species(species.indexShape()), indexMap, i_offset).add(a_offset);
 263 
 264         vix = VectorIntrinsics.checkIndex(vix, a.length);
 265 
 266         return VectorIntrinsics.loadWithMap((Class<IntVector>) species.boxType(), int.class, species.length(),
 267                                             IntVector.species(species.indexShape()).boxType(), a, Unsafe.ARRAY_INT_BASE_OFFSET, vix,
 268                                             a, a_offset, indexMap, i_offset, species,
 269                                             (int[] c, int idx, int[] iMap, int idy, VectorSpecies<Integer> s) ->
 270                                                 ((IntSpecies)s).op(n -> c[idx + iMap[idy+n]]));
 271         }
 272 
 273     /**
 274      * Loads a vector from an array using indexes obtained from an index
 275      * map and using a mask.
 276      * <p>
 277      * For each vector lane, where {@code N} is the vector lane index,
 278      * if the mask lane at index {@code N} is set then the array element at
 279      * index {@code a_offset + indexMap[i_offset + N]} is placed into the resulting vector
 280      * at lane index {@code N}.
 281      *
 282      * @param species species of desired vector
 283      * @param a the array
 284      * @param a_offset the offset into the array, may be negative if relative
 285      * indexes in the index map compensate to produce a value within the
 286      * array bounds
 287      * @param m the mask


 316      *   return fromByteBuffer(b, offset, VectorMask.allTrue())
 317      * }</pre>
 318      *
 319      * @param species species of desired vector
 320      * @param bb the byte buffer
 321      * @param offset the offset into the byte buffer
 322      * @return a vector loaded from a byte buffer
 323      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 324      * or {@code > b.limit()},
 325      * or if there are fewer than
 326      * {@code species.length() * species.elementSize() / Byte.SIZE} bytes
 327      * remaining in the byte buffer from the given offset
 328      */
 329     @ForceInline
 330     @SuppressWarnings("unchecked")
 331     public static IntVector fromByteBuffer(VectorSpecies<Integer> species, ByteBuffer bb, int offset) {
 332         if (bb.order() != ByteOrder.nativeOrder()) {
 333             throw new IllegalArgumentException();
 334         }
 335         offset = VectorIntrinsics.checkIndex(offset, bb.limit(), species.bitSize() / Byte.SIZE);
 336         return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
 337                                      U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + offset,
 338                                      bb, offset, species,
 339                                      (c, idx, s) -> {
 340                                          ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 341                                          IntBuffer tb = bbc.asIntBuffer();
 342                                          return ((IntSpecies)s).op(i -> tb.get());
 343                                      });
 344     }
 345 
 346     /**
 347      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 348      * offset into the byte buffer and using a mask.
 349      * <p>
 350      * This method behaves as if the byte buffer is viewed as a primitive
 351      * {@link java.nio.Buffer buffer} for the primitive element type,
 352      * according to the native byte order of the underlying platform, and
 353      * the returned vector is loaded with a mask from a primitive array
 354      * obtained from the primitive buffer.
 355      * The following pseudocode expresses the behaviour, where
 356      * {@code EBuffer} is the primitive buffer type, {@code e} is the


 380      * {@code offset >= b.limit() - (N * species.elementSize() / Byte.SIZE)}
 381      */
 382     @ForceInline
 383     public static IntVector fromByteBuffer(VectorSpecies<Integer> species, ByteBuffer bb, int offset, VectorMask<Integer> m) {
 384         return zero(species).blend(fromByteBuffer(species, bb, offset), m);
 385     }
 386 
 387     /**
 388      * Returns a vector where all lane elements are set to the primitive
 389      * value {@code e}.
 390      *
 391      * @param species species of the desired vector
 392      * @param e the value
 393      * @return a vector of vector where all lane elements are set to
 394      * the primitive value {@code e}
 395      */
 396     @ForceInline
 397     @SuppressWarnings("unchecked")
 398     public static IntVector broadcast(VectorSpecies<Integer> species, int e) {
 399         return VectorIntrinsics.broadcastCoerced(
 400             (Class<IntVector>) species.boxType(), int.class, species.length(),
 401             e, species,
 402             ((bits, sp) -> ((IntSpecies)sp).op(i -> (int)bits)));
 403     }
 404 
 405     /**
 406      * Returns a vector where each lane element is set to given
 407      * primitive values.
 408      * <p>
 409      * For each vector lane, where {@code N} is the vector lane index, the
 410      * the primitive value at index {@code N} is placed into the resulting
 411      * vector at lane index {@code N}.
 412      *
 413      * @param species species of the desired vector
 414      * @param es the given primitive values
 415      * @return a vector where each lane element is set to given primitive
 416      * values
 417      * @throws IndexOutOfBoundsException if {@code es.length < species.length()}
 418      */
 419     @ForceInline
 420     @SuppressWarnings("unchecked")
 421     public static IntVector scalars(VectorSpecies<Integer> species, int... es) {
 422         Objects.requireNonNull(es);
 423         int ix = VectorIntrinsics.checkIndex(0, es.length, species.length());
 424         return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
 425                                      es, Unsafe.ARRAY_INT_BASE_OFFSET,
 426                                      es, ix, species,
 427                                      (c, idx, sp) -> ((IntSpecies)sp).op(n -> c[idx + n]));
 428     }
 429 
 430     /**
 431      * Returns a vector where the first lane element is set to the primtive
 432      * value {@code e}, all other lane elements are set to the default
 433      * value.
 434      *
 435      * @param species species of the desired vector
 436      * @param e the value
 437      * @return a vector where the first lane element is set to the primitive
 438      * value {@code e}
 439      */
 440     @ForceInline
 441     public static final IntVector single(VectorSpecies<Integer> species, int e) {
 442         return zero(species).with(0, e);
 443     }
 444 


 782     @Override
 783     public abstract IntVector rearrange(Vector<Integer> v,
 784                                                       VectorShuffle<Integer> s, VectorMask<Integer> m);
 785 
 786     /**
 787      * {@inheritDoc}
 788      */
 789     @Override
 790     public abstract IntVector rearrange(VectorShuffle<Integer> m);
 791 
 792     /**
 793      * {@inheritDoc}
 794      */
 795     @Override
 796     public abstract IntVector reshape(VectorSpecies<Integer> s);
 797 
 798     /**
 799      * {@inheritDoc}
 800      */
 801     @Override
 802     public abstract IntVector rotateEL(int i);
 803 
 804     /**
 805      * {@inheritDoc}
 806      */
 807     @Override
 808     public abstract IntVector rotateER(int i);
 809 
 810     /**
 811      * {@inheritDoc}
 812      */
 813     @Override
 814     public abstract IntVector shiftEL(int i);
 815 
 816     /**
 817      * {@inheritDoc}
 818      */
 819     @Override
 820     public abstract IntVector shiftER(int i);
 821 
 822 
 823 
 824     /**
 825      * Bitwise ANDs this vector with an input vector.
 826      * <p>
 827      * This is a lane-wise binary operation which applies the primitive bitwise AND
 828      * operation ({@code &}) to each lane.
 829      *
 830      * @param v the input vector
 831      * @return the bitwise AND of this vector with the input vector
 832      */
 833     public abstract IntVector and(Vector<Integer> v);
 834 
 835     /**
 836      * Bitwise ANDs this vector with the broadcast of an input scalar.
 837      * <p>
 838      * This is a lane-wise binary operation which applies the primitive bitwise AND
 839      * operation ({@code &}) to each lane.
 840      *


 979      *
 980      * @return the bitwise NOT of this vector
 981      */
 982     public abstract IntVector not();
 983 
 984     /**
 985      * Bitwise NOTs this vector, selecting lane elements controlled by a mask.
 986      * <p>
 987      * This is a lane-wise unary operation which applies the primitive bitwise NOT
 988      * operation ({@code ~}) to each lane.
 989      *
 990      * @param m the mask controlling lane selection
 991      * @return the bitwise NOT of this vector
 992      */
 993     public abstract IntVector not(VectorMask<Integer> m);
 994 
 995     /**
 996      * Logically left shifts this vector by the broadcast of an input scalar.
 997      * <p>
 998      * This is a lane-wise binary operation which applies the primitive logical left shift
 999      * operation ({@code <<}) to each lane.

1000      *
1001      * @param s the input scalar; the number of the bits to left shift
1002      * @return the result of logically left shifting left this vector by the
1003      * broadcast of an input scalar
1004      */
1005     public abstract IntVector shiftL(int s);
1006 
1007     /**
1008      * Logically left shifts this vector by the broadcast of an input scalar,
1009      * selecting lane elements controlled by a mask.
1010      * <p>
1011      * This is a lane-wise binary operation which applies the primitive logical left shift
1012      * operation ({@code <<}) to each lane.

1013      *
1014      * @param s the input scalar; the number of the bits to left shift
1015      * @param m the mask controlling lane selection
1016      * @return the result of logically left shifting this vector by the
1017      * broadcast of an input scalar
1018      */
1019     public abstract IntVector shiftL(int s, VectorMask<Integer> m);
1020 
1021     /**
1022      * Logically left shifts this vector by an input vector.
1023      * <p>
1024      * This is a lane-wise binary operation which applies the primitive logical left shift
1025      * operation ({@code <<}) to each lane.

1026      *
1027      * @param v the input vector
1028      * @return the result of logically left shifting this vector by the input
1029      * vector
1030      */
1031     public abstract IntVector shiftL(Vector<Integer> v);
1032 
1033     /**
1034      * Logically left shifts this vector by an input vector, selecting lane
1035      * elements controlled by a mask.
1036      * <p>
1037      * This is a lane-wise binary operation which applies the primitive logical left shift
1038      * operation ({@code <<}) to each lane.

1039      *
1040      * @param v the input vector
1041      * @param m the mask controlling lane selection
1042      * @return the result of logically left shifting this vector by the input
1043      * vector
1044      */
1045     public IntVector shiftL(Vector<Integer> v, VectorMask<Integer> m) {
1046         return bOp(v, m, (i, a, b) -> (int) (a << b));
1047     }
1048 
1049     // logical, or unsigned, shift right
1050 
1051     /**
1052      * Logically right shifts (or unsigned right shifts) this vector by the
1053      * broadcast of an input scalar.
1054      * <p>
1055      * This is a lane-wise binary operation which applies the primitive logical right shift
1056      * operation ({@code >>>}) to each lane.

1057      *
1058      * @param s the input scalar; the number of the bits to right shift
1059      * @return the result of logically right shifting this vector by the
1060      * broadcast of an input scalar
1061      */
1062     public abstract IntVector shiftR(int s);
1063 
1064     /**
1065      * Logically right shifts (or unsigned right shifts) this vector by the
1066      * broadcast of an input scalar, selecting lane elements controlled by a
1067      * mask.
1068      * <p>
1069      * This is a lane-wise binary operation which applies the primitive logical right shift
1070      * operation ({@code >>>}) to each lane.

1071      *
1072      * @param s the input scalar; the number of the bits to right shift
1073      * @param m the mask controlling lane selection
1074      * @return the result of logically right shifting this vector by the
1075      * broadcast of an input scalar
1076      */
1077     public abstract IntVector shiftR(int s, VectorMask<Integer> m);
1078 
1079     /**
1080      * Logically right shifts (or unsigned right shifts) this vector by an
1081      * input vector.
1082      * <p>
1083      * This is a lane-wise binary operation which applies the primitive logical right shift
1084      * operation ({@code >>>}) to each lane.

1085      *
1086      * @param v the input vector
1087      * @return the result of logically right shifting this vector by the
1088      * input vector
1089      */
1090     public abstract IntVector shiftR(Vector<Integer> v);
1091 
1092     /**
1093      * Logically right shifts (or unsigned right shifts) this vector by an
1094      * input vector, selecting lane elements controlled by a mask.
1095      * <p>
1096      * This is a lane-wise binary operation which applies the primitive logical right shift
1097      * operation ({@code >>>}) to each lane.

1098      *
1099      * @param v the input vector
1100      * @param m the mask controlling lane selection
1101      * @return the result of logically right shifting this vector by the
1102      * input vector
1103      */
1104     public IntVector shiftR(Vector<Integer> v, VectorMask<Integer> m) {
1105         return bOp(v, m, (i, a, b) -> (int) (a >>> b));
1106     }
1107 
1108     /**
1109      * Arithmetically right shifts (or signed right shifts) this vector by the
1110      * broadcast of an input scalar.
1111      * <p>
1112      * This is a lane-wise binary operation which applies the primitive arithmetic right
1113      * shift operation ({@code >>}) to each lane.

1114      *
1115      * @param s the input scalar; the number of the bits to right shift
1116      * @return the result of arithmetically right shifting this vector by the
1117      * broadcast of an input scalar
1118      */
1119     public abstract IntVector aShiftR(int s);
1120 
1121     /**
1122      * Arithmetically right shifts (or signed right shifts) this vector by the
1123      * broadcast of an input scalar, selecting lane elements controlled by a
1124      * mask.
1125      * <p>
1126      * This is a lane-wise binary operation which applies the primitive arithmetic right
1127      * shift operation ({@code >>}) to each lane.

1128      *
1129      * @param s the input scalar; the number of the bits to right shift
1130      * @param m the mask controlling lane selection
1131      * @return the result of arithmetically right shifting this vector by the
1132      * broadcast of an input scalar
1133      */
1134     public abstract IntVector aShiftR(int s, VectorMask<Integer> m);
1135 
1136     /**
1137      * Arithmetically right shifts (or signed right shifts) this vector by an
1138      * input vector.
1139      * <p>
1140      * This is a lane-wise binary operation which applies the primitive arithmetic right
1141      * shift operation ({@code >>}) to each lane.

1142      *
1143      * @param v the input vector
1144      * @return the result of arithmetically right shifting this vector by the
1145      * input vector
1146      */
1147     public abstract IntVector aShiftR(Vector<Integer> v);
1148 
1149     /**
1150      * Arithmetically right shifts (or signed right shifts) this vector by an
1151      * input vector, selecting lane elements controlled by a mask.
1152      * <p>
1153      * This is a lane-wise binary operation which applies the primitive arithmetic right
1154      * shift operation ({@code >>}) to each lane.

1155      *
1156      * @param v the input vector
1157      * @param m the mask controlling lane selection
1158      * @return the result of arithmetically right shifting this vector by the
1159      * input vector
1160      */
1161     public IntVector aShiftR(Vector<Integer> v, VectorMask<Integer> m) {
1162         return bOp(v, m, (i, a, b) -> (int) (a >> b));
1163     }
1164 
1165     /**
1166      * Rotates left this vector by the broadcast of an input scalar.
1167      * <p>
1168      * This is a lane-wise binary operation which applies the operation
1169      * {@link Integer#rotateLeft} to each lane and where
1170      * lane elements of this vector apply to the first argument, and lane
1171      * elements of the broadcast vector apply to the second argument (the
1172      * rotation distance).
1173      *
1174      * @param s the input scalar; the number of the bits to rotate left
1175      * @return the result of rotating left this vector by the broadcast of an
1176      * input scalar
1177      */
1178     @ForceInline
1179     public final IntVector rotateL(int s) {
1180         return shiftL(s).or(shiftR(-s));
1181     }
1182 
1183     /**
1184      * Rotates left this vector by the broadcast of an input scalar, selecting
1185      * lane elements controlled by a mask.
1186      * <p>
1187      * This is a lane-wise binary operation which applies the operation
1188      * {@link Integer#rotateLeft} to each lane and where
1189      * lane elements of this vector apply to the first argument, and lane
1190      * elements of the broadcast vector apply to the second argument (the
1191      * rotation distance).
1192      *
1193      * @param s the input scalar; the number of the bits to rotate left
1194      * @param m the mask controlling lane selection
1195      * @return the result of rotating left this vector by the broadcast of an
1196      * input scalar
1197      */
1198     @ForceInline
1199     public final IntVector rotateL(int s, VectorMask<Integer> m) {
1200         return shiftL(s, m).or(shiftR(-s, m), m);
1201     }
1202 
1203     /**
1204      * Rotates right this vector by the broadcast of an input scalar.
1205      * <p>
1206      * This is a lane-wise binary operation which applies the operation
1207      * {@link Integer#rotateRight} to each lane and where
1208      * lane elements of this vector apply to the first argument, and lane
1209      * elements of the broadcast vector apply to the second argument (the
1210      * rotation distance).
1211      *
1212      * @param s the input scalar; the number of the bits to rotate right
1213      * @return the result of rotating right this vector by the broadcast of an
1214      * input scalar
1215      */
1216     @ForceInline
1217     public final IntVector rotateR(int s) {
1218         return shiftR(s).or(shiftL(-s));
1219     }
1220 
1221     /**
1222      * Rotates right this vector by the broadcast of an input scalar, selecting
1223      * lane elements controlled by a mask.
1224      * <p>
1225      * This is a lane-wise binary operation which applies the operation
1226      * {@link Integer#rotateRight} to each lane and where
1227      * lane elements of this vector apply to the first argument, and lane
1228      * elements of the broadcast vector apply to the second argument (the
1229      * rotation distance).
1230      *
1231      * @param s the input scalar; the number of the bits to rotate right
1232      * @param m the mask controlling lane selection
1233      * @return the result of rotating right this vector by the broadcast of an
1234      * input scalar
1235      */
1236     @ForceInline
1237     public final IntVector rotateR(int s, VectorMask<Integer> m) {
1238         return shiftR(s, m).or(shiftL(-s, m), m);
1239     }
1240 
1241     /**
1242      * {@inheritDoc}
1243      */
1244     @Override
1245     public abstract void intoByteArray(byte[] a, int ix);
1246 
1247     /**
1248      * {@inheritDoc}
1249      */
1250     @Override
1251     public abstract void intoByteArray(byte[] a, int ix, VectorMask<Integer> m);
1252 
1253     /**
1254      * {@inheritDoc}
1255      */
1256     @Override
1257     public abstract void intoByteBuffer(ByteBuffer bb, int ix);
1258 


1560      * or for any vector lane index {@code N} where the mask at lane
1561      * {@code N} is set the result of {@code a_offset + indexMap[i_offset + N]} is
1562      * {@code < 0} or {@code >= a.length}
1563      */
1564     public abstract void intoArray(int[] a, int a_offset, VectorMask<Integer> m, int[] indexMap, int i_offset);
1565     // Species
1566 
1567     /**
1568      * {@inheritDoc}
1569      */
1570     @Override
1571     public abstract VectorSpecies<Integer> species();
1572 
1573     /**
1574      * Class representing {@link IntVector}'s of the same {@link VectorShape VectorShape}.
1575      */
1576     static final class IntSpecies extends AbstractSpecies<Integer> {
1577         final Function<int[], IntVector> vectorFactory;
1578 
1579         private IntSpecies(VectorShape shape,
1580                           Class<?> boxType,
1581                           Class<?> maskType,
1582                           Function<int[], IntVector> vectorFactory,
1583                           Function<boolean[], VectorMask<Integer>> maskFactory,
1584                           Function<IntUnaryOperator, VectorShuffle<Integer>> shuffleFromArrayFactory,
1585                           fShuffleFromArray<Integer> shuffleFromOpFactory) {
1586             super(shape, int.class, Integer.SIZE, boxType, maskType, maskFactory,
1587                   shuffleFromArrayFactory, shuffleFromOpFactory);
1588             this.vectorFactory = vectorFactory;
1589         }
1590 
1591         interface FOp {
1592             int apply(int i);
1593         }
1594 
1595         IntVector op(FOp f) {
1596             int[] res = new int[length()];
1597             for (int i = 0; i < length(); i++) {
1598                 res[i] = f.apply(i);
1599             }
1600             return vectorFactory.apply(res);
1601         }
1602 
1603         IntVector op(VectorMask<Integer> o, FOp f) {
1604             int[] res = new int[length()];
1605             boolean[] mbits = ((AbstractMask<Integer>)o).getBits();
1606             for (int i = 0; i < length(); i++) {




  95     interface FUnCon {
  96         void apply(int i, int a);
  97     }
  98 
  99     abstract void forEach(FUnCon f);
 100 
 101     abstract void forEach(VectorMask<Integer> m, FUnCon f);
 102 
 103     // Static factories
 104 
 105     /**
 106      * Returns a vector where all lane elements are set to the default
 107      * primitive value.
 108      *
 109      * @param species species of desired vector
 110      * @return a zero vector of given species
 111      */
 112     @ForceInline
 113     @SuppressWarnings("unchecked")
 114     public static IntVector zero(VectorSpecies<Integer> species) {
 115         return VectorIntrinsics.broadcastCoerced((Class<IntVector>) species.vectorType(), int.class, species.length(),
 116                                                  0, species,
 117                                                  ((bits, s) -> ((IntSpecies)s).op(i -> (int)bits)));
 118     }
 119 
 120     /**
 121      * Loads a vector from a byte array starting at an offset.
 122      * <p>
 123      * Bytes are composed into primitive lane elements according to the
 124      * native byte order of the underlying platform
 125      * <p>
 126      * This method behaves as if it returns the result of calling the
 127      * byte buffer, offset, and mask accepting
 128      * {@link #fromByteBuffer(VectorSpecies, ByteBuffer, int, VectorMask) method} as follows:
 129      * <pre>{@code
 130      * return fromByteBuffer(species, ByteBuffer.wrap(a), offset, VectorMask.allTrue());
 131      * }</pre>
 132      *
 133      * @param species species of desired vector
 134      * @param a the byte array
 135      * @param offset the offset into the array
 136      * @return a vector loaded from a byte array
 137      * @throws IndexOutOfBoundsException if {@code i < 0} or
 138      * {@code offset > a.length - (species.length() * species.elementSize() / Byte.SIZE)}
 139      */
 140     @ForceInline
 141     @SuppressWarnings("unchecked")
 142     public static IntVector fromByteArray(VectorSpecies<Integer> species, byte[] a, int offset) {
 143         Objects.requireNonNull(a);
 144         offset = VectorIntrinsics.checkIndex(offset, a.length, species.bitSize() / Byte.SIZE);
 145         return VectorIntrinsics.load((Class<IntVector>) species.vectorType(), int.class, species.length(),
 146                                      a, ((long) offset) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 147                                      a, offset, species,
 148                                      (c, idx, s) -> {
 149                                          ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
 150                                          IntBuffer tb = bbc.asIntBuffer();
 151                                          return ((IntSpecies)s).op(i -> tb.get());
 152                                      });
 153     }
 154 
 155     /**
 156      * Loads a vector from a byte array starting at an offset and using a
 157      * mask.
 158      * <p>
 159      * Bytes are composed into primitive lane elements according to the
 160      * native byte order of the underlying platform.
 161      * <p>
 162      * This method behaves as if it returns the result of calling the
 163      * byte buffer, offset, and mask accepting
 164      * {@link #fromByteBuffer(VectorSpecies, ByteBuffer, int, VectorMask) method} as follows:
 165      * <pre>{@code


 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 offset + 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 offset the offset into the array
 194      * @return the vector loaded from an array
 195      * @throws IndexOutOfBoundsException if {@code offset < 0}, or
 196      * {@code offset > a.length - species.length()}
 197      */
 198     @ForceInline
 199     @SuppressWarnings("unchecked")
 200     public static IntVector fromArray(VectorSpecies<Integer> species, int[] a, int offset){
 201         Objects.requireNonNull(a);
 202         offset = VectorIntrinsics.checkIndex(offset, a.length, species.length());
 203         return VectorIntrinsics.load((Class<IntVector>) species.vectorType(), int.class, species.length(),
 204                                      a, (((long) offset) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET,
 205                                      a, offset, 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 offset + 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 offset the offset into the array
 222      * @param m the mask
 223      * @return the vector loaded from an array


 246      * @param indexMap the index map
 247      * @param i_offset the offset into the index map
 248      * @return the vector loaded from an array
 249      * @throws IndexOutOfBoundsException if {@code i_offset < 0}, or
 250      * {@code i_offset > indexMap.length - species.length()},
 251      * or for any vector lane index {@code N} the result of
 252      * {@code a_offset + indexMap[i_offset + N]} is {@code < 0} or {@code >= a.length}
 253      */
 254     @ForceInline
 255     @SuppressWarnings("unchecked")
 256     public static IntVector fromArray(VectorSpecies<Integer> species, int[] a, int a_offset, int[] indexMap, int i_offset) {
 257         Objects.requireNonNull(a);
 258         Objects.requireNonNull(indexMap);
 259 
 260 
 261         // Index vector: vix[0:n] = k -> a_offset + indexMap[i_offset + k]
 262         IntVector vix = IntVector.fromArray(IntVector.species(species.indexShape()), indexMap, i_offset).add(a_offset);
 263 
 264         vix = VectorIntrinsics.checkIndex(vix, a.length);
 265 
 266         return VectorIntrinsics.loadWithMap((Class<IntVector>) species.vectorType(), int.class, species.length(),
 267                                             IntVector.species(species.indexShape()).vectorType(), a, Unsafe.ARRAY_INT_BASE_OFFSET, vix,
 268                                             a, a_offset, indexMap, i_offset, species,
 269                                             (int[] c, int idx, int[] iMap, int idy, VectorSpecies<Integer> s) ->
 270                                                 ((IntSpecies)s).op(n -> c[idx + iMap[idy+n]]));
 271         }
 272 
 273     /**
 274      * Loads a vector from an array using indexes obtained from an index
 275      * map and using a mask.
 276      * <p>
 277      * For each vector lane, where {@code N} is the vector lane index,
 278      * if the mask lane at index {@code N} is set then the array element at
 279      * index {@code a_offset + indexMap[i_offset + N]} is placed into the resulting vector
 280      * at lane index {@code N}.
 281      *
 282      * @param species species of desired vector
 283      * @param a the array
 284      * @param a_offset the offset into the array, may be negative if relative
 285      * indexes in the index map compensate to produce a value within the
 286      * array bounds
 287      * @param m the mask


 316      *   return fromByteBuffer(b, offset, VectorMask.allTrue())
 317      * }</pre>
 318      *
 319      * @param species species of desired vector
 320      * @param bb the byte buffer
 321      * @param offset the offset into the byte buffer
 322      * @return a vector loaded from a byte buffer
 323      * @throws IndexOutOfBoundsException if the offset is {@code < 0},
 324      * or {@code > b.limit()},
 325      * or if there are fewer than
 326      * {@code species.length() * species.elementSize() / Byte.SIZE} bytes
 327      * remaining in the byte buffer from the given offset
 328      */
 329     @ForceInline
 330     @SuppressWarnings("unchecked")
 331     public static IntVector fromByteBuffer(VectorSpecies<Integer> species, ByteBuffer bb, int offset) {
 332         if (bb.order() != ByteOrder.nativeOrder()) {
 333             throw new IllegalArgumentException();
 334         }
 335         offset = VectorIntrinsics.checkIndex(offset, bb.limit(), species.bitSize() / Byte.SIZE);
 336         return VectorIntrinsics.load((Class<IntVector>) species.vectorType(), int.class, species.length(),
 337                                      U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + offset,
 338                                      bb, offset, species,
 339                                      (c, idx, s) -> {
 340                                          ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 341                                          IntBuffer tb = bbc.asIntBuffer();
 342                                          return ((IntSpecies)s).op(i -> tb.get());
 343                                      });
 344     }
 345 
 346     /**
 347      * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
 348      * offset into the byte buffer and using a mask.
 349      * <p>
 350      * This method behaves as if the byte buffer is viewed as a primitive
 351      * {@link java.nio.Buffer buffer} for the primitive element type,
 352      * according to the native byte order of the underlying platform, and
 353      * the returned vector is loaded with a mask from a primitive array
 354      * obtained from the primitive buffer.
 355      * The following pseudocode expresses the behaviour, where
 356      * {@code EBuffer} is the primitive buffer type, {@code e} is the


 380      * {@code offset >= b.limit() - (N * species.elementSize() / Byte.SIZE)}
 381      */
 382     @ForceInline
 383     public static IntVector fromByteBuffer(VectorSpecies<Integer> species, ByteBuffer bb, int offset, VectorMask<Integer> m) {
 384         return zero(species).blend(fromByteBuffer(species, bb, offset), m);
 385     }
 386 
 387     /**
 388      * Returns a vector where all lane elements are set to the primitive
 389      * value {@code e}.
 390      *
 391      * @param species species of the desired vector
 392      * @param e the value
 393      * @return a vector of vector where all lane elements are set to
 394      * the primitive value {@code e}
 395      */
 396     @ForceInline
 397     @SuppressWarnings("unchecked")
 398     public static IntVector broadcast(VectorSpecies<Integer> species, int e) {
 399         return VectorIntrinsics.broadcastCoerced(
 400             (Class<IntVector>) species.vectorType(), int.class, species.length(),
 401             e, species,
 402             ((bits, sp) -> ((IntSpecies)sp).op(i -> (int)bits)));
 403     }
 404 
 405     /**
 406      * Returns a vector where each lane element is set to given
 407      * primitive values.
 408      * <p>
 409      * For each vector lane, where {@code N} is the vector lane index, the
 410      * the primitive value at index {@code N} is placed into the resulting
 411      * vector at lane index {@code N}.
 412      *
 413      * @param species species of the desired vector
 414      * @param es the given primitive values
 415      * @return a vector where each lane element is set to given primitive
 416      * values
 417      * @throws IndexOutOfBoundsException if {@code es.length < species.length()}
 418      */
 419     @ForceInline
 420     @SuppressWarnings("unchecked")
 421     public static IntVector scalars(VectorSpecies<Integer> species, int... es) {
 422         Objects.requireNonNull(es);
 423         int ix = VectorIntrinsics.checkIndex(0, es.length, species.length());
 424         return VectorIntrinsics.load((Class<IntVector>) species.vectorType(), int.class, species.length(),
 425                                      es, Unsafe.ARRAY_INT_BASE_OFFSET,
 426                                      es, ix, species,
 427                                      (c, idx, sp) -> ((IntSpecies)sp).op(n -> c[idx + n]));
 428     }
 429 
 430     /**
 431      * Returns a vector where the first lane element is set to the primtive
 432      * value {@code e}, all other lane elements are set to the default
 433      * value.
 434      *
 435      * @param species species of the desired vector
 436      * @param e the value
 437      * @return a vector where the first lane element is set to the primitive
 438      * value {@code e}
 439      */
 440     @ForceInline
 441     public static final IntVector single(VectorSpecies<Integer> species, int e) {
 442         return zero(species).with(0, e);
 443     }
 444 


 782     @Override
 783     public abstract IntVector rearrange(Vector<Integer> v,
 784                                                       VectorShuffle<Integer> s, VectorMask<Integer> m);
 785 
 786     /**
 787      * {@inheritDoc}
 788      */
 789     @Override
 790     public abstract IntVector rearrange(VectorShuffle<Integer> m);
 791 
 792     /**
 793      * {@inheritDoc}
 794      */
 795     @Override
 796     public abstract IntVector reshape(VectorSpecies<Integer> s);
 797 
 798     /**
 799      * {@inheritDoc}
 800      */
 801     @Override
 802     public abstract IntVector rotateLanesLeft(int i);
 803 
 804     /**
 805      * {@inheritDoc}
 806      */
 807     @Override
 808     public abstract IntVector rotateLanesRight(int i);
 809 
 810     /**
 811      * {@inheritDoc}
 812      */
 813     @Override
 814     public abstract IntVector shiftLanesLeft(int i);
 815 
 816     /**
 817      * {@inheritDoc}
 818      */
 819     @Override
 820     public abstract IntVector shiftLanesRight(int i);
 821 
 822 
 823 
 824     /**
 825      * Bitwise ANDs this vector with an input vector.
 826      * <p>
 827      * This is a lane-wise binary operation which applies the primitive bitwise AND
 828      * operation ({@code &}) to each lane.
 829      *
 830      * @param v the input vector
 831      * @return the bitwise AND of this vector with the input vector
 832      */
 833     public abstract IntVector and(Vector<Integer> v);
 834 
 835     /**
 836      * Bitwise ANDs this vector with the broadcast of an input scalar.
 837      * <p>
 838      * This is a lane-wise binary operation which applies the primitive bitwise AND
 839      * operation ({@code &}) to each lane.
 840      *


 979      *
 980      * @return the bitwise NOT of this vector
 981      */
 982     public abstract IntVector not();
 983 
 984     /**
 985      * Bitwise NOTs this vector, selecting lane elements controlled by a mask.
 986      * <p>
 987      * This is a lane-wise unary operation which applies the primitive bitwise NOT
 988      * operation ({@code ~}) to each lane.
 989      *
 990      * @param m the mask controlling lane selection
 991      * @return the bitwise NOT of this vector
 992      */
 993     public abstract IntVector not(VectorMask<Integer> m);
 994 
 995     /**
 996      * Logically left shifts this vector by the broadcast of an input scalar.
 997      * <p>
 998      * This is a lane-wise binary operation which applies the primitive logical left shift
 999      * operation ({@code <<}) to each lane to left shift the
1000      * element by shift value as specified by the input scalar.
1001      *
1002      * @param s the input scalar; the number of the bits to left shift
1003      * @return the result of logically left shifting left this vector by the
1004      * broadcast of an input scalar
1005      */
1006     public abstract IntVector shiftLeft(int s);
1007 
1008     /**
1009      * Logically left shifts this vector by the broadcast of an input scalar,
1010      * selecting lane elements controlled by a mask.
1011      * <p>
1012      * This is a lane-wise binary operation which applies the primitive logical left shift
1013      * operation ({@code <<}) to each lane to left shift the
1014      * element by shift value as specified by the input scalar.
1015      *
1016      * @param s the input scalar; the number of the bits to left shift
1017      * @param m the mask controlling lane selection
1018      * @return the result of logically left shifting left this vector by the
1019      * broadcast of an input scalar
1020      */
1021     public abstract IntVector shiftLeft(int s, VectorMask<Integer> m);
1022 
1023     /**
1024      * Logically left shifts this vector by an input vector.
1025      * <p>
1026      * This is a lane-wise binary operation which applies the primitive logical left shift
1027      * operation ({@code <<}) to each lane. For each lane of this vector, the
1028      * shift value is the corresponding lane of input vector.
1029      *
1030      * @param v the input vector
1031      * @return the result of logically left shifting this vector by the input
1032      * vector
1033      */
1034     public abstract IntVector shiftLeft(Vector<Integer> v);
1035 
1036     /**
1037      * Logically left shifts this vector by an input vector, selecting lane
1038      * elements controlled by a mask.
1039      * <p>
1040      * This is a lane-wise binary operation which applies the primitive logical left shift
1041      * operation ({@code <<}) to each lane. For each lane of this vector, the
1042      * shift value is the corresponding lane of input vector.
1043      *
1044      * @param v the input vector
1045      * @param m the mask controlling lane selection
1046      * @return the result of logically left shifting this vector by the input
1047      * vector
1048      */
1049     public IntVector shiftLeft(Vector<Integer> v, VectorMask<Integer> m) {
1050         return blend(shiftLeft(v), m);
1051     }
1052 
1053     // logical, or unsigned, shift right
1054 
1055      /**
1056      * Logically right shifts (or unsigned right shifts) this vector by the
1057      * broadcast of an input scalar.
1058      * <p>
1059      * This is a lane-wise binary operation which applies the primitive logical right shift
1060      * operation ({@code >>>}) to each lane to logically right shift the
1061      * element by shift value as specified by the input scalar.
1062      *
1063      * @param s the input scalar; the number of the bits to right shift
1064      * @return the result of logically right shifting this vector by the
1065      * broadcast of an input scalar
1066      */
1067     public abstract IntVector shiftRight(int s);
1068 
1069      /**
1070      * Logically right shifts (or unsigned right shifts) this vector by the
1071      * broadcast of an input scalar, selecting lane elements controlled by a
1072      * mask.
1073      * <p>
1074      * This is a lane-wise binary operation which applies the primitive logical right shift
1075      * operation ({@code >>}) to each lane to logically right shift the
1076      * element by shift value as specified by the input scalar.
1077      *
1078      * @param s the input scalar; the number of the bits to right shift
1079      * @param m the mask controlling lane selection
1080      * @return the result of logically right shifting this vector by the
1081      * broadcast of an input scalar
1082      */
1083     public abstract IntVector shiftRight(int s, VectorMask<Integer> m);
1084 
1085     /**
1086      * Logically right shifts (or unsigned right shifts) this vector by an
1087      * input vector.
1088      * <p>
1089      * This is a lane-wise binary operation which applies the primitive logical right shift
1090      * operation ({@code >>>}) to each lane. For each lane of this vector, the
1091      * shift value is the corresponding lane of input vector.
1092      *
1093      * @param v the input vector
1094      * @return the result of logically right shifting this vector by the
1095      * input vector
1096      */
1097     public abstract IntVector shiftRight(Vector<Integer> v);
1098 
1099     /**
1100      * Logically right shifts (or unsigned right shifts) this vector by an
1101      * input vector, selecting lane elements controlled by a mask.
1102      * <p>
1103      * This is a lane-wise binary operation which applies the primitive logical right shift
1104      * operation ({@code >>>}) to each lane. For each lane of this vector, the
1105      * shift value is the corresponding lane of input vector.
1106      *
1107      * @param v the input vector
1108      * @param m the mask controlling lane selection
1109      * @return the result of logically right shifting this vector by the
1110      * input vector
1111      */
1112     public IntVector shiftRight(Vector<Integer> v, VectorMask<Integer> m) {
1113         return blend(shiftRight(v), 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 lane-wise binary operation which applies the primitive arithmetic right
1121      * shift operation ({@code >>}) to each lane to arithmetically
1122      * right shift the element by shift value as specified by the input scalar.
1123      *
1124      * @param s the input scalar; the number of the bits to right shift
1125      * @return the result of arithmetically right shifting this vector by the
1126      * broadcast of an input scalar
1127      */
1128     public abstract IntVector shiftArithmeticRight(int s);
1129 
1130     /**
1131      * Arithmetically right shifts (or signed 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 lane-wise binary operation which applies the primitive arithmetic right
1136      * shift operation ({@code >>}) to each lane to arithmetically
1137      * right shift the element by shift value as specified by the input scalar.
1138      *
1139      * @param s the input scalar; the number of the bits to right shift
1140      * @param m the mask controlling lane selection
1141      * @return the result of arithmetically right shifting this vector by the
1142      * broadcast of an input scalar
1143      */
1144     public abstract IntVector shiftArithmeticRight(int s, VectorMask<Integer> m);
1145 
1146     /**
1147      * Arithmetically right shifts (or signed right shifts) this vector by an
1148      * input vector.
1149      * <p>
1150      * This is a lane-wise binary operation which applies the primitive arithmetic right
1151      * shift operation ({@code >>}) to each lane. For each lane of this vector, the
1152      * shift value is the corresponding lane of input vector.
1153      *
1154      * @param v the input vector
1155      * @return the result of arithmetically right shifting this vector by the
1156      * input vector
1157      */
1158     public abstract IntVector shiftArithmeticRight(Vector<Integer> v);
1159 
1160     /**
1161      * Arithmetically right shifts (or signed right shifts) this vector by an
1162      * input vector, selecting lane elements controlled by a mask.
1163      * <p>
1164      * This is a lane-wise binary operation which applies the primitive arithmetic right
1165      * shift operation ({@code >>}) to each lane. For each lane of this vector, the
1166      * shift value is the corresponding lane of input vector.
1167      *
1168      * @param v the input vector
1169      * @param m the mask controlling lane selection
1170      * @return the result of arithmetically right shifting this vector by the
1171      * input vector
1172      */
1173     public IntVector shiftArithmeticRight(Vector<Integer> v, VectorMask<Integer> m) {
1174         return blend(shiftArithmeticRight(v), m);
1175     }
1176 
1177     /**
1178      * Rotates left this vector by the broadcast of an input scalar.
1179      * <p>
1180      * This is a lane-wise binary operation which applies the operation
1181      * {@link Integer#rotateLeft} to each lane and where
1182      * lane elements of this vector apply to the first argument, and lane
1183      * elements of the broadcast vector apply to the second argument (the
1184      * rotation distance).
1185      *
1186      * @param s the input scalar; the number of the bits to rotate left
1187      * @return the result of rotating left this vector by the broadcast of an
1188      * input scalar
1189      */
1190     @ForceInline
1191     public final IntVector rotateLeft(int s) {
1192         return shiftLeft(s).or(shiftRight(-s));
1193     }
1194 
1195     /**
1196      * Rotates left this vector by the broadcast of an input scalar, selecting
1197      * lane elements controlled by a mask.
1198      * <p>
1199      * This is a lane-wise binary operation which applies the operation
1200      * {@link Integer#rotateLeft} to each lane and where
1201      * lane elements of this vector apply to the first argument, and lane
1202      * elements of the broadcast vector apply to the second argument (the
1203      * rotation distance).
1204      *
1205      * @param s the input scalar; the number of the bits to rotate left
1206      * @param m the mask controlling lane selection
1207      * @return the result of rotating left this vector by the broadcast of an
1208      * input scalar
1209      */
1210     @ForceInline
1211     public final IntVector rotateLeft(int s, VectorMask<Integer> m) {
1212         return shiftLeft(s, m).or(shiftRight(-s, m), m);
1213     }
1214 
1215     /**
1216      * Rotates right this vector by the broadcast of an input scalar.
1217      * <p>
1218      * This is a lane-wise binary operation which applies the operation
1219      * {@link Integer#rotateRight} to each lane and where
1220      * lane elements of this vector apply to the first argument, and lane
1221      * elements of the broadcast vector apply to the second argument (the
1222      * rotation distance).
1223      *
1224      * @param s the input scalar; the number of the bits to rotate right
1225      * @return the result of rotating right this vector by the broadcast of an
1226      * input scalar
1227      */
1228     @ForceInline
1229     public final IntVector rotateRight(int s) {
1230         return shiftRight(s).or(shiftLeft(-s));
1231     }
1232 
1233     /**
1234      * Rotates right this vector by the broadcast of an input scalar, selecting
1235      * lane elements controlled by a mask.
1236      * <p>
1237      * This is a lane-wise binary operation which applies the operation
1238      * {@link Integer#rotateRight} to each lane and where
1239      * lane elements of this vector apply to the first argument, and lane
1240      * elements of the broadcast vector apply to the second argument (the
1241      * rotation distance).
1242      *
1243      * @param s the input scalar; the number of the bits to rotate right
1244      * @param m the mask controlling lane selection
1245      * @return the result of rotating right this vector by the broadcast of an
1246      * input scalar
1247      */
1248     @ForceInline
1249     public final IntVector rotateRight(int s, VectorMask<Integer> m) {
1250         return shiftRight(s, m).or(shiftLeft(-s, m), m);
1251     }
1252 
1253     /**
1254      * {@inheritDoc}
1255      */
1256     @Override
1257     public abstract void intoByteArray(byte[] a, int ix);
1258 
1259     /**
1260      * {@inheritDoc}
1261      */
1262     @Override
1263     public abstract void intoByteArray(byte[] a, int ix, VectorMask<Integer> m);
1264 
1265     /**
1266      * {@inheritDoc}
1267      */
1268     @Override
1269     public abstract void intoByteBuffer(ByteBuffer bb, int ix);
1270 


1572      * or for any vector lane index {@code N} where the mask at lane
1573      * {@code N} is set the result of {@code a_offset + indexMap[i_offset + N]} is
1574      * {@code < 0} or {@code >= a.length}
1575      */
1576     public abstract void intoArray(int[] a, int a_offset, VectorMask<Integer> m, int[] indexMap, int i_offset);
1577     // Species
1578 
1579     /**
1580      * {@inheritDoc}
1581      */
1582     @Override
1583     public abstract VectorSpecies<Integer> species();
1584 
1585     /**
1586      * Class representing {@link IntVector}'s of the same {@link VectorShape VectorShape}.
1587      */
1588     static final class IntSpecies extends AbstractSpecies<Integer> {
1589         final Function<int[], IntVector> vectorFactory;
1590 
1591         private IntSpecies(VectorShape shape,
1592                           Class<?> vectorType,
1593                           Class<?> maskType,
1594                           Function<int[], IntVector> vectorFactory,
1595                           Function<boolean[], VectorMask<Integer>> maskFactory,
1596                           Function<IntUnaryOperator, VectorShuffle<Integer>> shuffleFromArrayFactory,
1597                           fShuffleFromArray<Integer> shuffleFromOpFactory) {
1598             super(shape, int.class, Integer.SIZE, vectorType, maskType, maskFactory,
1599                   shuffleFromArrayFactory, shuffleFromOpFactory);
1600             this.vectorFactory = vectorFactory;
1601         }
1602 
1603         interface FOp {
1604             int apply(int i);
1605         }
1606 
1607         IntVector op(FOp f) {
1608             int[] res = new int[length()];
1609             for (int i = 0; i < length(); i++) {
1610                 res[i] = f.apply(i);
1611             }
1612             return vectorFactory.apply(res);
1613         }
1614 
1615         IntVector op(VectorMask<Integer> o, FOp f) {
1616             int[] res = new int[length()];
1617             boolean[] mbits = ((AbstractMask<Integer>)o).getBits();
1618             for (int i = 0; i < length(); i++) {


< prev index next >