< prev index next >

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

Print this page

        

*** 513,746 **** 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} - * then the mask lane at index {@code N} is set, otherwise it is unset. - * - * @param species mask species - * @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); - case 256: return new $Type$256Vector.$Type$256Mask(bits); - case 512: return new $Type$512Vector.$Type$512Mask(bits); - 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; - case 256: return $Type$256Vector.$Type$256Mask.TRUE_MASK; - 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; - case 256: return $Type$256Vector.$Type$256Mask.FALSE_MASK; - case 512: return $Type$512Vector.$Type$512Mask.FALSE_MASK; - default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); - } - } - - /** - * Loads a mask from a {@code boolean} array starting at an offset. - * <p> - * For each mask lane, where {@code N} is the mask lane index, - * if the array element at index {@code ix + N} is {@code true} then the - * mask lane at index {@code N} is set, otherwise it is unset. - * - * @param species mask species - * @param bits the {@code boolean} array - * @param ix the offset into the array - * @return the mask loaded from a {@code boolean} array - * @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, - (c, idx, s) -> (Mask<$Boxtype$>) (($Type$Species)s).opm(n -> c[idx + n])); - } - - /** - * Returns a mask where all lanes are set. - * - * @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 - * index. - * <p> - * Care should be taken to ensure Shuffle values produced from this - * method are consumed as constants to ensure optimal generation of - * code. For example, values held in static final fields or values - * held in loop constant local variables. - * <p> - * This method behaves as if a shuffle is created from an array of - * mapped indexes as follows: - * <pre>{@code - * int[] a = new int[species.length()]; - * for (int i = 0; i < a.length; i++) { - * a[i] = f.applyAsInt(i); - * } - * return this.shuffleFromValues(a); - * }</pre> - * - * @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); - case 256: return new $Type$256Vector.$Type$256Shuffle(f); - case 512: return new $Type$512Vector.$Type$512Shuffle(f); - default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); - } - } - - /** - * Returns a shuffle where each lane element is the value of its - * corresponding lane index. - * <p> - * This method behaves as if a shuffle is created from an identity - * index mapping function as follows: - * <pre>{@code - * return this.shuffle(i -> i); - * }</pre> - * - * @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); - case 256: return new $Type$256Vector.$Type$256Shuffle(AbstractShuffle.IDENTITY); - case 512: return new $Type$512Vector.$Type$512Shuffle(AbstractShuffle.IDENTITY); - default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); - } - } - - /** - * Returns a shuffle where each lane element is set to a given - * {@code int} value logically AND'ed by the species length minus one. - * <p> - * For each shuffle lane, where {@code N} is the shuffle lane index, the - * the {@code int} value at index {@code N} logically AND'ed by - * {@code species.length() - 1} is placed into the resulting shuffle at - * lane index {@code N}. - * - * @param species shuffle species - * @param ixs the given {@code int} values - * @return a shuffle where each lane element is set to a given - * {@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); - case 256: return new $Type$256Vector.$Type$256Shuffle(ixs); - case 512: return new $Type$512Vector.$Type$512Shuffle(ixs); - default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); - } - } - - /** - * Loads a shuffle from an {@code int} array starting at an offset. - * <p> - * For each shuffle lane, where {@code N} is the shuffle lane index, the - * array element at index {@code i + N} logically AND'ed by - * {@code species.length() - 1} is placed into the resulting shuffle at lane - * index {@code N}. - * - * @param species shuffle species - * @param ixs the {@code int} array - * @param i the offset into the array - * @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); - case 256: return new $Type$256Vector.$Type$256Shuffle(ixs, i); - 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); --- 513,522 ----
*** 2927,2950 **** @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); } --- 2703,2727 ---- @Override public abstract Species<$Boxtype$> species(); /** ! * Class representing {@link $abstractvectortype$}'s of the same {@link Shape Shape}. */ ! static final class $Type$Species extends AbstractSpecies<$Boxtype$> { final Function<$type$[], $Type$Vector> vectorFactory; ! private $Type$Species(Shape shape, Class<?> boxType, Class<?> maskType, Function<$type$[], $Type$Vector> vectorFactory, ! Function<boolean[], Mask<$Boxtype$>> maskFactory, ! Function<IntUnaryOperator, Shuffle<$Boxtype$>> shuffleFromArrayFactory, ! fShuffleFromArray<$Boxtype$> shuffleFromOpFactory) { ! super(shape, $type$.class, $Boxtype$.SIZE, boxType, maskType, maskFactory, ! shuffleFromArrayFactory, shuffleFromOpFactory); this.vectorFactory = vectorFactory; } interface FOp { $type$ apply(int i); }
*** 2959,2986 **** 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> --- 2736,2755 ---- res[i] = f.apply(i); } return vectorFactory.apply(res); } ! $Type$Vector op(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); } } /** * Finds the preferred species for an element type of {@code $type$}. * <p>
*** 3000,3010 **** * * @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; --- 2769,2779 ---- * * @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(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;
*** 3012,3040 **** 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. */ --- 2781,2814 ---- case S_Max_BIT: return ($Type$Species) SPECIES_MAX; default: throw new IllegalArgumentException("Bad shape: " + s); } } ! /** Species representing {@link $Type$Vector}s of {@link 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, ! $Type$64Vector.$Type$64Shuffle::new, $Type$64Vector.$Type$64Shuffle::new); ! /** Species representing {@link $Type$Vector}s of {@link 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, ! $Type$128Vector.$Type$128Shuffle::new, $Type$128Vector.$Type$128Shuffle::new); ! /** Species representing {@link $Type$Vector}s of {@link 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, ! $Type$256Vector.$Type$256Shuffle::new, $Type$256Vector.$Type$256Shuffle::new); ! /** Species representing {@link $Type$Vector}s of {@link 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, ! $Type$512Vector.$Type$512Shuffle::new, $Type$512Vector.$Type$512Shuffle::new); ! /** Species representing {@link $Type$Vector}s of {@link 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, ! $Type$MaxVector.$Type$MaxShuffle::new, $Type$MaxVector.$Type$MaxShuffle::new); /** * Preferred species for {@link $Type$Vector}s. * A preferred species is a species of maximal bit size for the platform. */
< prev index next >