From 4fb63a3624ab3f5e7e96faff0782d6df7280088f Mon Sep 17 00:00:00 2001 From: erfang Date: Tue, 2 Dec 2025 01:58:12 +0000 Subject: [PATCH 1/3] 8372978: [VectorAPI] Fix incorrect identity values in UMIN/UMAX reductions The original implementation of UMIN/UMAX reductions in JDK-8346174 used incorrect identity values in the Java implementation and test code. Problem: -------- UMIN was using MAX_OR_INF (signed maximum value) as the identity: - Byte.MAX_VALUE (127) instead of max unsigned byte (255) - Short.MAX_VALUE (32767) instead of max unsigned short (65535) - Integer.MAX_VALUE instead of max unsigned int (-1) - Long.MAX_VALUE instead of max unsigned long (-1) UMAX was using MIN_OR_INF (signed minimum value) as the identity: - Byte.MIN_VALUE (-128) instead of 0 - Short.MIN_VALUE (-32768) instead of 0 - Integer.MIN_VALUE instead of 0 - Long.MIN_VALUE instead of 0 This caused incorrect result. For example: UMAX([42,42,...,42]) returned 128 instead of 42 Solution: --------- Use correct unsigned identity values: - UMIN: ($type$)-1 (maximum unsigned value) - UMAX: ($type$)0 (minimum unsigned value) Changes: -------- - X-Vector.java.template: Fixed identity values in reductionOperations - gen-template.sh: Fixed identity values for test code generation - templates/Unit-header.template: Updated copyright year to 2025 - Regenerated all Vector classes and test files Testing: -------- All types (byte/short/int/long) now return correct results in both interpreter mode (-Xint) and compiled mode. --- .../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 | 4 +-- .../incubator/vector/Byte128VectorTests.java | 34 +++++++++---------- .../incubator/vector/Byte256VectorTests.java | 34 +++++++++---------- .../incubator/vector/Byte512VectorTests.java | 34 +++++++++---------- .../incubator/vector/Byte64VectorTests.java | 34 +++++++++---------- .../incubator/vector/ByteMaxVectorTests.java | 34 +++++++++---------- .../vector/Double128VectorTests.java | 2 +- .../vector/Double256VectorTests.java | 2 +- .../vector/Double512VectorTests.java | 2 +- .../incubator/vector/Double64VectorTests.java | 2 +- .../vector/DoubleMaxVectorTests.java | 2 +- .../incubator/vector/Float128VectorTests.java | 2 +- .../incubator/vector/Float256VectorTests.java | 2 +- .../incubator/vector/Float512VectorTests.java | 2 +- .../incubator/vector/Float64VectorTests.java | 2 +- .../incubator/vector/FloatMaxVectorTests.java | 2 +- .../incubator/vector/Int128VectorTests.java | 34 +++++++++---------- .../incubator/vector/Int256VectorTests.java | 34 +++++++++---------- .../incubator/vector/Int512VectorTests.java | 34 +++++++++---------- .../incubator/vector/Int64VectorTests.java | 34 +++++++++---------- .../incubator/vector/IntMaxVectorTests.java | 34 +++++++++---------- .../incubator/vector/Long128VectorTests.java | 34 +++++++++---------- .../incubator/vector/Long256VectorTests.java | 34 +++++++++---------- .../incubator/vector/Long512VectorTests.java | 34 +++++++++---------- .../incubator/vector/Long64VectorTests.java | 34 +++++++++---------- .../incubator/vector/LongMaxVectorTests.java | 34 +++++++++---------- .../incubator/vector/Short128VectorTests.java | 34 +++++++++---------- .../incubator/vector/Short256VectorTests.java | 34 +++++++++---------- .../incubator/vector/Short512VectorTests.java | 34 +++++++++---------- .../incubator/vector/Short64VectorTests.java | 34 +++++++++---------- .../incubator/vector/ShortMaxVectorTests.java | 34 +++++++++---------- test/jdk/jdk/incubator/vector/gen-template.sh | 6 ++-- .../vector/templates/Unit-header.template | 2 +- 37 files changed, 364 insertions(+), 364 deletions(-) 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 08406fef518df..26d2e4c53e6e5 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 @@ -2873,9 +2873,9 @@ private static ReductionOperation> reductionOperati 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))); + toBits(v.rOp((byte)-1, 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))); + toBits(v.rOp((byte)0, m, (i, a, b) -> (byte) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp((byte)0, m, (i, a, b) -> (byte) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> 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 43356b9ea6c9e..aaf06994335c8 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 @@ -2858,9 +2858,9 @@ private static ReductionOperation> reductionOpera 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))); + toBits(v.rOp((int)-1, 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))); + toBits(v.rOp((int)0, m, (i, a, b) -> (int) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp((int)0, m, (i, a, b) -> (int) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> 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 8947343ff306b..65cdc941bf634 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 @@ -2724,9 +2724,9 @@ private static ReductionOperation> reductionOperati 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))); + toBits(v.rOp((long)-1, 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))); + toBits(v.rOp((long)0, m, (i, a, b) -> (long) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp((long)0, m, (i, a, b) -> (long) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> 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 e222c6d25f390..d5f9d9b489775 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 @@ -2874,9 +2874,9 @@ private static ReductionOperation> reductionOpera 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))); + toBits(v.rOp((short)-1, 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))); + toBits(v.rOp((short)0, m, (i, a, b) -> (short) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp((short)0, m, (i, a, b) -> (short) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> 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 f7d987fd280a0..df34c6f4e4ce1 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 @@ -3448,9 +3448,9 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { 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))); + toBits(v.rOp(($type$)-1, 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))); + toBits(v.rOp(($type$)0, m, (i, a, b) -> ($type$) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp(($type$)0, m, (i, a, b) -> ($type$) VectorMath.addSaturatingUnsigned(a, b))); #end[!FP] diff --git a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java index bea4d541987e3..056c515af0668 100644 --- a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4189,7 +4189,7 @@ static void MAXReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio } static byte UMINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4198,7 +4198,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4210,7 +4210,7 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4220,7 +4220,7 @@ static void UMINReduceByte128VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4232,7 +4232,7 @@ static void UMINReduceByte128VectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4242,7 +4242,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4256,7 +4256,7 @@ static void UMINReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4266,7 +4266,7 @@ static void UMINReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4278,7 +4278,7 @@ static void UMINReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti } static byte UMAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4287,7 +4287,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4299,7 +4299,7 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4309,7 +4309,7 @@ static void UMAXReduceByte128VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); @@ -4321,7 +4321,7 @@ static void UMAXReduceByte128VectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4331,7 +4331,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4345,7 +4345,7 @@ static void UMAXReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4355,7 +4355,7 @@ static void UMAXReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java index be5b3cf6198cf..8a04e0ee5b103 100644 --- a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4189,7 +4189,7 @@ static void MAXReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio } static byte UMINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4198,7 +4198,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4210,7 +4210,7 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4220,7 +4220,7 @@ static void UMINReduceByte256VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4232,7 +4232,7 @@ static void UMINReduceByte256VectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4242,7 +4242,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4256,7 +4256,7 @@ static void UMINReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4266,7 +4266,7 @@ static void UMINReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4278,7 +4278,7 @@ static void UMINReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti } static byte UMAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4287,7 +4287,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4299,7 +4299,7 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4309,7 +4309,7 @@ static void UMAXReduceByte256VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); @@ -4321,7 +4321,7 @@ static void UMAXReduceByte256VectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4331,7 +4331,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4345,7 +4345,7 @@ static void UMAXReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4355,7 +4355,7 @@ static void UMAXReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java index 0fd68b6f712d7..96b78a3f02744 100644 --- a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4189,7 +4189,7 @@ static void MAXReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio } static byte UMINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4198,7 +4198,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4210,7 +4210,7 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4220,7 +4220,7 @@ static void UMINReduceByte512VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4232,7 +4232,7 @@ static void UMINReduceByte512VectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4242,7 +4242,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4256,7 +4256,7 @@ static void UMINReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4266,7 +4266,7 @@ static void UMINReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4278,7 +4278,7 @@ static void UMINReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti } static byte UMAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4287,7 +4287,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4299,7 +4299,7 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4309,7 +4309,7 @@ static void UMAXReduceByte512VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); @@ -4321,7 +4321,7 @@ static void UMAXReduceByte512VectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4331,7 +4331,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4345,7 +4345,7 @@ static void UMAXReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4355,7 +4355,7 @@ static void UMAXReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java index 112b2e56b6f58..a231e8fff18bd 100644 --- a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4189,7 +4189,7 @@ static void MAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunction } static byte UMINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4198,7 +4198,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4210,7 +4210,7 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4220,7 +4220,7 @@ static void UMINReduceByte64VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4232,7 +4232,7 @@ static void UMINReduceByte64VectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4242,7 +4242,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4256,7 +4256,7 @@ static void UMINReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4266,7 +4266,7 @@ static void UMINReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4278,7 +4278,7 @@ static void UMINReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio } static byte UMAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4287,7 +4287,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4299,7 +4299,7 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4309,7 +4309,7 @@ static void UMAXReduceByte64VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); @@ -4321,7 +4321,7 @@ static void UMAXReduceByte64VectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4331,7 +4331,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4345,7 +4345,7 @@ static void UMAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4355,7 +4355,7 @@ static void UMAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java index 435cacc013e2a..f0bba029109aa 100644 --- a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4194,7 +4194,7 @@ static void MAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio } static byte UMINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4203,7 +4203,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4215,7 +4215,7 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4225,7 +4225,7 @@ static void UMINReduceByteMaxVectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4237,7 +4237,7 @@ static void UMINReduceByteMaxVectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4247,7 +4247,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = (byte)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4261,7 +4261,7 @@ static void UMINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = (byte)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4271,7 +4271,7 @@ static void UMINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MAX_VALUE; + ra = (byte)-1; 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)); @@ -4283,7 +4283,7 @@ static void UMINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti } static byte UMAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4292,7 +4292,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4304,7 +4304,7 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4314,7 +4314,7 @@ static void UMAXReduceByteMaxVectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); @@ -4326,7 +4326,7 @@ static void UMAXReduceByteMaxVectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4336,7 +4336,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = (byte)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4350,7 +4350,7 @@ static void UMAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = (byte)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4360,7 +4360,7 @@ static void UMAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Byte.MIN_VALUE; + ra = (byte)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Double128VectorTests.java b/test/jdk/jdk/incubator/vector/Double128VectorTests.java index f15ce88ddb897..681b6c50093b2 100644 --- a/test/jdk/jdk/incubator/vector/Double128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double128VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/Double256VectorTests.java b/test/jdk/jdk/incubator/vector/Double256VectorTests.java index e6c3662e0ad6e..3fa8e7e2911ce 100644 --- a/test/jdk/jdk/incubator/vector/Double256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double256VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/Double512VectorTests.java b/test/jdk/jdk/incubator/vector/Double512VectorTests.java index 7c37c9878e8f6..96e72112bacb0 100644 --- a/test/jdk/jdk/incubator/vector/Double512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double512VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/Double64VectorTests.java b/test/jdk/jdk/incubator/vector/Double64VectorTests.java index 85b96288b379b..dc4488a5367ca 100644 --- a/test/jdk/jdk/incubator/vector/Double64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double64VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java index 7245990d66c1e..8898a098d3fe0 100644 --- a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/Float128VectorTests.java b/test/jdk/jdk/incubator/vector/Float128VectorTests.java index c4f4ed1b9661a..dd31439bc45d9 100644 --- a/test/jdk/jdk/incubator/vector/Float128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float128VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/Float256VectorTests.java b/test/jdk/jdk/incubator/vector/Float256VectorTests.java index 87cbc165d599e..49dfe5746ef20 100644 --- a/test/jdk/jdk/incubator/vector/Float256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float256VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/Float512VectorTests.java b/test/jdk/jdk/incubator/vector/Float512VectorTests.java index beb9561d88215..b52cd0cf69619 100644 --- a/test/jdk/jdk/incubator/vector/Float512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float512VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/Float64VectorTests.java b/test/jdk/jdk/incubator/vector/Float64VectorTests.java index ee630abd8e052..260ee21a647db 100644 --- a/test/jdk/jdk/incubator/vector/Float64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float64VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java index 41e4d6e4a5de3..0137364cf4e1c 100644 --- a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/jdk/incubator/vector/Int128VectorTests.java b/test/jdk/jdk/incubator/vector/Int128VectorTests.java index d6bca96ea6e7c..0e5161604b394 100644 --- a/test/jdk/jdk/incubator/vector/Int128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int128VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4233,7 +4233,7 @@ static void MAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< } static int UMINReduce(int[] a, int idx) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.minUnsigned(res, a[i]); } @@ -4242,7 +4242,7 @@ static int UMINReduce(int[] a, int idx) { } static int UMINReduceAll(int[] a) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4254,7 +4254,7 @@ static int UMINReduceAll(int[] a) { static void UMINReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4264,7 +4264,7 @@ static void UMINReduceInt128VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4276,7 +4276,7 @@ static void UMINReduceInt128VectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4286,7 +4286,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4300,7 +4300,7 @@ static void UMINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4310,7 +4310,7 @@ static void UMINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4322,7 +4322,7 @@ static void UMINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction } static int UMAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4331,7 +4331,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4343,7 +4343,7 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4353,7 +4353,7 @@ static void UMAXReduceInt128VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); @@ -4365,7 +4365,7 @@ static void UMAXReduceInt128VectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4375,7 +4375,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4389,7 +4389,7 @@ static void UMAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4399,7 +4399,7 @@ static void UMAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Int256VectorTests.java b/test/jdk/jdk/incubator/vector/Int256VectorTests.java index ac98217b71451..2966537052744 100644 --- a/test/jdk/jdk/incubator/vector/Int256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int256VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4233,7 +4233,7 @@ static void MAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< } static int UMINReduce(int[] a, int idx) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.minUnsigned(res, a[i]); } @@ -4242,7 +4242,7 @@ static int UMINReduce(int[] a, int idx) { } static int UMINReduceAll(int[] a) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4254,7 +4254,7 @@ static int UMINReduceAll(int[] a) { static void UMINReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4264,7 +4264,7 @@ static void UMINReduceInt256VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4276,7 +4276,7 @@ static void UMINReduceInt256VectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4286,7 +4286,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4300,7 +4300,7 @@ static void UMINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4310,7 +4310,7 @@ static void UMINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4322,7 +4322,7 @@ static void UMINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction } static int UMAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4331,7 +4331,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4343,7 +4343,7 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4353,7 +4353,7 @@ static void UMAXReduceInt256VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); @@ -4365,7 +4365,7 @@ static void UMAXReduceInt256VectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4375,7 +4375,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4389,7 +4389,7 @@ static void UMAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4399,7 +4399,7 @@ static void UMAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Int512VectorTests.java b/test/jdk/jdk/incubator/vector/Int512VectorTests.java index b56236db322e5..f6af7d0ac0f30 100644 --- a/test/jdk/jdk/incubator/vector/Int512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int512VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4233,7 +4233,7 @@ static void MAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< } static int UMINReduce(int[] a, int idx) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.minUnsigned(res, a[i]); } @@ -4242,7 +4242,7 @@ static int UMINReduce(int[] a, int idx) { } static int UMINReduceAll(int[] a) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4254,7 +4254,7 @@ static int UMINReduceAll(int[] a) { static void UMINReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4264,7 +4264,7 @@ static void UMINReduceInt512VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4276,7 +4276,7 @@ static void UMINReduceInt512VectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4286,7 +4286,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4300,7 +4300,7 @@ static void UMINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4310,7 +4310,7 @@ static void UMINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4322,7 +4322,7 @@ static void UMINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction } static int UMAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4331,7 +4331,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4343,7 +4343,7 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4353,7 +4353,7 @@ static void UMAXReduceInt512VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); @@ -4365,7 +4365,7 @@ static void UMAXReduceInt512VectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4375,7 +4375,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4389,7 +4389,7 @@ static void UMAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4399,7 +4399,7 @@ static void UMAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Int64VectorTests.java b/test/jdk/jdk/incubator/vector/Int64VectorTests.java index f87a0eb458c53..8a3d69f7a7e26 100644 --- a/test/jdk/jdk/incubator/vector/Int64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int64VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4233,7 +4233,7 @@ static void MAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4264,7 +4264,7 @@ static void UMINReduceInt64VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4276,7 +4276,7 @@ static void UMINReduceInt64VectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4286,7 +4286,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4300,7 +4300,7 @@ static void UMINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4310,7 +4310,7 @@ static void UMINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4322,7 +4322,7 @@ static void UMINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< } static int UMAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4331,7 +4331,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4343,7 +4343,7 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceInt64VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4353,7 +4353,7 @@ static void UMAXReduceInt64VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); @@ -4365,7 +4365,7 @@ static void UMAXReduceInt64VectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4375,7 +4375,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4389,7 +4389,7 @@ static void UMAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4399,7 +4399,7 @@ static void UMAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java index c61aab0013ee5..76c204b860d7c 100644 --- a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4238,7 +4238,7 @@ static void MAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< } static int UMINReduce(int[] a, int idx) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.minUnsigned(res, a[i]); } @@ -4247,7 +4247,7 @@ static int UMINReduce(int[] a, int idx) { } static int UMINReduceAll(int[] a) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4259,7 +4259,7 @@ static int UMINReduceAll(int[] a) { static void UMINReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4269,7 +4269,7 @@ static void UMINReduceIntMaxVectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4281,7 +4281,7 @@ static void UMINReduceIntMaxVectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4291,7 +4291,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = (int)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4305,7 +4305,7 @@ static void UMINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = (int)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4315,7 +4315,7 @@ static void UMINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MAX_VALUE; + ra = (int)-1; 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)); @@ -4327,7 +4327,7 @@ static void UMINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction } static int UMAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4336,7 +4336,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4348,7 +4348,7 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4358,7 +4358,7 @@ static void UMAXReduceIntMaxVectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); @@ -4370,7 +4370,7 @@ static void UMAXReduceIntMaxVectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4380,7 +4380,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = (int)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4394,7 +4394,7 @@ static void UMAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = (int)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4404,7 +4404,7 @@ static void UMAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Integer.MIN_VALUE; + ra = (int)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Long128VectorTests.java b/test/jdk/jdk/incubator/vector/Long128VectorTests.java index a8cf38c003a16..7a4f0c464a53d 100644 --- a/test/jdk/jdk/incubator/vector/Long128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long128VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4255,7 +4255,7 @@ static void MAXReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio } static long UMINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4264,7 +4264,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4276,7 +4276,7 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4286,7 +4286,7 @@ static void UMINReduceLong128VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4298,7 +4298,7 @@ static void UMINReduceLong128VectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4308,7 +4308,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4322,7 +4322,7 @@ static void UMINReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4332,7 +4332,7 @@ static void UMINReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4344,7 +4344,7 @@ static void UMINReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti } static long UMAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4353,7 +4353,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4365,7 +4365,7 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4375,7 +4375,7 @@ static void UMAXReduceLong128VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); @@ -4387,7 +4387,7 @@ static void UMAXReduceLong128VectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4397,7 +4397,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4411,7 +4411,7 @@ static void UMAXReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4421,7 +4421,7 @@ static void UMAXReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Long256VectorTests.java b/test/jdk/jdk/incubator/vector/Long256VectorTests.java index a394a59699fd6..41b705c338c4d 100644 --- a/test/jdk/jdk/incubator/vector/Long256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long256VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4255,7 +4255,7 @@ static void MAXReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio } static long UMINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4264,7 +4264,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4276,7 +4276,7 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4286,7 +4286,7 @@ static void UMINReduceLong256VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4298,7 +4298,7 @@ static void UMINReduceLong256VectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4308,7 +4308,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4322,7 +4322,7 @@ static void UMINReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4332,7 +4332,7 @@ static void UMINReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4344,7 +4344,7 @@ static void UMINReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti } static long UMAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4353,7 +4353,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4365,7 +4365,7 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4375,7 +4375,7 @@ static void UMAXReduceLong256VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); @@ -4387,7 +4387,7 @@ static void UMAXReduceLong256VectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4397,7 +4397,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4411,7 +4411,7 @@ static void UMAXReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4421,7 +4421,7 @@ static void UMAXReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Long512VectorTests.java b/test/jdk/jdk/incubator/vector/Long512VectorTests.java index 2f12ea983997f..2e1a14cb4d24f 100644 --- a/test/jdk/jdk/incubator/vector/Long512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long512VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4255,7 +4255,7 @@ static void MAXReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio } static long UMINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4264,7 +4264,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4276,7 +4276,7 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4286,7 +4286,7 @@ static void UMINReduceLong512VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4298,7 +4298,7 @@ static void UMINReduceLong512VectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4308,7 +4308,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4322,7 +4322,7 @@ static void UMINReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4332,7 +4332,7 @@ static void UMINReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4344,7 +4344,7 @@ static void UMINReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti } static long UMAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4353,7 +4353,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4365,7 +4365,7 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4375,7 +4375,7 @@ static void UMAXReduceLong512VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); @@ -4387,7 +4387,7 @@ static void UMAXReduceLong512VectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4397,7 +4397,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4411,7 +4411,7 @@ static void UMAXReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4421,7 +4421,7 @@ static void UMAXReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Long64VectorTests.java b/test/jdk/jdk/incubator/vector/Long64VectorTests.java index 0fda0abed587d..bb31cee6f79d8 100644 --- a/test/jdk/jdk/incubator/vector/Long64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long64VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4255,7 +4255,7 @@ static void MAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunction } static long UMINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4264,7 +4264,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4276,7 +4276,7 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4286,7 +4286,7 @@ static void UMINReduceLong64VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4298,7 +4298,7 @@ static void UMINReduceLong64VectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4308,7 +4308,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4322,7 +4322,7 @@ static void UMINReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4332,7 +4332,7 @@ static void UMINReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4344,7 +4344,7 @@ static void UMINReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio } static long UMAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4353,7 +4353,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4365,7 +4365,7 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4375,7 +4375,7 @@ static void UMAXReduceLong64VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); @@ -4387,7 +4387,7 @@ static void UMAXReduceLong64VectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4397,7 +4397,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4411,7 +4411,7 @@ static void UMAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4421,7 +4421,7 @@ static void UMAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java index 7aa2bc4c510da..3235631decef4 100644 --- a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4260,7 +4260,7 @@ static void MAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio } static long UMINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4269,7 +4269,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4281,7 +4281,7 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4291,7 +4291,7 @@ static void UMINReduceLongMaxVectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4303,7 +4303,7 @@ static void UMINReduceLongMaxVectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4313,7 +4313,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = (long)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4327,7 +4327,7 @@ static void UMINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = (long)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4337,7 +4337,7 @@ static void UMINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MAX_VALUE; + ra = (long)-1; 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)); @@ -4349,7 +4349,7 @@ static void UMINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti } static long UMAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4358,7 +4358,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4370,7 +4370,7 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4380,7 +4380,7 @@ static void UMAXReduceLongMaxVectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); @@ -4392,7 +4392,7 @@ static void UMAXReduceLongMaxVectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4402,7 +4402,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = (long)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4416,7 +4416,7 @@ static void UMAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = (long)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4426,7 +4426,7 @@ static void UMAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Long.MIN_VALUE; + ra = (long)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Short128VectorTests.java b/test/jdk/jdk/incubator/vector/Short128VectorTests.java index 5f4c54bb708c3..7df5606520c35 100644 --- a/test/jdk/jdk/incubator/vector/Short128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short128VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4180,7 +4180,7 @@ static void MAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunct } static short UMINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4189,7 +4189,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4201,7 +4201,7 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4211,7 +4211,7 @@ static void UMINReduceShort128VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4223,7 +4223,7 @@ static void UMINReduceShort128VectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4233,7 +4233,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4247,7 +4247,7 @@ static void UMINReduceShort128VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4257,7 +4257,7 @@ static void UMINReduceShort128VectorTestsMasked(IntFunction fa, IntFunc } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4269,7 +4269,7 @@ static void UMINReduceShort128VectorTestsMasked(IntFunction fa, IntFunc } static short UMAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4278,7 +4278,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4290,7 +4290,7 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4300,7 +4300,7 @@ static void UMAXReduceShort128VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); @@ -4312,7 +4312,7 @@ static void UMAXReduceShort128VectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4322,7 +4322,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4336,7 +4336,7 @@ static void UMAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4346,7 +4346,7 @@ static void UMAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunc } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Short256VectorTests.java b/test/jdk/jdk/incubator/vector/Short256VectorTests.java index 88986575f6010..0bf3e5ef178fb 100644 --- a/test/jdk/jdk/incubator/vector/Short256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short256VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4180,7 +4180,7 @@ static void MAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunct } static short UMINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4189,7 +4189,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4201,7 +4201,7 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4211,7 +4211,7 @@ static void UMINReduceShort256VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4223,7 +4223,7 @@ static void UMINReduceShort256VectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4233,7 +4233,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4247,7 +4247,7 @@ static void UMINReduceShort256VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4257,7 +4257,7 @@ static void UMINReduceShort256VectorTestsMasked(IntFunction fa, IntFunc } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4269,7 +4269,7 @@ static void UMINReduceShort256VectorTestsMasked(IntFunction fa, IntFunc } static short UMAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4278,7 +4278,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4290,7 +4290,7 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4300,7 +4300,7 @@ static void UMAXReduceShort256VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); @@ -4312,7 +4312,7 @@ static void UMAXReduceShort256VectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4322,7 +4322,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4336,7 +4336,7 @@ static void UMAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4346,7 +4346,7 @@ static void UMAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunc } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Short512VectorTests.java b/test/jdk/jdk/incubator/vector/Short512VectorTests.java index 0f474375a47fc..8eb005f528507 100644 --- a/test/jdk/jdk/incubator/vector/Short512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short512VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4180,7 +4180,7 @@ static void MAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunct } static short UMINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4189,7 +4189,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4201,7 +4201,7 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4211,7 +4211,7 @@ static void UMINReduceShort512VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4223,7 +4223,7 @@ static void UMINReduceShort512VectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4233,7 +4233,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4247,7 +4247,7 @@ static void UMINReduceShort512VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4257,7 +4257,7 @@ static void UMINReduceShort512VectorTestsMasked(IntFunction fa, IntFunc } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4269,7 +4269,7 @@ static void UMINReduceShort512VectorTestsMasked(IntFunction fa, IntFunc } static short UMAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4278,7 +4278,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4290,7 +4290,7 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4300,7 +4300,7 @@ static void UMAXReduceShort512VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); @@ -4312,7 +4312,7 @@ static void UMAXReduceShort512VectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4322,7 +4322,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4336,7 +4336,7 @@ static void UMAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4346,7 +4346,7 @@ static void UMAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunc } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/Short64VectorTests.java b/test/jdk/jdk/incubator/vector/Short64VectorTests.java index 4b99ed6d84cf2..dafad7d6e3c16 100644 --- a/test/jdk/jdk/incubator/vector/Short64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short64VectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4180,7 +4180,7 @@ static void MAXReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti } static short UMINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4189,7 +4189,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4201,7 +4201,7 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4211,7 +4211,7 @@ static void UMINReduceShort64VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4223,7 +4223,7 @@ static void UMINReduceShort64VectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4233,7 +4233,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4247,7 +4247,7 @@ static void UMINReduceShort64VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4257,7 +4257,7 @@ static void UMINReduceShort64VectorTestsMasked(IntFunction fa, IntFunct } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4269,7 +4269,7 @@ static void UMINReduceShort64VectorTestsMasked(IntFunction fa, IntFunct } static short UMAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4278,7 +4278,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4290,7 +4290,7 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4300,7 +4300,7 @@ static void UMAXReduceShort64VectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); @@ -4312,7 +4312,7 @@ static void UMAXReduceShort64VectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4322,7 +4322,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4336,7 +4336,7 @@ static void UMAXReduceShort64VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4346,7 +4346,7 @@ static void UMAXReduceShort64VectorTestsMasked(IntFunction fa, IntFunct } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java index 2bb3b9c1557cd..8175bcd75bb1f 100644 --- a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4185,7 +4185,7 @@ static void MAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct } static short UMINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4194,7 +4194,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4206,7 +4206,7 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4216,7 +4216,7 @@ static void UMINReduceShortMaxVectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4228,7 +4228,7 @@ static void UMINReduceShortMaxVectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4238,7 +4238,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = (short)-1; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4252,7 +4252,7 @@ static void UMINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = (short)-1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4262,7 +4262,7 @@ static void UMINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MAX_VALUE; + ra = (short)-1; 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)); @@ -4274,7 +4274,7 @@ static void UMINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc } static short UMAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4283,7 +4283,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4295,7 +4295,7 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4305,7 +4305,7 @@ static void UMAXReduceShortMaxVectorTests(IntFunction fa) { } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); @@ -4317,7 +4317,7 @@ static void UMAXReduceShortMaxVectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4327,7 +4327,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = (short)0; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4341,7 +4341,7 @@ static void UMAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = (short)0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { @@ -4351,7 +4351,7 @@ static void UMAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc } for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Short.MIN_VALUE; + ra = (short)0; 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)); diff --git a/test/jdk/jdk/incubator/vector/gen-template.sh b/test/jdk/jdk/incubator/vector/gen-template.sh index a6f794a555954..9021e3fa3c271 100644 --- a/test/jdk/jdk/incubator/vector/gen-template.sh +++ b/test/jdk/jdk/incubator/vector/gen-template.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -514,8 +514,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 "UMIN" "(\$type\$) VectorMath.minUnsigned" "BITWISE" "(\$type\$)-1" +gen_reduction_op_func "UMAX" "(\$type\$) VectorMath.maxUnsigned" "BITWISE" "(\$type\$)0" gen_reduction_op_func "FIRST_NONZERO" "firstNonZero" "" "(\$type\$) 0" # Boolean reductions. diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-header.template b/test/jdk/jdk/incubator/vector/templates/Unit-header.template index 33c52f18c1c33..b389dd1cedbe7 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-header.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-header.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it From 7f7374572f3f1a6998e4b847b90f13f8ef13aaa9 Mon Sep 17 00:00:00 2001 From: erfang Date: Fri, 12 Dec 2025 08:33:09 +0000 Subject: [PATCH 2/3] Declare two constants for UMIN/UMAX reduction identity values --- .../jdk/incubator/vector/ByteVector.java | 6 +- .../jdk/incubator/vector/IntVector.java | 6 +- .../jdk/incubator/vector/LongVector.java | 6 +- .../jdk/incubator/vector/ShortVector.java | 6 +- .../incubator/vector/X-Vector.java.template | 6 +- .../incubator/vector/Byte128VectorTests.java | 436 ++++++++---------- .../incubator/vector/Byte256VectorTests.java | 436 ++++++++---------- .../incubator/vector/Byte512VectorTests.java | 436 ++++++++---------- .../incubator/vector/Byte64VectorTests.java | 436 ++++++++---------- .../incubator/vector/ByteMaxVectorTests.java | 436 ++++++++---------- .../vector/Double128VectorTests.java | 214 +++++---- .../vector/Double256VectorTests.java | 214 +++++---- .../vector/Double512VectorTests.java | 214 +++++---- .../incubator/vector/Double64VectorTests.java | 214 +++++---- .../vector/DoubleMaxVectorTests.java | 214 +++++---- .../incubator/vector/Float128VectorTests.java | 214 +++++---- .../incubator/vector/Float256VectorTests.java | 214 +++++---- .../incubator/vector/Float512VectorTests.java | 214 +++++---- .../incubator/vector/Float64VectorTests.java | 214 +++++---- .../incubator/vector/FloatMaxVectorTests.java | 214 +++++---- .../incubator/vector/Int128VectorTests.java | 436 ++++++++---------- .../incubator/vector/Int256VectorTests.java | 436 ++++++++---------- .../incubator/vector/Int512VectorTests.java | 436 ++++++++---------- .../incubator/vector/Int64VectorTests.java | 436 ++++++++---------- .../incubator/vector/IntMaxVectorTests.java | 436 ++++++++---------- .../incubator/vector/Long128VectorTests.java | 436 ++++++++---------- .../incubator/vector/Long256VectorTests.java | 436 ++++++++---------- .../incubator/vector/Long512VectorTests.java | 436 ++++++++---------- .../incubator/vector/Long64VectorTests.java | 436 ++++++++---------- .../incubator/vector/LongMaxVectorTests.java | 436 ++++++++---------- .../incubator/vector/Short128VectorTests.java | 436 ++++++++---------- .../incubator/vector/Short256VectorTests.java | 436 ++++++++---------- .../incubator/vector/Short512VectorTests.java | 436 ++++++++---------- .../incubator/vector/Short64VectorTests.java | 436 ++++++++---------- .../incubator/vector/ShortMaxVectorTests.java | 436 ++++++++---------- test/jdk/jdk/incubator/vector/gen-template.sh | 25 +- .../Kernel-Reduction-Masked-op-func.template | 12 +- .../Kernel-Reduction-Masked-op.template | 12 +- .../Kernel-Reduction-op-func.template | 12 +- .../templates/Kernel-Reduction-op.template | 12 +- ...nel-SaturatingReduction-Masked-op.template | 12 +- .../Kernel-SaturatingReduction-op.template | 12 +- .../templates/Unit-Identity-test.template | 95 ++++ .../vector/templates/Unit-header.template | 17 + 44 files changed, 5264 insertions(+), 5835 deletions(-) create mode 100644 test/jdk/jdk/incubator/vector/templates/Unit-Identity-test.template 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 26d2e4c53e6e5..7732bd7e73632 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 @@ -2873,9 +2873,9 @@ private static ReductionOperation> reductionOperati 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((byte)-1, m, (i, a, b) -> (byte) VectorMath.minUnsigned(a, b))); + toBits(v.rOp(UMAX_VALUE, m, (i, a, b) -> (byte) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> - toBits(v.rOp((byte)0, m, (i, a, b) -> (byte) VectorMath.maxUnsigned(a, b))); + toBits(v.rOp(UMIN_VALUE, m, (i, a, b) -> (byte) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp((byte)0, m, (i, a, b) -> (byte) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> @@ -2890,6 +2890,8 @@ private static ReductionOperation> reductionOperati private static final byte MIN_OR_INF = Byte.MIN_VALUE; private static final byte MAX_OR_INF = Byte.MAX_VALUE; + private static final byte UMIN_VALUE = (byte)0; // Minimum unsigned value + private static final byte UMAX_VALUE = (byte)-1; // Maximum unsigned value public @Override abstract long reduceLanesToLong(VectorOperators.Associative op); public @Override abstract long reduceLanesToLong(VectorOperators.Associative op, 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 aaf06994335c8..e28b9220c9c65 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 @@ -2858,9 +2858,9 @@ private static ReductionOperation> reductionOpera 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((int)-1, m, (i, a, b) -> (int) VectorMath.minUnsigned(a, b))); + toBits(v.rOp(UMAX_VALUE, m, (i, a, b) -> (int) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> - toBits(v.rOp((int)0, m, (i, a, b) -> (int) VectorMath.maxUnsigned(a, b))); + toBits(v.rOp(UMIN_VALUE, m, (i, a, b) -> (int) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp((int)0, m, (i, a, b) -> (int) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> @@ -2875,6 +2875,8 @@ private static ReductionOperation> reductionOpera private static final int MIN_OR_INF = Integer.MIN_VALUE; private static final int MAX_OR_INF = Integer.MAX_VALUE; + private static final int UMIN_VALUE = (int)0; // Minimum unsigned value + private static final int UMAX_VALUE = (int)-1; // Maximum unsigned value public @Override abstract long reduceLanesToLong(VectorOperators.Associative op); public @Override abstract long reduceLanesToLong(VectorOperators.Associative op, 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 65cdc941bf634..6ba19e477f86f 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 @@ -2724,9 +2724,9 @@ private static ReductionOperation> reductionOperati 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((long)-1, m, (i, a, b) -> (long) VectorMath.minUnsigned(a, b))); + toBits(v.rOp(UMAX_VALUE, m, (i, a, b) -> (long) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> - toBits(v.rOp((long)0, m, (i, a, b) -> (long) VectorMath.maxUnsigned(a, b))); + toBits(v.rOp(UMIN_VALUE, m, (i, a, b) -> (long) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp((long)0, m, (i, a, b) -> (long) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> @@ -2741,6 +2741,8 @@ private static ReductionOperation> reductionOperati private static final long MIN_OR_INF = Long.MIN_VALUE; private static final long MAX_OR_INF = Long.MAX_VALUE; + private static final long UMIN_VALUE = (long)0; // Minimum unsigned value + private static final long UMAX_VALUE = (long)-1; // Maximum unsigned value public @Override abstract long reduceLanesToLong(VectorOperators.Associative op); public @Override abstract long reduceLanesToLong(VectorOperators.Associative op, 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 d5f9d9b489775..53ae9e6b45883 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 @@ -2874,9 +2874,9 @@ private static ReductionOperation> reductionOpera 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((short)-1, m, (i, a, b) -> (short) VectorMath.minUnsigned(a, b))); + toBits(v.rOp(UMAX_VALUE, m, (i, a, b) -> (short) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> - toBits(v.rOp((short)0, m, (i, a, b) -> (short) VectorMath.maxUnsigned(a, b))); + toBits(v.rOp(UMIN_VALUE, m, (i, a, b) -> (short) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp((short)0, m, (i, a, b) -> (short) VectorMath.addSaturatingUnsigned(a, b))); case VECTOR_OP_AND: return (v, m) -> @@ -2891,6 +2891,8 @@ private static ReductionOperation> reductionOpera private static final short MIN_OR_INF = Short.MIN_VALUE; private static final short MAX_OR_INF = Short.MAX_VALUE; + private static final short UMIN_VALUE = (short)0; // Minimum unsigned value + private static final short UMAX_VALUE = (short)-1; // Maximum unsigned value public @Override abstract long reduceLanesToLong(VectorOperators.Associative op); public @Override abstract long reduceLanesToLong(VectorOperators.Associative op, 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 df34c6f4e4ce1..37843e65c7040 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 @@ -3448,9 +3448,9 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { 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(($type$)-1, m, (i, a, b) -> ($type$) VectorMath.minUnsigned(a, b))); + toBits(v.rOp(UMAX_VALUE, m, (i, a, b) -> ($type$) VectorMath.minUnsigned(a, b))); case VECTOR_OP_UMAX: return (v, m) -> - toBits(v.rOp(($type$)0, m, (i, a, b) -> ($type$) VectorMath.maxUnsigned(a, b))); + toBits(v.rOp(UMIN_VALUE, m, (i, a, b) -> ($type$) VectorMath.maxUnsigned(a, b))); case VECTOR_OP_SUADD: return (v, m) -> toBits(v.rOp(($type$)0, m, (i, a, b) -> ($type$) VectorMath.addSaturatingUnsigned(a, b))); #end[!FP] @@ -3472,6 +3472,8 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { #else[FP] private static final $type$ MIN_OR_INF = $Boxtype$.MIN_VALUE; private static final $type$ MAX_OR_INF = $Boxtype$.MAX_VALUE; + private static final $type$ UMIN_VALUE = ($type$)0; // Minimum unsigned value + private static final $type$ UMAX_VALUE = ($type$)-1; // Maximum unsigned value #end[FP] public @Override abstract long reduceLanesToLong(VectorOperators.Associative op); diff --git a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java index 056c515af0668..6d16c476c32ff 100644 --- a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java @@ -66,6 +66,19 @@ public class Byte128VectorTests extends AbstractVectorTest { private static final byte CONST_SHIFT = Byte.SIZE / 2; + // Identity values for reduction operations + private static final byte ADD_IDENTITY = (byte)0; + private static final byte AND_IDENTITY = (byte)-1; + private static final byte FIRST_NONZERO_IDENTITY = (byte)0; + private static final byte MAX_IDENTITY = Byte.MIN_VALUE; + private static final byte MIN_IDENTITY = Byte.MAX_VALUE; + private static final byte MUL_IDENTITY = (byte)1; + private static final byte OR_IDENTITY = (byte)0; + private static final byte SUADD_IDENTITY = (byte)0; + private static final byte UMAX_IDENTITY = (byte)0; // Minimum unsigned value + private static final byte UMIN_IDENTITY = (byte)-1; // Maximum unsigned value + private static final byte XOR_IDENTITY = (byte)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); static void assertArraysStrictlyEquals(byte[] r, byte[] a) { @@ -3566,7 +3579,7 @@ static void SUADDAssocByte128VectorTestsMasked(IntFunction fa, IntFuncti } static byte ANDReduce(byte[] a, int idx) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3575,7 +3588,7 @@ static byte ANDReduce(byte[] a, int idx) { } static byte ANDReduceAll(byte[] a) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3587,20 +3600,14 @@ static byte ANDReduceAll(byte[] a) { static void ANDReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3609,7 +3616,7 @@ static void ANDReduceByte128VectorTests(IntFunction fa) { } static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3619,7 +3626,7 @@ static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3633,20 +3640,14 @@ static void ANDReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3655,7 +3656,7 @@ static void ANDReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio } static byte ORReduce(byte[] a, int idx) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3664,7 +3665,7 @@ static byte ORReduce(byte[] a, int idx) { } static byte ORReduceAll(byte[] a) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3679,17 +3680,11 @@ static void ORReduceByte128VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3698,7 +3693,7 @@ static void ORReduceByte128VectorTests(IntFunction fa) { } static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3708,7 +3703,7 @@ static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3725,17 +3720,11 @@ static void ORReduceByte128VectorTestsMasked(IntFunction fa, IntFunction byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3744,7 +3733,7 @@ static void ORReduceByte128VectorTestsMasked(IntFunction fa, IntFunction } static byte XORReduce(byte[] a, int idx) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3753,7 +3742,7 @@ static byte XORReduce(byte[] a, int idx) { } static byte XORReduceAll(byte[] a) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3768,17 +3757,11 @@ static void XORReduceByte128VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3787,7 +3770,7 @@ static void XORReduceByte128VectorTests(IntFunction fa) { } static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3797,7 +3780,7 @@ static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte XORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3814,17 +3797,11 @@ static void XORReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3833,7 +3810,7 @@ static void XORReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio } static byte ADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3842,7 +3819,7 @@ static byte ADDReduce(byte[] a, int idx) { } static byte ADDReduceAll(byte[] a) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3857,17 +3834,11 @@ static void ADDReduceByte128VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3876,7 +3847,7 @@ static void ADDReduceByte128VectorTests(IntFunction fa) { } static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3886,7 +3857,7 @@ static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3903,17 +3874,11 @@ static void ADDReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3922,7 +3887,7 @@ static void ADDReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio } static byte MULReduce(byte[] a, int idx) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3931,7 +3896,7 @@ static byte MULReduce(byte[] a, int idx) { } static byte MULReduceAll(byte[] a) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3943,20 +3908,14 @@ static byte MULReduceAll(byte[] a) { static void MULReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3965,7 +3924,7 @@ static void MULReduceByte128VectorTests(IntFunction fa) { } static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3975,7 +3934,7 @@ static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MULReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3989,20 +3948,14 @@ static void MULReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4011,7 +3964,7 @@ static void MULReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio } static byte MINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.min(res, a[i]); } @@ -4020,7 +3973,7 @@ static byte MINReduce(byte[] a, int idx) { } static byte MINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduce(a, i)); } @@ -4032,20 +3985,14 @@ static byte MINReduceAll(byte[] a) { static void MINReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4054,7 +4001,7 @@ static void MINReduceByte128VectorTests(IntFunction fa) { } static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.min(res, a[i]); @@ -4064,7 +4011,7 @@ static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4078,20 +4025,14 @@ static void MINReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4100,7 +4041,7 @@ static void MINReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio } static byte MAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.max(res, a[i]); } @@ -4109,7 +4050,7 @@ static byte MAXReduce(byte[] a, int idx) { } static byte MAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduce(a, i)); } @@ -4121,20 +4062,14 @@ static byte MAXReduceAll(byte[] a) { static void MAXReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4143,7 +4078,7 @@ static void MAXReduceByte128VectorTests(IntFunction fa) { } static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.max(res, a[i]); @@ -4153,7 +4088,7 @@ static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4167,20 +4102,14 @@ static void MAXReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4189,7 +4118,7 @@ static void MAXReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio } static byte UMINReduce(byte[] a, int idx) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4198,7 +4127,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4210,20 +4139,14 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4232,7 +4155,7 @@ static void UMINReduceByte128VectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4242,7 +4165,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4256,20 +4179,14 @@ static void UMINReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4278,7 +4195,7 @@ static void UMINReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti } static byte UMAXReduce(byte[] a, int idx) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4287,7 +4204,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4299,20 +4216,14 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4321,7 +4232,7 @@ static void UMAXReduceByte128VectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4331,7 +4242,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4345,20 +4256,14 @@ static void UMAXReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4367,7 +4272,7 @@ static void UMAXReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti } static byte FIRST_NONZEROReduce(byte[] a, int idx) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4376,7 +4281,7 @@ static byte FIRST_NONZEROReduce(byte[] a, int idx) { } static byte FIRST_NONZEROReduceAll(byte[] a) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4388,20 +4293,14 @@ static byte FIRST_NONZEROReduceAll(byte[] a) { static void FIRST_NONZEROReduceByte128VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4410,7 +4309,7 @@ static void FIRST_NONZEROReduceByte128VectorTests(IntFunction fa) { } static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4420,7 +4319,7 @@ static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte FIRST_NONZEROReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4434,20 +4333,14 @@ static void FIRST_NONZEROReduceByte128VectorTestsMasked(IntFunction fa, byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4504,7 +4397,7 @@ static void allTrueByte128VectorTests(IntFunction fm) { } static byte SUADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4513,7 +4406,7 @@ static byte SUADDReduce(byte[] a, int idx) { } static byte SUADDReduceAll(byte[] a) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4528,17 +4421,11 @@ static void SUADDReduceByte128VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4547,7 +4434,7 @@ static void SUADDReduceByte128VectorTests(IntFunction fa) { } static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4557,7 +4444,7 @@ static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4573,17 +4460,11 @@ static void SUADDReduceByte128VectorTestsMasked(IntFunction fa, IntFunct byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6390,6 +6271,93 @@ static void REVERSE_BYTESMaskedByte128VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Byte128VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "byteUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((byte)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((byte)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Byte.MIN_VALUE, x) == x + Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Byte.MAX_VALUE, x) == x + Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((byte)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((byte)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "byteCompareOpProvider") static void ltByte128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java index 8a04e0ee5b103..ce84ec8508e74 100644 --- a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java @@ -66,6 +66,19 @@ public class Byte256VectorTests extends AbstractVectorTest { private static final byte CONST_SHIFT = Byte.SIZE / 2; + // Identity values for reduction operations + private static final byte ADD_IDENTITY = (byte)0; + private static final byte AND_IDENTITY = (byte)-1; + private static final byte FIRST_NONZERO_IDENTITY = (byte)0; + private static final byte MAX_IDENTITY = Byte.MIN_VALUE; + private static final byte MIN_IDENTITY = Byte.MAX_VALUE; + private static final byte MUL_IDENTITY = (byte)1; + private static final byte OR_IDENTITY = (byte)0; + private static final byte SUADD_IDENTITY = (byte)0; + private static final byte UMAX_IDENTITY = (byte)0; // Minimum unsigned value + private static final byte UMIN_IDENTITY = (byte)-1; // Maximum unsigned value + private static final byte XOR_IDENTITY = (byte)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); static void assertArraysStrictlyEquals(byte[] r, byte[] a) { @@ -3566,7 +3579,7 @@ static void SUADDAssocByte256VectorTestsMasked(IntFunction fa, IntFuncti } static byte ANDReduce(byte[] a, int idx) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3575,7 +3588,7 @@ static byte ANDReduce(byte[] a, int idx) { } static byte ANDReduceAll(byte[] a) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3587,20 +3600,14 @@ static byte ANDReduceAll(byte[] a) { static void ANDReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3609,7 +3616,7 @@ static void ANDReduceByte256VectorTests(IntFunction fa) { } static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3619,7 +3626,7 @@ static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3633,20 +3640,14 @@ static void ANDReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3655,7 +3656,7 @@ static void ANDReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio } static byte ORReduce(byte[] a, int idx) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3664,7 +3665,7 @@ static byte ORReduce(byte[] a, int idx) { } static byte ORReduceAll(byte[] a) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3679,17 +3680,11 @@ static void ORReduceByte256VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3698,7 +3693,7 @@ static void ORReduceByte256VectorTests(IntFunction fa) { } static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3708,7 +3703,7 @@ static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3725,17 +3720,11 @@ static void ORReduceByte256VectorTestsMasked(IntFunction fa, IntFunction byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3744,7 +3733,7 @@ static void ORReduceByte256VectorTestsMasked(IntFunction fa, IntFunction } static byte XORReduce(byte[] a, int idx) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3753,7 +3742,7 @@ static byte XORReduce(byte[] a, int idx) { } static byte XORReduceAll(byte[] a) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3768,17 +3757,11 @@ static void XORReduceByte256VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3787,7 +3770,7 @@ static void XORReduceByte256VectorTests(IntFunction fa) { } static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3797,7 +3780,7 @@ static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte XORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3814,17 +3797,11 @@ static void XORReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3833,7 +3810,7 @@ static void XORReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio } static byte ADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3842,7 +3819,7 @@ static byte ADDReduce(byte[] a, int idx) { } static byte ADDReduceAll(byte[] a) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3857,17 +3834,11 @@ static void ADDReduceByte256VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3876,7 +3847,7 @@ static void ADDReduceByte256VectorTests(IntFunction fa) { } static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3886,7 +3857,7 @@ static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3903,17 +3874,11 @@ static void ADDReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3922,7 +3887,7 @@ static void ADDReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio } static byte MULReduce(byte[] a, int idx) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3931,7 +3896,7 @@ static byte MULReduce(byte[] a, int idx) { } static byte MULReduceAll(byte[] a) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3943,20 +3908,14 @@ static byte MULReduceAll(byte[] a) { static void MULReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3965,7 +3924,7 @@ static void MULReduceByte256VectorTests(IntFunction fa) { } static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3975,7 +3934,7 @@ static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MULReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3989,20 +3948,14 @@ static void MULReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4011,7 +3964,7 @@ static void MULReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio } static byte MINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.min(res, a[i]); } @@ -4020,7 +3973,7 @@ static byte MINReduce(byte[] a, int idx) { } static byte MINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduce(a, i)); } @@ -4032,20 +3985,14 @@ static byte MINReduceAll(byte[] a) { static void MINReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4054,7 +4001,7 @@ static void MINReduceByte256VectorTests(IntFunction fa) { } static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.min(res, a[i]); @@ -4064,7 +4011,7 @@ static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4078,20 +4025,14 @@ static void MINReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4100,7 +4041,7 @@ static void MINReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio } static byte MAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.max(res, a[i]); } @@ -4109,7 +4050,7 @@ static byte MAXReduce(byte[] a, int idx) { } static byte MAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduce(a, i)); } @@ -4121,20 +4062,14 @@ static byte MAXReduceAll(byte[] a) { static void MAXReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4143,7 +4078,7 @@ static void MAXReduceByte256VectorTests(IntFunction fa) { } static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.max(res, a[i]); @@ -4153,7 +4088,7 @@ static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4167,20 +4102,14 @@ static void MAXReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4189,7 +4118,7 @@ static void MAXReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio } static byte UMINReduce(byte[] a, int idx) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4198,7 +4127,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4210,20 +4139,14 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4232,7 +4155,7 @@ static void UMINReduceByte256VectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4242,7 +4165,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4256,20 +4179,14 @@ static void UMINReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4278,7 +4195,7 @@ static void UMINReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti } static byte UMAXReduce(byte[] a, int idx) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4287,7 +4204,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4299,20 +4216,14 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4321,7 +4232,7 @@ static void UMAXReduceByte256VectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4331,7 +4242,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4345,20 +4256,14 @@ static void UMAXReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4367,7 +4272,7 @@ static void UMAXReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti } static byte FIRST_NONZEROReduce(byte[] a, int idx) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4376,7 +4281,7 @@ static byte FIRST_NONZEROReduce(byte[] a, int idx) { } static byte FIRST_NONZEROReduceAll(byte[] a) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4388,20 +4293,14 @@ static byte FIRST_NONZEROReduceAll(byte[] a) { static void FIRST_NONZEROReduceByte256VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4410,7 +4309,7 @@ static void FIRST_NONZEROReduceByte256VectorTests(IntFunction fa) { } static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4420,7 +4319,7 @@ static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte FIRST_NONZEROReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4434,20 +4333,14 @@ static void FIRST_NONZEROReduceByte256VectorTestsMasked(IntFunction fa, byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4504,7 +4397,7 @@ static void allTrueByte256VectorTests(IntFunction fm) { } static byte SUADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4513,7 +4406,7 @@ static byte SUADDReduce(byte[] a, int idx) { } static byte SUADDReduceAll(byte[] a) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4528,17 +4421,11 @@ static void SUADDReduceByte256VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4547,7 +4434,7 @@ static void SUADDReduceByte256VectorTests(IntFunction fa) { } static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4557,7 +4444,7 @@ static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4573,17 +4460,11 @@ static void SUADDReduceByte256VectorTestsMasked(IntFunction fa, IntFunct byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6390,6 +6271,93 @@ static void REVERSE_BYTESMaskedByte256VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Byte256VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "byteUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((byte)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((byte)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Byte.MIN_VALUE, x) == x + Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Byte.MAX_VALUE, x) == x + Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((byte)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((byte)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "byteCompareOpProvider") static void ltByte256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java index 96b78a3f02744..c5e3533de0e41 100644 --- a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java @@ -66,6 +66,19 @@ public class Byte512VectorTests extends AbstractVectorTest { private static final byte CONST_SHIFT = Byte.SIZE / 2; + // Identity values for reduction operations + private static final byte ADD_IDENTITY = (byte)0; + private static final byte AND_IDENTITY = (byte)-1; + private static final byte FIRST_NONZERO_IDENTITY = (byte)0; + private static final byte MAX_IDENTITY = Byte.MIN_VALUE; + private static final byte MIN_IDENTITY = Byte.MAX_VALUE; + private static final byte MUL_IDENTITY = (byte)1; + private static final byte OR_IDENTITY = (byte)0; + private static final byte SUADD_IDENTITY = (byte)0; + private static final byte UMAX_IDENTITY = (byte)0; // Minimum unsigned value + private static final byte UMIN_IDENTITY = (byte)-1; // Maximum unsigned value + private static final byte XOR_IDENTITY = (byte)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); static void assertArraysStrictlyEquals(byte[] r, byte[] a) { @@ -3566,7 +3579,7 @@ static void SUADDAssocByte512VectorTestsMasked(IntFunction fa, IntFuncti } static byte ANDReduce(byte[] a, int idx) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3575,7 +3588,7 @@ static byte ANDReduce(byte[] a, int idx) { } static byte ANDReduceAll(byte[] a) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3587,20 +3600,14 @@ static byte ANDReduceAll(byte[] a) { static void ANDReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3609,7 +3616,7 @@ static void ANDReduceByte512VectorTests(IntFunction fa) { } static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3619,7 +3626,7 @@ static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3633,20 +3640,14 @@ static void ANDReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3655,7 +3656,7 @@ static void ANDReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio } static byte ORReduce(byte[] a, int idx) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3664,7 +3665,7 @@ static byte ORReduce(byte[] a, int idx) { } static byte ORReduceAll(byte[] a) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3679,17 +3680,11 @@ static void ORReduceByte512VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3698,7 +3693,7 @@ static void ORReduceByte512VectorTests(IntFunction fa) { } static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3708,7 +3703,7 @@ static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3725,17 +3720,11 @@ static void ORReduceByte512VectorTestsMasked(IntFunction fa, IntFunction byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3744,7 +3733,7 @@ static void ORReduceByte512VectorTestsMasked(IntFunction fa, IntFunction } static byte XORReduce(byte[] a, int idx) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3753,7 +3742,7 @@ static byte XORReduce(byte[] a, int idx) { } static byte XORReduceAll(byte[] a) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3768,17 +3757,11 @@ static void XORReduceByte512VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3787,7 +3770,7 @@ static void XORReduceByte512VectorTests(IntFunction fa) { } static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3797,7 +3780,7 @@ static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte XORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3814,17 +3797,11 @@ static void XORReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3833,7 +3810,7 @@ static void XORReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio } static byte ADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3842,7 +3819,7 @@ static byte ADDReduce(byte[] a, int idx) { } static byte ADDReduceAll(byte[] a) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3857,17 +3834,11 @@ static void ADDReduceByte512VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3876,7 +3847,7 @@ static void ADDReduceByte512VectorTests(IntFunction fa) { } static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3886,7 +3857,7 @@ static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3903,17 +3874,11 @@ static void ADDReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3922,7 +3887,7 @@ static void ADDReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio } static byte MULReduce(byte[] a, int idx) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3931,7 +3896,7 @@ static byte MULReduce(byte[] a, int idx) { } static byte MULReduceAll(byte[] a) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3943,20 +3908,14 @@ static byte MULReduceAll(byte[] a) { static void MULReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3965,7 +3924,7 @@ static void MULReduceByte512VectorTests(IntFunction fa) { } static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3975,7 +3934,7 @@ static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MULReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3989,20 +3948,14 @@ static void MULReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4011,7 +3964,7 @@ static void MULReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio } static byte MINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.min(res, a[i]); } @@ -4020,7 +3973,7 @@ static byte MINReduce(byte[] a, int idx) { } static byte MINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduce(a, i)); } @@ -4032,20 +3985,14 @@ static byte MINReduceAll(byte[] a) { static void MINReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4054,7 +4001,7 @@ static void MINReduceByte512VectorTests(IntFunction fa) { } static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.min(res, a[i]); @@ -4064,7 +4011,7 @@ static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4078,20 +4025,14 @@ static void MINReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4100,7 +4041,7 @@ static void MINReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio } static byte MAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.max(res, a[i]); } @@ -4109,7 +4050,7 @@ static byte MAXReduce(byte[] a, int idx) { } static byte MAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduce(a, i)); } @@ -4121,20 +4062,14 @@ static byte MAXReduceAll(byte[] a) { static void MAXReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4143,7 +4078,7 @@ static void MAXReduceByte512VectorTests(IntFunction fa) { } static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.max(res, a[i]); @@ -4153,7 +4088,7 @@ static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4167,20 +4102,14 @@ static void MAXReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4189,7 +4118,7 @@ static void MAXReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio } static byte UMINReduce(byte[] a, int idx) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4198,7 +4127,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4210,20 +4139,14 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4232,7 +4155,7 @@ static void UMINReduceByte512VectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4242,7 +4165,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4256,20 +4179,14 @@ static void UMINReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4278,7 +4195,7 @@ static void UMINReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti } static byte UMAXReduce(byte[] a, int idx) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4287,7 +4204,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4299,20 +4216,14 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4321,7 +4232,7 @@ static void UMAXReduceByte512VectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4331,7 +4242,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4345,20 +4256,14 @@ static void UMAXReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4367,7 +4272,7 @@ static void UMAXReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti } static byte FIRST_NONZEROReduce(byte[] a, int idx) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4376,7 +4281,7 @@ static byte FIRST_NONZEROReduce(byte[] a, int idx) { } static byte FIRST_NONZEROReduceAll(byte[] a) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4388,20 +4293,14 @@ static byte FIRST_NONZEROReduceAll(byte[] a) { static void FIRST_NONZEROReduceByte512VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4410,7 +4309,7 @@ static void FIRST_NONZEROReduceByte512VectorTests(IntFunction fa) { } static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4420,7 +4319,7 @@ static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte FIRST_NONZEROReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4434,20 +4333,14 @@ static void FIRST_NONZEROReduceByte512VectorTestsMasked(IntFunction fa, byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4504,7 +4397,7 @@ static void allTrueByte512VectorTests(IntFunction fm) { } static byte SUADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4513,7 +4406,7 @@ static byte SUADDReduce(byte[] a, int idx) { } static byte SUADDReduceAll(byte[] a) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4528,17 +4421,11 @@ static void SUADDReduceByte512VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4547,7 +4434,7 @@ static void SUADDReduceByte512VectorTests(IntFunction fa) { } static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4557,7 +4444,7 @@ static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4573,17 +4460,11 @@ static void SUADDReduceByte512VectorTestsMasked(IntFunction fa, IntFunct byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6390,6 +6271,93 @@ static void REVERSE_BYTESMaskedByte512VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Byte512VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "byteUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((byte)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((byte)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Byte.MIN_VALUE, x) == x + Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Byte.MAX_VALUE, x) == x + Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((byte)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((byte)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "byteCompareOpProvider") static void ltByte512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java index a231e8fff18bd..03a7bb075568d 100644 --- a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java @@ -66,6 +66,19 @@ public class Byte64VectorTests extends AbstractVectorTest { private static final byte CONST_SHIFT = Byte.SIZE / 2; + // Identity values for reduction operations + private static final byte ADD_IDENTITY = (byte)0; + private static final byte AND_IDENTITY = (byte)-1; + private static final byte FIRST_NONZERO_IDENTITY = (byte)0; + private static final byte MAX_IDENTITY = Byte.MIN_VALUE; + private static final byte MIN_IDENTITY = Byte.MAX_VALUE; + private static final byte MUL_IDENTITY = (byte)1; + private static final byte OR_IDENTITY = (byte)0; + private static final byte SUADD_IDENTITY = (byte)0; + private static final byte UMAX_IDENTITY = (byte)0; // Minimum unsigned value + private static final byte UMIN_IDENTITY = (byte)-1; // Maximum unsigned value + private static final byte XOR_IDENTITY = (byte)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); static void assertArraysStrictlyEquals(byte[] r, byte[] a) { @@ -3566,7 +3579,7 @@ static void SUADDAssocByte64VectorTestsMasked(IntFunction fa, IntFunctio } static byte ANDReduce(byte[] a, int idx) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3575,7 +3588,7 @@ static byte ANDReduce(byte[] a, int idx) { } static byte ANDReduceAll(byte[] a) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3587,20 +3600,14 @@ static byte ANDReduceAll(byte[] a) { static void ANDReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3609,7 +3616,7 @@ static void ANDReduceByte64VectorTests(IntFunction fa) { } static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3619,7 +3626,7 @@ static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3633,20 +3640,14 @@ static void ANDReduceByte64VectorTestsMasked(IntFunction fa, IntFunction byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3655,7 +3656,7 @@ static void ANDReduceByte64VectorTestsMasked(IntFunction fa, IntFunction } static byte ORReduce(byte[] a, int idx) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3664,7 +3665,7 @@ static byte ORReduce(byte[] a, int idx) { } static byte ORReduceAll(byte[] a) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3679,17 +3680,11 @@ static void ORReduceByte64VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3698,7 +3693,7 @@ static void ORReduceByte64VectorTests(IntFunction fa) { } static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3708,7 +3703,7 @@ static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3725,17 +3720,11 @@ static void ORReduceByte64VectorTestsMasked(IntFunction fa, IntFunction< byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3744,7 +3733,7 @@ static void ORReduceByte64VectorTestsMasked(IntFunction fa, IntFunction< } static byte XORReduce(byte[] a, int idx) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3753,7 +3742,7 @@ static byte XORReduce(byte[] a, int idx) { } static byte XORReduceAll(byte[] a) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3768,17 +3757,11 @@ static void XORReduceByte64VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3787,7 +3770,7 @@ static void XORReduceByte64VectorTests(IntFunction fa) { } static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3797,7 +3780,7 @@ static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte XORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3814,17 +3797,11 @@ static void XORReduceByte64VectorTestsMasked(IntFunction fa, IntFunction byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3833,7 +3810,7 @@ static void XORReduceByte64VectorTestsMasked(IntFunction fa, IntFunction } static byte ADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3842,7 +3819,7 @@ static byte ADDReduce(byte[] a, int idx) { } static byte ADDReduceAll(byte[] a) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3857,17 +3834,11 @@ static void ADDReduceByte64VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3876,7 +3847,7 @@ static void ADDReduceByte64VectorTests(IntFunction fa) { } static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3886,7 +3857,7 @@ static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3903,17 +3874,11 @@ static void ADDReduceByte64VectorTestsMasked(IntFunction fa, IntFunction byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3922,7 +3887,7 @@ static void ADDReduceByte64VectorTestsMasked(IntFunction fa, IntFunction } static byte MULReduce(byte[] a, int idx) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3931,7 +3896,7 @@ static byte MULReduce(byte[] a, int idx) { } static byte MULReduceAll(byte[] a) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3943,20 +3908,14 @@ static byte MULReduceAll(byte[] a) { static void MULReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3965,7 +3924,7 @@ static void MULReduceByte64VectorTests(IntFunction fa) { } static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3975,7 +3934,7 @@ static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MULReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3989,20 +3948,14 @@ static void MULReduceByte64VectorTestsMasked(IntFunction fa, IntFunction byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4011,7 +3964,7 @@ static void MULReduceByte64VectorTestsMasked(IntFunction fa, IntFunction } static byte MINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.min(res, a[i]); } @@ -4020,7 +3973,7 @@ static byte MINReduce(byte[] a, int idx) { } static byte MINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduce(a, i)); } @@ -4032,20 +3985,14 @@ static byte MINReduceAll(byte[] a) { static void MINReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4054,7 +4001,7 @@ static void MINReduceByte64VectorTests(IntFunction fa) { } static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.min(res, a[i]); @@ -4064,7 +4011,7 @@ static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4078,20 +4025,14 @@ static void MINReduceByte64VectorTestsMasked(IntFunction fa, IntFunction byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4100,7 +4041,7 @@ static void MINReduceByte64VectorTestsMasked(IntFunction fa, IntFunction } static byte MAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.max(res, a[i]); } @@ -4109,7 +4050,7 @@ static byte MAXReduce(byte[] a, int idx) { } static byte MAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduce(a, i)); } @@ -4121,20 +4062,14 @@ static byte MAXReduceAll(byte[] a) { static void MAXReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4143,7 +4078,7 @@ static void MAXReduceByte64VectorTests(IntFunction fa) { } static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.max(res, a[i]); @@ -4153,7 +4088,7 @@ static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4167,20 +4102,14 @@ static void MAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunction byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4189,7 +4118,7 @@ static void MAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunction } static byte UMINReduce(byte[] a, int idx) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4198,7 +4127,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4210,20 +4139,14 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4232,7 +4155,7 @@ static void UMINReduceByte64VectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4242,7 +4165,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4256,20 +4179,14 @@ static void UMINReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4278,7 +4195,7 @@ static void UMINReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio } static byte UMAXReduce(byte[] a, int idx) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4287,7 +4204,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4299,20 +4216,14 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4321,7 +4232,7 @@ static void UMAXReduceByte64VectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4331,7 +4242,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4345,20 +4256,14 @@ static void UMAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4367,7 +4272,7 @@ static void UMAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio } static byte FIRST_NONZEROReduce(byte[] a, int idx) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4376,7 +4281,7 @@ static byte FIRST_NONZEROReduce(byte[] a, int idx) { } static byte FIRST_NONZEROReduceAll(byte[] a) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4388,20 +4293,14 @@ static byte FIRST_NONZEROReduceAll(byte[] a) { static void FIRST_NONZEROReduceByte64VectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4410,7 +4309,7 @@ static void FIRST_NONZEROReduceByte64VectorTests(IntFunction fa) { } static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4420,7 +4319,7 @@ static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte FIRST_NONZEROReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4434,20 +4333,14 @@ static void FIRST_NONZEROReduceByte64VectorTestsMasked(IntFunction fa, I byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4504,7 +4397,7 @@ static void allTrueByte64VectorTests(IntFunction fm) { } static byte SUADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4513,7 +4406,7 @@ static byte SUADDReduce(byte[] a, int idx) { } static byte SUADDReduceAll(byte[] a) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4528,17 +4421,11 @@ static void SUADDReduceByte64VectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4547,7 +4434,7 @@ static void SUADDReduceByte64VectorTests(IntFunction fa) { } static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4557,7 +4444,7 @@ static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4573,17 +4460,11 @@ static void SUADDReduceByte64VectorTestsMasked(IntFunction fa, IntFuncti byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6390,6 +6271,93 @@ static void REVERSE_BYTESMaskedByte64VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Byte64VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "byteUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((byte)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((byte)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Byte.MIN_VALUE, x) == x + Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Byte.MAX_VALUE, x) == x + Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((byte)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((byte)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "byteCompareOpProvider") static void ltByte64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java index f0bba029109aa..f3af790108cca 100644 --- a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java @@ -71,6 +71,19 @@ static VectorShape getMaxBit() { private static final byte CONST_SHIFT = Byte.SIZE / 2; + // Identity values for reduction operations + private static final byte ADD_IDENTITY = (byte)0; + private static final byte AND_IDENTITY = (byte)-1; + private static final byte FIRST_NONZERO_IDENTITY = (byte)0; + private static final byte MAX_IDENTITY = Byte.MIN_VALUE; + private static final byte MIN_IDENTITY = Byte.MAX_VALUE; + private static final byte MUL_IDENTITY = (byte)1; + private static final byte OR_IDENTITY = (byte)0; + private static final byte SUADD_IDENTITY = (byte)0; + private static final byte UMAX_IDENTITY = (byte)0; // Minimum unsigned value + private static final byte UMIN_IDENTITY = (byte)-1; // Maximum unsigned value + private static final byte XOR_IDENTITY = (byte)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); static void assertArraysStrictlyEquals(byte[] r, byte[] a) { @@ -3571,7 +3584,7 @@ static void SUADDAssocByteMaxVectorTestsMasked(IntFunction fa, IntFuncti } static byte ANDReduce(byte[] a, int idx) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3580,7 +3593,7 @@ static byte ANDReduce(byte[] a, int idx) { } static byte ANDReduceAll(byte[] a) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3592,20 +3605,14 @@ static byte ANDReduceAll(byte[] a) { static void ANDReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3614,7 +3621,7 @@ static void ANDReduceByteMaxVectorTests(IntFunction fa) { } static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3624,7 +3631,7 @@ static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = -1; + byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3638,20 +3645,14 @@ static void ANDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = -1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3660,7 +3661,7 @@ static void ANDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio } static byte ORReduce(byte[] a, int idx) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3669,7 +3670,7 @@ static byte ORReduce(byte[] a, int idx) { } static byte ORReduceAll(byte[] a) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3684,17 +3685,11 @@ static void ORReduceByteMaxVectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3703,7 +3698,7 @@ static void ORReduceByteMaxVectorTests(IntFunction fa) { } static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3713,7 +3708,7 @@ static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3730,17 +3725,11 @@ static void ORReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunction byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3749,7 +3738,7 @@ static void ORReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunction } static byte XORReduce(byte[] a, int idx) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3758,7 +3747,7 @@ static byte XORReduce(byte[] a, int idx) { } static byte XORReduceAll(byte[] a) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3773,17 +3762,11 @@ static void XORReduceByteMaxVectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3792,7 +3775,7 @@ static void XORReduceByteMaxVectorTests(IntFunction fa) { } static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3802,7 +3785,7 @@ static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte XORReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3819,17 +3802,11 @@ static void XORReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3838,7 +3815,7 @@ static void XORReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio } static byte ADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3847,7 +3824,7 @@ static byte ADDReduce(byte[] a, int idx) { } static byte ADDReduceAll(byte[] a) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3862,17 +3839,11 @@ static void ADDReduceByteMaxVectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3881,7 +3852,7 @@ static void ADDReduceByteMaxVectorTests(IntFunction fa) { } static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3891,7 +3862,7 @@ static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3908,17 +3879,11 @@ static void ADDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3927,7 +3892,7 @@ static void ADDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio } static byte MULReduce(byte[] a, int idx) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3936,7 +3901,7 @@ static byte MULReduce(byte[] a, int idx) { } static byte MULReduceAll(byte[] a) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3948,20 +3913,14 @@ static byte MULReduceAll(byte[] a) { static void MULReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3970,7 +3929,7 @@ static void MULReduceByteMaxVectorTests(IntFunction fa) { } static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3980,7 +3939,7 @@ static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MULReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 1; + byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3994,20 +3953,14 @@ static void MULReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = 1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4016,7 +3969,7 @@ static void MULReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio } static byte MINReduce(byte[] a, int idx) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.min(res, a[i]); } @@ -4025,7 +3978,7 @@ static byte MINReduce(byte[] a, int idx) { } static byte MINReduceAll(byte[] a) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduce(a, i)); } @@ -4037,20 +3990,14 @@ static byte MINReduceAll(byte[] a) { static void MINReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4059,7 +4006,7 @@ static void MINReduceByteMaxVectorTests(IntFunction fa) { } static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.min(res, a[i]); @@ -4069,7 +4016,7 @@ static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MAX_VALUE; + byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4083,20 +4030,14 @@ static void MINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MAX_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (byte) Math.min(ra, r[i]); } } @@ -4105,7 +4046,7 @@ static void MINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio } static byte MAXReduce(byte[] a, int idx) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) Math.max(res, a[i]); } @@ -4114,7 +4055,7 @@ static byte MAXReduce(byte[] a, int idx) { } static byte MAXReduceAll(byte[] a) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduce(a, i)); } @@ -4126,20 +4067,14 @@ static byte MAXReduceAll(byte[] a) { static void MAXReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4148,7 +4083,7 @@ static void MAXReduceByteMaxVectorTests(IntFunction fa) { } static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) Math.max(res, a[i]); @@ -4158,7 +4093,7 @@ static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = Byte.MIN_VALUE; + byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4172,20 +4107,14 @@ static void MAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = Byte.MIN_VALUE; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (byte) Math.max(ra, r[i]); } } @@ -4194,7 +4123,7 @@ static void MAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio } static byte UMINReduce(byte[] a, int idx) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.minUnsigned(res, a[i]); } @@ -4203,7 +4132,7 @@ static byte UMINReduce(byte[] a, int idx) { } static byte UMINReduceAll(byte[] a) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4215,20 +4144,14 @@ static byte UMINReduceAll(byte[] a) { static void UMINReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4237,7 +4160,7 @@ static void UMINReduceByteMaxVectorTests(IntFunction fa) { } static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.minUnsigned(res, a[i]); @@ -4247,7 +4170,7 @@ static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMINReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)-1; + byte res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4261,20 +4184,14 @@ static void UMINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)-1; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (byte) VectorMath.minUnsigned(ra, r[i]); } } @@ -4283,7 +4200,7 @@ static void UMINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti } static byte UMAXReduce(byte[] a, int idx) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.maxUnsigned(res, a[i]); } @@ -4292,7 +4209,7 @@ static byte UMAXReduce(byte[] a, int idx) { } static byte UMAXReduceAll(byte[] a) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4304,20 +4221,14 @@ static byte UMAXReduceAll(byte[] a) { static void UMAXReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4326,7 +4237,7 @@ static void UMAXReduceByteMaxVectorTests(IntFunction fa) { } static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.maxUnsigned(res, a[i]); @@ -4336,7 +4247,7 @@ static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte)0; + byte res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4350,20 +4261,14 @@ static void UMAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte)0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (byte) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4372,7 +4277,7 @@ static void UMAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti } static byte FIRST_NONZEROReduce(byte[] a, int idx) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4381,7 +4286,7 @@ static byte FIRST_NONZEROReduce(byte[] a, int idx) { } static byte FIRST_NONZEROReduceAll(byte[] a) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4393,20 +4298,14 @@ static byte FIRST_NONZEROReduceAll(byte[] a) { static void FIRST_NONZEROReduceByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length()); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4415,7 +4314,7 @@ static void FIRST_NONZEROReduceByteMaxVectorTests(IntFunction fa) { } static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4425,7 +4324,7 @@ static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte FIRST_NONZEROReduceAllMasked(byte[] a, boolean[] mask) { - byte res = (byte) 0; + byte res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4439,20 +4338,14 @@ static void FIRST_NONZEROReduceByteMaxVectorTestsMasked(IntFunction fa, byte[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - byte ra = (byte) 0; + byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (byte) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4509,7 +4402,7 @@ static void allTrueByteMaxVectorTests(IntFunction fm) { } static byte SUADDReduce(byte[] a, int idx) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4518,7 +4411,7 @@ static byte SUADDReduce(byte[] a, int idx) { } static byte SUADDReduceAll(byte[] a) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4533,17 +4426,11 @@ static void SUADDReduceByteMaxVectorTests(IntFunction fa) { byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4552,7 +4439,7 @@ static void SUADDReduceByteMaxVectorTests(IntFunction fa) { } static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4562,7 +4449,7 @@ static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { } static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) { - byte res = 0; + byte res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4578,17 +4465,11 @@ static void SUADDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunct byte ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6395,6 +6276,93 @@ static void REVERSE_BYTESMaskedByteMaxVectorTests(IntFunction fa, assertArraysEquals(r, a, mask, ByteMaxVectorTests::REVERSE_BYTES); } + @Test(dataProvider = "byteUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((byte)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((byte)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Byte.MIN_VALUE, x) == x + Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Byte.MAX_VALUE, x) == x + Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((byte)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((byte)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "byteUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "byteCompareOpProvider") static void ltByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Double128VectorTests.java b/test/jdk/jdk/incubator/vector/Double128VectorTests.java index 681b6c50093b2..e6e8bf3145319 100644 --- a/test/jdk/jdk/incubator/vector/Double128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double128VectorTests.java @@ -63,6 +63,13 @@ public class Double128VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); + + // Identity values for reduction operations + private static final double ADD_IDENTITY = (double)0; + private static final double FIRST_NONZERO_IDENTITY = (double)0; + private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; + private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; + private static final double MUL_IDENTITY = (double)1; // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2339,7 +2346,7 @@ static void maxDouble128VectorTestsBroadcastSmokeTest(IntFunction fa, } static double ADDReduce(double[] a, int idx) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2348,7 +2355,7 @@ static double ADDReduce(double[] a, int idx) { } static double ADDReduceAll(double[] a) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2363,17 +2370,11 @@ static void ADDReduceDouble128VectorTests(IntFunction fa) { double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2382,7 +2383,7 @@ static void ADDReduceDouble128VectorTests(IntFunction fa) { } static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2392,7 +2393,7 @@ static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { } static double ADDReduceAllMasked(double[] a, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2409,17 +2410,11 @@ static void ADDReduceDouble128VectorTestsMasked(IntFunction fa, IntFun double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2428,7 +2423,7 @@ static void ADDReduceDouble128VectorTestsMasked(IntFunction fa, IntFun } static double MULReduce(double[] a, int idx) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2437,7 +2432,7 @@ static double MULReduce(double[] a, int idx) { } static double MULReduceAll(double[] a) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2449,20 +2444,14 @@ static double MULReduceAll(double[] a) { static void MULReduceDouble128VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2471,7 +2460,7 @@ static void MULReduceDouble128VectorTests(IntFunction fa) { } static double MULReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2481,7 +2470,7 @@ static double MULReduceMasked(double[] a, int idx, boolean[] mask) { } static double MULReduceAllMasked(double[] a, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2495,20 +2484,14 @@ static void MULReduceDouble128VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2517,7 +2500,7 @@ static void MULReduceDouble128VectorTestsMasked(IntFunction fa, IntFun } static double MINReduce(double[] a, int idx) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.min(res, a[i]); } @@ -2526,7 +2509,7 @@ static double MINReduce(double[] a, int idx) { } static double MINReduceAll(double[] a) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduce(a, i)); } @@ -2538,20 +2521,14 @@ static double MINReduceAll(double[] a) { static void MINReduceDouble128VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (double) Math.min(ra, r[i]); } } @@ -2560,7 +2537,7 @@ static void MINReduceDouble128VectorTests(IntFunction fa) { } static double MINReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.min(res, a[i]); @@ -2570,7 +2547,7 @@ static double MINReduceMasked(double[] a, int idx, boolean[] mask) { } static double MINReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2584,20 +2561,14 @@ static void MINReduceDouble128VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (double) Math.min(ra, r[i]); } } @@ -2606,7 +2577,7 @@ static void MINReduceDouble128VectorTestsMasked(IntFunction fa, IntFun } static double MAXReduce(double[] a, int idx) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.max(res, a[i]); } @@ -2615,7 +2586,7 @@ static double MAXReduce(double[] a, int idx) { } static double MAXReduceAll(double[] a) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduce(a, i)); } @@ -2627,20 +2598,14 @@ static double MAXReduceAll(double[] a) { static void MAXReduceDouble128VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (double) Math.max(ra, r[i]); } } @@ -2649,7 +2614,7 @@ static void MAXReduceDouble128VectorTests(IntFunction fa) { } static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.max(res, a[i]); @@ -2659,7 +2624,7 @@ static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { } static double MAXReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2673,20 +2638,14 @@ static void MAXReduceDouble128VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (double) Math.max(ra, r[i]); } } @@ -2695,7 +2654,7 @@ static void MAXReduceDouble128VectorTestsMasked(IntFunction fa, IntFun } static double FIRST_NONZEROReduce(double[] a, int idx) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2704,7 +2663,7 @@ static double FIRST_NONZEROReduce(double[] a, int idx) { } static double FIRST_NONZEROReduceAll(double[] a) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2716,20 +2675,14 @@ static double FIRST_NONZEROReduceAll(double[] a) { static void FIRST_NONZEROReduceDouble128VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2738,7 +2691,7 @@ static void FIRST_NONZEROReduceDouble128VectorTests(IntFunction fa) { } static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2748,7 +2701,7 @@ static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { } static double FIRST_NONZEROReduceAllMasked(double[] a, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2762,20 +2715,14 @@ static void FIRST_NONZEROReduceDouble128VectorTestsMasked(IntFunction double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4806,6 +4753,57 @@ static void SQRTMaskedDouble128VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Double128VectorTests::SQRT); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((double)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Double.POSITIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((double)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "doubleUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Double256VectorTests.java b/test/jdk/jdk/incubator/vector/Double256VectorTests.java index 3fa8e7e2911ce..3fc86b087b8bb 100644 --- a/test/jdk/jdk/incubator/vector/Double256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double256VectorTests.java @@ -63,6 +63,13 @@ public class Double256VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); + + // Identity values for reduction operations + private static final double ADD_IDENTITY = (double)0; + private static final double FIRST_NONZERO_IDENTITY = (double)0; + private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; + private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; + private static final double MUL_IDENTITY = (double)1; // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2339,7 +2346,7 @@ static void maxDouble256VectorTestsBroadcastSmokeTest(IntFunction fa, } static double ADDReduce(double[] a, int idx) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2348,7 +2355,7 @@ static double ADDReduce(double[] a, int idx) { } static double ADDReduceAll(double[] a) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2363,17 +2370,11 @@ static void ADDReduceDouble256VectorTests(IntFunction fa) { double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2382,7 +2383,7 @@ static void ADDReduceDouble256VectorTests(IntFunction fa) { } static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2392,7 +2393,7 @@ static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { } static double ADDReduceAllMasked(double[] a, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2409,17 +2410,11 @@ static void ADDReduceDouble256VectorTestsMasked(IntFunction fa, IntFun double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2428,7 +2423,7 @@ static void ADDReduceDouble256VectorTestsMasked(IntFunction fa, IntFun } static double MULReduce(double[] a, int idx) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2437,7 +2432,7 @@ static double MULReduce(double[] a, int idx) { } static double MULReduceAll(double[] a) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2449,20 +2444,14 @@ static double MULReduceAll(double[] a) { static void MULReduceDouble256VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2471,7 +2460,7 @@ static void MULReduceDouble256VectorTests(IntFunction fa) { } static double MULReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2481,7 +2470,7 @@ static double MULReduceMasked(double[] a, int idx, boolean[] mask) { } static double MULReduceAllMasked(double[] a, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2495,20 +2484,14 @@ static void MULReduceDouble256VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2517,7 +2500,7 @@ static void MULReduceDouble256VectorTestsMasked(IntFunction fa, IntFun } static double MINReduce(double[] a, int idx) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.min(res, a[i]); } @@ -2526,7 +2509,7 @@ static double MINReduce(double[] a, int idx) { } static double MINReduceAll(double[] a) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduce(a, i)); } @@ -2538,20 +2521,14 @@ static double MINReduceAll(double[] a) { static void MINReduceDouble256VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (double) Math.min(ra, r[i]); } } @@ -2560,7 +2537,7 @@ static void MINReduceDouble256VectorTests(IntFunction fa) { } static double MINReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.min(res, a[i]); @@ -2570,7 +2547,7 @@ static double MINReduceMasked(double[] a, int idx, boolean[] mask) { } static double MINReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2584,20 +2561,14 @@ static void MINReduceDouble256VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (double) Math.min(ra, r[i]); } } @@ -2606,7 +2577,7 @@ static void MINReduceDouble256VectorTestsMasked(IntFunction fa, IntFun } static double MAXReduce(double[] a, int idx) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.max(res, a[i]); } @@ -2615,7 +2586,7 @@ static double MAXReduce(double[] a, int idx) { } static double MAXReduceAll(double[] a) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduce(a, i)); } @@ -2627,20 +2598,14 @@ static double MAXReduceAll(double[] a) { static void MAXReduceDouble256VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (double) Math.max(ra, r[i]); } } @@ -2649,7 +2614,7 @@ static void MAXReduceDouble256VectorTests(IntFunction fa) { } static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.max(res, a[i]); @@ -2659,7 +2624,7 @@ static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { } static double MAXReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2673,20 +2638,14 @@ static void MAXReduceDouble256VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (double) Math.max(ra, r[i]); } } @@ -2695,7 +2654,7 @@ static void MAXReduceDouble256VectorTestsMasked(IntFunction fa, IntFun } static double FIRST_NONZEROReduce(double[] a, int idx) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2704,7 +2663,7 @@ static double FIRST_NONZEROReduce(double[] a, int idx) { } static double FIRST_NONZEROReduceAll(double[] a) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2716,20 +2675,14 @@ static double FIRST_NONZEROReduceAll(double[] a) { static void FIRST_NONZEROReduceDouble256VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2738,7 +2691,7 @@ static void FIRST_NONZEROReduceDouble256VectorTests(IntFunction fa) { } static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2748,7 +2701,7 @@ static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { } static double FIRST_NONZEROReduceAllMasked(double[] a, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2762,20 +2715,14 @@ static void FIRST_NONZEROReduceDouble256VectorTestsMasked(IntFunction double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4806,6 +4753,57 @@ static void SQRTMaskedDouble256VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Double256VectorTests::SQRT); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((double)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Double.POSITIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((double)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "doubleUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Double512VectorTests.java b/test/jdk/jdk/incubator/vector/Double512VectorTests.java index 96e72112bacb0..059e08cd4db18 100644 --- a/test/jdk/jdk/incubator/vector/Double512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double512VectorTests.java @@ -63,6 +63,13 @@ public class Double512VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); + + // Identity values for reduction operations + private static final double ADD_IDENTITY = (double)0; + private static final double FIRST_NONZERO_IDENTITY = (double)0; + private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; + private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; + private static final double MUL_IDENTITY = (double)1; // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2339,7 +2346,7 @@ static void maxDouble512VectorTestsBroadcastSmokeTest(IntFunction fa, } static double ADDReduce(double[] a, int idx) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2348,7 +2355,7 @@ static double ADDReduce(double[] a, int idx) { } static double ADDReduceAll(double[] a) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2363,17 +2370,11 @@ static void ADDReduceDouble512VectorTests(IntFunction fa) { double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2382,7 +2383,7 @@ static void ADDReduceDouble512VectorTests(IntFunction fa) { } static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2392,7 +2393,7 @@ static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { } static double ADDReduceAllMasked(double[] a, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2409,17 +2410,11 @@ static void ADDReduceDouble512VectorTestsMasked(IntFunction fa, IntFun double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2428,7 +2423,7 @@ static void ADDReduceDouble512VectorTestsMasked(IntFunction fa, IntFun } static double MULReduce(double[] a, int idx) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2437,7 +2432,7 @@ static double MULReduce(double[] a, int idx) { } static double MULReduceAll(double[] a) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2449,20 +2444,14 @@ static double MULReduceAll(double[] a) { static void MULReduceDouble512VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2471,7 +2460,7 @@ static void MULReduceDouble512VectorTests(IntFunction fa) { } static double MULReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2481,7 +2470,7 @@ static double MULReduceMasked(double[] a, int idx, boolean[] mask) { } static double MULReduceAllMasked(double[] a, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2495,20 +2484,14 @@ static void MULReduceDouble512VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2517,7 +2500,7 @@ static void MULReduceDouble512VectorTestsMasked(IntFunction fa, IntFun } static double MINReduce(double[] a, int idx) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.min(res, a[i]); } @@ -2526,7 +2509,7 @@ static double MINReduce(double[] a, int idx) { } static double MINReduceAll(double[] a) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduce(a, i)); } @@ -2538,20 +2521,14 @@ static double MINReduceAll(double[] a) { static void MINReduceDouble512VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (double) Math.min(ra, r[i]); } } @@ -2560,7 +2537,7 @@ static void MINReduceDouble512VectorTests(IntFunction fa) { } static double MINReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.min(res, a[i]); @@ -2570,7 +2547,7 @@ static double MINReduceMasked(double[] a, int idx, boolean[] mask) { } static double MINReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2584,20 +2561,14 @@ static void MINReduceDouble512VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (double) Math.min(ra, r[i]); } } @@ -2606,7 +2577,7 @@ static void MINReduceDouble512VectorTestsMasked(IntFunction fa, IntFun } static double MAXReduce(double[] a, int idx) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.max(res, a[i]); } @@ -2615,7 +2586,7 @@ static double MAXReduce(double[] a, int idx) { } static double MAXReduceAll(double[] a) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduce(a, i)); } @@ -2627,20 +2598,14 @@ static double MAXReduceAll(double[] a) { static void MAXReduceDouble512VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (double) Math.max(ra, r[i]); } } @@ -2649,7 +2614,7 @@ static void MAXReduceDouble512VectorTests(IntFunction fa) { } static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.max(res, a[i]); @@ -2659,7 +2624,7 @@ static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { } static double MAXReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2673,20 +2638,14 @@ static void MAXReduceDouble512VectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (double) Math.max(ra, r[i]); } } @@ -2695,7 +2654,7 @@ static void MAXReduceDouble512VectorTestsMasked(IntFunction fa, IntFun } static double FIRST_NONZEROReduce(double[] a, int idx) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2704,7 +2663,7 @@ static double FIRST_NONZEROReduce(double[] a, int idx) { } static double FIRST_NONZEROReduceAll(double[] a) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2716,20 +2675,14 @@ static double FIRST_NONZEROReduceAll(double[] a) { static void FIRST_NONZEROReduceDouble512VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2738,7 +2691,7 @@ static void FIRST_NONZEROReduceDouble512VectorTests(IntFunction fa) { } static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2748,7 +2701,7 @@ static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { } static double FIRST_NONZEROReduceAllMasked(double[] a, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2762,20 +2715,14 @@ static void FIRST_NONZEROReduceDouble512VectorTestsMasked(IntFunction double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4806,6 +4753,57 @@ static void SQRTMaskedDouble512VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Double512VectorTests::SQRT); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((double)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Double.POSITIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((double)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "doubleUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Double64VectorTests.java b/test/jdk/jdk/incubator/vector/Double64VectorTests.java index dc4488a5367ca..5fa2c9c1dae73 100644 --- a/test/jdk/jdk/incubator/vector/Double64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double64VectorTests.java @@ -63,6 +63,13 @@ public class Double64VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); + + // Identity values for reduction operations + private static final double ADD_IDENTITY = (double)0; + private static final double FIRST_NONZERO_IDENTITY = (double)0; + private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; + private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; + private static final double MUL_IDENTITY = (double)1; // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2339,7 +2346,7 @@ static void maxDouble64VectorTestsBroadcastSmokeTest(IntFunction fa, I } static double ADDReduce(double[] a, int idx) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2348,7 +2355,7 @@ static double ADDReduce(double[] a, int idx) { } static double ADDReduceAll(double[] a) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2363,17 +2370,11 @@ static void ADDReduceDouble64VectorTests(IntFunction fa) { double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2382,7 +2383,7 @@ static void ADDReduceDouble64VectorTests(IntFunction fa) { } static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2392,7 +2393,7 @@ static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { } static double ADDReduceAllMasked(double[] a, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2409,17 +2410,11 @@ static void ADDReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2428,7 +2423,7 @@ static void ADDReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc } static double MULReduce(double[] a, int idx) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2437,7 +2432,7 @@ static double MULReduce(double[] a, int idx) { } static double MULReduceAll(double[] a) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2449,20 +2444,14 @@ static double MULReduceAll(double[] a) { static void MULReduceDouble64VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2471,7 +2460,7 @@ static void MULReduceDouble64VectorTests(IntFunction fa) { } static double MULReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2481,7 +2470,7 @@ static double MULReduceMasked(double[] a, int idx, boolean[] mask) { } static double MULReduceAllMasked(double[] a, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2495,20 +2484,14 @@ static void MULReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2517,7 +2500,7 @@ static void MULReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc } static double MINReduce(double[] a, int idx) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.min(res, a[i]); } @@ -2526,7 +2509,7 @@ static double MINReduce(double[] a, int idx) { } static double MINReduceAll(double[] a) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduce(a, i)); } @@ -2538,20 +2521,14 @@ static double MINReduceAll(double[] a) { static void MINReduceDouble64VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (double) Math.min(ra, r[i]); } } @@ -2560,7 +2537,7 @@ static void MINReduceDouble64VectorTests(IntFunction fa) { } static double MINReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.min(res, a[i]); @@ -2570,7 +2547,7 @@ static double MINReduceMasked(double[] a, int idx, boolean[] mask) { } static double MINReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2584,20 +2561,14 @@ static void MINReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (double) Math.min(ra, r[i]); } } @@ -2606,7 +2577,7 @@ static void MINReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc } static double MAXReduce(double[] a, int idx) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.max(res, a[i]); } @@ -2615,7 +2586,7 @@ static double MAXReduce(double[] a, int idx) { } static double MAXReduceAll(double[] a) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduce(a, i)); } @@ -2627,20 +2598,14 @@ static double MAXReduceAll(double[] a) { static void MAXReduceDouble64VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (double) Math.max(ra, r[i]); } } @@ -2649,7 +2614,7 @@ static void MAXReduceDouble64VectorTests(IntFunction fa) { } static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.max(res, a[i]); @@ -2659,7 +2624,7 @@ static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { } static double MAXReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2673,20 +2638,14 @@ static void MAXReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (double) Math.max(ra, r[i]); } } @@ -2695,7 +2654,7 @@ static void MAXReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc } static double FIRST_NONZEROReduce(double[] a, int idx) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2704,7 +2663,7 @@ static double FIRST_NONZEROReduce(double[] a, int idx) { } static double FIRST_NONZEROReduceAll(double[] a) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2716,20 +2675,14 @@ static double FIRST_NONZEROReduceAll(double[] a) { static void FIRST_NONZEROReduceDouble64VectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2738,7 +2691,7 @@ static void FIRST_NONZEROReduceDouble64VectorTests(IntFunction fa) { } static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2748,7 +2701,7 @@ static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { } static double FIRST_NONZEROReduceAllMasked(double[] a, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2762,20 +2715,14 @@ static void FIRST_NONZEROReduceDouble64VectorTestsMasked(IntFunction f double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4806,6 +4753,57 @@ static void SQRTMaskedDouble64VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Double64VectorTests::SQRT); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((double)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Double.POSITIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((double)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "doubleUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java index 8898a098d3fe0..ca6aa15d9c3d2 100644 --- a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java @@ -68,6 +68,13 @@ static VectorShape getMaxBit() { private static final int Max = 256; // juts so we can do N/Max + + // Identity values for reduction operations + private static final double ADD_IDENTITY = (double)0; + private static final double FIRST_NONZERO_IDENTITY = (double)0; + private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; + private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; + private static final double MUL_IDENTITY = (double)1; // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2344,7 +2351,7 @@ static void maxDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction fa, } static double ADDReduce(double[] a, int idx) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2353,7 +2360,7 @@ static double ADDReduce(double[] a, int idx) { } static double ADDReduceAll(double[] a) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2368,17 +2375,11 @@ static void ADDReduceDoubleMaxVectorTests(IntFunction fa) { double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2387,7 +2388,7 @@ static void ADDReduceDoubleMaxVectorTests(IntFunction fa) { } static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2397,7 +2398,7 @@ static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { } static double ADDReduceAllMasked(double[] a, boolean[] mask) { - double res = 0; + double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2414,17 +2415,11 @@ static void ADDReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2433,7 +2428,7 @@ static void ADDReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun } static double MULReduce(double[] a, int idx) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2442,7 +2437,7 @@ static double MULReduce(double[] a, int idx) { } static double MULReduceAll(double[] a) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2454,20 +2449,14 @@ static double MULReduceAll(double[] a) { static void MULReduceDoubleMaxVectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2476,7 +2465,7 @@ static void MULReduceDoubleMaxVectorTests(IntFunction fa) { } static double MULReduceMasked(double[] a, int idx, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2486,7 +2475,7 @@ static double MULReduceMasked(double[] a, int idx, boolean[] mask) { } static double MULReduceAllMasked(double[] a, boolean[] mask) { - double res = 1; + double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2500,20 +2489,14 @@ static void MULReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = 1; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2522,7 +2505,7 @@ static void MULReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun } static double MINReduce(double[] a, int idx) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.min(res, a[i]); } @@ -2531,7 +2514,7 @@ static double MINReduce(double[] a, int idx) { } static double MINReduceAll(double[] a) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduce(a, i)); } @@ -2543,20 +2526,14 @@ static double MINReduceAll(double[] a) { static void MINReduceDoubleMaxVectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (double) Math.min(ra, r[i]); } } @@ -2565,7 +2542,7 @@ static void MINReduceDoubleMaxVectorTests(IntFunction fa) { } static double MINReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.min(res, a[i]); @@ -2575,7 +2552,7 @@ static double MINReduceMasked(double[] a, int idx, boolean[] mask) { } static double MINReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.POSITIVE_INFINITY; + double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2589,20 +2566,14 @@ static void MINReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.POSITIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (double) Math.min(ra, r[i]); } } @@ -2611,7 +2582,7 @@ static void MINReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun } static double MAXReduce(double[] a, int idx) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (double) Math.max(res, a[i]); } @@ -2620,7 +2591,7 @@ static double MAXReduce(double[] a, int idx) { } static double MAXReduceAll(double[] a) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduce(a, i)); } @@ -2632,20 +2603,14 @@ static double MAXReduceAll(double[] a) { static void MAXReduceDoubleMaxVectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (double) Math.max(ra, r[i]); } } @@ -2654,7 +2619,7 @@ static void MAXReduceDoubleMaxVectorTests(IntFunction fa) { } static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (double) Math.max(res, a[i]); @@ -2664,7 +2629,7 @@ static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { } static double MAXReduceAllMasked(double[] a, boolean[] mask) { - double res = Double.NEGATIVE_INFINITY; + double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2678,20 +2643,14 @@ static void MAXReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = Double.NEGATIVE_INFINITY; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Double.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (double) Math.max(ra, r[i]); } } @@ -2700,7 +2659,7 @@ static void MAXReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun } static double FIRST_NONZEROReduce(double[] a, int idx) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2709,7 +2668,7 @@ static double FIRST_NONZEROReduce(double[] a, int idx) { } static double FIRST_NONZEROReduceAll(double[] a) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2721,20 +2680,14 @@ static double FIRST_NONZEROReduceAll(double[] a) { static void FIRST_NONZEROReduceDoubleMaxVectorTests(IntFunction fa) { double[] a = fa.apply(SPECIES.length()); double[] r = fr.apply(SPECIES.length()); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2743,7 +2696,7 @@ static void FIRST_NONZEROReduceDoubleMaxVectorTests(IntFunction fa) { } static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2753,7 +2706,7 @@ static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { } static double FIRST_NONZEROReduceAllMasked(double[] a, boolean[] mask) { - double res = (double) 0; + double res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2767,20 +2720,14 @@ static void FIRST_NONZEROReduceDoubleMaxVectorTestsMasked(IntFunction double[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - double ra = (double) 0; + double ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (double) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4811,6 +4758,57 @@ static void SQRTMaskedDoubleMaxVectorTests(IntFunction fa, assertArraysEquals(r, a, mask, DoubleMaxVectorTests::SQRT); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((double)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Double.POSITIVE_INFINITY, x) == x + Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((double)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "doubleUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "doubleCompareOpProvider") static void ltDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Float128VectorTests.java b/test/jdk/jdk/incubator/vector/Float128VectorTests.java index dd31439bc45d9..5084783701422 100644 --- a/test/jdk/jdk/incubator/vector/Float128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float128VectorTests.java @@ -63,6 +63,13 @@ public class Float128VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); + + // Identity values for reduction operations + private static final float ADD_IDENTITY = (float)0; + private static final float FIRST_NONZERO_IDENTITY = (float)0; + private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; + private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; + private static final float MUL_IDENTITY = (float)1; // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2350,7 +2357,7 @@ static void maxFloat128VectorTestsBroadcastSmokeTest(IntFunction fa, In } static float ADDReduce(float[] a, int idx) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2359,7 +2366,7 @@ static float ADDReduce(float[] a, int idx) { } static float ADDReduceAll(float[] a) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2374,17 +2381,11 @@ static void ADDReduceFloat128VectorTests(IntFunction fa) { float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2393,7 +2394,7 @@ static void ADDReduceFloat128VectorTests(IntFunction fa) { } static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2403,7 +2404,7 @@ static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { } static float ADDReduceAllMasked(float[] a, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2420,17 +2421,11 @@ static void ADDReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2439,7 +2434,7 @@ static void ADDReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct } static float MULReduce(float[] a, int idx) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2448,7 +2443,7 @@ static float MULReduce(float[] a, int idx) { } static float MULReduceAll(float[] a) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2460,20 +2455,14 @@ static float MULReduceAll(float[] a) { static void MULReduceFloat128VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2482,7 +2471,7 @@ static void MULReduceFloat128VectorTests(IntFunction fa) { } static float MULReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2492,7 +2481,7 @@ static float MULReduceMasked(float[] a, int idx, boolean[] mask) { } static float MULReduceAllMasked(float[] a, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2506,20 +2495,14 @@ static void MULReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2528,7 +2511,7 @@ static void MULReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct } static float MINReduce(float[] a, int idx) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.min(res, a[i]); } @@ -2537,7 +2520,7 @@ static float MINReduce(float[] a, int idx) { } static float MINReduceAll(float[] a) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduce(a, i)); } @@ -2549,20 +2532,14 @@ static float MINReduceAll(float[] a) { static void MINReduceFloat128VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (float) Math.min(ra, r[i]); } } @@ -2571,7 +2548,7 @@ static void MINReduceFloat128VectorTests(IntFunction fa) { } static float MINReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.min(res, a[i]); @@ -2581,7 +2558,7 @@ static float MINReduceMasked(float[] a, int idx, boolean[] mask) { } static float MINReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2595,20 +2572,14 @@ static void MINReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (float) Math.min(ra, r[i]); } } @@ -2617,7 +2588,7 @@ static void MINReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct } static float MAXReduce(float[] a, int idx) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.max(res, a[i]); } @@ -2626,7 +2597,7 @@ static float MAXReduce(float[] a, int idx) { } static float MAXReduceAll(float[] a) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduce(a, i)); } @@ -2638,20 +2609,14 @@ static float MAXReduceAll(float[] a) { static void MAXReduceFloat128VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (float) Math.max(ra, r[i]); } } @@ -2660,7 +2625,7 @@ static void MAXReduceFloat128VectorTests(IntFunction fa) { } static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.max(res, a[i]); @@ -2670,7 +2635,7 @@ static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { } static float MAXReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2684,20 +2649,14 @@ static void MAXReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (float) Math.max(ra, r[i]); } } @@ -2706,7 +2665,7 @@ static void MAXReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct } static float FIRST_NONZEROReduce(float[] a, int idx) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2715,7 +2674,7 @@ static float FIRST_NONZEROReduce(float[] a, int idx) { } static float FIRST_NONZEROReduceAll(float[] a) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2727,20 +2686,14 @@ static float FIRST_NONZEROReduceAll(float[] a) { static void FIRST_NONZEROReduceFloat128VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2749,7 +2702,7 @@ static void FIRST_NONZEROReduceFloat128VectorTests(IntFunction fa) { } static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2759,7 +2712,7 @@ static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { } static float FIRST_NONZEROReduceAllMasked(float[] a, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2773,20 +2726,14 @@ static void FIRST_NONZEROReduceFloat128VectorTestsMasked(IntFunction fa float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4775,6 +4722,57 @@ static void SQRTMaskedFloat128VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Float128VectorTests::SQRT); } + @Test(dataProvider = "floatUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((float)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Float.POSITIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((float)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "floatUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "floatCompareOpProvider") static void ltFloat128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Float256VectorTests.java b/test/jdk/jdk/incubator/vector/Float256VectorTests.java index 49dfe5746ef20..76466f86931e4 100644 --- a/test/jdk/jdk/incubator/vector/Float256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float256VectorTests.java @@ -63,6 +63,13 @@ public class Float256VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); + + // Identity values for reduction operations + private static final float ADD_IDENTITY = (float)0; + private static final float FIRST_NONZERO_IDENTITY = (float)0; + private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; + private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; + private static final float MUL_IDENTITY = (float)1; // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2350,7 +2357,7 @@ static void maxFloat256VectorTestsBroadcastSmokeTest(IntFunction fa, In } static float ADDReduce(float[] a, int idx) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2359,7 +2366,7 @@ static float ADDReduce(float[] a, int idx) { } static float ADDReduceAll(float[] a) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2374,17 +2381,11 @@ static void ADDReduceFloat256VectorTests(IntFunction fa) { float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2393,7 +2394,7 @@ static void ADDReduceFloat256VectorTests(IntFunction fa) { } static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2403,7 +2404,7 @@ static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { } static float ADDReduceAllMasked(float[] a, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2420,17 +2421,11 @@ static void ADDReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2439,7 +2434,7 @@ static void ADDReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct } static float MULReduce(float[] a, int idx) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2448,7 +2443,7 @@ static float MULReduce(float[] a, int idx) { } static float MULReduceAll(float[] a) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2460,20 +2455,14 @@ static float MULReduceAll(float[] a) { static void MULReduceFloat256VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2482,7 +2471,7 @@ static void MULReduceFloat256VectorTests(IntFunction fa) { } static float MULReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2492,7 +2481,7 @@ static float MULReduceMasked(float[] a, int idx, boolean[] mask) { } static float MULReduceAllMasked(float[] a, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2506,20 +2495,14 @@ static void MULReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2528,7 +2511,7 @@ static void MULReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct } static float MINReduce(float[] a, int idx) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.min(res, a[i]); } @@ -2537,7 +2520,7 @@ static float MINReduce(float[] a, int idx) { } static float MINReduceAll(float[] a) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduce(a, i)); } @@ -2549,20 +2532,14 @@ static float MINReduceAll(float[] a) { static void MINReduceFloat256VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (float) Math.min(ra, r[i]); } } @@ -2571,7 +2548,7 @@ static void MINReduceFloat256VectorTests(IntFunction fa) { } static float MINReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.min(res, a[i]); @@ -2581,7 +2558,7 @@ static float MINReduceMasked(float[] a, int idx, boolean[] mask) { } static float MINReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2595,20 +2572,14 @@ static void MINReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (float) Math.min(ra, r[i]); } } @@ -2617,7 +2588,7 @@ static void MINReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct } static float MAXReduce(float[] a, int idx) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.max(res, a[i]); } @@ -2626,7 +2597,7 @@ static float MAXReduce(float[] a, int idx) { } static float MAXReduceAll(float[] a) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduce(a, i)); } @@ -2638,20 +2609,14 @@ static float MAXReduceAll(float[] a) { static void MAXReduceFloat256VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (float) Math.max(ra, r[i]); } } @@ -2660,7 +2625,7 @@ static void MAXReduceFloat256VectorTests(IntFunction fa) { } static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.max(res, a[i]); @@ -2670,7 +2635,7 @@ static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { } static float MAXReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2684,20 +2649,14 @@ static void MAXReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (float) Math.max(ra, r[i]); } } @@ -2706,7 +2665,7 @@ static void MAXReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct } static float FIRST_NONZEROReduce(float[] a, int idx) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2715,7 +2674,7 @@ static float FIRST_NONZEROReduce(float[] a, int idx) { } static float FIRST_NONZEROReduceAll(float[] a) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2727,20 +2686,14 @@ static float FIRST_NONZEROReduceAll(float[] a) { static void FIRST_NONZEROReduceFloat256VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2749,7 +2702,7 @@ static void FIRST_NONZEROReduceFloat256VectorTests(IntFunction fa) { } static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2759,7 +2712,7 @@ static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { } static float FIRST_NONZEROReduceAllMasked(float[] a, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2773,20 +2726,14 @@ static void FIRST_NONZEROReduceFloat256VectorTestsMasked(IntFunction fa float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4775,6 +4722,57 @@ static void SQRTMaskedFloat256VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Float256VectorTests::SQRT); } + @Test(dataProvider = "floatUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((float)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Float.POSITIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((float)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "floatUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "floatCompareOpProvider") static void ltFloat256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Float512VectorTests.java b/test/jdk/jdk/incubator/vector/Float512VectorTests.java index b52cd0cf69619..4b60b5d04d2fc 100644 --- a/test/jdk/jdk/incubator/vector/Float512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float512VectorTests.java @@ -63,6 +63,13 @@ public class Float512VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); + + // Identity values for reduction operations + private static final float ADD_IDENTITY = (float)0; + private static final float FIRST_NONZERO_IDENTITY = (float)0; + private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; + private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; + private static final float MUL_IDENTITY = (float)1; // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2350,7 +2357,7 @@ static void maxFloat512VectorTestsBroadcastSmokeTest(IntFunction fa, In } static float ADDReduce(float[] a, int idx) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2359,7 +2366,7 @@ static float ADDReduce(float[] a, int idx) { } static float ADDReduceAll(float[] a) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2374,17 +2381,11 @@ static void ADDReduceFloat512VectorTests(IntFunction fa) { float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2393,7 +2394,7 @@ static void ADDReduceFloat512VectorTests(IntFunction fa) { } static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2403,7 +2404,7 @@ static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { } static float ADDReduceAllMasked(float[] a, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2420,17 +2421,11 @@ static void ADDReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2439,7 +2434,7 @@ static void ADDReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct } static float MULReduce(float[] a, int idx) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2448,7 +2443,7 @@ static float MULReduce(float[] a, int idx) { } static float MULReduceAll(float[] a) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2460,20 +2455,14 @@ static float MULReduceAll(float[] a) { static void MULReduceFloat512VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2482,7 +2471,7 @@ static void MULReduceFloat512VectorTests(IntFunction fa) { } static float MULReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2492,7 +2481,7 @@ static float MULReduceMasked(float[] a, int idx, boolean[] mask) { } static float MULReduceAllMasked(float[] a, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2506,20 +2495,14 @@ static void MULReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2528,7 +2511,7 @@ static void MULReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct } static float MINReduce(float[] a, int idx) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.min(res, a[i]); } @@ -2537,7 +2520,7 @@ static float MINReduce(float[] a, int idx) { } static float MINReduceAll(float[] a) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduce(a, i)); } @@ -2549,20 +2532,14 @@ static float MINReduceAll(float[] a) { static void MINReduceFloat512VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (float) Math.min(ra, r[i]); } } @@ -2571,7 +2548,7 @@ static void MINReduceFloat512VectorTests(IntFunction fa) { } static float MINReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.min(res, a[i]); @@ -2581,7 +2558,7 @@ static float MINReduceMasked(float[] a, int idx, boolean[] mask) { } static float MINReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2595,20 +2572,14 @@ static void MINReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (float) Math.min(ra, r[i]); } } @@ -2617,7 +2588,7 @@ static void MINReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct } static float MAXReduce(float[] a, int idx) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.max(res, a[i]); } @@ -2626,7 +2597,7 @@ static float MAXReduce(float[] a, int idx) { } static float MAXReduceAll(float[] a) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduce(a, i)); } @@ -2638,20 +2609,14 @@ static float MAXReduceAll(float[] a) { static void MAXReduceFloat512VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (float) Math.max(ra, r[i]); } } @@ -2660,7 +2625,7 @@ static void MAXReduceFloat512VectorTests(IntFunction fa) { } static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.max(res, a[i]); @@ -2670,7 +2635,7 @@ static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { } static float MAXReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2684,20 +2649,14 @@ static void MAXReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (float) Math.max(ra, r[i]); } } @@ -2706,7 +2665,7 @@ static void MAXReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct } static float FIRST_NONZEROReduce(float[] a, int idx) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2715,7 +2674,7 @@ static float FIRST_NONZEROReduce(float[] a, int idx) { } static float FIRST_NONZEROReduceAll(float[] a) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2727,20 +2686,14 @@ static float FIRST_NONZEROReduceAll(float[] a) { static void FIRST_NONZEROReduceFloat512VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2749,7 +2702,7 @@ static void FIRST_NONZEROReduceFloat512VectorTests(IntFunction fa) { } static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2759,7 +2712,7 @@ static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { } static float FIRST_NONZEROReduceAllMasked(float[] a, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2773,20 +2726,14 @@ static void FIRST_NONZEROReduceFloat512VectorTestsMasked(IntFunction fa float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4775,6 +4722,57 @@ static void SQRTMaskedFloat512VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Float512VectorTests::SQRT); } + @Test(dataProvider = "floatUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((float)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Float.POSITIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((float)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "floatUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "floatCompareOpProvider") static void ltFloat512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Float64VectorTests.java b/test/jdk/jdk/incubator/vector/Float64VectorTests.java index 260ee21a647db..bf4eed2cd1c38 100644 --- a/test/jdk/jdk/incubator/vector/Float64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float64VectorTests.java @@ -63,6 +63,13 @@ public class Float64VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); + + // Identity values for reduction operations + private static final float ADD_IDENTITY = (float)0; + private static final float FIRST_NONZERO_IDENTITY = (float)0; + private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; + private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; + private static final float MUL_IDENTITY = (float)1; // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2350,7 +2357,7 @@ static void maxFloat64VectorTestsBroadcastSmokeTest(IntFunction fa, Int } static float ADDReduce(float[] a, int idx) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2359,7 +2366,7 @@ static float ADDReduce(float[] a, int idx) { } static float ADDReduceAll(float[] a) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2374,17 +2381,11 @@ static void ADDReduceFloat64VectorTests(IntFunction fa) { float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2393,7 +2394,7 @@ static void ADDReduceFloat64VectorTests(IntFunction fa) { } static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2403,7 +2404,7 @@ static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { } static float ADDReduceAllMasked(float[] a, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2420,17 +2421,11 @@ static void ADDReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2439,7 +2434,7 @@ static void ADDReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti } static float MULReduce(float[] a, int idx) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2448,7 +2443,7 @@ static float MULReduce(float[] a, int idx) { } static float MULReduceAll(float[] a) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2460,20 +2455,14 @@ static float MULReduceAll(float[] a) { static void MULReduceFloat64VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2482,7 +2471,7 @@ static void MULReduceFloat64VectorTests(IntFunction fa) { } static float MULReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2492,7 +2481,7 @@ static float MULReduceMasked(float[] a, int idx, boolean[] mask) { } static float MULReduceAllMasked(float[] a, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2506,20 +2495,14 @@ static void MULReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2528,7 +2511,7 @@ static void MULReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti } static float MINReduce(float[] a, int idx) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.min(res, a[i]); } @@ -2537,7 +2520,7 @@ static float MINReduce(float[] a, int idx) { } static float MINReduceAll(float[] a) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduce(a, i)); } @@ -2549,20 +2532,14 @@ static float MINReduceAll(float[] a) { static void MINReduceFloat64VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (float) Math.min(ra, r[i]); } } @@ -2571,7 +2548,7 @@ static void MINReduceFloat64VectorTests(IntFunction fa) { } static float MINReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.min(res, a[i]); @@ -2581,7 +2558,7 @@ static float MINReduceMasked(float[] a, int idx, boolean[] mask) { } static float MINReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2595,20 +2572,14 @@ static void MINReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (float) Math.min(ra, r[i]); } } @@ -2617,7 +2588,7 @@ static void MINReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti } static float MAXReduce(float[] a, int idx) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.max(res, a[i]); } @@ -2626,7 +2597,7 @@ static float MAXReduce(float[] a, int idx) { } static float MAXReduceAll(float[] a) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduce(a, i)); } @@ -2638,20 +2609,14 @@ static float MAXReduceAll(float[] a) { static void MAXReduceFloat64VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (float) Math.max(ra, r[i]); } } @@ -2660,7 +2625,7 @@ static void MAXReduceFloat64VectorTests(IntFunction fa) { } static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.max(res, a[i]); @@ -2670,7 +2635,7 @@ static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { } static float MAXReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2684,20 +2649,14 @@ static void MAXReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (float) Math.max(ra, r[i]); } } @@ -2706,7 +2665,7 @@ static void MAXReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti } static float FIRST_NONZEROReduce(float[] a, int idx) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2715,7 +2674,7 @@ static float FIRST_NONZEROReduce(float[] a, int idx) { } static float FIRST_NONZEROReduceAll(float[] a) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2727,20 +2686,14 @@ static float FIRST_NONZEROReduceAll(float[] a) { static void FIRST_NONZEROReduceFloat64VectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2749,7 +2702,7 @@ static void FIRST_NONZEROReduceFloat64VectorTests(IntFunction fa) { } static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2759,7 +2712,7 @@ static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { } static float FIRST_NONZEROReduceAllMasked(float[] a, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2773,20 +2726,14 @@ static void FIRST_NONZEROReduceFloat64VectorTestsMasked(IntFunction fa, float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4775,6 +4722,57 @@ static void SQRTMaskedFloat64VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Float64VectorTests::SQRT); } + @Test(dataProvider = "floatUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((float)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Float.POSITIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((float)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "floatUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "floatCompareOpProvider") static void ltFloat64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java index 0137364cf4e1c..046eb73a93c41 100644 --- a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java @@ -68,6 +68,13 @@ static VectorShape getMaxBit() { private static final int Max = 256; // juts so we can do N/Max + + // Identity values for reduction operations + private static final float ADD_IDENTITY = (float)0; + private static final float FIRST_NONZERO_IDENTITY = (float)0; + private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; + private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; + private static final float MUL_IDENTITY = (float)1; // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2355,7 +2362,7 @@ static void maxFloatMaxVectorTestsBroadcastSmokeTest(IntFunction fa, In } static float ADDReduce(float[] a, int idx) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -2364,7 +2371,7 @@ static float ADDReduce(float[] a, int idx) { } static float ADDReduceAll(float[] a) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -2379,17 +2386,11 @@ static void ADDReduceFloatMaxVectorTests(IntFunction fa) { float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -2398,7 +2399,7 @@ static void ADDReduceFloatMaxVectorTests(IntFunction fa) { } static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -2408,7 +2409,7 @@ static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { } static float ADDReduceAllMasked(float[] a, boolean[] mask) { - float res = 0; + float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -2425,17 +2426,11 @@ static void ADDReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -2444,7 +2439,7 @@ static void ADDReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct } static float MULReduce(float[] a, int idx) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -2453,7 +2448,7 @@ static float MULReduce(float[] a, int idx) { } static float MULReduceAll(float[] a) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -2465,20 +2460,14 @@ static float MULReduceAll(float[] a) { static void MULReduceFloatMaxVectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -2487,7 +2476,7 @@ static void MULReduceFloatMaxVectorTests(IntFunction fa) { } static float MULReduceMasked(float[] a, int idx, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -2497,7 +2486,7 @@ static float MULReduceMasked(float[] a, int idx, boolean[] mask) { } static float MULReduceAllMasked(float[] a, boolean[] mask) { - float res = 1; + float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -2511,20 +2500,14 @@ static void MULReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = 1; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -2533,7 +2516,7 @@ static void MULReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct } static float MINReduce(float[] a, int idx) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.min(res, a[i]); } @@ -2542,7 +2525,7 @@ static float MINReduce(float[] a, int idx) { } static float MINReduceAll(float[] a) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduce(a, i)); } @@ -2554,20 +2537,14 @@ static float MINReduceAll(float[] a) { static void MINReduceFloatMaxVectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (float) Math.min(ra, r[i]); } } @@ -2576,7 +2553,7 @@ static void MINReduceFloatMaxVectorTests(IntFunction fa) { } static float MINReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.min(res, a[i]); @@ -2586,7 +2563,7 @@ static float MINReduceMasked(float[] a, int idx, boolean[] mask) { } static float MINReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.POSITIVE_INFINITY; + float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -2600,20 +2577,14 @@ static void MINReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.POSITIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.POSITIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (float) Math.min(ra, r[i]); } } @@ -2622,7 +2593,7 @@ static void MINReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct } static float MAXReduce(float[] a, int idx) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (float) Math.max(res, a[i]); } @@ -2631,7 +2602,7 @@ static float MAXReduce(float[] a, int idx) { } static float MAXReduceAll(float[] a) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduce(a, i)); } @@ -2643,20 +2614,14 @@ static float MAXReduceAll(float[] a) { static void MAXReduceFloatMaxVectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (float) Math.max(ra, r[i]); } } @@ -2665,7 +2630,7 @@ static void MAXReduceFloatMaxVectorTests(IntFunction fa) { } static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (float) Math.max(res, a[i]); @@ -2675,7 +2640,7 @@ static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { } static float MAXReduceAllMasked(float[] a, boolean[] mask) { - float res = Float.NEGATIVE_INFINITY; + float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -2689,20 +2654,14 @@ static void MAXReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = Float.NEGATIVE_INFINITY; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = Float.NEGATIVE_INFINITY; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = (float) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (float) Math.max(ra, r[i]); } } @@ -2711,7 +2670,7 @@ static void MAXReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct } static float FIRST_NONZEROReduce(float[] a, int idx) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -2720,7 +2679,7 @@ static float FIRST_NONZEROReduce(float[] a, int idx) { } static float FIRST_NONZEROReduceAll(float[] a) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -2732,20 +2691,14 @@ static float FIRST_NONZEROReduceAll(float[] a) { static void FIRST_NONZEROReduceFloatMaxVectorTests(IntFunction fa) { float[] a = fa.apply(SPECIES.length()); float[] r = fr.apply(SPECIES.length()); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -2754,7 +2707,7 @@ static void FIRST_NONZEROReduceFloatMaxVectorTests(IntFunction fa) { } static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -2764,7 +2717,7 @@ static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { } static float FIRST_NONZEROReduceAllMasked(float[] a, boolean[] mask) { - float res = (float) 0; + float res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -2778,20 +2731,14 @@ static void FIRST_NONZEROReduceFloatMaxVectorTestsMasked(IntFunction fa float[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - float ra = (float) 0; + float ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (float) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4780,6 +4727,57 @@ static void SQRTMaskedFloatMaxVectorTests(IntFunction fa, assertArraysEquals(r, a, mask, FloatMaxVectorTests::SQRT); } + @Test(dataProvider = "floatUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((float)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Float.POSITIVE_INFINITY, x) == x + Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((float)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "floatUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + } + } + @Test(dataProvider = "floatCompareOpProvider") static void ltFloatMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int128VectorTests.java b/test/jdk/jdk/incubator/vector/Int128VectorTests.java index 0e5161604b394..0610984d39447 100644 --- a/test/jdk/jdk/incubator/vector/Int128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int128VectorTests.java @@ -66,6 +66,19 @@ public class Int128VectorTests extends AbstractVectorTest { private static final int CONST_SHIFT = Integer.SIZE / 2; + // Identity values for reduction operations + private static final int ADD_IDENTITY = (int)0; + private static final int AND_IDENTITY = (int)-1; + private static final int FIRST_NONZERO_IDENTITY = (int)0; + private static final int MAX_IDENTITY = Integer.MIN_VALUE; + private static final int MIN_IDENTITY = Integer.MAX_VALUE; + private static final int MUL_IDENTITY = (int)1; + private static final int OR_IDENTITY = (int)0; + private static final int SUADD_IDENTITY = (int)0; + private static final int UMAX_IDENTITY = (int)0; // Minimum unsigned value + private static final int UMIN_IDENTITY = (int)-1; // Maximum unsigned value + private static final int XOR_IDENTITY = (int)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); static void assertArraysStrictlyEquals(int[] r, int[] a) { @@ -3610,7 +3623,7 @@ static void SUADDAssocInt128VectorTestsMasked(IntFunction fa, IntFunction } static int ANDReduce(int[] a, int idx) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3619,7 +3632,7 @@ static int ANDReduce(int[] a, int idx) { } static int ANDReduceAll(int[] a) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3631,20 +3644,14 @@ static int ANDReduceAll(int[] a) { static void ANDReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3653,7 +3660,7 @@ static void ANDReduceInt128VectorTests(IntFunction fa) { } static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3663,7 +3670,7 @@ static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ANDReduceAllMasked(int[] a, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3677,20 +3684,14 @@ static void ANDReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3699,7 +3700,7 @@ static void ANDReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< } static int ORReduce(int[] a, int idx) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3708,7 +3709,7 @@ static int ORReduce(int[] a, int idx) { } static int ORReduceAll(int[] a) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3723,17 +3724,11 @@ static void ORReduceInt128VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3742,7 +3737,7 @@ static void ORReduceInt128VectorTests(IntFunction fa) { } static int ORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3752,7 +3747,7 @@ static int ORReduceMasked(int[] a, int idx, boolean[] mask) { } static int ORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3769,17 +3764,11 @@ static void ORReduceInt128VectorTestsMasked(IntFunction fa, IntFunction fa, IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3831,7 +3814,7 @@ static void XORReduceInt128VectorTests(IntFunction fa) { } static int XORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3841,7 +3824,7 @@ static int XORReduceMasked(int[] a, int idx, boolean[] mask) { } static int XORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3858,17 +3841,11 @@ static void XORReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3877,7 +3854,7 @@ static void XORReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< } static int ADDReduce(int[] a, int idx) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3886,7 +3863,7 @@ static int ADDReduce(int[] a, int idx) { } static int ADDReduceAll(int[] a) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3901,17 +3878,11 @@ static void ADDReduceInt128VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3920,7 +3891,7 @@ static void ADDReduceInt128VectorTests(IntFunction fa) { } static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3930,7 +3901,7 @@ static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3947,17 +3918,11 @@ static void ADDReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3966,7 +3931,7 @@ static void ADDReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< } static int MULReduce(int[] a, int idx) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3975,7 +3940,7 @@ static int MULReduce(int[] a, int idx) { } static int MULReduceAll(int[] a) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3987,20 +3952,14 @@ static int MULReduceAll(int[] a) { static void MULReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4009,7 +3968,7 @@ static void MULReduceInt128VectorTests(IntFunction fa) { } static int MULReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4019,7 +3978,7 @@ static int MULReduceMasked(int[] a, int idx, boolean[] mask) { } static int MULReduceAllMasked(int[] a, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4033,20 +3992,14 @@ static void MULReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4055,7 +4008,7 @@ static void MULReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< } static int MINReduce(int[] a, int idx) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) Math.min(res, a[i]); } @@ -4064,7 +4017,7 @@ static int MINReduce(int[] a, int idx) { } static int MINReduceAll(int[] a) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduce(a, i)); } @@ -4076,20 +4029,14 @@ static int MINReduceAll(int[] a) { static void MINReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (int) Math.min(ra, r[i]); } } @@ -4098,7 +4045,7 @@ static void MINReduceInt128VectorTests(IntFunction fa) { } static int MINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.min(res, a[i]); @@ -4108,7 +4055,7 @@ static int MINReduceMasked(int[] a, int idx, boolean[] mask) { } static int MINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4122,20 +4069,14 @@ static void MINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (int) Math.min(ra, r[i]); } } @@ -4144,7 +4085,7 @@ static void MINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< } static int MAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) Math.max(res, a[i]); } @@ -4153,7 +4094,7 @@ static int MAXReduce(int[] a, int idx) { } static int MAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduce(a, i)); } @@ -4165,20 +4106,14 @@ static int MAXReduceAll(int[] a) { static void MAXReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (int) Math.max(ra, r[i]); } } @@ -4187,7 +4122,7 @@ static void MAXReduceInt128VectorTests(IntFunction fa) { } static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.max(res, a[i]); @@ -4197,7 +4132,7 @@ static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int MAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4211,20 +4146,14 @@ static void MAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (int) Math.max(ra, r[i]); } } @@ -4233,7 +4162,7 @@ static void MAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< } static int UMINReduce(int[] a, int idx) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.minUnsigned(res, a[i]); } @@ -4242,7 +4171,7 @@ static int UMINReduce(int[] a, int idx) { } static int UMINReduceAll(int[] a) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4254,20 +4183,14 @@ static int UMINReduceAll(int[] a) { static void UMINReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4276,7 +4199,7 @@ static void UMINReduceInt128VectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4286,7 +4209,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4300,20 +4223,14 @@ static void UMINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4322,7 +4239,7 @@ static void UMINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction } static int UMAXReduce(int[] a, int idx) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4331,7 +4248,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4343,20 +4260,14 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4365,7 +4276,7 @@ static void UMAXReduceInt128VectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4375,7 +4286,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4389,20 +4300,14 @@ static void UMAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4411,7 +4316,7 @@ static void UMAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction } static int FIRST_NONZEROReduce(int[] a, int idx) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4420,7 +4325,7 @@ static int FIRST_NONZEROReduce(int[] a, int idx) { } static int FIRST_NONZEROReduceAll(int[] a) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4432,20 +4337,14 @@ static int FIRST_NONZEROReduceAll(int[] a) { static void FIRST_NONZEROReduceInt128VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4454,7 +4353,7 @@ static void FIRST_NONZEROReduceInt128VectorTests(IntFunction fa) { } static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4464,7 +4363,7 @@ static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { } static int FIRST_NONZEROReduceAllMasked(int[] a, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4478,20 +4377,14 @@ static void FIRST_NONZEROReduceInt128VectorTestsMasked(IntFunction fa, In int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4548,7 +4441,7 @@ static void allTrueInt128VectorTests(IntFunction fm) { } static int SUADDReduce(int[] a, int idx) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4557,7 +4450,7 @@ static int SUADDReduce(int[] a, int idx) { } static int SUADDReduceAll(int[] a) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4572,17 +4465,11 @@ static void SUADDReduceInt128VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4591,7 +4478,7 @@ static void SUADDReduceInt128VectorTests(IntFunction fa) { } static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4601,7 +4488,7 @@ static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int SUADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4617,17 +4504,11 @@ static void SUADDReduceInt128VectorTestsMasked(IntFunction fa, IntFunctio int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6434,6 +6315,93 @@ static void REVERSE_BYTESMaskedInt128VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Int128VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "intUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((int)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((int)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Integer.MIN_VALUE, x) == x + Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Integer.MAX_VALUE, x) == x + Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((int)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((int)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "intUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "intCompareOpProvider") static void ltInt128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int256VectorTests.java b/test/jdk/jdk/incubator/vector/Int256VectorTests.java index 2966537052744..e7309d1c9c6ca 100644 --- a/test/jdk/jdk/incubator/vector/Int256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int256VectorTests.java @@ -66,6 +66,19 @@ public class Int256VectorTests extends AbstractVectorTest { private static final int CONST_SHIFT = Integer.SIZE / 2; + // Identity values for reduction operations + private static final int ADD_IDENTITY = (int)0; + private static final int AND_IDENTITY = (int)-1; + private static final int FIRST_NONZERO_IDENTITY = (int)0; + private static final int MAX_IDENTITY = Integer.MIN_VALUE; + private static final int MIN_IDENTITY = Integer.MAX_VALUE; + private static final int MUL_IDENTITY = (int)1; + private static final int OR_IDENTITY = (int)0; + private static final int SUADD_IDENTITY = (int)0; + private static final int UMAX_IDENTITY = (int)0; // Minimum unsigned value + private static final int UMIN_IDENTITY = (int)-1; // Maximum unsigned value + private static final int XOR_IDENTITY = (int)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); static void assertArraysStrictlyEquals(int[] r, int[] a) { @@ -3610,7 +3623,7 @@ static void SUADDAssocInt256VectorTestsMasked(IntFunction fa, IntFunction } static int ANDReduce(int[] a, int idx) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3619,7 +3632,7 @@ static int ANDReduce(int[] a, int idx) { } static int ANDReduceAll(int[] a) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3631,20 +3644,14 @@ static int ANDReduceAll(int[] a) { static void ANDReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3653,7 +3660,7 @@ static void ANDReduceInt256VectorTests(IntFunction fa) { } static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3663,7 +3670,7 @@ static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ANDReduceAllMasked(int[] a, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3677,20 +3684,14 @@ static void ANDReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3699,7 +3700,7 @@ static void ANDReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< } static int ORReduce(int[] a, int idx) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3708,7 +3709,7 @@ static int ORReduce(int[] a, int idx) { } static int ORReduceAll(int[] a) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3723,17 +3724,11 @@ static void ORReduceInt256VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3742,7 +3737,7 @@ static void ORReduceInt256VectorTests(IntFunction fa) { } static int ORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3752,7 +3747,7 @@ static int ORReduceMasked(int[] a, int idx, boolean[] mask) { } static int ORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3769,17 +3764,11 @@ static void ORReduceInt256VectorTestsMasked(IntFunction fa, IntFunction fa, IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3831,7 +3814,7 @@ static void XORReduceInt256VectorTests(IntFunction fa) { } static int XORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3841,7 +3824,7 @@ static int XORReduceMasked(int[] a, int idx, boolean[] mask) { } static int XORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3858,17 +3841,11 @@ static void XORReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3877,7 +3854,7 @@ static void XORReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< } static int ADDReduce(int[] a, int idx) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3886,7 +3863,7 @@ static int ADDReduce(int[] a, int idx) { } static int ADDReduceAll(int[] a) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3901,17 +3878,11 @@ static void ADDReduceInt256VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3920,7 +3891,7 @@ static void ADDReduceInt256VectorTests(IntFunction fa) { } static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3930,7 +3901,7 @@ static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3947,17 +3918,11 @@ static void ADDReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3966,7 +3931,7 @@ static void ADDReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< } static int MULReduce(int[] a, int idx) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3975,7 +3940,7 @@ static int MULReduce(int[] a, int idx) { } static int MULReduceAll(int[] a) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3987,20 +3952,14 @@ static int MULReduceAll(int[] a) { static void MULReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4009,7 +3968,7 @@ static void MULReduceInt256VectorTests(IntFunction fa) { } static int MULReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4019,7 +3978,7 @@ static int MULReduceMasked(int[] a, int idx, boolean[] mask) { } static int MULReduceAllMasked(int[] a, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4033,20 +3992,14 @@ static void MULReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4055,7 +4008,7 @@ static void MULReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< } static int MINReduce(int[] a, int idx) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) Math.min(res, a[i]); } @@ -4064,7 +4017,7 @@ static int MINReduce(int[] a, int idx) { } static int MINReduceAll(int[] a) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduce(a, i)); } @@ -4076,20 +4029,14 @@ static int MINReduceAll(int[] a) { static void MINReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (int) Math.min(ra, r[i]); } } @@ -4098,7 +4045,7 @@ static void MINReduceInt256VectorTests(IntFunction fa) { } static int MINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.min(res, a[i]); @@ -4108,7 +4055,7 @@ static int MINReduceMasked(int[] a, int idx, boolean[] mask) { } static int MINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4122,20 +4069,14 @@ static void MINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (int) Math.min(ra, r[i]); } } @@ -4144,7 +4085,7 @@ static void MINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< } static int MAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) Math.max(res, a[i]); } @@ -4153,7 +4094,7 @@ static int MAXReduce(int[] a, int idx) { } static int MAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduce(a, i)); } @@ -4165,20 +4106,14 @@ static int MAXReduceAll(int[] a) { static void MAXReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (int) Math.max(ra, r[i]); } } @@ -4187,7 +4122,7 @@ static void MAXReduceInt256VectorTests(IntFunction fa) { } static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.max(res, a[i]); @@ -4197,7 +4132,7 @@ static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int MAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4211,20 +4146,14 @@ static void MAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (int) Math.max(ra, r[i]); } } @@ -4233,7 +4162,7 @@ static void MAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< } static int UMINReduce(int[] a, int idx) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.minUnsigned(res, a[i]); } @@ -4242,7 +4171,7 @@ static int UMINReduce(int[] a, int idx) { } static int UMINReduceAll(int[] a) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4254,20 +4183,14 @@ static int UMINReduceAll(int[] a) { static void UMINReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4276,7 +4199,7 @@ static void UMINReduceInt256VectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4286,7 +4209,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4300,20 +4223,14 @@ static void UMINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4322,7 +4239,7 @@ static void UMINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction } static int UMAXReduce(int[] a, int idx) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4331,7 +4248,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4343,20 +4260,14 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4365,7 +4276,7 @@ static void UMAXReduceInt256VectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4375,7 +4286,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4389,20 +4300,14 @@ static void UMAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4411,7 +4316,7 @@ static void UMAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction } static int FIRST_NONZEROReduce(int[] a, int idx) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4420,7 +4325,7 @@ static int FIRST_NONZEROReduce(int[] a, int idx) { } static int FIRST_NONZEROReduceAll(int[] a) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4432,20 +4337,14 @@ static int FIRST_NONZEROReduceAll(int[] a) { static void FIRST_NONZEROReduceInt256VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4454,7 +4353,7 @@ static void FIRST_NONZEROReduceInt256VectorTests(IntFunction fa) { } static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4464,7 +4363,7 @@ static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { } static int FIRST_NONZEROReduceAllMasked(int[] a, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4478,20 +4377,14 @@ static void FIRST_NONZEROReduceInt256VectorTestsMasked(IntFunction fa, In int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4548,7 +4441,7 @@ static void allTrueInt256VectorTests(IntFunction fm) { } static int SUADDReduce(int[] a, int idx) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4557,7 +4450,7 @@ static int SUADDReduce(int[] a, int idx) { } static int SUADDReduceAll(int[] a) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4572,17 +4465,11 @@ static void SUADDReduceInt256VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4591,7 +4478,7 @@ static void SUADDReduceInt256VectorTests(IntFunction fa) { } static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4601,7 +4488,7 @@ static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int SUADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4617,17 +4504,11 @@ static void SUADDReduceInt256VectorTestsMasked(IntFunction fa, IntFunctio int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6434,6 +6315,93 @@ static void REVERSE_BYTESMaskedInt256VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Int256VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "intUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((int)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((int)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Integer.MIN_VALUE, x) == x + Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Integer.MAX_VALUE, x) == x + Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((int)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((int)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "intUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "intCompareOpProvider") static void ltInt256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int512VectorTests.java b/test/jdk/jdk/incubator/vector/Int512VectorTests.java index f6af7d0ac0f30..d61c55e397ab9 100644 --- a/test/jdk/jdk/incubator/vector/Int512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int512VectorTests.java @@ -66,6 +66,19 @@ public class Int512VectorTests extends AbstractVectorTest { private static final int CONST_SHIFT = Integer.SIZE / 2; + // Identity values for reduction operations + private static final int ADD_IDENTITY = (int)0; + private static final int AND_IDENTITY = (int)-1; + private static final int FIRST_NONZERO_IDENTITY = (int)0; + private static final int MAX_IDENTITY = Integer.MIN_VALUE; + private static final int MIN_IDENTITY = Integer.MAX_VALUE; + private static final int MUL_IDENTITY = (int)1; + private static final int OR_IDENTITY = (int)0; + private static final int SUADD_IDENTITY = (int)0; + private static final int UMAX_IDENTITY = (int)0; // Minimum unsigned value + private static final int UMIN_IDENTITY = (int)-1; // Maximum unsigned value + private static final int XOR_IDENTITY = (int)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); static void assertArraysStrictlyEquals(int[] r, int[] a) { @@ -3610,7 +3623,7 @@ static void SUADDAssocInt512VectorTestsMasked(IntFunction fa, IntFunction } static int ANDReduce(int[] a, int idx) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3619,7 +3632,7 @@ static int ANDReduce(int[] a, int idx) { } static int ANDReduceAll(int[] a) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3631,20 +3644,14 @@ static int ANDReduceAll(int[] a) { static void ANDReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3653,7 +3660,7 @@ static void ANDReduceInt512VectorTests(IntFunction fa) { } static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3663,7 +3670,7 @@ static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ANDReduceAllMasked(int[] a, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3677,20 +3684,14 @@ static void ANDReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3699,7 +3700,7 @@ static void ANDReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< } static int ORReduce(int[] a, int idx) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3708,7 +3709,7 @@ static int ORReduce(int[] a, int idx) { } static int ORReduceAll(int[] a) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3723,17 +3724,11 @@ static void ORReduceInt512VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3742,7 +3737,7 @@ static void ORReduceInt512VectorTests(IntFunction fa) { } static int ORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3752,7 +3747,7 @@ static int ORReduceMasked(int[] a, int idx, boolean[] mask) { } static int ORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3769,17 +3764,11 @@ static void ORReduceInt512VectorTestsMasked(IntFunction fa, IntFunction fa, IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3831,7 +3814,7 @@ static void XORReduceInt512VectorTests(IntFunction fa) { } static int XORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3841,7 +3824,7 @@ static int XORReduceMasked(int[] a, int idx, boolean[] mask) { } static int XORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3858,17 +3841,11 @@ static void XORReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3877,7 +3854,7 @@ static void XORReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< } static int ADDReduce(int[] a, int idx) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3886,7 +3863,7 @@ static int ADDReduce(int[] a, int idx) { } static int ADDReduceAll(int[] a) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3901,17 +3878,11 @@ static void ADDReduceInt512VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3920,7 +3891,7 @@ static void ADDReduceInt512VectorTests(IntFunction fa) { } static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3930,7 +3901,7 @@ static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3947,17 +3918,11 @@ static void ADDReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3966,7 +3931,7 @@ static void ADDReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< } static int MULReduce(int[] a, int idx) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3975,7 +3940,7 @@ static int MULReduce(int[] a, int idx) { } static int MULReduceAll(int[] a) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3987,20 +3952,14 @@ static int MULReduceAll(int[] a) { static void MULReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4009,7 +3968,7 @@ static void MULReduceInt512VectorTests(IntFunction fa) { } static int MULReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4019,7 +3978,7 @@ static int MULReduceMasked(int[] a, int idx, boolean[] mask) { } static int MULReduceAllMasked(int[] a, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4033,20 +3992,14 @@ static void MULReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4055,7 +4008,7 @@ static void MULReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< } static int MINReduce(int[] a, int idx) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) Math.min(res, a[i]); } @@ -4064,7 +4017,7 @@ static int MINReduce(int[] a, int idx) { } static int MINReduceAll(int[] a) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduce(a, i)); } @@ -4076,20 +4029,14 @@ static int MINReduceAll(int[] a) { static void MINReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (int) Math.min(ra, r[i]); } } @@ -4098,7 +4045,7 @@ static void MINReduceInt512VectorTests(IntFunction fa) { } static int MINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.min(res, a[i]); @@ -4108,7 +4055,7 @@ static int MINReduceMasked(int[] a, int idx, boolean[] mask) { } static int MINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4122,20 +4069,14 @@ static void MINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (int) Math.min(ra, r[i]); } } @@ -4144,7 +4085,7 @@ static void MINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< } static int MAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) Math.max(res, a[i]); } @@ -4153,7 +4094,7 @@ static int MAXReduce(int[] a, int idx) { } static int MAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduce(a, i)); } @@ -4165,20 +4106,14 @@ static int MAXReduceAll(int[] a) { static void MAXReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (int) Math.max(ra, r[i]); } } @@ -4187,7 +4122,7 @@ static void MAXReduceInt512VectorTests(IntFunction fa) { } static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.max(res, a[i]); @@ -4197,7 +4132,7 @@ static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int MAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4211,20 +4146,14 @@ static void MAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (int) Math.max(ra, r[i]); } } @@ -4233,7 +4162,7 @@ static void MAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< } static int UMINReduce(int[] a, int idx) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.minUnsigned(res, a[i]); } @@ -4242,7 +4171,7 @@ static int UMINReduce(int[] a, int idx) { } static int UMINReduceAll(int[] a) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4254,20 +4183,14 @@ static int UMINReduceAll(int[] a) { static void UMINReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4276,7 +4199,7 @@ static void UMINReduceInt512VectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4286,7 +4209,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4300,20 +4223,14 @@ static void UMINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4322,7 +4239,7 @@ static void UMINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction } static int UMAXReduce(int[] a, int idx) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4331,7 +4248,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4343,20 +4260,14 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4365,7 +4276,7 @@ static void UMAXReduceInt512VectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4375,7 +4286,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4389,20 +4300,14 @@ static void UMAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4411,7 +4316,7 @@ static void UMAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction } static int FIRST_NONZEROReduce(int[] a, int idx) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4420,7 +4325,7 @@ static int FIRST_NONZEROReduce(int[] a, int idx) { } static int FIRST_NONZEROReduceAll(int[] a) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4432,20 +4337,14 @@ static int FIRST_NONZEROReduceAll(int[] a) { static void FIRST_NONZEROReduceInt512VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4454,7 +4353,7 @@ static void FIRST_NONZEROReduceInt512VectorTests(IntFunction fa) { } static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4464,7 +4363,7 @@ static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { } static int FIRST_NONZEROReduceAllMasked(int[] a, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4478,20 +4377,14 @@ static void FIRST_NONZEROReduceInt512VectorTestsMasked(IntFunction fa, In int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4548,7 +4441,7 @@ static void allTrueInt512VectorTests(IntFunction fm) { } static int SUADDReduce(int[] a, int idx) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4557,7 +4450,7 @@ static int SUADDReduce(int[] a, int idx) { } static int SUADDReduceAll(int[] a) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4572,17 +4465,11 @@ static void SUADDReduceInt512VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4591,7 +4478,7 @@ static void SUADDReduceInt512VectorTests(IntFunction fa) { } static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4601,7 +4488,7 @@ static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int SUADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4617,17 +4504,11 @@ static void SUADDReduceInt512VectorTestsMasked(IntFunction fa, IntFunctio int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6434,6 +6315,93 @@ static void REVERSE_BYTESMaskedInt512VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Int512VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "intUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((int)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((int)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Integer.MIN_VALUE, x) == x + Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Integer.MAX_VALUE, x) == x + Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((int)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((int)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "intUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "intCompareOpProvider") static void ltInt512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int64VectorTests.java b/test/jdk/jdk/incubator/vector/Int64VectorTests.java index 8a3d69f7a7e26..7efdb85c178ed 100644 --- a/test/jdk/jdk/incubator/vector/Int64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int64VectorTests.java @@ -66,6 +66,19 @@ public class Int64VectorTests extends AbstractVectorTest { private static final int CONST_SHIFT = Integer.SIZE / 2; + // Identity values for reduction operations + private static final int ADD_IDENTITY = (int)0; + private static final int AND_IDENTITY = (int)-1; + private static final int FIRST_NONZERO_IDENTITY = (int)0; + private static final int MAX_IDENTITY = Integer.MIN_VALUE; + private static final int MIN_IDENTITY = Integer.MAX_VALUE; + private static final int MUL_IDENTITY = (int)1; + private static final int OR_IDENTITY = (int)0; + private static final int SUADD_IDENTITY = (int)0; + private static final int UMAX_IDENTITY = (int)0; // Minimum unsigned value + private static final int UMIN_IDENTITY = (int)-1; // Maximum unsigned value + private static final int XOR_IDENTITY = (int)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); static void assertArraysStrictlyEquals(int[] r, int[] a) { @@ -3610,7 +3623,7 @@ static void SUADDAssocInt64VectorTestsMasked(IntFunction fa, IntFunction< } static int ANDReduce(int[] a, int idx) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3619,7 +3632,7 @@ static int ANDReduce(int[] a, int idx) { } static int ANDReduceAll(int[] a) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3631,20 +3644,14 @@ static int ANDReduceAll(int[] a) { static void ANDReduceInt64VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3653,7 +3660,7 @@ static void ANDReduceInt64VectorTests(IntFunction fa) { } static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3663,7 +3670,7 @@ static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ANDReduceAllMasked(int[] a, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3677,20 +3684,14 @@ static void ANDReduceInt64VectorTestsMasked(IntFunction fa, IntFunction vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3699,7 +3700,7 @@ static void ANDReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3742,7 +3737,7 @@ static void ORReduceInt64VectorTests(IntFunction fa) { } static int ORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3752,7 +3747,7 @@ static int ORReduceMasked(int[] a, int idx, boolean[] mask) { } static int ORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3769,17 +3764,11 @@ static void ORReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa, IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3831,7 +3814,7 @@ static void XORReduceInt64VectorTests(IntFunction fa) { } static int XORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3841,7 +3824,7 @@ static int XORReduceMasked(int[] a, int idx, boolean[] mask) { } static int XORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3858,17 +3841,11 @@ static void XORReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa, IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3920,7 +3891,7 @@ static void ADDReduceInt64VectorTests(IntFunction fa) { } static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3930,7 +3901,7 @@ static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3947,17 +3918,11 @@ static void ADDReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa, IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4009,7 +3968,7 @@ static void MULReduceInt64VectorTests(IntFunction fa) { } static int MULReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4019,7 +3978,7 @@ static int MULReduceMasked(int[] a, int idx, boolean[] mask) { } static int MULReduceAllMasked(int[] a, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4033,20 +3992,14 @@ static void MULReduceInt64VectorTestsMasked(IntFunction fa, IntFunction vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4055,7 +4008,7 @@ static void MULReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (int) Math.min(ra, r[i]); } } @@ -4098,7 +4045,7 @@ static void MINReduceInt64VectorTests(IntFunction fa) { } static int MINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.min(res, a[i]); @@ -4108,7 +4055,7 @@ static int MINReduceMasked(int[] a, int idx, boolean[] mask) { } static int MINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4122,20 +4069,14 @@ static void MINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (int) Math.min(ra, r[i]); } } @@ -4144,7 +4085,7 @@ static void MINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (int) Math.max(ra, r[i]); } } @@ -4187,7 +4122,7 @@ static void MAXReduceInt64VectorTests(IntFunction fa) { } static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.max(res, a[i]); @@ -4197,7 +4132,7 @@ static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int MAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4211,20 +4146,14 @@ static void MAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (int) Math.max(ra, r[i]); } } @@ -4233,7 +4162,7 @@ static void MAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4276,7 +4199,7 @@ static void UMINReduceInt64VectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4286,7 +4209,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4300,20 +4223,14 @@ static void UMINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4322,7 +4239,7 @@ static void UMINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< } static int UMAXReduce(int[] a, int idx) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4331,7 +4248,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4343,20 +4260,14 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceInt64VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4365,7 +4276,7 @@ static void UMAXReduceInt64VectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4375,7 +4286,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4389,20 +4300,14 @@ static void UMAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4411,7 +4316,7 @@ static void UMAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< } static int FIRST_NONZEROReduce(int[] a, int idx) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4420,7 +4325,7 @@ static int FIRST_NONZEROReduce(int[] a, int idx) { } static int FIRST_NONZEROReduceAll(int[] a) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4432,20 +4337,14 @@ static int FIRST_NONZEROReduceAll(int[] a) { static void FIRST_NONZEROReduceInt64VectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4454,7 +4353,7 @@ static void FIRST_NONZEROReduceInt64VectorTests(IntFunction fa) { } static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4464,7 +4363,7 @@ static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { } static int FIRST_NONZEROReduceAllMasked(int[] a, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4478,20 +4377,14 @@ static void FIRST_NONZEROReduceInt64VectorTestsMasked(IntFunction fa, Int int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4548,7 +4441,7 @@ static void allTrueInt64VectorTests(IntFunction fm) { } static int SUADDReduce(int[] a, int idx) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4557,7 +4450,7 @@ static int SUADDReduce(int[] a, int idx) { } static int SUADDReduceAll(int[] a) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4572,17 +4465,11 @@ static void SUADDReduceInt64VectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4591,7 +4478,7 @@ static void SUADDReduceInt64VectorTests(IntFunction fa) { } static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4601,7 +4488,7 @@ static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int SUADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4617,17 +4504,11 @@ static void SUADDReduceInt64VectorTestsMasked(IntFunction fa, IntFunction int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6434,6 +6315,93 @@ static void REVERSE_BYTESMaskedInt64VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Int64VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "intUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((int)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((int)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Integer.MIN_VALUE, x) == x + Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Integer.MAX_VALUE, x) == x + Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((int)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((int)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "intUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "intCompareOpProvider") static void ltInt64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java index 76c204b860d7c..e07c1ce402e40 100644 --- a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java @@ -71,6 +71,19 @@ static VectorShape getMaxBit() { private static final int CONST_SHIFT = Integer.SIZE / 2; + // Identity values for reduction operations + private static final int ADD_IDENTITY = (int)0; + private static final int AND_IDENTITY = (int)-1; + private static final int FIRST_NONZERO_IDENTITY = (int)0; + private static final int MAX_IDENTITY = Integer.MIN_VALUE; + private static final int MIN_IDENTITY = Integer.MAX_VALUE; + private static final int MUL_IDENTITY = (int)1; + private static final int OR_IDENTITY = (int)0; + private static final int SUADD_IDENTITY = (int)0; + private static final int UMAX_IDENTITY = (int)0; // Minimum unsigned value + private static final int UMIN_IDENTITY = (int)-1; // Maximum unsigned value + private static final int XOR_IDENTITY = (int)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); static void assertArraysStrictlyEquals(int[] r, int[] a) { @@ -3615,7 +3628,7 @@ static void SUADDAssocIntMaxVectorTestsMasked(IntFunction fa, IntFunction } static int ANDReduce(int[] a, int idx) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3624,7 +3637,7 @@ static int ANDReduce(int[] a, int idx) { } static int ANDReduceAll(int[] a) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3636,20 +3649,14 @@ static int ANDReduceAll(int[] a) { static void ANDReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3658,7 +3665,7 @@ static void ANDReduceIntMaxVectorTests(IntFunction fa) { } static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3668,7 +3675,7 @@ static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ANDReduceAllMasked(int[] a, boolean[] mask) { - int res = -1; + int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3682,20 +3689,14 @@ static void ANDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = -1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3704,7 +3705,7 @@ static void ANDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< } static int ORReduce(int[] a, int idx) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3713,7 +3714,7 @@ static int ORReduce(int[] a, int idx) { } static int ORReduceAll(int[] a) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3728,17 +3729,11 @@ static void ORReduceIntMaxVectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3747,7 +3742,7 @@ static void ORReduceIntMaxVectorTests(IntFunction fa) { } static int ORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3757,7 +3752,7 @@ static int ORReduceMasked(int[] a, int idx, boolean[] mask) { } static int ORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3774,17 +3769,11 @@ static void ORReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction fa, IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3836,7 +3819,7 @@ static void XORReduceIntMaxVectorTests(IntFunction fa) { } static int XORReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3846,7 +3829,7 @@ static int XORReduceMasked(int[] a, int idx, boolean[] mask) { } static int XORReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3863,17 +3846,11 @@ static void XORReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3882,7 +3859,7 @@ static void XORReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< } static int ADDReduce(int[] a, int idx) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3891,7 +3868,7 @@ static int ADDReduce(int[] a, int idx) { } static int ADDReduceAll(int[] a) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3906,17 +3883,11 @@ static void ADDReduceIntMaxVectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3925,7 +3896,7 @@ static void ADDReduceIntMaxVectorTests(IntFunction fa) { } static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3935,7 +3906,7 @@ static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int ADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3952,17 +3923,11 @@ static void ADDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3971,7 +3936,7 @@ static void ADDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< } static int MULReduce(int[] a, int idx) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3980,7 +3945,7 @@ static int MULReduce(int[] a, int idx) { } static int MULReduceAll(int[] a) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3992,20 +3957,14 @@ static int MULReduceAll(int[] a) { static void MULReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4014,7 +3973,7 @@ static void MULReduceIntMaxVectorTests(IntFunction fa) { } static int MULReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4024,7 +3983,7 @@ static int MULReduceMasked(int[] a, int idx, boolean[] mask) { } static int MULReduceAllMasked(int[] a, boolean[] mask) { - int res = 1; + int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4038,20 +3997,14 @@ static void MULReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = 1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4060,7 +4013,7 @@ static void MULReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< } static int MINReduce(int[] a, int idx) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) Math.min(res, a[i]); } @@ -4069,7 +4022,7 @@ static int MINReduce(int[] a, int idx) { } static int MINReduceAll(int[] a) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduce(a, i)); } @@ -4081,20 +4034,14 @@ static int MINReduceAll(int[] a) { static void MINReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (int) Math.min(ra, r[i]); } } @@ -4103,7 +4050,7 @@ static void MINReduceIntMaxVectorTests(IntFunction fa) { } static int MINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.min(res, a[i]); @@ -4113,7 +4060,7 @@ static int MINReduceMasked(int[] a, int idx, boolean[] mask) { } static int MINReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MAX_VALUE; + int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4127,20 +4074,14 @@ static void MINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MAX_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (int) Math.min(ra, r[i]); } } @@ -4149,7 +4090,7 @@ static void MINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< } static int MAXReduce(int[] a, int idx) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) Math.max(res, a[i]); } @@ -4158,7 +4099,7 @@ static int MAXReduce(int[] a, int idx) { } static int MAXReduceAll(int[] a) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduce(a, i)); } @@ -4170,20 +4111,14 @@ static int MAXReduceAll(int[] a) { static void MAXReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (int) Math.max(ra, r[i]); } } @@ -4192,7 +4127,7 @@ static void MAXReduceIntMaxVectorTests(IntFunction fa) { } static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) Math.max(res, a[i]); @@ -4202,7 +4137,7 @@ static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int MAXReduceAllMasked(int[] a, boolean[] mask) { - int res = Integer.MIN_VALUE; + int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4216,20 +4151,14 @@ static void MAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = Integer.MIN_VALUE; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (int) Math.max(ra, r[i]); } } @@ -4238,7 +4167,7 @@ static void MAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< } static int UMINReduce(int[] a, int idx) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.minUnsigned(res, a[i]); } @@ -4247,7 +4176,7 @@ static int UMINReduce(int[] a, int idx) { } static int UMINReduceAll(int[] a) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4259,20 +4188,14 @@ static int UMINReduceAll(int[] a) { static void UMINReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4281,7 +4204,7 @@ static void UMINReduceIntMaxVectorTests(IntFunction fa) { } static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.minUnsigned(res, a[i]); @@ -4291,7 +4214,7 @@ static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMINReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)-1; + int res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4305,20 +4228,14 @@ static void UMINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)-1; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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 = (int)-1; - 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)); + ra = (int) VectorMath.minUnsigned(ra, r[i]); } } @@ -4327,7 +4244,7 @@ static void UMINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction } static int UMAXReduce(int[] a, int idx) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.maxUnsigned(res, a[i]); } @@ -4336,7 +4253,7 @@ static int UMAXReduce(int[] a, int idx) { } static int UMAXReduceAll(int[] a) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4348,20 +4265,14 @@ static int UMAXReduceAll(int[] a) { static void UMAXReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4370,7 +4281,7 @@ static void UMAXReduceIntMaxVectorTests(IntFunction fa) { } static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.maxUnsigned(res, a[i]); @@ -4380,7 +4291,7 @@ static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { } static int UMAXReduceAllMasked(int[] a, boolean[] mask) { - int res = (int)0; + int res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4394,20 +4305,14 @@ static void UMAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int)0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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 = (int)0; - 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)); + ra = (int) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4416,7 +4321,7 @@ static void UMAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction } static int FIRST_NONZEROReduce(int[] a, int idx) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4425,7 +4330,7 @@ static int FIRST_NONZEROReduce(int[] a, int idx) { } static int FIRST_NONZEROReduceAll(int[] a) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4437,20 +4342,14 @@ static int FIRST_NONZEROReduceAll(int[] a) { static void FIRST_NONZEROReduceIntMaxVectorTests(IntFunction fa) { int[] a = fa.apply(SPECIES.length()); int[] r = fr.apply(SPECIES.length()); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4459,7 +4358,7 @@ static void FIRST_NONZEROReduceIntMaxVectorTests(IntFunction fa) { } static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4469,7 +4368,7 @@ static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { } static int FIRST_NONZEROReduceAllMasked(int[] a, boolean[] mask) { - int res = (int) 0; + int res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4483,20 +4382,14 @@ static void FIRST_NONZEROReduceIntMaxVectorTestsMasked(IntFunction fa, In int[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - int ra = (int) 0; + int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (int) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4553,7 +4446,7 @@ static void allTrueIntMaxVectorTests(IntFunction fm) { } static int SUADDReduce(int[] a, int idx) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4562,7 +4455,7 @@ static int SUADDReduce(int[] a, int idx) { } static int SUADDReduceAll(int[] a) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4577,17 +4470,11 @@ static void SUADDReduceIntMaxVectorTests(IntFunction fa) { int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4596,7 +4483,7 @@ static void SUADDReduceIntMaxVectorTests(IntFunction fa) { } static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (int) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4606,7 +4493,7 @@ static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { } static int SUADDReduceAllMasked(int[] a, boolean[] mask) { - int res = 0; + int res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (int) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4622,17 +4509,11 @@ static void SUADDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunctio int ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - ra = (int) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6439,6 +6320,93 @@ static void REVERSE_BYTESMaskedIntMaxVectorTests(IntFunction fa, assertArraysEquals(r, a, mask, IntMaxVectorTests::REVERSE_BYTES); } + @Test(dataProvider = "intUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((int)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((int)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Integer.MIN_VALUE, x) == x + Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Integer.MAX_VALUE, x) == x + Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((int)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((int)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "intUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + IntVector av = IntVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "intCompareOpProvider") static void ltIntMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long128VectorTests.java b/test/jdk/jdk/incubator/vector/Long128VectorTests.java index 7a4f0c464a53d..ab25addcd714b 100644 --- a/test/jdk/jdk/incubator/vector/Long128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long128VectorTests.java @@ -66,6 +66,19 @@ public class Long128VectorTests extends AbstractVectorTest { private static final long CONST_SHIFT = Long.SIZE / 2; + // Identity values for reduction operations + private static final long ADD_IDENTITY = (long)0; + private static final long AND_IDENTITY = (long)-1; + private static final long FIRST_NONZERO_IDENTITY = (long)0; + private static final long MAX_IDENTITY = Long.MIN_VALUE; + private static final long MIN_IDENTITY = Long.MAX_VALUE; + private static final long MUL_IDENTITY = (long)1; + private static final long OR_IDENTITY = (long)0; + private static final long SUADD_IDENTITY = (long)0; + private static final long UMAX_IDENTITY = (long)0; // Minimum unsigned value + private static final long UMIN_IDENTITY = (long)-1; // Maximum unsigned value + private static final long XOR_IDENTITY = (long)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); static void assertArraysStrictlyEquals(long[] r, long[] a) { @@ -3632,7 +3645,7 @@ static void SUADDAssocLong128VectorTestsMasked(IntFunction fa, IntFuncti } static long ANDReduce(long[] a, int idx) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3641,7 +3654,7 @@ static long ANDReduce(long[] a, int idx) { } static long ANDReduceAll(long[] a) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3653,20 +3666,14 @@ static long ANDReduceAll(long[] a) { static void ANDReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3675,7 +3682,7 @@ static void ANDReduceLong128VectorTests(IntFunction fa) { } static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3685,7 +3692,7 @@ static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ANDReduceAllMasked(long[] a, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3699,20 +3706,14 @@ static void ANDReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3721,7 +3722,7 @@ static void ANDReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio } static long ORReduce(long[] a, int idx) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3730,7 +3731,7 @@ static long ORReduce(long[] a, int idx) { } static long ORReduceAll(long[] a) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3745,17 +3746,11 @@ static void ORReduceLong128VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3764,7 +3759,7 @@ static void ORReduceLong128VectorTests(IntFunction fa) { } static long ORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3774,7 +3769,7 @@ static long ORReduceMasked(long[] a, int idx, boolean[] mask) { } static long ORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3791,17 +3786,11 @@ static void ORReduceLong128VectorTestsMasked(IntFunction fa, IntFunction long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3810,7 +3799,7 @@ static void ORReduceLong128VectorTestsMasked(IntFunction fa, IntFunction } static long XORReduce(long[] a, int idx) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3819,7 +3808,7 @@ static long XORReduce(long[] a, int idx) { } static long XORReduceAll(long[] a) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3834,17 +3823,11 @@ static void XORReduceLong128VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3853,7 +3836,7 @@ static void XORReduceLong128VectorTests(IntFunction fa) { } static long XORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3863,7 +3846,7 @@ static long XORReduceMasked(long[] a, int idx, boolean[] mask) { } static long XORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3880,17 +3863,11 @@ static void XORReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3899,7 +3876,7 @@ static void XORReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio } static long ADDReduce(long[] a, int idx) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3908,7 +3885,7 @@ static long ADDReduce(long[] a, int idx) { } static long ADDReduceAll(long[] a) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3923,17 +3900,11 @@ static void ADDReduceLong128VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3942,7 +3913,7 @@ static void ADDReduceLong128VectorTests(IntFunction fa) { } static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3952,7 +3923,7 @@ static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3969,17 +3940,11 @@ static void ADDReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3988,7 +3953,7 @@ static void ADDReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio } static long MULReduce(long[] a, int idx) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3997,7 +3962,7 @@ static long MULReduce(long[] a, int idx) { } static long MULReduceAll(long[] a) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -4009,20 +3974,14 @@ static long MULReduceAll(long[] a) { static void MULReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4031,7 +3990,7 @@ static void MULReduceLong128VectorTests(IntFunction fa) { } static long MULReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4041,7 +4000,7 @@ static long MULReduceMasked(long[] a, int idx, boolean[] mask) { } static long MULReduceAllMasked(long[] a, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4055,20 +4014,14 @@ static void MULReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4077,7 +4030,7 @@ static void MULReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio } static long MINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.min(res, a[i]); } @@ -4086,7 +4039,7 @@ static long MINReduce(long[] a, int idx) { } static long MINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduce(a, i)); } @@ -4098,20 +4051,14 @@ static long MINReduceAll(long[] a) { static void MINReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (long) Math.min(ra, r[i]); } } @@ -4120,7 +4067,7 @@ static void MINReduceLong128VectorTests(IntFunction fa) { } static long MINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.min(res, a[i]); @@ -4130,7 +4077,7 @@ static long MINReduceMasked(long[] a, int idx, boolean[] mask) { } static long MINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4144,20 +4091,14 @@ static void MINReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (long) Math.min(ra, r[i]); } } @@ -4166,7 +4107,7 @@ static void MINReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio } static long MAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.max(res, a[i]); } @@ -4175,7 +4116,7 @@ static long MAXReduce(long[] a, int idx) { } static long MAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduce(a, i)); } @@ -4187,20 +4128,14 @@ static long MAXReduceAll(long[] a) { static void MAXReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (long) Math.max(ra, r[i]); } } @@ -4209,7 +4144,7 @@ static void MAXReduceLong128VectorTests(IntFunction fa) { } static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.max(res, a[i]); @@ -4219,7 +4154,7 @@ static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long MAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4233,20 +4168,14 @@ static void MAXReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (long) Math.max(ra, r[i]); } } @@ -4255,7 +4184,7 @@ static void MAXReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio } static long UMINReduce(long[] a, int idx) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4264,7 +4193,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4276,20 +4205,14 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4298,7 +4221,7 @@ static void UMINReduceLong128VectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4308,7 +4231,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4322,20 +4245,14 @@ static void UMINReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4344,7 +4261,7 @@ static void UMINReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti } static long UMAXReduce(long[] a, int idx) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4353,7 +4270,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4365,20 +4282,14 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4387,7 +4298,7 @@ static void UMAXReduceLong128VectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4397,7 +4308,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4411,20 +4322,14 @@ static void UMAXReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4433,7 +4338,7 @@ static void UMAXReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti } static long FIRST_NONZEROReduce(long[] a, int idx) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4442,7 +4347,7 @@ static long FIRST_NONZEROReduce(long[] a, int idx) { } static long FIRST_NONZEROReduceAll(long[] a) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4454,20 +4359,14 @@ static long FIRST_NONZEROReduceAll(long[] a) { static void FIRST_NONZEROReduceLong128VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4476,7 +4375,7 @@ static void FIRST_NONZEROReduceLong128VectorTests(IntFunction fa) { } static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4486,7 +4385,7 @@ static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { } static long FIRST_NONZEROReduceAllMasked(long[] a, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4500,20 +4399,14 @@ static void FIRST_NONZEROReduceLong128VectorTestsMasked(IntFunction fa, long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4570,7 +4463,7 @@ static void allTrueLong128VectorTests(IntFunction fm) { } static long SUADDReduce(long[] a, int idx) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4579,7 +4472,7 @@ static long SUADDReduce(long[] a, int idx) { } static long SUADDReduceAll(long[] a) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4594,17 +4487,11 @@ static void SUADDReduceLong128VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4613,7 +4500,7 @@ static void SUADDReduceLong128VectorTests(IntFunction fa) { } static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4623,7 +4510,7 @@ static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long SUADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4639,17 +4526,11 @@ static void SUADDReduceLong128VectorTestsMasked(IntFunction fa, IntFunct long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6386,6 +6267,93 @@ static void REVERSE_BYTESMaskedLong128VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Long128VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "longUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((long)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((long)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Long.MIN_VALUE, x) == x + Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Long.MAX_VALUE, x) == x + Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((long)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((long)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "longUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "longCompareOpProvider") static void ltLong128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long256VectorTests.java b/test/jdk/jdk/incubator/vector/Long256VectorTests.java index 41b705c338c4d..e8da5328f2891 100644 --- a/test/jdk/jdk/incubator/vector/Long256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long256VectorTests.java @@ -66,6 +66,19 @@ public class Long256VectorTests extends AbstractVectorTest { private static final long CONST_SHIFT = Long.SIZE / 2; + // Identity values for reduction operations + private static final long ADD_IDENTITY = (long)0; + private static final long AND_IDENTITY = (long)-1; + private static final long FIRST_NONZERO_IDENTITY = (long)0; + private static final long MAX_IDENTITY = Long.MIN_VALUE; + private static final long MIN_IDENTITY = Long.MAX_VALUE; + private static final long MUL_IDENTITY = (long)1; + private static final long OR_IDENTITY = (long)0; + private static final long SUADD_IDENTITY = (long)0; + private static final long UMAX_IDENTITY = (long)0; // Minimum unsigned value + private static final long UMIN_IDENTITY = (long)-1; // Maximum unsigned value + private static final long XOR_IDENTITY = (long)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); static void assertArraysStrictlyEquals(long[] r, long[] a) { @@ -3632,7 +3645,7 @@ static void SUADDAssocLong256VectorTestsMasked(IntFunction fa, IntFuncti } static long ANDReduce(long[] a, int idx) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3641,7 +3654,7 @@ static long ANDReduce(long[] a, int idx) { } static long ANDReduceAll(long[] a) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3653,20 +3666,14 @@ static long ANDReduceAll(long[] a) { static void ANDReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3675,7 +3682,7 @@ static void ANDReduceLong256VectorTests(IntFunction fa) { } static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3685,7 +3692,7 @@ static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ANDReduceAllMasked(long[] a, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3699,20 +3706,14 @@ static void ANDReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3721,7 +3722,7 @@ static void ANDReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio } static long ORReduce(long[] a, int idx) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3730,7 +3731,7 @@ static long ORReduce(long[] a, int idx) { } static long ORReduceAll(long[] a) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3745,17 +3746,11 @@ static void ORReduceLong256VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3764,7 +3759,7 @@ static void ORReduceLong256VectorTests(IntFunction fa) { } static long ORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3774,7 +3769,7 @@ static long ORReduceMasked(long[] a, int idx, boolean[] mask) { } static long ORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3791,17 +3786,11 @@ static void ORReduceLong256VectorTestsMasked(IntFunction fa, IntFunction long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3810,7 +3799,7 @@ static void ORReduceLong256VectorTestsMasked(IntFunction fa, IntFunction } static long XORReduce(long[] a, int idx) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3819,7 +3808,7 @@ static long XORReduce(long[] a, int idx) { } static long XORReduceAll(long[] a) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3834,17 +3823,11 @@ static void XORReduceLong256VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3853,7 +3836,7 @@ static void XORReduceLong256VectorTests(IntFunction fa) { } static long XORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3863,7 +3846,7 @@ static long XORReduceMasked(long[] a, int idx, boolean[] mask) { } static long XORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3880,17 +3863,11 @@ static void XORReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3899,7 +3876,7 @@ static void XORReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio } static long ADDReduce(long[] a, int idx) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3908,7 +3885,7 @@ static long ADDReduce(long[] a, int idx) { } static long ADDReduceAll(long[] a) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3923,17 +3900,11 @@ static void ADDReduceLong256VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3942,7 +3913,7 @@ static void ADDReduceLong256VectorTests(IntFunction fa) { } static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3952,7 +3923,7 @@ static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3969,17 +3940,11 @@ static void ADDReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3988,7 +3953,7 @@ static void ADDReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio } static long MULReduce(long[] a, int idx) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3997,7 +3962,7 @@ static long MULReduce(long[] a, int idx) { } static long MULReduceAll(long[] a) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -4009,20 +3974,14 @@ static long MULReduceAll(long[] a) { static void MULReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4031,7 +3990,7 @@ static void MULReduceLong256VectorTests(IntFunction fa) { } static long MULReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4041,7 +4000,7 @@ static long MULReduceMasked(long[] a, int idx, boolean[] mask) { } static long MULReduceAllMasked(long[] a, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4055,20 +4014,14 @@ static void MULReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4077,7 +4030,7 @@ static void MULReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio } static long MINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.min(res, a[i]); } @@ -4086,7 +4039,7 @@ static long MINReduce(long[] a, int idx) { } static long MINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduce(a, i)); } @@ -4098,20 +4051,14 @@ static long MINReduceAll(long[] a) { static void MINReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (long) Math.min(ra, r[i]); } } @@ -4120,7 +4067,7 @@ static void MINReduceLong256VectorTests(IntFunction fa) { } static long MINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.min(res, a[i]); @@ -4130,7 +4077,7 @@ static long MINReduceMasked(long[] a, int idx, boolean[] mask) { } static long MINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4144,20 +4091,14 @@ static void MINReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (long) Math.min(ra, r[i]); } } @@ -4166,7 +4107,7 @@ static void MINReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio } static long MAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.max(res, a[i]); } @@ -4175,7 +4116,7 @@ static long MAXReduce(long[] a, int idx) { } static long MAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduce(a, i)); } @@ -4187,20 +4128,14 @@ static long MAXReduceAll(long[] a) { static void MAXReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (long) Math.max(ra, r[i]); } } @@ -4209,7 +4144,7 @@ static void MAXReduceLong256VectorTests(IntFunction fa) { } static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.max(res, a[i]); @@ -4219,7 +4154,7 @@ static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long MAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4233,20 +4168,14 @@ static void MAXReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (long) Math.max(ra, r[i]); } } @@ -4255,7 +4184,7 @@ static void MAXReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio } static long UMINReduce(long[] a, int idx) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4264,7 +4193,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4276,20 +4205,14 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4298,7 +4221,7 @@ static void UMINReduceLong256VectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4308,7 +4231,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4322,20 +4245,14 @@ static void UMINReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4344,7 +4261,7 @@ static void UMINReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti } static long UMAXReduce(long[] a, int idx) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4353,7 +4270,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4365,20 +4282,14 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4387,7 +4298,7 @@ static void UMAXReduceLong256VectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4397,7 +4308,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4411,20 +4322,14 @@ static void UMAXReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4433,7 +4338,7 @@ static void UMAXReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti } static long FIRST_NONZEROReduce(long[] a, int idx) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4442,7 +4347,7 @@ static long FIRST_NONZEROReduce(long[] a, int idx) { } static long FIRST_NONZEROReduceAll(long[] a) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4454,20 +4359,14 @@ static long FIRST_NONZEROReduceAll(long[] a) { static void FIRST_NONZEROReduceLong256VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4476,7 +4375,7 @@ static void FIRST_NONZEROReduceLong256VectorTests(IntFunction fa) { } static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4486,7 +4385,7 @@ static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { } static long FIRST_NONZEROReduceAllMasked(long[] a, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4500,20 +4399,14 @@ static void FIRST_NONZEROReduceLong256VectorTestsMasked(IntFunction fa, long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4570,7 +4463,7 @@ static void allTrueLong256VectorTests(IntFunction fm) { } static long SUADDReduce(long[] a, int idx) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4579,7 +4472,7 @@ static long SUADDReduce(long[] a, int idx) { } static long SUADDReduceAll(long[] a) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4594,17 +4487,11 @@ static void SUADDReduceLong256VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4613,7 +4500,7 @@ static void SUADDReduceLong256VectorTests(IntFunction fa) { } static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4623,7 +4510,7 @@ static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long SUADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4639,17 +4526,11 @@ static void SUADDReduceLong256VectorTestsMasked(IntFunction fa, IntFunct long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6386,6 +6267,93 @@ static void REVERSE_BYTESMaskedLong256VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Long256VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "longUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((long)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((long)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Long.MIN_VALUE, x) == x + Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Long.MAX_VALUE, x) == x + Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((long)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((long)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "longUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "longCompareOpProvider") static void ltLong256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long512VectorTests.java b/test/jdk/jdk/incubator/vector/Long512VectorTests.java index 2e1a14cb4d24f..4be3661e1a2ea 100644 --- a/test/jdk/jdk/incubator/vector/Long512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long512VectorTests.java @@ -66,6 +66,19 @@ public class Long512VectorTests extends AbstractVectorTest { private static final long CONST_SHIFT = Long.SIZE / 2; + // Identity values for reduction operations + private static final long ADD_IDENTITY = (long)0; + private static final long AND_IDENTITY = (long)-1; + private static final long FIRST_NONZERO_IDENTITY = (long)0; + private static final long MAX_IDENTITY = Long.MIN_VALUE; + private static final long MIN_IDENTITY = Long.MAX_VALUE; + private static final long MUL_IDENTITY = (long)1; + private static final long OR_IDENTITY = (long)0; + private static final long SUADD_IDENTITY = (long)0; + private static final long UMAX_IDENTITY = (long)0; // Minimum unsigned value + private static final long UMIN_IDENTITY = (long)-1; // Maximum unsigned value + private static final long XOR_IDENTITY = (long)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); static void assertArraysStrictlyEquals(long[] r, long[] a) { @@ -3632,7 +3645,7 @@ static void SUADDAssocLong512VectorTestsMasked(IntFunction fa, IntFuncti } static long ANDReduce(long[] a, int idx) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3641,7 +3654,7 @@ static long ANDReduce(long[] a, int idx) { } static long ANDReduceAll(long[] a) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3653,20 +3666,14 @@ static long ANDReduceAll(long[] a) { static void ANDReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3675,7 +3682,7 @@ static void ANDReduceLong512VectorTests(IntFunction fa) { } static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3685,7 +3692,7 @@ static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ANDReduceAllMasked(long[] a, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3699,20 +3706,14 @@ static void ANDReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3721,7 +3722,7 @@ static void ANDReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio } static long ORReduce(long[] a, int idx) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3730,7 +3731,7 @@ static long ORReduce(long[] a, int idx) { } static long ORReduceAll(long[] a) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3745,17 +3746,11 @@ static void ORReduceLong512VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3764,7 +3759,7 @@ static void ORReduceLong512VectorTests(IntFunction fa) { } static long ORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3774,7 +3769,7 @@ static long ORReduceMasked(long[] a, int idx, boolean[] mask) { } static long ORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3791,17 +3786,11 @@ static void ORReduceLong512VectorTestsMasked(IntFunction fa, IntFunction long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3810,7 +3799,7 @@ static void ORReduceLong512VectorTestsMasked(IntFunction fa, IntFunction } static long XORReduce(long[] a, int idx) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3819,7 +3808,7 @@ static long XORReduce(long[] a, int idx) { } static long XORReduceAll(long[] a) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3834,17 +3823,11 @@ static void XORReduceLong512VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3853,7 +3836,7 @@ static void XORReduceLong512VectorTests(IntFunction fa) { } static long XORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3863,7 +3846,7 @@ static long XORReduceMasked(long[] a, int idx, boolean[] mask) { } static long XORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3880,17 +3863,11 @@ static void XORReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3899,7 +3876,7 @@ static void XORReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio } static long ADDReduce(long[] a, int idx) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3908,7 +3885,7 @@ static long ADDReduce(long[] a, int idx) { } static long ADDReduceAll(long[] a) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3923,17 +3900,11 @@ static void ADDReduceLong512VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3942,7 +3913,7 @@ static void ADDReduceLong512VectorTests(IntFunction fa) { } static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3952,7 +3923,7 @@ static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3969,17 +3940,11 @@ static void ADDReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3988,7 +3953,7 @@ static void ADDReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio } static long MULReduce(long[] a, int idx) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3997,7 +3962,7 @@ static long MULReduce(long[] a, int idx) { } static long MULReduceAll(long[] a) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -4009,20 +3974,14 @@ static long MULReduceAll(long[] a) { static void MULReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4031,7 +3990,7 @@ static void MULReduceLong512VectorTests(IntFunction fa) { } static long MULReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4041,7 +4000,7 @@ static long MULReduceMasked(long[] a, int idx, boolean[] mask) { } static long MULReduceAllMasked(long[] a, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4055,20 +4014,14 @@ static void MULReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4077,7 +4030,7 @@ static void MULReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio } static long MINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.min(res, a[i]); } @@ -4086,7 +4039,7 @@ static long MINReduce(long[] a, int idx) { } static long MINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduce(a, i)); } @@ -4098,20 +4051,14 @@ static long MINReduceAll(long[] a) { static void MINReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (long) Math.min(ra, r[i]); } } @@ -4120,7 +4067,7 @@ static void MINReduceLong512VectorTests(IntFunction fa) { } static long MINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.min(res, a[i]); @@ -4130,7 +4077,7 @@ static long MINReduceMasked(long[] a, int idx, boolean[] mask) { } static long MINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4144,20 +4091,14 @@ static void MINReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (long) Math.min(ra, r[i]); } } @@ -4166,7 +4107,7 @@ static void MINReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio } static long MAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.max(res, a[i]); } @@ -4175,7 +4116,7 @@ static long MAXReduce(long[] a, int idx) { } static long MAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduce(a, i)); } @@ -4187,20 +4128,14 @@ static long MAXReduceAll(long[] a) { static void MAXReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (long) Math.max(ra, r[i]); } } @@ -4209,7 +4144,7 @@ static void MAXReduceLong512VectorTests(IntFunction fa) { } static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.max(res, a[i]); @@ -4219,7 +4154,7 @@ static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long MAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4233,20 +4168,14 @@ static void MAXReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (long) Math.max(ra, r[i]); } } @@ -4255,7 +4184,7 @@ static void MAXReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio } static long UMINReduce(long[] a, int idx) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4264,7 +4193,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4276,20 +4205,14 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4298,7 +4221,7 @@ static void UMINReduceLong512VectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4308,7 +4231,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4322,20 +4245,14 @@ static void UMINReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4344,7 +4261,7 @@ static void UMINReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti } static long UMAXReduce(long[] a, int idx) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4353,7 +4270,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4365,20 +4282,14 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4387,7 +4298,7 @@ static void UMAXReduceLong512VectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4397,7 +4308,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4411,20 +4322,14 @@ static void UMAXReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4433,7 +4338,7 @@ static void UMAXReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti } static long FIRST_NONZEROReduce(long[] a, int idx) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4442,7 +4347,7 @@ static long FIRST_NONZEROReduce(long[] a, int idx) { } static long FIRST_NONZEROReduceAll(long[] a) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4454,20 +4359,14 @@ static long FIRST_NONZEROReduceAll(long[] a) { static void FIRST_NONZEROReduceLong512VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4476,7 +4375,7 @@ static void FIRST_NONZEROReduceLong512VectorTests(IntFunction fa) { } static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4486,7 +4385,7 @@ static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { } static long FIRST_NONZEROReduceAllMasked(long[] a, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4500,20 +4399,14 @@ static void FIRST_NONZEROReduceLong512VectorTestsMasked(IntFunction fa, long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4570,7 +4463,7 @@ static void allTrueLong512VectorTests(IntFunction fm) { } static long SUADDReduce(long[] a, int idx) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4579,7 +4472,7 @@ static long SUADDReduce(long[] a, int idx) { } static long SUADDReduceAll(long[] a) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4594,17 +4487,11 @@ static void SUADDReduceLong512VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4613,7 +4500,7 @@ static void SUADDReduceLong512VectorTests(IntFunction fa) { } static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4623,7 +4510,7 @@ static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long SUADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4639,17 +4526,11 @@ static void SUADDReduceLong512VectorTestsMasked(IntFunction fa, IntFunct long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6386,6 +6267,93 @@ static void REVERSE_BYTESMaskedLong512VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Long512VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "longUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((long)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((long)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Long.MIN_VALUE, x) == x + Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Long.MAX_VALUE, x) == x + Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((long)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((long)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "longUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "longCompareOpProvider") static void ltLong512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long64VectorTests.java b/test/jdk/jdk/incubator/vector/Long64VectorTests.java index bb31cee6f79d8..81eefa8f79012 100644 --- a/test/jdk/jdk/incubator/vector/Long64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long64VectorTests.java @@ -66,6 +66,19 @@ public class Long64VectorTests extends AbstractVectorTest { private static final long CONST_SHIFT = Long.SIZE / 2; + // Identity values for reduction operations + private static final long ADD_IDENTITY = (long)0; + private static final long AND_IDENTITY = (long)-1; + private static final long FIRST_NONZERO_IDENTITY = (long)0; + private static final long MAX_IDENTITY = Long.MIN_VALUE; + private static final long MIN_IDENTITY = Long.MAX_VALUE; + private static final long MUL_IDENTITY = (long)1; + private static final long OR_IDENTITY = (long)0; + private static final long SUADD_IDENTITY = (long)0; + private static final long UMAX_IDENTITY = (long)0; // Minimum unsigned value + private static final long UMIN_IDENTITY = (long)-1; // Maximum unsigned value + private static final long XOR_IDENTITY = (long)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); static void assertArraysStrictlyEquals(long[] r, long[] a) { @@ -3632,7 +3645,7 @@ static void SUADDAssocLong64VectorTestsMasked(IntFunction fa, IntFunctio } static long ANDReduce(long[] a, int idx) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3641,7 +3654,7 @@ static long ANDReduce(long[] a, int idx) { } static long ANDReduceAll(long[] a) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3653,20 +3666,14 @@ static long ANDReduceAll(long[] a) { static void ANDReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3675,7 +3682,7 @@ static void ANDReduceLong64VectorTests(IntFunction fa) { } static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3685,7 +3692,7 @@ static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ANDReduceAllMasked(long[] a, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3699,20 +3706,14 @@ static void ANDReduceLong64VectorTestsMasked(IntFunction fa, IntFunction long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3721,7 +3722,7 @@ static void ANDReduceLong64VectorTestsMasked(IntFunction fa, IntFunction } static long ORReduce(long[] a, int idx) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3730,7 +3731,7 @@ static long ORReduce(long[] a, int idx) { } static long ORReduceAll(long[] a) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3745,17 +3746,11 @@ static void ORReduceLong64VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3764,7 +3759,7 @@ static void ORReduceLong64VectorTests(IntFunction fa) { } static long ORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3774,7 +3769,7 @@ static long ORReduceMasked(long[] a, int idx, boolean[] mask) { } static long ORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3791,17 +3786,11 @@ static void ORReduceLong64VectorTestsMasked(IntFunction fa, IntFunction< long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3810,7 +3799,7 @@ static void ORReduceLong64VectorTestsMasked(IntFunction fa, IntFunction< } static long XORReduce(long[] a, int idx) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3819,7 +3808,7 @@ static long XORReduce(long[] a, int idx) { } static long XORReduceAll(long[] a) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3834,17 +3823,11 @@ static void XORReduceLong64VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3853,7 +3836,7 @@ static void XORReduceLong64VectorTests(IntFunction fa) { } static long XORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3863,7 +3846,7 @@ static long XORReduceMasked(long[] a, int idx, boolean[] mask) { } static long XORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3880,17 +3863,11 @@ static void XORReduceLong64VectorTestsMasked(IntFunction fa, IntFunction long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3899,7 +3876,7 @@ static void XORReduceLong64VectorTestsMasked(IntFunction fa, IntFunction } static long ADDReduce(long[] a, int idx) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3908,7 +3885,7 @@ static long ADDReduce(long[] a, int idx) { } static long ADDReduceAll(long[] a) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3923,17 +3900,11 @@ static void ADDReduceLong64VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3942,7 +3913,7 @@ static void ADDReduceLong64VectorTests(IntFunction fa) { } static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3952,7 +3923,7 @@ static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3969,17 +3940,11 @@ static void ADDReduceLong64VectorTestsMasked(IntFunction fa, IntFunction long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3988,7 +3953,7 @@ static void ADDReduceLong64VectorTestsMasked(IntFunction fa, IntFunction } static long MULReduce(long[] a, int idx) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3997,7 +3962,7 @@ static long MULReduce(long[] a, int idx) { } static long MULReduceAll(long[] a) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -4009,20 +3974,14 @@ static long MULReduceAll(long[] a) { static void MULReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4031,7 +3990,7 @@ static void MULReduceLong64VectorTests(IntFunction fa) { } static long MULReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4041,7 +4000,7 @@ static long MULReduceMasked(long[] a, int idx, boolean[] mask) { } static long MULReduceAllMasked(long[] a, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4055,20 +4014,14 @@ static void MULReduceLong64VectorTestsMasked(IntFunction fa, IntFunction long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4077,7 +4030,7 @@ static void MULReduceLong64VectorTestsMasked(IntFunction fa, IntFunction } static long MINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.min(res, a[i]); } @@ -4086,7 +4039,7 @@ static long MINReduce(long[] a, int idx) { } static long MINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduce(a, i)); } @@ -4098,20 +4051,14 @@ static long MINReduceAll(long[] a) { static void MINReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (long) Math.min(ra, r[i]); } } @@ -4120,7 +4067,7 @@ static void MINReduceLong64VectorTests(IntFunction fa) { } static long MINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.min(res, a[i]); @@ -4130,7 +4077,7 @@ static long MINReduceMasked(long[] a, int idx, boolean[] mask) { } static long MINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4144,20 +4091,14 @@ static void MINReduceLong64VectorTestsMasked(IntFunction fa, IntFunction long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (long) Math.min(ra, r[i]); } } @@ -4166,7 +4107,7 @@ static void MINReduceLong64VectorTestsMasked(IntFunction fa, IntFunction } static long MAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.max(res, a[i]); } @@ -4175,7 +4116,7 @@ static long MAXReduce(long[] a, int idx) { } static long MAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduce(a, i)); } @@ -4187,20 +4128,14 @@ static long MAXReduceAll(long[] a) { static void MAXReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (long) Math.max(ra, r[i]); } } @@ -4209,7 +4144,7 @@ static void MAXReduceLong64VectorTests(IntFunction fa) { } static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.max(res, a[i]); @@ -4219,7 +4154,7 @@ static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long MAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4233,20 +4168,14 @@ static void MAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunction long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (long) Math.max(ra, r[i]); } } @@ -4255,7 +4184,7 @@ static void MAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunction } static long UMINReduce(long[] a, int idx) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4264,7 +4193,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4276,20 +4205,14 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4298,7 +4221,7 @@ static void UMINReduceLong64VectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4308,7 +4231,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4322,20 +4245,14 @@ static void UMINReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4344,7 +4261,7 @@ static void UMINReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio } static long UMAXReduce(long[] a, int idx) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4353,7 +4270,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4365,20 +4282,14 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4387,7 +4298,7 @@ static void UMAXReduceLong64VectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4397,7 +4308,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4411,20 +4322,14 @@ static void UMAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4433,7 +4338,7 @@ static void UMAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio } static long FIRST_NONZEROReduce(long[] a, int idx) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4442,7 +4347,7 @@ static long FIRST_NONZEROReduce(long[] a, int idx) { } static long FIRST_NONZEROReduceAll(long[] a) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4454,20 +4359,14 @@ static long FIRST_NONZEROReduceAll(long[] a) { static void FIRST_NONZEROReduceLong64VectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4476,7 +4375,7 @@ static void FIRST_NONZEROReduceLong64VectorTests(IntFunction fa) { } static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4486,7 +4385,7 @@ static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { } static long FIRST_NONZEROReduceAllMasked(long[] a, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4500,20 +4399,14 @@ static void FIRST_NONZEROReduceLong64VectorTestsMasked(IntFunction fa, I long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4570,7 +4463,7 @@ static void allTrueLong64VectorTests(IntFunction fm) { } static long SUADDReduce(long[] a, int idx) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4579,7 +4472,7 @@ static long SUADDReduce(long[] a, int idx) { } static long SUADDReduceAll(long[] a) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4594,17 +4487,11 @@ static void SUADDReduceLong64VectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4613,7 +4500,7 @@ static void SUADDReduceLong64VectorTests(IntFunction fa) { } static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4623,7 +4510,7 @@ static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long SUADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4639,17 +4526,11 @@ static void SUADDReduceLong64VectorTestsMasked(IntFunction fa, IntFuncti long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6386,6 +6267,93 @@ static void REVERSE_BYTESMaskedLong64VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Long64VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "longUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((long)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((long)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Long.MIN_VALUE, x) == x + Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Long.MAX_VALUE, x) == x + Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((long)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((long)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "longUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "longCompareOpProvider") static void ltLong64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java index 3235631decef4..eb9ab351769cf 100644 --- a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java @@ -71,6 +71,19 @@ static VectorShape getMaxBit() { private static final long CONST_SHIFT = Long.SIZE / 2; + // Identity values for reduction operations + private static final long ADD_IDENTITY = (long)0; + private static final long AND_IDENTITY = (long)-1; + private static final long FIRST_NONZERO_IDENTITY = (long)0; + private static final long MAX_IDENTITY = Long.MIN_VALUE; + private static final long MIN_IDENTITY = Long.MAX_VALUE; + private static final long MUL_IDENTITY = (long)1; + private static final long OR_IDENTITY = (long)0; + private static final long SUADD_IDENTITY = (long)0; + private static final long UMAX_IDENTITY = (long)0; // Minimum unsigned value + private static final long UMIN_IDENTITY = (long)-1; // Maximum unsigned value + private static final long XOR_IDENTITY = (long)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); static void assertArraysStrictlyEquals(long[] r, long[] a) { @@ -3637,7 +3650,7 @@ static void SUADDAssocLongMaxVectorTestsMasked(IntFunction fa, IntFuncti } static long ANDReduce(long[] a, int idx) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3646,7 +3659,7 @@ static long ANDReduce(long[] a, int idx) { } static long ANDReduceAll(long[] a) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3658,20 +3671,14 @@ static long ANDReduceAll(long[] a) { static void ANDReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3680,7 +3687,7 @@ static void ANDReduceLongMaxVectorTests(IntFunction fa) { } static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3690,7 +3697,7 @@ static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ANDReduceAllMasked(long[] a, boolean[] mask) { - long res = -1; + long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3704,20 +3711,14 @@ static void ANDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = -1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3726,7 +3727,7 @@ static void ANDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio } static long ORReduce(long[] a, int idx) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3735,7 +3736,7 @@ static long ORReduce(long[] a, int idx) { } static long ORReduceAll(long[] a) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3750,17 +3751,11 @@ static void ORReduceLongMaxVectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3769,7 +3764,7 @@ static void ORReduceLongMaxVectorTests(IntFunction fa) { } static long ORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3779,7 +3774,7 @@ static long ORReduceMasked(long[] a, int idx, boolean[] mask) { } static long ORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3796,17 +3791,11 @@ static void ORReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunction long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3815,7 +3804,7 @@ static void ORReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunction } static long XORReduce(long[] a, int idx) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3824,7 +3813,7 @@ static long XORReduce(long[] a, int idx) { } static long XORReduceAll(long[] a) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3839,17 +3828,11 @@ static void XORReduceLongMaxVectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3858,7 +3841,7 @@ static void XORReduceLongMaxVectorTests(IntFunction fa) { } static long XORReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3868,7 +3851,7 @@ static long XORReduceMasked(long[] a, int idx, boolean[] mask) { } static long XORReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3885,17 +3868,11 @@ static void XORReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3904,7 +3881,7 @@ static void XORReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio } static long ADDReduce(long[] a, int idx) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3913,7 +3890,7 @@ static long ADDReduce(long[] a, int idx) { } static long ADDReduceAll(long[] a) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3928,17 +3905,11 @@ static void ADDReduceLongMaxVectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3947,7 +3918,7 @@ static void ADDReduceLongMaxVectorTests(IntFunction fa) { } static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3957,7 +3928,7 @@ static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long ADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3974,17 +3945,11 @@ static void ADDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3993,7 +3958,7 @@ static void ADDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio } static long MULReduce(long[] a, int idx) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -4002,7 +3967,7 @@ static long MULReduce(long[] a, int idx) { } static long MULReduceAll(long[] a) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -4014,20 +3979,14 @@ static long MULReduceAll(long[] a) { static void MULReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -4036,7 +3995,7 @@ static void MULReduceLongMaxVectorTests(IntFunction fa) { } static long MULReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -4046,7 +4005,7 @@ static long MULReduceMasked(long[] a, int idx, boolean[] mask) { } static long MULReduceAllMasked(long[] a, boolean[] mask) { - long res = 1; + long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -4060,20 +4019,14 @@ static void MULReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = 1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4082,7 +4035,7 @@ static void MULReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio } static long MINReduce(long[] a, int idx) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.min(res, a[i]); } @@ -4091,7 +4044,7 @@ static long MINReduce(long[] a, int idx) { } static long MINReduceAll(long[] a) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduce(a, i)); } @@ -4103,20 +4056,14 @@ static long MINReduceAll(long[] a) { static void MINReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (long) Math.min(ra, r[i]); } } @@ -4125,7 +4072,7 @@ static void MINReduceLongMaxVectorTests(IntFunction fa) { } static long MINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.min(res, a[i]); @@ -4135,7 +4082,7 @@ static long MINReduceMasked(long[] a, int idx, boolean[] mask) { } static long MINReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MAX_VALUE; + long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4149,20 +4096,14 @@ static void MINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MAX_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (long) Math.min(ra, r[i]); } } @@ -4171,7 +4112,7 @@ static void MINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio } static long MAXReduce(long[] a, int idx) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) Math.max(res, a[i]); } @@ -4180,7 +4121,7 @@ static long MAXReduce(long[] a, int idx) { } static long MAXReduceAll(long[] a) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduce(a, i)); } @@ -4192,20 +4133,14 @@ static long MAXReduceAll(long[] a) { static void MAXReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (long) Math.max(ra, r[i]); } } @@ -4214,7 +4149,7 @@ static void MAXReduceLongMaxVectorTests(IntFunction fa) { } static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) Math.max(res, a[i]); @@ -4224,7 +4159,7 @@ static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long MAXReduceAllMasked(long[] a, boolean[] mask) { - long res = Long.MIN_VALUE; + long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4238,20 +4173,14 @@ static void MAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = Long.MIN_VALUE; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (long) Math.max(ra, r[i]); } } @@ -4260,7 +4189,7 @@ static void MAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio } static long UMINReduce(long[] a, int idx) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.minUnsigned(res, a[i]); } @@ -4269,7 +4198,7 @@ static long UMINReduce(long[] a, int idx) { } static long UMINReduceAll(long[] a) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4281,20 +4210,14 @@ static long UMINReduceAll(long[] a) { static void UMINReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4303,7 +4226,7 @@ static void UMINReduceLongMaxVectorTests(IntFunction fa) { } static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.minUnsigned(res, a[i]); @@ -4313,7 +4236,7 @@ static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMINReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)-1; + long res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4327,20 +4250,14 @@ static void UMINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)-1; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (long) VectorMath.minUnsigned(ra, r[i]); } } @@ -4349,7 +4266,7 @@ static void UMINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti } static long UMAXReduce(long[] a, int idx) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.maxUnsigned(res, a[i]); } @@ -4358,7 +4275,7 @@ static long UMAXReduce(long[] a, int idx) { } static long UMAXReduceAll(long[] a) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4370,20 +4287,14 @@ static long UMAXReduceAll(long[] a) { static void UMAXReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4392,7 +4303,7 @@ static void UMAXReduceLongMaxVectorTests(IntFunction fa) { } static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.maxUnsigned(res, a[i]); @@ -4402,7 +4313,7 @@ static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { } static long UMAXReduceAllMasked(long[] a, boolean[] mask) { - long res = (long)0; + long res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4416,20 +4327,14 @@ static void UMAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long)0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (long) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4438,7 +4343,7 @@ static void UMAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti } static long FIRST_NONZEROReduce(long[] a, int idx) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4447,7 +4352,7 @@ static long FIRST_NONZEROReduce(long[] a, int idx) { } static long FIRST_NONZEROReduceAll(long[] a) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4459,20 +4364,14 @@ static long FIRST_NONZEROReduceAll(long[] a) { static void FIRST_NONZEROReduceLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4481,7 +4380,7 @@ static void FIRST_NONZEROReduceLongMaxVectorTests(IntFunction fa) { } static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4491,7 +4390,7 @@ static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { } static long FIRST_NONZEROReduceAllMasked(long[] a, boolean[] mask) { - long res = (long) 0; + long res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4505,20 +4404,14 @@ static void FIRST_NONZEROReduceLongMaxVectorTestsMasked(IntFunction fa, long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - long ra = (long) 0; + long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (long) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4575,7 +4468,7 @@ static void allTrueLongMaxVectorTests(IntFunction fm) { } static long SUADDReduce(long[] a, int idx) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4584,7 +4477,7 @@ static long SUADDReduce(long[] a, int idx) { } static long SUADDReduceAll(long[] a) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4599,17 +4492,11 @@ static void SUADDReduceLongMaxVectorTests(IntFunction fa) { long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4618,7 +4505,7 @@ static void SUADDReduceLongMaxVectorTests(IntFunction fa) { } static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (long) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4628,7 +4515,7 @@ static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { } static long SUADDReduceAllMasked(long[] a, boolean[] mask) { - long res = 0; + long res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (long) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4644,17 +4531,11 @@ static void SUADDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunct long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - ra = (long) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6391,6 +6272,93 @@ static void REVERSE_BYTESMaskedLongMaxVectorTests(IntFunction fa, assertArraysEquals(r, a, mask, LongMaxVectorTests::REVERSE_BYTES); } + @Test(dataProvider = "longUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((long)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((long)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Long.MIN_VALUE, x) == x + Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Long.MAX_VALUE, x) == x + Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((long)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((long)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "longUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + LongVector av = LongVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "longCompareOpProvider") static void ltLongMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short128VectorTests.java b/test/jdk/jdk/incubator/vector/Short128VectorTests.java index 7df5606520c35..7cf90ef7f6dea 100644 --- a/test/jdk/jdk/incubator/vector/Short128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short128VectorTests.java @@ -66,6 +66,19 @@ public class Short128VectorTests extends AbstractVectorTest { private static final short CONST_SHIFT = Short.SIZE / 2; + // Identity values for reduction operations + private static final short ADD_IDENTITY = (short)0; + private static final short AND_IDENTITY = (short)-1; + private static final short FIRST_NONZERO_IDENTITY = (short)0; + private static final short MAX_IDENTITY = Short.MIN_VALUE; + private static final short MIN_IDENTITY = Short.MAX_VALUE; + private static final short MUL_IDENTITY = (short)1; + private static final short OR_IDENTITY = (short)0; + private static final short SUADD_IDENTITY = (short)0; + private static final short UMAX_IDENTITY = (short)0; // Minimum unsigned value + private static final short UMIN_IDENTITY = (short)-1; // Maximum unsigned value + private static final short XOR_IDENTITY = (short)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); static void assertArraysStrictlyEquals(short[] r, short[] a) { @@ -3557,7 +3570,7 @@ static void SUADDAssocShort128VectorTestsMasked(IntFunction fa, IntFunc } static short ANDReduce(short[] a, int idx) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3566,7 +3579,7 @@ static short ANDReduce(short[] a, int idx) { } static short ANDReduceAll(short[] a) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3578,20 +3591,14 @@ static short ANDReduceAll(short[] a) { static void ANDReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3600,7 +3607,7 @@ static void ANDReduceShort128VectorTests(IntFunction fa) { } static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3610,7 +3617,7 @@ static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ANDReduceAllMasked(short[] a, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3624,20 +3631,14 @@ static void ANDReduceShort128VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3646,7 +3647,7 @@ static void ANDReduceShort128VectorTestsMasked(IntFunction fa, IntFunct } static short ORReduce(short[] a, int idx) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3655,7 +3656,7 @@ static short ORReduce(short[] a, int idx) { } static short ORReduceAll(short[] a) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3670,17 +3671,11 @@ static void ORReduceShort128VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3689,7 +3684,7 @@ static void ORReduceShort128VectorTests(IntFunction fa) { } static short ORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3699,7 +3694,7 @@ static short ORReduceMasked(short[] a, int idx, boolean[] mask) { } static short ORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3716,17 +3711,11 @@ static void ORReduceShort128VectorTestsMasked(IntFunction fa, IntFuncti short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3735,7 +3724,7 @@ static void ORReduceShort128VectorTestsMasked(IntFunction fa, IntFuncti } static short XORReduce(short[] a, int idx) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3744,7 +3733,7 @@ static short XORReduce(short[] a, int idx) { } static short XORReduceAll(short[] a) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3759,17 +3748,11 @@ static void XORReduceShort128VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3778,7 +3761,7 @@ static void XORReduceShort128VectorTests(IntFunction fa) { } static short XORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3788,7 +3771,7 @@ static short XORReduceMasked(short[] a, int idx, boolean[] mask) { } static short XORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3805,17 +3788,11 @@ static void XORReduceShort128VectorTestsMasked(IntFunction fa, IntFunct short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3824,7 +3801,7 @@ static void XORReduceShort128VectorTestsMasked(IntFunction fa, IntFunct } static short ADDReduce(short[] a, int idx) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3833,7 +3810,7 @@ static short ADDReduce(short[] a, int idx) { } static short ADDReduceAll(short[] a) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3848,17 +3825,11 @@ static void ADDReduceShort128VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3867,7 +3838,7 @@ static void ADDReduceShort128VectorTests(IntFunction fa) { } static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3877,7 +3848,7 @@ static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3894,17 +3865,11 @@ static void ADDReduceShort128VectorTestsMasked(IntFunction fa, IntFunct short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3913,7 +3878,7 @@ static void ADDReduceShort128VectorTestsMasked(IntFunction fa, IntFunct } static short MULReduce(short[] a, int idx) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3922,7 +3887,7 @@ static short MULReduce(short[] a, int idx) { } static short MULReduceAll(short[] a) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3934,20 +3899,14 @@ static short MULReduceAll(short[] a) { static void MULReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3956,7 +3915,7 @@ static void MULReduceShort128VectorTests(IntFunction fa) { } static short MULReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3966,7 +3925,7 @@ static short MULReduceMasked(short[] a, int idx, boolean[] mask) { } static short MULReduceAllMasked(short[] a, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3980,20 +3939,14 @@ static void MULReduceShort128VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4002,7 +3955,7 @@ static void MULReduceShort128VectorTestsMasked(IntFunction fa, IntFunct } static short MINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.min(res, a[i]); } @@ -4011,7 +3964,7 @@ static short MINReduce(short[] a, int idx) { } static short MINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduce(a, i)); } @@ -4023,20 +3976,14 @@ static short MINReduceAll(short[] a) { static void MINReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (short) Math.min(ra, r[i]); } } @@ -4045,7 +3992,7 @@ static void MINReduceShort128VectorTests(IntFunction fa) { } static short MINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.min(res, a[i]); @@ -4055,7 +4002,7 @@ static short MINReduceMasked(short[] a, int idx, boolean[] mask) { } static short MINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4069,20 +4016,14 @@ static void MINReduceShort128VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (short) Math.min(ra, r[i]); } } @@ -4091,7 +4032,7 @@ static void MINReduceShort128VectorTestsMasked(IntFunction fa, IntFunct } static short MAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.max(res, a[i]); } @@ -4100,7 +4041,7 @@ static short MAXReduce(short[] a, int idx) { } static short MAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduce(a, i)); } @@ -4112,20 +4053,14 @@ static short MAXReduceAll(short[] a) { static void MAXReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (short) Math.max(ra, r[i]); } } @@ -4134,7 +4069,7 @@ static void MAXReduceShort128VectorTests(IntFunction fa) { } static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.max(res, a[i]); @@ -4144,7 +4079,7 @@ static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short MAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4158,20 +4093,14 @@ static void MAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (short) Math.max(ra, r[i]); } } @@ -4180,7 +4109,7 @@ static void MAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunct } static short UMINReduce(short[] a, int idx) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4189,7 +4118,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4201,20 +4130,14 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4223,7 +4146,7 @@ static void UMINReduceShort128VectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4233,7 +4156,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4247,20 +4170,14 @@ static void UMINReduceShort128VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4269,7 +4186,7 @@ static void UMINReduceShort128VectorTestsMasked(IntFunction fa, IntFunc } static short UMAXReduce(short[] a, int idx) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4278,7 +4195,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4290,20 +4207,14 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4312,7 +4223,7 @@ static void UMAXReduceShort128VectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4322,7 +4233,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4336,20 +4247,14 @@ static void UMAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4358,7 +4263,7 @@ static void UMAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunc } static short FIRST_NONZEROReduce(short[] a, int idx) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4367,7 +4272,7 @@ static short FIRST_NONZEROReduce(short[] a, int idx) { } static short FIRST_NONZEROReduceAll(short[] a) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4379,20 +4284,14 @@ static short FIRST_NONZEROReduceAll(short[] a) { static void FIRST_NONZEROReduceShort128VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4401,7 +4300,7 @@ static void FIRST_NONZEROReduceShort128VectorTests(IntFunction fa) { } static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4411,7 +4310,7 @@ static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { } static short FIRST_NONZEROReduceAllMasked(short[] a, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4425,20 +4324,14 @@ static void FIRST_NONZEROReduceShort128VectorTestsMasked(IntFunction fa short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4495,7 +4388,7 @@ static void allTrueShort128VectorTests(IntFunction fm) { } static short SUADDReduce(short[] a, int idx) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4504,7 +4397,7 @@ static short SUADDReduce(short[] a, int idx) { } static short SUADDReduceAll(short[] a) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4519,17 +4412,11 @@ static void SUADDReduceShort128VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4538,7 +4425,7 @@ static void SUADDReduceShort128VectorTests(IntFunction fa) { } static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4548,7 +4435,7 @@ static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short SUADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4564,17 +4451,11 @@ static void SUADDReduceShort128VectorTestsMasked(IntFunction fa, IntFun short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6381,6 +6262,93 @@ static void REVERSE_BYTESMaskedShort128VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Short128VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "shortUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((short)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((short)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Short.MIN_VALUE, x) == x + Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Short.MAX_VALUE, x) == x + Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((short)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((short)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "shortCompareOpProvider") static void ltShort128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short256VectorTests.java b/test/jdk/jdk/incubator/vector/Short256VectorTests.java index 0bf3e5ef178fb..c32c14c3a7c3f 100644 --- a/test/jdk/jdk/incubator/vector/Short256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short256VectorTests.java @@ -66,6 +66,19 @@ public class Short256VectorTests extends AbstractVectorTest { private static final short CONST_SHIFT = Short.SIZE / 2; + // Identity values for reduction operations + private static final short ADD_IDENTITY = (short)0; + private static final short AND_IDENTITY = (short)-1; + private static final short FIRST_NONZERO_IDENTITY = (short)0; + private static final short MAX_IDENTITY = Short.MIN_VALUE; + private static final short MIN_IDENTITY = Short.MAX_VALUE; + private static final short MUL_IDENTITY = (short)1; + private static final short OR_IDENTITY = (short)0; + private static final short SUADD_IDENTITY = (short)0; + private static final short UMAX_IDENTITY = (short)0; // Minimum unsigned value + private static final short UMIN_IDENTITY = (short)-1; // Maximum unsigned value + private static final short XOR_IDENTITY = (short)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); static void assertArraysStrictlyEquals(short[] r, short[] a) { @@ -3557,7 +3570,7 @@ static void SUADDAssocShort256VectorTestsMasked(IntFunction fa, IntFunc } static short ANDReduce(short[] a, int idx) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3566,7 +3579,7 @@ static short ANDReduce(short[] a, int idx) { } static short ANDReduceAll(short[] a) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3578,20 +3591,14 @@ static short ANDReduceAll(short[] a) { static void ANDReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3600,7 +3607,7 @@ static void ANDReduceShort256VectorTests(IntFunction fa) { } static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3610,7 +3617,7 @@ static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ANDReduceAllMasked(short[] a, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3624,20 +3631,14 @@ static void ANDReduceShort256VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3646,7 +3647,7 @@ static void ANDReduceShort256VectorTestsMasked(IntFunction fa, IntFunct } static short ORReduce(short[] a, int idx) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3655,7 +3656,7 @@ static short ORReduce(short[] a, int idx) { } static short ORReduceAll(short[] a) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3670,17 +3671,11 @@ static void ORReduceShort256VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3689,7 +3684,7 @@ static void ORReduceShort256VectorTests(IntFunction fa) { } static short ORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3699,7 +3694,7 @@ static short ORReduceMasked(short[] a, int idx, boolean[] mask) { } static short ORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3716,17 +3711,11 @@ static void ORReduceShort256VectorTestsMasked(IntFunction fa, IntFuncti short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3735,7 +3724,7 @@ static void ORReduceShort256VectorTestsMasked(IntFunction fa, IntFuncti } static short XORReduce(short[] a, int idx) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3744,7 +3733,7 @@ static short XORReduce(short[] a, int idx) { } static short XORReduceAll(short[] a) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3759,17 +3748,11 @@ static void XORReduceShort256VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3778,7 +3761,7 @@ static void XORReduceShort256VectorTests(IntFunction fa) { } static short XORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3788,7 +3771,7 @@ static short XORReduceMasked(short[] a, int idx, boolean[] mask) { } static short XORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3805,17 +3788,11 @@ static void XORReduceShort256VectorTestsMasked(IntFunction fa, IntFunct short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3824,7 +3801,7 @@ static void XORReduceShort256VectorTestsMasked(IntFunction fa, IntFunct } static short ADDReduce(short[] a, int idx) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3833,7 +3810,7 @@ static short ADDReduce(short[] a, int idx) { } static short ADDReduceAll(short[] a) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3848,17 +3825,11 @@ static void ADDReduceShort256VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3867,7 +3838,7 @@ static void ADDReduceShort256VectorTests(IntFunction fa) { } static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3877,7 +3848,7 @@ static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3894,17 +3865,11 @@ static void ADDReduceShort256VectorTestsMasked(IntFunction fa, IntFunct short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3913,7 +3878,7 @@ static void ADDReduceShort256VectorTestsMasked(IntFunction fa, IntFunct } static short MULReduce(short[] a, int idx) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3922,7 +3887,7 @@ static short MULReduce(short[] a, int idx) { } static short MULReduceAll(short[] a) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3934,20 +3899,14 @@ static short MULReduceAll(short[] a) { static void MULReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3956,7 +3915,7 @@ static void MULReduceShort256VectorTests(IntFunction fa) { } static short MULReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3966,7 +3925,7 @@ static short MULReduceMasked(short[] a, int idx, boolean[] mask) { } static short MULReduceAllMasked(short[] a, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3980,20 +3939,14 @@ static void MULReduceShort256VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4002,7 +3955,7 @@ static void MULReduceShort256VectorTestsMasked(IntFunction fa, IntFunct } static short MINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.min(res, a[i]); } @@ -4011,7 +3964,7 @@ static short MINReduce(short[] a, int idx) { } static short MINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduce(a, i)); } @@ -4023,20 +3976,14 @@ static short MINReduceAll(short[] a) { static void MINReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (short) Math.min(ra, r[i]); } } @@ -4045,7 +3992,7 @@ static void MINReduceShort256VectorTests(IntFunction fa) { } static short MINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.min(res, a[i]); @@ -4055,7 +4002,7 @@ static short MINReduceMasked(short[] a, int idx, boolean[] mask) { } static short MINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4069,20 +4016,14 @@ static void MINReduceShort256VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (short) Math.min(ra, r[i]); } } @@ -4091,7 +4032,7 @@ static void MINReduceShort256VectorTestsMasked(IntFunction fa, IntFunct } static short MAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.max(res, a[i]); } @@ -4100,7 +4041,7 @@ static short MAXReduce(short[] a, int idx) { } static short MAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduce(a, i)); } @@ -4112,20 +4053,14 @@ static short MAXReduceAll(short[] a) { static void MAXReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (short) Math.max(ra, r[i]); } } @@ -4134,7 +4069,7 @@ static void MAXReduceShort256VectorTests(IntFunction fa) { } static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.max(res, a[i]); @@ -4144,7 +4079,7 @@ static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short MAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4158,20 +4093,14 @@ static void MAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (short) Math.max(ra, r[i]); } } @@ -4180,7 +4109,7 @@ static void MAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunct } static short UMINReduce(short[] a, int idx) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4189,7 +4118,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4201,20 +4130,14 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4223,7 +4146,7 @@ static void UMINReduceShort256VectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4233,7 +4156,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4247,20 +4170,14 @@ static void UMINReduceShort256VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4269,7 +4186,7 @@ static void UMINReduceShort256VectorTestsMasked(IntFunction fa, IntFunc } static short UMAXReduce(short[] a, int idx) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4278,7 +4195,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4290,20 +4207,14 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4312,7 +4223,7 @@ static void UMAXReduceShort256VectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4322,7 +4233,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4336,20 +4247,14 @@ static void UMAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4358,7 +4263,7 @@ static void UMAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunc } static short FIRST_NONZEROReduce(short[] a, int idx) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4367,7 +4272,7 @@ static short FIRST_NONZEROReduce(short[] a, int idx) { } static short FIRST_NONZEROReduceAll(short[] a) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4379,20 +4284,14 @@ static short FIRST_NONZEROReduceAll(short[] a) { static void FIRST_NONZEROReduceShort256VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4401,7 +4300,7 @@ static void FIRST_NONZEROReduceShort256VectorTests(IntFunction fa) { } static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4411,7 +4310,7 @@ static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { } static short FIRST_NONZEROReduceAllMasked(short[] a, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4425,20 +4324,14 @@ static void FIRST_NONZEROReduceShort256VectorTestsMasked(IntFunction fa short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4495,7 +4388,7 @@ static void allTrueShort256VectorTests(IntFunction fm) { } static short SUADDReduce(short[] a, int idx) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4504,7 +4397,7 @@ static short SUADDReduce(short[] a, int idx) { } static short SUADDReduceAll(short[] a) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4519,17 +4412,11 @@ static void SUADDReduceShort256VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4538,7 +4425,7 @@ static void SUADDReduceShort256VectorTests(IntFunction fa) { } static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4548,7 +4435,7 @@ static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short SUADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4564,17 +4451,11 @@ static void SUADDReduceShort256VectorTestsMasked(IntFunction fa, IntFun short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6381,6 +6262,93 @@ static void REVERSE_BYTESMaskedShort256VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Short256VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "shortUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((short)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((short)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Short.MIN_VALUE, x) == x + Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Short.MAX_VALUE, x) == x + Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((short)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((short)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "shortCompareOpProvider") static void ltShort256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short512VectorTests.java b/test/jdk/jdk/incubator/vector/Short512VectorTests.java index 8eb005f528507..e63c041cbd37f 100644 --- a/test/jdk/jdk/incubator/vector/Short512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short512VectorTests.java @@ -66,6 +66,19 @@ public class Short512VectorTests extends AbstractVectorTest { private static final short CONST_SHIFT = Short.SIZE / 2; + // Identity values for reduction operations + private static final short ADD_IDENTITY = (short)0; + private static final short AND_IDENTITY = (short)-1; + private static final short FIRST_NONZERO_IDENTITY = (short)0; + private static final short MAX_IDENTITY = Short.MIN_VALUE; + private static final short MIN_IDENTITY = Short.MAX_VALUE; + private static final short MUL_IDENTITY = (short)1; + private static final short OR_IDENTITY = (short)0; + private static final short SUADD_IDENTITY = (short)0; + private static final short UMAX_IDENTITY = (short)0; // Minimum unsigned value + private static final short UMIN_IDENTITY = (short)-1; // Maximum unsigned value + private static final short XOR_IDENTITY = (short)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); static void assertArraysStrictlyEquals(short[] r, short[] a) { @@ -3557,7 +3570,7 @@ static void SUADDAssocShort512VectorTestsMasked(IntFunction fa, IntFunc } static short ANDReduce(short[] a, int idx) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3566,7 +3579,7 @@ static short ANDReduce(short[] a, int idx) { } static short ANDReduceAll(short[] a) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3578,20 +3591,14 @@ static short ANDReduceAll(short[] a) { static void ANDReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3600,7 +3607,7 @@ static void ANDReduceShort512VectorTests(IntFunction fa) { } static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3610,7 +3617,7 @@ static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ANDReduceAllMasked(short[] a, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3624,20 +3631,14 @@ static void ANDReduceShort512VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3646,7 +3647,7 @@ static void ANDReduceShort512VectorTestsMasked(IntFunction fa, IntFunct } static short ORReduce(short[] a, int idx) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3655,7 +3656,7 @@ static short ORReduce(short[] a, int idx) { } static short ORReduceAll(short[] a) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3670,17 +3671,11 @@ static void ORReduceShort512VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3689,7 +3684,7 @@ static void ORReduceShort512VectorTests(IntFunction fa) { } static short ORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3699,7 +3694,7 @@ static short ORReduceMasked(short[] a, int idx, boolean[] mask) { } static short ORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3716,17 +3711,11 @@ static void ORReduceShort512VectorTestsMasked(IntFunction fa, IntFuncti short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3735,7 +3724,7 @@ static void ORReduceShort512VectorTestsMasked(IntFunction fa, IntFuncti } static short XORReduce(short[] a, int idx) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3744,7 +3733,7 @@ static short XORReduce(short[] a, int idx) { } static short XORReduceAll(short[] a) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3759,17 +3748,11 @@ static void XORReduceShort512VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3778,7 +3761,7 @@ static void XORReduceShort512VectorTests(IntFunction fa) { } static short XORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3788,7 +3771,7 @@ static short XORReduceMasked(short[] a, int idx, boolean[] mask) { } static short XORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3805,17 +3788,11 @@ static void XORReduceShort512VectorTestsMasked(IntFunction fa, IntFunct short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3824,7 +3801,7 @@ static void XORReduceShort512VectorTestsMasked(IntFunction fa, IntFunct } static short ADDReduce(short[] a, int idx) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3833,7 +3810,7 @@ static short ADDReduce(short[] a, int idx) { } static short ADDReduceAll(short[] a) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3848,17 +3825,11 @@ static void ADDReduceShort512VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3867,7 +3838,7 @@ static void ADDReduceShort512VectorTests(IntFunction fa) { } static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3877,7 +3848,7 @@ static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3894,17 +3865,11 @@ static void ADDReduceShort512VectorTestsMasked(IntFunction fa, IntFunct short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3913,7 +3878,7 @@ static void ADDReduceShort512VectorTestsMasked(IntFunction fa, IntFunct } static short MULReduce(short[] a, int idx) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3922,7 +3887,7 @@ static short MULReduce(short[] a, int idx) { } static short MULReduceAll(short[] a) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3934,20 +3899,14 @@ static short MULReduceAll(short[] a) { static void MULReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3956,7 +3915,7 @@ static void MULReduceShort512VectorTests(IntFunction fa) { } static short MULReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3966,7 +3925,7 @@ static short MULReduceMasked(short[] a, int idx, boolean[] mask) { } static short MULReduceAllMasked(short[] a, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3980,20 +3939,14 @@ static void MULReduceShort512VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4002,7 +3955,7 @@ static void MULReduceShort512VectorTestsMasked(IntFunction fa, IntFunct } static short MINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.min(res, a[i]); } @@ -4011,7 +3964,7 @@ static short MINReduce(short[] a, int idx) { } static short MINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduce(a, i)); } @@ -4023,20 +3976,14 @@ static short MINReduceAll(short[] a) { static void MINReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (short) Math.min(ra, r[i]); } } @@ -4045,7 +3992,7 @@ static void MINReduceShort512VectorTests(IntFunction fa) { } static short MINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.min(res, a[i]); @@ -4055,7 +4002,7 @@ static short MINReduceMasked(short[] a, int idx, boolean[] mask) { } static short MINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4069,20 +4016,14 @@ static void MINReduceShort512VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (short) Math.min(ra, r[i]); } } @@ -4091,7 +4032,7 @@ static void MINReduceShort512VectorTestsMasked(IntFunction fa, IntFunct } static short MAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.max(res, a[i]); } @@ -4100,7 +4041,7 @@ static short MAXReduce(short[] a, int idx) { } static short MAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduce(a, i)); } @@ -4112,20 +4053,14 @@ static short MAXReduceAll(short[] a) { static void MAXReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (short) Math.max(ra, r[i]); } } @@ -4134,7 +4069,7 @@ static void MAXReduceShort512VectorTests(IntFunction fa) { } static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.max(res, a[i]); @@ -4144,7 +4079,7 @@ static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short MAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4158,20 +4093,14 @@ static void MAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (short) Math.max(ra, r[i]); } } @@ -4180,7 +4109,7 @@ static void MAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunct } static short UMINReduce(short[] a, int idx) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4189,7 +4118,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4201,20 +4130,14 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4223,7 +4146,7 @@ static void UMINReduceShort512VectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4233,7 +4156,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4247,20 +4170,14 @@ static void UMINReduceShort512VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4269,7 +4186,7 @@ static void UMINReduceShort512VectorTestsMasked(IntFunction fa, IntFunc } static short UMAXReduce(short[] a, int idx) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4278,7 +4195,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4290,20 +4207,14 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4312,7 +4223,7 @@ static void UMAXReduceShort512VectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4322,7 +4233,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4336,20 +4247,14 @@ static void UMAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4358,7 +4263,7 @@ static void UMAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunc } static short FIRST_NONZEROReduce(short[] a, int idx) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4367,7 +4272,7 @@ static short FIRST_NONZEROReduce(short[] a, int idx) { } static short FIRST_NONZEROReduceAll(short[] a) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4379,20 +4284,14 @@ static short FIRST_NONZEROReduceAll(short[] a) { static void FIRST_NONZEROReduceShort512VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4401,7 +4300,7 @@ static void FIRST_NONZEROReduceShort512VectorTests(IntFunction fa) { } static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4411,7 +4310,7 @@ static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { } static short FIRST_NONZEROReduceAllMasked(short[] a, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4425,20 +4324,14 @@ static void FIRST_NONZEROReduceShort512VectorTestsMasked(IntFunction fa short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4495,7 +4388,7 @@ static void allTrueShort512VectorTests(IntFunction fm) { } static short SUADDReduce(short[] a, int idx) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4504,7 +4397,7 @@ static short SUADDReduce(short[] a, int idx) { } static short SUADDReduceAll(short[] a) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4519,17 +4412,11 @@ static void SUADDReduceShort512VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4538,7 +4425,7 @@ static void SUADDReduceShort512VectorTests(IntFunction fa) { } static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4548,7 +4435,7 @@ static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short SUADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4564,17 +4451,11 @@ static void SUADDReduceShort512VectorTestsMasked(IntFunction fa, IntFun short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6381,6 +6262,93 @@ static void REVERSE_BYTESMaskedShort512VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Short512VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "shortUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((short)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((short)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Short.MIN_VALUE, x) == x + Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Short.MAX_VALUE, x) == x + Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((short)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((short)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "shortCompareOpProvider") static void ltShort512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short64VectorTests.java b/test/jdk/jdk/incubator/vector/Short64VectorTests.java index dafad7d6e3c16..2c335065524db 100644 --- a/test/jdk/jdk/incubator/vector/Short64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short64VectorTests.java @@ -66,6 +66,19 @@ public class Short64VectorTests extends AbstractVectorTest { private static final short CONST_SHIFT = Short.SIZE / 2; + // Identity values for reduction operations + private static final short ADD_IDENTITY = (short)0; + private static final short AND_IDENTITY = (short)-1; + private static final short FIRST_NONZERO_IDENTITY = (short)0; + private static final short MAX_IDENTITY = Short.MIN_VALUE; + private static final short MIN_IDENTITY = Short.MAX_VALUE; + private static final short MUL_IDENTITY = (short)1; + private static final short OR_IDENTITY = (short)0; + private static final short SUADD_IDENTITY = (short)0; + private static final short UMAX_IDENTITY = (short)0; // Minimum unsigned value + private static final short UMIN_IDENTITY = (short)-1; // Maximum unsigned value + private static final short XOR_IDENTITY = (short)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); static void assertArraysStrictlyEquals(short[] r, short[] a) { @@ -3557,7 +3570,7 @@ static void SUADDAssocShort64VectorTestsMasked(IntFunction fa, IntFunct } static short ANDReduce(short[] a, int idx) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3566,7 +3579,7 @@ static short ANDReduce(short[] a, int idx) { } static short ANDReduceAll(short[] a) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3578,20 +3591,14 @@ static short ANDReduceAll(short[] a) { static void ANDReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3600,7 +3607,7 @@ static void ANDReduceShort64VectorTests(IntFunction fa) { } static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3610,7 +3617,7 @@ static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ANDReduceAllMasked(short[] a, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3624,20 +3631,14 @@ static void ANDReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3646,7 +3647,7 @@ static void ANDReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti } static short ORReduce(short[] a, int idx) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3655,7 +3656,7 @@ static short ORReduce(short[] a, int idx) { } static short ORReduceAll(short[] a) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3670,17 +3671,11 @@ static void ORReduceShort64VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3689,7 +3684,7 @@ static void ORReduceShort64VectorTests(IntFunction fa) { } static short ORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3699,7 +3694,7 @@ static short ORReduceMasked(short[] a, int idx, boolean[] mask) { } static short ORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3716,17 +3711,11 @@ static void ORReduceShort64VectorTestsMasked(IntFunction fa, IntFunctio short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3735,7 +3724,7 @@ static void ORReduceShort64VectorTestsMasked(IntFunction fa, IntFunctio } static short XORReduce(short[] a, int idx) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3744,7 +3733,7 @@ static short XORReduce(short[] a, int idx) { } static short XORReduceAll(short[] a) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3759,17 +3748,11 @@ static void XORReduceShort64VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3778,7 +3761,7 @@ static void XORReduceShort64VectorTests(IntFunction fa) { } static short XORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3788,7 +3771,7 @@ static short XORReduceMasked(short[] a, int idx, boolean[] mask) { } static short XORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3805,17 +3788,11 @@ static void XORReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3824,7 +3801,7 @@ static void XORReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti } static short ADDReduce(short[] a, int idx) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3833,7 +3810,7 @@ static short ADDReduce(short[] a, int idx) { } static short ADDReduceAll(short[] a) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3848,17 +3825,11 @@ static void ADDReduceShort64VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3867,7 +3838,7 @@ static void ADDReduceShort64VectorTests(IntFunction fa) { } static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3877,7 +3848,7 @@ static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3894,17 +3865,11 @@ static void ADDReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3913,7 +3878,7 @@ static void ADDReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti } static short MULReduce(short[] a, int idx) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3922,7 +3887,7 @@ static short MULReduce(short[] a, int idx) { } static short MULReduceAll(short[] a) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3934,20 +3899,14 @@ static short MULReduceAll(short[] a) { static void MULReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3956,7 +3915,7 @@ static void MULReduceShort64VectorTests(IntFunction fa) { } static short MULReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3966,7 +3925,7 @@ static short MULReduceMasked(short[] a, int idx, boolean[] mask) { } static short MULReduceAllMasked(short[] a, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3980,20 +3939,14 @@ static void MULReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4002,7 +3955,7 @@ static void MULReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti } static short MINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.min(res, a[i]); } @@ -4011,7 +3964,7 @@ static short MINReduce(short[] a, int idx) { } static short MINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduce(a, i)); } @@ -4023,20 +3976,14 @@ static short MINReduceAll(short[] a) { static void MINReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (short) Math.min(ra, r[i]); } } @@ -4045,7 +3992,7 @@ static void MINReduceShort64VectorTests(IntFunction fa) { } static short MINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.min(res, a[i]); @@ -4055,7 +4002,7 @@ static short MINReduceMasked(short[] a, int idx, boolean[] mask) { } static short MINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4069,20 +4016,14 @@ static void MINReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (short) Math.min(ra, r[i]); } } @@ -4091,7 +4032,7 @@ static void MINReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti } static short MAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.max(res, a[i]); } @@ -4100,7 +4041,7 @@ static short MAXReduce(short[] a, int idx) { } static short MAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduce(a, i)); } @@ -4112,20 +4053,14 @@ static short MAXReduceAll(short[] a) { static void MAXReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (short) Math.max(ra, r[i]); } } @@ -4134,7 +4069,7 @@ static void MAXReduceShort64VectorTests(IntFunction fa) { } static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.max(res, a[i]); @@ -4144,7 +4079,7 @@ static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short MAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4158,20 +4093,14 @@ static void MAXReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (short) Math.max(ra, r[i]); } } @@ -4180,7 +4109,7 @@ static void MAXReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti } static short UMINReduce(short[] a, int idx) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4189,7 +4118,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4201,20 +4130,14 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4223,7 +4146,7 @@ static void UMINReduceShort64VectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4233,7 +4156,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4247,20 +4170,14 @@ static void UMINReduceShort64VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4269,7 +4186,7 @@ static void UMINReduceShort64VectorTestsMasked(IntFunction fa, IntFunct } static short UMAXReduce(short[] a, int idx) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4278,7 +4195,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4290,20 +4207,14 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4312,7 +4223,7 @@ static void UMAXReduceShort64VectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4322,7 +4233,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4336,20 +4247,14 @@ static void UMAXReduceShort64VectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4358,7 +4263,7 @@ static void UMAXReduceShort64VectorTestsMasked(IntFunction fa, IntFunct } static short FIRST_NONZEROReduce(short[] a, int idx) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4367,7 +4272,7 @@ static short FIRST_NONZEROReduce(short[] a, int idx) { } static short FIRST_NONZEROReduceAll(short[] a) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4379,20 +4284,14 @@ static short FIRST_NONZEROReduceAll(short[] a) { static void FIRST_NONZEROReduceShort64VectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4401,7 +4300,7 @@ static void FIRST_NONZEROReduceShort64VectorTests(IntFunction fa) { } static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4411,7 +4310,7 @@ static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { } static short FIRST_NONZEROReduceAllMasked(short[] a, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4425,20 +4324,14 @@ static void FIRST_NONZEROReduceShort64VectorTestsMasked(IntFunction fa, short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4495,7 +4388,7 @@ static void allTrueShort64VectorTests(IntFunction fm) { } static short SUADDReduce(short[] a, int idx) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4504,7 +4397,7 @@ static short SUADDReduce(short[] a, int idx) { } static short SUADDReduceAll(short[] a) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4519,17 +4412,11 @@ static void SUADDReduceShort64VectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4538,7 +4425,7 @@ static void SUADDReduceShort64VectorTests(IntFunction fa) { } static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4548,7 +4435,7 @@ static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short SUADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4564,17 +4451,11 @@ static void SUADDReduceShort64VectorTestsMasked(IntFunction fa, IntFunc short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6381,6 +6262,93 @@ static void REVERSE_BYTESMaskedShort64VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Short64VectorTests::REVERSE_BYTES); } + @Test(dataProvider = "shortUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((short)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((short)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Short.MIN_VALUE, x) == x + Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Short.MAX_VALUE, x) == x + Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((short)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((short)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "shortCompareOpProvider") static void ltShort64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java index 8175bcd75bb1f..910a686b23967 100644 --- a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java @@ -71,6 +71,19 @@ static VectorShape getMaxBit() { private static final short CONST_SHIFT = Short.SIZE / 2; + // Identity values for reduction operations + private static final short ADD_IDENTITY = (short)0; + private static final short AND_IDENTITY = (short)-1; + private static final short FIRST_NONZERO_IDENTITY = (short)0; + private static final short MAX_IDENTITY = Short.MIN_VALUE; + private static final short MIN_IDENTITY = Short.MAX_VALUE; + private static final short MUL_IDENTITY = (short)1; + private static final short OR_IDENTITY = (short)0; + private static final short SUADD_IDENTITY = (short)0; + private static final short UMAX_IDENTITY = (short)0; // Minimum unsigned value + private static final short UMIN_IDENTITY = (short)-1; // Maximum unsigned value + private static final short XOR_IDENTITY = (short)0; + static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); static void assertArraysStrictlyEquals(short[] r, short[] a) { @@ -3562,7 +3575,7 @@ static void SUADDAssocShortMaxVectorTestsMasked(IntFunction fa, IntFunc } static short ANDReduce(short[] a, int idx) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } @@ -3571,7 +3584,7 @@ static short ANDReduce(short[] a, int idx) { } static short ANDReduceAll(short[] a) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduce(a, i); } @@ -3583,20 +3596,14 @@ static short ANDReduceAll(short[] a) { static void ANDReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND); + ra &= r[i]; } } @@ -3605,7 +3612,7 @@ static void ANDReduceShortMaxVectorTests(IntFunction fa) { } static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res &= a[i]; @@ -3615,7 +3622,7 @@ static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ANDReduceAllMasked(short[] a, boolean[] mask) { - short res = -1; + short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res &= ANDReduceMasked(a, i, mask); } @@ -3629,20 +3636,14 @@ static void ANDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = -1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.AND, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = -1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra &= av.reduceLanes(VectorOperators.AND, vmask); + ra &= r[i]; } } @@ -3651,7 +3652,7 @@ static void ANDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct } static short ORReduce(short[] a, int idx) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } @@ -3660,7 +3661,7 @@ static short ORReduce(short[] a, int idx) { } static short ORReduceAll(short[] a) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduce(a, i); } @@ -3675,17 +3676,11 @@ static void ORReduceShortMaxVectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR); + ra |= r[i]; } } @@ -3694,7 +3689,7 @@ static void ORReduceShortMaxVectorTests(IntFunction fa) { } static short ORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res |= a[i]; @@ -3704,7 +3699,7 @@ static short ORReduceMasked(short[] a, int idx, boolean[] mask) { } static short ORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res |= ORReduceMasked(a, i, mask); } @@ -3721,17 +3716,11 @@ static void ORReduceShortMaxVectorTestsMasked(IntFunction fa, IntFuncti short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.OR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra |= av.reduceLanes(VectorOperators.OR, vmask); + ra |= r[i]; } } @@ -3740,7 +3729,7 @@ static void ORReduceShortMaxVectorTestsMasked(IntFunction fa, IntFuncti } static short XORReduce(short[] a, int idx) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } @@ -3749,7 +3738,7 @@ static short XORReduce(short[] a, int idx) { } static short XORReduceAll(short[] a) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduce(a, i); } @@ -3764,17 +3753,11 @@ static void XORReduceShortMaxVectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR); + ra ^= r[i]; } } @@ -3783,7 +3766,7 @@ static void XORReduceShortMaxVectorTests(IntFunction fa) { } static short XORReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res ^= a[i]; @@ -3793,7 +3776,7 @@ static short XORReduceMasked(short[] a, int idx, boolean[] mask) { } static short XORReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res ^= XORReduceMasked(a, i, mask); } @@ -3810,17 +3793,11 @@ static void XORReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra ^= av.reduceLanes(VectorOperators.XOR, vmask); + ra ^= r[i]; } } @@ -3829,7 +3806,7 @@ static void XORReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct } static short ADDReduce(short[] a, int idx) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } @@ -3838,7 +3815,7 @@ static short ADDReduce(short[] a, int idx) { } static short ADDReduceAll(short[] a) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduce(a, i); } @@ -3853,17 +3830,11 @@ static void ADDReduceShortMaxVectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD); + ra += r[i]; } } @@ -3872,7 +3843,7 @@ static void ADDReduceShortMaxVectorTests(IntFunction fa) { } static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res += a[i]; @@ -3882,7 +3853,7 @@ static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short ADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res += ADDReduceMasked(a, i, mask); } @@ -3899,17 +3870,11 @@ static void ADDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra += av.reduceLanes(VectorOperators.ADD, vmask); + ra += r[i]; } } @@ -3918,7 +3883,7 @@ static void ADDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct } static short MULReduce(short[] a, int idx) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } @@ -3927,7 +3892,7 @@ static short MULReduce(short[] a, int idx) { } static short MULReduceAll(short[] a) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduce(a, i); } @@ -3939,20 +3904,14 @@ static short MULReduceAll(short[] a) { static void MULReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL); + ra *= r[i]; } } @@ -3961,7 +3920,7 @@ static void MULReduceShortMaxVectorTests(IntFunction fa) { } static short MULReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res *= a[i]; @@ -3971,7 +3930,7 @@ static short MULReduceMasked(short[] a, int idx, boolean[] mask) { } static short MULReduceAllMasked(short[] a, boolean[] mask) { - short res = 1; + short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res *= MULReduceMasked(a, i, mask); } @@ -3985,20 +3944,14 @@ static void MULReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = 1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 1; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra *= av.reduceLanes(VectorOperators.MUL, vmask); + ra *= r[i]; } } @@ -4007,7 +3960,7 @@ static void MULReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct } static short MINReduce(short[] a, int idx) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.min(res, a[i]); } @@ -4016,7 +3969,7 @@ static short MINReduce(short[] a, int idx) { } static short MINReduceAll(short[] a) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduce(a, i)); } @@ -4028,20 +3981,14 @@ static short MINReduceAll(short[] a) { static void MINReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN); - } - } - - 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); + ra = (short) Math.min(ra, r[i]); } } @@ -4050,7 +3997,7 @@ static void MINReduceShortMaxVectorTests(IntFunction fa) { } static short MINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.min(res, a[i]); @@ -4060,7 +4007,7 @@ static short MINReduceMasked(short[] a, int idx, boolean[] mask) { } static short MINReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MAX_VALUE; + short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.min(res, MINReduceMasked(a, i, mask)); } @@ -4074,20 +4021,14 @@ static void MINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MAX_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MIN, 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) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); + ra = (short) Math.min(ra, r[i]); } } @@ -4096,7 +4037,7 @@ static void MINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct } static short MAXReduce(short[] a, int idx) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) Math.max(res, a[i]); } @@ -4105,7 +4046,7 @@ static short MAXReduce(short[] a, int idx) { } static short MAXReduceAll(short[] a) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduce(a, i)); } @@ -4117,20 +4058,14 @@ static short MAXReduceAll(short[] a) { static void MAXReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX); - } - } - - 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); + ra = (short) Math.max(ra, r[i]); } } @@ -4139,7 +4074,7 @@ static void MAXReduceShortMaxVectorTests(IntFunction fa) { } static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) Math.max(res, a[i]); @@ -4149,7 +4084,7 @@ static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short MAXReduceAllMasked(short[] a, boolean[] mask) { - short res = Short.MIN_VALUE; + short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); } @@ -4163,20 +4098,14 @@ static void MAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = Short.MIN_VALUE; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.MAX, 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) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); + ra = (short) Math.max(ra, r[i]); } } @@ -4185,7 +4114,7 @@ static void MAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct } static short UMINReduce(short[] a, int idx) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.minUnsigned(res, a[i]); } @@ -4194,7 +4123,7 @@ static short UMINReduce(short[] a, int idx) { } static short UMINReduceAll(short[] a) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); } @@ -4206,20 +4135,14 @@ static short UMINReduceAll(short[] a) { static void UMINReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4228,7 +4151,7 @@ static void UMINReduceShortMaxVectorTests(IntFunction fa) { } static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.minUnsigned(res, a[i]); @@ -4238,7 +4161,7 @@ static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMINReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)-1; + short res = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); } @@ -4252,20 +4175,14 @@ static void UMINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)-1; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMIN_IDENTITY; 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)-1; - 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)); + ra = (short) VectorMath.minUnsigned(ra, r[i]); } } @@ -4274,7 +4191,7 @@ static void UMINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc } static short UMAXReduce(short[] a, int idx) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.maxUnsigned(res, a[i]); } @@ -4283,7 +4200,7 @@ static short UMAXReduce(short[] a, int idx) { } static short UMAXReduceAll(short[] a) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); } @@ -4295,20 +4212,14 @@ static short UMAXReduceAll(short[] a) { static void UMAXReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4317,7 +4228,7 @@ static void UMAXReduceShortMaxVectorTests(IntFunction fa) { } static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.maxUnsigned(res, a[i]); @@ -4327,7 +4238,7 @@ static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { } static short UMAXReduceAllMasked(short[] a, boolean[] mask) { - short res = (short)0; + short res = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); } @@ -4341,20 +4252,14 @@ static void UMAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short)0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = UMAX_IDENTITY; 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)0; - 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)); + ra = (short) VectorMath.maxUnsigned(ra, r[i]); } } @@ -4363,7 +4268,7 @@ static void UMAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc } static short FIRST_NONZEROReduce(short[] a, int idx) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = firstNonZero(res, a[i]); } @@ -4372,7 +4277,7 @@ static short FIRST_NONZEROReduce(short[] a, int idx) { } static short FIRST_NONZEROReduceAll(short[] a) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); } @@ -4384,20 +4289,14 @@ static short FIRST_NONZEROReduceAll(short[] a) { static void FIRST_NONZEROReduceShortMaxVectorTests(IntFunction fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length()); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); + ra = firstNonZero(ra, r[i]); } } @@ -4406,7 +4305,7 @@ static void FIRST_NONZEROReduceShortMaxVectorTests(IntFunction fa) { } static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = firstNonZero(res, a[i]); @@ -4416,7 +4315,7 @@ static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { } static short FIRST_NONZEROReduceAllMasked(short[] a, boolean[] mask) { - short res = (short) 0; + short res = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); } @@ -4430,20 +4329,14 @@ static void FIRST_NONZEROReduceShortMaxVectorTestsMasked(IntFunction fa short[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - short ra = (short) 0; + short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = (short) 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); + ra = firstNonZero(ra, r[i]); } } @@ -4500,7 +4393,7 @@ static void allTrueShortMaxVectorTests(IntFunction fm) { } static short SUADDReduce(short[] a, int idx) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); } @@ -4509,7 +4402,7 @@ static short SUADDReduce(short[] a, int idx) { } static short SUADDReduceAll(short[] a) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); } @@ -4524,17 +4417,11 @@ static void SUADDReduceShortMaxVectorTests(IntFunction fa) { short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -4543,7 +4430,7 @@ static void SUADDReduceShortMaxVectorTests(IntFunction fa) { } static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); @@ -4553,7 +4440,7 @@ static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { } static short SUADDReduceAllMasked(short[] a, boolean[] mask) { - short res = 0; + short res = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); } @@ -4569,17 +4456,11 @@ static void SUADDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFun short ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { + ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - } - } - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - ra = 0; - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); + ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); } } @@ -6386,6 +6267,93 @@ static void REVERSE_BYTESMaskedShortMaxVectorTests(IntFunction fa, assertArraysEquals(r, a, mask, ShortMaxVectorTests::REVERSE_BYTES); } + @Test(dataProvider = "shortUnaryOpProvider") + static void testIdentityValues(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals((short)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + // AND identity: -1 & x == x + Assert.assertEquals((short)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max(Short.MIN_VALUE, x) == x + Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min(Short.MAX_VALUE, x) == x + Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals((short)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + // OR identity: 0 | x == x + Assert.assertEquals((short)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + } + } + + @Test(dataProvider = "shortUnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + VectorMask allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); + } + } + @Test(dataProvider = "shortCompareOpProvider") static void ltShortMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/gen-template.sh b/test/jdk/jdk/incubator/vector/gen-template.sh index 9021e3fa3c271..1214866c2c956 100644 --- a/test/jdk/jdk/incubator/vector/gen-template.sh +++ b/test/jdk/jdk/incubator/vector/gen-template.sh @@ -507,23 +507,23 @@ gen_binary_bcst_op_no_masked "MAX+max" "Math.max(a, b)" gen_saturating_binary_op_associative "SUADD" "VectorMath.addSaturatingUnsigned(a, b)" "BITWISE" # Reductions. -gen_reduction_op "AND" "\&" "BITWISE" "-1" -gen_reduction_op "OR" "|" "BITWISE" "0" -gen_reduction_op "XOR" "^" "BITWISE" "0" -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" "(\$type\$)-1" -gen_reduction_op_func "UMAX" "(\$type\$) VectorMath.maxUnsigned" "BITWISE" "(\$type\$)0" -gen_reduction_op_func "FIRST_NONZERO" "firstNonZero" "" "(\$type\$) 0" +gen_reduction_op "AND" "\&" "BITWISE" "AND_IDENTITY" +gen_reduction_op "OR" "|" "BITWISE" "OR_IDENTITY" +gen_reduction_op "XOR" "^" "BITWISE" "XOR_IDENTITY" +gen_reduction_op "ADD" "+" "" "ADD_IDENTITY" +gen_reduction_op "MUL" "*" "" "MUL_IDENTITY" +gen_reduction_op_func "MIN" "(\$type\$) Math.min" "" "MIN_IDENTITY" +gen_reduction_op_func "MAX" "(\$type\$) Math.max" "" "MAX_IDENTITY" +gen_reduction_op_func "UMIN" "(\$type\$) VectorMath.minUnsigned" "BITWISE" "UMIN_IDENTITY" +gen_reduction_op_func "UMAX" "(\$type\$) VectorMath.maxUnsigned" "BITWISE" "UMAX_IDENTITY" +gen_reduction_op_func "FIRST_NONZERO" "firstNonZero" "" "FIRST_NONZERO_IDENTITY" # Boolean reductions. gen_bool_reduction_op "anyTrue" "|" "BITWISE" "false" gen_bool_reduction_op "allTrue" "\&" "BITWISE" "true" # Saturating reductions. -gen_saturating_reduction_op "SUADD" "(\$type\$) VectorMath.addSaturatingUnsigned" "BITWISE" "0" +gen_saturating_reduction_op "SUADD" "(\$type\$) VectorMath.addSaturatingUnsigned" "BITWISE" "SUADD_IDENTITY" #Insert gen_with_op "withLane" "" "" "" @@ -625,6 +625,9 @@ gen_unary_alu_op "REVERSE_BYTES" "\$Boxtype\$.reverseBytes(a)" "intOrLong" gen_unary_alu_op "REVERSE_BYTES" "\$Boxtype\$.reverseBytes(a)" "short" gen_unary_alu_op "REVERSE_BYTES" "a" "byte" +# Identity value tests +gen_op_tmpl "Identity-test" "Identity" "" "" + # Miscellaneous Smoke Tests gen_op_tmpl $miscellaneous_template "MISC" "" "" diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op-func.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op-func.template index bf03a4d043059..6811884a11779 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op-func.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op-func.template @@ -2,20 +2,14 @@ $type$[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask<$Wideboxtype$> vmask = VectorMask.fromArray(SPECIES, mask, 0); - $type$ ra = [[TEST_INIT]]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); - } - } + $type$ ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - ra = [[TEST_OP]](ra, av.reduceLanes(VectorOperators.[[TEST]], vmask)); + r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); + ra = [[TEST_OP]](ra, r[i]); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op.template index f108491523ed5..95e154168e678 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op.template @@ -2,20 +2,14 @@ $type$[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask<$Wideboxtype$> vmask = VectorMask.fromArray(SPECIES, mask, 0); - $type$ ra = [[TEST_INIT]]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); - } - } + $type$ ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - ra [[TEST_OP]]= av.reduceLanes(VectorOperators.[[TEST]], vmask); + r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); + ra [[TEST_OP]]= r[i]; } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op-func.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op-func.template index 7082ff0795e81..6e573512c97e2 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op-func.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op-func.template @@ -1,19 +1,13 @@ $type$[] a = fa.apply(SPECIES.length()); $type$[] r = fr.apply(SPECIES.length()); - $type$ ra = [[TEST_INIT]]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]]); - } - } + $type$ ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - ra = [[TEST_OP]](ra, av.reduceLanes(VectorOperators.[[TEST]])); + r[i] = av.reduceLanes(VectorOperators.[[TEST]]); + ra = [[TEST_OP]](ra, r[i]); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template index 66250c09213a2..788de2b52a823 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template @@ -1,19 +1,13 @@ $type$[] a = fa.apply(SPECIES.length()); $type$[] r = fr.apply(SPECIES.length()); - $type$ ra = [[TEST_INIT]]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]]); - } - } + $type$ ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - ra [[TEST_OP]]= av.reduceLanes(VectorOperators.[[TEST]]); + r[i] = av.reduceLanes(VectorOperators.[[TEST]]); + ra [[TEST_OP]]= r[i]; } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template index bf03a4d043059..6811884a11779 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template @@ -2,20 +2,14 @@ $type$[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask<$Wideboxtype$> vmask = VectorMask.fromArray(SPECIES, mask, 0); - $type$ ra = [[TEST_INIT]]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); - } - } + $type$ ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - ra = [[TEST_OP]](ra, av.reduceLanes(VectorOperators.[[TEST]], vmask)); + r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); + ra = [[TEST_OP]](ra, r[i]); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template index 7082ff0795e81..6e573512c97e2 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template @@ -1,19 +1,13 @@ $type$[] a = fa.apply(SPECIES.length()); $type$[] r = fr.apply(SPECIES.length()); - $type$ ra = [[TEST_INIT]]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]]); - } - } + $type$ ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - ra = [[TEST_OP]](ra, av.reduceLanes(VectorOperators.[[TEST]])); + r[i] = av.reduceLanes(VectorOperators.[[TEST]]); + ra = [[TEST_OP]](ra, r[i]); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Identity-test.template b/test/jdk/jdk/incubator/vector/templates/Unit-Identity-test.template new file mode 100644 index 0000000000000..1b4b3ddcd40d6 --- /dev/null +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Identity-test.template @@ -0,0 +1,95 @@ + + @Test(dataProvider = "$type$UnaryOpProvider") + static void testIdentityValues(IntFunction<$type$[]> fa) { + $type$[] a = fa.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i++) { + $type$ x = a[i]; + + // ADD identity: 0 + x == x + Assert.assertEquals(($type$)(ADD_IDENTITY + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); +#if[BITWISE] + + // AND identity: -1 & x == x + Assert.assertEquals(($type$)(AND_IDENTITY & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); +#end[BITWISE] + + // FIRST_NONZERO identity: firstNonZero(0, x) == x + Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + // MAX identity: max($Wideboxtype$.$MinValue$, x) == x + Assert.assertEquals(($type$) Math.max(MAX_IDENTITY, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + // MIN identity: min($Wideboxtype$.$MaxValue$, x) == x + Assert.assertEquals(($type$) Math.min(MIN_IDENTITY, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + // MUL identity: 1 * x == x + Assert.assertEquals(($type$)(MUL_IDENTITY * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); +#if[BITWISE] + + // OR identity: 0 | x == x + Assert.assertEquals(($type$)(OR_IDENTITY | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + // SUADD identity: addSaturatingUnsigned(0, x) == x + Assert.assertEquals(($type$) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + // UMAX identity: maxUnsigned(0, x) == x + Assert.assertEquals(($type$) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + // UMIN identity: minUnsigned(-1, x) == x + Assert.assertEquals(($type$) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + // XOR identity: 0 ^ x == x + Assert.assertEquals(($type$)(XOR_IDENTITY ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); +#end[BITWISE] + } + } + + @Test(dataProvider = "$type$UnaryOpProvider") + static void testMaskedReductionIdentityAllFalse(IntFunction<$type$[]> fa) { + $type$[] a = fa.apply(SPECIES.length()); + VectorMask<$Wideboxtype$> allFalseMask = SPECIES.maskAll(false); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); + + // When mask is all false, reduction should return identity value + Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, + "ADD with all-false mask should return ADD_IDENTITY"); +#if[BITWISE] + Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, + "AND with all-false mask should return AND_IDENTITY"); +#end[BITWISE] + Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, + "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, + "MAX with all-false mask should return MAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, + "MIN with all-false mask should return MIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, + "MUL with all-false mask should return MUL_IDENTITY"); +#if[BITWISE] + Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, + "OR with all-false mask should return OR_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, + "SUADD with all-false mask should return SUADD_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, + "UMAX with all-false mask should return UMAX_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, + "UMIN with all-false mask should return UMIN_IDENTITY"); + Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, + "XOR with all-false mask should return XOR_IDENTITY"); +#end[BITWISE] + } + } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-header.template b/test/jdk/jdk/incubator/vector/templates/Unit-header.template index b389dd1cedbe7..44f6bb7971d03 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-header.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-header.template @@ -98,6 +98,23 @@ public class $vectorteststype$ extends AbstractVectorTest { #if[BITWISE] private static final $type$ CONST_SHIFT = $Boxtype$.SIZE / 2; #end[BITWISE] + + // Identity values for reduction operations + private static final $type$ ADD_IDENTITY = ($type$)0; +#if[BITWISE] + private static final $type$ AND_IDENTITY = ($type$)-1; +#end[BITWISE] + private static final $type$ FIRST_NONZERO_IDENTITY = ($type$)0; + private static final $type$ MAX_IDENTITY = $Wideboxtype$.$MinValue$; + private static final $type$ MIN_IDENTITY = $Wideboxtype$.$MaxValue$; + private static final $type$ MUL_IDENTITY = ($type$)1; +#if[BITWISE] + private static final $type$ OR_IDENTITY = ($type$)0; + private static final $type$ SUADD_IDENTITY = ($type$)0; + private static final $type$ UMAX_IDENTITY = ($type$)0; // Minimum unsigned value + private static final $type$ UMIN_IDENTITY = ($type$)-1; // Maximum unsigned value + private static final $type$ XOR_IDENTITY = ($type$)0; +#end[BITWISE] #if[FP] // for floating point addition reduction ops that may introduce rounding errors private static final $type$ RELATIVE_ROUNDING_ERROR_FACTOR_ADD = ($type$)10.0; From b5237a289448887b8334158921ee4a1f21194521 Mon Sep 17 00:00:00 2001 From: erfang Date: Fri, 19 Dec 2025 09:45:37 +0000 Subject: [PATCH 3/3] Refine the tests for identity values --- .../incubator/vector/Byte128VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Byte256VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Byte512VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Byte64VectorTests.java | 396 ++++++++++++------ .../incubator/vector/ByteMaxVectorTests.java | 395 +++++++++++------ .../vector/Double128VectorTests.java | 194 +++++---- .../vector/Double256VectorTests.java | 194 +++++---- .../vector/Double512VectorTests.java | 194 +++++---- .../incubator/vector/Double64VectorTests.java | 194 +++++---- .../vector/DoubleMaxVectorTests.java | 193 +++++---- .../incubator/vector/Float128VectorTests.java | 194 +++++---- .../incubator/vector/Float256VectorTests.java | 194 +++++---- .../incubator/vector/Float512VectorTests.java | 194 +++++---- .../incubator/vector/Float64VectorTests.java | 194 +++++---- .../incubator/vector/FloatMaxVectorTests.java | 193 +++++---- .../incubator/vector/Int128VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Int256VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Int512VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Int64VectorTests.java | 396 ++++++++++++------ .../incubator/vector/IntMaxVectorTests.java | 395 +++++++++++------ .../incubator/vector/Long128VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Long256VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Long512VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Long64VectorTests.java | 396 ++++++++++++------ .../incubator/vector/LongMaxVectorTests.java | 395 +++++++++++------ .../incubator/vector/Short128VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Short256VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Short512VectorTests.java | 396 ++++++++++++------ .../incubator/vector/Short64VectorTests.java | 396 ++++++++++++------ .../incubator/vector/ShortMaxVectorTests.java | 395 +++++++++++------ test/jdk/jdk/incubator/vector/gen-template.sh | 3 - .../Kernel-Reduction-Masked-op-func.template | 5 +- .../Kernel-Reduction-Masked-op.template | 5 +- .../Kernel-Reduction-op-func.template | 5 +- .../templates/Kernel-Reduction-op.template | 5 +- ...nel-SaturatingReduction-Masked-op.template | 5 +- .../Kernel-SaturatingReduction-op.template | 5 +- .../templates/Unit-Identity-test.template | 95 ----- .../templates/Unit-Reduction-op-func.template | 18 + .../templates/Unit-Reduction-op.template | 18 + .../Unit-SaturatingReduction-op.template | 18 + .../vector/templates/Unit-header.template | 5 +- 42 files changed, 6565 insertions(+), 3476 deletions(-) delete mode 100644 test/jdk/jdk/incubator/vector/templates/Unit-Identity-test.template diff --git a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java index 4368a80c52639..9693583a47525 100644 --- a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java @@ -63,7 +63,6 @@ public class Byte128VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final byte CONST_SHIFT = Byte.SIZE / 2; // Identity values for reduction operations @@ -3651,8 +3650,9 @@ static void ANDReduceByte128VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3660,6 +3660,24 @@ static void ANDReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::ANDReduce, Byte128VectorTests::ANDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = AND_IDENTITY; + + Assert.assertEquals((byte) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3691,8 +3709,9 @@ static void ANDReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3728,8 +3747,9 @@ static void ORReduceByte128VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3737,6 +3757,24 @@ static void ORReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::ORReduce, Byte128VectorTests::ORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = OR_IDENTITY; + + Assert.assertEquals((byte) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3768,8 +3806,9 @@ static void ORReduceByte128VectorTestsMasked(IntFunction fa, IntFunction ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3805,8 +3844,9 @@ static void XORReduceByte128VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3814,6 +3854,24 @@ static void XORReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::XORReduce, Byte128VectorTests::XORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = XOR_IDENTITY; + + Assert.assertEquals((byte) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3845,8 +3903,9 @@ static void XORReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3882,8 +3941,9 @@ static void ADDReduceByte128VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3891,6 +3951,24 @@ static void ADDReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::ADDReduce, Byte128VectorTests::ADDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = ADD_IDENTITY; + + Assert.assertEquals((byte) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3922,8 +4000,9 @@ static void ADDReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3959,8 +4038,9 @@ static void MULReduceByte128VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3968,6 +4048,24 @@ static void MULReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::MULReduce, Byte128VectorTests::MULReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MUL_IDENTITY; + + Assert.assertEquals((byte) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3999,8 +4097,9 @@ static void MULReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4036,8 +4135,9 @@ static void MINReduceByte128VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4045,6 +4145,24 @@ static void MINReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::MINReduce, Byte128VectorTests::MINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MIN_IDENTITY; + + Assert.assertEquals((byte) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4076,8 +4194,9 @@ static void MINReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4113,8 +4232,9 @@ static void MAXReduceByte128VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4122,6 +4242,24 @@ static void MAXReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::MAXReduce, Byte128VectorTests::MAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MAX_IDENTITY; + + Assert.assertEquals((byte) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4153,8 +4291,9 @@ static void MAXReduceByte128VectorTestsMasked(IntFunction fa, IntFunctio ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4190,8 +4329,9 @@ static void UMINReduceByte128VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4199,6 +4339,24 @@ static void UMINReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::UMINReduce, Byte128VectorTests::UMINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMIN_IDENTITY; + + Assert.assertEquals((byte) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4230,8 +4388,9 @@ static void UMINReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4267,8 +4426,9 @@ static void UMAXReduceByte128VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4276,6 +4436,24 @@ static void UMAXReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::UMAXReduce, Byte128VectorTests::UMAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMAX_IDENTITY; + + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4307,8 +4485,9 @@ static void UMAXReduceByte128VectorTestsMasked(IntFunction fa, IntFuncti ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4344,8 +4523,9 @@ static void FIRST_NONZEROReduceByte128VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4353,6 +4533,24 @@ static void FIRST_NONZEROReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::FIRST_NONZEROReduce, Byte128VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4384,8 +4582,9 @@ static void FIRST_NONZEROReduceByte128VectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4469,8 +4668,9 @@ static void SUADDReduceByte128VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4478,6 +4678,24 @@ static void SUADDReduceByte128VectorTests(IntFunction fa) { Byte128VectorTests::SUADDReduce, Byte128VectorTests::SUADDReduceAll); } + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = SUADD_IDENTITY; + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4508,8 +4726,9 @@ static void SUADDReduceByte128VectorTestsMasked(IntFunction fa, IntFunct ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6467,93 +6686,6 @@ static void maskFromToLongByte128VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "byteUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - byte x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((byte)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((byte)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Byte.MIN_VALUE, x) == x - Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Byte.MAX_VALUE, x) == x - Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((byte)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((byte)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "byteUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByte128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java index da52827d29328..1316f9cf2fe82 100644 --- a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java @@ -63,7 +63,6 @@ public class Byte256VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final byte CONST_SHIFT = Byte.SIZE / 2; // Identity values for reduction operations @@ -3651,8 +3650,9 @@ static void ANDReduceByte256VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3660,6 +3660,24 @@ static void ANDReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::ANDReduce, Byte256VectorTests::ANDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = AND_IDENTITY; + + Assert.assertEquals((byte) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3691,8 +3709,9 @@ static void ANDReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3728,8 +3747,9 @@ static void ORReduceByte256VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3737,6 +3757,24 @@ static void ORReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::ORReduce, Byte256VectorTests::ORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = OR_IDENTITY; + + Assert.assertEquals((byte) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3768,8 +3806,9 @@ static void ORReduceByte256VectorTestsMasked(IntFunction fa, IntFunction ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3805,8 +3844,9 @@ static void XORReduceByte256VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3814,6 +3854,24 @@ static void XORReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::XORReduce, Byte256VectorTests::XORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = XOR_IDENTITY; + + Assert.assertEquals((byte) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3845,8 +3903,9 @@ static void XORReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3882,8 +3941,9 @@ static void ADDReduceByte256VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3891,6 +3951,24 @@ static void ADDReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::ADDReduce, Byte256VectorTests::ADDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = ADD_IDENTITY; + + Assert.assertEquals((byte) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3922,8 +4000,9 @@ static void ADDReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3959,8 +4038,9 @@ static void MULReduceByte256VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3968,6 +4048,24 @@ static void MULReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::MULReduce, Byte256VectorTests::MULReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MUL_IDENTITY; + + Assert.assertEquals((byte) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3999,8 +4097,9 @@ static void MULReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4036,8 +4135,9 @@ static void MINReduceByte256VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4045,6 +4145,24 @@ static void MINReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::MINReduce, Byte256VectorTests::MINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MIN_IDENTITY; + + Assert.assertEquals((byte) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4076,8 +4194,9 @@ static void MINReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4113,8 +4232,9 @@ static void MAXReduceByte256VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4122,6 +4242,24 @@ static void MAXReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::MAXReduce, Byte256VectorTests::MAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MAX_IDENTITY; + + Assert.assertEquals((byte) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4153,8 +4291,9 @@ static void MAXReduceByte256VectorTestsMasked(IntFunction fa, IntFunctio ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4190,8 +4329,9 @@ static void UMINReduceByte256VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4199,6 +4339,24 @@ static void UMINReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::UMINReduce, Byte256VectorTests::UMINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMIN_IDENTITY; + + Assert.assertEquals((byte) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4230,8 +4388,9 @@ static void UMINReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4267,8 +4426,9 @@ static void UMAXReduceByte256VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4276,6 +4436,24 @@ static void UMAXReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::UMAXReduce, Byte256VectorTests::UMAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMAX_IDENTITY; + + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4307,8 +4485,9 @@ static void UMAXReduceByte256VectorTestsMasked(IntFunction fa, IntFuncti ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4344,8 +4523,9 @@ static void FIRST_NONZEROReduceByte256VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4353,6 +4533,24 @@ static void FIRST_NONZEROReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::FIRST_NONZEROReduce, Byte256VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4384,8 +4582,9 @@ static void FIRST_NONZEROReduceByte256VectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4469,8 +4668,9 @@ static void SUADDReduceByte256VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4478,6 +4678,24 @@ static void SUADDReduceByte256VectorTests(IntFunction fa) { Byte256VectorTests::SUADDReduce, Byte256VectorTests::SUADDReduceAll); } + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = SUADD_IDENTITY; + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4508,8 +4726,9 @@ static void SUADDReduceByte256VectorTestsMasked(IntFunction fa, IntFunct ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6467,93 +6686,6 @@ static void maskFromToLongByte256VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "byteUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - byte x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((byte)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((byte)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Byte.MIN_VALUE, x) == x - Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Byte.MAX_VALUE, x) == x - Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((byte)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((byte)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "byteUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByte256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java index bc6b288921080..feacfd6a68f3b 100644 --- a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java @@ -63,7 +63,6 @@ public class Byte512VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final byte CONST_SHIFT = Byte.SIZE / 2; // Identity values for reduction operations @@ -3651,8 +3650,9 @@ static void ANDReduceByte512VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3660,6 +3660,24 @@ static void ANDReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::ANDReduce, Byte512VectorTests::ANDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = AND_IDENTITY; + + Assert.assertEquals((byte) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3691,8 +3709,9 @@ static void ANDReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3728,8 +3747,9 @@ static void ORReduceByte512VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3737,6 +3757,24 @@ static void ORReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::ORReduce, Byte512VectorTests::ORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = OR_IDENTITY; + + Assert.assertEquals((byte) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3768,8 +3806,9 @@ static void ORReduceByte512VectorTestsMasked(IntFunction fa, IntFunction ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3805,8 +3844,9 @@ static void XORReduceByte512VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3814,6 +3854,24 @@ static void XORReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::XORReduce, Byte512VectorTests::XORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = XOR_IDENTITY; + + Assert.assertEquals((byte) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3845,8 +3903,9 @@ static void XORReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3882,8 +3941,9 @@ static void ADDReduceByte512VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3891,6 +3951,24 @@ static void ADDReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::ADDReduce, Byte512VectorTests::ADDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = ADD_IDENTITY; + + Assert.assertEquals((byte) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3922,8 +4000,9 @@ static void ADDReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3959,8 +4038,9 @@ static void MULReduceByte512VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3968,6 +4048,24 @@ static void MULReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::MULReduce, Byte512VectorTests::MULReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MUL_IDENTITY; + + Assert.assertEquals((byte) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3999,8 +4097,9 @@ static void MULReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4036,8 +4135,9 @@ static void MINReduceByte512VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4045,6 +4145,24 @@ static void MINReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::MINReduce, Byte512VectorTests::MINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MIN_IDENTITY; + + Assert.assertEquals((byte) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4076,8 +4194,9 @@ static void MINReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4113,8 +4232,9 @@ static void MAXReduceByte512VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4122,6 +4242,24 @@ static void MAXReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::MAXReduce, Byte512VectorTests::MAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MAX_IDENTITY; + + Assert.assertEquals((byte) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4153,8 +4291,9 @@ static void MAXReduceByte512VectorTestsMasked(IntFunction fa, IntFunctio ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4190,8 +4329,9 @@ static void UMINReduceByte512VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4199,6 +4339,24 @@ static void UMINReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::UMINReduce, Byte512VectorTests::UMINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMIN_IDENTITY; + + Assert.assertEquals((byte) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4230,8 +4388,9 @@ static void UMINReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4267,8 +4426,9 @@ static void UMAXReduceByte512VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4276,6 +4436,24 @@ static void UMAXReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::UMAXReduce, Byte512VectorTests::UMAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMAX_IDENTITY; + + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4307,8 +4485,9 @@ static void UMAXReduceByte512VectorTestsMasked(IntFunction fa, IntFuncti ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4344,8 +4523,9 @@ static void FIRST_NONZEROReduceByte512VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4353,6 +4533,24 @@ static void FIRST_NONZEROReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::FIRST_NONZEROReduce, Byte512VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4384,8 +4582,9 @@ static void FIRST_NONZEROReduceByte512VectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4469,8 +4668,9 @@ static void SUADDReduceByte512VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4478,6 +4678,24 @@ static void SUADDReduceByte512VectorTests(IntFunction fa) { Byte512VectorTests::SUADDReduce, Byte512VectorTests::SUADDReduceAll); } + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = SUADD_IDENTITY; + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4508,8 +4726,9 @@ static void SUADDReduceByte512VectorTestsMasked(IntFunction fa, IntFunct ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6467,93 +6686,6 @@ static void maskFromToLongByte512VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "byteUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - byte x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((byte)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((byte)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Byte.MIN_VALUE, x) == x - Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Byte.MAX_VALUE, x) == x - Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((byte)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((byte)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "byteUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByte512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java index eab538c98c6f4..5f8e3fefdfdcd 100644 --- a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java @@ -63,7 +63,6 @@ public class Byte64VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final byte CONST_SHIFT = Byte.SIZE / 2; // Identity values for reduction operations @@ -3651,8 +3650,9 @@ static void ANDReduceByte64VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3660,6 +3660,24 @@ static void ANDReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::ANDReduce, Byte64VectorTests::ANDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = AND_IDENTITY; + + Assert.assertEquals((byte) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3691,8 +3709,9 @@ static void ANDReduceByte64VectorTestsMasked(IntFunction fa, IntFunction ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3728,8 +3747,9 @@ static void ORReduceByte64VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3737,6 +3757,24 @@ static void ORReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::ORReduce, Byte64VectorTests::ORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = OR_IDENTITY; + + Assert.assertEquals((byte) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3768,8 +3806,9 @@ static void ORReduceByte64VectorTestsMasked(IntFunction fa, IntFunction< ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3805,8 +3844,9 @@ static void XORReduceByte64VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3814,6 +3854,24 @@ static void XORReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::XORReduce, Byte64VectorTests::XORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = XOR_IDENTITY; + + Assert.assertEquals((byte) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3845,8 +3903,9 @@ static void XORReduceByte64VectorTestsMasked(IntFunction fa, IntFunction ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3882,8 +3941,9 @@ static void ADDReduceByte64VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3891,6 +3951,24 @@ static void ADDReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::ADDReduce, Byte64VectorTests::ADDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = ADD_IDENTITY; + + Assert.assertEquals((byte) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3922,8 +4000,9 @@ static void ADDReduceByte64VectorTestsMasked(IntFunction fa, IntFunction ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3959,8 +4038,9 @@ static void MULReduceByte64VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3968,6 +4048,24 @@ static void MULReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::MULReduce, Byte64VectorTests::MULReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MUL_IDENTITY; + + Assert.assertEquals((byte) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3999,8 +4097,9 @@ static void MULReduceByte64VectorTestsMasked(IntFunction fa, IntFunction ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4036,8 +4135,9 @@ static void MINReduceByte64VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4045,6 +4145,24 @@ static void MINReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::MINReduce, Byte64VectorTests::MINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MIN_IDENTITY; + + Assert.assertEquals((byte) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4076,8 +4194,9 @@ static void MINReduceByte64VectorTestsMasked(IntFunction fa, IntFunction ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4113,8 +4232,9 @@ static void MAXReduceByte64VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4122,6 +4242,24 @@ static void MAXReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::MAXReduce, Byte64VectorTests::MAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MAX_IDENTITY; + + Assert.assertEquals((byte) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4153,8 +4291,9 @@ static void MAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunction ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4190,8 +4329,9 @@ static void UMINReduceByte64VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4199,6 +4339,24 @@ static void UMINReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::UMINReduce, Byte64VectorTests::UMINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMIN_IDENTITY; + + Assert.assertEquals((byte) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4230,8 +4388,9 @@ static void UMINReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4267,8 +4426,9 @@ static void UMAXReduceByte64VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4276,6 +4436,24 @@ static void UMAXReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::UMAXReduce, Byte64VectorTests::UMAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMAX_IDENTITY; + + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4307,8 +4485,9 @@ static void UMAXReduceByte64VectorTestsMasked(IntFunction fa, IntFunctio ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4344,8 +4523,9 @@ static void FIRST_NONZEROReduceByte64VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4353,6 +4533,24 @@ static void FIRST_NONZEROReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::FIRST_NONZEROReduce, Byte64VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4384,8 +4582,9 @@ static void FIRST_NONZEROReduceByte64VectorTestsMasked(IntFunction fa, I ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4469,8 +4668,9 @@ static void SUADDReduceByte64VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4478,6 +4678,24 @@ static void SUADDReduceByte64VectorTests(IntFunction fa) { Byte64VectorTests::SUADDReduce, Byte64VectorTests::SUADDReduceAll); } + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = SUADD_IDENTITY; + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4508,8 +4726,9 @@ static void SUADDReduceByte64VectorTestsMasked(IntFunction fa, IntFuncti ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6467,93 +6686,6 @@ static void maskFromToLongByte64VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "byteUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - byte x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((byte)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((byte)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Byte.MIN_VALUE, x) == x - Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Byte.MAX_VALUE, x) == x - Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((byte)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((byte)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "byteUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByte64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java index 34911c33d0401..9422d8f8f6967 100644 --- a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java @@ -3656,8 +3656,9 @@ static void ANDReduceByteMaxVectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3665,6 +3666,24 @@ static void ANDReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::ANDReduce, ByteMaxVectorTests::ANDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = AND_IDENTITY; + + Assert.assertEquals((byte) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3696,8 +3715,9 @@ static void ANDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + byte v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3733,8 +3753,9 @@ static void ORReduceByteMaxVectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3742,6 +3763,24 @@ static void ORReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::ORReduce, ByteMaxVectorTests::ORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = OR_IDENTITY; + + Assert.assertEquals((byte) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3773,8 +3812,9 @@ static void ORReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunction ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + byte v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3810,8 +3850,9 @@ static void XORReduceByteMaxVectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3819,6 +3860,24 @@ static void XORReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::XORReduce, ByteMaxVectorTests::XORReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = XOR_IDENTITY; + + Assert.assertEquals((byte) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3850,8 +3909,9 @@ static void XORReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + byte v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3887,8 +3947,9 @@ static void ADDReduceByteMaxVectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3896,6 +3957,24 @@ static void ADDReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::ADDReduce, ByteMaxVectorTests::ADDReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = ADD_IDENTITY; + + Assert.assertEquals((byte) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3927,8 +4006,9 @@ static void ADDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + byte v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3964,8 +4044,9 @@ static void MULReduceByteMaxVectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3973,6 +4054,24 @@ static void MULReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::MULReduce, ByteMaxVectorTests::MULReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MUL_IDENTITY; + + Assert.assertEquals((byte) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4004,8 +4103,9 @@ static void MULReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + byte v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4041,8 +4141,9 @@ static void MINReduceByteMaxVectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4050,6 +4151,24 @@ static void MINReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::MINReduce, ByteMaxVectorTests::MINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MIN_IDENTITY; + + Assert.assertEquals((byte) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4081,8 +4200,9 @@ static void MINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (byte) Math.min(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (byte) Math.min(ra, v); } } @@ -4118,8 +4238,9 @@ static void MAXReduceByteMaxVectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4127,6 +4248,24 @@ static void MAXReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::MAXReduce, ByteMaxVectorTests::MAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = MAX_IDENTITY; + + Assert.assertEquals((byte) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4158,8 +4297,9 @@ static void MAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (byte) Math.max(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (byte) Math.max(ra, v); } } @@ -4195,8 +4335,9 @@ static void UMINReduceByteMaxVectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4204,6 +4345,24 @@ static void UMINReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::UMINReduce, ByteMaxVectorTests::UMINReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMIN_IDENTITY; + + Assert.assertEquals((byte) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4235,8 +4394,9 @@ static void UMINReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (byte) VectorMath.minUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (byte) VectorMath.minUnsigned(ra, v); } } @@ -4272,8 +4432,9 @@ static void UMAXReduceByteMaxVectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4281,6 +4442,24 @@ static void UMAXReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::UMAXReduce, ByteMaxVectorTests::UMAXReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = UMAX_IDENTITY; + + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4312,8 +4491,9 @@ static void UMAXReduceByteMaxVectorTestsMasked(IntFunction fa, IntFuncti ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (byte) VectorMath.maxUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (byte) VectorMath.maxUnsigned(ra, v); } } @@ -4349,8 +4529,9 @@ static void FIRST_NONZEROReduceByteMaxVectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4358,6 +4539,24 @@ static void FIRST_NONZEROReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::FIRST_NONZEROReduce, ByteMaxVectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "byteUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4389,8 +4588,9 @@ static void FIRST_NONZEROReduceByteMaxVectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4474,8 +4674,9 @@ static void SUADDReduceByteMaxVectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4483,6 +4684,24 @@ static void SUADDReduceByteMaxVectorTests(IntFunction fa) { ByteMaxVectorTests::SUADDReduce, ByteMaxVectorTests::SUADDReduceAll); } + @Test(dataProvider = "byteSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte id = SUADD_IDENTITY; + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + byte x = a[i]; + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) { byte res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4513,8 +4732,9 @@ static void SUADDReduceByteMaxVectorTestsMasked(IntFunction fa, IntFunct ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ByteVector av = ByteVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (byte) VectorMath.addSaturatingUnsigned(ra, r[i]); + byte v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (byte) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6472,93 +6692,6 @@ static void maskFromToLongByteMaxVectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "byteUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - byte x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((byte)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((byte)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Byte.MIN_VALUE, x) == x - Assert.assertEquals((byte) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Byte.MAX_VALUE, x) == x - Assert.assertEquals((byte) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((byte)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((byte)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((byte) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((byte) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((byte)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "byteUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - byte[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { byte[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Double128VectorTests.java b/test/jdk/jdk/incubator/vector/Double128VectorTests.java index 8b60e13981ffe..c0b4389681625 100644 --- a/test/jdk/jdk/incubator/vector/Double128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double128VectorTests.java @@ -62,14 +62,13 @@ public class Double128VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - - // Identity values for reduction operations private static final double ADD_IDENTITY = (double)0; private static final double FIRST_NONZERO_IDENTITY = (double)0; private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; private static final double MUL_IDENTITY = (double)1; + // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2418,8 +2417,9 @@ static void ADDReduceDouble128VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2427,6 +2427,24 @@ static void ADDReduceDouble128VectorTests(IntFunction fa) { Double128VectorTests::ADDReduce, Double128VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = ADD_IDENTITY; + + Assert.assertEquals((double) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2458,8 +2476,9 @@ static void ADDReduceDouble128VectorTestsMasked(IntFunction fa, IntFun ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2495,8 +2514,9 @@ static void MULReduceDouble128VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2504,6 +2524,24 @@ static void MULReduceDouble128VectorTests(IntFunction fa) { Double128VectorTests::MULReduce, Double128VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MUL_IDENTITY; + + Assert.assertEquals((double) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static double MULReduceMasked(double[] a, int idx, boolean[] mask) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2535,8 +2573,9 @@ static void MULReduceDouble128VectorTestsMasked(IntFunction fa, IntFun ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2572,8 +2611,9 @@ static void MINReduceDouble128VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2581,6 +2621,24 @@ static void MINReduceDouble128VectorTests(IntFunction fa) { Double128VectorTests::MINReduce, Double128VectorTests::MINReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MIN_IDENTITY; + + Assert.assertEquals((double) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static double MINReduceMasked(double[] a, int idx, boolean[] mask) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2612,8 +2670,9 @@ static void MINReduceDouble128VectorTestsMasked(IntFunction fa, IntFun ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2649,8 +2708,9 @@ static void MAXReduceDouble128VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2658,6 +2718,24 @@ static void MAXReduceDouble128VectorTests(IntFunction fa) { Double128VectorTests::MAXReduce, Double128VectorTests::MAXReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MAX_IDENTITY; + + Assert.assertEquals((double) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2689,8 +2767,9 @@ static void MAXReduceDouble128VectorTestsMasked(IntFunction fa, IntFun ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2726,8 +2805,9 @@ static void FIRST_NONZEROReduceDouble128VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2735,6 +2815,24 @@ static void FIRST_NONZEROReduceDouble128VectorTests(IntFunction fa) { Double128VectorTests::FIRST_NONZEROReduce, Double128VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2766,8 +2864,9 @@ static void FIRST_NONZEROReduceDouble128VectorTestsMasked(IntFunction ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4949,57 +5048,6 @@ static void maskFromToLongDouble128VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "doubleUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - double x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((double)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Double.POSITIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((double)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "doubleUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Double256VectorTests.java b/test/jdk/jdk/incubator/vector/Double256VectorTests.java index b6c8948524371..e6498a725eb87 100644 --- a/test/jdk/jdk/incubator/vector/Double256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double256VectorTests.java @@ -62,14 +62,13 @@ public class Double256VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - - // Identity values for reduction operations private static final double ADD_IDENTITY = (double)0; private static final double FIRST_NONZERO_IDENTITY = (double)0; private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; private static final double MUL_IDENTITY = (double)1; + // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2418,8 +2417,9 @@ static void ADDReduceDouble256VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2427,6 +2427,24 @@ static void ADDReduceDouble256VectorTests(IntFunction fa) { Double256VectorTests::ADDReduce, Double256VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = ADD_IDENTITY; + + Assert.assertEquals((double) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2458,8 +2476,9 @@ static void ADDReduceDouble256VectorTestsMasked(IntFunction fa, IntFun ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2495,8 +2514,9 @@ static void MULReduceDouble256VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2504,6 +2524,24 @@ static void MULReduceDouble256VectorTests(IntFunction fa) { Double256VectorTests::MULReduce, Double256VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MUL_IDENTITY; + + Assert.assertEquals((double) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static double MULReduceMasked(double[] a, int idx, boolean[] mask) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2535,8 +2573,9 @@ static void MULReduceDouble256VectorTestsMasked(IntFunction fa, IntFun ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2572,8 +2611,9 @@ static void MINReduceDouble256VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2581,6 +2621,24 @@ static void MINReduceDouble256VectorTests(IntFunction fa) { Double256VectorTests::MINReduce, Double256VectorTests::MINReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MIN_IDENTITY; + + Assert.assertEquals((double) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static double MINReduceMasked(double[] a, int idx, boolean[] mask) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2612,8 +2670,9 @@ static void MINReduceDouble256VectorTestsMasked(IntFunction fa, IntFun ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2649,8 +2708,9 @@ static void MAXReduceDouble256VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2658,6 +2718,24 @@ static void MAXReduceDouble256VectorTests(IntFunction fa) { Double256VectorTests::MAXReduce, Double256VectorTests::MAXReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MAX_IDENTITY; + + Assert.assertEquals((double) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2689,8 +2767,9 @@ static void MAXReduceDouble256VectorTestsMasked(IntFunction fa, IntFun ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2726,8 +2805,9 @@ static void FIRST_NONZEROReduceDouble256VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2735,6 +2815,24 @@ static void FIRST_NONZEROReduceDouble256VectorTests(IntFunction fa) { Double256VectorTests::FIRST_NONZEROReduce, Double256VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2766,8 +2864,9 @@ static void FIRST_NONZEROReduceDouble256VectorTestsMasked(IntFunction ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4949,57 +5048,6 @@ static void maskFromToLongDouble256VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "doubleUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - double x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((double)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Double.POSITIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((double)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "doubleUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Double512VectorTests.java b/test/jdk/jdk/incubator/vector/Double512VectorTests.java index e22308a51a7e2..f7fafbc7c9ab9 100644 --- a/test/jdk/jdk/incubator/vector/Double512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double512VectorTests.java @@ -62,14 +62,13 @@ public class Double512VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - - // Identity values for reduction operations private static final double ADD_IDENTITY = (double)0; private static final double FIRST_NONZERO_IDENTITY = (double)0; private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; private static final double MUL_IDENTITY = (double)1; + // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2418,8 +2417,9 @@ static void ADDReduceDouble512VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2427,6 +2427,24 @@ static void ADDReduceDouble512VectorTests(IntFunction fa) { Double512VectorTests::ADDReduce, Double512VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = ADD_IDENTITY; + + Assert.assertEquals((double) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2458,8 +2476,9 @@ static void ADDReduceDouble512VectorTestsMasked(IntFunction fa, IntFun ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2495,8 +2514,9 @@ static void MULReduceDouble512VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2504,6 +2524,24 @@ static void MULReduceDouble512VectorTests(IntFunction fa) { Double512VectorTests::MULReduce, Double512VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MUL_IDENTITY; + + Assert.assertEquals((double) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static double MULReduceMasked(double[] a, int idx, boolean[] mask) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2535,8 +2573,9 @@ static void MULReduceDouble512VectorTestsMasked(IntFunction fa, IntFun ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2572,8 +2611,9 @@ static void MINReduceDouble512VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2581,6 +2621,24 @@ static void MINReduceDouble512VectorTests(IntFunction fa) { Double512VectorTests::MINReduce, Double512VectorTests::MINReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MIN_IDENTITY; + + Assert.assertEquals((double) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static double MINReduceMasked(double[] a, int idx, boolean[] mask) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2612,8 +2670,9 @@ static void MINReduceDouble512VectorTestsMasked(IntFunction fa, IntFun ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2649,8 +2708,9 @@ static void MAXReduceDouble512VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2658,6 +2718,24 @@ static void MAXReduceDouble512VectorTests(IntFunction fa) { Double512VectorTests::MAXReduce, Double512VectorTests::MAXReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MAX_IDENTITY; + + Assert.assertEquals((double) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2689,8 +2767,9 @@ static void MAXReduceDouble512VectorTestsMasked(IntFunction fa, IntFun ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2726,8 +2805,9 @@ static void FIRST_NONZEROReduceDouble512VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2735,6 +2815,24 @@ static void FIRST_NONZEROReduceDouble512VectorTests(IntFunction fa) { Double512VectorTests::FIRST_NONZEROReduce, Double512VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2766,8 +2864,9 @@ static void FIRST_NONZEROReduceDouble512VectorTestsMasked(IntFunction ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4949,57 +5048,6 @@ static void maskFromToLongDouble512VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "doubleUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - double x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((double)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Double.POSITIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((double)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "doubleUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Double64VectorTests.java b/test/jdk/jdk/incubator/vector/Double64VectorTests.java index 75126d51c58c3..fd711cd4935ee 100644 --- a/test/jdk/jdk/incubator/vector/Double64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double64VectorTests.java @@ -62,14 +62,13 @@ public class Double64VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - - // Identity values for reduction operations private static final double ADD_IDENTITY = (double)0; private static final double FIRST_NONZERO_IDENTITY = (double)0; private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; private static final double MUL_IDENTITY = (double)1; + // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2418,8 +2417,9 @@ static void ADDReduceDouble64VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2427,6 +2427,24 @@ static void ADDReduceDouble64VectorTests(IntFunction fa) { Double64VectorTests::ADDReduce, Double64VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = ADD_IDENTITY; + + Assert.assertEquals((double) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2458,8 +2476,9 @@ static void ADDReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2495,8 +2514,9 @@ static void MULReduceDouble64VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2504,6 +2524,24 @@ static void MULReduceDouble64VectorTests(IntFunction fa) { Double64VectorTests::MULReduce, Double64VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MUL_IDENTITY; + + Assert.assertEquals((double) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static double MULReduceMasked(double[] a, int idx, boolean[] mask) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2535,8 +2573,9 @@ static void MULReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2572,8 +2611,9 @@ static void MINReduceDouble64VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2581,6 +2621,24 @@ static void MINReduceDouble64VectorTests(IntFunction fa) { Double64VectorTests::MINReduce, Double64VectorTests::MINReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MIN_IDENTITY; + + Assert.assertEquals((double) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static double MINReduceMasked(double[] a, int idx, boolean[] mask) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2612,8 +2670,9 @@ static void MINReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2649,8 +2708,9 @@ static void MAXReduceDouble64VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2658,6 +2718,24 @@ static void MAXReduceDouble64VectorTests(IntFunction fa) { Double64VectorTests::MAXReduce, Double64VectorTests::MAXReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MAX_IDENTITY; + + Assert.assertEquals((double) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2689,8 +2767,9 @@ static void MAXReduceDouble64VectorTestsMasked(IntFunction fa, IntFunc ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2726,8 +2805,9 @@ static void FIRST_NONZEROReduceDouble64VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2735,6 +2815,24 @@ static void FIRST_NONZEROReduceDouble64VectorTests(IntFunction fa) { Double64VectorTests::FIRST_NONZEROReduce, Double64VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2766,8 +2864,9 @@ static void FIRST_NONZEROReduceDouble64VectorTestsMasked(IntFunction f ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4949,57 +5048,6 @@ static void maskFromToLongDouble64VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "doubleUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - double x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((double)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Double.POSITIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((double)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "doubleUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java index 4fa135beb2631..53e920eb30024 100644 --- a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java @@ -68,13 +68,13 @@ static VectorShape getMaxBit() { private static final int Max = 256; // juts so we can do N/Max - // Identity values for reduction operations private static final double ADD_IDENTITY = (double)0; private static final double FIRST_NONZERO_IDENTITY = (double)0; private static final double MAX_IDENTITY = Double.NEGATIVE_INFINITY; private static final double MIN_IDENTITY = Double.POSITIVE_INFINITY; private static final double MUL_IDENTITY = (double)1; + // for floating point addition reduction ops that may introduce rounding errors private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0; @@ -2423,8 +2423,9 @@ static void ADDReduceDoubleMaxVectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2432,6 +2433,24 @@ static void ADDReduceDoubleMaxVectorTests(IntFunction fa) { DoubleMaxVectorTests::ADDReduce, DoubleMaxVectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = ADD_IDENTITY; + + Assert.assertEquals((double) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2463,8 +2482,9 @@ static void ADDReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + double v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2500,8 +2520,9 @@ static void MULReduceDoubleMaxVectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2509,6 +2530,24 @@ static void MULReduceDoubleMaxVectorTests(IntFunction fa) { DoubleMaxVectorTests::MULReduce, DoubleMaxVectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MUL_IDENTITY; + + Assert.assertEquals((double) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static double MULReduceMasked(double[] a, int idx, boolean[] mask) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2540,8 +2579,9 @@ static void MULReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + double v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2577,8 +2617,9 @@ static void MINReduceDoubleMaxVectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2586,6 +2627,24 @@ static void MINReduceDoubleMaxVectorTests(IntFunction fa) { DoubleMaxVectorTests::MINReduce, DoubleMaxVectorTests::MINReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MIN_IDENTITY; + + Assert.assertEquals((double) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static double MINReduceMasked(double[] a, int idx, boolean[] mask) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2617,8 +2676,9 @@ static void MINReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (double) Math.min(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (double) Math.min(ra, v); } } @@ -2654,8 +2714,9 @@ static void MAXReduceDoubleMaxVectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2663,6 +2724,24 @@ static void MAXReduceDoubleMaxVectorTests(IntFunction fa) { DoubleMaxVectorTests::MAXReduce, DoubleMaxVectorTests::MAXReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = MAX_IDENTITY; + + Assert.assertEquals((double) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals((double) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((double) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2694,8 +2773,9 @@ static void MAXReduceDoubleMaxVectorTestsMasked(IntFunction fa, IntFun ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (double) Math.max(ra, r[i]); + double v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (double) Math.max(ra, v); } } @@ -2731,8 +2811,9 @@ static void FIRST_NONZEROReduceDoubleMaxVectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2740,6 +2821,24 @@ static void FIRST_NONZEROReduceDoubleMaxVectorTests(IntFunction fa) { DoubleMaxVectorTests::FIRST_NONZEROReduce, DoubleMaxVectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "doubleUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + double[] a = fa.apply(SPECIES.length()); + double id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + double x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { double res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2771,8 +2870,9 @@ static void FIRST_NONZEROReduceDoubleMaxVectorTestsMasked(IntFunction ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + double v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4954,57 +5054,6 @@ static void maskFromToLongDoubleMaxVectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "doubleUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - double x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((double)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Double.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Double.POSITIVE_INFINITY, x) == x - Assert.assertEquals((double) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((double)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "doubleUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - double[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { double[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Float128VectorTests.java b/test/jdk/jdk/incubator/vector/Float128VectorTests.java index 06280df401291..6e111a6b8d137 100644 --- a/test/jdk/jdk/incubator/vector/Float128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float128VectorTests.java @@ -62,14 +62,13 @@ public class Float128VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - - // Identity values for reduction operations private static final float ADD_IDENTITY = (float)0; private static final float FIRST_NONZERO_IDENTITY = (float)0; private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; private static final float MUL_IDENTITY = (float)1; + // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2429,8 +2428,9 @@ static void ADDReduceFloat128VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2438,6 +2438,24 @@ static void ADDReduceFloat128VectorTests(IntFunction fa) { Float128VectorTests::ADDReduce, Float128VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "floatUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = ADD_IDENTITY; + + Assert.assertEquals((float) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2469,8 +2487,9 @@ static void ADDReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2506,8 +2525,9 @@ static void MULReduceFloat128VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2515,6 +2535,24 @@ static void MULReduceFloat128VectorTests(IntFunction fa) { Float128VectorTests::MULReduce, Float128VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MUL_IDENTITY; + + Assert.assertEquals((float) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static float MULReduceMasked(float[] a, int idx, boolean[] mask) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2546,8 +2584,9 @@ static void MULReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2583,8 +2622,9 @@ static void MINReduceFloat128VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2592,6 +2632,24 @@ static void MINReduceFloat128VectorTests(IntFunction fa) { Float128VectorTests::MINReduce, Float128VectorTests::MINReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MIN_IDENTITY; + + Assert.assertEquals((float) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static float MINReduceMasked(float[] a, int idx, boolean[] mask) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2623,8 +2681,9 @@ static void MINReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2660,8 +2719,9 @@ static void MAXReduceFloat128VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2669,6 +2729,24 @@ static void MAXReduceFloat128VectorTests(IntFunction fa) { Float128VectorTests::MAXReduce, Float128VectorTests::MAXReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MAX_IDENTITY; + + Assert.assertEquals((float) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2700,8 +2778,9 @@ static void MAXReduceFloat128VectorTestsMasked(IntFunction fa, IntFunct ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2737,8 +2816,9 @@ static void FIRST_NONZEROReduceFloat128VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2746,6 +2826,24 @@ static void FIRST_NONZEROReduceFloat128VectorTests(IntFunction fa) { Float128VectorTests::FIRST_NONZEROReduce, Float128VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2777,8 +2875,9 @@ static void FIRST_NONZEROReduceFloat128VectorTestsMasked(IntFunction fa ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4918,57 +5017,6 @@ static void maskFromToLongFloat128VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "floatUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - float x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((float)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Float.POSITIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((float)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "floatUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloat128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Float256VectorTests.java b/test/jdk/jdk/incubator/vector/Float256VectorTests.java index b6271acb13cf7..d6af436619d2b 100644 --- a/test/jdk/jdk/incubator/vector/Float256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float256VectorTests.java @@ -62,14 +62,13 @@ public class Float256VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - - // Identity values for reduction operations private static final float ADD_IDENTITY = (float)0; private static final float FIRST_NONZERO_IDENTITY = (float)0; private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; private static final float MUL_IDENTITY = (float)1; + // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2429,8 +2428,9 @@ static void ADDReduceFloat256VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2438,6 +2438,24 @@ static void ADDReduceFloat256VectorTests(IntFunction fa) { Float256VectorTests::ADDReduce, Float256VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "floatUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = ADD_IDENTITY; + + Assert.assertEquals((float) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2469,8 +2487,9 @@ static void ADDReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2506,8 +2525,9 @@ static void MULReduceFloat256VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2515,6 +2535,24 @@ static void MULReduceFloat256VectorTests(IntFunction fa) { Float256VectorTests::MULReduce, Float256VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MUL_IDENTITY; + + Assert.assertEquals((float) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static float MULReduceMasked(float[] a, int idx, boolean[] mask) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2546,8 +2584,9 @@ static void MULReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2583,8 +2622,9 @@ static void MINReduceFloat256VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2592,6 +2632,24 @@ static void MINReduceFloat256VectorTests(IntFunction fa) { Float256VectorTests::MINReduce, Float256VectorTests::MINReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MIN_IDENTITY; + + Assert.assertEquals((float) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static float MINReduceMasked(float[] a, int idx, boolean[] mask) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2623,8 +2681,9 @@ static void MINReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2660,8 +2719,9 @@ static void MAXReduceFloat256VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2669,6 +2729,24 @@ static void MAXReduceFloat256VectorTests(IntFunction fa) { Float256VectorTests::MAXReduce, Float256VectorTests::MAXReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MAX_IDENTITY; + + Assert.assertEquals((float) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2700,8 +2778,9 @@ static void MAXReduceFloat256VectorTestsMasked(IntFunction fa, IntFunct ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2737,8 +2816,9 @@ static void FIRST_NONZEROReduceFloat256VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2746,6 +2826,24 @@ static void FIRST_NONZEROReduceFloat256VectorTests(IntFunction fa) { Float256VectorTests::FIRST_NONZEROReduce, Float256VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2777,8 +2875,9 @@ static void FIRST_NONZEROReduceFloat256VectorTestsMasked(IntFunction fa ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4918,57 +5017,6 @@ static void maskFromToLongFloat256VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "floatUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - float x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((float)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Float.POSITIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((float)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "floatUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloat256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Float512VectorTests.java b/test/jdk/jdk/incubator/vector/Float512VectorTests.java index 9e47121559718..6c9978ffc8e6b 100644 --- a/test/jdk/jdk/incubator/vector/Float512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float512VectorTests.java @@ -62,14 +62,13 @@ public class Float512VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - - // Identity values for reduction operations private static final float ADD_IDENTITY = (float)0; private static final float FIRST_NONZERO_IDENTITY = (float)0; private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; private static final float MUL_IDENTITY = (float)1; + // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2429,8 +2428,9 @@ static void ADDReduceFloat512VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2438,6 +2438,24 @@ static void ADDReduceFloat512VectorTests(IntFunction fa) { Float512VectorTests::ADDReduce, Float512VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "floatUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = ADD_IDENTITY; + + Assert.assertEquals((float) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2469,8 +2487,9 @@ static void ADDReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2506,8 +2525,9 @@ static void MULReduceFloat512VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2515,6 +2535,24 @@ static void MULReduceFloat512VectorTests(IntFunction fa) { Float512VectorTests::MULReduce, Float512VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MUL_IDENTITY; + + Assert.assertEquals((float) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static float MULReduceMasked(float[] a, int idx, boolean[] mask) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2546,8 +2584,9 @@ static void MULReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2583,8 +2622,9 @@ static void MINReduceFloat512VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2592,6 +2632,24 @@ static void MINReduceFloat512VectorTests(IntFunction fa) { Float512VectorTests::MINReduce, Float512VectorTests::MINReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MIN_IDENTITY; + + Assert.assertEquals((float) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static float MINReduceMasked(float[] a, int idx, boolean[] mask) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2623,8 +2681,9 @@ static void MINReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2660,8 +2719,9 @@ static void MAXReduceFloat512VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2669,6 +2729,24 @@ static void MAXReduceFloat512VectorTests(IntFunction fa) { Float512VectorTests::MAXReduce, Float512VectorTests::MAXReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MAX_IDENTITY; + + Assert.assertEquals((float) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2700,8 +2778,9 @@ static void MAXReduceFloat512VectorTestsMasked(IntFunction fa, IntFunct ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2737,8 +2816,9 @@ static void FIRST_NONZEROReduceFloat512VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2746,6 +2826,24 @@ static void FIRST_NONZEROReduceFloat512VectorTests(IntFunction fa) { Float512VectorTests::FIRST_NONZEROReduce, Float512VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2777,8 +2875,9 @@ static void FIRST_NONZEROReduceFloat512VectorTestsMasked(IntFunction fa ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4918,57 +5017,6 @@ static void maskFromToLongFloat512VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "floatUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - float x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((float)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Float.POSITIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((float)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "floatUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloat512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Float64VectorTests.java b/test/jdk/jdk/incubator/vector/Float64VectorTests.java index ae0797a2f9f6f..22958bcb7be1a 100644 --- a/test/jdk/jdk/incubator/vector/Float64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float64VectorTests.java @@ -62,14 +62,13 @@ public class Float64VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - - // Identity values for reduction operations private static final float ADD_IDENTITY = (float)0; private static final float FIRST_NONZERO_IDENTITY = (float)0; private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; private static final float MUL_IDENTITY = (float)1; + // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2429,8 +2428,9 @@ static void ADDReduceFloat64VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2438,6 +2438,24 @@ static void ADDReduceFloat64VectorTests(IntFunction fa) { Float64VectorTests::ADDReduce, Float64VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "floatUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = ADD_IDENTITY; + + Assert.assertEquals((float) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2469,8 +2487,9 @@ static void ADDReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2506,8 +2525,9 @@ static void MULReduceFloat64VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2515,6 +2535,24 @@ static void MULReduceFloat64VectorTests(IntFunction fa) { Float64VectorTests::MULReduce, Float64VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MUL_IDENTITY; + + Assert.assertEquals((float) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static float MULReduceMasked(float[] a, int idx, boolean[] mask) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2546,8 +2584,9 @@ static void MULReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2583,8 +2622,9 @@ static void MINReduceFloat64VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2592,6 +2632,24 @@ static void MINReduceFloat64VectorTests(IntFunction fa) { Float64VectorTests::MINReduce, Float64VectorTests::MINReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MIN_IDENTITY; + + Assert.assertEquals((float) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static float MINReduceMasked(float[] a, int idx, boolean[] mask) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2623,8 +2681,9 @@ static void MINReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2660,8 +2719,9 @@ static void MAXReduceFloat64VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2669,6 +2729,24 @@ static void MAXReduceFloat64VectorTests(IntFunction fa) { Float64VectorTests::MAXReduce, Float64VectorTests::MAXReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MAX_IDENTITY; + + Assert.assertEquals((float) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2700,8 +2778,9 @@ static void MAXReduceFloat64VectorTestsMasked(IntFunction fa, IntFuncti ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2737,8 +2816,9 @@ static void FIRST_NONZEROReduceFloat64VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2746,6 +2826,24 @@ static void FIRST_NONZEROReduceFloat64VectorTests(IntFunction fa) { Float64VectorTests::FIRST_NONZEROReduce, Float64VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2777,8 +2875,9 @@ static void FIRST_NONZEROReduceFloat64VectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4918,57 +5017,6 @@ static void maskFromToLongFloat64VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "floatUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - float x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((float)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Float.POSITIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((float)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "floatUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloat64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java index 8164c3ae88045..26d54e7e4df19 100644 --- a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java @@ -68,13 +68,13 @@ static VectorShape getMaxBit() { private static final int Max = 256; // juts so we can do N/Max - // Identity values for reduction operations private static final float ADD_IDENTITY = (float)0; private static final float FIRST_NONZERO_IDENTITY = (float)0; private static final float MAX_IDENTITY = Float.NEGATIVE_INFINITY; private static final float MIN_IDENTITY = Float.POSITIVE_INFINITY; private static final float MUL_IDENTITY = (float)1; + // for floating point addition reduction ops that may introduce rounding errors private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0; @@ -2434,8 +2434,9 @@ static void ADDReduceFloatMaxVectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -2443,6 +2444,24 @@ static void ADDReduceFloatMaxVectorTests(IntFunction fa) { FloatMaxVectorTests::ADDReduce, FloatMaxVectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_ADD); } + @Test(dataProvider = "floatUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = ADD_IDENTITY; + + Assert.assertEquals((float) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2474,8 +2493,9 @@ static void ADDReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + float v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -2511,8 +2531,9 @@ static void MULReduceFloatMaxVectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -2520,6 +2541,24 @@ static void MULReduceFloatMaxVectorTests(IntFunction fa) { FloatMaxVectorTests::MULReduce, FloatMaxVectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR_FACTOR_MUL); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MUL_IDENTITY; + + Assert.assertEquals((float) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static float MULReduceMasked(float[] a, int idx, boolean[] mask) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2551,8 +2590,9 @@ static void MULReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + float v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -2588,8 +2628,9 @@ static void MINReduceFloatMaxVectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2597,6 +2638,24 @@ static void MINReduceFloatMaxVectorTests(IntFunction fa) { FloatMaxVectorTests::MINReduce, FloatMaxVectorTests::MINReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MIN_IDENTITY; + + Assert.assertEquals((float) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static float MINReduceMasked(float[] a, int idx, boolean[] mask) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2628,8 +2687,9 @@ static void MINReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (float) Math.min(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (float) Math.min(ra, v); } } @@ -2665,8 +2725,9 @@ static void MAXReduceFloatMaxVectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2674,6 +2735,24 @@ static void MAXReduceFloatMaxVectorTests(IntFunction fa) { FloatMaxVectorTests::MAXReduce, FloatMaxVectorTests::MAXReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = MAX_IDENTITY; + + Assert.assertEquals((float) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals((float) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((float) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2705,8 +2784,9 @@ static void MAXReduceFloatMaxVectorTestsMasked(IntFunction fa, IntFunct ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (float) Math.max(ra, r[i]); + float v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (float) Math.max(ra, v); } } @@ -2742,8 +2822,9 @@ static void FIRST_NONZEROReduceFloatMaxVectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -2751,6 +2832,24 @@ static void FIRST_NONZEROReduceFloatMaxVectorTests(IntFunction fa) { FloatMaxVectorTests::FIRST_NONZEROReduce, FloatMaxVectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "floatUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + float[] a = fa.apply(SPECIES.length()); + float id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + float x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static float FIRST_NONZEROReduceMasked(float[] a, int idx, boolean[] mask) { float res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -2782,8 +2881,9 @@ static void FIRST_NONZEROReduceFloatMaxVectorTestsMasked(IntFunction fa ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { FloatVector av = FloatVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + float v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4923,57 +5023,6 @@ static void maskFromToLongFloatMaxVectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "floatUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - float x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((float)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Float.NEGATIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Float.POSITIVE_INFINITY, x) == x - Assert.assertEquals((float) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((float)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "floatUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - float[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - } - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloatMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { float[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int128VectorTests.java b/test/jdk/jdk/incubator/vector/Int128VectorTests.java index 26b90e80c82b7..e4b437fff35ad 100644 --- a/test/jdk/jdk/incubator/vector/Int128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int128VectorTests.java @@ -63,7 +63,6 @@ public class Int128VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final int CONST_SHIFT = Integer.SIZE / 2; // Identity values for reduction operations @@ -3695,8 +3694,9 @@ static void ANDReduceInt128VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3704,6 +3704,24 @@ static void ANDReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::ANDReduce, Int128VectorTests::ANDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = AND_IDENTITY; + + Assert.assertEquals((int) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3735,8 +3753,9 @@ static void ANDReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3772,8 +3791,9 @@ static void ORReduceInt128VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + int v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3781,6 +3801,24 @@ static void ORReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::ORReduce, Int128VectorTests::ORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = OR_IDENTITY; + + Assert.assertEquals((int) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static int ORReduceMasked(int[] a, int idx, boolean[] mask) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3812,8 +3850,9 @@ static void ORReduceInt128VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3858,6 +3898,24 @@ static void XORReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::XORReduce, Int128VectorTests::XORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = XOR_IDENTITY; + + Assert.assertEquals((int) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static int XORReduceMasked(int[] a, int idx, boolean[] mask) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3889,8 +3947,9 @@ static void XORReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3926,8 +3985,9 @@ static void ADDReduceInt128VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3935,6 +3995,24 @@ static void ADDReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::ADDReduce, Int128VectorTests::ADDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = ADD_IDENTITY; + + Assert.assertEquals((int) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3966,8 +4044,9 @@ static void ADDReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4003,8 +4082,9 @@ static void MULReduceInt128VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4012,6 +4092,24 @@ static void MULReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::MULReduce, Int128VectorTests::MULReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MUL_IDENTITY; + + Assert.assertEquals((int) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static int MULReduceMasked(int[] a, int idx, boolean[] mask) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4043,8 +4141,9 @@ static void MULReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4080,8 +4179,9 @@ static void MINReduceInt128VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4089,6 +4189,24 @@ static void MINReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::MINReduce, Int128VectorTests::MINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MIN_IDENTITY; + + Assert.assertEquals((int) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static int MINReduceMasked(int[] a, int idx, boolean[] mask) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4120,8 +4238,9 @@ static void MINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4157,8 +4276,9 @@ static void MAXReduceInt128VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4166,6 +4286,24 @@ static void MAXReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::MAXReduce, Int128VectorTests::MAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MAX_IDENTITY; + + Assert.assertEquals((int) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4197,8 +4335,9 @@ static void MAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction< ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4234,8 +4373,9 @@ static void UMINReduceInt128VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4243,6 +4383,24 @@ static void UMINReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::UMINReduce, Int128VectorTests::UMINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMIN_IDENTITY; + + Assert.assertEquals((int) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4274,8 +4432,9 @@ static void UMINReduceInt128VectorTestsMasked(IntFunction fa, IntFunction ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4311,8 +4470,9 @@ static void UMAXReduceInt128VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4320,6 +4480,24 @@ static void UMAXReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::UMAXReduce, Int128VectorTests::UMAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMAX_IDENTITY; + + Assert.assertEquals((int) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4351,8 +4529,9 @@ static void UMAXReduceInt128VectorTestsMasked(IntFunction fa, IntFunction ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4388,8 +4567,9 @@ static void FIRST_NONZEROReduceInt128VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4397,6 +4577,24 @@ static void FIRST_NONZEROReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::FIRST_NONZEROReduce, Int128VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4428,8 +4626,9 @@ static void FIRST_NONZEROReduceInt128VectorTestsMasked(IntFunction fa, In ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4513,8 +4712,9 @@ static void SUADDReduceInt128VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4522,6 +4722,24 @@ static void SUADDReduceInt128VectorTests(IntFunction fa) { Int128VectorTests::SUADDReduce, Int128VectorTests::SUADDReduceAll); } + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = SUADD_IDENTITY; + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4552,8 +4770,9 @@ static void SUADDReduceInt128VectorTestsMasked(IntFunction fa, IntFunctio ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6511,93 +6730,6 @@ static void maskFromToLongInt128VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "intUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - int x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((int)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((int)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Integer.MIN_VALUE, x) == x - Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Integer.MAX_VALUE, x) == x - Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((int)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((int)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "intUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "intCompareOpProvider") static void ltInt128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int256VectorTests.java b/test/jdk/jdk/incubator/vector/Int256VectorTests.java index c0719a0d5a60b..fa2368f584d12 100644 --- a/test/jdk/jdk/incubator/vector/Int256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int256VectorTests.java @@ -63,7 +63,6 @@ public class Int256VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final int CONST_SHIFT = Integer.SIZE / 2; // Identity values for reduction operations @@ -3695,8 +3694,9 @@ static void ANDReduceInt256VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3704,6 +3704,24 @@ static void ANDReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::ANDReduce, Int256VectorTests::ANDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = AND_IDENTITY; + + Assert.assertEquals((int) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3735,8 +3753,9 @@ static void ANDReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3772,8 +3791,9 @@ static void ORReduceInt256VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + int v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3781,6 +3801,24 @@ static void ORReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::ORReduce, Int256VectorTests::ORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = OR_IDENTITY; + + Assert.assertEquals((int) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static int ORReduceMasked(int[] a, int idx, boolean[] mask) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3812,8 +3850,9 @@ static void ORReduceInt256VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3858,6 +3898,24 @@ static void XORReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::XORReduce, Int256VectorTests::XORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = XOR_IDENTITY; + + Assert.assertEquals((int) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static int XORReduceMasked(int[] a, int idx, boolean[] mask) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3889,8 +3947,9 @@ static void XORReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3926,8 +3985,9 @@ static void ADDReduceInt256VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3935,6 +3995,24 @@ static void ADDReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::ADDReduce, Int256VectorTests::ADDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = ADD_IDENTITY; + + Assert.assertEquals((int) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3966,8 +4044,9 @@ static void ADDReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4003,8 +4082,9 @@ static void MULReduceInt256VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4012,6 +4092,24 @@ static void MULReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::MULReduce, Int256VectorTests::MULReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MUL_IDENTITY; + + Assert.assertEquals((int) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static int MULReduceMasked(int[] a, int idx, boolean[] mask) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4043,8 +4141,9 @@ static void MULReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4080,8 +4179,9 @@ static void MINReduceInt256VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4089,6 +4189,24 @@ static void MINReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::MINReduce, Int256VectorTests::MINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MIN_IDENTITY; + + Assert.assertEquals((int) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static int MINReduceMasked(int[] a, int idx, boolean[] mask) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4120,8 +4238,9 @@ static void MINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4157,8 +4276,9 @@ static void MAXReduceInt256VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4166,6 +4286,24 @@ static void MAXReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::MAXReduce, Int256VectorTests::MAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MAX_IDENTITY; + + Assert.assertEquals((int) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4197,8 +4335,9 @@ static void MAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction< ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4234,8 +4373,9 @@ static void UMINReduceInt256VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4243,6 +4383,24 @@ static void UMINReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::UMINReduce, Int256VectorTests::UMINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMIN_IDENTITY; + + Assert.assertEquals((int) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4274,8 +4432,9 @@ static void UMINReduceInt256VectorTestsMasked(IntFunction fa, IntFunction ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4311,8 +4470,9 @@ static void UMAXReduceInt256VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4320,6 +4480,24 @@ static void UMAXReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::UMAXReduce, Int256VectorTests::UMAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMAX_IDENTITY; + + Assert.assertEquals((int) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4351,8 +4529,9 @@ static void UMAXReduceInt256VectorTestsMasked(IntFunction fa, IntFunction ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4388,8 +4567,9 @@ static void FIRST_NONZEROReduceInt256VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4397,6 +4577,24 @@ static void FIRST_NONZEROReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::FIRST_NONZEROReduce, Int256VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4428,8 +4626,9 @@ static void FIRST_NONZEROReduceInt256VectorTestsMasked(IntFunction fa, In ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4513,8 +4712,9 @@ static void SUADDReduceInt256VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4522,6 +4722,24 @@ static void SUADDReduceInt256VectorTests(IntFunction fa) { Int256VectorTests::SUADDReduce, Int256VectorTests::SUADDReduceAll); } + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = SUADD_IDENTITY; + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4552,8 +4770,9 @@ static void SUADDReduceInt256VectorTestsMasked(IntFunction fa, IntFunctio ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6511,93 +6730,6 @@ static void maskFromToLongInt256VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "intUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - int x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((int)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((int)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Integer.MIN_VALUE, x) == x - Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Integer.MAX_VALUE, x) == x - Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((int)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((int)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "intUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "intCompareOpProvider") static void ltInt256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int512VectorTests.java b/test/jdk/jdk/incubator/vector/Int512VectorTests.java index 7c89ee6ae1863..6f0c3118ff963 100644 --- a/test/jdk/jdk/incubator/vector/Int512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int512VectorTests.java @@ -63,7 +63,6 @@ public class Int512VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final int CONST_SHIFT = Integer.SIZE / 2; // Identity values for reduction operations @@ -3695,8 +3694,9 @@ static void ANDReduceInt512VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3704,6 +3704,24 @@ static void ANDReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::ANDReduce, Int512VectorTests::ANDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = AND_IDENTITY; + + Assert.assertEquals((int) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3735,8 +3753,9 @@ static void ANDReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3772,8 +3791,9 @@ static void ORReduceInt512VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + int v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3781,6 +3801,24 @@ static void ORReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::ORReduce, Int512VectorTests::ORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = OR_IDENTITY; + + Assert.assertEquals((int) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static int ORReduceMasked(int[] a, int idx, boolean[] mask) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3812,8 +3850,9 @@ static void ORReduceInt512VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3858,6 +3898,24 @@ static void XORReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::XORReduce, Int512VectorTests::XORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = XOR_IDENTITY; + + Assert.assertEquals((int) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static int XORReduceMasked(int[] a, int idx, boolean[] mask) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3889,8 +3947,9 @@ static void XORReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3926,8 +3985,9 @@ static void ADDReduceInt512VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3935,6 +3995,24 @@ static void ADDReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::ADDReduce, Int512VectorTests::ADDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = ADD_IDENTITY; + + Assert.assertEquals((int) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3966,8 +4044,9 @@ static void ADDReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4003,8 +4082,9 @@ static void MULReduceInt512VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4012,6 +4092,24 @@ static void MULReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::MULReduce, Int512VectorTests::MULReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MUL_IDENTITY; + + Assert.assertEquals((int) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static int MULReduceMasked(int[] a, int idx, boolean[] mask) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4043,8 +4141,9 @@ static void MULReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4080,8 +4179,9 @@ static void MINReduceInt512VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4089,6 +4189,24 @@ static void MINReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::MINReduce, Int512VectorTests::MINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MIN_IDENTITY; + + Assert.assertEquals((int) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static int MINReduceMasked(int[] a, int idx, boolean[] mask) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4120,8 +4238,9 @@ static void MINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4157,8 +4276,9 @@ static void MAXReduceInt512VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4166,6 +4286,24 @@ static void MAXReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::MAXReduce, Int512VectorTests::MAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MAX_IDENTITY; + + Assert.assertEquals((int) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4197,8 +4335,9 @@ static void MAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction< ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4234,8 +4373,9 @@ static void UMINReduceInt512VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4243,6 +4383,24 @@ static void UMINReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::UMINReduce, Int512VectorTests::UMINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMIN_IDENTITY; + + Assert.assertEquals((int) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4274,8 +4432,9 @@ static void UMINReduceInt512VectorTestsMasked(IntFunction fa, IntFunction ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4311,8 +4470,9 @@ static void UMAXReduceInt512VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4320,6 +4480,24 @@ static void UMAXReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::UMAXReduce, Int512VectorTests::UMAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMAX_IDENTITY; + + Assert.assertEquals((int) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4351,8 +4529,9 @@ static void UMAXReduceInt512VectorTestsMasked(IntFunction fa, IntFunction ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4388,8 +4567,9 @@ static void FIRST_NONZEROReduceInt512VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4397,6 +4577,24 @@ static void FIRST_NONZEROReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::FIRST_NONZEROReduce, Int512VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4428,8 +4626,9 @@ static void FIRST_NONZEROReduceInt512VectorTestsMasked(IntFunction fa, In ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4513,8 +4712,9 @@ static void SUADDReduceInt512VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4522,6 +4722,24 @@ static void SUADDReduceInt512VectorTests(IntFunction fa) { Int512VectorTests::SUADDReduce, Int512VectorTests::SUADDReduceAll); } + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = SUADD_IDENTITY; + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4552,8 +4770,9 @@ static void SUADDReduceInt512VectorTestsMasked(IntFunction fa, IntFunctio ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6511,93 +6730,6 @@ static void maskFromToLongInt512VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "intUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - int x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((int)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((int)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Integer.MIN_VALUE, x) == x - Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Integer.MAX_VALUE, x) == x - Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((int)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((int)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "intUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "intCompareOpProvider") static void ltInt512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Int64VectorTests.java b/test/jdk/jdk/incubator/vector/Int64VectorTests.java index 9666f66af306e..fb7b55b9cb9cf 100644 --- a/test/jdk/jdk/incubator/vector/Int64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int64VectorTests.java @@ -63,7 +63,6 @@ public class Int64VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final int CONST_SHIFT = Integer.SIZE / 2; // Identity values for reduction operations @@ -3695,8 +3694,9 @@ static void ANDReduceInt64VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3704,6 +3704,24 @@ static void ANDReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::ANDReduce, Int64VectorTests::ANDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = AND_IDENTITY; + + Assert.assertEquals((int) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3735,8 +3753,9 @@ static void ANDReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + int v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3781,6 +3801,24 @@ static void ORReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::ORReduce, Int64VectorTests::ORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = OR_IDENTITY; + + Assert.assertEquals((int) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static int ORReduceMasked(int[] a, int idx, boolean[] mask) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3812,8 +3850,9 @@ static void ORReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3858,6 +3898,24 @@ static void XORReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::XORReduce, Int64VectorTests::XORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = XOR_IDENTITY; + + Assert.assertEquals((int) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static int XORReduceMasked(int[] a, int idx, boolean[] mask) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3889,8 +3947,9 @@ static void XORReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3935,6 +3995,24 @@ static void ADDReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::ADDReduce, Int64VectorTests::ADDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = ADD_IDENTITY; + + Assert.assertEquals((int) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3966,8 +4044,9 @@ static void ADDReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4012,6 +4092,24 @@ static void MULReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::MULReduce, Int64VectorTests::MULReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MUL_IDENTITY; + + Assert.assertEquals((int) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static int MULReduceMasked(int[] a, int idx, boolean[] mask) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4043,8 +4141,9 @@ static void MULReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4089,6 +4189,24 @@ static void MINReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::MINReduce, Int64VectorTests::MINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MIN_IDENTITY; + + Assert.assertEquals((int) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static int MINReduceMasked(int[] a, int idx, boolean[] mask) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4120,8 +4238,9 @@ static void MINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4166,6 +4286,24 @@ static void MAXReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::MAXReduce, Int64VectorTests::MAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MAX_IDENTITY; + + Assert.assertEquals((int) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4197,8 +4335,9 @@ static void MAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4243,6 +4383,24 @@ static void UMINReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::UMINReduce, Int64VectorTests::UMINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMIN_IDENTITY; + + Assert.assertEquals((int) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4274,8 +4432,9 @@ static void UMINReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4311,8 +4470,9 @@ static void UMAXReduceInt64VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4320,6 +4480,24 @@ static void UMAXReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::UMAXReduce, Int64VectorTests::UMAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMAX_IDENTITY; + + Assert.assertEquals((int) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4351,8 +4529,9 @@ static void UMAXReduceInt64VectorTestsMasked(IntFunction fa, IntFunction< ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4388,8 +4567,9 @@ static void FIRST_NONZEROReduceInt64VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4397,6 +4577,24 @@ static void FIRST_NONZEROReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::FIRST_NONZEROReduce, Int64VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4428,8 +4626,9 @@ static void FIRST_NONZEROReduceInt64VectorTestsMasked(IntFunction fa, Int ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4513,8 +4712,9 @@ static void SUADDReduceInt64VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4522,6 +4722,24 @@ static void SUADDReduceInt64VectorTests(IntFunction fa) { Int64VectorTests::SUADDReduce, Int64VectorTests::SUADDReduceAll); } + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = SUADD_IDENTITY; + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4552,8 +4770,9 @@ static void SUADDReduceInt64VectorTestsMasked(IntFunction fa, IntFunction ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6511,93 +6730,6 @@ static void maskFromToLongInt64VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "intUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - int x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((int)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((int)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Integer.MIN_VALUE, x) == x - Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Integer.MAX_VALUE, x) == x - Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((int)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((int)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "intUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "intCompareOpProvider") static void ltInt64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java index a91debd9c2e7b..050c2baa7ded0 100644 --- a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java @@ -3700,8 +3700,9 @@ static void ANDReduceIntMaxVectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3709,6 +3710,24 @@ static void ANDReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::ANDReduce, IntMaxVectorTests::ANDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = AND_IDENTITY; + + Assert.assertEquals((int) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static int ANDReduceMasked(int[] a, int idx, boolean[] mask) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3740,8 +3759,9 @@ static void ANDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + int v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3777,8 +3797,9 @@ static void ORReduceIntMaxVectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + int v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3786,6 +3807,24 @@ static void ORReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::ORReduce, IntMaxVectorTests::ORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = OR_IDENTITY; + + Assert.assertEquals((int) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static int ORReduceMasked(int[] a, int idx, boolean[] mask) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3817,8 +3856,9 @@ static void ORReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3863,6 +3904,24 @@ static void XORReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::XORReduce, IntMaxVectorTests::XORReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = XOR_IDENTITY; + + Assert.assertEquals((int) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static int XORReduceMasked(int[] a, int idx, boolean[] mask) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3894,8 +3953,9 @@ static void XORReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + int v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3931,8 +3991,9 @@ static void ADDReduceIntMaxVectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3940,6 +4001,24 @@ static void ADDReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::ADDReduce, IntMaxVectorTests::ADDReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = ADD_IDENTITY; + + Assert.assertEquals((int) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static int ADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3971,8 +4050,9 @@ static void ADDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + int v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4008,8 +4088,9 @@ static void MULReduceIntMaxVectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4017,6 +4098,24 @@ static void MULReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::MULReduce, IntMaxVectorTests::MULReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MUL_IDENTITY; + + Assert.assertEquals((int) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static int MULReduceMasked(int[] a, int idx, boolean[] mask) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4048,8 +4147,9 @@ static void MULReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + int v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4085,8 +4185,9 @@ static void MINReduceIntMaxVectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4094,6 +4195,24 @@ static void MINReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::MINReduce, IntMaxVectorTests::MINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MIN_IDENTITY; + + Assert.assertEquals((int) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static int MINReduceMasked(int[] a, int idx, boolean[] mask) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4125,8 +4244,9 @@ static void MINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (int) Math.min(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (int) Math.min(ra, v); } } @@ -4162,8 +4282,9 @@ static void MAXReduceIntMaxVectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4171,6 +4292,24 @@ static void MAXReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::MAXReduce, IntMaxVectorTests::MAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = MAX_IDENTITY; + + Assert.assertEquals((int) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static int MAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4202,8 +4341,9 @@ static void MAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction< ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (int) Math.max(ra, r[i]); + int v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (int) Math.max(ra, v); } } @@ -4239,8 +4379,9 @@ static void UMINReduceIntMaxVectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4248,6 +4389,24 @@ static void UMINReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::UMINReduce, IntMaxVectorTests::UMINReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMIN_IDENTITY; + + Assert.assertEquals((int) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static int UMINReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4279,8 +4438,9 @@ static void UMINReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (int) VectorMath.minUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (int) VectorMath.minUnsigned(ra, v); } } @@ -4316,8 +4476,9 @@ static void UMAXReduceIntMaxVectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4325,6 +4486,24 @@ static void UMAXReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::UMAXReduce, IntMaxVectorTests::UMAXReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = UMAX_IDENTITY; + + Assert.assertEquals((int) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static int UMAXReduceMasked(int[] a, int idx, boolean[] mask) { int res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4356,8 +4535,9 @@ static void UMAXReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunction ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (int) VectorMath.maxUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (int) VectorMath.maxUnsigned(ra, v); } } @@ -4393,8 +4573,9 @@ static void FIRST_NONZEROReduceIntMaxVectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4402,6 +4583,24 @@ static void FIRST_NONZEROReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::FIRST_NONZEROReduce, IntMaxVectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "intUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) { int res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4433,8 +4632,9 @@ static void FIRST_NONZEROReduceIntMaxVectorTestsMasked(IntFunction fa, In ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + int v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4518,8 +4718,9 @@ static void SUADDReduceIntMaxVectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4527,6 +4728,24 @@ static void SUADDReduceIntMaxVectorTests(IntFunction fa) { IntMaxVectorTests::SUADDReduce, IntMaxVectorTests::SUADDReduceAll); } + @Test(dataProvider = "intSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + int[] a = fa.apply(SPECIES.length()); + int id = SUADD_IDENTITY; + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + int x = a[i]; + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static int SUADDReduceMasked(int[] a, int idx, boolean[] mask) { int res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4557,8 +4776,9 @@ static void SUADDReduceIntMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { IntVector av = IntVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (int) VectorMath.addSaturatingUnsigned(ra, r[i]); + int v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (int) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6516,93 +6736,6 @@ static void maskFromToLongIntMaxVectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "intUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - int x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((int)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((int)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Integer.MIN_VALUE, x) == x - Assert.assertEquals((int) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Integer.MAX_VALUE, x) == x - Assert.assertEquals((int) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((int)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((int)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((int) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((int) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((int)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "intUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - int[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - IntVector av = IntVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "intCompareOpProvider") static void ltIntMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { int[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long128VectorTests.java b/test/jdk/jdk/incubator/vector/Long128VectorTests.java index e7ef3f75eb5e4..c2553088bab2e 100644 --- a/test/jdk/jdk/incubator/vector/Long128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long128VectorTests.java @@ -63,7 +63,6 @@ public class Long128VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final long CONST_SHIFT = Long.SIZE / 2; // Identity values for reduction operations @@ -3717,8 +3716,9 @@ static void ANDReduceLong128VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3726,6 +3726,24 @@ static void ANDReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::ANDReduce, Long128VectorTests::ANDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = AND_IDENTITY; + + Assert.assertEquals((long) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3757,8 +3775,9 @@ static void ANDReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3794,8 +3813,9 @@ static void ORReduceLong128VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3803,6 +3823,24 @@ static void ORReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::ORReduce, Long128VectorTests::ORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = OR_IDENTITY; + + Assert.assertEquals((long) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static long ORReduceMasked(long[] a, int idx, boolean[] mask) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3834,8 +3872,9 @@ static void ORReduceLong128VectorTestsMasked(IntFunction fa, IntFunction ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3871,8 +3910,9 @@ static void XORReduceLong128VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3880,6 +3920,24 @@ static void XORReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::XORReduce, Long128VectorTests::XORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = XOR_IDENTITY; + + Assert.assertEquals((long) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static long XORReduceMasked(long[] a, int idx, boolean[] mask) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3911,8 +3969,9 @@ static void XORReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3948,8 +4007,9 @@ static void ADDReduceLong128VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3957,6 +4017,24 @@ static void ADDReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::ADDReduce, Long128VectorTests::ADDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = ADD_IDENTITY; + + Assert.assertEquals((long) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3988,8 +4066,9 @@ static void ADDReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4025,8 +4104,9 @@ static void MULReduceLong128VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4034,6 +4114,24 @@ static void MULReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::MULReduce, Long128VectorTests::MULReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MUL_IDENTITY; + + Assert.assertEquals((long) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static long MULReduceMasked(long[] a, int idx, boolean[] mask) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4065,8 +4163,9 @@ static void MULReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4102,8 +4201,9 @@ static void MINReduceLong128VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4111,6 +4211,24 @@ static void MINReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::MINReduce, Long128VectorTests::MINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MIN_IDENTITY; + + Assert.assertEquals((long) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static long MINReduceMasked(long[] a, int idx, boolean[] mask) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4142,8 +4260,9 @@ static void MINReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4179,8 +4298,9 @@ static void MAXReduceLong128VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4188,6 +4308,24 @@ static void MAXReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::MAXReduce, Long128VectorTests::MAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MAX_IDENTITY; + + Assert.assertEquals((long) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4219,8 +4357,9 @@ static void MAXReduceLong128VectorTestsMasked(IntFunction fa, IntFunctio ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4256,8 +4395,9 @@ static void UMINReduceLong128VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4265,6 +4405,24 @@ static void UMINReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::UMINReduce, Long128VectorTests::UMINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMIN_IDENTITY; + + Assert.assertEquals((long) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4296,8 +4454,9 @@ static void UMINReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4333,8 +4492,9 @@ static void UMAXReduceLong128VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4342,6 +4502,24 @@ static void UMAXReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::UMAXReduce, Long128VectorTests::UMAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMAX_IDENTITY; + + Assert.assertEquals((long) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4373,8 +4551,9 @@ static void UMAXReduceLong128VectorTestsMasked(IntFunction fa, IntFuncti ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4410,8 +4589,9 @@ static void FIRST_NONZEROReduceLong128VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4419,6 +4599,24 @@ static void FIRST_NONZEROReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::FIRST_NONZEROReduce, Long128VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4450,8 +4648,9 @@ static void FIRST_NONZEROReduceLong128VectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4535,8 +4734,9 @@ static void SUADDReduceLong128VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4544,6 +4744,24 @@ static void SUADDReduceLong128VectorTests(IntFunction fa) { Long128VectorTests::SUADDReduce, Long128VectorTests::SUADDReduceAll); } + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = SUADD_IDENTITY; + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4574,8 +4792,9 @@ static void SUADDReduceLong128VectorTestsMasked(IntFunction fa, IntFunct ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6463,93 +6682,6 @@ static void maskFromToLongLong128VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "longUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - long x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((long)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((long)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Long.MIN_VALUE, x) == x - Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Long.MAX_VALUE, x) == x - Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((long)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((long)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "longUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "longCompareOpProvider") static void ltLong128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long256VectorTests.java b/test/jdk/jdk/incubator/vector/Long256VectorTests.java index bf8646d809e6c..dc9efae7e9919 100644 --- a/test/jdk/jdk/incubator/vector/Long256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long256VectorTests.java @@ -63,7 +63,6 @@ public class Long256VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final long CONST_SHIFT = Long.SIZE / 2; // Identity values for reduction operations @@ -3717,8 +3716,9 @@ static void ANDReduceLong256VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3726,6 +3726,24 @@ static void ANDReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::ANDReduce, Long256VectorTests::ANDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = AND_IDENTITY; + + Assert.assertEquals((long) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3757,8 +3775,9 @@ static void ANDReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3794,8 +3813,9 @@ static void ORReduceLong256VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3803,6 +3823,24 @@ static void ORReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::ORReduce, Long256VectorTests::ORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = OR_IDENTITY; + + Assert.assertEquals((long) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static long ORReduceMasked(long[] a, int idx, boolean[] mask) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3834,8 +3872,9 @@ static void ORReduceLong256VectorTestsMasked(IntFunction fa, IntFunction ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3871,8 +3910,9 @@ static void XORReduceLong256VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3880,6 +3920,24 @@ static void XORReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::XORReduce, Long256VectorTests::XORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = XOR_IDENTITY; + + Assert.assertEquals((long) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static long XORReduceMasked(long[] a, int idx, boolean[] mask) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3911,8 +3969,9 @@ static void XORReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3948,8 +4007,9 @@ static void ADDReduceLong256VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3957,6 +4017,24 @@ static void ADDReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::ADDReduce, Long256VectorTests::ADDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = ADD_IDENTITY; + + Assert.assertEquals((long) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3988,8 +4066,9 @@ static void ADDReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4025,8 +4104,9 @@ static void MULReduceLong256VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4034,6 +4114,24 @@ static void MULReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::MULReduce, Long256VectorTests::MULReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MUL_IDENTITY; + + Assert.assertEquals((long) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static long MULReduceMasked(long[] a, int idx, boolean[] mask) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4065,8 +4163,9 @@ static void MULReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4102,8 +4201,9 @@ static void MINReduceLong256VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4111,6 +4211,24 @@ static void MINReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::MINReduce, Long256VectorTests::MINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MIN_IDENTITY; + + Assert.assertEquals((long) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static long MINReduceMasked(long[] a, int idx, boolean[] mask) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4142,8 +4260,9 @@ static void MINReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4179,8 +4298,9 @@ static void MAXReduceLong256VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4188,6 +4308,24 @@ static void MAXReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::MAXReduce, Long256VectorTests::MAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MAX_IDENTITY; + + Assert.assertEquals((long) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4219,8 +4357,9 @@ static void MAXReduceLong256VectorTestsMasked(IntFunction fa, IntFunctio ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4256,8 +4395,9 @@ static void UMINReduceLong256VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4265,6 +4405,24 @@ static void UMINReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::UMINReduce, Long256VectorTests::UMINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMIN_IDENTITY; + + Assert.assertEquals((long) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4296,8 +4454,9 @@ static void UMINReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4333,8 +4492,9 @@ static void UMAXReduceLong256VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4342,6 +4502,24 @@ static void UMAXReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::UMAXReduce, Long256VectorTests::UMAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMAX_IDENTITY; + + Assert.assertEquals((long) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4373,8 +4551,9 @@ static void UMAXReduceLong256VectorTestsMasked(IntFunction fa, IntFuncti ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4410,8 +4589,9 @@ static void FIRST_NONZEROReduceLong256VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4419,6 +4599,24 @@ static void FIRST_NONZEROReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::FIRST_NONZEROReduce, Long256VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4450,8 +4648,9 @@ static void FIRST_NONZEROReduceLong256VectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4535,8 +4734,9 @@ static void SUADDReduceLong256VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4544,6 +4744,24 @@ static void SUADDReduceLong256VectorTests(IntFunction fa) { Long256VectorTests::SUADDReduce, Long256VectorTests::SUADDReduceAll); } + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = SUADD_IDENTITY; + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4574,8 +4792,9 @@ static void SUADDReduceLong256VectorTestsMasked(IntFunction fa, IntFunct ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6463,93 +6682,6 @@ static void maskFromToLongLong256VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "longUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - long x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((long)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((long)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Long.MIN_VALUE, x) == x - Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Long.MAX_VALUE, x) == x - Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((long)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((long)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "longUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "longCompareOpProvider") static void ltLong256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long512VectorTests.java b/test/jdk/jdk/incubator/vector/Long512VectorTests.java index 5fdb76aa16b6b..137791c221b97 100644 --- a/test/jdk/jdk/incubator/vector/Long512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long512VectorTests.java @@ -63,7 +63,6 @@ public class Long512VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final long CONST_SHIFT = Long.SIZE / 2; // Identity values for reduction operations @@ -3717,8 +3716,9 @@ static void ANDReduceLong512VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3726,6 +3726,24 @@ static void ANDReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::ANDReduce, Long512VectorTests::ANDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = AND_IDENTITY; + + Assert.assertEquals((long) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3757,8 +3775,9 @@ static void ANDReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3794,8 +3813,9 @@ static void ORReduceLong512VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3803,6 +3823,24 @@ static void ORReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::ORReduce, Long512VectorTests::ORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = OR_IDENTITY; + + Assert.assertEquals((long) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static long ORReduceMasked(long[] a, int idx, boolean[] mask) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3834,8 +3872,9 @@ static void ORReduceLong512VectorTestsMasked(IntFunction fa, IntFunction ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3871,8 +3910,9 @@ static void XORReduceLong512VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3880,6 +3920,24 @@ static void XORReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::XORReduce, Long512VectorTests::XORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = XOR_IDENTITY; + + Assert.assertEquals((long) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static long XORReduceMasked(long[] a, int idx, boolean[] mask) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3911,8 +3969,9 @@ static void XORReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3948,8 +4007,9 @@ static void ADDReduceLong512VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3957,6 +4017,24 @@ static void ADDReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::ADDReduce, Long512VectorTests::ADDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = ADD_IDENTITY; + + Assert.assertEquals((long) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3988,8 +4066,9 @@ static void ADDReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4025,8 +4104,9 @@ static void MULReduceLong512VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4034,6 +4114,24 @@ static void MULReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::MULReduce, Long512VectorTests::MULReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MUL_IDENTITY; + + Assert.assertEquals((long) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static long MULReduceMasked(long[] a, int idx, boolean[] mask) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4065,8 +4163,9 @@ static void MULReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4102,8 +4201,9 @@ static void MINReduceLong512VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4111,6 +4211,24 @@ static void MINReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::MINReduce, Long512VectorTests::MINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MIN_IDENTITY; + + Assert.assertEquals((long) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static long MINReduceMasked(long[] a, int idx, boolean[] mask) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4142,8 +4260,9 @@ static void MINReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4179,8 +4298,9 @@ static void MAXReduceLong512VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4188,6 +4308,24 @@ static void MAXReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::MAXReduce, Long512VectorTests::MAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MAX_IDENTITY; + + Assert.assertEquals((long) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4219,8 +4357,9 @@ static void MAXReduceLong512VectorTestsMasked(IntFunction fa, IntFunctio ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4256,8 +4395,9 @@ static void UMINReduceLong512VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4265,6 +4405,24 @@ static void UMINReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::UMINReduce, Long512VectorTests::UMINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMIN_IDENTITY; + + Assert.assertEquals((long) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4296,8 +4454,9 @@ static void UMINReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4333,8 +4492,9 @@ static void UMAXReduceLong512VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4342,6 +4502,24 @@ static void UMAXReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::UMAXReduce, Long512VectorTests::UMAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMAX_IDENTITY; + + Assert.assertEquals((long) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4373,8 +4551,9 @@ static void UMAXReduceLong512VectorTestsMasked(IntFunction fa, IntFuncti ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4410,8 +4589,9 @@ static void FIRST_NONZEROReduceLong512VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4419,6 +4599,24 @@ static void FIRST_NONZEROReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::FIRST_NONZEROReduce, Long512VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4450,8 +4648,9 @@ static void FIRST_NONZEROReduceLong512VectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4535,8 +4734,9 @@ static void SUADDReduceLong512VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4544,6 +4744,24 @@ static void SUADDReduceLong512VectorTests(IntFunction fa) { Long512VectorTests::SUADDReduce, Long512VectorTests::SUADDReduceAll); } + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = SUADD_IDENTITY; + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4574,8 +4792,9 @@ static void SUADDReduceLong512VectorTestsMasked(IntFunction fa, IntFunct ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6463,93 +6682,6 @@ static void maskFromToLongLong512VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "longUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - long x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((long)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((long)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Long.MIN_VALUE, x) == x - Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Long.MAX_VALUE, x) == x - Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((long)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((long)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "longUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "longCompareOpProvider") static void ltLong512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Long64VectorTests.java b/test/jdk/jdk/incubator/vector/Long64VectorTests.java index 22ac71312f3dd..f59ba1f56b963 100644 --- a/test/jdk/jdk/incubator/vector/Long64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long64VectorTests.java @@ -63,7 +63,6 @@ public class Long64VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final long CONST_SHIFT = Long.SIZE / 2; // Identity values for reduction operations @@ -3717,8 +3716,9 @@ static void ANDReduceLong64VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3726,6 +3726,24 @@ static void ANDReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::ANDReduce, Long64VectorTests::ANDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = AND_IDENTITY; + + Assert.assertEquals((long) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3757,8 +3775,9 @@ static void ANDReduceLong64VectorTestsMasked(IntFunction fa, IntFunction ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3794,8 +3813,9 @@ static void ORReduceLong64VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3803,6 +3823,24 @@ static void ORReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::ORReduce, Long64VectorTests::ORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = OR_IDENTITY; + + Assert.assertEquals((long) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static long ORReduceMasked(long[] a, int idx, boolean[] mask) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3834,8 +3872,9 @@ static void ORReduceLong64VectorTestsMasked(IntFunction fa, IntFunction< ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3871,8 +3910,9 @@ static void XORReduceLong64VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3880,6 +3920,24 @@ static void XORReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::XORReduce, Long64VectorTests::XORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = XOR_IDENTITY; + + Assert.assertEquals((long) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static long XORReduceMasked(long[] a, int idx, boolean[] mask) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3911,8 +3969,9 @@ static void XORReduceLong64VectorTestsMasked(IntFunction fa, IntFunction ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3948,8 +4007,9 @@ static void ADDReduceLong64VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3957,6 +4017,24 @@ static void ADDReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::ADDReduce, Long64VectorTests::ADDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = ADD_IDENTITY; + + Assert.assertEquals((long) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3988,8 +4066,9 @@ static void ADDReduceLong64VectorTestsMasked(IntFunction fa, IntFunction ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4025,8 +4104,9 @@ static void MULReduceLong64VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4034,6 +4114,24 @@ static void MULReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::MULReduce, Long64VectorTests::MULReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MUL_IDENTITY; + + Assert.assertEquals((long) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static long MULReduceMasked(long[] a, int idx, boolean[] mask) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4065,8 +4163,9 @@ static void MULReduceLong64VectorTestsMasked(IntFunction fa, IntFunction ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4102,8 +4201,9 @@ static void MINReduceLong64VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4111,6 +4211,24 @@ static void MINReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::MINReduce, Long64VectorTests::MINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MIN_IDENTITY; + + Assert.assertEquals((long) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static long MINReduceMasked(long[] a, int idx, boolean[] mask) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4142,8 +4260,9 @@ static void MINReduceLong64VectorTestsMasked(IntFunction fa, IntFunction ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4179,8 +4298,9 @@ static void MAXReduceLong64VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4188,6 +4308,24 @@ static void MAXReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::MAXReduce, Long64VectorTests::MAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MAX_IDENTITY; + + Assert.assertEquals((long) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4219,8 +4357,9 @@ static void MAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunction ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4256,8 +4395,9 @@ static void UMINReduceLong64VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4265,6 +4405,24 @@ static void UMINReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::UMINReduce, Long64VectorTests::UMINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMIN_IDENTITY; + + Assert.assertEquals((long) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4296,8 +4454,9 @@ static void UMINReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4333,8 +4492,9 @@ static void UMAXReduceLong64VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4342,6 +4502,24 @@ static void UMAXReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::UMAXReduce, Long64VectorTests::UMAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMAX_IDENTITY; + + Assert.assertEquals((long) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4373,8 +4551,9 @@ static void UMAXReduceLong64VectorTestsMasked(IntFunction fa, IntFunctio ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4410,8 +4589,9 @@ static void FIRST_NONZEROReduceLong64VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4419,6 +4599,24 @@ static void FIRST_NONZEROReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::FIRST_NONZEROReduce, Long64VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4450,8 +4648,9 @@ static void FIRST_NONZEROReduceLong64VectorTestsMasked(IntFunction fa, I ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4535,8 +4734,9 @@ static void SUADDReduceLong64VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4544,6 +4744,24 @@ static void SUADDReduceLong64VectorTests(IntFunction fa) { Long64VectorTests::SUADDReduce, Long64VectorTests::SUADDReduceAll); } + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = SUADD_IDENTITY; + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4574,8 +4792,9 @@ static void SUADDReduceLong64VectorTestsMasked(IntFunction fa, IntFuncti ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6463,93 +6682,6 @@ static void maskFromToLongLong64VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "longUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - long x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((long)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((long)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Long.MIN_VALUE, x) == x - Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Long.MAX_VALUE, x) == x - Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((long)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((long)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "longUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "longCompareOpProvider") static void ltLong64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java index 79bec1feffd8d..e6497687ffd90 100644 --- a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java @@ -3722,8 +3722,9 @@ static void ANDReduceLongMaxVectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3731,6 +3732,24 @@ static void ANDReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::ANDReduce, LongMaxVectorTests::ANDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = AND_IDENTITY; + + Assert.assertEquals((long) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static long ANDReduceMasked(long[] a, int idx, boolean[] mask) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3762,8 +3781,9 @@ static void ANDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + long v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3799,8 +3819,9 @@ static void ORReduceLongMaxVectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3808,6 +3829,24 @@ static void ORReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::ORReduce, LongMaxVectorTests::ORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = OR_IDENTITY; + + Assert.assertEquals((long) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static long ORReduceMasked(long[] a, int idx, boolean[] mask) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3839,8 +3878,9 @@ static void ORReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunction ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + long v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3876,8 +3916,9 @@ static void XORReduceLongMaxVectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3885,6 +3926,24 @@ static void XORReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::XORReduce, LongMaxVectorTests::XORReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = XOR_IDENTITY; + + Assert.assertEquals((long) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static long XORReduceMasked(long[] a, int idx, boolean[] mask) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3916,8 +3975,9 @@ static void XORReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + long v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3953,8 +4013,9 @@ static void ADDReduceLongMaxVectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3962,6 +4023,24 @@ static void ADDReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::ADDReduce, LongMaxVectorTests::ADDReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = ADD_IDENTITY; + + Assert.assertEquals((long) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static long ADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3993,8 +4072,9 @@ static void ADDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + long v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -4030,8 +4110,9 @@ static void MULReduceLongMaxVectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -4039,6 +4120,24 @@ static void MULReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::MULReduce, LongMaxVectorTests::MULReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MUL_IDENTITY; + + Assert.assertEquals((long) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static long MULReduceMasked(long[] a, int idx, boolean[] mask) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4070,8 +4169,9 @@ static void MULReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + long v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4107,8 +4207,9 @@ static void MINReduceLongMaxVectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4116,6 +4217,24 @@ static void MINReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::MINReduce, LongMaxVectorTests::MINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MIN_IDENTITY; + + Assert.assertEquals((long) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static long MINReduceMasked(long[] a, int idx, boolean[] mask) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4147,8 +4266,9 @@ static void MINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (long) Math.min(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (long) Math.min(ra, v); } } @@ -4184,8 +4304,9 @@ static void MAXReduceLongMaxVectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4193,6 +4314,24 @@ static void MAXReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::MAXReduce, LongMaxVectorTests::MAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = MAX_IDENTITY; + + Assert.assertEquals((long) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static long MAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4224,8 +4363,9 @@ static void MAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunctio ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (long) Math.max(ra, r[i]); + long v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (long) Math.max(ra, v); } } @@ -4261,8 +4401,9 @@ static void UMINReduceLongMaxVectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4270,6 +4411,24 @@ static void UMINReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::UMINReduce, LongMaxVectorTests::UMINReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMIN_IDENTITY; + + Assert.assertEquals((long) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static long UMINReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4301,8 +4460,9 @@ static void UMINReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (long) VectorMath.minUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (long) VectorMath.minUnsigned(ra, v); } } @@ -4338,8 +4498,9 @@ static void UMAXReduceLongMaxVectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4347,6 +4508,24 @@ static void UMAXReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::UMAXReduce, LongMaxVectorTests::UMAXReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = UMAX_IDENTITY; + + Assert.assertEquals((long) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static long UMAXReduceMasked(long[] a, int idx, boolean[] mask) { long res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4378,8 +4557,9 @@ static void UMAXReduceLongMaxVectorTestsMasked(IntFunction fa, IntFuncti ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (long) VectorMath.maxUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (long) VectorMath.maxUnsigned(ra, v); } } @@ -4415,8 +4595,9 @@ static void FIRST_NONZEROReduceLongMaxVectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4424,6 +4605,24 @@ static void FIRST_NONZEROReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::FIRST_NONZEROReduce, LongMaxVectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "longUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static long FIRST_NONZEROReduceMasked(long[] a, int idx, boolean[] mask) { long res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4455,8 +4654,9 @@ static void FIRST_NONZEROReduceLongMaxVectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + long v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4540,8 +4740,9 @@ static void SUADDReduceLongMaxVectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4549,6 +4750,24 @@ static void SUADDReduceLongMaxVectorTests(IntFunction fa) { LongMaxVectorTests::SUADDReduce, LongMaxVectorTests::SUADDReduceAll); } + @Test(dataProvider = "longSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + long[] a = fa.apply(SPECIES.length()); + long id = SUADD_IDENTITY; + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + long x = a[i]; + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static long SUADDReduceMasked(long[] a, int idx, boolean[] mask) { long res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4579,8 +4798,9 @@ static void SUADDReduceLongMaxVectorTestsMasked(IntFunction fa, IntFunct ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (long) VectorMath.addSaturatingUnsigned(ra, r[i]); + long v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (long) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6468,93 +6688,6 @@ static void maskFromToLongLongMaxVectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "longUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - long x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((long)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((long)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Long.MIN_VALUE, x) == x - Assert.assertEquals((long) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Long.MAX_VALUE, x) == x - Assert.assertEquals((long) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((long)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((long)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((long) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((long) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((long)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "longUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - long[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - LongVector av = LongVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "longCompareOpProvider") static void ltLongMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short128VectorTests.java b/test/jdk/jdk/incubator/vector/Short128VectorTests.java index 9934ae01d4c7a..f28b2c936754f 100644 --- a/test/jdk/jdk/incubator/vector/Short128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short128VectorTests.java @@ -63,7 +63,6 @@ public class Short128VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final short CONST_SHIFT = Short.SIZE / 2; // Identity values for reduction operations @@ -3642,8 +3641,9 @@ static void ANDReduceShort128VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3651,6 +3651,24 @@ static void ANDReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::ANDReduce, Short128VectorTests::ANDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = AND_IDENTITY; + + Assert.assertEquals((short) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3682,8 +3700,9 @@ static void ANDReduceShort128VectorTestsMasked(IntFunction fa, IntFunct ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3719,8 +3738,9 @@ static void ORReduceShort128VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3728,6 +3748,24 @@ static void ORReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::ORReduce, Short128VectorTests::ORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = OR_IDENTITY; + + Assert.assertEquals((short) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static short ORReduceMasked(short[] a, int idx, boolean[] mask) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3759,8 +3797,9 @@ static void ORReduceShort128VectorTestsMasked(IntFunction fa, IntFuncti ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3796,8 +3835,9 @@ static void XORReduceShort128VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3805,6 +3845,24 @@ static void XORReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::XORReduce, Short128VectorTests::XORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = XOR_IDENTITY; + + Assert.assertEquals((short) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static short XORReduceMasked(short[] a, int idx, boolean[] mask) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3836,8 +3894,9 @@ static void XORReduceShort128VectorTestsMasked(IntFunction fa, IntFunct ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3873,8 +3932,9 @@ static void ADDReduceShort128VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3882,6 +3942,24 @@ static void ADDReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::ADDReduce, Short128VectorTests::ADDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = ADD_IDENTITY; + + Assert.assertEquals((short) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3913,8 +3991,9 @@ static void ADDReduceShort128VectorTestsMasked(IntFunction fa, IntFunct ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3950,8 +4029,9 @@ static void MULReduceShort128VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3959,6 +4039,24 @@ static void MULReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::MULReduce, Short128VectorTests::MULReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MUL_IDENTITY; + + Assert.assertEquals((short) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static short MULReduceMasked(short[] a, int idx, boolean[] mask) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3990,8 +4088,9 @@ static void MULReduceShort128VectorTestsMasked(IntFunction fa, IntFunct ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4027,8 +4126,9 @@ static void MINReduceShort128VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4036,6 +4136,24 @@ static void MINReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::MINReduce, Short128VectorTests::MINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MIN_IDENTITY; + + Assert.assertEquals((short) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static short MINReduceMasked(short[] a, int idx, boolean[] mask) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4067,8 +4185,9 @@ static void MINReduceShort128VectorTestsMasked(IntFunction fa, IntFunct ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4104,8 +4223,9 @@ static void MAXReduceShort128VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4113,6 +4233,24 @@ static void MAXReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::MAXReduce, Short128VectorTests::MAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MAX_IDENTITY; + + Assert.assertEquals((short) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4144,8 +4282,9 @@ static void MAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunct ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4181,8 +4320,9 @@ static void UMINReduceShort128VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4190,6 +4330,24 @@ static void UMINReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::UMINReduce, Short128VectorTests::UMINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMIN_IDENTITY; + + Assert.assertEquals((short) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4221,8 +4379,9 @@ static void UMINReduceShort128VectorTestsMasked(IntFunction fa, IntFunc ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4258,8 +4417,9 @@ static void UMAXReduceShort128VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4267,6 +4427,24 @@ static void UMAXReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::UMAXReduce, Short128VectorTests::UMAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMAX_IDENTITY; + + Assert.assertEquals((short) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4298,8 +4476,9 @@ static void UMAXReduceShort128VectorTestsMasked(IntFunction fa, IntFunc ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4335,8 +4514,9 @@ static void FIRST_NONZEROReduceShort128VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4344,6 +4524,24 @@ static void FIRST_NONZEROReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::FIRST_NONZEROReduce, Short128VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4375,8 +4573,9 @@ static void FIRST_NONZEROReduceShort128VectorTestsMasked(IntFunction fa ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4460,8 +4659,9 @@ static void SUADDReduceShort128VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4469,6 +4669,24 @@ static void SUADDReduceShort128VectorTests(IntFunction fa) { Short128VectorTests::SUADDReduce, Short128VectorTests::SUADDReduceAll); } + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = SUADD_IDENTITY; + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4499,8 +4717,9 @@ static void SUADDReduceShort128VectorTestsMasked(IntFunction fa, IntFun ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6458,93 +6677,6 @@ static void maskFromToLongShort128VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "shortUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - short x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((short)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((short)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Short.MIN_VALUE, x) == x - Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Short.MAX_VALUE, x) == x - Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((short)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((short)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "shortUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShort128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short256VectorTests.java b/test/jdk/jdk/incubator/vector/Short256VectorTests.java index 449dad2a03c7b..7c9094cc7edbb 100644 --- a/test/jdk/jdk/incubator/vector/Short256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short256VectorTests.java @@ -63,7 +63,6 @@ public class Short256VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final short CONST_SHIFT = Short.SIZE / 2; // Identity values for reduction operations @@ -3642,8 +3641,9 @@ static void ANDReduceShort256VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3651,6 +3651,24 @@ static void ANDReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::ANDReduce, Short256VectorTests::ANDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = AND_IDENTITY; + + Assert.assertEquals((short) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3682,8 +3700,9 @@ static void ANDReduceShort256VectorTestsMasked(IntFunction fa, IntFunct ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3719,8 +3738,9 @@ static void ORReduceShort256VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3728,6 +3748,24 @@ static void ORReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::ORReduce, Short256VectorTests::ORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = OR_IDENTITY; + + Assert.assertEquals((short) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static short ORReduceMasked(short[] a, int idx, boolean[] mask) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3759,8 +3797,9 @@ static void ORReduceShort256VectorTestsMasked(IntFunction fa, IntFuncti ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3796,8 +3835,9 @@ static void XORReduceShort256VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3805,6 +3845,24 @@ static void XORReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::XORReduce, Short256VectorTests::XORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = XOR_IDENTITY; + + Assert.assertEquals((short) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static short XORReduceMasked(short[] a, int idx, boolean[] mask) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3836,8 +3894,9 @@ static void XORReduceShort256VectorTestsMasked(IntFunction fa, IntFunct ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3873,8 +3932,9 @@ static void ADDReduceShort256VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3882,6 +3942,24 @@ static void ADDReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::ADDReduce, Short256VectorTests::ADDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = ADD_IDENTITY; + + Assert.assertEquals((short) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3913,8 +3991,9 @@ static void ADDReduceShort256VectorTestsMasked(IntFunction fa, IntFunct ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3950,8 +4029,9 @@ static void MULReduceShort256VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3959,6 +4039,24 @@ static void MULReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::MULReduce, Short256VectorTests::MULReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MUL_IDENTITY; + + Assert.assertEquals((short) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static short MULReduceMasked(short[] a, int idx, boolean[] mask) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3990,8 +4088,9 @@ static void MULReduceShort256VectorTestsMasked(IntFunction fa, IntFunct ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4027,8 +4126,9 @@ static void MINReduceShort256VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4036,6 +4136,24 @@ static void MINReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::MINReduce, Short256VectorTests::MINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MIN_IDENTITY; + + Assert.assertEquals((short) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static short MINReduceMasked(short[] a, int idx, boolean[] mask) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4067,8 +4185,9 @@ static void MINReduceShort256VectorTestsMasked(IntFunction fa, IntFunct ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4104,8 +4223,9 @@ static void MAXReduceShort256VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4113,6 +4233,24 @@ static void MAXReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::MAXReduce, Short256VectorTests::MAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MAX_IDENTITY; + + Assert.assertEquals((short) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4144,8 +4282,9 @@ static void MAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunct ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4181,8 +4320,9 @@ static void UMINReduceShort256VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4190,6 +4330,24 @@ static void UMINReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::UMINReduce, Short256VectorTests::UMINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMIN_IDENTITY; + + Assert.assertEquals((short) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4221,8 +4379,9 @@ static void UMINReduceShort256VectorTestsMasked(IntFunction fa, IntFunc ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4258,8 +4417,9 @@ static void UMAXReduceShort256VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4267,6 +4427,24 @@ static void UMAXReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::UMAXReduce, Short256VectorTests::UMAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMAX_IDENTITY; + + Assert.assertEquals((short) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4298,8 +4476,9 @@ static void UMAXReduceShort256VectorTestsMasked(IntFunction fa, IntFunc ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4335,8 +4514,9 @@ static void FIRST_NONZEROReduceShort256VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4344,6 +4524,24 @@ static void FIRST_NONZEROReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::FIRST_NONZEROReduce, Short256VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4375,8 +4573,9 @@ static void FIRST_NONZEROReduceShort256VectorTestsMasked(IntFunction fa ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4460,8 +4659,9 @@ static void SUADDReduceShort256VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4469,6 +4669,24 @@ static void SUADDReduceShort256VectorTests(IntFunction fa) { Short256VectorTests::SUADDReduce, Short256VectorTests::SUADDReduceAll); } + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = SUADD_IDENTITY; + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4499,8 +4717,9 @@ static void SUADDReduceShort256VectorTestsMasked(IntFunction fa, IntFun ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6458,93 +6677,6 @@ static void maskFromToLongShort256VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "shortUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - short x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((short)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((short)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Short.MIN_VALUE, x) == x - Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Short.MAX_VALUE, x) == x - Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((short)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((short)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "shortUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShort256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short512VectorTests.java b/test/jdk/jdk/incubator/vector/Short512VectorTests.java index fff459956b6d8..199847b669371 100644 --- a/test/jdk/jdk/incubator/vector/Short512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short512VectorTests.java @@ -63,7 +63,6 @@ public class Short512VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final short CONST_SHIFT = Short.SIZE / 2; // Identity values for reduction operations @@ -3642,8 +3641,9 @@ static void ANDReduceShort512VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3651,6 +3651,24 @@ static void ANDReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::ANDReduce, Short512VectorTests::ANDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = AND_IDENTITY; + + Assert.assertEquals((short) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3682,8 +3700,9 @@ static void ANDReduceShort512VectorTestsMasked(IntFunction fa, IntFunct ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3719,8 +3738,9 @@ static void ORReduceShort512VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3728,6 +3748,24 @@ static void ORReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::ORReduce, Short512VectorTests::ORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = OR_IDENTITY; + + Assert.assertEquals((short) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static short ORReduceMasked(short[] a, int idx, boolean[] mask) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3759,8 +3797,9 @@ static void ORReduceShort512VectorTestsMasked(IntFunction fa, IntFuncti ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3796,8 +3835,9 @@ static void XORReduceShort512VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3805,6 +3845,24 @@ static void XORReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::XORReduce, Short512VectorTests::XORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = XOR_IDENTITY; + + Assert.assertEquals((short) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static short XORReduceMasked(short[] a, int idx, boolean[] mask) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3836,8 +3894,9 @@ static void XORReduceShort512VectorTestsMasked(IntFunction fa, IntFunct ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3873,8 +3932,9 @@ static void ADDReduceShort512VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3882,6 +3942,24 @@ static void ADDReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::ADDReduce, Short512VectorTests::ADDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = ADD_IDENTITY; + + Assert.assertEquals((short) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3913,8 +3991,9 @@ static void ADDReduceShort512VectorTestsMasked(IntFunction fa, IntFunct ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3950,8 +4029,9 @@ static void MULReduceShort512VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3959,6 +4039,24 @@ static void MULReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::MULReduce, Short512VectorTests::MULReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MUL_IDENTITY; + + Assert.assertEquals((short) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static short MULReduceMasked(short[] a, int idx, boolean[] mask) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3990,8 +4088,9 @@ static void MULReduceShort512VectorTestsMasked(IntFunction fa, IntFunct ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4027,8 +4126,9 @@ static void MINReduceShort512VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4036,6 +4136,24 @@ static void MINReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::MINReduce, Short512VectorTests::MINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MIN_IDENTITY; + + Assert.assertEquals((short) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static short MINReduceMasked(short[] a, int idx, boolean[] mask) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4067,8 +4185,9 @@ static void MINReduceShort512VectorTestsMasked(IntFunction fa, IntFunct ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4104,8 +4223,9 @@ static void MAXReduceShort512VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4113,6 +4233,24 @@ static void MAXReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::MAXReduce, Short512VectorTests::MAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MAX_IDENTITY; + + Assert.assertEquals((short) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4144,8 +4282,9 @@ static void MAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunct ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4181,8 +4320,9 @@ static void UMINReduceShort512VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4190,6 +4330,24 @@ static void UMINReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::UMINReduce, Short512VectorTests::UMINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMIN_IDENTITY; + + Assert.assertEquals((short) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4221,8 +4379,9 @@ static void UMINReduceShort512VectorTestsMasked(IntFunction fa, IntFunc ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4258,8 +4417,9 @@ static void UMAXReduceShort512VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4267,6 +4427,24 @@ static void UMAXReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::UMAXReduce, Short512VectorTests::UMAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMAX_IDENTITY; + + Assert.assertEquals((short) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4298,8 +4476,9 @@ static void UMAXReduceShort512VectorTestsMasked(IntFunction fa, IntFunc ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4335,8 +4514,9 @@ static void FIRST_NONZEROReduceShort512VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4344,6 +4524,24 @@ static void FIRST_NONZEROReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::FIRST_NONZEROReduce, Short512VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4375,8 +4573,9 @@ static void FIRST_NONZEROReduceShort512VectorTestsMasked(IntFunction fa ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4460,8 +4659,9 @@ static void SUADDReduceShort512VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4469,6 +4669,24 @@ static void SUADDReduceShort512VectorTests(IntFunction fa) { Short512VectorTests::SUADDReduce, Short512VectorTests::SUADDReduceAll); } + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = SUADD_IDENTITY; + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4499,8 +4717,9 @@ static void SUADDReduceShort512VectorTestsMasked(IntFunction fa, IntFun ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6458,93 +6677,6 @@ static void maskFromToLongShort512VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "shortUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - short x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((short)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((short)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Short.MIN_VALUE, x) == x - Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Short.MAX_VALUE, x) == x - Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((short)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((short)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "shortUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShort512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/Short64VectorTests.java b/test/jdk/jdk/incubator/vector/Short64VectorTests.java index 7bab146ce3e16..4b10a6ac3eba4 100644 --- a/test/jdk/jdk/incubator/vector/Short64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short64VectorTests.java @@ -63,7 +63,6 @@ public class Short64VectorTests extends AbstractVectorTest { static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - private static final short CONST_SHIFT = Short.SIZE / 2; // Identity values for reduction operations @@ -3642,8 +3641,9 @@ static void ANDReduceShort64VectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3651,6 +3651,24 @@ static void ANDReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::ANDReduce, Short64VectorTests::ANDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = AND_IDENTITY; + + Assert.assertEquals((short) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3682,8 +3700,9 @@ static void ANDReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3719,8 +3738,9 @@ static void ORReduceShort64VectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3728,6 +3748,24 @@ static void ORReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::ORReduce, Short64VectorTests::ORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = OR_IDENTITY; + + Assert.assertEquals((short) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static short ORReduceMasked(short[] a, int idx, boolean[] mask) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3759,8 +3797,9 @@ static void ORReduceShort64VectorTestsMasked(IntFunction fa, IntFunctio ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3796,8 +3835,9 @@ static void XORReduceShort64VectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3805,6 +3845,24 @@ static void XORReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::XORReduce, Short64VectorTests::XORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = XOR_IDENTITY; + + Assert.assertEquals((short) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static short XORReduceMasked(short[] a, int idx, boolean[] mask) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3836,8 +3894,9 @@ static void XORReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3873,8 +3932,9 @@ static void ADDReduceShort64VectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3882,6 +3942,24 @@ static void ADDReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::ADDReduce, Short64VectorTests::ADDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = ADD_IDENTITY; + + Assert.assertEquals((short) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3913,8 +3991,9 @@ static void ADDReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3950,8 +4029,9 @@ static void MULReduceShort64VectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3959,6 +4039,24 @@ static void MULReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::MULReduce, Short64VectorTests::MULReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MUL_IDENTITY; + + Assert.assertEquals((short) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static short MULReduceMasked(short[] a, int idx, boolean[] mask) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3990,8 +4088,9 @@ static void MULReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4027,8 +4126,9 @@ static void MINReduceShort64VectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4036,6 +4136,24 @@ static void MINReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::MINReduce, Short64VectorTests::MINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MIN_IDENTITY; + + Assert.assertEquals((short) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static short MINReduceMasked(short[] a, int idx, boolean[] mask) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4067,8 +4185,9 @@ static void MINReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4104,8 +4223,9 @@ static void MAXReduceShort64VectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4113,6 +4233,24 @@ static void MAXReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::MAXReduce, Short64VectorTests::MAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MAX_IDENTITY; + + Assert.assertEquals((short) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4144,8 +4282,9 @@ static void MAXReduceShort64VectorTestsMasked(IntFunction fa, IntFuncti ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4181,8 +4320,9 @@ static void UMINReduceShort64VectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4190,6 +4330,24 @@ static void UMINReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::UMINReduce, Short64VectorTests::UMINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMIN_IDENTITY; + + Assert.assertEquals((short) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4221,8 +4379,9 @@ static void UMINReduceShort64VectorTestsMasked(IntFunction fa, IntFunct ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4258,8 +4417,9 @@ static void UMAXReduceShort64VectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4267,6 +4427,24 @@ static void UMAXReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::UMAXReduce, Short64VectorTests::UMAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMAX_IDENTITY; + + Assert.assertEquals((short) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4298,8 +4476,9 @@ static void UMAXReduceShort64VectorTestsMasked(IntFunction fa, IntFunct ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4335,8 +4514,9 @@ static void FIRST_NONZEROReduceShort64VectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4344,6 +4524,24 @@ static void FIRST_NONZEROReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::FIRST_NONZEROReduce, Short64VectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4375,8 +4573,9 @@ static void FIRST_NONZEROReduceShort64VectorTestsMasked(IntFunction fa, ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4460,8 +4659,9 @@ static void SUADDReduceShort64VectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4469,6 +4669,24 @@ static void SUADDReduceShort64VectorTests(IntFunction fa) { Short64VectorTests::SUADDReduce, Short64VectorTests::SUADDReduceAll); } + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = SUADD_IDENTITY; + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4499,8 +4717,9 @@ static void SUADDReduceShort64VectorTestsMasked(IntFunction fa, IntFunc ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6458,93 +6677,6 @@ static void maskFromToLongShort64VectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "shortUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - short x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((short)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((short)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Short.MIN_VALUE, x) == x - Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Short.MAX_VALUE, x) == x - Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((short)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((short)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "shortUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShort64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java index dbfe7d38ede56..782b25d015a92 100644 --- a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java @@ -3647,8 +3647,9 @@ static void ANDReduceShortMaxVectorTests(IntFunction fa) { ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND); + r[i] = v; + ra &= v; } } @@ -3656,6 +3657,24 @@ static void ANDReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::ANDReduce, ShortMaxVectorTests::ANDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ANDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = AND_IDENTITY; + + Assert.assertEquals((short) (id & id), id, + "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id & x), x, + "AND(AND_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x & id), x, + "AND(" + x + ", AND_IDENTITY) != " + x); + } + } + static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3687,8 +3706,9 @@ static void ANDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct ra = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.AND, vmask); - ra &= r[i]; + short v = av.reduceLanes(VectorOperators.AND, vmask); + r[i] = v; + ra &= v; } } @@ -3724,8 +3744,9 @@ static void ORReduceShortMaxVectorTests(IntFunction fa) { ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR); + r[i] = v; + ra |= v; } } @@ -3733,6 +3754,24 @@ static void ORReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::ORReduce, ShortMaxVectorTests::ORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = OR_IDENTITY; + + Assert.assertEquals((short) (id | id), id, + "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id | x), x, + "OR(OR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x | id), x, + "OR(" + x + ", OR_IDENTITY) != " + x); + } + } + static short ORReduceMasked(short[] a, int idx, boolean[] mask) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3764,8 +3803,9 @@ static void ORReduceShortMaxVectorTestsMasked(IntFunction fa, IntFuncti ra = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.OR, vmask); - ra |= r[i]; + short v = av.reduceLanes(VectorOperators.OR, vmask); + r[i] = v; + ra |= v; } } @@ -3801,8 +3841,9 @@ static void XORReduceShortMaxVectorTests(IntFunction fa) { ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR); + r[i] = v; + ra ^= v; } } @@ -3810,6 +3851,24 @@ static void XORReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::XORReduce, ShortMaxVectorTests::XORReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void XORReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = XOR_IDENTITY; + + Assert.assertEquals((short) (id ^ id), id, + "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id ^ x), x, + "XOR(XOR_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x ^ id), x, + "XOR(" + x + ", XOR_IDENTITY) != " + x); + } + } + static short XORReduceMasked(short[] a, int idx, boolean[] mask) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3841,8 +3900,9 @@ static void XORReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct ra = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.XOR, vmask); - ra ^= r[i]; + short v = av.reduceLanes(VectorOperators.XOR, vmask); + r[i] = v; + ra ^= v; } } @@ -3878,8 +3938,9 @@ static void ADDReduceShortMaxVectorTests(IntFunction fa) { ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD); + r[i] = v; + ra += v; } } @@ -3887,6 +3948,24 @@ static void ADDReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::ADDReduce, ShortMaxVectorTests::ADDReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void ADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = ADD_IDENTITY; + + Assert.assertEquals((short) (id + id), id, + "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id + x), x, + "ADD(ADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x + id), x, + "ADD(" + x + ", ADD_IDENTITY) != " + x); + } + } + static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3918,8 +3997,9 @@ static void ADDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct ra = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.ADD, vmask); - ra += r[i]; + short v = av.reduceLanes(VectorOperators.ADD, vmask); + r[i] = v; + ra += v; } } @@ -3955,8 +4035,9 @@ static void MULReduceShortMaxVectorTests(IntFunction fa) { ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL); + r[i] = v; + ra *= v; } } @@ -3964,6 +4045,24 @@ static void MULReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::MULReduce, ShortMaxVectorTests::MULReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MULReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MUL_IDENTITY; + + Assert.assertEquals((short) (id * id), id, + "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) (id * x), x, + "MUL(MUL_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) (x * id), x, + "MUL(" + x + ", MUL_IDENTITY) != " + x); + } + } + static short MULReduceMasked(short[] a, int idx, boolean[] mask) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3995,8 +4094,9 @@ static void MULReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct ra = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MUL, vmask); - ra *= r[i]; + short v = av.reduceLanes(VectorOperators.MUL, vmask); + r[i] = v; + ra *= v; } } @@ -4032,8 +4132,9 @@ static void MINReduceShortMaxVectorTests(IntFunction fa) { ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4041,6 +4142,24 @@ static void MINReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::MINReduce, ShortMaxVectorTests::MINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MIN_IDENTITY; + + Assert.assertEquals((short) Math.min(id, id), id, + "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.min(id, x), x, + "MIN(MIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.min(x, id), x, + "MIN(" + x + ", MIN_IDENTITY) != " + x); + } + } + static short MINReduceMasked(short[] a, int idx, boolean[] mask) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4072,8 +4191,9 @@ static void MINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct ra = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MIN, vmask); - ra = (short) Math.min(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MIN, vmask); + r[i] = v; + ra = (short) Math.min(ra, v); } } @@ -4109,8 +4229,9 @@ static void MAXReduceShortMaxVectorTests(IntFunction fa) { ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4118,6 +4239,24 @@ static void MAXReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::MAXReduce, ShortMaxVectorTests::MAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void MAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = MAX_IDENTITY; + + Assert.assertEquals((short) Math.max(id, id), id, + "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) Math.max(id, x), x, + "MAX(MAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) Math.max(x, id), x, + "MAX(" + x + ", MAX_IDENTITY) != " + x); + } + } + static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4149,8 +4288,9 @@ static void MAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunct ra = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.MAX, vmask); - ra = (short) Math.max(ra, r[i]); + short v = av.reduceLanes(VectorOperators.MAX, vmask); + r[i] = v; + ra = (short) Math.max(ra, v); } } @@ -4186,8 +4326,9 @@ static void UMINReduceShortMaxVectorTests(IntFunction fa) { ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4195,6 +4336,24 @@ static void UMINReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::UMINReduce, ShortMaxVectorTests::UMINReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMINReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMIN_IDENTITY; + + Assert.assertEquals((short) VectorMath.minUnsigned(id, id), id, + "UMIN(UMIN_IDENTITY, UMIN_IDENTITY) != UMIN_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.minUnsigned(id, x), x, + "UMIN(UMIN_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.minUnsigned(x, id), x, + "UMIN(" + x + ", UMIN_IDENTITY) != " + x); + } + } + static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4226,8 +4385,9 @@ static void UMINReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc ra = UMIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); - ra = (short) VectorMath.minUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMIN, vmask); + r[i] = v; + ra = (short) VectorMath.minUnsigned(ra, v); } } @@ -4263,8 +4423,9 @@ static void UMAXReduceShortMaxVectorTests(IntFunction fa) { ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4272,6 +4433,24 @@ static void UMAXReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::UMAXReduce, ShortMaxVectorTests::UMAXReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void UMAXReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = UMAX_IDENTITY; + + Assert.assertEquals((short) VectorMath.maxUnsigned(id, id), id, + "UMAX(UMAX_IDENTITY, UMAX_IDENTITY) != UMAX_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.maxUnsigned(id, x), x, + "UMAX(UMAX_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.maxUnsigned(x, id), x, + "UMAX(" + x + ", UMAX_IDENTITY) != " + x); + } + } + static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { short res = UMAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4303,8 +4482,9 @@ static void UMAXReduceShortMaxVectorTestsMasked(IntFunction fa, IntFunc ra = UMAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); - ra = (short) VectorMath.maxUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.UMAX, vmask); + r[i] = v; + ra = (short) VectorMath.maxUnsigned(ra, v); } } @@ -4340,8 +4520,9 @@ static void FIRST_NONZEROReduceShortMaxVectorTests(IntFunction fa) { ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4349,6 +4530,24 @@ static void FIRST_NONZEROReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::FIRST_NONZEROReduce, ShortMaxVectorTests::FIRST_NONZEROReduceAll); } + @Test(dataProvider = "shortUnaryOpProvider") + static void FIRST_NONZEROReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = FIRST_NONZERO_IDENTITY; + + Assert.assertEquals(firstNonZero(id, id), id, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, FIRST_NONZERO_IDENTITY) != FIRST_NONZERO_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals(firstNonZero(id, x), x, + "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals(firstNonZero(x, id), x, + "FIRST_NONZERO(" + x + ", FIRST_NONZERO_IDENTITY) != " + x); + } + } + static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { short res = FIRST_NONZERO_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4380,8 +4579,9 @@ static void FIRST_NONZEROReduceShortMaxVectorTestsMasked(IntFunction fa ra = FIRST_NONZERO_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); - ra = firstNonZero(ra, r[i]); + short v = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); + r[i] = v; + ra = firstNonZero(ra, v); } } @@ -4465,8 +4665,9 @@ static void SUADDReduceShortMaxVectorTests(IntFunction fa) { ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -4474,6 +4675,24 @@ static void SUADDReduceShortMaxVectorTests(IntFunction fa) { ShortMaxVectorTests::SUADDReduce, ShortMaxVectorTests::SUADDReduceAll); } + @Test(dataProvider = "shortSaturatingUnaryOpProvider") + static void SUADDReduceIdentityValueTests(IntFunction fa) { + short[] a = fa.apply(SPECIES.length()); + short id = SUADD_IDENTITY; + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, id), id, + "SUADD(SUADD_IDENTITY, SUADD_IDENTITY) != SUADD_IDENTITY"); + + for (int i = 0; i < a.length; i++) { + short x = a[i]; + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(id, x), x, + "SUADD(SUADD_IDENTITY, " + x + ") != " + x); + + Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(x, id), x, + "SUADD(" + x + ", SUADD_IDENTITY) != " + x); + } + } + static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { short res = SUADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -4504,8 +4723,9 @@ static void SUADDReduceShortMaxVectorTestsMasked(IntFunction fa, IntFun ra = SUADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { ShortVector av = ShortVector.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); - ra = (short) VectorMath.addSaturatingUnsigned(ra, r[i]); + short v = av.reduceLanes(VectorOperators.SUADD, vmask); + r[i] = v; + ra = (short) VectorMath.addSaturatingUnsigned(ra, v); } } @@ -6463,93 +6683,6 @@ static void maskFromToLongShortMaxVectorTests(IntFunction fa) { assertArraysEquals(r, a, LONG_MASK_BITS); } - @Test(dataProvider = "shortUnaryOpProvider") - static void testIdentityValues(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - short x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals((short)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); - - // AND identity: -1 & x == x - Assert.assertEquals((short)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max(Short.MIN_VALUE, x) == x - Assert.assertEquals((short) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min(Short.MAX_VALUE, x) == x - Assert.assertEquals((short) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals((short)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); - - // OR identity: 0 | x == x - Assert.assertEquals((short)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals((short) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals((short) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals((short)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); - } - } - - @Test(dataProvider = "shortUnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction fa) { - short[] a = fa.apply(SPECIES.length()); - VectorMask allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); - } - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShortMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { short[] a = fa.apply(SPECIES.length()); diff --git a/test/jdk/jdk/incubator/vector/gen-template.sh b/test/jdk/jdk/incubator/vector/gen-template.sh index 817f4fbe05bce..7f8d20db6d5d5 100644 --- a/test/jdk/jdk/incubator/vector/gen-template.sh +++ b/test/jdk/jdk/incubator/vector/gen-template.sh @@ -638,9 +638,6 @@ gen_op_tmpl $bool_binary_template "eq" "a == b" gen_op_tmpl $bool_unary_template "not" "!a" gen_op_tmpl $mask_fromtolong_template "FromToLong" "" -# Identity value tests -gen_op_tmpl "Identity-test" "Identity" "" "" - # Miscellaneous Smoke Tests gen_op_tmpl $miscellaneous_template "MISC" "" "" diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op-func.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op-func.template index 6811884a11779..73e02bf68dd25 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op-func.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op-func.template @@ -8,8 +8,9 @@ ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); - ra = [[TEST_OP]](ra, r[i]); + $type$ v = av.reduceLanes(VectorOperators.[[TEST]], vmask); + r[i] = v; + ra = [[TEST_OP]](ra, v); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op.template index 95e154168e678..82e20d594b64a 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-Masked-op.template @@ -8,8 +8,9 @@ ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); - ra [[TEST_OP]]= r[i]; + $type$ v = av.reduceLanes(VectorOperators.[[TEST]], vmask); + r[i] = v; + ra [[TEST_OP]]= v; } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op-func.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op-func.template index 6e573512c97e2..94fae420cddc8 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op-func.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op-func.template @@ -6,8 +6,9 @@ ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]]); - ra = [[TEST_OP]](ra, r[i]); + $type$ v = av.reduceLanes(VectorOperators.[[TEST]]); + r[i] = v; + ra = [[TEST_OP]](ra, v); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template index 788de2b52a823..3edc2b27e3e3e 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template @@ -6,8 +6,9 @@ ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]]); - ra [[TEST_OP]]= r[i]; + $type$ v = av.reduceLanes(VectorOperators.[[TEST]]); + r[i] = v; + ra [[TEST_OP]]= v; } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template index 6811884a11779..73e02bf68dd25 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-Masked-op.template @@ -8,8 +8,9 @@ ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]], vmask); - ra = [[TEST_OP]](ra, r[i]); + $type$ v = av.reduceLanes(VectorOperators.[[TEST]], vmask); + r[i] = v; + ra = [[TEST_OP]](ra, v); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template index 6e573512c97e2..94fae420cddc8 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-SaturatingReduction-op.template @@ -6,8 +6,9 @@ ra = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - r[i] = av.reduceLanes(VectorOperators.[[TEST]]); - ra = [[TEST_OP]](ra, r[i]); + $type$ v = av.reduceLanes(VectorOperators.[[TEST]]); + r[i] = v; + ra = [[TEST_OP]](ra, v); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Identity-test.template b/test/jdk/jdk/incubator/vector/templates/Unit-Identity-test.template deleted file mode 100644 index 1b4b3ddcd40d6..0000000000000 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Identity-test.template +++ /dev/null @@ -1,95 +0,0 @@ - - @Test(dataProvider = "$type$UnaryOpProvider") - static void testIdentityValues(IntFunction<$type$[]> fa) { - $type$[] a = fa.apply(SPECIES.length()); - - for (int i = 0; i < a.length; i++) { - $type$ x = a[i]; - - // ADD identity: 0 + x == x - Assert.assertEquals(($type$)(ADD_IDENTITY + x), x, - "ADD(ADD_IDENTITY, " + x + ") != " + x); -#if[BITWISE] - - // AND identity: -1 & x == x - Assert.assertEquals(($type$)(AND_IDENTITY & x), x, - "AND(AND_IDENTITY, " + x + ") != " + x); -#end[BITWISE] - - // FIRST_NONZERO identity: firstNonZero(0, x) == x - Assert.assertEquals(firstNonZero(FIRST_NONZERO_IDENTITY, x), x, - "FIRST_NONZERO(FIRST_NONZERO_IDENTITY, " + x + ") != " + x); - - // MAX identity: max($Wideboxtype$.$MinValue$, x) == x - Assert.assertEquals(($type$) Math.max(MAX_IDENTITY, x), x, - "MAX(MAX_IDENTITY, " + x + ") != " + x); - - // MIN identity: min($Wideboxtype$.$MaxValue$, x) == x - Assert.assertEquals(($type$) Math.min(MIN_IDENTITY, x), x, - "MIN(MIN_IDENTITY, " + x + ") != " + x); - - // MUL identity: 1 * x == x - Assert.assertEquals(($type$)(MUL_IDENTITY * x), x, - "MUL(MUL_IDENTITY, " + x + ") != " + x); -#if[BITWISE] - - // OR identity: 0 | x == x - Assert.assertEquals(($type$)(OR_IDENTITY | x), x, - "OR(OR_IDENTITY, " + x + ") != " + x); - - // SUADD identity: addSaturatingUnsigned(0, x) == x - Assert.assertEquals(($type$) VectorMath.addSaturatingUnsigned(SUADD_IDENTITY, x), x, - "SUADD(SUADD_IDENTITY, " + x + ") != " + x); - - // UMAX identity: maxUnsigned(0, x) == x - Assert.assertEquals(($type$) VectorMath.maxUnsigned(UMAX_IDENTITY, x), x, - "UMAX(UMAX_IDENTITY, " + x + ") != " + x); - - // UMIN identity: minUnsigned(-1, x) == x - Assert.assertEquals(($type$) VectorMath.minUnsigned(UMIN_IDENTITY, x), x, - "UMIN(UMIN_IDENTITY, " + x + ") != " + x); - - // XOR identity: 0 ^ x == x - Assert.assertEquals(($type$)(XOR_IDENTITY ^ x), x, - "XOR(XOR_IDENTITY, " + x + ") != " + x); -#end[BITWISE] - } - } - - @Test(dataProvider = "$type$UnaryOpProvider") - static void testMaskedReductionIdentityAllFalse(IntFunction<$type$[]> fa) { - $type$[] a = fa.apply(SPECIES.length()); - VectorMask<$Wideboxtype$> allFalseMask = SPECIES.maskAll(false); - - for (int i = 0; i < a.length; i += SPECIES.length()) { - $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); - - // When mask is all false, reduction should return identity value - Assert.assertEquals(av.reduceLanes(VectorOperators.ADD, allFalseMask), ADD_IDENTITY, - "ADD with all-false mask should return ADD_IDENTITY"); -#if[BITWISE] - Assert.assertEquals(av.reduceLanes(VectorOperators.AND, allFalseMask), AND_IDENTITY, - "AND with all-false mask should return AND_IDENTITY"); -#end[BITWISE] - Assert.assertEquals(av.reduceLanes(VectorOperators.FIRST_NONZERO, allFalseMask), FIRST_NONZERO_IDENTITY, - "FIRST_NONZERO with all-false mask should return FIRST_NONZERO_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MAX, allFalseMask), MAX_IDENTITY, - "MAX with all-false mask should return MAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MIN, allFalseMask), MIN_IDENTITY, - "MIN with all-false mask should return MIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.MUL, allFalseMask), MUL_IDENTITY, - "MUL with all-false mask should return MUL_IDENTITY"); -#if[BITWISE] - Assert.assertEquals(av.reduceLanes(VectorOperators.OR, allFalseMask), OR_IDENTITY, - "OR with all-false mask should return OR_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.SUADD, allFalseMask), SUADD_IDENTITY, - "SUADD with all-false mask should return SUADD_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMAX, allFalseMask), UMAX_IDENTITY, - "UMAX with all-false mask should return UMAX_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.UMIN, allFalseMask), UMIN_IDENTITY, - "UMIN with all-false mask should return UMIN_IDENTITY"); - Assert.assertEquals(av.reduceLanes(VectorOperators.XOR, allFalseMask), XOR_IDENTITY, - "XOR with all-false mask should return XOR_IDENTITY"); -#end[BITWISE] - } - } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op-func.template b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op-func.template index e6bcdb83c2e02..191ce073277e4 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op-func.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op-func.template @@ -5,3 +5,21 @@ assertReductionArraysEquals(r, ra, a, $vectorteststype$::[[TEST]]Reduce, $vectorteststype$::[[TEST]]ReduceAll); } + + @Test(dataProvider = "$type$UnaryOpProvider") + static void [[TEST]]ReduceIdentityValueTests(IntFunction<$type$[]> fa) { + $type$[] a = fa.apply(SPECIES.length()); + $type$ id = [[TEST_INIT]]; + + Assert.assertEquals([[TEST_OP]](id, id), id, + "[[TEST]]([[TEST_INIT]], [[TEST_INIT]]) != [[TEST_INIT]]"); + + for (int i = 0; i < a.length; i++) { + $type$ x = a[i]; + Assert.assertEquals([[TEST_OP]](id, x), x, + "[[TEST]]([[TEST_INIT]], " + x + ") != " + x); + + Assert.assertEquals([[TEST_OP]](x, id), x, + "[[TEST]](" + x + ", [[TEST_INIT]]) != " + x); + } + } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op.template index 5638940045dc6..9cd29ec54977a 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op.template @@ -9,3 +9,21 @@ $vectorteststype$::[[TEST]]Reduce, $vectorteststype$::[[TEST]]ReduceAll); #end[FP] } + + @Test(dataProvider = "$type$UnaryOpProvider") + static void [[TEST]]ReduceIdentityValueTests(IntFunction<$type$[]> fa) { + $type$[] a = fa.apply(SPECIES.length()); + $type$ id = [[TEST_INIT]]; + + Assert.assertEquals(($type$) (id [[TEST_OP]] id), id, + "[[TEST]]([[TEST_INIT]], [[TEST_INIT]]) != [[TEST_INIT]]"); + + for (int i = 0; i < a.length; i++) { + $type$ x = a[i]; + Assert.assertEquals(($type$) (id [[TEST_OP]] x), x, + "[[TEST]]([[TEST_INIT]], " + x + ") != " + x); + + Assert.assertEquals(($type$) (x [[TEST_OP]] id), x, + "[[TEST]](" + x + ", [[TEST_INIT]]) != " + x); + } + } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-op.template index fdd9e47167eed..07f29c20d7692 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-SaturatingReduction-op.template @@ -5,3 +5,21 @@ assertReductionArraysEquals(r, ra, a, $vectorteststype$::[[TEST]]Reduce, $vectorteststype$::[[TEST]]ReduceAll); } + + @Test(dataProvider = "$type$SaturatingUnaryOpProvider") + static void [[TEST]]ReduceIdentityValueTests(IntFunction<$type$[]> fa) { + $type$[] a = fa.apply(SPECIES.length()); + $type$ id = [[TEST_INIT]]; + + Assert.assertEquals([[TEST_OP]](id, id), id, + "[[TEST]]([[TEST_INIT]], [[TEST_INIT]]) != [[TEST_INIT]]"); + + for (int i = 0; i < a.length; i++) { + $type$ x = a[i]; + Assert.assertEquals([[TEST_OP]](id, x), x, + "[[TEST]]([[TEST_INIT]], " + x + ") != " + x); + + Assert.assertEquals([[TEST_OP]](x, id), x, + "[[TEST]](" + x + ", [[TEST_INIT]]) != " + x); + } + } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-header.template b/test/jdk/jdk/incubator/vector/templates/Unit-header.template index 89b9dbed8d781..d2b2ee6fe131e 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-header.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-header.template @@ -86,16 +86,16 @@ public class $vectorteststype$ extends AbstractVectorTest { #end[MaxBit] static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); - #if[MaxBit] + static VectorShape getMaxBit() { return VectorShape.S_Max_BIT; } private static final int Max = 256; // juts so we can do N/$bits$ #end[MaxBit] - #if[BITWISE] + private static final $type$ CONST_SHIFT = $Boxtype$.SIZE / 2; #end[BITWISE] @@ -116,6 +116,7 @@ public class $vectorteststype$ extends AbstractVectorTest { private static final $type$ XOR_IDENTITY = ($type$)0; #end[BITWISE] #if[FP] + // for floating point addition reduction ops that may introduce rounding errors private static final $type$ RELATIVE_ROUNDING_ERROR_FACTOR_ADD = ($type$)10.0;