[vector] RFC: Add AArch64 SVE 256-byte support for API fromArray with a mask
Yang Zhang
Yang.Zhang at arm.com
Tue Feb 18 07:23:11 UTC 2020
Hi,
I'm adding AArch64 SVE 256-byte support for API fromArray with a mask.
The issue of current implementation.
In Vector API Java implementations, byte[-128, 127] data type is used to express the lane numbers of a ByteVector.
For AArch64 SVE, the maximum vector length is 256 bytes(2048/8) which is out of the range of byte.
A test case for API ByteVector fromArray with a mask:
This API loads a vector from an array of type {@code byte[]}
starting at an offset and using a mask.
// Assume vector length is 256 bytes.
static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_MAX;
int vl = SPECIES.length(); // 256
static final int LENGTH = 1024;
byte [] index = new byte[LENGTH];
boolean [] mask = new boolean[LENGTH];
for (int i = 0; i < LENGTH; i++) {
index[i] = (byte) i;
mask[i] = false;
}
for (int i = 0; i < 200; i++) {
mask[i] = true;
}
vmask = VectorMask.fromArray(SPECIES, mask, 0);
io = ByteVector.fromArray(SPECIES, index, 800, vmask);
System.out.println("io: " + io);
This test case fails. Error log is:
Caused by: java.lang.IllegalArgumentException: Vector creation failed: value 255 cannot be represented in ETYPE byte; result of cast is -1
at jdk.incubator.vector/jdk.incubator.vector.AbstractSpecies.badElementBits(AbstractSpecies.java:411)
at jdk.incubator.vector/jdk.incubator.vector.ByteVector$ByteSpecies.longToElementBits(ByteVector.java:3644)
at jdk.incubator.vector/jdk.incubator.vector.ByteVector$ByteSpecies.checkValue(ByteVector.java:3610)
at jdk.incubator.vector/jdk.incubator.vector.AbstractSpecies.iotaArray(AbstractSpecies.java:435)
at jdk.incubator.vector/jdk.incubator.vector.ByteMaxVector.<clinit>(ByteMaxVector.java:69)
... 10 more
I have raised such concern before[1], and there are a lot of discussions.
Based on these, I draft a patch that using two vectors to support 256-byte vector. Could you please help to review it?
Webrev: http://cr.openjdk.java.net/~yzhang/vectorapi/vectorapi.fromarray/webrev.00/index.html
In original version, byte array iota[] is used to store lane numbers.
for (int i = 0; i < laneCount; i++) {
iota[i] = i;
}
In my version, byte array iota[] and iotaMask[] are used.
for (int i = 0; i < laneCount; i++) {
if (i < 128) {
iota[i] = i;
iotamask[i] = 0;
} else {
iota[i] = i - 128;
iotamask[i] = 1;
}
}
When lane numbers are needed, we need to restore real lane numbers
based on iota and iotaMask.
With this patch, byte vector with a mask can be loaded correctly.
correctly.
Regards
Yang
[1] https://mail.openjdk.java.net/pipermail/panama-dev/2019-November/006605.html
More information about the panama-dev
mailing list