< prev index next >

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

Print this page
rev 55589 : 8221817: [vector] No suitable species for indexMap of Gather/Scatter VectorAPI
Reviewed-by: duke


 240      *
 241      * @param species species of desired vector
 242      * @param a the array
 243      * @param i the offset into the array, may be negative if relative
 244      * indexes in the index map compensate to produce a value within the
 245      * array bounds
 246      * @param indexMap the index map
 247      * @param j the offset into the index map
 248      * @return the vector loaded from an array
 249      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 250      * {@code j > indexMap.length - this.length()},
 251      * or for any vector lane index {@code N} the result of
 252      * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
 253      */
 254     @ForceInline
 255     @SuppressWarnings("unchecked")
 256     public static IntVector fromArray(IntSpecies species, int[] a, int i, int[] indexMap, int j) {
 257         Objects.requireNonNull(a);
 258         Objects.requireNonNull(indexMap);
 259 
 260 
 261         // Index vector: vix[0:n] = k -> i + indexMap[j + i]
 262         IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i);
 263 
 264         vix = VectorIntrinsics.checkIndex(vix, a.length);
 265 
 266         return VectorIntrinsics.loadWithMap((Class<IntVector>) species.boxType(), int.class, species.length(),
 267                                             species.indexSpecies().vectorType(), a, Unsafe.ARRAY_INT_BASE_OFFSET, vix,
 268                                             a, i, indexMap, j, species,
 269                                            (c, idx, iMap, idy, s) -> ((IntSpecies)s).op(n -> c[idx + iMap[idy+n]]));
 270         }
 271 
 272     /**
 273      * Loads a vector from an array using indexes obtained from an index
 274      * map and using a mask.
 275      * <p>
 276      * For each vector lane, where {@code N} is the vector lane index,
 277      * if the mask lane at index {@code N} is set then the array element at
 278      * index {@code i + indexMap[j + N]} is placed into the resulting vector
 279      * at lane index {@code N}.
 280      *


1623 
1624     /**
1625      * Class representing {@link IntVector}'s of the same {@link Vector.Shape Shape}.
1626      */
1627     public static abstract class IntSpecies extends Vector.Species<Integer> {
1628         interface FOp {
1629             int apply(int i);
1630         }
1631 
1632         abstract IntVector op(FOp f);
1633 
1634         abstract IntVector op(Mask<Integer> m, FOp f);
1635 
1636         interface FOpm {
1637             boolean apply(int i);
1638         }
1639 
1640         abstract Mask<Integer> opm(FOpm f);
1641 
1642         abstract IntVector.IntSpecies indexSpecies();
1643 
1644 
1645         // Factories
1646 
1647         @Override
1648         public abstract IntVector zero();
1649 
1650         /**
1651          * Returns a vector where all lane elements are set to the primitive
1652          * value {@code e}.
1653          *
1654          * @param e the value
1655          * @return a vector of vector where all lane elements are set to
1656          * the primitive value {@code e}
1657          */
1658         public abstract IntVector broadcast(int e);
1659 
1660         /**
1661          * Returns a vector where the first lane element is set to the primtive
1662          * value {@code e}, all other lane elements are set to the default
1663          * value.




 240      *
 241      * @param species species of desired vector
 242      * @param a the array
 243      * @param i the offset into the array, may be negative if relative
 244      * indexes in the index map compensate to produce a value within the
 245      * array bounds
 246      * @param indexMap the index map
 247      * @param j the offset into the index map
 248      * @return the vector loaded from an array
 249      * @throws IndexOutOfBoundsException if {@code j < 0}, or
 250      * {@code j > indexMap.length - this.length()},
 251      * or for any vector lane index {@code N} the result of
 252      * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
 253      */
 254     @ForceInline
 255     @SuppressWarnings("unchecked")
 256     public static IntVector fromArray(IntSpecies species, int[] a, int i, int[] indexMap, int j) {
 257         Objects.requireNonNull(a);
 258         Objects.requireNonNull(indexMap);
 259 

 260         // Index vector: vix[0:n] = k -> i + indexMap[j + i]
 261         IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i);
 262 
 263         vix = VectorIntrinsics.checkIndex(vix, a.length);
 264 
 265         return VectorIntrinsics.loadWithMap((Class<IntVector>) species.boxType(), int.class, species.length(),
 266                                             species.indexSpecies().vectorType(), a, Unsafe.ARRAY_INT_BASE_OFFSET, vix,
 267                                             a, i, indexMap, j, species,
 268                                            (c, idx, iMap, idy, s) -> ((IntSpecies)s).op(n -> c[idx + iMap[idy+n]]));
 269         }
 270 
 271     /**
 272      * Loads a vector from an array using indexes obtained from an index
 273      * map and using a mask.
 274      * <p>
 275      * For each vector lane, where {@code N} is the vector lane index,
 276      * if the mask lane at index {@code N} is set then the array element at
 277      * index {@code i + indexMap[j + N]} is placed into the resulting vector
 278      * at lane index {@code N}.
 279      *


1622 
1623     /**
1624      * Class representing {@link IntVector}'s of the same {@link Vector.Shape Shape}.
1625      */
1626     public static abstract class IntSpecies extends Vector.Species<Integer> {
1627         interface FOp {
1628             int apply(int i);
1629         }
1630 
1631         abstract IntVector op(FOp f);
1632 
1633         abstract IntVector op(Mask<Integer> m, FOp f);
1634 
1635         interface FOpm {
1636             boolean apply(int i);
1637         }
1638 
1639         abstract Mask<Integer> opm(FOpm f);
1640 
1641         abstract IntVector.IntSpecies indexSpecies();

1642 
1643         // Factories
1644 
1645         @Override
1646         public abstract IntVector zero();
1647 
1648         /**
1649          * Returns a vector where all lane elements are set to the primitive
1650          * value {@code e}.
1651          *
1652          * @param e the value
1653          * @return a vector of vector where all lane elements are set to
1654          * the primitive value {@code e}
1655          */
1656         public abstract IntVector broadcast(int e);
1657 
1658         /**
1659          * Returns a vector where the first lane element is set to the primtive
1660          * value {@code e}, all other lane elements are set to the default
1661          * value.


< prev index next >