< prev index next >

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

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -22,10 +22,12 @@
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  package jdk.incubator.vector;
  
+ import jdk.incubator.foreign.MemorySegment;
+ 
  import java.nio.ByteOrder;
  import java.util.function.IntUnaryOperator;
  
  /**
   * Interface for managing all vectors of the same combination

@@ -147,15 +149,41 @@
       *
       * @param length the input length
       * @return the largest multiple of the vector length not greater
       *         than the given length
       * @throws IllegalArgumentException if the {@code length} is
-                negative and the result would overflow to a positive value
+      *         negative and the result would overflow to a positive value
       * @see Math#floorMod(int, int)
       */
      int loopBound(int length);
  
+     /**
+      * Loop control function which returns the largest multiple of
+      * {@code VLENGTH} that is less than or equal to the given
+      * {@code length} value.
+      * Here, {@code VLENGTH} is the result of {@code this.length()},
+      * and {@code length} is interpreted as a number of lanes.
+      * The resulting value {@code R} satisfies this inequality:
+      * <pre>{@code R <= length < R+VLENGTH}
+      * </pre>
+      * <p> Specifically, this method computes
+      * {@code length - floorMod(length, VLENGTH)}, where
+      * {@link Math#floorMod(long,int) floorMod} computes a remainder
+      * value by rounding its quotient toward negative infinity.
+      * As long as {@code VLENGTH} is a power of two, then the result
+      * is also equal to {@code length & ~(VLENGTH - 1)}.
+      *
+      * @param length the input length
+      * @return the largest multiple of the vector length not greater
+      *         than the given length
+      * @throws IllegalArgumentException if the {@code length} is
+      *         negative and the result would overflow to a positive value
+      * @see Math#floorMod(long, int)
+      * @since 19
+      */
+     long loopBound(long length);
+ 
      /**
       * Returns a mask of this species where only
       * the lanes at index N such that the adjusted index
       * {@code N+offset} is in the range {@code [0..limit-1]}
       * are set.

@@ -169,10 +197,28 @@
       * @return a mask with out-of-range lanes unset
       * @see VectorMask#indexInRange(int, int)
       */
      VectorMask<E> indexInRange(int offset, int limit);
  
+     /**
+      * Returns a mask of this species where only
+      * the lanes at index N such that the adjusted index
+      * {@code N+offset} is in the range {@code [0..limit-1]}
+      * are set.
+      *
+      * <p>
+      * This method returns the value of the expression
+      * {@code maskAll(true).indexInRange(offset, limit)}
+      *
+      * @param offset the starting index
+      * @param limit the upper-bound (exclusive) of index range
+      * @return a mask with out-of-range lanes unset
+      * @see VectorMask#indexInRange(long, long)
+      * @since 19
+      */
+     VectorMask<E> indexInRange(long offset, long limit);
+ 
      /**
       * Checks that this species has the given element type,
       * and returns this species unchanged.
       * The effect is similar to this pseudocode:
       * {@code elementType == elementType()

@@ -431,35 +477,35 @@
       */
      Vector<E> fromArray(Object a, int offset);
      // Defined when ETYPE is known.
  
      /**
-      * Loads a vector of this species from a byte array starting
-      * at an offset.
+      * Loads a vector of this species from a {@linkplain MemorySegment memory segment}
+      * starting at an offset into the memory segment.
       * Bytes are composed into primitive lane elements according
       * to the specified byte order.
       * The vector is arranged into lanes according to
       * <a href="Vector.html#lane-order">memory ordering</a>.
       * <p>
       * Equivalent to
-      * {@code IntVector.fromByteArray(this,a,offset,bo)}
-      * or an equivalent {@code fromByteArray} method,
+      * {@code IntVector.fromMemorySegment(this,ms,offset,bo)},
       * on the vector type corresponding to
       * this species.
       *
-      * @param a a byte array
-      * @param offset the index of the first byte to load
+      * @param ms the memory segment
+      * @param offset the offset into the memory segment
       * @param bo the intended byte order
-      * @return a vector of the given species filled from the byte array
+      * @return a vector of the given species filled from the memory segment
       * @throws IndexOutOfBoundsException
       *         if {@code offset+N*ESIZE < 0}
       *         or {@code offset+(N+1)*ESIZE > a.length}
       *         for any lane {@code N} in the vector
-      * @see IntVector#fromByteArray(VectorSpecies,byte[],int,ByteOrder)
-      * @see FloatVector#fromByteArray(VectorSpecies,byte[],int,ByteOrder)
+      * @see IntVector#fromMemorySegment(VectorSpecies, jdk.incubator.foreign.MemorySegment, long, java.nio.ByteOrder)
+      * @see FloatVector#fromMemorySegment(VectorSpecies, jdk.incubator.foreign.MemorySegment, long, java.nio.ByteOrder)
+      * @since 19
       */
-     Vector<E> fromByteArray(byte[] a, int offset, ByteOrder bo);
+     Vector<E> fromMemorySegment(MemorySegment ms, long offset, ByteOrder bo);
  
      /**
       * Returns a mask of this species
       * where lane elements are initialized
       * from the given array at the given offset.
< prev index next >