Skip to content

Commit 57d02d9

Browse files
author
Ian Graves
committed
8362279: [vectorapi] VECTOR_OP_SUADD needs reduction support
Reviewed-by: jbhateja, qamai
1 parent a2e86ff commit 57d02d9

31 files changed

+2171
-0
lines changed

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,6 +2876,8 @@ private static ReductionOperation<ByteVector, VectorMask<Byte>> reductionOperati
28762876
toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (byte) VectorMath.minUnsigned(a, b)));
28772877
case VECTOR_OP_UMAX: return (v, m) ->
28782878
toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (byte) VectorMath.maxUnsigned(a, b)));
2879+
case VECTOR_OP_SUADD: return (v, m) ->
2880+
toBits(v.rOp((byte)0, m, (i, a, b) -> (byte) VectorMath.addSaturatingUnsigned(a, b)));
28792881
case VECTOR_OP_AND: return (v, m) ->
28802882
toBits(v.rOp((byte)-1, m, (i, a, b) -> (byte)(a & b)));
28812883
case VECTOR_OP_OR: return (v, m) ->

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,8 @@ private static ReductionOperation<IntVector, VectorMask<Integer>> reductionOpera
28612861
toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (int) VectorMath.minUnsigned(a, b)));
28622862
case VECTOR_OP_UMAX: return (v, m) ->
28632863
toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (int) VectorMath.maxUnsigned(a, b)));
2864+
case VECTOR_OP_SUADD: return (v, m) ->
2865+
toBits(v.rOp((int)0, m, (i, a, b) -> (int) VectorMath.addSaturatingUnsigned(a, b)));
28642866
case VECTOR_OP_AND: return (v, m) ->
28652867
toBits(v.rOp((int)-1, m, (i, a, b) -> (int)(a & b)));
28662868
case VECTOR_OP_OR: return (v, m) ->

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,6 +2727,8 @@ private static ReductionOperation<LongVector, VectorMask<Long>> reductionOperati
27272727
toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (long) VectorMath.minUnsigned(a, b)));
27282728
case VECTOR_OP_UMAX: return (v, m) ->
27292729
toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (long) VectorMath.maxUnsigned(a, b)));
2730+
case VECTOR_OP_SUADD: return (v, m) ->
2731+
toBits(v.rOp((long)0, m, (i, a, b) -> (long) VectorMath.addSaturatingUnsigned(a, b)));
27302732
case VECTOR_OP_AND: return (v, m) ->
27312733
toBits(v.rOp((long)-1, m, (i, a, b) -> (long)(a & b)));
27322734
case VECTOR_OP_OR: return (v, m) ->

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,8 @@ private static ReductionOperation<ShortVector, VectorMask<Short>> reductionOpera
28772877
toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (short) VectorMath.minUnsigned(a, b)));
28782878
case VECTOR_OP_UMAX: return (v, m) ->
28792879
toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (short) VectorMath.maxUnsigned(a, b)));
2880+
case VECTOR_OP_SUADD: return (v, m) ->
2881+
toBits(v.rOp((short)0, m, (i, a, b) -> (short) VectorMath.addSaturatingUnsigned(a, b)));
28802882
case VECTOR_OP_AND: return (v, m) ->
28812883
toBits(v.rOp((short)-1, m, (i, a, b) -> (short)(a & b)));
28822884
case VECTOR_OP_OR: return (v, m) ->

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,8 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
34513451
toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> ($type$) VectorMath.minUnsigned(a, b)));
34523452
case VECTOR_OP_UMAX: return (v, m) ->
34533453
toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> ($type$) VectorMath.maxUnsigned(a, b)));
3454+
case VECTOR_OP_SUADD: return (v, m) ->
3455+
toBits(v.rOp(($type$)0, m, (i, a, b) -> ($type$) VectorMath.addSaturatingUnsigned(a, b)));
34543456
#end[!FP]
34553457
#if[BITWISE]
34563458
case VECTOR_OP_AND: return (v, m) ->

test/jdk/jdk/incubator/vector/Byte128VectorTests.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,22 @@ public Object[][] byteSaturatingBinaryOpMaskProvider() {
11621162
toArray(Object[][]::new);
11631163
}
11641164

