< prev index next >

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

Print this page
rev 55589 : Species-phase2
rev 55590 : added missing javadocs, changed jtreg test
rev 55591 : XxxSpecies made package private
rev 55592 : Capitalized Species names

*** 27,36 **** --- 27,37 ---- import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.nio.ByteOrder; import java.util.Objects; import java.util.function.IntUnaryOperator; + import java.util.function.Function; import java.util.concurrent.ThreadLocalRandom; import jdk.internal.misc.Unsafe; import jdk.internal.vm.annotation.ForceInline; import static jdk.incubator.vector.VectorIntrinsics.*;
*** 108,130 **** * @param species species of desired vector * @return a zero vector of given species */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector zero(IntSpecies species) { ! return species.zero(); } /** * Loads a vector from a byte array starting at an offset. * <p> * Bytes are composed into primitive lane elements according to the * native byte order of the underlying platform * <p> * This method behaves as if it returns the result of calling the * byte buffer, offset, and mask accepting ! * {@link #fromByteBuffer(IntSpecies, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue()); * }</pre> * * @param species species of desired vector --- 109,133 ---- * @param species species of desired vector * @return a zero vector of given species */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector zero(Species<Integer> species) { ! return VectorIntrinsics.broadcastCoerced((Class<IntVector>) species.boxType(), int.class, species.length(), ! 0, species, ! ((bits, s) -> ((IntSpecies)s).op(i -> (int)bits))); } /** * Loads a vector from a byte array starting at an offset. * <p> * Bytes are composed into primitive lane elements according to the * native byte order of the underlying platform * <p> * This method behaves as if it returns the result of calling the * byte buffer, offset, and mask accepting ! * {@link #fromByteBuffer(Species<Integer>, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue()); * }</pre> * * @param species species of desired vector
*** 134,144 **** * @throws IndexOutOfBoundsException if {@code i < 0} or * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)} */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromByteArray(IntSpecies species, byte[] a, int ix) { Objects.requireNonNull(a); ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE); return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(), a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, a, ix, species, --- 137,147 ---- * @throws IndexOutOfBoundsException if {@code i < 0} or * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)} */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromByteArray(Species<Integer> species, byte[] a, int ix) { Objects.requireNonNull(a); ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE); return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(), a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, a, ix, species,
*** 156,166 **** * Bytes are composed into primitive lane elements according to the * native byte order of the underlying platform. * <p> * This method behaves as if it returns the result of calling the * byte buffer, offset, and mask accepting ! * {@link #fromByteBuffer(IntSpecies, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m); * }</pre> * * @param species species of desired vector --- 159,169 ---- * Bytes are composed into primitive lane elements according to the * native byte order of the underlying platform. * <p> * This method behaves as if it returns the result of calling the * byte buffer, offset, and mask accepting ! * {@link #fromByteBuffer(Species<Integer>, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m); * }</pre> * * @param species species of desired vector
*** 175,185 **** * for any vector lane index {@code N} where the mask at lane {@code N} * is set * {@code i >= a.length - (N * this.elementSize() / Byte.SIZE)} */ @ForceInline ! public static IntVector fromByteArray(IntSpecies species, byte[] a, int ix, Mask<Integer> m) { return zero(species).blend(fromByteArray(species, a, ix), m); } /** * Loads a vector from an array starting at offset. --- 178,188 ---- * for any vector lane index {@code N} where the mask at lane {@code N} * is set * {@code i >= a.length - (N * this.elementSize() / Byte.SIZE)} */ @ForceInline ! public static IntVector fromByteArray(Species<Integer> species, byte[] a, int ix, Mask<Integer> m) { return zero(species).blend(fromByteArray(species, a, ix), m); } /** * Loads a vector from an array starting at offset.
*** 195,205 **** * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - this.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromArray(IntSpecies species, int[] a, int i){ Objects.requireNonNull(a); i = VectorIntrinsics.checkIndex(i, a.length, species.length()); return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(), a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET, a, i, species, --- 198,208 ---- * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - this.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromArray(Species<Integer> species, int[] a, int i){ Objects.requireNonNull(a); i = VectorIntrinsics.checkIndex(i, a.length, species.length()); return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(), a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET, a, i, species,
*** 224,234 **** * @throws IndexOutOfBoundsException if {@code i < 0}, or * for any vector lane index {@code N} where the mask at lane {@code N} * is set {@code i > a.length - N} */ @ForceInline ! public static IntVector fromArray(IntSpecies species, int[] a, int i, Mask<Integer> m) { return zero(species).blend(fromArray(species, a, i), m); } /** * Loads a vector from an array using indexes obtained from an index --- 227,237 ---- * @throws IndexOutOfBoundsException if {@code i < 0}, or * for any vector lane index {@code N} where the mask at lane {@code N} * is set {@code i > a.length - N} */ @ForceInline ! public static IntVector fromArray(Species<Integer> species, int[] a, int i, Mask<Integer> m) { return zero(species).blend(fromArray(species, a, i), m); } /** * Loads a vector from an array using indexes obtained from an index
*** 251,274 **** * or for any vector lane index {@code N} the result of * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length} */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromArray(IntSpecies species, int[] a, int i, int[] indexMap, int j) { Objects.requireNonNull(a); Objects.requireNonNull(indexMap); ! // Index vector: vix[0:n] = k -> i + indexMap[j + i] ! IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i); vix = VectorIntrinsics.checkIndex(vix, a.length); return VectorIntrinsics.loadWithMap((Class<IntVector>) species.boxType(), int.class, species.length(), ! species.indexSpecies().vectorType(), a, Unsafe.ARRAY_INT_BASE_OFFSET, vix, a, i, indexMap, j, species, ! (c, idx, iMap, idy, s) -> ((IntSpecies)s).op(n -> c[idx + iMap[idy+n]])); } /** * Loads a vector from an array using indexes obtained from an index * map and using a mask. --- 254,278 ---- * or for any vector lane index {@code N} the result of * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length} */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromArray(Species<Integer> species, int[] a, int i, int[] indexMap, int j) { Objects.requireNonNull(a); Objects.requireNonNull(indexMap); ! // Index vector: vix[0:n] = k -> i + indexMap[j + k] ! IntVector vix = IntVector.fromArray(IntVector.species(species.indexShape()), indexMap, j).add(i); vix = VectorIntrinsics.checkIndex(vix, a.length); return VectorIntrinsics.loadWithMap((Class<IntVector>) species.boxType(), int.class, species.length(), ! IntVector.species(species.indexShape()).boxType(), a, Unsafe.ARRAY_INT_BASE_OFFSET, vix, a, i, indexMap, j, species, ! (int[] c, int idx, int[] iMap, int idy, Species<Integer> s) -> ! ((IntSpecies)s).op(n -> c[idx + iMap[idy+n]])); } /** * Loads a vector from an array using indexes obtained from an index * map and using a mask.
*** 293,303 **** * {@code N} is set the result of {@code i + indexMap[j + N]} is * {@code < 0} or {@code >= a.length} */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromArray(IntSpecies species, int[] a, int i, Mask<Integer> m, int[] indexMap, int j) { // @@@ This can result in out of bounds errors for unset mask lanes return zero(species).blend(fromArray(species, a, i, indexMap, j), m); } --- 297,307 ---- * {@code N} is set the result of {@code i + indexMap[j + N]} is * {@code < 0} or {@code >= a.length} */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromArray(Species<Integer> species, int[] a, int i, Mask<Integer> m, int[] indexMap, int j) { // @@@ This can result in out of bounds errors for unset mask lanes return zero(species).blend(fromArray(species, a, i, indexMap, j), m); }
*** 308,318 **** * Bytes are composed into primitive lane elements according to the * native byte order of the underlying platform. * <p> * This method behaves as if it returns the result of calling the * byte buffer, offset, and mask accepting ! * {@link #fromByteBuffer(IntSpecies, ByteBuffer, int, Mask)} method} as follows: * <pre>{@code * return this.fromByteBuffer(b, i, this.maskAllTrue()) * }</pre> * * @param species species of desired vector --- 312,322 ---- * Bytes are composed into primitive lane elements according to the * native byte order of the underlying platform. * <p> * This method behaves as if it returns the result of calling the * byte buffer, offset, and mask accepting ! * {@link #fromByteBuffer(Species<Integer>, ByteBuffer, int, Mask)} method} as follows: * <pre>{@code * return this.fromByteBuffer(b, i, this.maskAllTrue()) * }</pre> * * @param species species of desired vector
*** 325,335 **** * {@code this.length() * this.elementSize() / Byte.SIZE} bytes * remaining in the byte buffer from the given offset */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromByteBuffer(IntSpecies species, ByteBuffer bb, int ix) { if (bb.order() != ByteOrder.nativeOrder()) { throw new IllegalArgumentException(); } ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE); return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(), --- 329,339 ---- * {@code this.length() * this.elementSize() / Byte.SIZE} bytes * remaining in the byte buffer from the given offset */ @ForceInline @SuppressWarnings("unchecked") ! public static IntVector fromByteBuffer(Species<Integer> species, ByteBuffer bb, int ix) { if (bb.order() != ByteOrder.nativeOrder()) { throw new IllegalArgumentException(); } ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE); return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
*** 377,391 **** * for any vector lane index {@code N} where the mask at lane {@code N} * is set * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)} */ @ForceInline ! public static IntVector fromByteBuffer(IntSpecies species, ByteBuffer bb, int ix, Mask<Integer> m) { return zero(species).blend(fromByteBuffer(species, bb, ix), m); } /** * Returns a mask where each lane is set or unset according to given * {@code boolean} values * <p> * For each mask lane, where {@code N} is the mask lane index, * if the given {@code boolean} value at index {@code N} is {@code true} --- 381,469 ---- * for any vector lane index {@code N} where the mask at lane {@code N} * is set * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)} */ @ForceInline ! public static IntVector fromByteBuffer(Species<Integer> species, ByteBuffer bb, int ix, Mask<Integer> m) { return zero(species).blend(fromByteBuffer(species, bb, ix), m); } /** + * Returns a vector where all lane elements are set to the primitive + * value {@code e}. + * + * @param s species of the desired vector + * @param e the value + * @return a vector of vector where all lane elements are set to + * the primitive value {@code e} + */ + @ForceInline + @SuppressWarnings("unchecked") + public static IntVector broadcast(Species<Integer> s, int e) { + return VectorIntrinsics.broadcastCoerced( + (Class<IntVector>) s.boxType(), int.class, s.length(), + e, s, + ((bits, sp) -> ((IntSpecies)sp).op(i -> (int)bits))); + } + + /** + * Returns a vector where each lane element is set to a given + * primitive value. + * <p> + * For each vector lane, where {@code N} is the vector lane index, the + * the primitive value at index {@code N} is placed into the resulting + * vector at lane index {@code N}. + * + * @param s species of the desired vector + * @param es the given primitive values + * @return a vector where each lane element is set to a given primitive + * value + * @throws IndexOutOfBoundsException if {@code es.length < this.length()} + */ + @ForceInline + @SuppressWarnings("unchecked") + public static IntVector scalars(Species<Integer> s, int... es) { + Objects.requireNonNull(es); + int ix = VectorIntrinsics.checkIndex(0, es.length, s.length()); + return VectorIntrinsics.load((Class<IntVector>) s.boxType(), int.class, s.length(), + es, Unsafe.ARRAY_INT_BASE_OFFSET, + es, ix, s, + (c, idx, sp) -> ((IntSpecies)sp).op(n -> c[idx + n])); + } + + /** + * Returns a vector where the first lane element is set to the primtive + * value {@code e}, all other lane elements are set to the default + * value. + * + * @param s species of the desired vector + * @param e the value + * @return a vector where the first lane element is set to the primitive + * value {@code e} + */ + @ForceInline + public static final IntVector single(Species<Integer> s, int e) { + return zero(s).with(0, e); + } + + /** + * Returns a vector where each lane element is set to a randomly + * generated primitive value. + * + * The semantics are equivalent to calling + * {@link ThreadLocalRandom#nextInt()} + * + * @param s species of the desired vector + * @return a vector where each lane elements is set to a randomly + * generated primitive value + */ + public static IntVector random(Species<Integer> s) { + ThreadLocalRandom r = ThreadLocalRandom.current(); + return ((IntSpecies)s).op(i -> r.nextInt()); + } + + /** * Returns a mask where each lane is set or unset according to given * {@code boolean} values * <p> * For each mask lane, where {@code N} is the mask lane index, * if the given {@code boolean} value at index {@code N} is {@code true}
*** 395,405 **** * @param bits the given {@code boolean} values * @return a mask where each lane is set or unset according to the given {@code boolean} value * @throws IndexOutOfBoundsException if {@code bits.length < species.length()} */ @ForceInline ! public static Mask<Integer> maskFromValues(IntSpecies species, boolean... bits) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxMask(bits); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Mask(bits); case 128: return new Int128Vector.Int128Mask(bits); --- 473,483 ---- * @param bits the given {@code boolean} values * @return a mask where each lane is set or unset according to the given {@code boolean} value * @throws IndexOutOfBoundsException if {@code bits.length < species.length()} */ @ForceInline ! public static Mask<Integer> maskFromValues(Species<Integer> species, boolean... bits) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxMask(bits); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Mask(bits); case 128: return new Int128Vector.Int128Mask(bits);
*** 408,418 **** default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } // @@@ This is a bad implementation -- makes lambdas capturing -- fix this ! static Mask<Integer> trueMask(IntSpecies species) { if (species.boxType() == IntMaxVector.class) return IntMaxVector.IntMaxMask.TRUE_MASK; switch (species.bitSize()) { case 64: return Int64Vector.Int64Mask.TRUE_MASK; case 128: return Int128Vector.Int128Mask.TRUE_MASK; --- 486,496 ---- default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } // @@@ This is a bad implementation -- makes lambdas capturing -- fix this ! static Mask<Integer> trueMask(Species<Integer> species) { if (species.boxType() == IntMaxVector.class) return IntMaxVector.IntMaxMask.TRUE_MASK; switch (species.bitSize()) { case 64: return Int64Vector.Int64Mask.TRUE_MASK; case 128: return Int128Vector.Int128Mask.TRUE_MASK;
*** 420,430 **** case 512: return Int512Vector.Int512Mask.TRUE_MASK; default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } ! static Mask<Integer> falseMask(IntSpecies species) { if (species.boxType() == IntMaxVector.class) return IntMaxVector.IntMaxMask.FALSE_MASK; switch (species.bitSize()) { case 64: return Int64Vector.Int64Mask.FALSE_MASK; case 128: return Int128Vector.Int128Mask.FALSE_MASK; --- 498,508 ---- case 512: return Int512Vector.Int512Mask.TRUE_MASK; default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } ! static Mask<Integer> falseMask(Species<Integer> species) { if (species.boxType() == IntMaxVector.class) return IntMaxVector.IntMaxMask.FALSE_MASK; switch (species.bitSize()) { case 64: return Int64Vector.Int64Mask.FALSE_MASK; case 128: return Int128Vector.Int128Mask.FALSE_MASK;
*** 448,458 **** * @throws IndexOutOfBoundsException if {@code ix < 0}, or * {@code ix > bits.length - species.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Integer> maskFromArray(IntSpecies species, boolean[] bits, int ix) { Objects.requireNonNull(bits); ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length()); return VectorIntrinsics.load((Class<Mask<Integer>>) species.maskType(), int.class, species.length(), bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, bits, ix, species, --- 526,536 ---- * @throws IndexOutOfBoundsException if {@code ix < 0}, or * {@code ix > bits.length - species.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Integer> maskFromArray(Species<Integer> species, boolean[] bits, int ix) { Objects.requireNonNull(bits); ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length()); return VectorIntrinsics.load((Class<Mask<Integer>>) species.maskType(), int.class, species.length(), bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, bits, ix, species,
*** 465,492 **** * @param species mask species * @return a mask where all lanes are set */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Integer> maskAllTrue(IntSpecies species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<Integer>>) species.maskType(), int.class, species.length(), (int)-1, species, ! ((z, s) -> trueMask((IntSpecies)s))); } /** * Returns a mask where all lanes are unset. * * @param species mask species * @return a mask where all lanes are unset */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Integer> maskAllFalse(IntSpecies species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<Integer>>) species.maskType(), int.class, species.length(), 0, species, ! ((z, s) -> falseMask((IntSpecies)s))); } /** * Returns a shuffle of mapped indexes where each lane element is * the result of applying a mapping function to the corresponding lane --- 543,570 ---- * @param species mask species * @return a mask where all lanes are set */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Integer> maskAllTrue(Species<Integer> species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<Integer>>) species.maskType(), int.class, species.length(), (int)-1, species, ! ((z, s) -> trueMask(s))); } /** * Returns a mask where all lanes are unset. * * @param species mask species * @return a mask where all lanes are unset */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Integer> maskAllFalse(Species<Integer> species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<Integer>>) species.maskType(), int.class, species.length(), 0, species, ! ((z, s) -> falseMask(s))); } /** * Returns a shuffle of mapped indexes where each lane element is * the result of applying a mapping function to the corresponding lane
*** 510,520 **** * @param species shuffle species * @param f the lane index mapping function * @return a shuffle of mapped indexes */ @ForceInline ! public static Shuffle<Integer> shuffle(IntSpecies species, IntUnaryOperator f) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxShuffle(f); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Shuffle(f); case 128: return new Int128Vector.Int128Shuffle(f); --- 588,598 ---- * @param species shuffle species * @param f the lane index mapping function * @return a shuffle of mapped indexes */ @ForceInline ! public static Shuffle<Integer> shuffle(Species<Integer> species, IntUnaryOperator f) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxShuffle(f); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Shuffle(f); case 128: return new Int128Vector.Int128Shuffle(f);
*** 536,546 **** * * @param species shuffle species * @return a shuffle of lane indexes */ @ForceInline ! public static Shuffle<Integer> shuffleIota(IntSpecies species) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxShuffle(AbstractShuffle.IDENTITY); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Shuffle(AbstractShuffle.IDENTITY); case 128: return new Int128Vector.Int128Shuffle(AbstractShuffle.IDENTITY); --- 614,624 ---- * * @param species shuffle species * @return a shuffle of lane indexes */ @ForceInline ! public static Shuffle<Integer> shuffleIota(Species<Integer> species) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxShuffle(AbstractShuffle.IDENTITY); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Shuffle(AbstractShuffle.IDENTITY); case 128: return new Int128Vector.Int128Shuffle(AbstractShuffle.IDENTITY);
*** 565,575 **** * {@code int} value * @throws IndexOutOfBoundsException if the number of int values is * {@code < species.length()} */ @ForceInline ! public static Shuffle<Integer> shuffleFromValues(IntSpecies species, int... ixs) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxShuffle(ixs); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Shuffle(ixs); case 128: return new Int128Vector.Int128Shuffle(ixs); --- 643,653 ---- * {@code int} value * @throws IndexOutOfBoundsException if the number of int values is * {@code < species.length()} */ @ForceInline ! public static Shuffle<Integer> shuffleFromValues(Species<Integer> species, int... ixs) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxShuffle(ixs); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Shuffle(ixs); case 128: return new Int128Vector.Int128Shuffle(ixs);
*** 593,603 **** * @return a shuffle loaded from the {@code int} array * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - species.length()} */ @ForceInline ! public static Shuffle<Integer> shuffleFromArray(IntSpecies species, int[] ixs, int i) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxShuffle(ixs, i); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Shuffle(ixs, i); case 128: return new Int128Vector.Int128Shuffle(ixs, i); --- 671,681 ---- * @return a shuffle loaded from the {@code int} array * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - species.length()} */ @ForceInline ! public static Shuffle<Integer> shuffleFromArray(Species<Integer> species, int[] ixs, int i) { if (species.boxType() == IntMaxVector.class) return new IntMaxVector.IntMaxShuffle(ixs, i); switch (species.bitSize()) { case 64: return new Int64Vector.Int64Shuffle(ixs, i); case 128: return new Int128Vector.Int128Shuffle(ixs, i);
*** 605,615 **** case 512: return new Int512Vector.Int512Shuffle(ixs, i); default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } - // Ops @Override public abstract IntVector add(Vector<Integer> v); --- 683,692 ----
*** 1617,1707 **** */ public abstract void intoArray(int[] a, int i, Mask<Integer> m, int[] indexMap, int j); // Species @Override ! public abstract IntSpecies species(); /** * Class representing {@link IntVector}'s of the same {@link Vector.Shape Shape}. */ ! public static abstract class IntSpecies extends Vector.Species<Integer> { interface FOp { int apply(int i); } - abstract IntVector op(FOp f); - - abstract IntVector op(Mask<Integer> m, FOp f); - interface FOpm { boolean apply(int i); } ! abstract Mask<Integer> opm(FOpm f); ! ! abstract IntVector.IntSpecies indexSpecies(); ! ! ! // Factories ! ! @Override ! public abstract IntVector zero(); ! ! /** ! * Returns a vector where all lane elements are set to the primitive ! * value {@code e}. ! * ! * @param e the value ! * @return a vector of vector where all lane elements are set to ! * the primitive value {@code e} ! */ ! public abstract IntVector broadcast(int e); ! ! /** ! * Returns a vector where the first lane element is set to the primtive ! * value {@code e}, all other lane elements are set to the default ! * value. ! * ! * @param e the value ! * @return a vector where the first lane element is set to the primitive ! * value {@code e} ! */ ! @ForceInline ! public final IntVector single(int e) { ! return zero().with(0, e); } ! /** ! * Returns a vector where each lane element is set to a randomly ! * generated primitive value. ! * ! * The semantics are equivalent to calling ! * {@code (int)ThreadLocalRandom#nextInt()}. ! * ! * @return a vector where each lane elements is set to a randomly ! * generated primitive value ! */ ! public IntVector random() { ! ThreadLocalRandom r = ThreadLocalRandom.current(); ! return op(i -> r.nextInt()); } ! /** ! * Returns a vector where each lane element is set to a given ! * primitive value. ! * <p> ! * For each vector lane, where {@code N} is the vector lane index, the ! * the primitive value at index {@code N} is placed into the resulting ! * vector at lane index {@code N}. ! * ! * @param es the given primitive values ! * @return a vector where each lane element is set to a given primitive ! * value ! * @throws IndexOutOfBoundsException if {@code es.length < this.length()} ! */ ! public abstract IntVector scalars(int... es); } /** * Finds the preferred species for an element type of {@code int}. * <p> --- 1694,1756 ---- */ public abstract void intoArray(int[] a, int i, Mask<Integer> m, int[] indexMap, int j); // Species @Override ! public abstract Species<Integer> species(); /** * Class representing {@link IntVector}'s of the same {@link Vector.Shape Shape}. */ ! static final class IntSpecies extends Vector.AbstractSpecies<Integer> { ! final Function<int[], IntVector> vectorFactory; ! final Function<boolean[], Vector.Mask<Integer>> maskFactory; ! ! private IntSpecies(Vector.Shape shape, ! Class<?> boxType, ! Class<?> maskType, ! Function<int[], IntVector> vectorFactory, ! Function<boolean[], Vector.Mask<Integer>> maskFactory) { ! super(shape, int.class, Integer.SIZE, boxType, maskType); ! this.vectorFactory = vectorFactory; ! this.maskFactory = maskFactory; ! } ! interface FOp { int apply(int i); } interface FOpm { boolean apply(int i); } ! IntVector op(FOp f) { ! int[] res = new int[length()]; ! for (int i = 0; i < length(); i++) { ! res[i] = f.apply(i); ! } ! return vectorFactory.apply(res); } ! IntVector op(Vector.Mask<Integer> o, FOp f) { ! int[] res = new int[length()]; ! boolean[] mbits = ((AbstractMask<Integer>)o).getBits(); ! for (int i = 0; i < length(); i++) { ! if (mbits[i]) { ! res[i] = f.apply(i); ! } ! } ! return vectorFactory.apply(res); } ! Vector.Mask<Integer> opm(IntVector.IntSpecies.FOpm f) { ! boolean[] res = new boolean[length()]; ! for (int i = 0; i < length(); i++) { ! res[i] = (boolean)f.apply(i); ! } ! return maskFactory.apply(res); ! } } /** * Finds the preferred species for an element type of {@code int}. * <p>
*** 1710,1739 **** * types will have the same shape, and therefore vectors, masks, and * shuffles created from such species will be shape compatible. * * @return the preferred species for an element type of {@code int} */ ! @SuppressWarnings("unchecked") ! public static IntSpecies preferredSpecies() { return (IntSpecies) Species.ofPreferred(int.class); } /** * Finds a species for an element type of {@code int} and shape. * * @param s the shape * @return a species for an element type of {@code int} and shape * @throws IllegalArgumentException if no such species exists for the shape */ ! @SuppressWarnings("unchecked") ! public static IntSpecies species(Vector.Shape s) { Objects.requireNonNull(s); switch (s) { ! case S_64_BIT: return Int64Vector.SPECIES; ! case S_128_BIT: return Int128Vector.SPECIES; ! case S_256_BIT: return Int256Vector.SPECIES; ! case S_512_BIT: return Int512Vector.SPECIES; ! case S_Max_BIT: return IntMaxVector.SPECIES; default: throw new IllegalArgumentException("Bad shape: " + s); } } } --- 1759,1812 ---- * types will have the same shape, and therefore vectors, masks, and * shuffles created from such species will be shape compatible. * * @return the preferred species for an element type of {@code int} */ ! private static IntSpecies preferredSpecies() { return (IntSpecies) Species.ofPreferred(int.class); } /** * Finds a species for an element type of {@code int} and shape. * * @param s the shape * @return a species for an element type of {@code int} and shape * @throws IllegalArgumentException if no such species exists for the shape */ ! static IntSpecies species(Vector.Shape s) { Objects.requireNonNull(s); switch (s) { ! case S_64_BIT: return (IntSpecies) SPECIES_64; ! case S_128_BIT: return (IntSpecies) SPECIES_128; ! case S_256_BIT: return (IntSpecies) SPECIES_256; ! case S_512_BIT: return (IntSpecies) SPECIES_512; ! case S_Max_BIT: return (IntSpecies) SPECIES_MAX; default: throw new IllegalArgumentException("Bad shape: " + s); } } + + /** Species representing {@link IntVector}s of {@link Vector.Shape#S_64_BIT Shape.S_64_BIT}. */ + public static final Species<Integer> SPECIES_64 = new IntSpecies(Shape.S_64_BIT, Int64Vector.class, Int64Vector.Int64Mask.class, + Int64Vector::new, Int64Vector.Int64Mask::new); + + /** Species representing {@link IntVector}s of {@link Vector.Shape#S_128_BIT Shape.S_128_BIT}. */ + public static final Species<Integer> SPECIES_128 = new IntSpecies(Shape.S_128_BIT, Int128Vector.class, Int128Vector.Int128Mask.class, + Int128Vector::new, Int128Vector.Int128Mask::new); + + /** Species representing {@link IntVector}s of {@link Vector.Shape#S_256_BIT Shape.S_256_BIT}. */ + public static final Species<Integer> SPECIES_256 = new IntSpecies(Shape.S_256_BIT, Int256Vector.class, Int256Vector.Int256Mask.class, + Int256Vector::new, Int256Vector.Int256Mask::new); + + /** Species representing {@link IntVector}s of {@link Vector.Shape#S_512_BIT Shape.S_512_BIT}. */ + public static final Species<Integer> SPECIES_512 = new IntSpecies(Shape.S_512_BIT, Int512Vector.class, Int512Vector.Int512Mask.class, + Int512Vector::new, Int512Vector.Int512Mask::new); + + /** Species representing {@link IntVector}s of {@link Vector.Shape#S_Max_BIT Shape.S_Max_BIT}. */ + public static final Species<Integer> SPECIES_MAX = new IntSpecies(Shape.S_Max_BIT, IntMaxVector.class, IntMaxVector.IntMaxMask.class, + IntMaxVector::new, IntMaxVector.IntMaxMask::new); + + /** + * Preferred species for {@link IntVector}s. + * A preferred species is a species of maximal bit size for the platform. + */ + public static final Species<Integer> SPECIES_PREFERRED = (Species<Integer>) preferredSpecies(); }
< prev index next >