< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.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

*** 26,35 **** --- 26,36 ---- import java.nio.ByteBuffer; 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.*;
*** 107,129 **** * @param species species of desired vector * @return a zero vector of given species */ @ForceInline @SuppressWarnings("unchecked") ! public static ByteVector zero(ByteSpecies 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(ByteSpecies, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue()); * }</pre> * * @param species species of desired vector --- 108,132 ---- * @param species species of desired vector * @return a zero vector of given species */ @ForceInline @SuppressWarnings("unchecked") ! public static ByteVector zero(Species<Byte> species) { ! return VectorIntrinsics.broadcastCoerced((Class<ByteVector>) species.boxType(), byte.class, species.length(), ! 0, species, ! ((bits, s) -> ((ByteSpecies)s).op(i -> (byte)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<Byte>, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue()); * }</pre> * * @param species species of desired vector
*** 133,143 **** * @throws IndexOutOfBoundsException if {@code i < 0} or * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)} */ @ForceInline @SuppressWarnings("unchecked") ! public static ByteVector fromByteArray(ByteSpecies species, byte[] a, int ix) { Objects.requireNonNull(a); ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE); return VectorIntrinsics.load((Class<ByteVector>) species.boxType(), byte.class, species.length(), a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, a, ix, species, --- 136,146 ---- * @throws IndexOutOfBoundsException if {@code i < 0} or * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)} */ @ForceInline @SuppressWarnings("unchecked") ! public static ByteVector fromByteArray(Species<Byte> species, byte[] a, int ix) { Objects.requireNonNull(a); ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE); return VectorIntrinsics.load((Class<ByteVector>) species.boxType(), byte.class, species.length(), a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, a, ix, species,
*** 155,165 **** * 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(ByteSpecies, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m); * }</pre> * * @param species species of desired vector --- 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(Species<Byte>, ByteBuffer, int, Mask) method} as follows: * <pre>{@code * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m); * }</pre> * * @param species species of desired vector
*** 174,184 **** * 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 ByteVector fromByteArray(ByteSpecies species, byte[] a, int ix, Mask<Byte> m) { return zero(species).blend(fromByteArray(species, a, ix), m); } /** * Loads a vector from an array starting at offset. --- 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 ByteVector fromByteArray(Species<Byte> species, byte[] a, int ix, Mask<Byte> m) { return zero(species).blend(fromByteArray(species, a, ix), m); } /** * Loads a vector from an array starting at offset.
*** 194,204 **** * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - this.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static ByteVector fromArray(ByteSpecies species, byte[] a, int i){ Objects.requireNonNull(a); i = VectorIntrinsics.checkIndex(i, a.length, species.length()); return VectorIntrinsics.load((Class<ByteVector>) species.boxType(), byte.class, species.length(), a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_BYTE_BASE_OFFSET, a, i, species, --- 197,207 ---- * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - this.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static ByteVector fromArray(Species<Byte> species, byte[] a, int i){ Objects.requireNonNull(a); i = VectorIntrinsics.checkIndex(i, a.length, species.length()); return VectorIntrinsics.load((Class<ByteVector>) species.boxType(), byte.class, species.length(), a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_BYTE_BASE_OFFSET, a, i, species,
*** 223,233 **** * @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 ByteVector fromArray(ByteSpecies species, byte[] a, int i, Mask<Byte> m) { return zero(species).blend(fromArray(species, a, i), m); } /** * Loads a vector from an array using indexes obtained from an index --- 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 ByteVector fromArray(Species<Byte> species, byte[] a, int i, Mask<Byte> m) { return zero(species).blend(fromArray(species, a, i), m); } /** * Loads a vector from an array using indexes obtained from an index
*** 248,259 **** * @throws IndexOutOfBoundsException if {@code j < 0}, or * {@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} */ ! public static ByteVector fromArray(ByteSpecies species, byte[] a, int i, int[] indexMap, int j) { ! return species.op(n -> a[i + indexMap[j + n]]); } /** * Loads a vector from an array using indexes obtained from an index * map and using a mask. * <p> --- 251,262 ---- * @throws IndexOutOfBoundsException if {@code j < 0}, or * {@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} */ ! public static ByteVector fromArray(Species<Byte> species, byte[] a, int i, int[] indexMap, int j) { ! return ((ByteSpecies)species).op(n -> a[i + indexMap[j + n]]); } /** * Loads a vector from an array using indexes obtained from an index * map and using a mask. * <p>
*** 275,286 **** * {@code j > indexMap.length - this.length()}, * 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} */ ! public static ByteVector fromArray(ByteSpecies species, byte[] a, int i, Mask<Byte> m, int[] indexMap, int j) { ! return species.op(m, n -> a[i + indexMap[j + n]]); } /** * Loads a vector from a {@link ByteBuffer byte buffer} starting at an * offset into the byte buffer. --- 278,289 ---- * {@code j > indexMap.length - this.length()}, * 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} */ ! public static ByteVector fromArray(Species<Byte> species, byte[] a, int i, Mask<Byte> m, int[] indexMap, int j) { ! return ((ByteSpecies)species).op(m, n -> a[i + indexMap[j + n]]); } /** * Loads a vector from a {@link ByteBuffer byte buffer} starting at an * offset into the byte buffer.
*** 288,298 **** * 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(ByteSpecies, ByteBuffer, int, Mask)} method} as follows: * <pre>{@code * return this.fromByteBuffer(b, i, this.maskAllTrue()) * }</pre> * * @param species species of desired vector --- 291,301 ---- * 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<Byte>, ByteBuffer, int, Mask)} method} as follows: * <pre>{@code * return this.fromByteBuffer(b, i, this.maskAllTrue()) * }</pre> * * @param species species of desired vector
*** 305,315 **** * {@code this.length() * this.elementSize() / Byte.SIZE} bytes * remaining in the byte buffer from the given offset */ @ForceInline @SuppressWarnings("unchecked") ! public static ByteVector fromByteBuffer(ByteSpecies 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<ByteVector>) species.boxType(), byte.class, species.length(), --- 308,318 ---- * {@code this.length() * this.elementSize() / Byte.SIZE} bytes * remaining in the byte buffer from the given offset */ @ForceInline @SuppressWarnings("unchecked") ! public static ByteVector fromByteBuffer(Species<Byte> 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<ByteVector>) species.boxType(), byte.class, species.length(),
*** 357,371 **** * 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 ByteVector fromByteBuffer(ByteSpecies species, ByteBuffer bb, int ix, Mask<Byte> 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} --- 360,448 ---- * 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 ByteVector fromByteBuffer(Species<Byte> species, ByteBuffer bb, int ix, Mask<Byte> 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 ByteVector broadcast(Species<Byte> s, byte e) { + return VectorIntrinsics.broadcastCoerced( + (Class<ByteVector>) s.boxType(), byte.class, s.length(), + e, s, + ((bits, sp) -> ((ByteSpecies)sp).op(i -> (byte)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 ByteVector scalars(Species<Byte> s, byte... es) { + Objects.requireNonNull(es); + int ix = VectorIntrinsics.checkIndex(0, es.length, s.length()); + return VectorIntrinsics.load((Class<ByteVector>) s.boxType(), byte.class, s.length(), + es, Unsafe.ARRAY_BYTE_BASE_OFFSET, + es, ix, s, + (c, idx, sp) -> ((ByteSpecies)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 ByteVector single(Species<Byte> s, byte 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 + * (byte){@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 ByteVector random(Species<Byte> s) { + ThreadLocalRandom r = ThreadLocalRandom.current(); + return ((ByteSpecies)s).op(i -> (byte) 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}
*** 375,385 **** * @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<Byte> maskFromValues(ByteSpecies species, boolean... bits) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxMask(bits); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Mask(bits); case 128: return new Byte128Vector.Byte128Mask(bits); --- 452,462 ---- * @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<Byte> maskFromValues(Species<Byte> species, boolean... bits) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxMask(bits); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Mask(bits); case 128: return new Byte128Vector.Byte128Mask(bits);
*** 388,398 **** default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } // @@@ This is a bad implementation -- makes lambdas capturing -- fix this ! static Mask<Byte> trueMask(ByteSpecies species) { if (species.boxType() == ByteMaxVector.class) return ByteMaxVector.ByteMaxMask.TRUE_MASK; switch (species.bitSize()) { case 64: return Byte64Vector.Byte64Mask.TRUE_MASK; case 128: return Byte128Vector.Byte128Mask.TRUE_MASK; --- 465,475 ---- default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } // @@@ This is a bad implementation -- makes lambdas capturing -- fix this ! static Mask<Byte> trueMask(Species<Byte> species) { if (species.boxType() == ByteMaxVector.class) return ByteMaxVector.ByteMaxMask.TRUE_MASK; switch (species.bitSize()) { case 64: return Byte64Vector.Byte64Mask.TRUE_MASK; case 128: return Byte128Vector.Byte128Mask.TRUE_MASK;
*** 400,410 **** case 512: return Byte512Vector.Byte512Mask.TRUE_MASK; default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } ! static Mask<Byte> falseMask(ByteSpecies species) { if (species.boxType() == ByteMaxVector.class) return ByteMaxVector.ByteMaxMask.FALSE_MASK; switch (species.bitSize()) { case 64: return Byte64Vector.Byte64Mask.FALSE_MASK; case 128: return Byte128Vector.Byte128Mask.FALSE_MASK; --- 477,487 ---- case 512: return Byte512Vector.Byte512Mask.TRUE_MASK; default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } ! static Mask<Byte> falseMask(Species<Byte> species) { if (species.boxType() == ByteMaxVector.class) return ByteMaxVector.ByteMaxMask.FALSE_MASK; switch (species.bitSize()) { case 64: return Byte64Vector.Byte64Mask.FALSE_MASK; case 128: return Byte128Vector.Byte128Mask.FALSE_MASK;
*** 428,438 **** * @throws IndexOutOfBoundsException if {@code ix < 0}, or * {@code ix > bits.length - species.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Byte> maskFromArray(ByteSpecies species, boolean[] bits, int ix) { Objects.requireNonNull(bits); ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length()); return VectorIntrinsics.load((Class<Mask<Byte>>) species.maskType(), byte.class, species.length(), bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, bits, ix, species, --- 505,515 ---- * @throws IndexOutOfBoundsException if {@code ix < 0}, or * {@code ix > bits.length - species.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Byte> maskFromArray(Species<Byte> species, boolean[] bits, int ix) { Objects.requireNonNull(bits); ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length()); return VectorIntrinsics.load((Class<Mask<Byte>>) species.maskType(), byte.class, species.length(), bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, bits, ix, species,
*** 445,472 **** * @param species mask species * @return a mask where all lanes are set */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Byte> maskAllTrue(ByteSpecies species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<Byte>>) species.maskType(), byte.class, species.length(), (byte)-1, species, ! ((z, s) -> trueMask((ByteSpecies)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<Byte> maskAllFalse(ByteSpecies species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<Byte>>) species.maskType(), byte.class, species.length(), 0, species, ! ((z, s) -> falseMask((ByteSpecies)s))); } /** * Returns a shuffle of mapped indexes where each lane element is * the result of applying a mapping function to the corresponding lane --- 522,549 ---- * @param species mask species * @return a mask where all lanes are set */ @ForceInline @SuppressWarnings("unchecked") ! public static Mask<Byte> maskAllTrue(Species<Byte> species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<Byte>>) species.maskType(), byte.class, species.length(), (byte)-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<Byte> maskAllFalse(Species<Byte> species) { return VectorIntrinsics.broadcastCoerced((Class<Mask<Byte>>) species.maskType(), byte.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
*** 490,500 **** * @param species shuffle species * @param f the lane index mapping function * @return a shuffle of mapped indexes */ @ForceInline ! public static Shuffle<Byte> shuffle(ByteSpecies species, IntUnaryOperator f) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxShuffle(f); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Shuffle(f); case 128: return new Byte128Vector.Byte128Shuffle(f); --- 567,577 ---- * @param species shuffle species * @param f the lane index mapping function * @return a shuffle of mapped indexes */ @ForceInline ! public static Shuffle<Byte> shuffle(Species<Byte> species, IntUnaryOperator f) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxShuffle(f); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Shuffle(f); case 128: return new Byte128Vector.Byte128Shuffle(f);
*** 516,526 **** * * @param species shuffle species * @return a shuffle of lane indexes */ @ForceInline ! public static Shuffle<Byte> shuffleIota(ByteSpecies species) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxShuffle(AbstractShuffle.IDENTITY); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Shuffle(AbstractShuffle.IDENTITY); case 128: return new Byte128Vector.Byte128Shuffle(AbstractShuffle.IDENTITY); --- 593,603 ---- * * @param species shuffle species * @return a shuffle of lane indexes */ @ForceInline ! public static Shuffle<Byte> shuffleIota(Species<Byte> species) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxShuffle(AbstractShuffle.IDENTITY); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Shuffle(AbstractShuffle.IDENTITY); case 128: return new Byte128Vector.Byte128Shuffle(AbstractShuffle.IDENTITY);
*** 545,555 **** * {@code int} value * @throws IndexOutOfBoundsException if the number of int values is * {@code < species.length()} */ @ForceInline ! public static Shuffle<Byte> shuffleFromValues(ByteSpecies species, int... ixs) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxShuffle(ixs); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Shuffle(ixs); case 128: return new Byte128Vector.Byte128Shuffle(ixs); --- 622,632 ---- * {@code int} value * @throws IndexOutOfBoundsException if the number of int values is * {@code < species.length()} */ @ForceInline ! public static Shuffle<Byte> shuffleFromValues(Species<Byte> species, int... ixs) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxShuffle(ixs); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Shuffle(ixs); case 128: return new Byte128Vector.Byte128Shuffle(ixs);
*** 573,583 **** * @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<Byte> shuffleFromArray(ByteSpecies species, int[] ixs, int i) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxShuffle(ixs, i); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Shuffle(ixs, i); case 128: return new Byte128Vector.Byte128Shuffle(ixs, i); --- 650,660 ---- * @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<Byte> shuffleFromArray(Species<Byte> species, int[] ixs, int i) { if (species.boxType() == ByteMaxVector.class) return new ByteMaxVector.ByteMaxShuffle(ixs, i); switch (species.bitSize()) { case 64: return new Byte64Vector.Byte64Shuffle(ixs, i); case 128: return new Byte128Vector.Byte128Shuffle(ixs, i);
*** 585,595 **** case 512: return new Byte512Vector.Byte512Shuffle(ixs, i); default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); } } - // Ops @Override public abstract ByteVector add(Vector<Byte> v); --- 662,671 ----
*** 1466,1555 **** forEach(m, (n, e) -> a[i + indexMap[j + n]] = e); } // Species @Override ! public abstract ByteSpecies species(); /** * Class representing {@link ByteVector}'s of the same {@link Vector.Shape Shape}. */ ! public static abstract class ByteSpecies extends Vector.Species<Byte> { interface FOp { byte apply(int i); } - abstract ByteVector op(FOp f); - - abstract ByteVector op(Mask<Byte> m, FOp f); - interface FOpm { boolean apply(int i); } ! abstract Mask<Byte> opm(FOpm f); ! ! ! ! // Factories ! ! @Override ! public abstract ByteVector 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 ByteVector broadcast(byte 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 ByteVector single(byte 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 (byte)ThreadLocalRandom#nextInt()}. ! * ! * @return a vector where each lane elements is set to a randomly ! * generated primitive value ! */ ! public ByteVector random() { ! ThreadLocalRandom r = ThreadLocalRandom.current(); ! return op(i -> (byte) 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 ByteVector scalars(byte... es); } /** * Finds the preferred species for an element type of {@code byte}. * <p> --- 1542,1604 ---- forEach(m, (n, e) -> a[i + indexMap[j + n]] = e); } // Species @Override ! public abstract Species<Byte> species(); /** * Class representing {@link ByteVector}'s of the same {@link Vector.Shape Shape}. */ ! static final class ByteSpecies extends Vector.AbstractSpecies<Byte> { ! final Function<byte[], ByteVector> vectorFactory; ! final Function<boolean[], Vector.Mask<Byte>> maskFactory; ! ! private ByteSpecies(Vector.Shape shape, ! Class<?> boxType, ! Class<?> maskType, ! Function<byte[], ByteVector> vectorFactory, ! Function<boolean[], Vector.Mask<Byte>> maskFactory) { ! super(shape, byte.class, Byte.SIZE, boxType, maskType); ! this.vectorFactory = vectorFactory; ! this.maskFactory = maskFactory; ! } ! interface FOp { byte apply(int i); } interface FOpm { boolean apply(int i); } ! ByteVector op(FOp f) { ! byte[] res = new byte[length()]; ! for (int i = 0; i < length(); i++) { ! res[i] = f.apply(i); ! } ! return vectorFactory.apply(res); } ! ByteVector op(Vector.Mask<Byte> o, FOp f) { ! byte[] res = new byte[length()]; ! boolean[] mbits = ((AbstractMask<Byte>)o).getBits(); ! for (int i = 0; i < length(); i++) { ! if (mbits[i]) { ! res[i] = f.apply(i); ! } ! } ! return vectorFactory.apply(res); } ! Vector.Mask<Byte> 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 byte}. * <p>
*** 1558,1587 **** * 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 byte} */ ! @SuppressWarnings("unchecked") ! public static ByteSpecies preferredSpecies() { return (ByteSpecies) Species.ofPreferred(byte.class); } /** * Finds a species for an element type of {@code byte} and shape. * * @param s the shape * @return a species for an element type of {@code byte} and shape * @throws IllegalArgumentException if no such species exists for the shape */ ! @SuppressWarnings("unchecked") ! public static ByteSpecies species(Vector.Shape s) { Objects.requireNonNull(s); switch (s) { ! case S_64_BIT: return Byte64Vector.SPECIES; ! case S_128_BIT: return Byte128Vector.SPECIES; ! case S_256_BIT: return Byte256Vector.SPECIES; ! case S_512_BIT: return Byte512Vector.SPECIES; ! case S_Max_BIT: return ByteMaxVector.SPECIES; default: throw new IllegalArgumentException("Bad shape: " + s); } } } --- 1607,1660 ---- * 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 byte} */ ! private static ByteSpecies preferredSpecies() { return (ByteSpecies) Species.ofPreferred(byte.class); } /** * Finds a species for an element type of {@code byte} and shape. * * @param s the shape * @return a species for an element type of {@code byte} and shape * @throws IllegalArgumentException if no such species exists for the shape */ ! static ByteSpecies species(Vector.Shape s) { Objects.requireNonNull(s); switch (s) { ! case S_64_BIT: return (ByteSpecies) SPECIES_64; ! case S_128_BIT: return (ByteSpecies) SPECIES_128; ! case S_256_BIT: return (ByteSpecies) SPECIES_256; ! case S_512_BIT: return (ByteSpecies) SPECIES_512; ! case S_Max_BIT: return (ByteSpecies) SPECIES_MAX; default: throw new IllegalArgumentException("Bad shape: " + s); } } + + /** Species representing {@link ByteVector}s of {@link Vector.Shape#S_64_BIT Shape.S_64_BIT}. */ + public static final Species<Byte> SPECIES_64 = new ByteSpecies(Shape.S_64_BIT, Byte64Vector.class, Byte64Vector.Byte64Mask.class, + Byte64Vector::new, Byte64Vector.Byte64Mask::new); + + /** Species representing {@link ByteVector}s of {@link Vector.Shape#S_128_BIT Shape.S_128_BIT}. */ + public static final Species<Byte> SPECIES_128 = new ByteSpecies(Shape.S_128_BIT, Byte128Vector.class, Byte128Vector.Byte128Mask.class, + Byte128Vector::new, Byte128Vector.Byte128Mask::new); + + /** Species representing {@link ByteVector}s of {@link Vector.Shape#S_256_BIT Shape.S_256_BIT}. */ + public static final Species<Byte> SPECIES_256 = new ByteSpecies(Shape.S_256_BIT, Byte256Vector.class, Byte256Vector.Byte256Mask.class, + Byte256Vector::new, Byte256Vector.Byte256Mask::new); + + /** Species representing {@link ByteVector}s of {@link Vector.Shape#S_512_BIT Shape.S_512_BIT}. */ + public static final Species<Byte> SPECIES_512 = new ByteSpecies(Shape.S_512_BIT, Byte512Vector.class, Byte512Vector.Byte512Mask.class, + Byte512Vector::new, Byte512Vector.Byte512Mask::new); + + /** Species representing {@link ByteVector}s of {@link Vector.Shape#S_Max_BIT Shape.S_Max_BIT}. */ + public static final Species<Byte> SPECIES_MAX = new ByteSpecies(Shape.S_Max_BIT, ByteMaxVector.class, ByteMaxVector.ByteMaxMask.class, + ByteMaxVector::new, ByteMaxVector.ByteMaxMask::new); + + /** + * Preferred species for {@link ByteVector}s. + * A preferred species is a species of maximal bit size for the platform. + */ + public static final Species<Byte> SPECIES_PREFERRED = (Species<Byte>) preferredSpecies(); }
< prev index next >