1165+
@DataProvider
1166+
public Object[][] byteSaturatingUnaryOpProvider() {
1167+
return BYTE_SATURATING_GENERATORS.stream().
1168+
map(f -> new Object[]{f}).
1169+
toArray(Object[][]::new);
1170+
}
1171+
1172+
@DataProvider
1173+
public Object[][] byteSaturatingUnaryOpMaskProvider() {
1174+
return BOOLEAN_MASK_GENERATORS.stream().
1175+
flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> {
1176+
return new Object[] {fa, fm};
1177+
})).
1178+
toArray(Object[][]::new);
1179+
}
1180+
11651181
@DataProvider
11661182
public Object[][] byteBinaryOpMaskProvider() {
11671183
return BOOLEAN_MASK_GENERATORS.stream().
@@ -4487,6 +4503,94 @@ static void allTrueByte128VectorTests(IntFunction<boolean[]> fm) {
44874503
assertReductionBoolArraysEquals(r, mask, Byte128VectorTests::allTrue);
44884504
}
44894505

4506+
static byte SUADDReduce(byte[] a, int idx) {
4507+
byte res = 0;
4508+
for (int i = idx; i < (idx + SPECIES.length()); i++) {
4509+
res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]);
4510+
}
4511+
4512+
return res;
4513+
}
4514+
4515+
static byte SUADDReduceAll(byte[] a) {
4516+
byte res = 0;
4517+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4518+
res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i));
4519+
}
4520+
4521+
return res;
4522+
}
4523+
4524+
@Test(dataProvider = "byteSaturatingUnaryOpProvider")
4525+
static void SUADDReduceByte128VectorTests(IntFunction<byte[]> fa) {
4526+
byte[] a = fa.apply(SPECIES.length());
4527+
byte[] r = fr.apply(SPECIES.length());
4528+
byte ra = 0;
4529+
4530+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4531+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4532+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4533+
r[i] = av.reduceLanes(VectorOperators.SUADD);
4534+
}
4535+
}
4536+
4537+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4538+
ra = 0;
4539+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4540+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4541+
ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD));
4542+
}
4543+
}
4544+
4545+
assertReductionArraysEquals(r, ra, a,
4546+
Byte128VectorTests::SUADDReduce, Byte128VectorTests::SUADDReduceAll);
4547+
}
4548+
4549+
static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) {
4550+
byte res = 0;
4551+
for (int i = idx; i < (idx + SPECIES.length()); i++) {
4552+
if (mask[i % SPECIES.length()])
4553+
res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]);
4554+
}
4555+
4556+
return res;
4557+
}
4558+
4559+
static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) {
4560+
byte res = 0;
4561+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4562+
res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask));
4563+
}
4564+
4565+
return res;
4566+
}
4567+
@Test(dataProvider = "byteSaturatingUnaryOpMaskProvider")
4568+
static void SUADDReduceByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4569+
byte[] a = fa.apply(SPECIES.length());
4570+
byte[] r = fr.apply(SPECIES.length());
4571+
boolean[] mask = fm.apply(SPECIES.length());
4572+
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4573+
byte ra = 0;
4574+
4575+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4576+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4577+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4578+
r[i] = av.reduceLanes(VectorOperators.SUADD, vmask);
4579+
}
4580+
}
4581+
4582+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4583+
ra = 0;
4584+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4585+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4586+
ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask));
4587+
}
4588+
}
4589+
4590+
assertReductionArraysEqualsMasked(r, ra, a, mask,
4591+
Byte128VectorTests::SUADDReduceMasked, Byte128VectorTests::SUADDReduceAllMasked);
4592+
}
4593+
44904594
@Test(dataProvider = "byteBinaryOpProvider")
44914595
static void withByte128VectorTests(IntFunction<byte []> fa, IntFunction<byte []> fb) {
44924596
byte[] a = fa.apply(SPECIES.length());

test/jdk/jdk/incubator/vector/Byte256VectorTests.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,22 @@ public Object[][] byteSaturatingBinaryOpMaskProvider() {
11621162
toArray(Object[][]::new);
11631163
}
11641164

1165+
@DataProvider
1166+
public Object[][] byteSaturatingUnaryOpProvider() {
1167+
return BYTE_SATURATING_GENERATORS.stream().
1168+
map(f -> new Object[]{f}).
1169+
toArray(Object[][]::new);
1170+
}
1171+
1172+
@DataProvider
1173+
public Object[][] byteSaturatingUnaryOpMaskProvider() {
1174+
return BOOLEAN_MASK_GENERATORS.stream().
1175+
flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> {
1176+
return new Object[] {fa, fm};
1177+
})).
1178+
toArray(Object[][]::new);
1179+
}
1180+
11651181
@DataProvider
11661182
public Object[][] byteBinaryOpMaskProvider() {
11671183
return BOOLEAN_MASK_GENERATORS.stream().
@@ -4487,6 +4503,94 @@ static void allTrueByte256VectorTests(IntFunction<boolean[]> fm) {
44874503
assertReductionBoolArraysEquals(r, mask, Byte256VectorTests::allTrue);
44884504
}
44894505

4506+
static byte SUADDReduce(byte[] a, int idx) {
4507+
byte res = 0;
4508+
for (int i = idx; i < (idx + SPECIES.length()); i++) {
4509+
res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]);
4510+
}
4511+
4512+
return res;
4513+
}
4514+
4515+
static byte SUADDReduceAll(byte[] a) {
4516+
byte res = 0;
4517+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4518+
res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i));
4519+
}
4520+
4521+
return res;
4522+
}
4523+
4524+
@Test(dataProvider = "byteSaturatingUnaryOpProvider")
4525+
static void SUADDReduceByte256VectorTests(IntFunction<byte[]> fa) {
4526+
byte[] a = fa.apply(SPECIES.length());
4527+
byte[] r = fr.apply(SPECIES.length());
4528+
byte ra = 0;
4529+
4530+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4531+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4532+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4533+
r[i] = av.reduceLanes(VectorOperators.SUADD);
4534+
}
4535+
}
4536+
4537+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4538+
ra = 0;
4539+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4540+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4541+
ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD));
4542+
}
4543+
}
4544+
4545+
assertReductionArraysEquals(r, ra, a,
4546+
Byte256VectorTests::SUADDReduce, Byte256VectorTests::SUADDReduceAll);
4547+
}
4548+
4549+
static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) {
4550+
byte res = 0;
4551+
for (int i = idx; i < (idx + SPECIES.length()); i++) {
4552+
if (mask[i % SPECIES.length()])
4553+
res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]);
4554+
}
4555+
4556+
return res;
4557+
}
4558+
4559+
static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) {
4560+
byte res = 0;
4561+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4562+
res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask));
4563+
}
4564+
4565+
return res;
4566+
}
4567+
@Test(dataProvider = "byteSaturatingUnaryOpMaskProvider")
4568+
static void SUADDReduceByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4569+
byte[] a = fa.apply(SPECIES.length());
4570+
byte[] r = fr.apply(SPECIES.length());
4571+
boolean[] mask = fm.apply(SPECIES.length());
4572+
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4573+
byte ra = 0;
4574+
4575+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4576+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4577+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4578+
r[i] = av.reduceLanes(VectorOperators.SUADD, vmask);
4579+
}
4580+
}
4581+
4582+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4583+
ra = 0;
4584+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4585+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4586+
ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask));
4587+
}
4588+
}
4589+
4590+
assertReductionArraysEqualsMasked(r, ra, a, mask,
4591+
Byte256VectorTests::SUADDReduceMasked, Byte256VectorTests::SUADDReduceAllMasked);
4592+
}
4593+
44904594
@Test(dataProvider = "byteBinaryOpProvider")
44914595
static void withByte256VectorTests(IntFunction<byte []> fa, IntFunction<byte []> fb) {
44924596
byte[] a = fa.apply(SPECIES.length());

test/jdk/jdk/incubator/vector/Byte512VectorTests.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,22 @@ public Object[][] byteSaturatingBinaryOpMaskProvider() {
11621162
toArray(Object[][]::new);
11631163
}
11641164

1165+
@DataProvider
1166+
public Object[][] byteSaturatingUnaryOpProvider() {
1167+
return BYTE_SATURATING_GENERATORS.stream().
1168+
map(f -> new Object[]{f}).
1169+
toArray(Object[][]::new);
1170+
}
1171+
1172+
@DataProvider
1173+
public Object[][] byteSaturatingUnaryOpMaskProvider() {
1174+
return BOOLEAN_MASK_GENERATORS.stream().
1175+
flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> {
1176+
return new Object[] {fa, fm};
1177+
})).
1178+
toArray(Object[][]::new);
1179+
}
1180+
11651181
@DataProvider
11661182
public Object[][] byteBinaryOpMaskProvider() {
11671183
return BOOLEAN_MASK_GENERATORS.stream().
@@ -4487,6 +4503,94 @@ static void allTrueByte512VectorTests(IntFunction<boolean[]> fm) {
44874503
assertReductionBoolArraysEquals(r, mask, Byte512VectorTests::allTrue);
44884504
}
44894505

4506+
static byte SUADDReduce(byte[] a, int idx) {
4507+
byte res = 0;
4508+
for (int i = idx; i < (idx + SPECIES.length()); i++) {
4509+
res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]);
4510+
}
4511+
4512+
return res;
4513+
}
4514+
4515+
static byte SUADDReduceAll(byte[] a) {
4516+
byte res = 0;
4517+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4518+
res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i));
4519+
}
4520+
4521+
return res;
4522+
}
4523+
4524+
@Test(dataProvider = "byteSaturatingUnaryOpProvider")
4525+
static void SUADDReduceByte512VectorTests(IntFunction<byte[]> fa) {
4526+
byte[] a = fa.apply(SPECIES.length());
4527+
byte[] r = fr.apply(SPECIES.length());
4528+
byte ra = 0;
4529+
4530+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4531+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4532+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4533+
r[i] = av.reduceLanes(VectorOperators.SUADD);
4534+
}
4535+
}
4536+
4537+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4538+
ra = 0;
4539+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4540+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4541+
ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD));
4542+
}
4543+
}
4544+
4545+
assertReductionArraysEquals(r, ra, a,
4546+
Byte512VectorTests::SUADDReduce, Byte512VectorTests::SUADDReduceAll);
4547+
}
4548+
4549+
static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) {
4550+
byte res = 0;
4551+
for (int i = idx; i < (idx + SPECIES.length()); i++) {
4552+
if (mask[i % SPECIES.length()])
4553+
res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]);
4554+
}
4555+
4556+
return res;
4557+
}
4558+
4559+
static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) {
4560+
byte res = 0;
4561+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4562+
res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask));
4563+
}
4564+
4565+
return res;
4566+
}
4567+
@Test(dataProvider = "byteSaturatingUnaryOpMaskProvider")
4568+
static void SUADDReduceByte512VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4569+
byte[] a = fa.apply(SPECIES.length());
4570+
byte[] r = fr.apply(SPECIES.length());
4571+
boolean[] mask = fm.apply(SPECIES.length());
4572+
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4573+
byte ra = 0;
4574+
4575+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4576+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4577+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4578+
r[i] = av.reduceLanes(VectorOperators.SUADD, vmask);
4579+
}
4580+
}
4581+
4582+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
4583+
ra = 0;
4584+
for (int i = 0; i < a.length; i += SPECIES.length()) {
4585+
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4586+
ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask));
4587+
}
4588+
}
4589+
4590+
assertReductionArraysEqualsMasked(r, ra, a, mask,
4591+
Byte512VectorTests::SUADDReduceMasked, Byte512VectorTests::SUADDReduceAllMasked);
4592+
}
4593+
44904594
@Test(dataProvider = "byteBinaryOpProvider")
44914595
static void withByte512VectorTests(IntFunction<byte []> fa, IntFunction<byte []> fb) {
44924596
byte[] a = fa.apply(SPECIES.length());

0 commit comments

Comments
 (0)