< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template

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

*** 29,38 **** --- 29,39 ---- import java.nio.$Type$Buffer; #end[!byte] 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.*;
*** 110,132 **** * @param species species of desired vector * @return a zero vector of given species */ @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ zero($Type$Species 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($Type$Species, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue()); * }</pre> * * @param species species of desired vector --- 111,141 ---- * @param species species of desired vector * @return a zero vector of given species */ @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ zero(Species<$Boxtype$> species) { ! #if[FP] ! return VectorIntrinsics.broadcastCoerced((Class<$Type$Vector>) species.boxType(), $type$.class, species.length(), ! $Type$.$type$To$Bitstype$Bits(0.0f), species, ! ((bits, s) -> (($Type$Species)s).op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits)))); ! #else[FP] ! return VectorIntrinsics.broadcastCoerced((Class<$Type$Vector>) species.boxType(), $type$.class, species.length(), ! 0, species, ! ((bits, s) -> (($Type$Species)s).op(i -> ($type$)bits))); ! #end[FP] } /** * 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<$Boxtype$>, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue()); * }</pre> * * @param species species of desired vector
*** 136,146 **** * @throws IndexOutOfBoundsException if {@code i < 0} or * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)} */ @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromByteArray($Type$Species species, byte[] a, int ix) { Objects.requireNonNull(a); ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE); return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, a, ix, species, --- 145,155 ---- * @throws IndexOutOfBoundsException if {@code i < 0} or * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)} */ @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromByteArray(Species<$Boxtype$> species, byte[] a, int ix) { Objects.requireNonNull(a); ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE); return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, a, ix, species,
*** 158,168 **** * 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($Type$Species, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m); * }</pre> * * @param species species of desired vector --- 167,177 ---- * 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<$Boxtype$>, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m); * }</pre> * * @param species species of desired vector
*** 177,187 **** * 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 $abstractvectortype$ fromByteArray($Type$Species species, byte[] a, int ix, Mask<$Boxtype$> m) { return zero(species).blend(fromByteArray(species, a, ix), m); } /** * Loads a vector from an array starting at offset. --- 186,196 ---- * 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 $abstractvectortype$ fromByteArray(Species<$Boxtype$> species, byte[] a, int ix, Mask<$Boxtype$> m) { return zero(species).blend(fromByteArray(species, a, ix), m); } /** * Loads a vector from an array starting at offset.
*** 197,207 **** * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - this.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i){ Objects.requireNonNull(a); i = VectorIntrinsics.checkIndex(i, a.length, species.length()); return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_$TYPE$_BASE_OFFSET, a, i, species, --- 206,216 ---- * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - this.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i){ Objects.requireNonNull(a); i = VectorIntrinsics.checkIndex(i, a.length, species.length()); return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_$TYPE$_BASE_OFFSET, a, i, species,
*** 226,236 **** * @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 $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, Mask<$Boxtype$> m) { return zero(species).blend(fromArray(species, a, i), m); } /** * Loads a vector from an array using indexes obtained from an index --- 235,245 ---- * @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 $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, Mask<$Boxtype$> m) { return zero(species).blend(fromArray(species, a, i), m); } /** * Loads a vector from an array using indexes obtained from an index
*** 252,286 **** * {@code j > indexMap.length - this.length()}, * or for any vector lane index {@code N} the result of * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length} */ #if[byteOrShort] ! public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, int[] indexMap, int j) { ! return species.op(n -> a[i + indexMap[j + n]]); } #else[byteOrShort] @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, int[] indexMap, int j) { Objects.requireNonNull(a); Objects.requireNonNull(indexMap); #if[longOrDouble] if (species.length() == 1) { return $abstractvectortype$.fromArray(species, a, i + indexMap[j]); } #end[longOrDouble] ! // 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<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), ! species.indexSpecies().vectorType(), a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix, a, i, indexMap, j, species, ! (c, idx, iMap, idy, s) -> (($Type$Species)s).op(n -> c[idx + iMap[idy+n]])); } #end[byteOrShort] /** * Loads a vector from an array using indexes obtained from an index --- 261,296 ---- * {@code j > indexMap.length - this.length()}, * or for any vector lane index {@code N} the result of * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length} */ #if[byteOrShort] ! public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, int[] indexMap, int j) { ! return (($Type$Species)species).op(n -> a[i + indexMap[j + n]]); } #else[byteOrShort] @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, int[] indexMap, int j) { Objects.requireNonNull(a); Objects.requireNonNull(indexMap); #if[longOrDouble] if (species.length() == 1) { return $abstractvectortype$.fromArray(species, a, i + indexMap[j]); } #end[longOrDouble] ! // 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<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), ! IntVector.species(species.indexShape()).boxType(), a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix, a, i, indexMap, j, species, ! ($type$[] c, int idx, int[] iMap, int idy, Species<$Boxtype$> s) -> ! (($Type$Species)s).op(n -> c[idx + iMap[idy+n]])); } #end[byteOrShort] /** * Loads a vector from an array using indexes obtained from an index
*** 305,321 **** * or for any vector lane index {@code N} where the mask at lane * {@code N} is set the result of {@code i + indexMap[j + N]} is * {@code < 0} or {@code >= a.length} */ #if[byteOrShort] ! public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j) { ! return species.op(m, n -> a[i + indexMap[j + n]]); } #else[byteOrShort] @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, Mask<$Boxtype$> 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); } #end[byteOrShort] --- 315,331 ---- * or for any vector lane index {@code N} where the mask at lane * {@code N} is set the result of {@code i + indexMap[j + N]} is * {@code < 0} or {@code >= a.length} */ #if[byteOrShort] ! public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j) { ! return (($Type$Species)species).op(m, n -> a[i + indexMap[j + n]]); } #else[byteOrShort] @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, Mask<$Boxtype$> 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); } #end[byteOrShort]
*** 327,337 **** * 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($Type$Species, ByteBuffer, int, Mask)} method} as follows: * <pre>{@code * return this.fromByteBuffer(b, i, this.maskAllTrue()) * }</pre> * * @param species species of desired vector --- 337,347 ---- * 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<$Boxtype$>, ByteBuffer, int, Mask)} method} as follows: * <pre>{@code * return this.fromByteBuffer(b, i, this.maskAllTrue()) * }</pre> * * @param species species of desired vector
*** 344,354 **** * {@code this.length() * this.elementSize() / Byte.SIZE} bytes * remaining in the byte buffer from the given offset */ @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromByteBuffer($Type$Species 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<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), --- 354,364 ---- * {@code this.length() * this.elementSize() / Byte.SIZE} bytes * remaining in the byte buffer from the given offset */ @ForceInline @SuppressWarnings("unchecked") ! public static $abstractvectortype$ fromByteBuffer(Species<$Boxtype$> 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<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
*** 396,410 **** * 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 $abstractvectortype$ fromByteBuffer($Type$Species species, ByteBuffer bb, int ix, Mask<$Boxtype$> 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} --- 406,523 ---- * 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 $abstractvectortype$ fromByteBuffer(Species<$Boxtype$> species, ByteBuffer bb, int ix, Mask<$Boxtype$> 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} + */ + #if[FP] + @ForceInline + @SuppressWarnings("unchecked") + public static $abstractvectortype$ broadcast(Species<$Boxtype$> s, $type$ e) { + return VectorIntrinsics.broadcastCoerced( + (Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(), + $Type$.$type$To$Bitstype$Bits(e), s, + ((bits, sp) -> (($Type$Species)sp).op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits)))); + } + #else[FP] + @ForceInline + @SuppressWarnings("unchecked") + public static $abstractvectortype$ broadcast(Species<$Boxtype$> s, $type$ e) { + return VectorIntrinsics.broadcastCoerced( + (Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(), + e, s, + ((bits, sp) -> (($Type$Species)sp).op(i -> ($type$)bits))); + } + #end[FP] + + /** + * 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 $abstractvectortype$ scalars(Species<$Boxtype$> s, $type$... es) { + Objects.requireNonNull(es); + int ix = VectorIntrinsics.checkIndex(0, es.length, s.length()); + return VectorIntrinsics.load((Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(), + es, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, + es, ix, s, + (c, idx, sp) -> (($Type$Species)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 $abstractvectortype$ single(Species<$Boxtype$> s, $type$ 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 + #if[byteOrShort] + * ($type$){@link ThreadLocalRandom#nextInt()} + #else[byteOrShort] + * {@link ThreadLocalRandom#next$Type$()} + #end[byteOrShort] + * + * @param s species of the desired vector + * @return a vector where each lane elements is set to a randomly + * generated primitive value + */ + #if[intOrLong] + public static $abstractvectortype$ random(Species<$Boxtype$> s) { + ThreadLocalRandom r = ThreadLocalRandom.current(); + return (($Type$Species)s).op(i -> r.next$Type$()); + } + #else[intOrLong] + #if[FP] + public static $abstractvectortype$ random(Species<$Boxtype$> s) { + ThreadLocalRandom r = ThreadLocalRandom.current(); + return (($Type$Species)s).op(i -> r.next$Type$()); + } + #else[FP] + public static $abstractvectortype$ random(Species<$Boxtype$> s) { + ThreadLocalRandom r = ThreadLocalRandom.current(); + return (($Type$Species)s).op(i -> ($type$) r.nextInt()); + } + #end[FP] + #end[intOrLong] + + /** * 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}
*** 414,424 **** * @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<$Boxtype$> maskFromValues($Type$Species species, boolean... bits) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxMask(bits); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Mask(bits); case 128: return new $Type$128Vector.$Type$128Mask(bits); --- 527,537 ---- * @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<$Boxtype$> maskFromValues(Species<$Boxtype$> species, boolean... bits) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxMask(bits); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Mask(bits); case 128: return new $Type$128Vector.$Type$128Mask(bits);
*** 427,437 **** default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } // @@@ This is a bad implementation -- makes lambdas capturing -- fix this ! static Mask<$Boxtype$> trueMask($Type$Species species) { if (species.boxType() == $Type$MaxVector.class) return $Type$MaxVector.$Type$MaxMask.TRUE_MASK; switch (species.bitSize()) { case 64: return $Type$64Vector.$Type$64Mask.TRUE_MASK; case 128: return $Type$128Vector.$Type$128Mask.TRUE_MASK; --- 540,550 ---- default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } // @@@ This is a bad implementation -- makes lambdas capturing -- fix this ! static Mask<$Boxtype$> trueMask(Species<$Boxtype$> species) { if (species.boxType() == $Type$MaxVector.class) return $Type$MaxVector.$Type$MaxMask.TRUE_MASK; switch (species.bitSize()) { case 64: return $Type$64Vector.$Type$64Mask.TRUE_MASK; case 128: return $Type$128Vector.$Type$128Mask.TRUE_MASK;
*** 439,449 **** case 512: return $Type$512Vector.$Type$512Mask.TRUE_MASK; default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } ! static Mask<$Boxtype$> falseMask($Type$Species species) { if (species.boxType() == $Type$MaxVector.class) return $Type$MaxVector.$Type$MaxMask.FALSE_MASK; switch (species.bitSize()) { case 64: return $Type$64Vector.$Type$64Mask.FALSE_MASK; case 128: return $Type$128Vector.$Type$128Mask.FALSE_MASK; --- 552,562 ---- case 512: return $Type$512Vector.$Type$512Mask.TRUE_MASK; default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } ! static Mask<$Boxtype$> falseMask(Species<$Boxtype$> species) { if (species.boxType() == $Type$MaxVector.class) return $Type$MaxVector.$Type$MaxMask.FALSE_MASK; switch (species.bitSize()) { case 64: return $Type$64Vector.$Type$64Mask.FALSE_MASK; case 128: return $Type$128Vector.$Type$128Mask.FALSE_MASK;
*** 467,477 **** * @throws IndexOutOfBoundsException if {@code ix < 0}, or * {@code ix > bits.length - species.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<$Boxtype$> maskFromArray($Type$Species species, boolean[] bits, int ix) { Objects.requireNonNull(bits); ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length()); return VectorIntrinsics.load((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(), bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, bits, ix, species, --- 580,590 ---- * @throws IndexOutOfBoundsException if {@code ix < 0}, or * {@code ix > bits.length - species.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<$Boxtype$> maskFromArray(Species<$Boxtype$> species, boolean[] bits, int ix) { Objects.requireNonNull(bits); ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length()); return VectorIntrinsics.load((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(), bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, bits, ix, species,
*** 484,511 **** * @param species mask species * @return a mask where all lanes are set */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<$Boxtype$> maskAllTrue($Type$Species species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(), ($bitstype$)-1, species, ! ((z, s) -> trueMask(($Type$Species)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<$Boxtype$> maskAllFalse($Type$Species species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(), 0, species, ! ((z, s) -> falseMask(($Type$Species)s))); } /** * Returns a shuffle of mapped indexes where each lane element is * the result of applying a mapping function to the corresponding lane --- 597,624 ---- * @param species mask species * @return a mask where all lanes are set */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<$Boxtype$> maskAllTrue(Species<$Boxtype$> species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(), ($bitstype$)-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<$Boxtype$> maskAllFalse(Species<$Boxtype$> species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.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
*** 529,539 **** * @param species shuffle species * @param f the lane index mapping function * @return a shuffle of mapped indexes */ @ForceInline ! public static Shuffle<$Boxtype$> shuffle($Type$Species species, IntUnaryOperator f) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxShuffle(f); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Shuffle(f); case 128: return new $Type$128Vector.$Type$128Shuffle(f); --- 642,652 ---- * @param species shuffle species * @param f the lane index mapping function * @return a shuffle of mapped indexes */ @ForceInline ! public static Shuffle<$Boxtype$> shuffle(Species<$Boxtype$> species, IntUnaryOperator f) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxShuffle(f); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Shuffle(f); case 128: return new $Type$128Vector.$Type$128Shuffle(f);
*** 555,565 **** * * @param species shuffle species * @return a shuffle of lane indexes */ @ForceInline ! public static Shuffle<$Boxtype$> shuffleIota($Type$Species species) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxShuffle(AbstractShuffle.IDENTITY); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Shuffle(AbstractShuffle.IDENTITY); case 128: return new $Type$128Vector.$Type$128Shuffle(AbstractShuffle.IDENTITY); --- 668,678 ---- * * @param species shuffle species * @return a shuffle of lane indexes */ @ForceInline ! public static Shuffle<$Boxtype$> shuffleIota(Species<$Boxtype$> species) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxShuffle(AbstractShuffle.IDENTITY); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Shuffle(AbstractShuffle.IDENTITY); case 128: return new $Type$128Vector.$Type$128Shuffle(AbstractShuffle.IDENTITY);
*** 584,594 **** * {@code int} value * @throws IndexOutOfBoundsException if the number of int values is * {@code < species.length()} */ @ForceInline ! public static Shuffle<$Boxtype$> shuffleFromValues($Type$Species species, int... ixs) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxShuffle(ixs); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Shuffle(ixs); case 128: return new $Type$128Vector.$Type$128Shuffle(ixs); --- 697,707 ---- * {@code int} value * @throws IndexOutOfBoundsException if the number of int values is * {@code < species.length()} */ @ForceInline ! public static Shuffle<$Boxtype$> shuffleFromValues(Species<$Boxtype$> species, int... ixs) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxShuffle(ixs); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Shuffle(ixs); case 128: return new $Type$128Vector.$Type$128Shuffle(ixs);
*** 612,622 **** * @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<$Boxtype$> shuffleFromArray($Type$Species species, int[] ixs, int i) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxShuffle(ixs, i); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Shuffle(ixs, i); case 128: return new $Type$128Vector.$Type$128Shuffle(ixs, i); --- 725,735 ---- * @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<$Boxtype$> shuffleFromArray(Species<$Boxtype$> species, int[] ixs, int i) { if (species.boxType() == $Type$MaxVector.class) return new $Type$MaxVector.$Type$MaxShuffle(ixs, i); switch (species.bitSize()) { case 64: return new $Type$64Vector.$Type$64Shuffle(ixs, i); case 128: return new $Type$128Vector.$Type$128Shuffle(ixs, i);
*** 624,634 **** case 512: return new $Type$512Vector.$Type$512Shuffle(ixs, i); default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } - // Ops @Override public abstract $abstractvectortype$ add(Vector<$Boxtype$> v); --- 737,746 ----
*** 2812,2922 **** public abstract void intoArray($type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j); #end[byteOrShort] // Species @Override ! public abstract $Type$Species species(); /** * Class representing {@link $abstractvectortype$}'s of the same {@link Vector.Shape Shape}. */ ! public static abstract class $Type$Species extends Vector.Species<$Boxtype$> { interface FOp { $type$ apply(int i); } - abstract $abstractvectortype$ op(FOp f); - - abstract $abstractvectortype$ op(Mask<$Boxtype$> m, FOp f); - interface FOpm { boolean apply(int i); } ! abstract Mask<$Boxtype$> opm(FOpm f); ! ! #if[!byteOrShort] ! abstract IntVector.IntSpecies indexSpecies(); ! #end[!byteOrShort] ! ! ! // Factories ! ! @Override ! public abstract $abstractvectortype$ 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 $abstractvectortype$ broadcast($type$ 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 $abstractvectortype$ single($type$ 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 ! #if[FP] ! * {@code ThreadLocalRandom#next$Type$}. ! #else[FP] ! * {@code ($type$)ThreadLocalRandom#nextInt()}. ! #end[FP] ! * ! * @return a vector where each lane elements is set to a randomly ! * generated primitive value ! */ ! #if[intOrLong] ! public $abstractvectortype$ random() { ! ThreadLocalRandom r = ThreadLocalRandom.current(); ! return op(i -> r.next$Type$()); } - #else[intOrLong] - #if[FP] - public $abstractvectortype$ random() { - ThreadLocalRandom r = ThreadLocalRandom.current(); - return op(i -> r.next$Type$()); } ! #else[FP] ! public $abstractvectortype$ random() { ! ThreadLocalRandom r = ThreadLocalRandom.current(); ! return op(i -> ($type$) r.nextInt()); } - #end[FP] - #end[intOrLong] ! /** ! * 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 $abstractvectortype$ scalars($type$... es); } /** * Finds the preferred species for an element type of {@code $type$}. * <p> --- 2924,2986 ---- public abstract void intoArray($type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j); #end[byteOrShort] // Species @Override ! public abstract Species<$Boxtype$> species(); /** * Class representing {@link $abstractvectortype$}'s of the same {@link Vector.Shape Shape}. */ ! static final class $Type$Species extends Vector.AbstractSpecies<$Boxtype$> { ! final Function<$type$[], $Type$Vector> vectorFactory; ! final Function<boolean[], Vector.Mask<$Boxtype$>> maskFactory; ! ! private $Type$Species(Vector.Shape shape, ! Class<?> boxType, ! Class<?> maskType, ! Function<$type$[], $Type$Vector> vectorFactory, ! Function<boolean[], Vector.Mask<$Boxtype$>> maskFactory) { ! super(shape, $type$.class, $Boxtype$.SIZE, boxType, maskType); ! this.vectorFactory = vectorFactory; ! this.maskFactory = maskFactory; ! } ! interface FOp { $type$ apply(int i); } interface FOpm { boolean apply(int i); } ! $Type$Vector op(FOp f) { ! $type$[] res = new $type$[length()]; ! for (int i = 0; i < length(); i++) { ! res[i] = f.apply(i); ! } ! return vectorFactory.apply(res); } ! $Type$Vector op(Vector.Mask<$Boxtype$> o, FOp f) { ! $type$[] res = new $type$[length()]; ! boolean[] mbits = ((AbstractMask<$Boxtype$>)o).getBits(); ! for (int i = 0; i < length(); i++) { ! if (mbits[i]) { ! res[i] = f.apply(i); } } ! return vectorFactory.apply(res); } ! Vector.Mask<$Boxtype$> 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 $type$}. * <p>
*** 2925,2954 **** * 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 $type$} */ ! @SuppressWarnings("unchecked") ! public static $Type$Species preferredSpecies() { return ($Type$Species) Species.ofPreferred($type$.class); } /** * Finds a species for an element type of {@code $type$} and shape. * * @param s the shape * @return a species for an element type of {@code $type$} and shape * @throws IllegalArgumentException if no such species exists for the shape */ ! @SuppressWarnings("unchecked") ! public static $Type$Species species(Vector.Shape s) { Objects.requireNonNull(s); switch (s) { ! case S_64_BIT: return $Type$64Vector.SPECIES; ! case S_128_BIT: return $Type$128Vector.SPECIES; ! case S_256_BIT: return $Type$256Vector.SPECIES; ! case S_512_BIT: return $Type$512Vector.SPECIES; ! case S_Max_BIT: return $Type$MaxVector.SPECIES; default: throw new IllegalArgumentException("Bad shape: " + s); } } } --- 2989,3042 ---- * 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 $type$} */ ! private static $Type$Species preferredSpecies() { return ($Type$Species) Species.ofPreferred($type$.class); } /** * Finds a species for an element type of {@code $type$} and shape. * * @param s the shape * @return a species for an element type of {@code $type$} and shape * @throws IllegalArgumentException if no such species exists for the shape */ ! static $Type$Species species(Vector.Shape s) { Objects.requireNonNull(s); switch (s) { ! case S_64_BIT: return ($Type$Species) SPECIES_64; ! case S_128_BIT: return ($Type$Species) SPECIES_128; ! case S_256_BIT: return ($Type$Species) SPECIES_256; ! case S_512_BIT: return ($Type$Species) SPECIES_512; ! case S_Max_BIT: return ($Type$Species) SPECIES_MAX; default: throw new IllegalArgumentException("Bad shape: " + s); } } + + /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_64_BIT Shape.S_64_BIT}. */ + public static final Species<$Boxtype$> SPECIES_64 = new $Type$Species(Shape.S_64_BIT, $Type$64Vector.class, $Type$64Vector.$Type$64Mask.class, + $Type$64Vector::new, $Type$64Vector.$Type$64Mask::new); + + /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_128_BIT Shape.S_128_BIT}. */ + public static final Species<$Boxtype$> SPECIES_128 = new $Type$Species(Shape.S_128_BIT, $Type$128Vector.class, $Type$128Vector.$Type$128Mask.class, + $Type$128Vector::new, $Type$128Vector.$Type$128Mask::new); + + /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_256_BIT Shape.S_256_BIT}. */ + public static final Species<$Boxtype$> SPECIES_256 = new $Type$Species(Shape.S_256_BIT, $Type$256Vector.class, $Type$256Vector.$Type$256Mask.class, + $Type$256Vector::new, $Type$256Vector.$Type$256Mask::new); + + /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_512_BIT Shape.S_512_BIT}. */ + public static final Species<$Boxtype$> SPECIES_512 = new $Type$Species(Shape.S_512_BIT, $Type$512Vector.class, $Type$512Vector.$Type$512Mask.class, + $Type$512Vector::new, $Type$512Vector.$Type$512Mask::new); + + /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_Max_BIT Shape.S_Max_BIT}. */ + public static final Species<$Boxtype$> SPECIES_MAX = new $Type$Species(Shape.S_Max_BIT, $Type$MaxVector.class, $Type$MaxVector.$Type$MaxMask.class, + $Type$MaxVector::new, $Type$MaxVector.$Type$MaxMask::new); + + /** + * Preferred species for {@link $Type$Vector}s. + * A preferred species is a species of maximal bit size for the platform. + */ + public static final Species<$Boxtype$> SPECIES_PREFERRED = (Species<$Boxtype$>) preferredSpecies(); }
< prev index next >