[vector] time for 2-D memory addressing?
John Rose
john.r.rose at oracle.com
Wed Jun 26 06:20:11 UTC 2019
I think it’s almost time to implement 2-D address modes on `ETYPE[][] a; a[i][j]` where `i` and `j` are vector values and the 2-D array base `a` is a broadcast constant.
As documented in https://bugs.openjdk.java.net/browse/JDK-8223367 it would give a portable way to implement masked scatter (using a fake bit-bucket target).
Of course it’s also generally useful in its own right. And it's a "sweet spot", since you can emulate multi-dimensional Java arrays using a 2-D primitive, as long as you are willing to set up the first array `a` in Java code, collecting all last-dimension base addresses in some organized fashion.
The reason I think the time is near is that I think we need a solution to masked gather and scatter on platforms which don't support that natively, and this is the best way I know to do it:
void maskedStore1D(ETYPE[] target, EVector indexes, VectorMask<E> m) {
ETYPE[] bitBucket = new ETYPE[indexes.length()];
ETYPE[][] temp = new ETYPE[][]{ target, bitBucket };
EVector i = indexes.broadcast(1).blend(0, m);
EVector j = indexes.broadcast(0).addIndex(1).blend(indexes, m);
maskedStore2D(temp, i, j);
}
I suppose the actual method signature for 2D addressing is similar to 1D addressing, except (a) the scalar array is 2D, and (b) there is an extra vector argument providing the `j` index.
More information about the panama-dev
mailing list