Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,17 @@ static ByteVector compressHelper(Vector<Byte> v, VectorMask<Byte> m) {
return r;
}

static ByteVector selectFromTwoVectorHelper(Vector<Byte> v1, Vector<Byte> v2, Vector<Byte> v3) {
int vlen = v1.length();
static ByteVector selectFromTwoVectorHelper(Vector<Byte> wrappedIndex, Vector<Byte> src1, Vector<Byte> src2) {
int vlen = wrappedIndex.length();
byte[] res = new byte[vlen];
byte[] vecPayload1 = ((ByteVector)v1).vec();
byte[] vecPayload2 = ((ByteVector)v2).vec();
byte[] vecPayload3 = ((ByteVector)v3).vec();
byte[] vecPayload1 = ((ByteVector)wrappedIndex).vec();
byte[] vecPayload2 = ((ByteVector)src1).vec();
byte[] vecPayload3 = ((ByteVector)src2).vec();
for (int i = 0; i < vlen; i++) {
int index = ((int)vecPayload1[i]);
res[i] = index >= vlen ? vecPayload3[index & (vlen - 1)] : vecPayload2[index];
res[i] = index >= vlen ? vecPayload3[index - vlen] : vecPayload2[index];
}
return ((ByteVector)v2).vectorFactory(res);
return ((ByteVector)src1).vectorFactory(res);
}

// Static factories (other than memory operations)
Expand Down Expand Up @@ -2594,10 +2594,12 @@ final ByteVector selectFromTemplate(ByteVector v,
@ForceInline
final ByteVector selectFromTemplate(Class<? extends Vector<Byte>> indexVecClass,
ByteVector v1, ByteVector v2) {
int twoVectorLenMask = (length() << 1) - 1;
int vlen = length();
assert ((vlen & (vlen -1)) == 0);
int twoVectorLenMask = (vlen << 1) - 1;
ByteVector wrapped_indexes = this.lanewise(VectorOperators.AND, twoVectorLenMask);
return VectorSupport.selectFromTwoVectorOp(getClass(), indexVecClass, byte.class, byte.class,
length(), wrapped_indexes, v1, v2,
vlen, wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,17 @@ static DoubleVector compressHelper(Vector<Double> v, VectorMask<Double> m) {
return r;
}

static DoubleVector selectFromTwoVectorHelper(Vector<Long> v1, Vector<Double> v2, Vector<Double> v3) {
int vlen = v1.length();
static DoubleVector selectFromTwoVectorHelper(Vector<Long> wrappedIndex, Vector<Double> src1, Vector<Double> src2) {
int vlen = wrappedIndex.length();
double[] res = new double[vlen];
long[] vecPayload1 = ((LongVector)v1).vec();
double[] vecPayload2 = ((DoubleVector)v2).vec();
double[] vecPayload3 = ((DoubleVector)v3).vec();
long[] vecPayload1 = ((LongVector)wrappedIndex).vec();
double[] vecPayload2 = ((DoubleVector)src1).vec();
double[] vecPayload3 = ((DoubleVector)src2).vec();
for (int i = 0; i < vlen; i++) {
int index = ((int)vecPayload1[i]);
res[i] = index >= vlen ? vecPayload3[index & (vlen - 1)] : vecPayload2[index];
res[i] = index >= vlen ? vecPayload3[index - vlen] : vecPayload2[index];
}
return ((DoubleVector)v2).vectorFactory(res);
return ((DoubleVector)src1).vectorFactory(res);
}

// Static factories (other than memory operations)
Expand Down Expand Up @@ -2436,11 +2436,13 @@ final DoubleVector selectFromTemplate(DoubleVector v,
@ForceInline
final DoubleVector selectFromTemplate(Class<? extends Vector<Long>> indexVecClass,
DoubleVector v1, DoubleVector v2) {
int twoVectorLenMask = (length() << 1) - 1;
int vlen = length();
assert ((vlen & (vlen -1)) == 0);
int twoVectorLenMask = (vlen << 1) - 1;
Vector<Long> wrapped_indexes = this.convert(VectorOperators.D2L, 0)
.lanewise(VectorOperators.AND, twoVectorLenMask);
return VectorSupport.selectFromTwoVectorOp(getClass(), indexVecClass , double.class, long.class,
length(), wrapped_indexes, v1, v2,
vlen, wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,17 @@ static FloatVector compressHelper(Vector<Float> v, VectorMask<Float> m) {
return r;
}

static FloatVector selectFromTwoVectorHelper(Vector<Integer> v1, Vector<Float> v2, Vector<Float> v3) {
int vlen = v1.length();
static FloatVector selectFromTwoVectorHelper(Vector<Integer> wrappedIndex, Vector<Float> src1, Vector<Float> src2) {
int vlen = wrappedIndex.length();
float[] res = new float[vlen];
int[] vecPayload1 = ((IntVector)v1).vec();
float[] vecPayload2 = ((FloatVector)v2).vec();
float[] vecPayload3 = ((FloatVector)v3).vec();
int[] vecPayload1 = ((IntVector)wrappedIndex).vec();
float[] vecPayload2 = ((FloatVector)src1).vec();
float[] vecPayload3 = ((FloatVector)src2).vec();
for (int i = 0; i < vlen; i++) {
int index = ((int)vecPayload1[i]);
res[i] = index >= vlen ? vecPayload3[index & (vlen - 1)] : vecPayload2[index];
res[i] = index >= vlen ? vecPayload3[index - vlen] : vecPayload2[index];
}
return ((FloatVector)v2).vectorFactory(res);
return ((FloatVector)src1).vectorFactory(res);
}

// Static factories (other than memory operations)
Expand Down Expand Up @@ -2448,11 +2448,13 @@ final FloatVector selectFromTemplate(FloatVector v,
@ForceInline
final FloatVector selectFromTemplate(Class<? extends Vector<Integer>> indexVecClass,
FloatVector v1, FloatVector v2) {
int twoVectorLenMask = (length() << 1) - 1;
int vlen = length();
assert ((vlen & (vlen -1)) == 0);
int twoVectorLenMask = (vlen << 1) - 1;
Vector<Integer> wrapped_indexes = this.convert(VectorOperators.F2I, 0)
.lanewise(VectorOperators.AND, twoVectorLenMask);
return VectorSupport.selectFromTwoVectorOp(getClass(), indexVecClass , float.class, int.class,
length(), wrapped_indexes, v1, v2,
vlen, wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,17 @@ static IntVector compressHelper(Vector<Integer> v, VectorMask<Integer> m) {
return r;
}

static IntVector selectFromTwoVectorHelper(Vector<Integer> v1, Vector<Integer> v2, Vector<Integer> v3) {
int vlen = v1.length();
static IntVector selectFromTwoVectorHelper(Vector<Integer> wrappedIndex, Vector<Integer> src1, Vector<Integer> src2) {
int vlen = wrappedIndex.length();
int[] res = new int[vlen];
int[] vecPayload1 = ((IntVector)v1).vec();
int[] vecPayload2 = ((IntVector)v2).vec();
int[] vecPayload3 = ((IntVector)v3).vec();
int[] vecPayload1 = ((IntVector)wrappedIndex).vec();
int[] vecPayload2 = ((IntVector)src1).vec();
int[] vecPayload3 = ((IntVector)src2).vec();
for (int i = 0; i < vlen; i++) {
int index = ((int)vecPayload1[i]);
res[i] = index >= vlen ? vecPayload3[index & (vlen - 1)] : vecPayload2[index];
res[i] = index >= vlen ? vecPayload3[index - vlen] : vecPayload2[index];
}
return ((IntVector)v2).vectorFactory(res);
return ((IntVector)src1).vectorFactory(res);
}

// Static factories (other than memory operations)
Expand Down Expand Up @@ -2579,10 +2579,12 @@ final IntVector selectFromTemplate(IntVector v,
@ForceInline
final IntVector selectFromTemplate(Class<? extends Vector<Integer>> indexVecClass,
IntVector v1, IntVector v2) {
int twoVectorLenMask = (length() << 1) - 1;
int vlen = length();
assert ((vlen & (vlen -1)) == 0);
int twoVectorLenMask = (vlen << 1) - 1;
IntVector wrapped_indexes = this.lanewise(VectorOperators.AND, twoVectorLenMask);
return VectorSupport.selectFromTwoVectorOp(getClass(), indexVecClass, int.class, int.class,
length(), wrapped_indexes, v1, v2,
vlen, wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,17 @@ static LongVector compressHelper(Vector<Long> v, VectorMask<Long> m) {
return r;
}

static LongVector selectFromTwoVectorHelper(Vector<Long> v1, Vector<Long> v2, Vector<Long> v3) {
int vlen = v1.length();
static LongVector selectFromTwoVectorHelper(Vector<Long> wrappedIndex, Vector<Long> src1, Vector<Long> src2) {
int vlen = wrappedIndex.length();
long[] res = new long[vlen];
long[] vecPayload1 = ((LongVector)v1).vec();
long[] vecPayload2 = ((LongVector)v2).vec();
long[] vecPayload3 = ((LongVector)v3).vec();
long[] vecPayload1 = ((LongVector)wrappedIndex).vec();
long[] vecPayload2 = ((LongVector)src1).vec();
long[] vecPayload3 = ((LongVector)src2).vec();
for (int i = 0; i < vlen; i++) {
int index = ((int)vecPayload1[i]);
res[i] = index >= vlen ? vecPayload3[index & (vlen - 1)] : vecPayload2[index];
res[i] = index >= vlen ? vecPayload3[index - vlen] : vecPayload2[index];
}
return ((LongVector)v2).vectorFactory(res);
return ((LongVector)src1).vectorFactory(res);
}

// Static factories (other than memory operations)
Expand Down Expand Up @@ -2445,10 +2445,12 @@ final LongVector selectFromTemplate(LongVector v,
@ForceInline
final LongVector selectFromTemplate(Class<? extends Vector<Long>> indexVecClass,
LongVector v1, LongVector v2) {
int twoVectorLenMask = (length() << 1) - 1;
int vlen = length();
assert ((vlen & (vlen -1)) == 0);
int twoVectorLenMask = (vlen << 1) - 1;
LongVector wrapped_indexes = this.lanewise(VectorOperators.AND, twoVectorLenMask);
return VectorSupport.selectFromTwoVectorOp(getClass(), indexVecClass, long.class, long.class,
length(), wrapped_indexes, v1, v2,
vlen, wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,17 @@ static ShortVector compressHelper(Vector<Short> v, VectorMask<Short> m) {
return r;
}

static ShortVector selectFromTwoVectorHelper(Vector<Short> v1, Vector<Short> v2, Vector<Short> v3) {
int vlen = v1.length();
static ShortVector selectFromTwoVectorHelper(Vector<Short> wrappedIndex, Vector<Short> src1, Vector<Short> src2) {
int vlen = wrappedIndex.length();
short[] res = new short[vlen];
short[] vecPayload1 = ((ShortVector)v1).vec();
short[] vecPayload2 = ((ShortVector)v2).vec();
short[] vecPayload3 = ((ShortVector)v3).vec();
short[] vecPayload1 = ((ShortVector)wrappedIndex).vec();
short[] vecPayload2 = ((ShortVector)src1).vec();
short[] vecPayload3 = ((ShortVector)src2).vec();
for (int i = 0; i < vlen; i++) {
int index = ((int)vecPayload1[i]);
res[i] = index >= vlen ? vecPayload3[index & (vlen - 1)] : vecPayload2[index];
res[i] = index >= vlen ? vecPayload3[index - vlen] : vecPayload2[index];
}
return ((ShortVector)v2).vectorFactory(res);
return ((ShortVector)src1).vectorFactory(res);
}

// Static factories (other than memory operations)
Expand Down Expand Up @@ -2595,10 +2595,12 @@ final ShortVector selectFromTemplate(ShortVector v,
@ForceInline
final ShortVector selectFromTemplate(Class<? extends Vector<Short>> indexVecClass,
ShortVector v1, ShortVector v2) {
int twoVectorLenMask = (length() << 1) - 1;
int vlen = length();
assert ((vlen & (vlen -1)) == 0);
int twoVectorLenMask = (vlen << 1) - 1;
ShortVector wrapped_indexes = this.lanewise(VectorOperators.AND, twoVectorLenMask);
return VectorSupport.selectFromTwoVectorOp(getClass(), indexVecClass, short.class, short.class,
length(), wrapped_indexes, v1, v2,
vlen, wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2785,28 +2785,39 @@ public abstract VectorMask<E> compare(VectorOperators.Comparison op,
* the third vector at lane {@code I - VLENGTH}.
*
* Here, {@code VLENGTH} is the result of {@code this.length()},
* and {@code wrapIndex} computes the result of
* {@code Math.floorMod(E, 2 * VLENGTH)},
* where {@code E} is the index to be wrapped.
* As long as {@code VLENGTH} is a power of two, then the result
* is also equal to {@code E & (2 * VLENGTH - 1)}.
* and for integral values {@code wrapIndex} computes the result of
* {@code Math.floorMod(E, 2 * VLENGTH)}, where {@code E} is the index
* to be wrapped. As long as {@code VLENGTH} is a power of two, then the
* result is also equal to {@code E & (2 * VLENGTH - 1)}.
*
* For floating point values {@code wrapIndex} computes
* {@code Math.floorMod(convert(E), 2 * VLENGTH)}, where {@code convert}
* converts the floating point value to an integral value with the same
* number of representational bits - as in converting a double value to
* a long value ({@code (long)doubleVal}), or a float value to an int value
* ({@code (int)floatVal}).
*
* In this way, the result contains only values stored in the
* argument vectors {@code v1} and {@code v2}, but presented in
* an order which depends on the index values in {@code this}.
*
* The result is the same as the expression
* The result for integral values is the same as the expression
* {@snippet lang=java :
* v1.rearrange(
* this.lanewise(VectorOperators.AND, 2 * VLENGTH - 1).toShuffle(),
* v2)
* }
* when {@code VLENGTH} is a power of two.
* The lane-wise {@code AND} operation results in a vector whose
* elements are in the range {@code [0, 2 * VLENGTH - 1])}. The shuffle
* conversion results in a partially wrapped shuffle whose indexes are
* in the range {@code [-VLENGTH, VLENGTH - 1])}, where exceptional
* indexes are used to select elements in the third vector.
*
* @param v1 the first input vector
* @param v2 the second input vector
* @return the rearrangement of lane elements of {@code v1} and {@code v2}
* @see #rearrange(VectorShuffle, Vector)
* @see #rearrange(VectorShuffle,Vector)
*/
public abstract Vector<E> selectFrom(Vector<E> v1, Vector<E> v2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,17 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
return r;
}

static $abstractvectortype$ selectFromTwoVectorHelper(Vector<$Boxbitstype$> v1, Vector<$Boxtype$> v2, Vector<$Boxtype$> v3) {
int vlen = v1.length();
static $abstractvectortype$ selectFromTwoVectorHelper(Vector<$Boxbitstype$> wrappedIndex, Vector<$Boxtype$> src1, Vector<$Boxtype$> src2) {
int vlen = wrappedIndex.length();
$type$[] res = new $type$[vlen];
$bitstype$[] vecPayload1 = (($abstractbitsvectortype$)v1).vec();
$type$[] vecPayload2 = (($abstractvectortype$)v2).vec();
$type$[] vecPayload3 = (($abstractvectortype$)v3).vec();
$bitstype$[] vecPayload1 = (($abstractbitsvectortype$)wrappedIndex).vec();
$type$[] vecPayload2 = (($abstractvectortype$)src1).vec();
$type$[] vecPayload3 = (($abstractvectortype$)src2).vec();
for (int i = 0; i < vlen; i++) {
int index = ((int)vecPayload1[i]);
res[i] = index >= vlen ? vecPayload3[index & (vlen - 1)] : vecPayload2[index];
res[i] = index >= vlen ? vecPayload3[index - vlen] : vecPayload2[index];
}
return (($abstractvectortype$)v2).vectorFactory(res);
return (($abstractvectortype$)src1).vectorFactory(res);
}

// Static factories (other than memory operations)
Expand Down Expand Up @@ -2971,18 +2971,20 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
@ForceInline
final $abstractvectortype$ selectFromTemplate(Class<? extends Vector<$Boxbitstype$>> indexVecClass,
$abstractvectortype$ v1, $abstractvectortype$ v2) {
int twoVectorLenMask = (length() << 1) - 1;
int vlen = length();
assert ((vlen & (vlen -1)) == 0);
int twoVectorLenMask = (vlen << 1) - 1;
#if[FP]
Vector<$Boxbitstype$> wrapped_indexes = this.convert(VectorOperators.{#if[intOrFloat]?F2I:D2L}, 0)
.lanewise(VectorOperators.AND, twoVectorLenMask);
return VectorSupport.selectFromTwoVectorOp(getClass(), indexVecClass , $type$.class, $bitstype$.class,
length(), wrapped_indexes, v1, v2,
vlen, wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
#else[FP]
$abstractvectortype$ wrapped_indexes = this.lanewise(VectorOperators.AND, twoVectorLenMask);
return VectorSupport.selectFromTwoVectorOp(getClass(), indexVecClass, $type$.class, $type$.class,
length(), wrapped_indexes, v1, v2,
vlen, wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
#end[FP]
Expand Down