< prev index next >

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

Print this page

        

@@ -459,234 +459,10 @@
     public static IntVector random(Species<Integer> s) {
         ThreadLocalRandom r = ThreadLocalRandom.current();
         return ((IntSpecies)s).op(i -> r.nextInt());
     }
 
-    /**
-     * Returns a mask where each lane is set or unset according to given
-     * {@code boolean} values
-     * <p>
-     * For each mask lane, where {@code N} is the mask lane index,
-     * if the given {@code boolean} value at index {@code N} is {@code true}
-     * 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<Integer> maskFromValues(Species<Integer> species, boolean... bits) {
-        if (species.boxType() == IntMaxVector.class)
-            return new IntMaxVector.IntMaxMask(bits);
-        switch (species.bitSize()) {
-            case 64: return new Int64Vector.Int64Mask(bits);
-            case 128: return new Int128Vector.Int128Mask(bits);
-            case 256: return new Int256Vector.Int256Mask(bits);
-            case 512: return new Int512Vector.Int512Mask(bits);
-            default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
-        }
-    }
-
-    // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
-    static Mask<Integer> trueMask(Species<Integer> species) {
-        if (species.boxType() == IntMaxVector.class)
-            return IntMaxVector.IntMaxMask.TRUE_MASK;
-        switch (species.bitSize()) {
-            case 64: return Int64Vector.Int64Mask.TRUE_MASK;
-            case 128: return Int128Vector.Int128Mask.TRUE_MASK;
-            case 256: return Int256Vector.Int256Mask.TRUE_MASK;
-            case 512: return Int512Vector.Int512Mask.TRUE_MASK;
-            default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
-        }
-    }
-
-    static Mask<Integer> falseMask(Species<Integer> species) {
-        if (species.boxType() == IntMaxVector.class)
-            return IntMaxVector.IntMaxMask.FALSE_MASK;
-        switch (species.bitSize()) {
-            case 64: return Int64Vector.Int64Mask.FALSE_MASK;
-            case 128: return Int128Vector.Int128Mask.FALSE_MASK;
-            case 256: return Int256Vector.Int256Mask.FALSE_MASK;
-            case 512: return Int512Vector.Int512Mask.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<Integer> maskFromArray(Species<Integer> species, boolean[] bits, int ix) {
-        Objects.requireNonNull(bits);
-        ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length());
-        return VectorIntrinsics.load((Class<Mask<Integer>>) species.maskType(), int.class, species.length(),
-                                     bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
-                                     bits, ix, species,
-                                     (c, idx, s) -> (Mask<Integer>) ((IntSpecies)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<Integer> maskAllTrue(Species<Integer> species) {
-        return VectorIntrinsics.broadcastCoerced((Class<Mask<Integer>>) species.maskType(), int.class, species.length(),
-                                                 (int)-1,  species,
-                                                 ((z, s) -> trueMask(s)));
-    }
-
-    /**
-     * Returns a mask where all lanes are unset.
-     *
-     * @param species mask species
-     * @return a mask where all lanes are unset
-     */
-    @ForceInline
-    @SuppressWarnings("unchecked")
-    public static Mask<Integer> maskAllFalse(Species<Integer> species) {
-        return VectorIntrinsics.broadcastCoerced((Class<Mask<Integer>>) species.maskType(), int.class, species.length(),
-                                                 0, species, 
-                                                 ((z, s) -> falseMask(s)));
-    }
-
-    /**
-     * Returns a shuffle of mapped indexes where each lane element is
-     * the result of applying a mapping function to the corresponding lane
-     * 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<Integer> shuffle(Species<Integer> species, IntUnaryOperator f) {
-        if (species.boxType() == IntMaxVector.class)
-            return new IntMaxVector.IntMaxShuffle(f);
-        switch (species.bitSize()) {
-            case 64: return new Int64Vector.Int64Shuffle(f);
-            case 128: return new Int128Vector.Int128Shuffle(f);
-            case 256: return new Int256Vector.Int256Shuffle(f);
-            case 512: return new Int512Vector.Int512Shuffle(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<Integer> shuffleIota(Species<Integer> species) {
-        if (species.boxType() == IntMaxVector.class)
-            return new IntMaxVector.IntMaxShuffle(AbstractShuffle.IDENTITY);
-        switch (species.bitSize()) {
-            case 64: return new Int64Vector.Int64Shuffle(AbstractShuffle.IDENTITY);
-            case 128: return new Int128Vector.Int128Shuffle(AbstractShuffle.IDENTITY);
-            case 256: return new Int256Vector.Int256Shuffle(AbstractShuffle.IDENTITY);
-            case 512: return new Int512Vector.Int512Shuffle(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<Integer> shuffleFromValues(Species<Integer> species, int... ixs) {
-        if (species.boxType() == IntMaxVector.class)
-            return new IntMaxVector.IntMaxShuffle(ixs);
-        switch (species.bitSize()) {
-            case 64: return new Int64Vector.Int64Shuffle(ixs);
-            case 128: return new Int128Vector.Int128Shuffle(ixs);
-            case 256: return new Int256Vector.Int256Shuffle(ixs);
-            case 512: return new Int512Vector.Int512Shuffle(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<Integer> shuffleFromArray(Species<Integer> species, int[] ixs, int i) {
-        if (species.boxType() == IntMaxVector.class)
-            return new IntMaxVector.IntMaxShuffle(ixs, i);
-        switch (species.bitSize()) {
-            case 64: return new Int64Vector.Int64Shuffle(ixs, i);
-            case 128: return new Int128Vector.Int128Shuffle(ixs, i);
-            case 256: return new Int256Vector.Int256Shuffle(ixs, i);
-            case 512: return new Int512Vector.Int512Shuffle(ixs, i);
-            default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
-        }
-    }
-
     // Ops
 
     @Override
     public abstract IntVector add(Vector<Integer> v);
 

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

@@ -1729,28 +1506,20 @@
                 res[i] = f.apply(i);
             }
             return vectorFactory.apply(res);
         }
 
-        IntVector op(Vector.Mask<Integer> o, FOp f) {
+        IntVector op(Mask<Integer> o, FOp f) {
             int[] res = new int[length()];
             boolean[] mbits = ((AbstractMask<Integer>)o).getBits();
             for (int i = 0; i < length(); i++) {
                 if (mbits[i]) {
                     res[i] = f.apply(i);
                 }
             }
             return vectorFactory.apply(res);
         }
-
-        Vector.Mask<Integer> opm(IntVector.IntSpecies.FOpm f) {
-            boolean[] res = new boolean[length()];
-            for (int i = 0; i < length(); i++) {
-                res[i] = (boolean)f.apply(i);
-            }
-            return maskFactory.apply(res);
-        }
     }
 
     /**
      * Finds the preferred species for an element type of {@code int}.
      * <p>

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

@@ -1782,29 +1551,34 @@
             case S_Max_BIT: return (IntSpecies) SPECIES_MAX;
             default: throw new IllegalArgumentException("Bad shape: " + s);
         }
     }
 
-    /** Species representing {@link IntVector}s of {@link Vector.Shape#S_64_BIT Shape.S_64_BIT}. */
+    /** Species representing {@link IntVector}s of {@link Shape#S_64_BIT Shape.S_64_BIT}. */
     public static final Species<Integer> SPECIES_64 = new IntSpecies(Shape.S_64_BIT, Int64Vector.class, Int64Vector.Int64Mask.class,
-                                                                     Int64Vector::new, Int64Vector.Int64Mask::new);
+                                                                     Int64Vector::new, Int64Vector.Int64Mask::new,
+                                                                     Int64Vector.Int64Shuffle::new, Int64Vector.Int64Shuffle::new);
 
