From 0225372e0b44e8cfc58fa3d442f08ea269a9dcc1 Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Wed, 18 Dec 2024 17:23:51 +0000 Subject: [PATCH] 8346174: UMAX/UMIN are missing from XXXVector::reductionOperations Reviewed-by: jbhateja Backport-of: 31c3b191745b5c97ae4e757323355fb9831da9fe --- src/hotspot/share/opto/vectorIntrinsics.cpp | 3 +- .../jdk/incubator/vector/ByteVector.java | 4 + .../jdk/incubator/vector/IntVector.java | 4 + .../jdk/incubator/vector/LongVector.java | 4 + .../jdk/incubator/vector/ShortVector.java | 4 + .../incubator/vector/X-Vector.java.template | 6 + .../incubator/vector/Byte128VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Byte256VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Byte512VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Byte64VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/ByteMaxVectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Int128VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Int256VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Int512VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Int64VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/IntMaxVectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Long128VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Long256VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Long512VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Long64VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/LongMaxVectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Short128VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Short256VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Short512VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/Short64VectorTests.java | 178 ++++++++++++++++++ .../incubator/vector/ShortMaxVectorTests.java | 178 ++++++++++++++++++ test/jdk/jdk/incubator/vector/gen-template.sh | 2 + 27 files changed, 3586 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/opto/vectorIntrinsics.cpp b/src/hotspot/share/opto/vectorIntrinsics.cpp index 3d20b22a175..63bbc0443b6 100644 --- a/src/hotspot/share/opto/vectorIntrinsics.cpp +++ b/src/hotspot/share/opto/vectorIntrinsics.cpp @@ -1637,8 +1637,9 @@ bool LibraryCallKit::inline_vector_reduction() { int opc = VectorSupport::vop2ideal(opr->get_con(), elem_bt); int sopc = ReductionNode::opcode(opc, elem_bt); + // Ensure reduction operation for lanewise operation // When using mask, mask use type needs to be VecMaskUseLoad. - if (!arch_supports_vector(sopc, num_elem, elem_bt, is_masked_op ? VecMaskUseLoad : VecMaskNotUsed)) { + if (sopc == opc || !arch_supports_vector(sopc, num_elem, elem_bt, is_masked_op ? VecMaskUseLoad : VecMaskNotUsed)) { log_if_needed(" ** not supported: arity=1 op=%d/reduce vlen=%d etype=%s is_masked_op=%d", sopc, num_elem, type2name(elem_bt), is_masked_op ? 1 : 0); return false; 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 346b00eda5e..b578390e50f 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 @@ -2869,6 +2869,10 @@ private static ReductionOperation> reductionOperati toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (byte) Math.min(a, b))); case VECTOR_OP_MAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (byte) Math.max(a, b))); + case VECTOR_OP_UMIN: return (v, m) -> + 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_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 390c8026083..9a46db33de8 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 @@ -2854,6 +2854,10 @@ private static ReductionOperation> reductionOpera toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (int) Math.min(a, b))); case VECTOR_OP_MAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (int) Math.max(a, b))); + case VECTOR_OP_UMIN: return (v, m) -> + 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_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 43fedc2693b..8963e52cab1 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 @@ -2720,6 +2720,10 @@ private static ReductionOperation> reductionOperati toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (long) Math.min(a, b))); case VECTOR_OP_MAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (long) Math.max(a, b))); + case VECTOR_OP_UMIN: return (v, m) -> + 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_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 552967d82e7..88965835e9b 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 @@ -2870,6 +2870,10 @@ private static ReductionOperation> reductionOpera toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> (short) Math.min(a, b))); case VECTOR_OP_MAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> (short) Math.max(a, b))); + case VECTOR_OP_UMIN: return (v, m) -> + 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_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 7eb1d9810b1..de9c74130cb 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 @@ -3375,6 +3375,12 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { toBits(v.rOp(MAX_OR_INF, m, (i, a, b) -> ($type$) Math.min(a, b))); case VECTOR_OP_MAX: return (v, m) -> toBits(v.rOp(MIN_OR_INF, m, (i, a, b) -> ($type$) Math.max(a, b))); +#if[!FP] + case VECTOR_OP_UMIN: return (v, m) -> + 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))); +#end[!FP] #if[BITWISE] case VECTOR_OP_AND: return (v, m) -> toBits(v.rOp(($type$)-1, m, (i, a, b) -> ($type$)(a & b))); diff --git a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java index 36a140c474a..7c8265169f4 100644 --- a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java @@ -3912,6 +3912,184 @@ static void MAXReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio Byte128VectorTests::MAXReduceMasked, Byte128VectorTests::MAXReduceAllMasked); } + static byte UMINReduce(byte[] a, int idx) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAll(byte[] a) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceByte128VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte128VectorTests::UMINReduce, Byte128VectorTests::UMINReduceAll); + } + + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMINReduceByte128VectorTestsMasked(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 = Byte.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte128VectorTests::UMINReduceMasked, Byte128VectorTests::UMINReduceAllMasked); + } + + static byte UMAXReduce(byte[] a, int idx) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAll(byte[] a) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceByte128VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte128VectorTests::UMAXReduce, Byte128VectorTests::UMAXReduceAll); + } + + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMAXReduceByte128VectorTestsMasked(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 = Byte.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte128VectorTests::UMAXReduceMasked, Byte128VectorTests::UMAXReduceAllMasked); + } + static byte FIRST_NONZEROReduce(byte[] a, int idx) { byte res = (byte) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java index 0ad567b5ee4..0fbbca79f5d 100644 --- a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java @@ -3912,6 +3912,184 @@ static void MAXReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio Byte256VectorTests::MAXReduceMasked, Byte256VectorTests::MAXReduceAllMasked); } + static byte UMINReduce(byte[] a, int idx) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAll(byte[] a) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceByte256VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte256VectorTests::UMINReduce, Byte256VectorTests::UMINReduceAll); + } + + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMINReduceByte256VectorTestsMasked(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 = Byte.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte256VectorTests::UMINReduceMasked, Byte256VectorTests::UMINReduceAllMasked); + } + + static byte UMAXReduce(byte[] a, int idx) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAll(byte[] a) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceByte256VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte256VectorTests::UMAXReduce, Byte256VectorTests::UMAXReduceAll); + } + + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMAXReduceByte256VectorTestsMasked(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 = Byte.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte256VectorTests::UMAXReduceMasked, Byte256VectorTests::UMAXReduceAllMasked); + } + static byte FIRST_NONZEROReduce(byte[] a, int idx) { byte res = (byte) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java index 0edc66dfccc..a17e621a0e6 100644 --- a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java @@ -3912,6 +3912,184 @@ static void MAXReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio Byte512VectorTests::MAXReduceMasked, Byte512VectorTests::MAXReduceAllMasked); } + static byte UMINReduce(byte[] a, int idx) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAll(byte[] a) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceByte512VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte512VectorTests::UMINReduce, Byte512VectorTests::UMINReduceAll); + } + + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMINReduceByte512VectorTestsMasked(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 = Byte.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte512VectorTests::UMINReduceMasked, Byte512VectorTests::UMINReduceAllMasked); + } + + static byte UMAXReduce(byte[] a, int idx) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAll(byte[] a) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceByte512VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte512VectorTests::UMAXReduce, Byte512VectorTests::UMAXReduceAll); + } + + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMAXReduceByte512VectorTestsMasked(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 = Byte.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte512VectorTests::UMAXReduceMasked, Byte512VectorTests::UMAXReduceAllMasked); + } + static byte FIRST_NONZEROReduce(byte[] a, int idx) { byte res = (byte) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java index 98c8382c526..58f1d6295a0 100644 --- a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java @@ -3912,6 +3912,184 @@ static void MAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunction Byte64VectorTests::MAXReduceMasked, Byte64VectorTests::MAXReduceAllMasked); } + static byte UMINReduce(byte[] a, int idx) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAll(byte[] a) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceByte64VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte64VectorTests::UMINReduce, Byte64VectorTests::UMINReduceAll); + } + + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMINReduceByte64VectorTestsMasked(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 = Byte.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte64VectorTests::UMINReduceMasked, Byte64VectorTests::UMINReduceAllMasked); + } + + static byte UMAXReduce(byte[] a, int idx) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAll(byte[] a) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceByte64VectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Byte64VectorTests::UMAXReduce, Byte64VectorTests::UMAXReduceAll); + } + + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMAXReduceByte64VectorTestsMasked(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 = Byte.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Byte64VectorTests::UMAXReduceMasked, Byte64VectorTests::UMAXReduceAllMasked); + } + static byte FIRST_NONZEROReduce(byte[] a, int idx) { byte res = (byte) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java index 2d9d49f32ad..9aaf1b6db95 100644 --- a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java @@ -3917,6 +3917,184 @@ static void MAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio ByteMaxVectorTests::MAXReduceMasked, ByteMaxVectorTests::MAXReduceAllMasked); } + static byte UMINReduce(byte[] a, int idx) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAll(byte[] a) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceByteMaxVectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + ByteMaxVectorTests::UMINReduce, ByteMaxVectorTests::UMINReduceAll); + } + + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMINReduceByteMaxVectorTestsMasked(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 = Byte.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + ByteMaxVectorTests::UMINReduceMasked, ByteMaxVectorTests::UMINReduceAllMasked); + } + + static byte UMAXReduce(byte[] a, int idx) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAll(byte[] a) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceByteMaxVectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + byte ra = Byte.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + ByteMaxVectorTests::UMAXReduce, ByteMaxVectorTests::UMAXReduceAll); + } + + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (byte) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { + byte res = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "byteUnaryOpMaskProvider") + static void UMAXReduceByteMaxVectorTestsMasked(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 = Byte.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Byte.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + ByteMaxVectorTests::UMAXReduceMasked, ByteMaxVectorTests::UMAXReduceAllMasked); + } + static byte FIRST_NONZEROReduce(byte[] a, int idx) { byte res = (byte) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Int128VectorTests.java b/test/jdk/jdk/incubator/vector/Int128VectorTests.java index 028e757e853..4f8f296c519 100644 --- a/test/jdk/jdk/incubator/vector/Int128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int128VectorTests.java @@ -3956,6 +3956,184 @@ static void MAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< Int128VectorTests::MAXReduceMasked, Int128VectorTests::MAXReduceAllMasked); } + static int UMINReduce(int[] a, int idx) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAll(int[] a) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceInt128VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int128VectorTests::UMINReduce, Int128VectorTests::UMINReduceAll); + } + + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMINReduceInt128VectorTestsMasked(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 = Integer.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int128VectorTests::UMINReduceMasked, Int128VectorTests::UMINReduceAllMasked); + } + + static int UMAXReduce(int[] a, int idx) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAll(int[] a) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceInt128VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int128VectorTests::UMAXReduce, Int128VectorTests::UMAXReduceAll); + } + + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMAXReduceInt128VectorTestsMasked(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 = Integer.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int128VectorTests::UMAXReduceMasked, Int128VectorTests::UMAXReduceAllMasked); + } + static int FIRST_NONZEROReduce(int[] a, int idx) { int res = (int) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Int256VectorTests.java b/test/jdk/jdk/incubator/vector/Int256VectorTests.java index 6dab8a39873..312227c54e1 100644 --- a/test/jdk/jdk/incubator/vector/Int256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int256VectorTests.java @@ -3956,6 +3956,184 @@ static void MAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< Int256VectorTests::MAXReduceMasked, Int256VectorTests::MAXReduceAllMasked); } + static int UMINReduce(int[] a, int idx) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAll(int[] a) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceInt256VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int256VectorTests::UMINReduce, Int256VectorTests::UMINReduceAll); + } + + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMINReduceInt256VectorTestsMasked(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 = Integer.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int256VectorTests::UMINReduceMasked, Int256VectorTests::UMINReduceAllMasked); + } + + static int UMAXReduce(int[] a, int idx) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAll(int[] a) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceInt256VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int256VectorTests::UMAXReduce, Int256VectorTests::UMAXReduceAll); + } + + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMAXReduceInt256VectorTestsMasked(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 = Integer.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int256VectorTests::UMAXReduceMasked, Int256VectorTests::UMAXReduceAllMasked); + } + static int FIRST_NONZEROReduce(int[] a, int idx) { int res = (int) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Int512VectorTests.java b/test/jdk/jdk/incubator/vector/Int512VectorTests.java index 0c86655ff22..3e5b51180b6 100644 --- a/test/jdk/jdk/incubator/vector/Int512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int512VectorTests.java @@ -3956,6 +3956,184 @@ static void MAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< Int512VectorTests::MAXReduceMasked, Int512VectorTests::MAXReduceAllMasked); } + static int UMINReduce(int[] a, int idx) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAll(int[] a) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceInt512VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int512VectorTests::UMINReduce, Int512VectorTests::UMINReduceAll); + } + + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMINReduceInt512VectorTestsMasked(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 = Integer.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int512VectorTests::UMINReduceMasked, Int512VectorTests::UMINReduceAllMasked); + } + + static int UMAXReduce(int[] a, int idx) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAll(int[] a) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceInt512VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int512VectorTests::UMAXReduce, Int512VectorTests::UMAXReduceAll); + } + + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMAXReduceInt512VectorTestsMasked(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 = Integer.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int512VectorTests::UMAXReduceMasked, Int512VectorTests::UMAXReduceAllMasked); + } + static int FIRST_NONZEROReduce(int[] a, int idx) { int res = (int) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Int64VectorTests.java b/test/jdk/jdk/incubator/vector/Int64VectorTests.java index b2cb3698f62..fccad11d4d6 100644 --- a/test/jdk/jdk/incubator/vector/Int64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int64VectorTests.java @@ -3956,6 +3956,184 @@ static void MAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int64VectorTests::UMINReduce, Int64VectorTests::UMINReduceAll); + } + + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMINReduceInt64VectorTestsMasked(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 = Integer.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int64VectorTests::UMINReduceMasked, Int64VectorTests::UMINReduceAllMasked); + } + + static int UMAXReduce(int[] a, int idx) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAll(int[] a) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceInt64VectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Int64VectorTests::UMAXReduce, Int64VectorTests::UMAXReduceAll); + } + + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMAXReduceInt64VectorTestsMasked(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 = Integer.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Int64VectorTests::UMAXReduceMasked, Int64VectorTests::UMAXReduceAllMasked); + } + static int FIRST_NONZEROReduce(int[] a, int idx) { int res = (int) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java index fc0f6c1c139..3254c2fb86c 100644 --- a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java @@ -3961,6 +3961,184 @@ static void MAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< IntMaxVectorTests::MAXReduceMasked, IntMaxVectorTests::MAXReduceAllMasked); } + static int UMINReduce(int[] a, int idx) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAll(int[] a) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceIntMaxVectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + IntMaxVectorTests::UMINReduce, IntMaxVectorTests::UMINReduceAll); + } + + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static int UMINReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMINReduceIntMaxVectorTestsMasked(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 = Integer.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + IntMaxVectorTests::UMINReduceMasked, IntMaxVectorTests::UMINReduceAllMasked); + } + + static int UMAXReduce(int[] a, int idx) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAll(int[] a) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceIntMaxVectorTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int[] r = fr.apply(SPECIES.length()); + int ra = Integer.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + IntMaxVectorTests::UMAXReduce, IntMaxVectorTests::UMAXReduceAll); + } + + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (int) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static int UMAXReduceAllMasked(int[] a, boolean[] mask) { + int res = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "intUnaryOpMaskProvider") + static void UMAXReduceIntMaxVectorTestsMasked(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 = Integer.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Integer.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + ra = (int) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + IntMaxVectorTests::UMAXReduceMasked, IntMaxVectorTests::UMAXReduceAllMasked); + } + static int FIRST_NONZEROReduce(int[] a, int idx) { int res = (int) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Long128VectorTests.java b/test/jdk/jdk/incubator/vector/Long128VectorTests.java index 3694128877a..09fdc3c1979 100644 --- a/test/jdk/jdk/incubator/vector/Long128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long128VectorTests.java @@ -3978,6 +3978,184 @@ static void MAXReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio Long128VectorTests::MAXReduceMasked, Long128VectorTests::MAXReduceAllMasked); } + static long UMINReduce(long[] a, int idx) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAll(long[] a) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceLong128VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long128VectorTests::UMINReduce, Long128VectorTests::UMINReduceAll); + } + + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMINReduceLong128VectorTestsMasked(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 = Long.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long128VectorTests::UMINReduceMasked, Long128VectorTests::UMINReduceAllMasked); + } + + static long UMAXReduce(long[] a, int idx) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAll(long[] a) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceLong128VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long128VectorTests::UMAXReduce, Long128VectorTests::UMAXReduceAll); + } + + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMAXReduceLong128VectorTestsMasked(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 = Long.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long128VectorTests::UMAXReduceMasked, Long128VectorTests::UMAXReduceAllMasked); + } + static long FIRST_NONZEROReduce(long[] a, int idx) { long res = (long) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Long256VectorTests.java b/test/jdk/jdk/incubator/vector/Long256VectorTests.java index 1fc441680fd..7dd0da772ed 100644 --- a/test/jdk/jdk/incubator/vector/Long256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long256VectorTests.java @@ -3978,6 +3978,184 @@ static void MAXReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio Long256VectorTests::MAXReduceMasked, Long256VectorTests::MAXReduceAllMasked); } + static long UMINReduce(long[] a, int idx) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAll(long[] a) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceLong256VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long256VectorTests::UMINReduce, Long256VectorTests::UMINReduceAll); + } + + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMINReduceLong256VectorTestsMasked(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 = Long.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long256VectorTests::UMINReduceMasked, Long256VectorTests::UMINReduceAllMasked); + } + + static long UMAXReduce(long[] a, int idx) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAll(long[] a) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceLong256VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long256VectorTests::UMAXReduce, Long256VectorTests::UMAXReduceAll); + } + + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMAXReduceLong256VectorTestsMasked(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 = Long.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long256VectorTests::UMAXReduceMasked, Long256VectorTests::UMAXReduceAllMasked); + } + static long FIRST_NONZEROReduce(long[] a, int idx) { long res = (long) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Long512VectorTests.java b/test/jdk/jdk/incubator/vector/Long512VectorTests.java index 81d538a55c4..360e822e121 100644 --- a/test/jdk/jdk/incubator/vector/Long512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long512VectorTests.java @@ -3978,6 +3978,184 @@ static void MAXReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio Long512VectorTests::MAXReduceMasked, Long512VectorTests::MAXReduceAllMasked); } + static long UMINReduce(long[] a, int idx) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAll(long[] a) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceLong512VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long512VectorTests::UMINReduce, Long512VectorTests::UMINReduceAll); + } + + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMINReduceLong512VectorTestsMasked(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 = Long.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long512VectorTests::UMINReduceMasked, Long512VectorTests::UMINReduceAllMasked); + } + + static long UMAXReduce(long[] a, int idx) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAll(long[] a) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceLong512VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long512VectorTests::UMAXReduce, Long512VectorTests::UMAXReduceAll); + } + + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMAXReduceLong512VectorTestsMasked(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 = Long.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long512VectorTests::UMAXReduceMasked, Long512VectorTests::UMAXReduceAllMasked); + } + static long FIRST_NONZEROReduce(long[] a, int idx) { long res = (long) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Long64VectorTests.java b/test/jdk/jdk/incubator/vector/Long64VectorTests.java index 1d85fc510d9..31f6fafea7c 100644 --- a/test/jdk/jdk/incubator/vector/Long64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long64VectorTests.java @@ -3978,6 +3978,184 @@ static void MAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunction Long64VectorTests::MAXReduceMasked, Long64VectorTests::MAXReduceAllMasked); } + static long UMINReduce(long[] a, int idx) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAll(long[] a) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceLong64VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long64VectorTests::UMINReduce, Long64VectorTests::UMINReduceAll); + } + + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMINReduceLong64VectorTestsMasked(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 = Long.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long64VectorTests::UMINReduceMasked, Long64VectorTests::UMINReduceAllMasked); + } + + static long UMAXReduce(long[] a, int idx) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAll(long[] a) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceLong64VectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Long64VectorTests::UMAXReduce, Long64VectorTests::UMAXReduceAll); + } + + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMAXReduceLong64VectorTestsMasked(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 = Long.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Long64VectorTests::UMAXReduceMasked, Long64VectorTests::UMAXReduceAllMasked); + } + static long FIRST_NONZEROReduce(long[] a, int idx) { long res = (long) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java index bae5b968d79..a3cacbe3251 100644 --- a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java @@ -3983,6 +3983,184 @@ static void MAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio LongMaxVectorTests::MAXReduceMasked, LongMaxVectorTests::MAXReduceAllMasked); } + static long UMINReduce(long[] a, int idx) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAll(long[] a) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceLongMaxVectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + LongMaxVectorTests::UMINReduce, LongMaxVectorTests::UMINReduceAll); + } + + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static long UMINReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMINReduceLongMaxVectorTestsMasked(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 = Long.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + LongMaxVectorTests::UMINReduceMasked, LongMaxVectorTests::UMINReduceAllMasked); + } + + static long UMAXReduce(long[] a, int idx) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAll(long[] a) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceLongMaxVectorTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long[] r = fr.apply(SPECIES.length()); + long ra = Long.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + LongMaxVectorTests::UMAXReduce, LongMaxVectorTests::UMAXReduceAll); + } + + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (long) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static long UMAXReduceAllMasked(long[] a, boolean[] mask) { + long res = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "longUnaryOpMaskProvider") + static void UMAXReduceLongMaxVectorTestsMasked(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 = Long.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Long.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + ra = (long) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + LongMaxVectorTests::UMAXReduceMasked, LongMaxVectorTests::UMAXReduceAllMasked); + } + static long FIRST_NONZEROReduce(long[] a, int idx) { long res = (long) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Short128VectorTests.java b/test/jdk/jdk/incubator/vector/Short128VectorTests.java index 2d6a1fd0a5f..967418181bf 100644 --- a/test/jdk/jdk/incubator/vector/Short128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short128VectorTests.java @@ -3903,6 +3903,184 @@ static void MAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunct Short128VectorTests::MAXReduceMasked, Short128VectorTests::MAXReduceAllMasked); } + static short UMINReduce(short[] a, int idx) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAll(short[] a) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceShort128VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short128VectorTests::UMINReduce, Short128VectorTests::UMINReduceAll); + } + + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMINReduceShort128VectorTestsMasked(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 = Short.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short128VectorTests::UMINReduceMasked, Short128VectorTests::UMINReduceAllMasked); + } + + static short UMAXReduce(short[] a, int idx) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAll(short[] a) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceShort128VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short128VectorTests::UMAXReduce, Short128VectorTests::UMAXReduceAll); + } + + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMAXReduceShort128VectorTestsMasked(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 = Short.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short128VectorTests::UMAXReduceMasked, Short128VectorTests::UMAXReduceAllMasked); + } + static short FIRST_NONZEROReduce(short[] a, int idx) { short res = (short) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Short256VectorTests.java b/test/jdk/jdk/incubator/vector/Short256VectorTests.java index fa8ec1f31b6..2386d89e53b 100644 --- a/test/jdk/jdk/incubator/vector/Short256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short256VectorTests.java @@ -3903,6 +3903,184 @@ static void MAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunct Short256VectorTests::MAXReduceMasked, Short256VectorTests::MAXReduceAllMasked); } + static short UMINReduce(short[] a, int idx) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAll(short[] a) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceShort256VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short256VectorTests::UMINReduce, Short256VectorTests::UMINReduceAll); + } + + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMINReduceShort256VectorTestsMasked(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 = Short.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short256VectorTests::UMINReduceMasked, Short256VectorTests::UMINReduceAllMasked); + } + + static short UMAXReduce(short[] a, int idx) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAll(short[] a) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceShort256VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short256VectorTests::UMAXReduce, Short256VectorTests::UMAXReduceAll); + } + + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMAXReduceShort256VectorTestsMasked(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 = Short.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short256VectorTests::UMAXReduceMasked, Short256VectorTests::UMAXReduceAllMasked); + } + static short FIRST_NONZEROReduce(short[] a, int idx) { short res = (short) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Short512VectorTests.java b/test/jdk/jdk/incubator/vector/Short512VectorTests.java index ba6a7dadebd..cb9fc1830b9 100644 --- a/test/jdk/jdk/incubator/vector/Short512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short512VectorTests.java @@ -3903,6 +3903,184 @@ static void MAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunct Short512VectorTests::MAXReduceMasked, Short512VectorTests::MAXReduceAllMasked); } + static short UMINReduce(short[] a, int idx) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAll(short[] a) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceShort512VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short512VectorTests::UMINReduce, Short512VectorTests::UMINReduceAll); + } + + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMINReduceShort512VectorTestsMasked(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 = Short.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short512VectorTests::UMINReduceMasked, Short512VectorTests::UMINReduceAllMasked); + } + + static short UMAXReduce(short[] a, int idx) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAll(short[] a) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceShort512VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short512VectorTests::UMAXReduce, Short512VectorTests::UMAXReduceAll); + } + + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMAXReduceShort512VectorTestsMasked(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 = Short.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short512VectorTests::UMAXReduceMasked, Short512VectorTests::UMAXReduceAllMasked); + } + static short FIRST_NONZEROReduce(short[] a, int idx) { short res = (short) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/Short64VectorTests.java b/test/jdk/jdk/incubator/vector/Short64VectorTests.java index 939da11d53a..64bb5f52329 100644 --- a/test/jdk/jdk/incubator/vector/Short64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short64VectorTests.java @@ -3903,6 +3903,184 @@ static void MAXReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti Short64VectorTests::MAXReduceMasked, Short64VectorTests::MAXReduceAllMasked); } + static short UMINReduce(short[] a, int idx) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAll(short[] a) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceShort64VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short64VectorTests::UMINReduce, Short64VectorTests::UMINReduceAll); + } + + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMINReduceShort64VectorTestsMasked(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 = Short.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short64VectorTests::UMINReduceMasked, Short64VectorTests::UMINReduceAllMasked); + } + + static short UMAXReduce(short[] a, int idx) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAll(short[] a) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceShort64VectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + Short64VectorTests::UMAXReduce, Short64VectorTests::UMAXReduceAll); + } + + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMAXReduceShort64VectorTestsMasked(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 = Short.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + Short64VectorTests::UMAXReduceMasked, Short64VectorTests::UMAXReduceAllMasked); + } + static short FIRST_NONZEROReduce(short[] a, int idx) { short res = (short) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java index ade78e1f3f5..6445443b9d6 100644 --- a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java @@ -3908,6 +3908,184 @@ static void MAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct ShortMaxVectorTests::MAXReduceMasked, ShortMaxVectorTests::MAXReduceAllMasked); } + static short UMINReduce(short[] a, int idx) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAll(short[] a) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceShortMaxVectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MAX_VALUE; + + 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.UMIN); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); + } + } + + assertReductionArraysEquals(r, ra, a, + ShortMaxVectorTests::UMINReduce, ShortMaxVectorTests::UMINReduceAll); + } + + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.minUnsigned(res, a[i]); + } + + return res; + } + + static short UMINReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMINReduceShortMaxVectorTestsMasked(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 = Short.MAX_VALUE; + + 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.UMIN, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MAX_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + ShortMaxVectorTests::UMINReduceMasked, ShortMaxVectorTests::UMINReduceAllMasked); + } + + static short UMAXReduce(short[] a, int idx) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAll(short[] a) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceShortMaxVectorTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + short ra = Short.MIN_VALUE; + + 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.UMAX); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); + } + } + + assertReductionArraysEquals(r, ra, a, + ShortMaxVectorTests::UMAXReduce, ShortMaxVectorTests::UMAXReduceAll); + } + + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = idx; i < (idx + SPECIES.length()); i++) { + if (mask[i % SPECIES.length()]) + res = (short) VectorMath.maxUnsigned(res, a[i]); + } + + return res; + } + + static short UMAXReduceAllMasked(short[] a, boolean[] mask) { + short res = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); + } + + return res; + } + + @Test(dataProvider = "shortUnaryOpMaskProvider") + static void UMAXReduceShortMaxVectorTestsMasked(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 = Short.MIN_VALUE; + + 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.UMAX, vmask); + } + } + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = Short.MIN_VALUE; + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); + } + } + + assertReductionArraysEqualsMasked(r, ra, a, mask, + ShortMaxVectorTests::UMAXReduceMasked, ShortMaxVectorTests::UMAXReduceAllMasked); + } + static short FIRST_NONZEROReduce(short[] a, int idx) { short res = (short) 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { diff --git a/test/jdk/jdk/incubator/vector/gen-template.sh b/test/jdk/jdk/incubator/vector/gen-template.sh index 232de04ba7c..06e89b824cd 100644 --- a/test/jdk/jdk/incubator/vector/gen-template.sh +++ b/test/jdk/jdk/incubator/vector/gen-template.sh @@ -484,6 +484,8 @@ gen_reduction_op "ADD" "+" "" "0" gen_reduction_op "MUL" "*" "" "1" gen_reduction_op_func "MIN" "(\$type\$) Math.min" "" "\$Wideboxtype\$.\$MaxValue\$" gen_reduction_op_func "MAX" "(\$type\$) Math.max" "" "\$Wideboxtype\$.\$MinValue\$" +gen_reduction_op_func "UMIN" "(\$type\$) VectorMath.minUnsigned" "BITWISE" "\$Wideboxtype\$.\$MaxValue\$" +gen_reduction_op_func "UMAX" "(\$type\$) VectorMath.maxUnsigned" "BITWISE" "\$Wideboxtype\$.\$MinValue\$" gen_reduction_op_func "FIRST_NONZERO" "firstNonZero" "" "(\$type\$) 0" # Boolean reductions.