< prev index next >

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

Print this page




  27 import jdk.internal.misc.Unsafe;
  28 import jdk.internal.vm.annotation.ForceInline;
  29 import java.util.function.Function;
  30 import java.util.function.IntUnaryOperator;
  31 
  32 /**
  33  * Interface supporting vectors of same element type, {@code E} and {@link VectorShape shape}.
  34  *
  35  * @param <E> the boxed element type of this species
  36  */
  37 public interface VectorSpecies<E> {
  38     /**
  39      * Returns the primitive element type of vectors produced by this
  40      * species.
  41      *
  42      * @return the primitive element type
  43      */
  44     public abstract Class<E> elementType();
  45 
  46     /**
  47      * Returns the vector box type for this species
  48      *
  49      * @return the box type
  50      */
  51     abstract Class<?> boxType();
  52 
  53     /**
  54      * Returns the vector mask type for this species
  55      *
  56      * @return the box type
  57      */
  58     abstract Class<?> maskType();
  59 
  60     /**
  61      * Returns the element size, in bits, of vectors produced by this
  62      * species.
  63      *
  64      * @return the element size, in bits
  65      */
  66     public abstract int elementSize();
  67 
  68     /**
  69      * Returns the shape of masks, shuffles, and vectors produced by this
  70      * species.
  71      *


  77      * Returns the shape of the corresponding index species
  78      * @return the shape
  79      */
  80     @ForceInline
  81     public abstract VectorShape indexShape();
  82 
  83     /**
  84      * Returns the mask, shuffe, or vector lanes produced by this species.
  85      *
  86      * @return the the number of lanes
  87      */
  88     default public int length() { return shape().length(this); }
  89 
  90     /**
  91      * Returns the total vector size, in bits, of vectors produced by this
  92      * species.
  93      *
  94      * @return the total vector size, in bits
  95      */
  96     default public int bitSize() { return shape().bitSize(); }










  97 
  98     // Factory
  99 
 100     /**
 101      * Finds a species for an element type and shape.
 102      *
 103      * @param c the element type
 104      * @param s the shape
 105      * @param <E> the boxed element type
 106      * @return a species for an element type and shape
 107      * @throws IllegalArgumentException if no such species exists for the
 108      * element type and/or shape
 109      */
 110     @SuppressWarnings("unchecked")
 111     public static <E> VectorSpecies<E> of(Class<E> c, VectorShape s) {
 112         if (c == float.class) {
 113             return (VectorSpecies<E>) FloatVector.species(s);
 114         }
 115         else if (c == double.class) {
 116             return (VectorSpecies<E>) DoubleVector.species(s);




  27 import jdk.internal.misc.Unsafe;
  28 import jdk.internal.vm.annotation.ForceInline;
  29 import java.util.function.Function;
  30 import java.util.function.IntUnaryOperator;
  31 
  32 /**
  33  * Interface supporting vectors of same element type, {@code E} and {@link VectorShape shape}.
  34  *
  35  * @param <E> the boxed element type of this species
  36  */
  37 public interface VectorSpecies<E> {
  38     /**
  39      * Returns the primitive element type of vectors produced by this
  40      * species.
  41      *
  42      * @return the primitive element type
  43      */
  44     public abstract Class<E> elementType();
  45 
  46     /**
  47      * Returns the vector type corresponding to this species
  48      *
  49      * @return the vector type corresponding to this species
  50      */
  51     abstract Class<?> vectorType();
  52 
  53     /**
  54      * Returns the vector mask type for this species
  55      *
  56      * @return the box type
  57      */
  58     abstract Class<?> maskType();
  59 
  60     /**
  61      * Returns the element size, in bits, of vectors produced by this
  62      * species.
  63      *
  64      * @return the element size, in bits
  65      */
  66     public abstract int elementSize();
  67 
  68     /**
  69      * Returns the shape of masks, shuffles, and vectors produced by this
  70      * species.
  71      *


  77      * Returns the shape of the corresponding index species
  78      * @return the shape
  79      */
  80     @ForceInline
  81     public abstract VectorShape indexShape();
  82 
  83     /**
  84      * Returns the mask, shuffe, or vector lanes produced by this species.
  85      *
  86      * @return the the number of lanes
  87      */
  88     default public int length() { return shape().length(this); }
  89 
  90     /**
  91      * Returns the total vector size, in bits, of vectors produced by this
  92      * species.
  93      *
  94      * @return the total vector size, in bits
  95      */
  96     default public int bitSize() { return shape().bitSize(); }
  97 
  98     /**
  99      * Helper function to calculate the loop terminating condition when iterating over an array of given length.
 100      * Returns the result of {@code (length & ~(this.length() - 1))}
 101      *
 102      * @return the result of {@code (length & ~(this.length() - 1))}
 103      */
 104     default public int loopBound(int length) {
 105         return length & ~(this.length() - 1);
 106     }
 107 
 108     // Factory
 109 
 110     /**
 111      * Finds a species for an element type and shape.
 112      *
 113      * @param c the element type
 114      * @param s the shape
 115      * @param <E> the boxed element type
 116      * @return a species for an element type and shape
 117      * @throws IllegalArgumentException if no such species exists for the
 118      * element type and/or shape
 119      */
 120     @SuppressWarnings("unchecked")
 121     public static <E> VectorSpecies<E> of(Class<E> c, VectorShape s) {
 122         if (c == float.class) {
 123             return (VectorSpecies<E>) FloatVector.species(s);
 124         }
 125         else if (c == double.class) {
 126             return (VectorSpecies<E>) DoubleVector.species(s);


< prev index next >