[vectorIntrinsics] Issue to VectorAPI "selectFrom" for byte type with Arm SVE 2048-bits
Xiaohong Gong
Xiaohong.Gong at arm.com
Fri Oct 23 06:59:20 UTC 2020
Hi,
Currently the vector API test "SelectFromByteMaxVectorTests" throws with "IndexOutOfBoundsException"
when run with Arm SVE 2048-bits. The tests are used to test the two APIs:
```
// Using index values stored in the lanes of this vector, assemble values stored in second vector v.
public abstract Vector<E> selectFrom(Vector<E> v);
// Using index values stored in the lanes of this vector, assemble values stored in second vector, under the
// control of a mask.
public abstract Vector<E> selectFrom(Vector<E> v, VectorMask<E> m);
```
Just as the notes described, the vector itself stores the index values in the lanes and returns a vector whose
elements are from the "vector v" under the control of the index values. It works just like the "VectorShuffle".
So for the vector itself, the element values should be in the range of 0 ~ (vector_length - 1). And since the
two APIs are defined in all vector types (byte, short, int, long, float, double), the element type is the relative
primitive type. This can work fine for all types if the vector length is lower than the max value of the type.
Otherwise, the index value might not be the right one due to type cast.
So here is the root cause for the test exception: for SVE 2048-bits, the max vector length for byte is 256
(2048 / 8). The valid index values are in the range of 0 ~ 255. However, since the values are stored to a byte
vector with the range of -128 ~ 127, the final values might be negative. So the exception happens like:
```
test ByteMaxVectorTests.SelectFromByteMaxVectorTestsMaskedSmokeTest(byte[cornerCaseValue(i)], shuffle[random], mask[i % 2]): failure
java.lang.IndexOutOfBoundsException: required an index in [0..255] but found -116
at jdk.incubator.vector/jdk.incubator.vector.AbstractShuffle.checkIndexFailed(AbstractShuffle.java:288)
at jdk.incubator.vector/jdk.incubator.vector.AbstractShuffle.checkIndexes(AbstractShuffle.java:187)
at jdk.incubator.vector/jdk.incubator.vector.ByteVector.rearrangeTemplate(ByteVector.java:2142)
at jdk.incubator.vector/jdk.incubator.vector.ByteMaxVector.rearrange(ByteMaxVector.java:478)
at jdk.incubator.vector/jdk.incubator.vector.ByteMaxVector.rearrange(ByteMaxVector.java:43)
at jdk.incubator.vector/jdk.incubator.vector.ByteVector.selectFromTemplate(ByteVector.java:2208)
at jdk.incubator.vector/jdk.incubator.vector.ByteMaxVector.selectFrom(ByteMaxVector.java:505)
at jdk.incubator.vector/jdk.incubator.vector.ByteMaxVector.selectFrom(ByteMaxVector.java:43)
at ByteMaxVectorTests.SelectFromByteMaxVectorTestsMaskedSmokeTest(ByteMaxVectorTests.java:5058)
```
One way to fix this issue is to use a more appropriate type (like int) to store the index values while not the relevant
vector type. And since the values in the lanes are used as the vector index, is it possible to only define the APIs for
int type? Many thanks if I can get any comments or better ideas about this issue!
Thanks,
Xiaohong Gong
More information about the panama-dev
mailing list