< prev index next >

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

Print this page

        

@@ -439,234 +439,10 @@
     public static ShortVector random(Species<Short> s) {
         ThreadLocalRandom r = ThreadLocalRandom.current();
         return ((ShortSpecies)s).op(i -> (short) 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}
-     * 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<Short> maskFromValues(Species<Short> species, boolean... bits) {
-        if (species.boxType() == ShortMaxVector.class)
-            return new ShortMaxVector.ShortMaxMask(bits);
-        switch (species.bitSize()) {
-            case 64: return new Short64Vector.Short64Mask(bits);
-            case 128: return new Short128Vector.Short128Mask(bits);
-            case 256: return new Short256Vector.Short256Mask(bits);
-            case 512: return new Short512Vector.Short512Mask(bits);
-            default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
-        }
-    }
-
-    // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
-    static Mask<Short> trueMask(Species<Short> species) {
-        if (species.boxType() == ShortMaxVector.class)
-            return ShortMaxVector.ShortMaxMask.TRUE_MASK;
-        switch (species.bitSize()) {
-            case 64: return Short64Vector.Short64Mask.TRUE_MASK;
-            case 128: return Short128Vector.Short128Mask.TRUE_MASK;
-            case 256: return Short256Vector.Short256Mask.TRUE_MASK;
-            case 512: return Short512Vector.Short512Mask.TRUE_MASK;
-            default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
-        }
-    }
-
-    static Mask<Short> falseMask(Species<Short> species) {
-        if (species.boxType() == ShortMaxVector.class)
-            return ShortMaxVector.ShortMaxMask.FALSE_MASK;
-        switch (species.bitSize()) {
-            case 64: return Short64Vector.Short64Mask.FALSE_MASK;
-            case 128: return Short128Vector.Short128Mask.FALSE_MASK;
-            case 256: return Short256Vector.Short256Mask.FALSE_MASK;
-            case 512: return Short512Vector.Short512Mask.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<Short> maskFromArray(Species<Short> species, boolean[] bits, int ix) {
-        Objects.requireNonNull(bits);
-        ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length());
-        return VectorIntrinsics.load((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
-                                     bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
-                                     bits, ix, species,
-                                     (c, idx, s) -> (Mask<Short>) ((ShortSpecies)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<Short> maskAllTrue(Species<Short> species) {
-        return VectorIntrinsics.broadcastCoerced((Class<Mask<Short>>) species.maskType(), short.class, species.length(),
-                                                 (short)-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<Short> maskAllFalse(Species<Short> species) {
-        return VectorIntrinsics.broadcastCoerced((Class<Mask<Short>>) species.maskType(), short.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<Short> shuffle(Species<Short> species, IntUnaryOperator f) {
-        if (species.boxType() == ShortMaxVector.class)
-            return new ShortMaxVector.ShortMaxShuffle(f);
-        switch (species.bitSize()) {
-            case 64: return new Short64Vector.Short64Shuffle(f);
-            case 128: return new Short128Vector.Short128Shuffle(f);
-            case 256: return new Short256Vector.Short256Shuffle(f);
-            case 512: return new Short512Vector.Short512Shuffle(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<Short> shuffleIota(Species<Short> species) {
-        if (species.boxType() == ShortMaxVector.class)
-            return new ShortMaxVector.ShortMaxShuffle(AbstractShuffle.IDENTITY);
-        switch (species.bitSize()) {
-            case 64: return new Short64Vector.Short64Shuffle(AbstractShuffle.IDENTITY);
-            case 128: return new Short128Vector.Short128Shuffle(AbstractShuffle.IDENTITY);
-            case 256: return new Short256Vector.Short256Shuffle(AbstractShuffle.IDENTITY);
-            case 512: return new Short512Vector.Short512Shuffle(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<Short> shuffleFromValues(Species<Short> species, int... ixs) {
-        if (species.boxType() == ShortMaxVector.class)
-            return new ShortMaxVector.ShortMaxShuffle(ixs);
-        switch (species.bitSize()) {
-            case 64: return new Short64Vector.Short64Shuffle(ixs);
-            case 128: return new Short128Vector.Short128Shuffle(ixs);
-            case 256: return new Short256Vector.Short256Shuffle(ixs);
-            case 512: return new Short512Vector.Short512Shuffle(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<Short> shuffleFromArray(Species<Short> species, int[] ixs, int i) {
-        if (species.boxType() == ShortMaxVector.class)
-            return new ShortMaxVector.ShortMaxShuffle(ixs, i);
-        switch (species.bitSize()) {
-            case 64: return new Short64Vector.Short64Shuffle(ixs, i);
-            case 128: return new Short128Vector.Short128Shuffle(ixs, i);
-            case 256: return new Short256Vector.Short256Shuffle(ixs, i);
-            case 512: return new Short512Vector.Short512Shuffle(ixs, i);
-            default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
-        }
-    }
-
     // Ops
 
     @Override
     public abstract ShortVector add(Vector<Short> v);
 

@@ -1546,24 +1322,25 @@
 
     @Override
     public abstract Species<Short> species();
 
     /**
-     * Class representing {@link ShortVector}'s of the same {@link Vector.Shape Shape}.
+     * Class representing {@link ShortVector}'s of the same {@link Shape Shape}.
      */
-    static final class ShortSpecies extends Vector.AbstractSpecies<Short> {
+    static final class ShortSpecies extends AbstractSpecies<Short> {
         final Function<short[], ShortVector> vectorFactory;
-        final Function<boolean[], Vector.Mask<Short>> maskFactory;
 
-        private ShortSpecies(Vector.Shape shape,
+        private ShortSpecies(Shape shape,
                           Class<?> boxType,
                           Class<?> maskType,
                           Function<short[], ShortVector> vectorFactory,
-                          Function<boolean[], Vector.Mask<Short>> maskFactory) {
-            super(shape, short.class, Short.SIZE, boxType, maskType);
+                          Function<boolean[], Mask<Short>> maskFactory,
+                          Function<IntUnaryOperator, Shuffle<Short>> shuffleFromArrayFactory,
+                          fShuffleFromArray<Short> shuffleFromOpFactory) {
+            super(shape, short.class, Short.SIZE, boxType, maskType, maskFactory,
+                  shuffleFromArrayFactory, shuffleFromOpFactory);
             this.vectorFactory = vectorFactory;
-            this.maskFactory = maskFactory;
         }
 
         interface FOp {
             short apply(int i);
         }

@@ -1578,28 +1355,20 @@
                 res[i] = f.apply(i);
             }
             return vectorFactory.apply(res);
         }
 
-        ShortVector op(Vector.Mask<Short> o, FOp f) {
+        ShortVector op(Mask<Short> o, FOp f) {
             short[] res = new short[length()];
             boolean[] mbits = ((AbstractMask<Short>)o).getBits();
             for (int i = 0; i < length(); i++) {
                 if (mbits[i]) {
                     res[i] = f.apply(i);
                 }
             }
             return vectorFactory.apply(res);
         }
-
-        Vector.Mask<Short> 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 short}.
      * <p>

@@ -1619,11 +1388,11 @@
      *
      * @param s the shape
      * @return a species for an element type of {@code short} and shape
      * @throws IllegalArgumentException if no such species exists for the shape
      */
-    static ShortSpecies species(Vector.Shape s) {
+    static ShortSpecies species(Shape s) {
         Objects.requireNonNull(s);
         switch (s) {
             case S_64_BIT: return (ShortSpecies) SPECIES_64;
             case S_128_BIT: return (ShortSpecies) SPECIES_128;
             case S_256_BIT: return (ShortSpecies) SPECIES_256;

@@ -1631,29 +1400,34 @@
             case S_Max_BIT: return (ShortSpecies) SPECIES_MAX;
             default: throw new IllegalArgumentException("Bad shape: " + s);
         }
     }
 
-    /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_64_BIT Shape.S_64_BIT}. */
+    /** Species representing {@link ShortVector}s of {@link Shape#S_64_BIT Shape.S_64_BIT}. */
     public static final Species<Short> SPECIES_64 = new ShortSpecies(Shape.S_64_BIT, Short64Vector.class, Short64Vector.Short64Mask.class,
-                                                                     Short64Vector::new, Short64Vector.Short64Mask::new);
+                                                                     Short64Vector::new, Short64Vector.Short64Mask::new,
+                                                                     Short64Vector.Short64Shuffle::new, Short64Vector.Short64Shuffle::new);
 
-    /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_128_BIT Shape.S_128_BIT}. */
+    /** Species representing {@link ShortVector}s of {@link Shape#S_128_BIT Shape.S_128_BIT}. */
     public static final Species<Short> SPECIES_128 = new ShortSpecies(Shape.S_128_BIT, Short128Vector.class, Short128Vector.Short128Mask.class,
-                                                                      Short128Vector::new, Short128Vector.Short128Mask::new);
+                                                                      Short128Vector::new, Short128Vector.Short128Mask::new,
+                                                                      Short128Vector.Short128Shuffle::new, Short128Vector.Short128Shuffle::new);
 
-    /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_256_BIT Shape.S_256_BIT}. */
+    /** Species representing {@link ShortVector}s of {@link Shape#S_256_BIT Shape.S_256_BIT}. */
     public static final Species<Short> SPECIES_256 = new ShortSpecies(Shape.S_256_BIT, Short256Vector.class, Short256Vector.Short256Mask.class,
-                                                                      Short256Vector::new, Short256Vector.Short256Mask::new);
+                                                                      Short256Vector::new, Short256Vector.Short256Mask::new,
+                                                                      Short256Vector.Short256Shuffle::new, Short256Vector.Short256Shuffle::new);
 
-    /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_512_BIT Shape.S_512_BIT}. */
+    /** Species representing {@link ShortVector}s of {@link Shape#S_512_BIT Shape.S_512_BIT}. */
     public static final Species<Short> SPECIES_512 = new ShortSpecies(Shape.S_512_BIT, Short512Vector.class, Short512Vector.Short512Mask.class,
-                                                                      Short512Vector::new, Short512Vector.Short512Mask::new);
+                                                                      Short512Vector::new, Short512Vector.Short512Mask::new,
+                                                                      Short512Vector.Short512Shuffle::new, Short512Vector.Short512Shuffle::new);
 
-    /** Species representing {@link ShortVector}s of {@link Vector.Shape#S_Max_BIT Shape.S_Max_BIT}. */
+    /** Species representing {@link ShortVector}s of {@link Shape#S_Max_BIT Shape.S_Max_BIT}. */
     public static final Species<Short> SPECIES_MAX = new ShortSpecies(Shape.S_Max_BIT, ShortMaxVector.class, ShortMaxVector.ShortMaxMask.class,
-                                                                      ShortMaxVector::new, ShortMaxVector.ShortMaxMask::new);
+                                                                      ShortMaxVector::new, ShortMaxVector.ShortMaxMask::new,
+                                                                      ShortMaxVector.ShortMaxShuffle::new, ShortMaxVector.ShortMaxShuffle::new);
 
     /**
      * Preferred species for {@link ShortVector}s.
      * A preferred species is a species of maximal bit size for the platform.
      */
< prev index next >