-    /** Species representing {@link IntVector}s of {@link Vector.Shape#S_128_BIT Shape.S_128_BIT}. */
+    /** Species representing {@link IntVector}s of {@link Shape#S_128_BIT Shape.S_128_BIT}. */
     public static final Species<Integer> SPECIES_128 = new IntSpecies(Shape.S_128_BIT, Int128Vector.class, Int128Vector.Int128Mask.class,
-                                                                      Int128Vector::new, Int128Vector.Int128Mask::new);
+                                                                      Int128Vector::new, Int128Vector.Int128Mask::new,
+                                                                      Int128Vector.Int128Shuffle::new, Int128Vector.Int128Shuffle::new);
 
-    /** Species representing {@link IntVector}s of {@link Vector.Shape#S_256_BIT Shape.S_256_BIT}. */
+    /** Species representing {@link IntVector}s of {@link Shape#S_256_BIT Shape.S_256_BIT}. */
     public static final Species<Integer> SPECIES_256 = new IntSpecies(Shape.S_256_BIT, Int256Vector.class, Int256Vector.Int256Mask.class,
-                                                                      Int256Vector::new, Int256Vector.Int256Mask::new);
+                                                                      Int256Vector::new, Int256Vector.Int256Mask::new,
+                                                                      Int256Vector.Int256Shuffle::new, Int256Vector.Int256Shuffle::new);
 
-    /** Species representing {@link IntVector}s of {@link Vector.Shape#S_512_BIT Shape.S_512_BIT}. */
+    /** Species representing {@link IntVector}s of {@link Shape#S_512_BIT Shape.S_512_BIT}. */
     public static final Species<Integer> SPECIES_512 = new IntSpecies(Shape.S_512_BIT, Int512Vector.class, Int512Vector.Int512Mask.class,
-                                                                      Int512Vector::new, Int512Vector.Int512Mask::new);
+                                                                      Int512Vector::new, Int512Vector.Int512Mask::new,
+                                                                      Int512Vector.Int512Shuffle::new, Int512Vector.Int512Shuffle::new);
 
-    /** Species representing {@link IntVector}s of {@link Vector.Shape#S_Max_BIT Shape.S_Max_BIT}. */
+    /** Species representing {@link IntVector}s of {@link Shape#S_Max_BIT Shape.S_Max_BIT}. */
     public static final Species<Integer> SPECIES_MAX = new IntSpecies(Shape.S_Max_BIT, IntMaxVector.class, IntMaxVector.IntMaxMask.class,
-                                                                      IntMaxVector::new, IntMaxVector.IntMaxMask::new);
+                                                                      IntMaxVector::new, IntMaxVector.IntMaxMask::new,
+                                                                      IntMaxVector.IntMaxShuffle::new, IntMaxVector.IntMaxShuffle::new);
 
     /**
      * Preferred species for {@link IntVector}s.
      * A preferred species is a species of maximal bit size for the platform.
      */
< prev index next >