< prev index next >

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

Print this page
rev 55589 : Species-phase2
rev 55591 : XxxSpecies made package private
rev 55592 : Capitalized Species names

@@ -36,11 +36,11 @@
 import jdk.internal.vm.annotation.ForceInline;
 import static jdk.incubator.vector.VectorIntrinsics.*;
 
 @SuppressWarnings("cast")
 final class ShortMaxVector extends ShortVector {
-    static final ShortMaxSpecies SPECIES = new ShortMaxSpecies();
+    private static final Species<Short> SPECIES = ShortVector.SPECIES_MAX;
 
     static final ShortMaxVector ZERO = new ShortMaxVector();
 
     static final int LENGTH = SPECIES.length();
 

@@ -153,11 +153,11 @@
             throw new IllegalArgumentException("Vector length this species length differ");
 
         return VectorIntrinsics.cast(
             ShortMaxVector.class,
             short.class, LENGTH,
-            s.vectorType(),
+            s.boxType(),
             s.elementType(), LENGTH,
             this, s,
             (species, vector) -> vector.castDefault(species)
         );
     }

@@ -171,41 +171,41 @@
         if (stype == byte.class) {
             byte[] a = new byte[limit];
             for (int i = 0; i < limit; i++) {
                 a[i] = (byte) this.get(i);
             }
-            return (Vector) ByteVector.fromArray((ByteVector.ByteSpecies) s, a, 0);
+            return (Vector) ByteVector.fromArray((Species<Byte>) s, a, 0);
         } else if (stype == short.class) {
             short[] a = new short[limit];
             for (int i = 0; i < limit; i++) {
                 a[i] = (short) this.get(i);
             }
-            return (Vector) ShortVector.fromArray((ShortVector.ShortSpecies) s, a, 0);
+            return (Vector) ShortVector.fromArray((Species<Short>) s, a, 0);
         } else if (stype == int.class) {
             int[] a = new int[limit];
             for (int i = 0; i < limit; i++) {
                 a[i] = (int) this.get(i);
             }
-            return (Vector) IntVector.fromArray((IntVector.IntSpecies) s, a, 0);
+            return (Vector) IntVector.fromArray((Species<Integer>) s, a, 0);
         } else if (stype == long.class) {
             long[] a = new long[limit];
             for (int i = 0; i < limit; i++) {
                 a[i] = (long) this.get(i);
             }
-            return (Vector) LongVector.fromArray((LongVector.LongSpecies) s, a, 0);
+            return (Vector) LongVector.fromArray((Species<Long>) s, a, 0);
         } else if (stype == float.class) {
             float[] a = new float[limit];
             for (int i = 0; i < limit; i++) {
                 a[i] = (float) this.get(i);
             }
-            return (Vector) FloatVector.fromArray((FloatVector.FloatSpecies) s, a, 0);
+            return (Vector) FloatVector.fromArray((Species<Float>) s, a, 0);
         } else if (stype == double.class) {
             double[] a = new double[limit];
             for (int i = 0; i < limit; i++) {
                 a[i] = (double) this.get(i);
             }
-            return (Vector) DoubleVector.fromArray((DoubleVector.DoubleSpecies) s, a, 0);
+            return (Vector) DoubleVector.fromArray((Species<Double>) s, a, 0);
         } else {
             throw new UnsupportedOperationException("Bad lane type for casting.");
         }
     }
 

