< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/package-info.java

Print this page




  87  * static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_512;
  88  *
  89  * void vectorMultiply(float[] a, float[] b, float[] c) {
  90  *   int i = 0;
  91  *   // It is assumed array arguments are of the same size
  92  *   for (; i < (a.length & ~(SPECIES.length() - 1));
  93  *            i += SPECIES.length()) {
  94  *         FloatVector va = FloatVector.fromArray(SPECIES, a, i);
  95  *         FloatVector vb = FloatVector.fromArray(SPECIES, b, i);
  96  *         FloatVector vc = va.mul(vb)
  97  *         vc.intoArray(c, i);
  98  *   }
  99  *
 100  *   for (; i < a.length; i++) {
 101  *     c[i] = a[i] * b[i];
 102  *   }
 103  * }
 104  * }</pre>
 105  *
 106  * The scalar computation after the vector computation is required to process the tail of
 107  * elements, the length of which is smaller than the species length.


 108  *
 109  * The example above uses vectors hardcoded to a concrete shape (512-bit). Instead, we could use preferred
 110  * species as shown below, to make the code dynamically adapt to optimal shape for the platform on which it runs.
 111  *
 112  * <pre>{@code
 113  * static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_PREFERRED;
 114  * }</pre>
 115  *
 116  * <h2>Vector operations</h2>
 117  * We use the term <em>lanes</em> when defining operations on vectors. The number of lanes
 118  * in a vector is the number of scalar elements it holds. For example, a vector of
 119  * type {@code Float} and shape {@code VectorShape.S_256_BIT} has eight lanes.
 120  * Vector operations can be grouped into various categories and their behavior
 121  * generally specified as follows:
 122  * <ul>
 123  * <li>
 124  * A lane-wise unary operation operates on one input vector and produce a
 125  * result vector.
 126  * For each lane of the input vector the
 127  * lane element is operated on using the specified scalar unary operation and




  87  * static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_512;
  88  *
  89  * void vectorMultiply(float[] a, float[] b, float[] c) {
  90  *   int i = 0;
  91  *   // It is assumed array arguments are of the same size
  92  *   for (; i < (a.length & ~(SPECIES.length() - 1));
  93  *            i += SPECIES.length()) {
  94  *         FloatVector va = FloatVector.fromArray(SPECIES, a, i);
  95  *         FloatVector vb = FloatVector.fromArray(SPECIES, b, i);
  96  *         FloatVector vc = va.mul(vb)
  97  *         vc.intoArray(c, i);
  98  *   }
  99  *
 100  *   for (; i < a.length; i++) {
 101  *     c[i] = a[i] * b[i];
 102  *   }
 103  * }
 104  * }</pre>
 105  *
 106  * The scalar computation after the vector computation is required to process the tail of
 107  * elements, the length of which is smaller than the species length. {@code VectorSpecies} also defines a
 108  * {@link jdk.incubator.vector.VectorSpecies#loopBound(int) loopBound()} helper method which can be used in place of
 109  * {@code (a.length & ~(SPECIES.length() - 1))} in the above code to determine the terminating condition.
 110  *
 111  * The example above uses vectors hardcoded to a concrete shape (512-bit). Instead, we could use preferred
 112  * species as shown below, to make the code dynamically adapt to optimal shape for the platform on which it runs.
 113  *
 114  * <pre>{@code
 115  * static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_PREFERRED;
 116  * }</pre>
 117  *
 118  * <h2>Vector operations</h2>
 119  * We use the term <em>lanes</em> when defining operations on vectors. The number of lanes
 120  * in a vector is the number of scalar elements it holds. For example, a vector of
 121  * type {@code Float} and shape {@code VectorShape.S_256_BIT} has eight lanes.
 122  * Vector operations can be grouped into various categories and their behavior
 123  * generally specified as follows:
 124  * <ul>
 125  * <li>
 126  * A lane-wise unary operation operates on one input vector and produce a
 127  * result vector.
 128  * For each lane of the input vector the
 129  * lane element is operated on using the specified scalar unary operation and


< prev index next >