--- old/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short256Vector.java 2019-04-09 12:07:58.178701200 -0700 +++ new/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short256Vector.java 2019-04-09 12:07:57.453353700 -0700 @@ -38,7 +38,7 @@ @SuppressWarnings("cast") final class Short256Vector extends ShortVector { - static final Short256Species SPECIES = new Short256Species(); + private static final Species SPECIES = ShortVector.SPECIES_256; static final Short256Vector ZERO = new Short256Vector(); @@ -155,7 +155,7 @@ return VectorIntrinsics.cast( Short256Vector.class, short.class, LENGTH, - s.vectorType(), + s.boxType(), s.elementType(), LENGTH, this, s, (species, vector) -> vector.castDefault(species) @@ -173,37 +173,37 @@ 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) 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) 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) 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) 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) 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) s, a, 0); } else { throw new UnsupportedOperationException("Bad lane type for casting."); } @@ -293,55 +293,50 @@ @ForceInline public ShortVector reshape(Species 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( Short256Vector.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( Short256Vector.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( Short256Vector.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( Short256Vector.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( Short256Vector.class, short.class, LENGTH, ShortMaxVector.class, short.class, ShortMaxVector.LENGTH, - this, ts, + this, s, (species, vector) -> (ShortVector) vector.defaultReinterpret(species) ); } else { @@ -354,128 +349,128 @@ @Override @ForceInline public ShortVector add(short o) { - return add(SPECIES.broadcast(o)); + return add((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public ShortVector add(short o, Mask m) { - return add(SPECIES.broadcast(o), m); + return add((Short256Vector)ShortVector.broadcast(SPECIES, o), m); } @Override @ForceInline public ShortVector sub(short o) { - return sub(SPECIES.broadcast(o)); + return sub((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public ShortVector sub(short o, Mask m) { - return sub(SPECIES.broadcast(o), m); + return sub((Short256Vector)ShortVector.broadcast(SPECIES, o), m); } @Override @ForceInline public ShortVector mul(short o) { - return mul(SPECIES.broadcast(o)); + return mul((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public ShortVector mul(short o, Mask m) { - return mul(SPECIES.broadcast(o), m); + return mul((Short256Vector)ShortVector.broadcast(SPECIES, o), m); } @Override @ForceInline public ShortVector min(short o) { - return min(SPECIES.broadcast(o)); + return min((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public ShortVector max(short o) { - return max(SPECIES.broadcast(o)); + return max((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public Mask equal(short o) { - return equal(SPECIES.broadcast(o)); + return equal((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public Mask notEqual(short o) { - return notEqual(SPECIES.broadcast(o)); + return notEqual((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public Mask lessThan(short o) { - return lessThan(SPECIES.broadcast(o)); + return lessThan((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public Mask lessThanEq(short o) { - return lessThanEq(SPECIES.broadcast(o)); + return lessThanEq((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public Mask greaterThan(short o) { - return greaterThan(SPECIES.broadcast(o)); + return greaterThan((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public Mask greaterThanEq(short o) { - return greaterThanEq(SPECIES.broadcast(o)); + return greaterThanEq((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public ShortVector blend(short o, Mask m) { - return blend(SPECIES.broadcast(o), m); + return blend((Short256Vector)ShortVector.broadcast(SPECIES, o), m); } @Override @ForceInline public ShortVector and(short o) { - return and(SPECIES.broadcast(o)); + return and((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public ShortVector and(short o, Mask m) { - return and(SPECIES.broadcast(o), m); + return and((Short256Vector)ShortVector.broadcast(SPECIES, o), m); } @Override @ForceInline public ShortVector or(short o) { - return or(SPECIES.broadcast(o)); + return or((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public ShortVector or(short o, Mask m) { - return or(SPECIES.broadcast(o), m); + return or((Short256Vector)ShortVector.broadcast(SPECIES, o), m); } @Override @ForceInline public ShortVector xor(short o) { - return xor(SPECIES.broadcast(o)); + return xor((Short256Vector)ShortVector.broadcast(SPECIES, o)); } @Override @ForceInline public ShortVector xor(short o, Mask m) { - return xor(SPECIES.broadcast(o), m); + return xor((Short256Vector)ShortVector.broadcast(SPECIES, o), m); } @Override @@ -730,7 +725,7 @@ @Override @ForceInline public short andAll(Mask m) { - return SPECIES.broadcast((short) -1).blend(this, m).andAll(); + return blend((Short256Vector)ShortVector.broadcast(SPECIES, (short) -1), m).andAll(); } @Override @@ -772,7 +767,7 @@ @Override @ForceInline public short orAll(Mask m) { - return SPECIES.broadcast((short) 0).blend(this, m).orAll(); + return blend((Short256Vector)ShortVector.broadcast(SPECIES, (short) 0), m).orAll(); } @Override @@ -787,33 +782,33 @@ @Override @ForceInline public short xorAll(Mask m) { - return SPECIES.broadcast((short) 0).blend(this, m).xorAll(); + return blend((Short256Vector)ShortVector.broadcast(SPECIES, (short) 0), m).xorAll(); } @Override @ForceInline public short addAll(Mask m) { - return SPECIES.broadcast((short) 0).blend(this, m).addAll(); + return blend((Short256Vector)ShortVector.broadcast(SPECIES, (short) 0), m).addAll(); } @Override @ForceInline public short mulAll(Mask m) { - return SPECIES.broadcast((short) 1).blend(this, m).mulAll(); + return blend((Short256Vector)ShortVector.broadcast(SPECIES, (short) 1), m).mulAll(); } @Override @ForceInline public short minAll(Mask m) { - return SPECIES.broadcast(Short.MAX_VALUE).blend(this, m).minAll(); + return blend((Short256Vector)ShortVector.broadcast(SPECIES, Short.MAX_VALUE), m).minAll(); } @Override @ForceInline public short maxAll(Mask m) { - return SPECIES.broadcast(Short.MIN_VALUE).blend(this, m).maxAll(); + return blend((Short256Vector)ShortVector.broadcast(SPECIES, Short.MIN_VALUE), m).maxAll(); } @Override @@ -1197,7 +1192,7 @@ } @Override - public Short256Species species() { + public Species species() { return SPECIES; } @@ -1213,6 +1208,31 @@ return new Short256Vector(res); } + @Override + @ForceInline + @SuppressWarnings("unchecked") + public Mask cast(Species 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 ) new Byte256Vector.Byte256Mask(maskArray); + } else if (stype == short.class) { + return (Mask ) new Short256Vector.Short256Mask(maskArray); + } else if (stype == int.class) { + return (Mask ) new Int256Vector.Int256Mask(maskArray); + } else if (stype == long.class) { + return (Mask ) new Long256Vector.Long256Mask(maskArray); + } else if (stype == float.class) { + return (Mask ) new Float256Vector.Float256Mask(maskArray); + } else if (stype == double.class) { + return (Mask ) new Double256Vector.Double256Mask(maskArray); + } else { + throw new UnsupportedOperationException("Bad lane type for casting."); + } + } + // Unary operations @Override @@ -1285,7 +1305,7 @@ } @Override - public Short256Species species() { + public Species species() { return SPECIES; } @@ -1299,6 +1319,31 @@ } @Override + @ForceInline + @SuppressWarnings("unchecked") + public Shuffle cast(Species 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) new Byte256Vector.Byte256Shuffle(shuffleArray); + } else if (stype == short.class) { + return (Shuffle) new Short256Vector.Short256Shuffle(shuffleArray); + } else if (stype == int.class) { + return (Shuffle) new Int256Vector.Int256Shuffle(shuffleArray); + } else if (stype == long.class) { + return (Shuffle) new Long256Vector.Long256Shuffle(shuffleArray); + } else if (stype == float.class) { + return (Shuffle) new Float256Vector.Float256Shuffle(shuffleArray); + } else if (stype == double.class) { + return (Shuffle) new Double256Vector.Double256Shuffle(shuffleArray); + } else { + throw new UnsupportedOperationException("Bad lane type for casting."); + } + } + + @Override public Short256Shuffle rearrange(Vector.Shuffle o) { Short256Shuffle s = (Short256Shuffle) o; byte[] r = new byte[reorder.length]; @@ -1312,148 +1357,7 @@ // Species @Override - public Short256Species species() { + public Species species() { return SPECIES; } - - static final class Short256Species extends ShortSpecies { - static final int BIT_SIZE = Shape.S_256_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 elementType() { - return short.class; - } - - @Override - @ForceInline - public Class boxType() { - return Short256Vector.class; - } - - @Override - @ForceInline - public Class maskType() { - return Short256Mask.class; - } - - @Override - @ForceInline - public int elementSize() { - return Short.SIZE; - } - - @Override - @ForceInline - @SuppressWarnings("unchecked") - Class vectorType() { - return Short256Vector.class; - } - - @Override - @ForceInline - public Shape shape() { - return Shape.S_256_BIT; - } - - @Override - Short256Vector op(FOp f) { - short[] res = new short[length()]; - for (int i = 0; i < length(); i++) { - res[i] = f.apply(i); - } - return new Short256Vector(res); - } - - @Override - Short256Vector op(Mask o, FOp f) { - short[] res = new short[length()]; - boolean[] mbits = ((Short256Mask)o).getBits(); - for (int i = 0; i < length(); i++) { - if (mbits[i]) { - res[i] = f.apply(i); - } - } - return new Short256Vector(res); - } - - @Override - Short256Mask opm(FOpm f) { - boolean[] res = new boolean[length()]; - for (int i = 0; i < length(); i++) { - res[i] = (boolean)f.apply(i); - } - return new Short256Mask(res); - } - - // Factories - - @Override - @ForceInline - public Short256Vector zero() { - return VectorIntrinsics.broadcastCoerced(Short256Vector.class, short.class, LENGTH, - 0, SPECIES, - ((bits, s) -> ((Short256Species)s).op(i -> (short)bits))); - } - - @Override - @ForceInline - public Short256Vector broadcast(short e) { - return VectorIntrinsics.broadcastCoerced( - Short256Vector.class, short.class, LENGTH, - e, SPECIES, - ((bits, s) -> ((Short256Species)s).op(i -> (short)bits))); - } - - @Override - @ForceInline - public Short256Vector scalars(short... es) { - Objects.requireNonNull(es); - int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH); - return VectorIntrinsics.load(Short256Vector.class, short.class, LENGTH, - es, Unsafe.ARRAY_SHORT_BASE_OFFSET, - es, ix, SPECIES, - (c, idx, s) -> ((Short256Species)s).op(n -> c[idx + n])); - } - - @Override - @ForceInline - public Short256Mask cast(Mask m) { - if (m.length() != LENGTH) - throw new IllegalArgumentException("Mask length this species length differ"); - return new Short256Mask(m.toArray()); - } - - @Override - @ForceInline - public Short256Shuffle cast(Shuffle s) { - if (s.length() != LENGTH) - throw new IllegalArgumentException("Shuffle length this species length differ"); - return new Short256Shuffle(s.toArray()); - } - } }