diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java index c788b4e1617..08406fef518 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java @@ -2876,6 +2876,8 @@ public abstract class ByteVector extends AbstractVector { toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (byte) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (byte) VectorMath.maxUnsigned(a, b))); + case VECTOR_OP_SUADD: return (v, m) -> + toBits(v.rOp((byte)0, m, (i, a, b) -> (byte) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> toBits(v.rOp((byte)-1, m, (i, a, b) -> (byte)(a & b))); case VECTOR_OP_OR: return (v, m) -> diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java index 85aac460f8b..43356b9ea6c 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java @@ -2861,6 +2861,8 @@ public abstract class IntVector extends AbstractVector { toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (int) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (int) VectorMath.maxUnsigned(a, b))); + case VECTOR_OP_SUADD: return (v, m) -> + toBits(v.rOp((int)0, m, (i, a, b) -> (int) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> toBits(v.rOp((int)-1, m, (i, a, b) -> (int)(a & b))); case VECTOR_OP_OR: return (v, m) -> diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java index abd86863165..8947343ff30 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java @@ -2727,6 +2727,8 @@ public abstract class LongVector extends AbstractVector { toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (long) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (long) VectorMath.maxUnsigned(a, b))); + case VECTOR_OP_SUADD: return (v, m) -> + toBits(v.rOp((long)0, m, (i, a, b) -> (long) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> toBits(v.rOp((long)-1, m, (i, a, b) -> (long)(a & b))); case VECTOR_OP_OR: return (v, m) -> diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java index 464b792e0f7..e222c6d25f3 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java @@ -2877,6 +2877,8 @@ public abstract class ShortVector extends AbstractVector { toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (short) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (short) VectorMath.maxUnsigned(a, b))); + case VECTOR_OP_SUADD: return (v, m) -> + toBits(v.rOp((short)0, m, (i, a, b) -> (short) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> toBits(v.rOp((short)-1, m, (i, a, b) -> (short)(a & b))); case VECTOR_OP_OR: return (v, m) -> diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template index 3fa7d1dab6c..f7d987fd280 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template @@ -3451,6 +3451,8 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> ($type$) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> ($type$) VectorMath.maxUnsigned(a, b))); + case VECTOR_OP_SUADD: return (v, m) -> + toBits(v.rOp(($type$)0, m, (i, a, b) -> ($type$) VectorMath.addSaturatingUnsigned(a, b))); #end[!FP] #if[BITWISE] case VECTOR_OP_AND: return (v, m) -> diff --git a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java index fd017ce183b..bea4d541987 100644 --- a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java @@ -1162,6 +1162,22 @@ public class Byte128VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] byteSaturatingUnaryOpProvider() { + return BYTE_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] byteSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] byteBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4487,6 +4503,94 @@ public class Byte128VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Byte128VectorTests::allTrue); } + static byte SUADDReduce(byte[] a, int idx) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAll(byte[] a) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceByte128VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte128VectorTests::SUADDReduce, Byte128VectorTests::SUADDReduceAll); + } + + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "byteSaturatingUnaryOpMaskProvider") + static void SUADDReduceByte128VectorTestsMasked(IntFunction fa, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte128VectorTests::SUADDReduceMasked, Byte128VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "byteBinaryOpProvider") static void withByte128VectorTests(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java index 17ab56f2540..be5b3cf6198 100644 --- a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java @@ -1162,6 +1162,22 @@ public class Byte256VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] byteSaturatingUnaryOpProvider() { + return BYTE_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] byteSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] byteBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4487,6 +4503,94 @@ public class Byte256VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Byte256VectorTests::allTrue); } + static byte SUADDReduce(byte[] a, int idx) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAll(byte[] a) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceByte256VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte256VectorTests::SUADDReduce, Byte256VectorTests::SUADDReduceAll); + } + + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "byteSaturatingUnaryOpMaskProvider") + static void SUADDReduceByte256VectorTestsMasked(IntFunction fa, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte256VectorTests::SUADDReduceMasked, Byte256VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "byteBinaryOpProvider") static void withByte256VectorTests(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java index 4c43b995c2f..0fd68b6f712 100644 --- a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java @@ -1162,6 +1162,22 @@ public class Byte512VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] byteSaturatingUnaryOpProvider() { + return BYTE_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] byteSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] byteBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4487,6 +4503,94 @@ public class Byte512VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Byte512VectorTests::allTrue); } + static byte SUADDReduce(byte[] a, int idx) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAll(byte[] a) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceByte512VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte512VectorTests::SUADDReduce, Byte512VectorTests::SUADDReduceAll); + } + + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "byteSaturatingUnaryOpMaskProvider") + static void SUADDReduceByte512VectorTestsMasked(IntFunction fa, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte512VectorTests::SUADDReduceMasked, Byte512VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "byteBinaryOpProvider") static void withByte512VectorTests(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java index d30afe30fe2..112b2e56b6f 100644 --- a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java @@ -1162,6 +1162,22 @@ public class Byte64VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] byteSaturatingUnaryOpProvider() { + return BYTE_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] byteSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] byteBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4487,6 +4503,94 @@ public class Byte64VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Byte64VectorTests::allTrue); } + static byte SUADDReduce(byte[] a, int idx) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAll(byte[] a) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceByte64VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte64VectorTests::SUADDReduce, Byte64VectorTests::SUADDReduceAll); + } + + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "byteSaturatingUnaryOpMaskProvider") + static void SUADDReduceByte64VectorTestsMasked(IntFunction fa, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte64VectorTests::SUADDReduceMasked, Byte64VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "byteBinaryOpProvider") static void withByte64VectorTests(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java index 8738191f5ca..435cacc013e 100644 --- a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java @@ -1167,6 +1167,22 @@ public class ByteMaxVectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] byteSaturatingUnaryOpProvider() { + return BYTE_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] byteSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] byteBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4492,6 +4508,94 @@ public class ByteMaxVectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, ByteMaxVectorTests::allTrue); } + static byte SUADDReduce(byte[] a, int idx) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAll(byte[] a) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceByteMaxVectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + ByteMaxVectorTests::SUADDReduce, ByteMaxVectorTests::SUADDReduceAll); + } + + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { + byte res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "byteSaturatingUnaryOpMaskProvider") + static void SUADDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + byte ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + ByteMaxVectorTests::SUADDReduceMasked, ByteMaxVectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "byteBinaryOpProvider") static void withByteMaxVectorTests(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int128VectorTests.java b/test/jdk/jdk/incubator/vector/Int128VectorTests.java index 0bd77cc1008..d6bca96ea6e 100644 --- a/test/jdk/jdk/incubator/vector/Int128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int128VectorTests.java @@ -1152,6 +1152,22 @@ public class Int128VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] intSaturatingUnaryOpProvider() { + return INT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] intSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> INT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] intBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4531,6 +4547,94 @@ public class Int128VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Int128VectorTests::allTrue); } + static int SUADDReduce(int[] a, int idx) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAll(int[] a) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceInt128VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int128VectorTests::SUADDReduce, Int128VectorTests::SUADDReduceAll); + } + + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAllMasked(int[] a, boolean[] mask) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "intSaturatingUnaryOpMaskProvider") + static void SUADDReduceInt128VectorTestsMasked(IntFunction fa, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int128VectorTests::SUADDReduceMasked, Int128VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "intBinaryOpProvider") static void withInt128VectorTests(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int256VectorTests.java b/test/jdk/jdk/incubator/vector/Int256VectorTests.java index a4a0a2bd88e..ac98217b714 100644 --- a/test/jdk/jdk/incubator/vector/Int256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int256VectorTests.java @@ -1152,6 +1152,22 @@ public class Int256VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] intSaturatingUnaryOpProvider() { + return INT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] intSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> INT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] intBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4531,6 +4547,94 @@ public class Int256VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Int256VectorTests::allTrue); } + static int SUADDReduce(int[] a, int idx) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAll(int[] a) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceInt256VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int256VectorTests::SUADDReduce, Int256VectorTests::SUADDReduceAll); + } + + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAllMasked(int[] a, boolean[] mask) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "intSaturatingUnaryOpMaskProvider") + static void SUADDReduceInt256VectorTestsMasked(IntFunction fa, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int256VectorTests::SUADDReduceMasked, Int256VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "intBinaryOpProvider") static void withInt256VectorTests(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int512VectorTests.java b/test/jdk/jdk/incubator/vector/Int512VectorTests.java index 0679b410e59..b56236db322 100644 --- a/test/jdk/jdk/incubator/vector/Int512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int512VectorTests.java @@ -1152,6 +1152,22 @@ public class Int512VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] intSaturatingUnaryOpProvider() { + return INT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] intSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> INT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] intBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4531,6 +4547,94 @@ public class Int512VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Int512VectorTests::allTrue); } + static int SUADDReduce(int[] a, int idx) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAll(int[] a) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceInt512VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int512VectorTests::SUADDReduce, Int512VectorTests::SUADDReduceAll); + } + + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAllMasked(int[] a, boolean[] mask) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "intSaturatingUnaryOpMaskProvider") + static void SUADDReduceInt512VectorTestsMasked(IntFunction fa, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int512VectorTests::SUADDReduceMasked, Int512VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "intBinaryOpProvider") static void withInt512VectorTests(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int64VectorTests.java b/test/jdk/jdk/incubator/vector/Int64VectorTests.java index c77e246473b..f87a0eb458c 100644 --- a/test/jdk/jdk/incubator/vector/Int64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int64VectorTests.java @@ -1152,6 +1152,22 @@ public class Int64VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] intSaturatingUnaryOpProvider() { + return INT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] intSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> INT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] intBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4531,6 +4547,94 @@ public class Int64VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Int64VectorTests::allTrue); } + static int SUADDReduce(int[] a, int idx) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAll(int[] a) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceInt64VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int64VectorTests::SUADDReduce, Int64VectorTests::SUADDReduceAll); + } + + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAllMasked(int[] a, boolean[] mask) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "intSaturatingUnaryOpMaskProvider") + static void SUADDReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int64VectorTests::SUADDReduceMasked, Int64VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "intBinaryOpProvider") static void withInt64VectorTests(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java index 4f7338c50cb..c61aab0013e 100644 --- a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java @@ -1157,6 +1157,22 @@ public class IntMaxVectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] intSaturatingUnaryOpProvider() { + return INT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] intSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> INT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] intBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4536,6 +4552,94 @@ public class IntMaxVectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, IntMaxVectorTests::allTrue); } + static int SUADDReduce(int[] a, int idx) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAll(int[] a) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceIntMaxVectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + IntMaxVectorTests::SUADDReduce, IntMaxVectorTests::SUADDReduceAll); + } + + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { + int res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static int SUADDReduceAllMasked(int[] a, boolean[] mask) { + int res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "intSaturatingUnaryOpMaskProvider") + static void SUADDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + int ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + IntMaxVectorTests::SUADDReduceMasked, IntMaxVectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "intBinaryOpProvider") static void withIntMaxVectorTests(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long128VectorTests.java b/test/jdk/jdk/incubator/vector/Long128VectorTests.java index 01cac6a505e..a8cf38c003a 100644 --- a/test/jdk/jdk/incubator/vector/Long128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long128VectorTests.java @@ -1142,6 +1142,22 @@ public class Long128VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] longSaturatingUnaryOpProvider() { + return LONG_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] longSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> LONG_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] longBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4553,6 +4569,94 @@ public class Long128VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Long128VectorTests::allTrue); } + static long SUADDReduce(long[] a, int idx) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAll(long[] a) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceLong128VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long128VectorTests::SUADDReduce, Long128VectorTests::SUADDReduceAll); + } + + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAllMasked(long[] a, boolean[] mask) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "longSaturatingUnaryOpMaskProvider") + static void SUADDReduceLong128VectorTestsMasked(IntFunction fa, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long128VectorTests::SUADDReduceMasked, Long128VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "longBinaryOpProvider") static void withLong128VectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long256VectorTests.java b/test/jdk/jdk/incubator/vector/Long256VectorTests.java index 9e571c3cbe9..a394a59699f 100644 --- a/test/jdk/jdk/incubator/vector/Long256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long256VectorTests.java @@ -1142,6 +1142,22 @@ public class Long256VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] longSaturatingUnaryOpProvider() { + return LONG_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] longSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> LONG_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] longBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4553,6 +4569,94 @@ public class Long256VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Long256VectorTests::allTrue); } + static long SUADDReduce(long[] a, int idx) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAll(long[] a) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceLong256VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long256VectorTests::SUADDReduce, Long256VectorTests::SUADDReduceAll); + } + + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAllMasked(long[] a, boolean[] mask) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "longSaturatingUnaryOpMaskProvider") + static void SUADDReduceLong256VectorTestsMasked(IntFunction fa, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long256VectorTests::SUADDReduceMasked, Long256VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "longBinaryOpProvider") static void withLong256VectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long512VectorTests.java b/test/jdk/jdk/incubator/vector/Long512VectorTests.java index 5cb3cc32a68..2f12ea98399 100644 --- a/test/jdk/jdk/incubator/vector/Long512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long512VectorTests.java @@ -1142,6 +1142,22 @@ public class Long512VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] longSaturatingUnaryOpProvider() { + return LONG_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] longSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> LONG_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] longBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4553,6 +4569,94 @@ public class Long512VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Long512VectorTests::allTrue); } + static long SUADDReduce(long[] a, int idx) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAll(long[] a) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceLong512VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long512VectorTests::SUADDReduce, Long512VectorTests::SUADDReduceAll); + } + + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAllMasked(long[] a, boolean[] mask) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "longSaturatingUnaryOpMaskProvider") + static void SUADDReduceLong512VectorTestsMasked(IntFunction fa, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long512VectorTests::SUADDReduceMasked, Long512VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "longBinaryOpProvider") static void withLong512VectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long64VectorTests.java b/test/jdk/jdk/incubator/vector/Long64VectorTests.java index d5595395b0a..0fda0abed58 100644 --- a/test/jdk/jdk/incubator/vector/Long64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long64VectorTests.java @@ -1142,6 +1142,22 @@ public class Long64VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] longSaturatingUnaryOpProvider() { + return LONG_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] longSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> LONG_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] longBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4553,6 +4569,94 @@ public class Long64VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Long64VectorTests::allTrue); } + static long SUADDReduce(long[] a, int idx) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAll(long[] a) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceLong64VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long64VectorTests::SUADDReduce, Long64VectorTests::SUADDReduceAll); + } + + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAllMasked(long[] a, boolean[] mask) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "longSaturatingUnaryOpMaskProvider") + static void SUADDReduceLong64VectorTestsMasked(IntFunction fa, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long64VectorTests::SUADDReduceMasked, Long64VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "longBinaryOpProvider") static void withLong64VectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java index cec3e0756b2..7aa2bc4c510 100644 --- a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java @@ -1147,6 +1147,22 @@ public class LongMaxVectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] longSaturatingUnaryOpProvider() { + return LONG_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] longSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> LONG_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] longBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4558,6 +4574,94 @@ public class LongMaxVectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, LongMaxVectorTests::allTrue); } + static long SUADDReduce(long[] a, int idx) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAll(long[] a) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceLongMaxVectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + LongMaxVectorTests::SUADDReduce, LongMaxVectorTests::SUADDReduceAll); + } + + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { + long res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static long SUADDReduceAllMasked(long[] a, boolean[] mask) { + long res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "longSaturatingUnaryOpMaskProvider") + static void SUADDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + long ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + LongMaxVectorTests::SUADDReduceMasked, LongMaxVectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "longBinaryOpProvider") static void withLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short128VectorTests.java b/test/jdk/jdk/incubator/vector/Short128VectorTests.java index 1ce486eb709..5f4c54bb708 100644 --- a/test/jdk/jdk/incubator/vector/Short128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short128VectorTests.java @@ -1152,6 +1152,22 @@ public class Short128VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] shortSaturatingUnaryOpProvider() { + return SHORT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] shortSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> SHORT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] shortBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4478,6 +4494,94 @@ public class Short128VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Short128VectorTests::allTrue); } + static short SUADDReduce(short[] a, int idx) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAll(short[] a) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceShort128VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short128VectorTests::SUADDReduce, Short128VectorTests::SUADDReduceAll); + } + + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAllMasked(short[] a, boolean[] mask) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "shortSaturatingUnaryOpMaskProvider") + static void SUADDReduceShort128VectorTestsMasked(IntFunction fa, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short128VectorTests::SUADDReduceMasked, Short128VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "shortBinaryOpProvider") static void withShort128VectorTests(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short256VectorTests.java b/test/jdk/jdk/incubator/vector/Short256VectorTests.java index 8361c59923f..88986575f60 100644 --- a/test/jdk/jdk/incubator/vector/Short256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short256VectorTests.java @@ -1152,6 +1152,22 @@ public class Short256VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] shortSaturatingUnaryOpProvider() { + return SHORT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] shortSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> SHORT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] shortBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4478,6 +4494,94 @@ public class Short256VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Short256VectorTests::allTrue); } + static short SUADDReduce(short[] a, int idx) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAll(short[] a) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceShort256VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short256VectorTests::SUADDReduce, Short256VectorTests::SUADDReduceAll); + } + + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAllMasked(short[] a, boolean[] mask) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "shortSaturatingUnaryOpMaskProvider") + static void SUADDReduceShort256VectorTestsMasked(IntFunction fa, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short256VectorTests::SUADDReduceMasked, Short256VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "shortBinaryOpProvider") static void withShort256VectorTests(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short512VectorTests.java b/test/jdk/jdk/incubator/vector/Short512VectorTests.java index a9c1a5eb7ed..0f474375a47 100644 --- a/test/jdk/jdk/incubator/vector/Short512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short512VectorTests.java @@ -1152,6 +1152,22 @@ public class Short512VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] shortSaturatingUnaryOpProvider() { + return SHORT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] shortSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> SHORT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] shortBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4478,6 +4494,94 @@ public class Short512VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Short512VectorTests::allTrue); } + static short SUADDReduce(short[] a, int idx) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAll(short[] a) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceShort512VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short512VectorTests::SUADDReduce, Short512VectorTests::SUADDReduceAll); + } + + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAllMasked(short[] a, boolean[] mask) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "shortSaturatingUnaryOpMaskProvider") + static void SUADDReduceShort512VectorTestsMasked(IntFunction fa, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short512VectorTests::SUADDReduceMasked, Short512VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "shortBinaryOpProvider") static void withShort512VectorTests(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short64VectorTests.java b/test/jdk/jdk/incubator/vector/Short64VectorTests.java index d10b4ca7196..4b99ed6d84c 100644 --- a/test/jdk/jdk/incubator/vector/Short64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short64VectorTests.java @@ -1152,6 +1152,22 @@ public class Short64VectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] shortSaturatingUnaryOpProvider() { + return SHORT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] shortSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> SHORT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] shortBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4478,6 +4494,94 @@ public class Short64VectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, Short64VectorTests::allTrue); } + static short SUADDReduce(short[] a, int idx) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAll(short[] a) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceShort64VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short64VectorTests::SUADDReduce, Short64VectorTests::SUADDReduceAll); + } + + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAllMasked(short[] a, boolean[] mask) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "shortSaturatingUnaryOpMaskProvider") + static void SUADDReduceShort64VectorTestsMasked(IntFunction fa, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short64VectorTests::SUADDReduceMasked, Short64VectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "shortBinaryOpProvider") static void withShort64VectorTests(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java index cca15c4e941..2bb3b9c1557 100644 --- a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java @@ -1157,6 +1157,22 @@ public class ShortMaxVectorTests extends AbstractVectorTest { toArray(Object[][]::new); } + @DataProvider + public Object[][] shortSaturatingUnaryOpProvider() { + return SHORT_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] shortSaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> SHORT_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + @DataProvider public Object[][] shortBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). @@ -4483,6 +4499,94 @@ public class ShortMaxVectorTests extends AbstractVectorTest { assertReductionBoolArraysEquals(r, mask, ShortMaxVectorTests::allTrue); } + static short SUADDReduce(short[] a, int idx) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAll(short[] a) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceShortMaxVectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + } + } + + assertReductionArraysEquals(r, ra, a, + ShortMaxVectorTests::SUADDReduce, ShortMaxVectorTests::SUADDReduceAll); + } + + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { + short res = 0; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); + } + + return res; + } + + static short SUADDReduceAllMasked(short[] a, boolean[] mask) { + short res = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); + } + + return res; + } + @Test(dataProvider = "shortSaturatingUnaryOpMaskProvider") + static void SUADDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + short ra = 0; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = 0; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + ShortMaxVectorTests::SUADDReduceMasked, ShortMaxVectorTests::SUADDReduceAllMasked); + } + @Test(dataProvider = "shortBinaryOpProvider") static void withShortMaxVectorTests(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/gen-template.sh b/test/jdk/jdk/incubator/vector/gen-template.sh index 71dc4a1ef0a..a6f794a5559 100644 --- a/test/jdk/jdk/incubator/vector/gen-template.sh +++ b/test/jdk/jdk/incubator/vector/gen-template.sh @@ -66,6 +66,8 @@ reduction_op="Reduction-op" reduction_op_func="Reduction-op-func" reduction_op_masked="Reduction-Masked-op" reduction_op_masked_func="Reduction-Masked-op-func" +reduction_saturating_op="SaturatingReduction-op" +reduction_saturating_op_masked="SaturatingReduction-Masked-op" unary_math_template="Unary-op-math" binary_math_template="Binary-op-math" binary_math_broadcast_template="Binary-Broadcast-op-math" @@ -377,6 +379,13 @@ function gen_bool_reduction_op { gen_op_tmpl $bool_reduction_scalar "$@" gen_op_tmpl $bool_reduction_template "$@" } +function gen_saturating_reduction_op { + echo "Generating saturating reduction op $1 ($2)..." + gen_op_tmpl $reduction_scalar_func "$@" + gen_op_tmpl $reduction_saturating_op "$@" + gen_op_tmpl $reduction_scalar_masked_func "$@" + gen_op_tmpl $reduction_saturating_op_masked "$@" +} function gen_with_op { echo "Generating with op $1 ($2)..." @@ -513,6 +522,9 @@ gen_reduction_op_func "FIRST_NONZERO" "firstNonZero" "" "(\$type\$) 0" gen_bool_reduction_op "anyTrue" "|" "BITWISE" "false" gen_bool_reduction_op "allTrue" "\&" "BITWISE" "true" +# Saturating reductions. +gen_saturating_reduction_op "SUADD" "(\$type\$) VectorMath.addSaturatingUnsigned" "BITWISE" "0" + #Insert gen_with_op "withLane" "" "" "" diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template new file mode 100644 index 00000000000..bf03a4d0430 --- /dev/null +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template @@ -0,0 +1,21 @@ + $type$[] a = fa.apply(SPECIES.length()); + $type$[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask<$Wideboxtype$> vmask = VectorMask.fromArray(SPECIES, mask, 0); + $type$ ra = [[TEST_INIT]]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = [[TEST_INIT]]; + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); + ra = [[TEST_OP]](ra, av.reduceLanes(VectorOperators.[[TEST]], vmask)); + } + } + diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template new file mode 100644 index 00000000000..7082ff0795e --- /dev/null +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template @@ -0,0 +1,19 @@ + $type$[] a = fa.apply(SPECIES.length()); + $type$[] r = fr.apply(SPECIES.length()); + $type$ ra = [[TEST_INIT]]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); + r[i] = av.reduceLanes(VectorOperators.[[TEST]]); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = [[TEST_INIT]]; + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); + ra = [[TEST_OP]](ra, av.reduceLanes(VectorOperators.[[TEST]])); + } + } + diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-Masked-op.template new file mode 100644 index 00000000000..f9e965128b1 --- /dev/null +++ b/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-Masked-op.template @@ -0,0 +1,6 @@ + @Test(dataProvider = "$type$SaturatingUnaryOpMaskProvider") + static void [[TEST]]Reduce$vectorteststype$Masked(IntFunction<$type$[]> fa, IntFunction fm) { +[[KERNEL]] + assertReductionArraysEqualsMasked(r, ra, a, mask, + $vectorteststype$::[[TEST]]ReduceMasked, $vectorteststype$::[[TEST]]ReduceAllMasked); + } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-op.template new file mode 100644 index 00000000000..fdd9e47167e --- /dev/null +++ b/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-op.template @@ -0,0 +1,7 @@ + + @Test(dataProvider = "$type$SaturatingUnaryOpProvider") + static void [[TEST]]Reduce$vectorteststype$(IntFunction<$type$[]> fa) { +[[KERNEL]] + assertReductionArraysEquals(r, ra, a, + $vectorteststype$::[[TEST]]Reduce, $vectorteststype$::[[TEST]]ReduceAll); + } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-header.template b/test/jdk/jdk/incubator/vector/templates/Unit-header.template index d50267318f5..33c52f18c1c 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-header.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-header.template @@ -1430,6 +1430,22 @@ relativeError)); toArray(Object[][]::new); } + @DataProvider + public Object[][] $type$SaturatingUnaryOpProvider() { + return $TYPE$_SATURATING_GENERATORS.stream(). + map(f -> new Object[]{f}). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] $type$SaturatingUnaryOpMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fm -> $TYPE$_SATURATING_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm}; + })). + toArray(Object[][]::new); + } + #end[!FP] @DataProvider public Object[][] $type$BinaryOpMaskProvider() {