@@ -291,59 +291,54 @@
 
     @Override
     @ForceInline
     public ShortVector reshape(Species<Short> s) {
         Objects.requireNonNull(s);
-        if (s.bitSize() == 64 && (s instanceof Short64Vector.Short64Species)) {
-            Short64Vector.Short64Species ts = (Short64Vector.Short64Species)s;
+        if (s.bitSize() == 64 && (s.boxType() == Short64Vector.class)) {
             return VectorIntrinsics.reinterpret(
                 ShortMaxVector.class,
                 short.class, LENGTH,
                 Short64Vector.class,
                 short.class, Short64Vector.LENGTH,
-                this, ts,
+                this, s,
                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
             );
-        } else if (s.bitSize() == 128 && (s instanceof Short128Vector.Short128Species)) {
-            Short128Vector.Short128Species ts = (Short128Vector.Short128Species)s;
+        } else if (s.bitSize() == 128 && (s.boxType() == Short128Vector.class)) {
             return VectorIntrinsics.reinterpret(
                 ShortMaxVector.class,
                 short.class, LENGTH,
                 Short128Vector.class,
                 short.class, Short128Vector.LENGTH,
-                this, ts,
+                this, s,
                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
             );
-        } else if (s.bitSize() == 256 && (s instanceof Short256Vector.Short256Species)) {
-            Short256Vector.Short256Species ts = (Short256Vector.Short256Species)s;
+        } else if (s.bitSize() == 256 && (s.boxType() == Short256Vector.class)) {
             return VectorIntrinsics.reinterpret(
                 ShortMaxVector.class,
                 short.class, LENGTH,
                 Short256Vector.class,
                 short.class, Short256Vector.LENGTH,
-                this, ts,
+                this, s,
                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
             );
-        } else if (s.bitSize() == 512 && (s instanceof Short512Vector.Short512Species)) {
-            Short512Vector.Short512Species ts = (Short512Vector.Short512Species)s;
+        } else if (s.bitSize() == 512 && (s.boxType() == Short512Vector.class)) {
             return VectorIntrinsics.reinterpret(
                 ShortMaxVector.class,
                 short.class, LENGTH,
                 Short512Vector.class,
                 short.class, Short512Vector.LENGTH,
-                this, ts,
+                this, s,
                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
             );
         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
-                && (s.bitSize() % 128 == 0) && (s instanceof ShortMaxVector.ShortMaxSpecies)) {
-            ShortMaxVector.ShortMaxSpecies ts = (ShortMaxVector.ShortMaxSpecies)s;
+                && (s.bitSize() % 128 == 0) && (s.boxType() == ShortMaxVector.class)) {
             return VectorIntrinsics.reinterpret(
                 ShortMaxVector.class,
                 short.class, LENGTH,
                 ShortMaxVector.class,
                 short.class, ShortMaxVector.LENGTH,
-                this, ts,
+                this, s,
                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
             );
         } else {
             throw new InternalError("Unimplemented size");
         }

@@ -352,132 +347,132 @@
     // Binary operations with scalars
 
     @Override
     @ForceInline
     public ShortVector add(short o) {
-        return add(SPECIES.broadcast(o));
+        return add((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public ShortVector add(short o, Mask<Short> m) {
-        return add(SPECIES.broadcast(o), m);
+        return add((ShortMaxVector)ShortVector.broadcast(SPECIES, o), m);
     }
 
     @Override
     @ForceInline
     public ShortVector sub(short o) {
-        return sub(SPECIES.broadcast(o));
+        return sub((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public ShortVector sub(short o, Mask<Short> m) {
-        return sub(SPECIES.broadcast(o), m);
+        return sub((ShortMaxVector)ShortVector.broadcast(SPECIES, o), m);
     }
 
     @Override
     @ForceInline
     public ShortVector mul(short o) {
-        return mul(SPECIES.broadcast(o));
+        return mul((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public ShortVector mul(short o, Mask<Short> m) {
-        return mul(SPECIES.broadcast(o), m);
+        return mul((ShortMaxVector)ShortVector.broadcast(SPECIES, o), m);
     }
 
     @Override
     @ForceInline
     public ShortVector min(short o) {
-        return min(SPECIES.broadcast(o));
+        return min((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public ShortVector max(short o) {
-        return max(SPECIES.broadcast(o));
+        return max((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public Mask<Short> equal(short o) {
-        return equal(SPECIES.broadcast(o));
+        return equal((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public Mask<Short> notEqual(short o) {
-        return notEqual(SPECIES.broadcast(o));
+        return notEqual((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public Mask<Short> lessThan(short o) {
-        return lessThan(SPECIES.broadcast(o));
+        return lessThan((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public Mask<Short> lessThanEq(short o) {
-        return lessThanEq(SPECIES.broadcast(o));
+        return lessThanEq((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public Mask<Short> greaterThan(short o) {
-        return greaterThan(SPECIES.broadcast(o));
+        return greaterThan((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public Mask<Short> greaterThanEq(short o) {
-        return greaterThanEq(SPECIES.broadcast(o));
+        return greaterThanEq((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public ShortVector blend(short o, Mask<Short> m) {
-        return blend(SPECIES.broadcast(o), m);
+        return blend((ShortMaxVector)ShortVector.broadcast(SPECIES, o), m);
     }
 
 
     @Override
     @ForceInline
     public ShortVector and(short o) {
-        return and(SPECIES.broadcast(o));
+        return and((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public ShortVector and(short o, Mask<Short> m) {
-        return and(SPECIES.broadcast(o), m);
+        return and((ShortMaxVector)ShortVector.broadcast(SPECIES, o), m);
     }
 
     @Override
     @ForceInline
     public ShortVector or(short o) {
-        return or(SPECIES.broadcast(o));
+        return or((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public ShortVector or(short o, Mask<Short> m) {
-        return or(SPECIES.broadcast(o), m);
+        return or((ShortMaxVector)ShortVector.broadcast(SPECIES, o), m);
     }
 
     @Override
     @ForceInline
     public ShortVector xor(short o) {
-        return xor(SPECIES.broadcast(o));
+        return xor((ShortMaxVector)ShortVector.broadcast(SPECIES, o));
     }
 
     @Override
     @ForceInline
     public ShortVector xor(short o, Mask<Short> m) {
-        return xor(SPECIES.broadcast(o), m);
+        return xor((ShortMaxVector)ShortVector.broadcast(SPECIES, o), m);
     }
 
     @Override
     @ForceInline
     public ShortMaxVector neg() {

@@ -728,11 +723,11 @@
     }
 
     @Override
     @ForceInline
     public short andAll(Mask<Short> m) {
-        return SPECIES.broadcast((short) -1).blend(this, m).andAll();
+        return blend((ShortMaxVector)ShortVector.broadcast(SPECIES, (short) -1), m).andAll();
     }
 
     @Override
     @ForceInline
     public short minAll() {

@@ -770,11 +765,11 @@
     }
 
     @Override
     @ForceInline
     public short orAll(Mask<Short> m) {
-        return SPECIES.broadcast((short) 0).blend(this, m).orAll();
+        return blend((ShortMaxVector)ShortVector.broadcast(SPECIES, (short) 0), m).orAll();
     }
 
     @Override
     @ForceInline
     public short xorAll() {

@@ -785,37 +780,37 @@
     }
 
     @Override
     @ForceInline
     public short xorAll(Mask<Short> m) {
-        return SPECIES.broadcast((short) 0).blend(this, m).xorAll();
+        return blend((ShortMaxVector)ShortVector.broadcast(SPECIES, (short) 0), m).xorAll();
     }
 
 
     @Override
     @ForceInline
     public short addAll(Mask<Short> m) {
-        return SPECIES.broadcast((short) 0).blend(this, m).addAll();
+        return blend((ShortMaxVector)ShortVector.broadcast(SPECIES, (short) 0), m).addAll();
     }
 
 
     @Override
     @ForceInline
     public short mulAll(Mask<Short> m) {
-        return SPECIES.broadcast((short) 1).blend(this, m).mulAll();
+        return blend((ShortMaxVector)ShortVector.broadcast(SPECIES, (short) 1), m).mulAll();
     }
 
     @Override
     @ForceInline
     public short minAll(Mask<Short> m) {
-        return SPECIES.broadcast(Short.MAX_VALUE).blend(this, m).minAll();
+        return blend((ShortMaxVector)ShortVector.broadcast(SPECIES, Short.MAX_VALUE), m).minAll();
     }
 
     @Override
     @ForceInline
     public short maxAll(Mask<Short> m) {
-        return SPECIES.broadcast(Short.MIN_VALUE).blend(this, m).maxAll();
+        return blend((ShortMaxVector)ShortVector.broadcast(SPECIES, Short.MIN_VALUE), m).maxAll();
     }
 
     @Override
     @ForceInline
     public Shuffle<Short> toShuffle() {

@@ -1195,11 +1190,11 @@
             }
             return new ShortMaxMask(res);
         }
 
         @Override
-        public ShortMaxSpecies species() {
+        public Species<Short> species() {
             return SPECIES;
         }
 
         @Override
         public ShortMaxVector toVector() {

@@ -1211,10 +1206,35 @@
                 res[i] = (short) (bits[i] ? -1 : 0);
             }
             return new ShortMaxVector(res);
         }
 
+        @Override
+        @ForceInline
+        @SuppressWarnings("unchecked")
+        public <E> Mask<E> cast(Species<E> species) {
+            if (length() != species.length())
+                throw new IllegalArgumentException("Mask length and species length differ");
+            Class<?> stype = species.elementType();
+            boolean [] maskArray = toArray();
+            if (stype == byte.class) {
+                return (Mask <E>) new ByteMaxVector.ByteMaxMask(maskArray);
+            } else if (stype == short.class) {
+                return (Mask <E>) new ShortMaxVector.ShortMaxMask(maskArray);
+            } else if (stype == int.class) {
+                return (Mask <E>) new IntMaxVector.IntMaxMask(maskArray);
+            } else if (stype == long.class) {
+                return (Mask <E>) new LongMaxVector.LongMaxMask(maskArray);
+            } else if (stype == float.class) {
+                return (Mask <E>) new FloatMaxVector.FloatMaxMask(maskArray);
+            } else if (stype == double.class) {
+                return (Mask <E>) new DoubleMaxVector.DoubleMaxMask(maskArray);
+            } else {
+                throw new UnsupportedOperationException("Bad lane type for casting.");
+            }
+        }
+
         // Unary operations
 
         @Override
         @ForceInline
         public ShortMaxMask not() {

@@ -1283,11 +1303,11 @@
         public ShortMaxShuffle(IntUnaryOperator f) {
             super(f);
         }
 
         @Override
-        public ShortMaxSpecies species() {
+        public Species<Short> species() {
             return SPECIES;
         }
 
         @Override
         public ShortVector toVector() {

@@ -1297,10 +1317,35 @@
             }
             return ShortVector.fromArray(SPECIES, va, 0);
         }
 
         @Override
+        @ForceInline
+        @SuppressWarnings("unchecked")
+        public <F> Shuffle<F> cast(Species<F> species) {
+            if (length() != species.length())
+                throw new IllegalArgumentException("Shuffle length and species length differ");
+            Class<?> stype = species.elementType();
+            int [] shuffleArray = toArray();
+            if (stype == byte.class) {
+                return (Shuffle<F>) new ByteMaxVector.ByteMaxShuffle(shuffleArray);
+            } else if (stype == short.class) {
+                return (Shuffle<F>) new ShortMaxVector.ShortMaxShuffle(shuffleArray);
+            } else if (stype == int.class) {
+                return (Shuffle<F>) new IntMaxVector.IntMaxShuffle(shuffleArray);
+            } else if (stype == long.class) {
+                return (Shuffle<F>) new LongMaxVector.LongMaxShuffle(shuffleArray);
+            } else if (stype == float.class) {
+                return (Shuffle<F>) new FloatMaxVector.FloatMaxShuffle(shuffleArray);
+            } else if (stype == double.class) {
+                return (Shuffle<F>) new DoubleMaxVector.DoubleMaxShuffle(shuffleArray);
+            } else {
+                throw new UnsupportedOperationException("Bad lane type for casting.");
+            }
+        }
+
+        @Override
         public ShortMaxShuffle rearrange(Vector.Shuffle<Short> o) {
             ShortMaxShuffle s = (ShortMaxShuffle) o;
             byte[] r = new byte[reorder.length];
             for (int i = 0; i < reorder.length; i++) {
                 r[i] = reorder[s.reorder[i]];

@@ -1310,150 +1355,9 @@
     }
 
     // Species
 
     @Override
-    public ShortMaxSpecies species() {
+    public Species<Short> species() {
         return SPECIES;
     }
-
-    static final class ShortMaxSpecies extends ShortSpecies {
-        static final int BIT_SIZE = Shape.S_Max_BIT.bitSize();
-
-        static final int LENGTH = BIT_SIZE / Short.SIZE;
-
-        @Override
-        public String toString() {
-           StringBuilder sb = new StringBuilder("Shape[");
-           sb.append(bitSize()).append(" bits, ");
-           sb.append(length()).append(" ").append(short.class.getSimpleName()).append("s x ");
-           sb.append(elementSize()).append(" bits");
-           sb.append("]");
-           return sb.toString();
-        }
-
-        @Override
-        @ForceInline
-        public int bitSize() {
-            return BIT_SIZE;
-        }
-
-        @Override
-        @ForceInline
-        public int length() {
-            return LENGTH;
-        }
-
-        @Override
-        @ForceInline
-        public Class<Short> elementType() {
-            return short.class;
-        }
-
-        @Override
-        @ForceInline
-        public Class<?> boxType() {
-            return ShortMaxVector.class;
-        }
-
-        @Override
-        @ForceInline
-        public Class<?> maskType() {
-            return ShortMaxMask.class;
-        }
-
-        @Override
-        @ForceInline
-        public int elementSize() {
-            return Short.SIZE;
-        }
-
-        @Override
-        @ForceInline
-        @SuppressWarnings("unchecked")
-        Class<?> vectorType() {
-            return ShortMaxVector.class;
-        }
-
-        @Override
-        @ForceInline
-        public Shape shape() {
-            return Shape.S_Max_BIT;
-        }
-
-        @Override
-        ShortMaxVector op(FOp f) {
-            short[] res = new short[length()];
-            for (int i = 0; i < length(); i++) {
-                res[i] = f.apply(i);
-            }
-            return new ShortMaxVector(res);
-        }
-
-        @Override
-        ShortMaxVector op(Mask<Short> o, FOp f) {
-            short[] res = new short[length()];
-            boolean[] mbits = ((ShortMaxMask)o).getBits();
-            for (int i = 0; i < length(); i++) {
-                if (mbits[i]) {
-                    res[i] = f.apply(i);
-                }
-            }
-            return new ShortMaxVector(res);
-        }
-
-        @Override
-        ShortMaxMask opm(FOpm f) {
-            boolean[] res = new boolean[length()];
-            for (int i = 0; i < length(); i++) {
-                res[i] = (boolean)f.apply(i);
-            }
-            return new ShortMaxMask(res);
-        }
-
-        // Factories
-
-        @Override
-        @ForceInline
-        public ShortMaxVector zero() {
-            return VectorIntrinsics.broadcastCoerced(ShortMaxVector.class, short.class, LENGTH,
-                                                     0, SPECIES,
-                                                     ((bits, s) -> ((ShortMaxSpecies)s).op(i -> (short)bits)));
-        }
-
-        @Override
-        @ForceInline
-        public ShortMaxVector broadcast(short e) {
-            return VectorIntrinsics.broadcastCoerced(
-                ShortMaxVector.class, short.class, LENGTH,
-                e, SPECIES,
-                ((bits, s) -> ((ShortMaxSpecies)s).op(i -> (short)bits)));
-        }
-
-        @Override
-        @ForceInline
-        public ShortMaxVector scalars(short... es) {
-            Objects.requireNonNull(es);
-            int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
-            return VectorIntrinsics.load(ShortMaxVector.class, short.class, LENGTH,
-                                         es, Unsafe.ARRAY_SHORT_BASE_OFFSET,
-                                         es, ix, SPECIES,
-                                         (c, idx, s) -> ((ShortMaxSpecies)s).op(n -> c[idx + n]));
-        }
-
-        @Override
-        @ForceInline
-        public <E> ShortMaxMask cast(Mask<E> m) {
-            if (m.length() != LENGTH)
-                throw new IllegalArgumentException("Mask length this species length differ");
-            return new ShortMaxMask(m.toArray());
-        }
-
-        @Override
-        @ForceInline
-        public <E> ShortMaxShuffle cast(Shuffle<E> s) {
-            if (s.length() != LENGTH)
-                throw new IllegalArgumentException("Shuffle length this species length differ");
-            return new ShortMaxShuffle(s.toArray());
-        }
-    }
 }
< prev index next >