< prev index next >
src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long64Vector.java
Print this page
rev 55589 : Species-phase2
rev 55591 : XxxSpecies made package private
@@ -36,21 +36,23 @@
import jdk.internal.vm.annotation.ForceInline;
import static jdk.incubator.vector.VectorIntrinsics.*;
@SuppressWarnings("cast")
final class Long64Vector extends LongVector {
- static final Long64Species SPECIES = new Long64Species();
+ private static final Species<Long> SPECIES = LongVector.SPECIES_64;
static final Long64Vector ZERO = new Long64Vector();
static final int LENGTH = SPECIES.length();
// Index vector species
- private static final IntVector.IntSpecies INDEX_SPEC;
+ private static final IntVector.IntSpecies INDEX_SPECIES;
+
static {
- INDEX_SPEC = (IntVector.IntSpecies) Species.of(int.class, Shape.S_64_BIT);
+ INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(Shape.S_64_BIT);
}
+
private final long[] vec; // Don't access directly, use getElements() instead.
private long[] getElements() {
return VectorIntrinsics.maybeRebox(this).vec;
}
@@ -158,11 +160,11 @@
throw new IllegalArgumentException("Vector length this species length differ");
return VectorIntrinsics.cast(
Long64Vector.class,
long.class, LENGTH,
- s.vectorType(),
+ s.boxType(),
s.elementType(), LENGTH,
this, s,
(species, vector) -> vector.castDefault(species)
);
}
@@ -176,41 +178,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.");
}
}
@@ -296,59 +298,54 @@
@Override
@ForceInline
public LongVector reshape(Species<Long> s) {
Objects.requireNonNull(s);
- if (s.bitSize() == 64 && (s instanceof Long64Vector.Long64Species)) {
- Long64Vector.Long64Species ts = (Long64Vector.Long64Species)s;
+ if (s.bitSize() == 64 && (s.boxType() == Long64Vector.class)) {
return VectorIntrinsics.reinterpret(
Long64Vector.class,
long.class, LENGTH,
Long64Vector.class,
long.class, Long64Vector.LENGTH,
- this, ts,
+ this, s,
(species, vector) -> (LongVector) vector.defaultReinterpret(species)
);
- } else if (s.bitSize() == 128 && (s instanceof Long128Vector.Long128Species)) {
- Long128Vector.Long128Species ts = (Long128Vector.Long128Species)s;
+ } else if (s.bitSize() == 128 && (s.boxType() == Long128Vector.class)) {
return VectorIntrinsics.reinterpret(
Long64Vector.class,
long.class, LENGTH,
Long128Vector.class,
long.class, Long128Vector.LENGTH,
- this, ts,
+ this, s,
(species, vector) -> (LongVector) vector.defaultReinterpret(species)
);
- } else if (s.bitSize() == 256 && (s instanceof Long256Vector.Long256Species)) {
- Long256Vector.Long256Species ts = (Long256Vector.Long256Species)s;
+ } else if (s.bitSize() == 256 && (s.boxType() == Long256Vector.class)) {
return VectorIntrinsics.reinterpret(
Long64Vector.class,
long.class, LENGTH,
Long256Vector.class,
long.class, Long256Vector.LENGTH,
- this, ts,
+ this, s,
(species, vector) -> (LongVector) vector.defaultReinterpret(species)
);
- } else if (s.bitSize() == 512 && (s instanceof Long512Vector.Long512Species)) {
- Long512Vector.Long512Species ts = (Long512Vector.Long512Species)s;
+ } else if (s.bitSize() == 512 && (s.boxType() == Long512Vector.class)) {
return VectorIntrinsics.reinterpret(
Long64Vector.class,
long.class, LENGTH,
Long512Vector.class,
long.class, Long512Vector.LENGTH,
- this, ts,
+ this, s,
(species, vector) -> (LongVector) vector.defaultReinterpret(species)
);
} else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
- && (s.bitSize() % 128 == 0) && (s instanceof LongMaxVector.LongMaxSpecies)) {
- LongMaxVector.LongMaxSpecies ts = (LongMaxVector.LongMaxSpecies)s;
+ && (s.bitSize() % 128 == 0) && (s.boxType() == LongMaxVector.class)) {
return VectorIntrinsics.reinterpret(
Long64Vector.class,
long.class, LENGTH,
LongMaxVector.class,
long.class, LongMaxVector.LENGTH,
- this, ts,
+ this, s,
(species, vector) -> (LongVector) vector.defaultReinterpret(species)
);
} else {
throw new InternalError("Unimplemented size");
}
@@ -357,132 +354,132 @@
// Binary operations with scalars
@Override
@ForceInline
public LongVector add(long o) {
- return add(SPECIES.broadcast(o));
+ return add((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public LongVector add(long o, Mask<Long> m) {
- return add(SPECIES.broadcast(o), m);
+ return add((Long64Vector)LongVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public LongVector sub(long o) {
- return sub(SPECIES.broadcast(o));
+ return sub((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public LongVector sub(long o, Mask<Long> m) {
- return sub(SPECIES.broadcast(o), m);
+ return sub((Long64Vector)LongVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public LongVector mul(long o) {
- return mul(SPECIES.broadcast(o));
+ return mul((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public LongVector mul(long o, Mask<Long> m) {
- return mul(SPECIES.broadcast(o), m);
+ return mul((Long64Vector)LongVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public LongVector min(long o) {
- return min(SPECIES.broadcast(o));
+ return min((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public LongVector max(long o) {
- return max(SPECIES.broadcast(o));
+ return max((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Long> equal(long o) {
- return equal(SPECIES.broadcast(o));
+ return equal((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Long> notEqual(long o) {
- return notEqual(SPECIES.broadcast(o));
+ return notEqual((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Long> lessThan(long o) {
- return lessThan(SPECIES.broadcast(o));
+ return lessThan((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Long> lessThanEq(long o) {
- return lessThanEq(SPECIES.broadcast(o));
+ return lessThanEq((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Long> greaterThan(long o) {
- return greaterThan(SPECIES.broadcast(o));
+ return greaterThan((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public Mask<Long> greaterThanEq(long o) {
- return greaterThanEq(SPECIES.broadcast(o));
+ return greaterThanEq((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public LongVector blend(long o, Mask<Long> m) {
- return blend(SPECIES.broadcast(o), m);
+ return blend((Long64Vector)LongVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public LongVector and(long o) {
- return and(SPECIES.broadcast(o));
+ return and((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public LongVector and(long o, Mask<Long> m) {
- return and(SPECIES.broadcast(o), m);
+ return and((Long64Vector)LongVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public LongVector or(long o) {
- return or(SPECIES.broadcast(o));
+ return or((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public LongVector or(long o, Mask<Long> m) {
- return or(SPECIES.broadcast(o), m);
+ return or((Long64Vector)LongVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public LongVector xor(long o) {
- return xor(SPECIES.broadcast(o));
+ return xor((Long64Vector)LongVector.broadcast(SPECIES, o));
}
@Override
@ForceInline
public LongVector xor(long o, Mask<Long> m) {
- return xor(SPECIES.broadcast(o), m);
+ return xor((Long64Vector)LongVector.broadcast(SPECIES, o), m);
}
@Override
@ForceInline
public Long64Vector neg() {
@@ -713,11 +710,11 @@
@Override
@ForceInline
public Long64Vector shiftL(Vector<Long> s) {
Long64Vector shiftv = (Long64Vector)s;
// As per shift specification for Java, mask the shift count.
- shiftv = shiftv.and(species().broadcast(0x3f));
+ shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
return VectorIntrinsics.binaryOp(
VECTOR_OP_LSHIFT, Long64Vector.class, long.class, LENGTH,
this, shiftv,
(v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a << b)));
}
@@ -725,11 +722,11 @@
@Override
@ForceInline
public Long64Vector shiftR(Vector<Long> s) {
Long64Vector shiftv = (Long64Vector)s;
// As per shift specification for Java, mask the shift count.
- shiftv = shiftv.and(species().broadcast(0x3f));
+ shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
return VectorIntrinsics.binaryOp(
VECTOR_OP_URSHIFT, Long64Vector.class, long.class, LENGTH,
this, shiftv,
(v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >>> b)));
}
@@ -737,11 +734,11 @@
@Override
@ForceInline
public Long64Vector aShiftR(Vector<Long> s) {
Long64Vector shiftv = (Long64Vector)s;
// As per shift specification for Java, mask the shift count.
- shiftv = shiftv.and(species().broadcast(0x3f));
+ shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
return VectorIntrinsics.binaryOp(
VECTOR_OP_RSHIFT, Long64Vector.class, long.class, LENGTH,
this, shiftv,
(v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >> b)));
}
@@ -769,11 +766,11 @@
}
@Override
@ForceInline
public long andAll(Mask<Long> m) {
- return SPECIES.broadcast((long) -1).blend(this, m).andAll();
+ return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) -1), m).andAll();
}
@Override
@ForceInline
public long minAll() {
@@ -811,11 +808,11 @@
}
@Override
@ForceInline
public long orAll(Mask<Long> m) {
- return SPECIES.broadcast((long) 0).blend(this, m).orAll();
+ return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) 0), m).orAll();
}
@Override
@ForceInline
public long xorAll() {
@@ -826,37 +823,37 @@
}
@Override
@ForceInline
public long xorAll(Mask<Long> m) {
- return SPECIES.broadcast((long) 0).blend(this, m).xorAll();
+ return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) 0), m).xorAll();
}
@Override
@ForceInline
public long addAll(Mask<Long> m) {
- return SPECIES.broadcast((long) 0).blend(this, m).addAll();
+ return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) 0), m).addAll();
}
@Override
@ForceInline
public long mulAll(Mask<Long> m) {
- return SPECIES.broadcast((long) 1).blend(this, m).mulAll();
+ return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) 1), m).mulAll();
}
@Override
@ForceInline
public long minAll(Mask<Long> m) {
- return SPECIES.broadcast(Long.MAX_VALUE).blend(this, m).minAll();
+ return blend((Long64Vector)LongVector.broadcast(SPECIES, Long.MAX_VALUE), m).minAll();
}
@Override
@ForceInline
public long maxAll(Mask<Long> m) {
- return SPECIES.broadcast(Long.MIN_VALUE).blend(this, m).maxAll();
+ return blend((Long64Vector)LongVector.broadcast(SPECIES, Long.MIN_VALUE), m).maxAll();
}
@Override
@ForceInline
public Shuffle<Long> toShuffle() {
@@ -1258,11 +1255,11 @@
}
return new Long64Mask(res);
}
@Override
- public Long64Species species() {
+ public Species<Long> species() {
return SPECIES;
}
@Override
public Long64Vector toVector() {
@@ -1274,10 +1271,35 @@
res[i] = (long) (bits[i] ? -1 : 0);
}
return new Long64Vector(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 Long64Mask not() {
@@ -1346,11 +1368,11 @@
public Long64Shuffle(IntUnaryOperator f) {
super(f);
}
@Override
- public Long64Species species() {
+ public Species<Long> species() {
return SPECIES;
}
@Override
public LongVector toVector() {
@@ -1360,10 +1382,35 @@
}
return LongVector.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 Long64Shuffle rearrange(Vector.Shuffle<Long> o) {
Long64Shuffle s = (Long64Shuffle) o;
byte[] r = new byte[reorder.length];
for (int i = 0; i < reorder.length; i++) {
r[i] = reorder[s.reorder[i]];
@@ -1373,155 +1420,9 @@
}
// Species
@Override
- public Long64Species species() {
+ public Species<Long> species() {
return SPECIES;
}
-
- static final class Long64Species extends LongSpecies {
- static final int BIT_SIZE = Shape.S_64_BIT.bitSize();
-
- static final int LENGTH = BIT_SIZE / Long.SIZE;
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("Shape[");
- sb.append(bitSize()).append(" bits, ");
- sb.append(length()).append(" ").append(long.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<Long> elementType() {
- return long.class;
- }
-
- @Override
- @ForceInline
- public Class<?> boxType() {
- return Long64Vector.class;
- }
-
- @Override
- @ForceInline
- public Class<?> maskType() {
- return Long64Mask.class;
- }
-
- @Override
- @ForceInline
- public int elementSize() {
- return Long.SIZE;
- }
-
- @Override
- @ForceInline
- @SuppressWarnings("unchecked")
- Class<?> vectorType() {
- return Long64Vector.class;
- }
-
- @Override
- @ForceInline
- public Shape shape() {
- return Shape.S_64_BIT;
- }
-
- @Override
- IntVector.IntSpecies indexSpecies() {
- return INDEX_SPEC;
- }
-
- @Override
- Long64Vector op(FOp f) {
- long[] res = new long[length()];
- for (int i = 0; i < length(); i++) {
- res[i] = f.apply(i);
- }
- return new Long64Vector(res);
- }
-
- @Override
- Long64Vector op(Mask<Long> o, FOp f) {
- long[] res = new long[length()];
- boolean[] mbits = ((Long64Mask)o).getBits();
- for (int i = 0; i < length(); i++) {
- if (mbits[i]) {
- res[i] = f.apply(i);
- }
- }
- return new Long64Vector(res);
- }
-
- @Override
- Long64Mask opm(FOpm f) {
- boolean[] res = new boolean[length()];
- for (int i = 0; i < length(); i++) {
- res[i] = (boolean)f.apply(i);
- }
- return new Long64Mask(res);
- }
-
- // Factories
-
- @Override
- @ForceInline
- public Long64Vector zero() {
- return VectorIntrinsics.broadcastCoerced(Long64Vector.class, long.class, LENGTH,
- 0, SPECIES,
- ((bits, s) -> ((Long64Species)s).op(i -> (long)bits)));
- }
-
- @Override
- @ForceInline
- public Long64Vector broadcast(long e) {
- return VectorIntrinsics.broadcastCoerced(
- Long64Vector.class, long.class, LENGTH,
- e, SPECIES,
- ((bits, s) -> ((Long64Species)s).op(i -> (long)bits)));
- }
-
- @Override
- @ForceInline
- public Long64Vector scalars(long... es) {
- Objects.requireNonNull(es);
- int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
- return VectorIntrinsics.load(Long64Vector.class, long.class, LENGTH,
- es, Unsafe.ARRAY_LONG_BASE_OFFSET,
- es, ix, SPECIES,
- (c, idx, s) -> ((Long64Species)s).op(n -> c[idx + n]));
- }
-
- @Override
- @ForceInline
- public <E> Long64Mask cast(Mask<E> m) {
- if (m.length() != LENGTH)
- throw new IllegalArgumentException("Mask length this species length differ");
- return new Long64Mask(m.toArray());
- }
-
- @Override
- @ForceInline
- public <E> Long64Shuffle cast(Shuffle<E> s) {
- if (s.length() != LENGTH)
- throw new IllegalArgumentException("Shuffle length this species length differ");
- return new Long64Shuffle(s.toArray());
- }
- }
}
< prev index next >