< prev index next >

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

Print this page
*** 22,10 ***
--- 22,12 ---
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  package jdk.incubator.vector;
  
+ import java.util.Objects;
+ 
  import jdk.internal.vm.annotation.ForceInline;
  
  import static jdk.incubator.vector.VectorOperators.*;
  
  abstract class AbstractMask<E> extends VectorMask<E> {

*** 61,27 ***
          return vspecies();
      }
  
      @Override
      public boolean laneIsSet(int i) {
!         return getBits()[i];
!     }
! 
!     @Override
!     public long toLong() {
!         // FIXME: This should be an intrinsic.
-         if (length() > Long.SIZE) {
-             throw new UnsupportedOperationException("too many lanes for one long");
-         }
-         long res = 0;
-         long set = 1;
-         boolean[] bits = getBits();
-         for (int i = 0; i < bits.length; i++) {
-             res = bits[i] ? res | set : res;
-             set = set << 1;
          }
-         return res;
      }
  
      @Override
      public void intoArray(boolean[] bits, int i) {
          System.arraycopy(getBits(), 0, bits, i, length());
--- 63,17 ---
          return vspecies();
      }
  
      @Override
      public boolean laneIsSet(int i) {
!         int length = length();
!         Objects.checkIndex(i, length);
!         if (length <= Long.SIZE) {
!             return ((toLong() >>> i) & 1L) == 1;
!         } else {
!             return getBits()[i];
          }
      }
  
      @Override
      public void intoArray(boolean[] bits, int i) {
          System.arraycopy(getBits(), 0, bits, i, length());

*** 112,10 ***
--- 104,27 ---
              throw AbstractSpecies.checkFailed(this, species);
          }
          return (VectorMask<F>) this;
      }
  
+     @Override
+     @ForceInline
+     @SuppressWarnings("unchecked")
+     <F> VectorMask<F> check(Class<? extends VectorMask<F>> maskClass, Vector<F> vector) {
+         if (!sameSpecies(maskClass, vector)) {
+             throw AbstractSpecies.checkFailed(this, vector);
+         }
+         return (VectorMask<F>) this;
+     }
+ 
+     @ForceInline
+     private <F> boolean sameSpecies(Class<? extends VectorMask<F>> maskClass, Vector<F> vector) {
+         boolean same = getClass() == maskClass;
+         assert (same == (vectorSpecies() == vector.species())) : same;
+         return same;
+     }
+ 
      @Override
      public VectorMask<E> andNot(VectorMask<E> m) {
          return and(m.not());
      }
  

*** 160,10 ***
--- 169,21 ---
              if (bits[i])  return i;
          }
          return -1;
      }
  
+     /*package-private*/
+     static long toLongHelper(boolean[] bits) {
+         long res = 0;
+         long set = 1;
+         for (int i = 0; i < bits.length; i++) {
+             res = bits[i] ? res | set : res;
+             set = set << 1;
+         }
+         return res;
+     }
+ 
      @Override
      @ForceInline
      public VectorMask<E> indexInRange(int offset, int limit) {
          int vlength = length();
          Vector<E> iota = vectorSpecies().zero().addIndex(1);

*** 213,18 ***
              // Masked access to multi-byte lanes in byte array.
              // It could be aligned anywhere.
              int elemCount = Math.min(vlength, (alength - offset) / esize);
              badMask = checkIndex0(0, elemCount, iota, vlength);
          } else {
-             // This requires a split test.
              int clipOffset = Math.max(offset, -(vlength * esize));
!             int elemCount = Math.min(vlength, (alength - clipOffset) / esize);
!             badMask = checkIndex0(0, elemCount, iota, vlength);
!             clipOffset &= (esize - 1);  // power of two, so OK
-             VectorMask<E> badMask2 = checkIndex0(clipOffset / esize, vlength,
-                                                  iota, vlength);
-             badMask = badMask.or(badMask2);
          }
          badMask = badMask.and(this);
          if (badMask.anyTrue()) {
              int badLane = badMask.firstTrue();
              throw ((AbstractMask<E>)badMask)
--- 233,14 ---
              // Masked access to multi-byte lanes in byte array.
              // It could be aligned anywhere.
              int elemCount = Math.min(vlength, (alength - offset) / esize);
              badMask = checkIndex0(0, elemCount, iota, vlength);
          } else {
              int clipOffset = Math.max(offset, -(vlength * esize));
!             badMask = checkIndex0(clipOffset, alength,
!                                   iota.lanewise(VectorOperators.MUL, esize),
!                                   vlength * esize);
          }
          badMask = badMask.and(this);
          if (badMask.anyTrue()) {
              int badLane = badMask.firstTrue();
              throw ((AbstractMask<E>)badMask)
< prev index next >