< prev index next >

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

Print this page

        

@@ -24,11 +24,11 @@
  */
 package jdk.incubator.vector;
 
 import java.util.Arrays;
 
-abstract class AbstractMask<E> extends Vector.Mask<E> {
+abstract class AbstractMask<E> extends Mask<E> {
 
     /*package-private*/
     abstract boolean[] getBits();
 
     // Unary operator

@@ -43,11 +43,11 @@
 
     interface MBinOp {
         boolean apply(int i, boolean a, boolean b);
     }
 
-    abstract AbstractMask<E> bOp(Vector.Mask<E> o, MBinOp f);
+    abstract AbstractMask<E> bOp(Mask<E> o, MBinOp f);
 
     @Override
     public String toString() {
         return Arrays.toString(getBits());
     }

@@ -87,16 +87,16 @@
         }
         return c;
     }
 
     @Override
-    public AbstractMask<E> and(Vector.Mask<E> o) {
+    public AbstractMask<E> and(Mask<E> o) {
         return bOp(o, (i, a, b) -> a && b);
     }
 
     @Override
-    public AbstractMask<E> or(Vector.Mask<E> o) {
+    public AbstractMask<E> or(Mask<E> o) {
         return bOp(o, (i, a, b) -> a || b);
     }
 
     @Override
     public AbstractMask<E> not() {

@@ -116,6 +116,146 @@
         for (boolean i : bits) {
             if (!i) return false;
         }
         return true;
     }
+
+    // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
+    @SuppressWarnings("unchecked")
+    static <E> Mask<E> trueMask(Species<E> species) {
+        Class<?> eType = species.elementType();
+
+        if (eType == byte.class) {
+            if (species.boxType() == ByteMaxVector.class)
+                return (Mask<E>) ByteMaxVector.ByteMaxMask.TRUE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Byte64Vector.Byte64Mask.TRUE_MASK;
+                case 128: return (Mask<E>) Byte128Vector.Byte128Mask.TRUE_MASK;
+                case 256: return (Mask<E>) Byte256Vector.Byte256Mask.TRUE_MASK;
+                case 512: return (Mask<E>) Byte512Vector.Byte512Mask.TRUE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == short.class) {
+            if (species.boxType() == ShortMaxVector.class)
+                return (Mask<E>) ShortMaxVector.ShortMaxMask.TRUE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Short64Vector.Short64Mask.TRUE_MASK;
+                case 128: return (Mask<E>) Short128Vector.Short128Mask.TRUE_MASK;
+                case 256: return (Mask<E>) Short256Vector.Short256Mask.TRUE_MASK;
+                case 512: return (Mask<E>) Short512Vector.Short512Mask.TRUE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == int.class) {
+            if (species.boxType() == IntMaxVector.class)
+                return (Mask<E>) IntMaxVector.IntMaxMask.TRUE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Int64Vector.Int64Mask.TRUE_MASK;
+                case 128: return (Mask<E>) Int128Vector.Int128Mask.TRUE_MASK;
+                case 256: return (Mask<E>) Int256Vector.Int256Mask.TRUE_MASK;
+                case 512: return (Mask<E>) Int512Vector.Int512Mask.TRUE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == long.class) {
+            if (species.boxType() == LongMaxVector.class)
+                return (Mask<E>) LongMaxVector.LongMaxMask.TRUE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Long64Vector.Long64Mask.TRUE_MASK;
+                case 128: return (Mask<E>) Long128Vector.Long128Mask.TRUE_MASK;
+                case 256: return (Mask<E>) Long256Vector.Long256Mask.TRUE_MASK;
+                case 512: return (Mask<E>) Long512Vector.Long512Mask.TRUE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == float.class) {
+            if (species.boxType() == FloatMaxVector.class)
+                return (Mask<E>) FloatMaxVector.FloatMaxMask.TRUE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Float64Vector.Float64Mask.TRUE_MASK;
+                case 128: return (Mask<E>) Float128Vector.Float128Mask.TRUE_MASK;
+                case 256: return (Mask<E>) Float256Vector.Float256Mask.TRUE_MASK;
+                case 512: return (Mask<E>) Float512Vector.Float512Mask.TRUE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == double.class) {
+            if (species.boxType() == DoubleMaxVector.class)
+                return (Mask<E>) DoubleMaxVector.DoubleMaxMask.TRUE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Double64Vector.Double64Mask.TRUE_MASK;
+                case 128: return (Mask<E>) Double128Vector.Double128Mask.TRUE_MASK;
+                case 256: return (Mask<E>) Double256Vector.Double256Mask.TRUE_MASK;
+                case 512: return (Mask<E>) Double512Vector.Double512Mask.TRUE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else {
+            throw new IllegalArgumentException("Bad element type of species");
+        }
+    }
+
+    // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
+    @SuppressWarnings("unchecked")
+    static <E> Mask<E> falseMask(Species<E> species) {
+        Class<?> eType = species.elementType();
+
+        if (eType == byte.class) {
+            if (species.boxType() == ByteMaxVector.class)
+                return (Mask<E>) ByteMaxVector.ByteMaxMask.FALSE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Byte64Vector.Byte64Mask.FALSE_MASK;
+                case 128: return (Mask<E>) Byte128Vector.Byte128Mask.FALSE_MASK;
+                case 256: return (Mask<E>) Byte256Vector.Byte256Mask.FALSE_MASK;
+                case 512: return (Mask<E>) Byte512Vector.Byte512Mask.FALSE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == short.class) {
+            if (species.boxType() == ShortMaxVector.class)
+                return (Mask<E>) ShortMaxVector.ShortMaxMask.FALSE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Short64Vector.Short64Mask.FALSE_MASK;
+                case 128: return (Mask<E>) Short128Vector.Short128Mask.FALSE_MASK;
+                case 256: return (Mask<E>) Short256Vector.Short256Mask.FALSE_MASK;
+                case 512: return (Mask<E>) Short512Vector.Short512Mask.FALSE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == int.class) {
+            if (species.boxType() == IntMaxVector.class)
+                return (Mask<E>) IntMaxVector.IntMaxMask.FALSE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Int64Vector.Int64Mask.FALSE_MASK;
+                case 128: return (Mask<E>) Int128Vector.Int128Mask.FALSE_MASK;
+                case 256: return (Mask<E>) Int256Vector.Int256Mask.FALSE_MASK;
+                case 512: return (Mask<E>) Int512Vector.Int512Mask.FALSE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == long.class) {
+            if (species.boxType() == LongMaxVector.class)
+                return (Mask<E>) LongMaxVector.LongMaxMask.FALSE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Long64Vector.Long64Mask.FALSE_MASK;
+                case 128: return (Mask<E>) Long128Vector.Long128Mask.FALSE_MASK;
+                case 256: return (Mask<E>) Long256Vector.Long256Mask.FALSE_MASK;
+                case 512: return (Mask<E>) Long512Vector.Long512Mask.FALSE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == float.class) {
+            if (species.boxType() == FloatMaxVector.class)
+                return (Mask<E>) FloatMaxVector.FloatMaxMask.FALSE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Float64Vector.Float64Mask.FALSE_MASK;
+                case 128: return (Mask<E>) Float128Vector.Float128Mask.FALSE_MASK;
+                case 256: return (Mask<E>) Float256Vector.Float256Mask.FALSE_MASK;
+                case 512: return (Mask<E>) Float512Vector.Float512Mask.FALSE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else if (eType == double.class) {
+            if (species.boxType() == DoubleMaxVector.class)
+                return (Mask<E>) DoubleMaxVector.DoubleMaxMask.FALSE_MASK;
+            switch (species.bitSize()) {
+                case 64: return (Mask<E>) Double64Vector.Double64Mask.FALSE_MASK;
+                case 128: return (Mask<E>) Double128Vector.Double128Mask.FALSE_MASK;
+                case 256: return (Mask<E>) Double256Vector.Double256Mask.FALSE_MASK;
+                case 512: return (Mask<E>) Double512Vector.Double512Mask.FALSE_MASK;
+                default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
+            }
+        } else {
+            throw new IllegalArgumentException("Bad element type of species");
+        }
+    }
 }
< prev index next >