< prev index next >
src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short64Vector.java
Print this page
rev 55589 : Species-phase2
rev 55591 : XxxSpecies made package private
@@ -36,11 +36,11 @@
import jdk.internal.vm.annotation.ForceInline;
import static jdk.incubator.vector.VectorIntrinsics.*;
@SuppressWarnings("cast")
final class Short64Vector extends ShortVector {
- static final Short64Species SPECIES = new Short64Species();
+ private static final Species<Short> SPECIES = ShortVector.SPECIES_64;
static final Short64Vector ZERO = new Short64Vector();
static final int LENGTH = SPECIES.length();
@@ -153,11 +153,11 @@
throw new IllegalArgumentException("Vector length this species length differ");
return VectorIntrinsics.cast(
Short64Vector.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(
Short64Vector.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(
Short64Vector.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(
Short64Vector.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(
Short64Vector.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(
Short64Vector.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((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public ShortVector add(short o, Mask<Short> m) {
- return add(SPECIES.broadcast(o), m);
+ return add((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public ShortVector sub(short o) {
- return sub(SPECIES.broadcast(o));
+ return sub((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public ShortVector sub(short o, Mask<Short> m) {
- return sub(SPECIES.broadcast(o), m);
+ return sub((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public ShortVector mul(short o) {
- return mul(SPECIES.broadcast(o));
+ return mul((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public ShortVector mul(short o, Mask<Short> m) {
- return mul(SPECIES.broadcast(o), m);
+ return mul((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public ShortVector min(short o) {
- return min(SPECIES.broadcast(o));
+ return min((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public ShortVector max(short o) {
- return max(SPECIES.broadcast(o));
+ return max((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Short> equal(short o) {
- return equal(SPECIES.broadcast(o));
+ return equal((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Short> notEqual(short o) {
- return notEqual(SPECIES.broadcast(o));
+ return notEqual((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Short> lessThan(short o) {
- return lessThan(SPECIES.broadcast(o));
+ return lessThan((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Short> lessThanEq(short o) {
- return lessThanEq(SPECIES.broadcast(o));
+ return lessThanEq((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Short> greaterThan(short o) {
- return greaterThan(SPECIES.broadcast(o));
+ return greaterThan((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Short> greaterThanEq(short o) {
- return greaterThanEq(SPECIES.broadcast(o));
+ return greaterThanEq((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public ShortVector blend(short o, Mask<Short> m) {
- return blend(SPECIES.broadcast(o), m);
+ return blend((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public ShortVector and(short o) {
- return and(SPECIES.broadcast(o));
+ return and((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public ShortVector and(short o, Mask<Short> m) {
- return and(SPECIES.broadcast(o), m);
+ return and((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public ShortVector or(short o) {
- return or(SPECIES.broadcast(o));
+ return or((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public ShortVector or(short o, Mask<Short> m) {
- return or(SPECIES.broadcast(o), m);
+ return or((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public ShortVector xor(short o) {
- return xor(SPECIES.broadcast(o));
+ return xor((Short64Vector)ShortVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public ShortVector xor(short o, Mask<Short> m) {
- return xor(SPECIES.broadcast(o), m);
+ return xor((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public Short64Vector neg() {
@@ -728,11 +723,11 @@
}
@Override
@ForceInline
public short andAll(Mask<Short> m) {
- return SPECIES.broadcast((short) -1).blend(this, m).andAll();
+ return blend((Short64Vector)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((Short64Vector)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((Short64Vector)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((Short64Vector)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((Short64Vector)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((Short64Vector)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((Short64Vector)ShortVector.broadcast(SPECIES, Short.MIN_VALUE), m).maxAll();
}
@Override
@ForceInline
public Shuffle<Short> toShuffle() {
@@ -1195,11 +1190,11 @@
}
return new Short64Mask(res);
}
@Override
- public Short64Species species() {
+ public Species<Short> species() {
return SPECIES;
}
@Override
public Short64Vector toVector() {
@@ -1211,10 +1206,35 @@
res[i] = (short) (bits[i] ? -1 : 0);
}
return new Short64Vector(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 Byte64Vector.Byte64Mask(maskArray);
+ } else if (stype == short.class) {
+ return (Mask <E>) new Short64Vector.Short64Mask(maskArray);
+ } else if (stype == int.class) {
+ return (Mask <E>) new Int64Vector.Int64Mask(maskArray);
+ } else if (stype == long.class) {
+ return (Mask <E>) new Long64Vector.Long64Mask(maskArray);
+ } else if (stype == float.class) {
+ return (Mask <E>) new Float64Vector.Float64Mask(maskArray);
+ } else if (stype == double.class) {
+ return (Mask <E>) new Double64Vector.Double64Mask(maskArray);
+ } else {
+ throw new UnsupportedOperationException("Bad lane type for casting.");
+ }
+ }
+
// Unary operations
@Override
@ForceInline
public Short64Mask not() {
@@ -1283,11 +1303,11 @@
public Short64Shuffle(IntUnaryOperator f) {
super(f);
}
@Override
- public Short64Species 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 Byte64Vector.Byte64Shuffle(shuffleArray);
+ } else if (stype == short.class) {
+ return (Shuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
+ } else if (stype == int.class) {
+ return (Shuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
+ } else if (stype == long.class) {
+ return (Shuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);
+ } else if (stype == float.class) {
+ return (Shuffle<F>) new Float64Vector.Float64Shuffle(shuffleArray);
+ } else if (stype == double.class) {
+ return (Shuffle<F>) new Double64Vector.Double64Shuffle(shuffleArray);
+ } else {
+ throw new UnsupportedOperationException("Bad lane type for casting.");
+ }
+ }
+
+ @Override
public Short64Shuffle rearrange(Vector.Shuffle<Short> o) {
Short64Shuffle s = (Short64Shuffle) 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 Short64Species species() {
+ public Species<Short> species() {
return SPECIES;
}
-
- static final class Short64Species extends ShortSpecies {
- static final int BIT_SIZE = Shape.S_64_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 Short64Vector.class;
- }
-
- @Override
- @ForceInline
- public Class<?> maskType() {
- return Short64Mask.class;
- }
-
- @Override
- @ForceInline
- public int elementSize() {
- return Short.SIZE;
- }
-
- @Override
- @ForceInline
- @SuppressWarnings("unchecked")
- Class<?> vectorType() {
- return Short64Vector.class;
- }
-
- @Override
- @ForceInline
- public Shape shape() {
- return Shape.S_64_BIT;
- }
-
- @Override
- Short64Vector op(FOp f) {
- short[] res = new short[length()];
- for (int i = 0; i < length(); i++) {
- res[i] = f.apply(i);
- }
- return new Short64Vector(res);
- }
-
- @Override
- Short64Vector op(Mask<Short> o, FOp f) {
- short[] res = new short[length()];
- boolean[] mbits = ((Short64Mask)o).getBits();
- for (int i = 0; i < length(); i++) {
- if (mbits[i]) {
- res[i] = f.apply(i);
- }
- }
- return new Short64Vector(res);
- }
-
- @Override
- Short64Mask opm(FOpm f) {
- boolean[] res = new boolean[length()];
- for (int i = 0; i < length(); i++) {
- res[i] = (boolean)f.apply(i);
- }
- return new Short64Mask(res);
- }
-
- // Factories
-
- @Override
- @ForceInline
- public Short64Vector zero() {
- return VectorIntrinsics.broadcastCoerced(Short64Vector.class, short.class, LENGTH,
- 0, SPECIES,
- ((bits, s) -> ((Short64Species)s).op(i -> (short)bits)));
- }
-
- @Override
- @ForceInline
- public Short64Vector broadcast(short e) {
- return VectorIntrinsics.broadcastCoerced(
- Short64Vector.class, short.class, LENGTH,
- e, SPECIES,
- ((bits, s) -> ((Short64Species)s).op(i -> (short)bits)));
- }
-
- @Override
- @ForceInline
- public Short64Vector scalars(short... es) {
- Objects.requireNonNull(es);
- int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
- return VectorIntrinsics.load(Short64Vector.class, short.class, LENGTH,
- es, Unsafe.ARRAY_SHORT_BASE_OFFSET,
- es, ix, SPECIES,
- (c, idx, s) -> ((Short64Species)s).op(n -> c[idx + n]));
- }
-
- @Override
- @ForceInline
- public <E> Short64Mask cast(Mask<E> m) {
- if (m.length() != LENGTH)
- throw new IllegalArgumentException("Mask length this species length differ");
- return new Short64Mask(m.toArray());
- }
-
- @Override
- @ForceInline
- public <E> Short64Shuffle cast(Shuffle<E> s) {
- if (s.length() != LENGTH)
- throw new IllegalArgumentException("Shuffle length this species length differ");
- return new Short64Shuffle(s.toArray());
- }
- }
}
< prev index next >