diff --git a/test/jdk/jdk/incubator/vector/ByteVector128Tests.java b/test/jdk/jdk/incubator/vector/ByteVector128Tests.java index 91148fd5d66..ca6fa537ac4 100644 --- a/test/jdk/jdk/incubator/vector/ByteVector128Tests.java +++ b/test/jdk/jdk/incubator/vector/ByteVector128Tests.java @@ -1574,6 +1574,59 @@ public class ByteVector128Tests extends AbstractVectorTest { return a >= b; } + static byte firstNonZero(byte a, byte b) { + return Byte.compare(a, (byte) 0) != 0 ? a : b; + } + + static byte scalar_or(byte a, byte b) { + return (byte)(a | b); + } + + static byte scalar_and(byte a, byte b) { + return (byte)(a & b); + } + + static byte scalar_xor(byte a, byte b) { + return (byte)(a ^ b); + } + + static byte scalar_add(byte a, byte b) { + return (byte)(a + b); + } + + static byte scalar_sub(byte a, byte b) { + return (byte)(a - b); + } + + static byte scalar_mul(byte a, byte b) { + return (byte)(a * b); + } + + static byte scalar_min(byte a, byte b) { + return (byte)(Math.min(a, b)); + } + + static byte scalar_max(byte a, byte b) { + return (byte)(Math.max(a, b)); + } + + static byte scalar_div(byte a, byte b) { + return (byte)(a / b); + } + + static byte scalar_fma(byte a, byte b, byte c) { + return (byte)(Math.fma(a, b, c)); + } + + static byte scalar_abs(byte a) { + return (byte)(Math.abs(a)); + } + + static byte scalar_neg(byte a) { + return ((byte)-a); + } + + static boolean ult(byte a, byte b) { return Byte.compareUnsigned(a, b) < 0; } @@ -1590,9 +1643,6 @@ public class ByteVector128Tests extends AbstractVectorTest { return Byte.compareUnsigned(a, b) >= 0; } - static byte firstNonZero(byte a, byte b) { - return Byte.compare(a, (byte) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1701,7 +1751,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte ADD(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1722,7 +1772,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte add(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1779,7 +1829,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte SUB(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1800,7 +1850,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte sub(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1857,7 +1907,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte MUL(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1878,7 +1928,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte mul(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -2025,7 +2075,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte FIRST_NONZERO(byte a, byte b) { - return (byte)((a)!=0?a:b); + return (byte)(firstNonZero(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3239,7 +3289,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte MIN(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3260,7 +3310,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte min(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3279,7 +3329,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte MAX(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3300,7 +3350,7 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte max(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3668,7 +3718,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ANDReduce(byte[] a, int idx) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3677,7 +3727,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ANDReduceAll(byte[] a) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3695,7 +3745,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3708,20 +3758,20 @@ public class ByteVector128Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = AND_IDENTITY; - assertEquals((byte) (id & id), id, + assertEquals((byte) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id & x), x); - assertEquals((byte) (x & id), x); + assertEquals((byte) (scalar_and(id, x)), x); + assertEquals((byte) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id & x), x, + assertEquals((byte) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x & id), x, + assertEquals((byte) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3730,7 +3780,7 @@ public class ByteVector128Tests extends AbstractVectorTest { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3739,7 +3789,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3759,7 +3809,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3770,7 +3820,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ORReduce(byte[] a, int idx) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3779,7 +3829,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ORReduceAll(byte[] a) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3797,7 +3847,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3810,20 +3860,20 @@ public class ByteVector128Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = OR_IDENTITY; - assertEquals((byte) (id | id), id, + assertEquals((byte) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id | x), x); - assertEquals((byte) (x | id), x); + assertEquals((byte) (scalar_or(id, x)), x); + assertEquals((byte) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id | x), x, + assertEquals((byte) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x | id), x, + assertEquals((byte) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3832,7 +3882,7 @@ public class ByteVector128Tests extends AbstractVectorTest { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3841,7 +3891,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ORReduceAllMasked(byte[] a, boolean[] mask) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3861,7 +3911,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3872,7 +3922,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte XORReduce(byte[] a, int idx) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3881,7 +3931,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte XORReduceAll(byte[] a) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3899,7 +3949,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3912,20 +3962,20 @@ public class ByteVector128Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = XOR_IDENTITY; - assertEquals((byte) (id ^ id), id, + assertEquals((byte) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id ^ x), x); - assertEquals((byte) (x ^ id), x); + assertEquals((byte) (scalar_xor(id, x)), x); + assertEquals((byte) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id ^ x), x, + assertEquals((byte) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x ^ id), x, + assertEquals((byte) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3934,7 +3984,7 @@ public class ByteVector128Tests extends AbstractVectorTest { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3943,7 +3993,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte XORReduceAllMasked(byte[] a, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3963,7 +4013,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3974,7 +4024,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ADDReduce(byte[] a, int idx) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3983,7 +4033,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ADDReduceAll(byte[] a) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4001,7 +4051,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4014,20 +4064,20 @@ public class ByteVector128Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = ADD_IDENTITY; - assertEquals((byte) (id + id), id, + assertEquals((byte) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id + x), x); - assertEquals((byte) (x + id), x); + assertEquals((byte) (scalar_add(id, x)), x); + assertEquals((byte) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id + x), x, + assertEquals((byte) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x + id), x, + assertEquals((byte) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4036,7 +4086,7 @@ public class ByteVector128Tests extends AbstractVectorTest { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4045,7 +4095,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4065,7 +4115,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4076,7 +4126,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MULReduce(byte[] a, int idx) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4085,7 +4135,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MULReduceAll(byte[] a) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4103,7 +4153,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4116,20 +4166,20 @@ public class ByteVector128Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MUL_IDENTITY; - assertEquals((byte) (id * id), id, + assertEquals((byte) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id * x), x); - assertEquals((byte) (x * id), x); + assertEquals((byte) (scalar_mul(id, x)), x); + assertEquals((byte) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id * x), x, + assertEquals((byte) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x * id), x, + assertEquals((byte) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4138,7 +4188,7 @@ public class ByteVector128Tests extends AbstractVectorTest { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4147,7 +4197,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MULReduceAllMasked(byte[] a, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4167,7 +4217,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4178,7 +4228,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MINReduce(byte[] a, int idx) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4187,7 +4237,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MINReduceAll(byte[] a) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4205,7 +4255,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4218,20 +4268,20 @@ public class ByteVector128Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MIN_IDENTITY; - assertEquals((byte) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.min(id, x), x); - assertEquals((byte) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4240,7 +4290,7 @@ public class ByteVector128Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4249,7 +4299,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MINReduceAllMasked(byte[] a, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4269,7 +4319,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4280,7 +4330,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MAXReduce(byte[] a, int idx) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4289,7 +4339,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MAXReduceAll(byte[] a) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4307,7 +4357,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4320,20 +4370,20 @@ public class ByteVector128Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MAX_IDENTITY; - assertEquals((byte) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.max(id, x), x); - assertEquals((byte) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4342,7 +4392,7 @@ public class ByteVector128Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4351,7 +4401,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4371,7 +4421,7 @@ public class ByteVector128Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5404,7 +5454,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5424,7 +5474,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5440,7 +5490,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (byte)((long)b[i]))); } } } @@ -5460,7 +5510,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (byte)((long)b[i])))); } } } @@ -5476,7 +5526,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5496,7 +5546,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5512,7 +5562,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (byte)((long)b[i]))); } } } @@ -5532,7 +5582,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (byte)((long)b[i])))); } } } @@ -6244,11 +6294,11 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte NEG(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } static byte neg(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6300,11 +6350,11 @@ public class ByteVector128Tests extends AbstractVectorTest { } static byte ABS(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } static byte abs(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6795,7 +6845,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6811,7 +6861,7 @@ public class ByteVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6891,7 +6941,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static long ADDReduceLong(byte[] a, int idx) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6900,7 +6950,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static long ADDReduceAllLong(byte[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((byte)res, (byte)ADDReduceLong(a, i)); } return res; @@ -6918,8 +6968,8 @@ public class ByteVector128Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6929,8 +6979,9 @@ public class ByteVector128Tests extends AbstractVectorTest { static long ADDReduceLongMasked(byte[] a, int idx, boolean[] mask) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6939,7 +6990,7 @@ public class ByteVector128Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(byte[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((byte)res, (byte)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6959,8 +7010,8 @@ public class ByteVector128Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/ByteVector256Tests.java b/test/jdk/jdk/incubator/vector/ByteVector256Tests.java index 1173a4b7783..5c32d4a7f74 100644 --- a/test/jdk/jdk/incubator/vector/ByteVector256Tests.java +++ b/test/jdk/jdk/incubator/vector/ByteVector256Tests.java @@ -1574,6 +1574,59 @@ public class ByteVector256Tests extends AbstractVectorTest { return a >= b; } + static byte firstNonZero(byte a, byte b) { + return Byte.compare(a, (byte) 0) != 0 ? a : b; + } + + static byte scalar_or(byte a, byte b) { + return (byte)(a | b); + } + + static byte scalar_and(byte a, byte b) { + return (byte)(a & b); + } + + static byte scalar_xor(byte a, byte b) { + return (byte)(a ^ b); + } + + static byte scalar_add(byte a, byte b) { + return (byte)(a + b); + } + + static byte scalar_sub(byte a, byte b) { + return (byte)(a - b); + } + + static byte scalar_mul(byte a, byte b) { + return (byte)(a * b); + } + + static byte scalar_min(byte a, byte b) { + return (byte)(Math.min(a, b)); + } + + static byte scalar_max(byte a, byte b) { + return (byte)(Math.max(a, b)); + } + + static byte scalar_div(byte a, byte b) { + return (byte)(a / b); + } + + static byte scalar_fma(byte a, byte b, byte c) { + return (byte)(Math.fma(a, b, c)); + } + + static byte scalar_abs(byte a) { + return (byte)(Math.abs(a)); + } + + static byte scalar_neg(byte a) { + return ((byte)-a); + } + + static boolean ult(byte a, byte b) { return Byte.compareUnsigned(a, b) < 0; } @@ -1590,9 +1643,6 @@ public class ByteVector256Tests extends AbstractVectorTest { return Byte.compareUnsigned(a, b) >= 0; } - static byte firstNonZero(byte a, byte b) { - return Byte.compare(a, (byte) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1701,7 +1751,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte ADD(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1722,7 +1772,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte add(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1779,7 +1829,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte SUB(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1800,7 +1850,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte sub(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1857,7 +1907,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte MUL(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1878,7 +1928,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte mul(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -2025,7 +2075,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte FIRST_NONZERO(byte a, byte b) { - return (byte)((a)!=0?a:b); + return (byte)(firstNonZero(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3239,7 +3289,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte MIN(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3260,7 +3310,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte min(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3279,7 +3329,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte MAX(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3300,7 +3350,7 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte max(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3668,7 +3718,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ANDReduce(byte[] a, int idx) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3677,7 +3727,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ANDReduceAll(byte[] a) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3695,7 +3745,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3708,20 +3758,20 @@ public class ByteVector256Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = AND_IDENTITY; - assertEquals((byte) (id & id), id, + assertEquals((byte) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id & x), x); - assertEquals((byte) (x & id), x); + assertEquals((byte) (scalar_and(id, x)), x); + assertEquals((byte) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id & x), x, + assertEquals((byte) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x & id), x, + assertEquals((byte) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3730,7 +3780,7 @@ public class ByteVector256Tests extends AbstractVectorTest { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3739,7 +3789,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3759,7 +3809,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3770,7 +3820,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ORReduce(byte[] a, int idx) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3779,7 +3829,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ORReduceAll(byte[] a) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3797,7 +3847,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3810,20 +3860,20 @@ public class ByteVector256Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = OR_IDENTITY; - assertEquals((byte) (id | id), id, + assertEquals((byte) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id | x), x); - assertEquals((byte) (x | id), x); + assertEquals((byte) (scalar_or(id, x)), x); + assertEquals((byte) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id | x), x, + assertEquals((byte) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x | id), x, + assertEquals((byte) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3832,7 +3882,7 @@ public class ByteVector256Tests extends AbstractVectorTest { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3841,7 +3891,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ORReduceAllMasked(byte[] a, boolean[] mask) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3861,7 +3911,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3872,7 +3922,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte XORReduce(byte[] a, int idx) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3881,7 +3931,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte XORReduceAll(byte[] a) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3899,7 +3949,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3912,20 +3962,20 @@ public class ByteVector256Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = XOR_IDENTITY; - assertEquals((byte) (id ^ id), id, + assertEquals((byte) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id ^ x), x); - assertEquals((byte) (x ^ id), x); + assertEquals((byte) (scalar_xor(id, x)), x); + assertEquals((byte) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id ^ x), x, + assertEquals((byte) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x ^ id), x, + assertEquals((byte) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3934,7 +3984,7 @@ public class ByteVector256Tests extends AbstractVectorTest { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3943,7 +3993,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte XORReduceAllMasked(byte[] a, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3963,7 +4013,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3974,7 +4024,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ADDReduce(byte[] a, int idx) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3983,7 +4033,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ADDReduceAll(byte[] a) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4001,7 +4051,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4014,20 +4064,20 @@ public class ByteVector256Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = ADD_IDENTITY; - assertEquals((byte) (id + id), id, + assertEquals((byte) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id + x), x); - assertEquals((byte) (x + id), x); + assertEquals((byte) (scalar_add(id, x)), x); + assertEquals((byte) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id + x), x, + assertEquals((byte) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x + id), x, + assertEquals((byte) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4036,7 +4086,7 @@ public class ByteVector256Tests extends AbstractVectorTest { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4045,7 +4095,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4065,7 +4115,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4076,7 +4126,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MULReduce(byte[] a, int idx) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4085,7 +4135,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MULReduceAll(byte[] a) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4103,7 +4153,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4116,20 +4166,20 @@ public class ByteVector256Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MUL_IDENTITY; - assertEquals((byte) (id * id), id, + assertEquals((byte) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id * x), x); - assertEquals((byte) (x * id), x); + assertEquals((byte) (scalar_mul(id, x)), x); + assertEquals((byte) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id * x), x, + assertEquals((byte) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x * id), x, + assertEquals((byte) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4138,7 +4188,7 @@ public class ByteVector256Tests extends AbstractVectorTest { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4147,7 +4197,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MULReduceAllMasked(byte[] a, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4167,7 +4217,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4178,7 +4228,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MINReduce(byte[] a, int idx) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4187,7 +4237,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MINReduceAll(byte[] a) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4205,7 +4255,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4218,20 +4268,20 @@ public class ByteVector256Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MIN_IDENTITY; - assertEquals((byte) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.min(id, x), x); - assertEquals((byte) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4240,7 +4290,7 @@ public class ByteVector256Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4249,7 +4299,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MINReduceAllMasked(byte[] a, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4269,7 +4319,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4280,7 +4330,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MAXReduce(byte[] a, int idx) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4289,7 +4339,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MAXReduceAll(byte[] a) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4307,7 +4357,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4320,20 +4370,20 @@ public class ByteVector256Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MAX_IDENTITY; - assertEquals((byte) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.max(id, x), x); - assertEquals((byte) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4342,7 +4392,7 @@ public class ByteVector256Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4351,7 +4401,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4371,7 +4421,7 @@ public class ByteVector256Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5404,7 +5454,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5424,7 +5474,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5440,7 +5490,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (byte)((long)b[i]))); } } } @@ -5460,7 +5510,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (byte)((long)b[i])))); } } } @@ -5476,7 +5526,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5496,7 +5546,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5512,7 +5562,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (byte)((long)b[i]))); } } } @@ -5532,7 +5582,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (byte)((long)b[i])))); } } } @@ -6244,11 +6294,11 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte NEG(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } static byte neg(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6300,11 +6350,11 @@ public class ByteVector256Tests extends AbstractVectorTest { } static byte ABS(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } static byte abs(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6795,7 +6845,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6811,7 +6861,7 @@ public class ByteVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6891,7 +6941,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static long ADDReduceLong(byte[] a, int idx) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6900,7 +6950,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static long ADDReduceAllLong(byte[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((byte)res, (byte)ADDReduceLong(a, i)); } return res; @@ -6918,8 +6968,8 @@ public class ByteVector256Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6929,8 +6979,9 @@ public class ByteVector256Tests extends AbstractVectorTest { static long ADDReduceLongMasked(byte[] a, int idx, boolean[] mask) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6939,7 +6990,7 @@ public class ByteVector256Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(byte[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((byte)res, (byte)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6959,8 +7010,8 @@ public class ByteVector256Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/ByteVector512Tests.java b/test/jdk/jdk/incubator/vector/ByteVector512Tests.java index 02da1889dc8..094f3bbebdc 100644 --- a/test/jdk/jdk/incubator/vector/ByteVector512Tests.java +++ b/test/jdk/jdk/incubator/vector/ByteVector512Tests.java @@ -1574,6 +1574,59 @@ public class ByteVector512Tests extends AbstractVectorTest { return a >= b; } + static byte firstNonZero(byte a, byte b) { + return Byte.compare(a, (byte) 0) != 0 ? a : b; + } + + static byte scalar_or(byte a, byte b) { + return (byte)(a | b); + } + + static byte scalar_and(byte a, byte b) { + return (byte)(a & b); + } + + static byte scalar_xor(byte a, byte b) { + return (byte)(a ^ b); + } + + static byte scalar_add(byte a, byte b) { + return (byte)(a + b); + } + + static byte scalar_sub(byte a, byte b) { + return (byte)(a - b); + } + + static byte scalar_mul(byte a, byte b) { + return (byte)(a * b); + } + + static byte scalar_min(byte a, byte b) { + return (byte)(Math.min(a, b)); + } + + static byte scalar_max(byte a, byte b) { + return (byte)(Math.max(a, b)); + } + + static byte scalar_div(byte a, byte b) { + return (byte)(a / b); + } + + static byte scalar_fma(byte a, byte b, byte c) { + return (byte)(Math.fma(a, b, c)); + } + + static byte scalar_abs(byte a) { + return (byte)(Math.abs(a)); + } + + static byte scalar_neg(byte a) { + return ((byte)-a); + } + + static boolean ult(byte a, byte b) { return Byte.compareUnsigned(a, b) < 0; } @@ -1590,9 +1643,6 @@ public class ByteVector512Tests extends AbstractVectorTest { return Byte.compareUnsigned(a, b) >= 0; } - static byte firstNonZero(byte a, byte b) { - return Byte.compare(a, (byte) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1701,7 +1751,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte ADD(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1722,7 +1772,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte add(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1779,7 +1829,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte SUB(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1800,7 +1850,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte sub(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1857,7 +1907,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte MUL(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1878,7 +1928,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte mul(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -2025,7 +2075,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte FIRST_NONZERO(byte a, byte b) { - return (byte)((a)!=0?a:b); + return (byte)(firstNonZero(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3239,7 +3289,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte MIN(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3260,7 +3310,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte min(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3279,7 +3329,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte MAX(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3300,7 +3350,7 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte max(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3668,7 +3718,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ANDReduce(byte[] a, int idx) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3677,7 +3727,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ANDReduceAll(byte[] a) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3695,7 +3745,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3708,20 +3758,20 @@ public class ByteVector512Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = AND_IDENTITY; - assertEquals((byte) (id & id), id, + assertEquals((byte) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id & x), x); - assertEquals((byte) (x & id), x); + assertEquals((byte) (scalar_and(id, x)), x); + assertEquals((byte) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id & x), x, + assertEquals((byte) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x & id), x, + assertEquals((byte) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3730,7 +3780,7 @@ public class ByteVector512Tests extends AbstractVectorTest { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3739,7 +3789,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3759,7 +3809,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3770,7 +3820,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ORReduce(byte[] a, int idx) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3779,7 +3829,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ORReduceAll(byte[] a) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3797,7 +3847,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3810,20 +3860,20 @@ public class ByteVector512Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = OR_IDENTITY; - assertEquals((byte) (id | id), id, + assertEquals((byte) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id | x), x); - assertEquals((byte) (x | id), x); + assertEquals((byte) (scalar_or(id, x)), x); + assertEquals((byte) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id | x), x, + assertEquals((byte) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x | id), x, + assertEquals((byte) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3832,7 +3882,7 @@ public class ByteVector512Tests extends AbstractVectorTest { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3841,7 +3891,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ORReduceAllMasked(byte[] a, boolean[] mask) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3861,7 +3911,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3872,7 +3922,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte XORReduce(byte[] a, int idx) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3881,7 +3931,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte XORReduceAll(byte[] a) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3899,7 +3949,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3912,20 +3962,20 @@ public class ByteVector512Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = XOR_IDENTITY; - assertEquals((byte) (id ^ id), id, + assertEquals((byte) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id ^ x), x); - assertEquals((byte) (x ^ id), x); + assertEquals((byte) (scalar_xor(id, x)), x); + assertEquals((byte) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id ^ x), x, + assertEquals((byte) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x ^ id), x, + assertEquals((byte) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3934,7 +3984,7 @@ public class ByteVector512Tests extends AbstractVectorTest { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3943,7 +3993,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte XORReduceAllMasked(byte[] a, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3963,7 +4013,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3974,7 +4024,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ADDReduce(byte[] a, int idx) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3983,7 +4033,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ADDReduceAll(byte[] a) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4001,7 +4051,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4014,20 +4064,20 @@ public class ByteVector512Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = ADD_IDENTITY; - assertEquals((byte) (id + id), id, + assertEquals((byte) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id + x), x); - assertEquals((byte) (x + id), x); + assertEquals((byte) (scalar_add(id, x)), x); + assertEquals((byte) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id + x), x, + assertEquals((byte) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x + id), x, + assertEquals((byte) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4036,7 +4086,7 @@ public class ByteVector512Tests extends AbstractVectorTest { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4045,7 +4095,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4065,7 +4115,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4076,7 +4126,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MULReduce(byte[] a, int idx) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4085,7 +4135,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MULReduceAll(byte[] a) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4103,7 +4153,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4116,20 +4166,20 @@ public class ByteVector512Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MUL_IDENTITY; - assertEquals((byte) (id * id), id, + assertEquals((byte) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id * x), x); - assertEquals((byte) (x * id), x); + assertEquals((byte) (scalar_mul(id, x)), x); + assertEquals((byte) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id * x), x, + assertEquals((byte) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x * id), x, + assertEquals((byte) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4138,7 +4188,7 @@ public class ByteVector512Tests extends AbstractVectorTest { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4147,7 +4197,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MULReduceAllMasked(byte[] a, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4167,7 +4217,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4178,7 +4228,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MINReduce(byte[] a, int idx) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4187,7 +4237,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MINReduceAll(byte[] a) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4205,7 +4255,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4218,20 +4268,20 @@ public class ByteVector512Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MIN_IDENTITY; - assertEquals((byte) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.min(id, x), x); - assertEquals((byte) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4240,7 +4290,7 @@ public class ByteVector512Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4249,7 +4299,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MINReduceAllMasked(byte[] a, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4269,7 +4319,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4280,7 +4330,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MAXReduce(byte[] a, int idx) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4289,7 +4339,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MAXReduceAll(byte[] a) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4307,7 +4357,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4320,20 +4370,20 @@ public class ByteVector512Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MAX_IDENTITY; - assertEquals((byte) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.max(id, x), x); - assertEquals((byte) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4342,7 +4392,7 @@ public class ByteVector512Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4351,7 +4401,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4371,7 +4421,7 @@ public class ByteVector512Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5404,7 +5454,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5424,7 +5474,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5440,7 +5490,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (byte)((long)b[i]))); } } } @@ -5460,7 +5510,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (byte)((long)b[i])))); } } } @@ -5476,7 +5526,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5496,7 +5546,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5512,7 +5562,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (byte)((long)b[i]))); } } } @@ -5532,7 +5582,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (byte)((long)b[i])))); } } } @@ -6244,11 +6294,11 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte NEG(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } static byte neg(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6300,11 +6350,11 @@ public class ByteVector512Tests extends AbstractVectorTest { } static byte ABS(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } static byte abs(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6795,7 +6845,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6811,7 +6861,7 @@ public class ByteVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6891,7 +6941,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static long ADDReduceLong(byte[] a, int idx) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6900,7 +6950,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static long ADDReduceAllLong(byte[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((byte)res, (byte)ADDReduceLong(a, i)); } return res; @@ -6918,8 +6968,8 @@ public class ByteVector512Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6929,8 +6979,9 @@ public class ByteVector512Tests extends AbstractVectorTest { static long ADDReduceLongMasked(byte[] a, int idx, boolean[] mask) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6939,7 +6990,7 @@ public class ByteVector512Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(byte[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((byte)res, (byte)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6959,8 +7010,8 @@ public class ByteVector512Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/ByteVector64Tests.java b/test/jdk/jdk/incubator/vector/ByteVector64Tests.java index ce671440d2e..e8ff81678cd 100644 --- a/test/jdk/jdk/incubator/vector/ByteVector64Tests.java +++ b/test/jdk/jdk/incubator/vector/ByteVector64Tests.java @@ -1574,6 +1574,59 @@ public class ByteVector64Tests extends AbstractVectorTest { return a >= b; } + static byte firstNonZero(byte a, byte b) { + return Byte.compare(a, (byte) 0) != 0 ? a : b; + } + + static byte scalar_or(byte a, byte b) { + return (byte)(a | b); + } + + static byte scalar_and(byte a, byte b) { + return (byte)(a & b); + } + + static byte scalar_xor(byte a, byte b) { + return (byte)(a ^ b); + } + + static byte scalar_add(byte a, byte b) { + return (byte)(a + b); + } + + static byte scalar_sub(byte a, byte b) { + return (byte)(a - b); + } + + static byte scalar_mul(byte a, byte b) { + return (byte)(a * b); + } + + static byte scalar_min(byte a, byte b) { + return (byte)(Math.min(a, b)); + } + + static byte scalar_max(byte a, byte b) { + return (byte)(Math.max(a, b)); + } + + static byte scalar_div(byte a, byte b) { + return (byte)(a / b); + } + + static byte scalar_fma(byte a, byte b, byte c) { + return (byte)(Math.fma(a, b, c)); + } + + static byte scalar_abs(byte a) { + return (byte)(Math.abs(a)); + } + + static byte scalar_neg(byte a) { + return ((byte)-a); + } + + static boolean ult(byte a, byte b) { return Byte.compareUnsigned(a, b) < 0; } @@ -1590,9 +1643,6 @@ public class ByteVector64Tests extends AbstractVectorTest { return Byte.compareUnsigned(a, b) >= 0; } - static byte firstNonZero(byte a, byte b) { - return Byte.compare(a, (byte) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1701,7 +1751,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte ADD(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1722,7 +1772,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte add(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1779,7 +1829,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte SUB(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1800,7 +1850,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte sub(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1857,7 +1907,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte MUL(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1878,7 +1928,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte mul(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -2025,7 +2075,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte FIRST_NONZERO(byte a, byte b) { - return (byte)((a)!=0?a:b); + return (byte)(firstNonZero(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3239,7 +3289,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte MIN(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3260,7 +3310,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte min(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3279,7 +3329,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte MAX(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3300,7 +3350,7 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte max(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3668,7 +3718,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ANDReduce(byte[] a, int idx) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3677,7 +3727,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ANDReduceAll(byte[] a) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3695,7 +3745,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3708,20 +3758,20 @@ public class ByteVector64Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = AND_IDENTITY; - assertEquals((byte) (id & id), id, + assertEquals((byte) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id & x), x); - assertEquals((byte) (x & id), x); + assertEquals((byte) (scalar_and(id, x)), x); + assertEquals((byte) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id & x), x, + assertEquals((byte) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x & id), x, + assertEquals((byte) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3730,7 +3780,7 @@ public class ByteVector64Tests extends AbstractVectorTest { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3739,7 +3789,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3759,7 +3809,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3770,7 +3820,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ORReduce(byte[] a, int idx) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3779,7 +3829,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ORReduceAll(byte[] a) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3797,7 +3847,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3810,20 +3860,20 @@ public class ByteVector64Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = OR_IDENTITY; - assertEquals((byte) (id | id), id, + assertEquals((byte) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id | x), x); - assertEquals((byte) (x | id), x); + assertEquals((byte) (scalar_or(id, x)), x); + assertEquals((byte) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id | x), x, + assertEquals((byte) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x | id), x, + assertEquals((byte) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3832,7 +3882,7 @@ public class ByteVector64Tests extends AbstractVectorTest { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3841,7 +3891,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ORReduceAllMasked(byte[] a, boolean[] mask) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3861,7 +3911,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3872,7 +3922,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte XORReduce(byte[] a, int idx) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3881,7 +3931,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte XORReduceAll(byte[] a) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3899,7 +3949,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3912,20 +3962,20 @@ public class ByteVector64Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = XOR_IDENTITY; - assertEquals((byte) (id ^ id), id, + assertEquals((byte) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id ^ x), x); - assertEquals((byte) (x ^ id), x); + assertEquals((byte) (scalar_xor(id, x)), x); + assertEquals((byte) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id ^ x), x, + assertEquals((byte) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x ^ id), x, + assertEquals((byte) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3934,7 +3984,7 @@ public class ByteVector64Tests extends AbstractVectorTest { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3943,7 +3993,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte XORReduceAllMasked(byte[] a, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3963,7 +4013,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3974,7 +4024,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ADDReduce(byte[] a, int idx) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3983,7 +4033,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ADDReduceAll(byte[] a) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4001,7 +4051,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4014,20 +4064,20 @@ public class ByteVector64Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = ADD_IDENTITY; - assertEquals((byte) (id + id), id, + assertEquals((byte) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id + x), x); - assertEquals((byte) (x + id), x); + assertEquals((byte) (scalar_add(id, x)), x); + assertEquals((byte) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id + x), x, + assertEquals((byte) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x + id), x, + assertEquals((byte) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4036,7 +4086,7 @@ public class ByteVector64Tests extends AbstractVectorTest { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4045,7 +4095,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4065,7 +4115,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4076,7 +4126,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MULReduce(byte[] a, int idx) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4085,7 +4135,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MULReduceAll(byte[] a) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4103,7 +4153,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4116,20 +4166,20 @@ public class ByteVector64Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MUL_IDENTITY; - assertEquals((byte) (id * id), id, + assertEquals((byte) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id * x), x); - assertEquals((byte) (x * id), x); + assertEquals((byte) (scalar_mul(id, x)), x); + assertEquals((byte) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id * x), x, + assertEquals((byte) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x * id), x, + assertEquals((byte) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4138,7 +4188,7 @@ public class ByteVector64Tests extends AbstractVectorTest { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4147,7 +4197,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MULReduceAllMasked(byte[] a, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4167,7 +4217,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4178,7 +4228,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MINReduce(byte[] a, int idx) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4187,7 +4237,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MINReduceAll(byte[] a) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4205,7 +4255,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4218,20 +4268,20 @@ public class ByteVector64Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MIN_IDENTITY; - assertEquals((byte) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.min(id, x), x); - assertEquals((byte) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4240,7 +4290,7 @@ public class ByteVector64Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4249,7 +4299,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MINReduceAllMasked(byte[] a, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4269,7 +4319,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4280,7 +4330,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MAXReduce(byte[] a, int idx) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4289,7 +4339,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MAXReduceAll(byte[] a) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4307,7 +4357,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4320,20 +4370,20 @@ public class ByteVector64Tests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MAX_IDENTITY; - assertEquals((byte) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.max(id, x), x); - assertEquals((byte) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4342,7 +4392,7 @@ public class ByteVector64Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4351,7 +4401,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4371,7 +4421,7 @@ public class ByteVector64Tests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5404,7 +5454,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5424,7 +5474,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5440,7 +5490,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (byte)((long)b[i]))); } } } @@ -5460,7 +5510,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (byte)((long)b[i])))); } } } @@ -5476,7 +5526,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5496,7 +5546,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5512,7 +5562,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (byte)((long)b[i]))); } } } @@ -5532,7 +5582,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (byte)((long)b[i])))); } } } @@ -6244,11 +6294,11 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte NEG(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } static byte neg(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6300,11 +6350,11 @@ public class ByteVector64Tests extends AbstractVectorTest { } static byte ABS(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } static byte abs(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6795,7 +6845,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6811,7 +6861,7 @@ public class ByteVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6891,7 +6941,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static long ADDReduceLong(byte[] a, int idx) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6900,7 +6950,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static long ADDReduceAllLong(byte[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((byte)res, (byte)ADDReduceLong(a, i)); } return res; @@ -6918,8 +6968,8 @@ public class ByteVector64Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6929,8 +6979,9 @@ public class ByteVector64Tests extends AbstractVectorTest { static long ADDReduceLongMasked(byte[] a, int idx, boolean[] mask) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6939,7 +6990,7 @@ public class ByteVector64Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(byte[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((byte)res, (byte)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6959,8 +7010,8 @@ public class ByteVector64Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/ByteVectorMaxTests.java b/test/jdk/jdk/incubator/vector/ByteVectorMaxTests.java index c2d8188c090..c53710c3fdd 100644 --- a/test/jdk/jdk/incubator/vector/ByteVectorMaxTests.java +++ b/test/jdk/jdk/incubator/vector/ByteVectorMaxTests.java @@ -1580,6 +1580,59 @@ public class ByteVectorMaxTests extends AbstractVectorTest { return a >= b; } + static byte firstNonZero(byte a, byte b) { + return Byte.compare(a, (byte) 0) != 0 ? a : b; + } + + static byte scalar_or(byte a, byte b) { + return (byte)(a | b); + } + + static byte scalar_and(byte a, byte b) { + return (byte)(a & b); + } + + static byte scalar_xor(byte a, byte b) { + return (byte)(a ^ b); + } + + static byte scalar_add(byte a, byte b) { + return (byte)(a + b); + } + + static byte scalar_sub(byte a, byte b) { + return (byte)(a - b); + } + + static byte scalar_mul(byte a, byte b) { + return (byte)(a * b); + } + + static byte scalar_min(byte a, byte b) { + return (byte)(Math.min(a, b)); + } + + static byte scalar_max(byte a, byte b) { + return (byte)(Math.max(a, b)); + } + + static byte scalar_div(byte a, byte b) { + return (byte)(a / b); + } + + static byte scalar_fma(byte a, byte b, byte c) { + return (byte)(Math.fma(a, b, c)); + } + + static byte scalar_abs(byte a) { + return (byte)(Math.abs(a)); + } + + static byte scalar_neg(byte a) { + return ((byte)-a); + } + + static boolean ult(byte a, byte b) { return Byte.compareUnsigned(a, b) < 0; } @@ -1596,9 +1649,6 @@ public class ByteVectorMaxTests extends AbstractVectorTest { return Byte.compareUnsigned(a, b) >= 0; } - static byte firstNonZero(byte a, byte b) { - return Byte.compare(a, (byte) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1707,7 +1757,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte ADD(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1728,7 +1778,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte add(byte a, byte b) { - return (byte)(a + b); + return (byte)(scalar_add(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1785,7 +1835,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte SUB(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1806,7 +1856,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte sub(byte a, byte b) { - return (byte)(a - b); + return (byte)(scalar_sub(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1863,7 +1913,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte MUL(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -1884,7 +1934,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte mul(byte a, byte b) { - return (byte)(a * b); + return (byte)(scalar_mul(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -2031,7 +2081,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte FIRST_NONZERO(byte a, byte b) { - return (byte)((a)!=0?a:b); + return (byte)(firstNonZero(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3245,7 +3295,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte MIN(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3266,7 +3316,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte min(byte a, byte b) { - return (byte)(Math.min(a, b)); + return (byte)(scalar_min(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3285,7 +3335,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte MAX(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3306,7 +3356,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte max(byte a, byte b) { - return (byte)(Math.max(a, b)); + return (byte)(scalar_max(a, b)); } @Test(dataProvider = "byteBinaryOpProvider") @@ -3674,7 +3724,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ANDReduce(byte[] a, int idx) { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3683,7 +3733,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ANDReduceAll(byte[] a) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3701,7 +3751,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3714,20 +3764,20 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = AND_IDENTITY; - assertEquals((byte) (id & id), id, + assertEquals((byte) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id & x), x); - assertEquals((byte) (x & id), x); + assertEquals((byte) (scalar_and(id, x)), x); + assertEquals((byte) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id & x), x, + assertEquals((byte) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x & id), x, + assertEquals((byte) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3736,7 +3786,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3745,7 +3795,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { byte res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3765,7 +3815,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3776,7 +3826,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ORReduce(byte[] a, int idx) { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3785,7 +3835,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ORReduceAll(byte[] a) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3803,7 +3853,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3816,20 +3866,20 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = OR_IDENTITY; - assertEquals((byte) (id | id), id, + assertEquals((byte) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id | x), x); - assertEquals((byte) (x | id), x); + assertEquals((byte) (scalar_or(id, x)), x); + assertEquals((byte) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id | x), x, + assertEquals((byte) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x | id), x, + assertEquals((byte) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3838,7 +3888,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3847,7 +3897,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ORReduceAllMasked(byte[] a, boolean[] mask) { byte res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3867,7 +3917,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3878,7 +3928,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte XORReduce(byte[] a, int idx) { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3887,7 +3937,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte XORReduceAll(byte[] a) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3905,7 +3955,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3918,20 +3968,20 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = XOR_IDENTITY; - assertEquals((byte) (id ^ id), id, + assertEquals((byte) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id ^ x), x); - assertEquals((byte) (x ^ id), x); + assertEquals((byte) (scalar_xor(id, x)), x); + assertEquals((byte) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id ^ x), x, + assertEquals((byte) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x ^ id), x, + assertEquals((byte) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3940,7 +3990,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3949,7 +3999,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte XORReduceAllMasked(byte[] a, boolean[] mask) { byte res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3969,7 +4019,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3980,7 +4030,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ADDReduce(byte[] a, int idx) { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3989,7 +4039,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ADDReduceAll(byte[] a) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4007,7 +4057,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4020,20 +4070,20 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = ADD_IDENTITY; - assertEquals((byte) (id + id), id, + assertEquals((byte) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id + x), x); - assertEquals((byte) (x + id), x); + assertEquals((byte) (scalar_add(id, x)), x); + assertEquals((byte) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id + x), x, + assertEquals((byte) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x + id), x, + assertEquals((byte) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4042,7 +4092,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4051,7 +4101,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { byte res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4071,7 +4121,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4082,7 +4132,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MULReduce(byte[] a, int idx) { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4091,7 +4141,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MULReduceAll(byte[] a) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4109,7 +4159,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4122,20 +4172,20 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MUL_IDENTITY; - assertEquals((byte) (id * id), id, + assertEquals((byte) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) (id * x), x); - assertEquals((byte) (x * id), x); + assertEquals((byte) (scalar_mul(id, x)), x); + assertEquals((byte) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((byte) (id * x), x, + assertEquals((byte) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((byte) (x * id), x, + assertEquals((byte) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4144,7 +4194,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4153,7 +4203,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MULReduceAllMasked(byte[] a, boolean[] mask) { byte res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4173,7 +4223,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4184,7 +4234,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MINReduce(byte[] a, int idx) { byte res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4193,7 +4243,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MINReduceAll(byte[] a) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4211,7 +4261,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4224,20 +4274,20 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MIN_IDENTITY; - assertEquals((byte) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.min(id, x), x); - assertEquals((byte) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4246,7 +4296,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4255,7 +4305,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MINReduceAllMasked(byte[] a, boolean[] mask) { byte res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4275,7 +4325,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (byte) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4286,7 +4336,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MAXReduce(byte[] a, int idx) { byte res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (byte) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4295,7 +4345,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MAXReduceAll(byte[] a) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4313,7 +4363,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4326,20 +4376,20 @@ public class ByteVectorMaxTests extends AbstractVectorTest { byte[] a = fa.apply(SPECIES.length()); byte id = MAX_IDENTITY; - assertEquals((byte) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); byte x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((byte) Math.max(id, x), x); - assertEquals((byte) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((byte) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((byte) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4348,7 +4398,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4357,7 +4407,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { byte res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4377,7 +4427,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { ByteVector av = ByteVector.fromArray(SPECIES, a, i); byte v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (byte) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5410,7 +5460,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5430,7 +5480,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5446,7 +5496,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (byte)((long)b[i]))); } } } @@ -5466,7 +5516,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (byte)((long)b[i])))); } } } @@ -5482,7 +5532,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5502,7 +5552,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5518,7 +5568,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (byte)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (byte)((long)b[i]))); } } } @@ -5538,7 +5588,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (byte)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (byte)((long)b[i])))); } } } @@ -6250,11 +6300,11 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte NEG(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } static byte neg(byte a) { - return (byte)(-((byte)a)); + return (byte)(scalar_neg((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6306,11 +6356,11 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } static byte ABS(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } static byte abs(byte a) { - return (byte)(Math.abs((byte)a)); + return (byte)(scalar_abs((byte)a)); } @Test(dataProvider = "byteUnaryOpProvider") @@ -6801,7 +6851,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6817,7 +6867,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6897,7 +6947,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static long ADDReduceLong(byte[] a, int idx) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6906,7 +6956,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static long ADDReduceAllLong(byte[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((byte)res, (byte)ADDReduceLong(a, i)); } return res; @@ -6924,8 +6974,8 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6935,8 +6985,9 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static long ADDReduceLongMasked(byte[] a, int idx, boolean[] mask) { byte res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6945,7 +6996,7 @@ public class ByteVectorMaxTests extends AbstractVectorTest { static long ADDReduceAllLongMasked(byte[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((byte)res, (byte)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6965,8 +7016,8 @@ public class ByteVectorMaxTests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((byte)ra, (byte)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/DoubleVector128Tests.java b/test/jdk/jdk/incubator/vector/DoubleVector128Tests.java index 7b4b587b142..1457e5a51ca 100644 --- a/test/jdk/jdk/incubator/vector/DoubleVector128Tests.java +++ b/test/jdk/jdk/incubator/vector/DoubleVector128Tests.java @@ -1584,6 +1584,205 @@ relativeError)); return Double.compare(a, (double) 0) != 0 ? a : b; } + + static double scalar_add(double a, double b) { + return (double)(a + b); + } + + static double scalar_sub(double a, double b) { + return (double)(a - b); + } + + static double scalar_mul(double a, double b) { + return (double)(a * b); + } + + static double scalar_min(double a, double b) { + return (double)(Math.min(a, b)); + } + + static double scalar_max(double a, double b) { + return (double)(Math.max(a, b)); + } + + static double scalar_div(double a, double b) { + return (double)(a / b); + } + + static double scalar_fma(double a, double b, double c) { + return (double)(Math.fma(a, b, c)); + } + + static double scalar_abs(double a) { + return (double)(Math.abs(a)); + } + + static double scalar_neg(double a) { + return ((double)-a); + } + + static double scalar_sin(double a) { + return (double)Math.sin((double)a); + } + + static double scalar_exp(double a) { + return (double)Math.exp((double)a); + } + + static double scalar_log1p(double a) { + return (double)Math.log1p((double)a); + } + + static double scalar_log(double a) { + return (double)Math.log((double)a); + } + + static double scalar_log10(double a) { + return (double)Math.log10((double)a); + } + + static double scalar_expm1(double a) { + return (double)Math.expm1((double)a); + } + + static double scalar_cos(double a) { + return (double)Math.cos((double)a); + } + + static double scalar_tan(double a) { + return (double)Math.tan((double)a); + } + + static double scalar_sinh(double a) { + return (double)Math.sinh((double)a); + } + + static double scalar_cosh(double a) { + return (double)Math.cosh((double)a); + } + + static double scalar_tanh(double a) { + return (double)Math.tanh((double)a); + } + + static double scalar_asin(double a) { + return (double)Math.asin((double)a); + } + + static double scalar_acos(double a) { + return (double)Math.acos((double)a); + } + + static double scalar_atan(double a) { + return (double)Math.atan((double)a); + } + + static double scalar_cbrt(double a) { + return (double)Math.cbrt((double)a); + } + + static double scalar_sqrt(double a) { + return (double)Math.sqrt((double)a); + } + + static double scalar_hypot(double a, double b) { + return (double)Math.hypot((double)a, (double)b); + } + + static double scalar_pow(double a, double b) { + return (double)Math.pow((double)a, (double)b); + } + + static double scalar_atan2(double a, double b) { + return (double)Math.atan2((double)a, (double)b); + } + + static double strict_scalar_sin(double a) { + return (double)StrictMath.sin((double)a); + } + + static double strict_scalar_exp(double a) { + return (double)StrictMath.exp((double)a); + } + + static double strict_scalar_log1p(double a) { + return (double)StrictMath.log1p((double)a); + } + + static double strict_scalar_log(double a) { + return (double)StrictMath.log((double)a); + } + + static double strict_scalar_log10(double a) { + return (double)StrictMath.log10((double)a); + } + + static double strict_scalar_expm1(double a) { + return (double)StrictMath.expm1((double)a); + } + + static double strict_scalar_cos(double a) { + return (double)StrictMath.cos((double)a); + } + + static double strict_scalar_tan(double a) { + return (double)StrictMath.tan((double)a); + } + + static double strict_scalar_sinh(double a) { + return (double)StrictMath.sinh((double)a); + } + + static double strict_scalar_cosh(double a) { + return (double)StrictMath.cosh((double)a); + } + + static double strict_scalar_tanh(double a) { + return (double)StrictMath.tanh((double)a); + } + + static double strict_scalar_asin(double a) { + return (double)StrictMath.asin((double)a); + } + + static double strict_scalar_acos(double a) { + return (double)StrictMath.acos((double)a); + } + + static double strict_scalar_atan(double a) { + return (double)StrictMath.atan((double)a); + } + + static double strict_scalar_cbrt(double a) { + return (double)StrictMath.cbrt((double)a); + } + + static double strict_scalar_sqrt(double a) { + return (double)StrictMath.sqrt((double)a); + } + + static double strict_scalar_hypot(double a, double b) { + return (double)StrictMath.hypot((double)a, (double)b); + } + + static double strict_scalar_pow(double a, double b) { + return (double)StrictMath.pow((double)a, (double)b); + } + + static double strict_scalar_atan2(double a, double b) { + return (double)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(double a) { + return Double.isNaN(a); + } + static boolean isFinite(double a) { + return Double.isFinite(a); + } + static boolean isInfinite(double a) { + return Double.isInfinite(a); + } + @Test static void smokeTest1() { DoubleVector three = DoubleVector.broadcast(SPECIES, (byte)-3); @@ -1677,7 +1876,7 @@ relativeError)); } static double ADD(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1698,7 +1897,7 @@ relativeError)); } static double add(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1755,7 +1954,7 @@ relativeError)); } static double SUB(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1776,7 +1975,7 @@ relativeError)); } static double sub(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1833,7 +2032,7 @@ relativeError)); } static double MUL(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1854,7 +2053,7 @@ relativeError)); } static double mul(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1911,7 +2110,7 @@ relativeError)); } static double DIV(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1932,7 +2131,7 @@ relativeError)); } static double div(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1989,7 +2188,7 @@ relativeError)); } static double FIRST_NONZERO(double a, double b) { - return (double)(Double.doubleToLongBits(a)!=0?a:b); + return (double)(firstNonZero(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2291,7 +2490,7 @@ relativeError)); } static double MIN(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2312,7 +2511,7 @@ relativeError)); } static double min(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2331,7 +2530,7 @@ relativeError)); } static double MAX(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2352,7 +2551,7 @@ relativeError)); } static double max(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2429,7 +2628,7 @@ relativeError)); static double ADDReduce(double[] a, int idx) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2438,7 +2637,7 @@ relativeError)); static double ADDReduceAll(double[] a) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2456,7 +2655,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2469,20 +2668,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = ADD_IDENTITY; - assertEquals((double) (id + id), id, + assertEquals((double) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id + x), x); - assertEquals((double) (x + id), x); + assertEquals((double) (scalar_add(id, x)), x); + assertEquals((double) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id + x), x, + assertEquals((double) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x + id), x, + assertEquals((double) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2491,7 +2690,7 @@ relativeError)); double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2500,7 +2699,7 @@ relativeError)); static double ADDReduceAllMasked(double[] a, boolean[] mask) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2520,7 +2719,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2531,7 +2730,7 @@ relativeError)); static double MULReduce(double[] a, int idx) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2540,7 +2739,7 @@ relativeError)); static double MULReduceAll(double[] a) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2558,7 +2757,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2571,20 +2770,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MUL_IDENTITY; - assertEquals((double) (id * id), id, + assertEquals((double) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id * x), x); - assertEquals((double) (x * id), x); + assertEquals((double) (scalar_mul(id, x)), x); + assertEquals((double) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id * x), x, + assertEquals((double) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x * id), x, + assertEquals((double) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2593,7 +2792,7 @@ relativeError)); double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2602,7 +2801,7 @@ relativeError)); static double MULReduceAllMasked(double[] a, boolean[] mask) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2622,7 +2821,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2633,7 +2832,7 @@ relativeError)); static double MINReduce(double[] a, int idx) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2642,7 +2841,7 @@ relativeError)); static double MINReduceAll(double[] a) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2660,7 +2859,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2673,20 +2872,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MIN_IDENTITY; - assertEquals((double) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.min(id, x), x); - assertEquals((double) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2695,7 +2894,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2704,7 +2903,7 @@ relativeError)); static double MINReduceAllMasked(double[] a, boolean[] mask) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2724,7 +2923,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2735,7 +2934,7 @@ relativeError)); static double MAXReduce(double[] a, int idx) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2744,7 +2943,7 @@ relativeError)); static double MAXReduceAll(double[] a) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2762,7 +2961,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2775,20 +2974,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MAX_IDENTITY; - assertEquals((double) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.max(id, x), x); - assertEquals((double) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2797,7 +2996,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2806,7 +3005,7 @@ relativeError)); static double MAXReduceAllMasked(double[] a, boolean[] mask) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2826,7 +3025,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3038,7 +3237,7 @@ relativeError)); } static boolean testIS_FINITE(double a) { - return Double.isFinite(a); + return isFinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3079,7 +3278,7 @@ relativeError)); } static boolean testIS_NAN(double a) { - return Double.isNaN(a); + return isNaN(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3120,7 +3319,7 @@ relativeError)); } static boolean testIS_INFINITE(double a) { - return Double.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3461,7 +3660,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3481,7 +3680,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3497,7 +3696,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (double)((long)b[i]))); } } } @@ -3517,7 +3716,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (double)((long)b[i])))); } } } @@ -3533,7 +3732,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3553,7 +3752,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3569,7 +3768,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (double)((long)b[i]))); } } } @@ -3589,7 +3788,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (double)((long)b[i])))); } } } @@ -4089,11 +4288,11 @@ relativeError)); } static double SIN(double a) { - return (double)(Math.sin((double)a)); + return (double)(scalar_sin(a)); } static double strictSIN(double a) { - return (double)(StrictMath.sin((double)a)); + return (double)(strict_scalar_sin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4112,11 +4311,11 @@ relativeError)); } static double EXP(double a) { - return (double)(Math.exp((double)a)); + return (double)(scalar_exp(a)); } static double strictEXP(double a) { - return (double)(StrictMath.exp((double)a)); + return (double)(strict_scalar_exp(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4135,11 +4334,11 @@ relativeError)); } static double LOG1P(double a) { - return (double)(Math.log1p((double)a)); + return (double)(scalar_log1p(a)); } static double strictLOG1P(double a) { - return (double)(StrictMath.log1p((double)a)); + return (double)(strict_scalar_log1p(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4158,11 +4357,11 @@ relativeError)); } static double LOG(double a) { - return (double)(Math.log((double)a)); + return (double)(scalar_log(a)); } static double strictLOG(double a) { - return (double)(StrictMath.log((double)a)); + return (double)(strict_scalar_log(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4181,11 +4380,11 @@ relativeError)); } static double LOG10(double a) { - return (double)(Math.log10((double)a)); + return (double)(scalar_log10(a)); } static double strictLOG10(double a) { - return (double)(StrictMath.log10((double)a)); + return (double)(strict_scalar_log10(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4204,11 +4403,11 @@ relativeError)); } static double EXPM1(double a) { - return (double)(Math.expm1((double)a)); + return (double)(scalar_expm1(a)); } static double strictEXPM1(double a) { - return (double)(StrictMath.expm1((double)a)); + return (double)(strict_scalar_expm1(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4227,11 +4426,11 @@ relativeError)); } static double COS(double a) { - return (double)(Math.cos((double)a)); + return (double)(scalar_cos(a)); } static double strictCOS(double a) { - return (double)(StrictMath.cos((double)a)); + return (double)(strict_scalar_cos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4250,11 +4449,11 @@ relativeError)); } static double TAN(double a) { - return (double)(Math.tan((double)a)); + return (double)(scalar_tan(a)); } static double strictTAN(double a) { - return (double)(StrictMath.tan((double)a)); + return (double)(strict_scalar_tan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4273,11 +4472,11 @@ relativeError)); } static double SINH(double a) { - return (double)(Math.sinh((double)a)); + return (double)(scalar_sinh(a)); } static double strictSINH(double a) { - return (double)(StrictMath.sinh((double)a)); + return (double)(strict_scalar_sinh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4296,11 +4495,11 @@ relativeError)); } static double COSH(double a) { - return (double)(Math.cosh((double)a)); + return (double)(scalar_cosh(a)); } static double strictCOSH(double a) { - return (double)(StrictMath.cosh((double)a)); + return (double)(strict_scalar_cosh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4319,11 +4518,11 @@ relativeError)); } static double TANH(double a) { - return (double)(Math.tanh((double)a)); + return (double)(scalar_tanh(a)); } static double strictTANH(double a) { - return (double)(StrictMath.tanh((double)a)); + return (double)(strict_scalar_tanh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4342,11 +4541,11 @@ relativeError)); } static double ASIN(double a) { - return (double)(Math.asin((double)a)); + return (double)(scalar_asin(a)); } static double strictASIN(double a) { - return (double)(StrictMath.asin((double)a)); + return (double)(strict_scalar_asin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4365,11 +4564,11 @@ relativeError)); } static double ACOS(double a) { - return (double)(Math.acos((double)a)); + return (double)(scalar_acos(a)); } static double strictACOS(double a) { - return (double)(StrictMath.acos((double)a)); + return (double)(strict_scalar_acos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4388,11 +4587,11 @@ relativeError)); } static double ATAN(double a) { - return (double)(Math.atan((double)a)); + return (double)(scalar_atan(a)); } static double strictATAN(double a) { - return (double)(StrictMath.atan((double)a)); + return (double)(strict_scalar_atan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4411,11 +4610,11 @@ relativeError)); } static double CBRT(double a) { - return (double)(Math.cbrt((double)a)); + return (double)(scalar_cbrt(a)); } static double strictCBRT(double a) { - return (double)(StrictMath.cbrt((double)a)); + return (double)(strict_scalar_cbrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4434,11 +4633,11 @@ relativeError)); } static double HYPOT(double a, double b) { - return (double)(Math.hypot((double)a, (double)b)); + return (double)(scalar_hypot(a, b)); } static double strictHYPOT(double a, double b) { - return (double)(StrictMath.hypot((double)a, (double)b)); + return (double)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4460,11 +4659,11 @@ relativeError)); static double POW(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictPOW(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4486,11 +4685,11 @@ relativeError)); static double pow(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictpow(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4512,11 +4711,11 @@ relativeError)); static double ATAN2(double a, double b) { - return (double)(Math.atan2((double)a, (double)b)); + return (double)(scalar_atan2(a, b)); } static double strictATAN2(double a, double b) { - return (double)(StrictMath.atan2((double)a, (double)b)); + return (double)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4568,11 +4767,11 @@ relativeError)); static double FMA(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } static double fma(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } @Test(dataProvider = "doubleTernaryOpProvider") @@ -4792,11 +4991,11 @@ relativeError)); } static double NEG(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } static double neg(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4848,11 +5047,11 @@ relativeError)); } static double ABS(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } static double abs(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4904,11 +5103,11 @@ relativeError)); } static double SQRT(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } static double sqrt(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -5121,7 +5320,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5137,7 +5336,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5196,7 +5395,7 @@ relativeError)); static long ADDReduceLong(double[] a, int idx) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5205,7 +5404,7 @@ relativeError)); static long ADDReduceAllLong(double[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((double)res, (double)ADDReduceLong(a, i)); } return res; @@ -5223,8 +5422,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5234,8 +5433,9 @@ relativeError)); static long ADDReduceLongMasked(double[] a, int idx, boolean[] mask) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5244,7 +5444,7 @@ relativeError)); static long ADDReduceAllLongMasked(double[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((double)res, (double)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5264,8 +5464,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/DoubleVector256Tests.java b/test/jdk/jdk/incubator/vector/DoubleVector256Tests.java index 4d650d7b407..e417abe52e6 100644 --- a/test/jdk/jdk/incubator/vector/DoubleVector256Tests.java +++ b/test/jdk/jdk/incubator/vector/DoubleVector256Tests.java @@ -1584,6 +1584,205 @@ relativeError)); return Double.compare(a, (double) 0) != 0 ? a : b; } + + static double scalar_add(double a, double b) { + return (double)(a + b); + } + + static double scalar_sub(double a, double b) { + return (double)(a - b); + } + + static double scalar_mul(double a, double b) { + return (double)(a * b); + } + + static double scalar_min(double a, double b) { + return (double)(Math.min(a, b)); + } + + static double scalar_max(double a, double b) { + return (double)(Math.max(a, b)); + } + + static double scalar_div(double a, double b) { + return (double)(a / b); + } + + static double scalar_fma(double a, double b, double c) { + return (double)(Math.fma(a, b, c)); + } + + static double scalar_abs(double a) { + return (double)(Math.abs(a)); + } + + static double scalar_neg(double a) { + return ((double)-a); + } + + static double scalar_sin(double a) { + return (double)Math.sin((double)a); + } + + static double scalar_exp(double a) { + return (double)Math.exp((double)a); + } + + static double scalar_log1p(double a) { + return (double)Math.log1p((double)a); + } + + static double scalar_log(double a) { + return (double)Math.log((double)a); + } + + static double scalar_log10(double a) { + return (double)Math.log10((double)a); + } + + static double scalar_expm1(double a) { + return (double)Math.expm1((double)a); + } + + static double scalar_cos(double a) { + return (double)Math.cos((double)a); + } + + static double scalar_tan(double a) { + return (double)Math.tan((double)a); + } + + static double scalar_sinh(double a) { + return (double)Math.sinh((double)a); + } + + static double scalar_cosh(double a) { + return (double)Math.cosh((double)a); + } + + static double scalar_tanh(double a) { + return (double)Math.tanh((double)a); + } + + static double scalar_asin(double a) { + return (double)Math.asin((double)a); + } + + static double scalar_acos(double a) { + return (double)Math.acos((double)a); + } + + static double scalar_atan(double a) { + return (double)Math.atan((double)a); + } + + static double scalar_cbrt(double a) { + return (double)Math.cbrt((double)a); + } + + static double scalar_sqrt(double a) { + return (double)Math.sqrt((double)a); + } + + static double scalar_hypot(double a, double b) { + return (double)Math.hypot((double)a, (double)b); + } + + static double scalar_pow(double a, double b) { + return (double)Math.pow((double)a, (double)b); + } + + static double scalar_atan2(double a, double b) { + return (double)Math.atan2((double)a, (double)b); + } + + static double strict_scalar_sin(double a) { + return (double)StrictMath.sin((double)a); + } + + static double strict_scalar_exp(double a) { + return (double)StrictMath.exp((double)a); + } + + static double strict_scalar_log1p(double a) { + return (double)StrictMath.log1p((double)a); + } + + static double strict_scalar_log(double a) { + return (double)StrictMath.log((double)a); + } + + static double strict_scalar_log10(double a) { + return (double)StrictMath.log10((double)a); + } + + static double strict_scalar_expm1(double a) { + return (double)StrictMath.expm1((double)a); + } + + static double strict_scalar_cos(double a) { + return (double)StrictMath.cos((double)a); + } + + static double strict_scalar_tan(double a) { + return (double)StrictMath.tan((double)a); + } + + static double strict_scalar_sinh(double a) { + return (double)StrictMath.sinh((double)a); + } + + static double strict_scalar_cosh(double a) { + return (double)StrictMath.cosh((double)a); + } + + static double strict_scalar_tanh(double a) { + return (double)StrictMath.tanh((double)a); + } + + static double strict_scalar_asin(double a) { + return (double)StrictMath.asin((double)a); + } + + static double strict_scalar_acos(double a) { + return (double)StrictMath.acos((double)a); + } + + static double strict_scalar_atan(double a) { + return (double)StrictMath.atan((double)a); + } + + static double strict_scalar_cbrt(double a) { + return (double)StrictMath.cbrt((double)a); + } + + static double strict_scalar_sqrt(double a) { + return (double)StrictMath.sqrt((double)a); + } + + static double strict_scalar_hypot(double a, double b) { + return (double)StrictMath.hypot((double)a, (double)b); + } + + static double strict_scalar_pow(double a, double b) { + return (double)StrictMath.pow((double)a, (double)b); + } + + static double strict_scalar_atan2(double a, double b) { + return (double)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(double a) { + return Double.isNaN(a); + } + static boolean isFinite(double a) { + return Double.isFinite(a); + } + static boolean isInfinite(double a) { + return Double.isInfinite(a); + } + @Test static void smokeTest1() { DoubleVector three = DoubleVector.broadcast(SPECIES, (byte)-3); @@ -1677,7 +1876,7 @@ relativeError)); } static double ADD(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1698,7 +1897,7 @@ relativeError)); } static double add(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1755,7 +1954,7 @@ relativeError)); } static double SUB(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1776,7 +1975,7 @@ relativeError)); } static double sub(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1833,7 +2032,7 @@ relativeError)); } static double MUL(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1854,7 +2053,7 @@ relativeError)); } static double mul(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1911,7 +2110,7 @@ relativeError)); } static double DIV(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1932,7 +2131,7 @@ relativeError)); } static double div(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1989,7 +2188,7 @@ relativeError)); } static double FIRST_NONZERO(double a, double b) { - return (double)(Double.doubleToLongBits(a)!=0?a:b); + return (double)(firstNonZero(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2291,7 +2490,7 @@ relativeError)); } static double MIN(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2312,7 +2511,7 @@ relativeError)); } static double min(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2331,7 +2530,7 @@ relativeError)); } static double MAX(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2352,7 +2551,7 @@ relativeError)); } static double max(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2429,7 +2628,7 @@ relativeError)); static double ADDReduce(double[] a, int idx) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2438,7 +2637,7 @@ relativeError)); static double ADDReduceAll(double[] a) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2456,7 +2655,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2469,20 +2668,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = ADD_IDENTITY; - assertEquals((double) (id + id), id, + assertEquals((double) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id + x), x); - assertEquals((double) (x + id), x); + assertEquals((double) (scalar_add(id, x)), x); + assertEquals((double) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id + x), x, + assertEquals((double) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x + id), x, + assertEquals((double) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2491,7 +2690,7 @@ relativeError)); double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2500,7 +2699,7 @@ relativeError)); static double ADDReduceAllMasked(double[] a, boolean[] mask) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2520,7 +2719,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2531,7 +2730,7 @@ relativeError)); static double MULReduce(double[] a, int idx) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2540,7 +2739,7 @@ relativeError)); static double MULReduceAll(double[] a) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2558,7 +2757,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2571,20 +2770,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MUL_IDENTITY; - assertEquals((double) (id * id), id, + assertEquals((double) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id * x), x); - assertEquals((double) (x * id), x); + assertEquals((double) (scalar_mul(id, x)), x); + assertEquals((double) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id * x), x, + assertEquals((double) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x * id), x, + assertEquals((double) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2593,7 +2792,7 @@ relativeError)); double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2602,7 +2801,7 @@ relativeError)); static double MULReduceAllMasked(double[] a, boolean[] mask) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2622,7 +2821,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2633,7 +2832,7 @@ relativeError)); static double MINReduce(double[] a, int idx) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2642,7 +2841,7 @@ relativeError)); static double MINReduceAll(double[] a) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2660,7 +2859,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2673,20 +2872,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MIN_IDENTITY; - assertEquals((double) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.min(id, x), x); - assertEquals((double) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2695,7 +2894,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2704,7 +2903,7 @@ relativeError)); static double MINReduceAllMasked(double[] a, boolean[] mask) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2724,7 +2923,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2735,7 +2934,7 @@ relativeError)); static double MAXReduce(double[] a, int idx) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2744,7 +2943,7 @@ relativeError)); static double MAXReduceAll(double[] a) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2762,7 +2961,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2775,20 +2974,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MAX_IDENTITY; - assertEquals((double) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.max(id, x), x); - assertEquals((double) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2797,7 +2996,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2806,7 +3005,7 @@ relativeError)); static double MAXReduceAllMasked(double[] a, boolean[] mask) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2826,7 +3025,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3038,7 +3237,7 @@ relativeError)); } static boolean testIS_FINITE(double a) { - return Double.isFinite(a); + return isFinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3079,7 +3278,7 @@ relativeError)); } static boolean testIS_NAN(double a) { - return Double.isNaN(a); + return isNaN(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3120,7 +3319,7 @@ relativeError)); } static boolean testIS_INFINITE(double a) { - return Double.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3461,7 +3660,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3481,7 +3680,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3497,7 +3696,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (double)((long)b[i]))); } } } @@ -3517,7 +3716,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (double)((long)b[i])))); } } } @@ -3533,7 +3732,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3553,7 +3752,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3569,7 +3768,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (double)((long)b[i]))); } } } @@ -3589,7 +3788,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (double)((long)b[i])))); } } } @@ -4089,11 +4288,11 @@ relativeError)); } static double SIN(double a) { - return (double)(Math.sin((double)a)); + return (double)(scalar_sin(a)); } static double strictSIN(double a) { - return (double)(StrictMath.sin((double)a)); + return (double)(strict_scalar_sin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4112,11 +4311,11 @@ relativeError)); } static double EXP(double a) { - return (double)(Math.exp((double)a)); + return (double)(scalar_exp(a)); } static double strictEXP(double a) { - return (double)(StrictMath.exp((double)a)); + return (double)(strict_scalar_exp(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4135,11 +4334,11 @@ relativeError)); } static double LOG1P(double a) { - return (double)(Math.log1p((double)a)); + return (double)(scalar_log1p(a)); } static double strictLOG1P(double a) { - return (double)(StrictMath.log1p((double)a)); + return (double)(strict_scalar_log1p(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4158,11 +4357,11 @@ relativeError)); } static double LOG(double a) { - return (double)(Math.log((double)a)); + return (double)(scalar_log(a)); } static double strictLOG(double a) { - return (double)(StrictMath.log((double)a)); + return (double)(strict_scalar_log(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4181,11 +4380,11 @@ relativeError)); } static double LOG10(double a) { - return (double)(Math.log10((double)a)); + return (double)(scalar_log10(a)); } static double strictLOG10(double a) { - return (double)(StrictMath.log10((double)a)); + return (double)(strict_scalar_log10(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4204,11 +4403,11 @@ relativeError)); } static double EXPM1(double a) { - return (double)(Math.expm1((double)a)); + return (double)(scalar_expm1(a)); } static double strictEXPM1(double a) { - return (double)(StrictMath.expm1((double)a)); + return (double)(strict_scalar_expm1(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4227,11 +4426,11 @@ relativeError)); } static double COS(double a) { - return (double)(Math.cos((double)a)); + return (double)(scalar_cos(a)); } static double strictCOS(double a) { - return (double)(StrictMath.cos((double)a)); + return (double)(strict_scalar_cos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4250,11 +4449,11 @@ relativeError)); } static double TAN(double a) { - return (double)(Math.tan((double)a)); + return (double)(scalar_tan(a)); } static double strictTAN(double a) { - return (double)(StrictMath.tan((double)a)); + return (double)(strict_scalar_tan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4273,11 +4472,11 @@ relativeError)); } static double SINH(double a) { - return (double)(Math.sinh((double)a)); + return (double)(scalar_sinh(a)); } static double strictSINH(double a) { - return (double)(StrictMath.sinh((double)a)); + return (double)(strict_scalar_sinh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4296,11 +4495,11 @@ relativeError)); } static double COSH(double a) { - return (double)(Math.cosh((double)a)); + return (double)(scalar_cosh(a)); } static double strictCOSH(double a) { - return (double)(StrictMath.cosh((double)a)); + return (double)(strict_scalar_cosh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4319,11 +4518,11 @@ relativeError)); } static double TANH(double a) { - return (double)(Math.tanh((double)a)); + return (double)(scalar_tanh(a)); } static double strictTANH(double a) { - return (double)(StrictMath.tanh((double)a)); + return (double)(strict_scalar_tanh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4342,11 +4541,11 @@ relativeError)); } static double ASIN(double a) { - return (double)(Math.asin((double)a)); + return (double)(scalar_asin(a)); } static double strictASIN(double a) { - return (double)(StrictMath.asin((double)a)); + return (double)(strict_scalar_asin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4365,11 +4564,11 @@ relativeError)); } static double ACOS(double a) { - return (double)(Math.acos((double)a)); + return (double)(scalar_acos(a)); } static double strictACOS(double a) { - return (double)(StrictMath.acos((double)a)); + return (double)(strict_scalar_acos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4388,11 +4587,11 @@ relativeError)); } static double ATAN(double a) { - return (double)(Math.atan((double)a)); + return (double)(scalar_atan(a)); } static double strictATAN(double a) { - return (double)(StrictMath.atan((double)a)); + return (double)(strict_scalar_atan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4411,11 +4610,11 @@ relativeError)); } static double CBRT(double a) { - return (double)(Math.cbrt((double)a)); + return (double)(scalar_cbrt(a)); } static double strictCBRT(double a) { - return (double)(StrictMath.cbrt((double)a)); + return (double)(strict_scalar_cbrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4434,11 +4633,11 @@ relativeError)); } static double HYPOT(double a, double b) { - return (double)(Math.hypot((double)a, (double)b)); + return (double)(scalar_hypot(a, b)); } static double strictHYPOT(double a, double b) { - return (double)(StrictMath.hypot((double)a, (double)b)); + return (double)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4460,11 +4659,11 @@ relativeError)); static double POW(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictPOW(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4486,11 +4685,11 @@ relativeError)); static double pow(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictpow(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4512,11 +4711,11 @@ relativeError)); static double ATAN2(double a, double b) { - return (double)(Math.atan2((double)a, (double)b)); + return (double)(scalar_atan2(a, b)); } static double strictATAN2(double a, double b) { - return (double)(StrictMath.atan2((double)a, (double)b)); + return (double)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4568,11 +4767,11 @@ relativeError)); static double FMA(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } static double fma(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } @Test(dataProvider = "doubleTernaryOpProvider") @@ -4792,11 +4991,11 @@ relativeError)); } static double NEG(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } static double neg(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4848,11 +5047,11 @@ relativeError)); } static double ABS(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } static double abs(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4904,11 +5103,11 @@ relativeError)); } static double SQRT(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } static double sqrt(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -5121,7 +5320,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5137,7 +5336,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5196,7 +5395,7 @@ relativeError)); static long ADDReduceLong(double[] a, int idx) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5205,7 +5404,7 @@ relativeError)); static long ADDReduceAllLong(double[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((double)res, (double)ADDReduceLong(a, i)); } return res; @@ -5223,8 +5422,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5234,8 +5433,9 @@ relativeError)); static long ADDReduceLongMasked(double[] a, int idx, boolean[] mask) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5244,7 +5444,7 @@ relativeError)); static long ADDReduceAllLongMasked(double[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((double)res, (double)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5264,8 +5464,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/DoubleVector512Tests.java b/test/jdk/jdk/incubator/vector/DoubleVector512Tests.java index 534470e194c..d23b2bf1511 100644 --- a/test/jdk/jdk/incubator/vector/DoubleVector512Tests.java +++ b/test/jdk/jdk/incubator/vector/DoubleVector512Tests.java @@ -1584,6 +1584,205 @@ relativeError)); return Double.compare(a, (double) 0) != 0 ? a : b; } + + static double scalar_add(double a, double b) { + return (double)(a + b); + } + + static double scalar_sub(double a, double b) { + return (double)(a - b); + } + + static double scalar_mul(double a, double b) { + return (double)(a * b); + } + + static double scalar_min(double a, double b) { + return (double)(Math.min(a, b)); + } + + static double scalar_max(double a, double b) { + return (double)(Math.max(a, b)); + } + + static double scalar_div(double a, double b) { + return (double)(a / b); + } + + static double scalar_fma(double a, double b, double c) { + return (double)(Math.fma(a, b, c)); + } + + static double scalar_abs(double a) { + return (double)(Math.abs(a)); + } + + static double scalar_neg(double a) { + return ((double)-a); + } + + static double scalar_sin(double a) { + return (double)Math.sin((double)a); + } + + static double scalar_exp(double a) { + return (double)Math.exp((double)a); + } + + static double scalar_log1p(double a) { + return (double)Math.log1p((double)a); + } + + static double scalar_log(double a) { + return (double)Math.log((double)a); + } + + static double scalar_log10(double a) { + return (double)Math.log10((double)a); + } + + static double scalar_expm1(double a) { + return (double)Math.expm1((double)a); + } + + static double scalar_cos(double a) { + return (double)Math.cos((double)a); + } + + static double scalar_tan(double a) { + return (double)Math.tan((double)a); + } + + static double scalar_sinh(double a) { + return (double)Math.sinh((double)a); + } + + static double scalar_cosh(double a) { + return (double)Math.cosh((double)a); + } + + static double scalar_tanh(double a) { + return (double)Math.tanh((double)a); + } + + static double scalar_asin(double a) { + return (double)Math.asin((double)a); + } + + static double scalar_acos(double a) { + return (double)Math.acos((double)a); + } + + static double scalar_atan(double a) { + return (double)Math.atan((double)a); + } + + static double scalar_cbrt(double a) { + return (double)Math.cbrt((double)a); + } + + static double scalar_sqrt(double a) { + return (double)Math.sqrt((double)a); + } + + static double scalar_hypot(double a, double b) { + return (double)Math.hypot((double)a, (double)b); + } + + static double scalar_pow(double a, double b) { + return (double)Math.pow((double)a, (double)b); + } + + static double scalar_atan2(double a, double b) { + return (double)Math.atan2((double)a, (double)b); + } + + static double strict_scalar_sin(double a) { + return (double)StrictMath.sin((double)a); + } + + static double strict_scalar_exp(double a) { + return (double)StrictMath.exp((double)a); + } + + static double strict_scalar_log1p(double a) { + return (double)StrictMath.log1p((double)a); + } + + static double strict_scalar_log(double a) { + return (double)StrictMath.log((double)a); + } + + static double strict_scalar_log10(double a) { + return (double)StrictMath.log10((double)a); + } + + static double strict_scalar_expm1(double a) { + return (double)StrictMath.expm1((double)a); + } + + static double strict_scalar_cos(double a) { + return (double)StrictMath.cos((double)a); + } + + static double strict_scalar_tan(double a) { + return (double)StrictMath.tan((double)a); + } + + static double strict_scalar_sinh(double a) { + return (double)StrictMath.sinh((double)a); + } + + static double strict_scalar_cosh(double a) { + return (double)StrictMath.cosh((double)a); + } + + static double strict_scalar_tanh(double a) { + return (double)StrictMath.tanh((double)a); + } + + static double strict_scalar_asin(double a) { + return (double)StrictMath.asin((double)a); + } + + static double strict_scalar_acos(double a) { + return (double)StrictMath.acos((double)a); + } + + static double strict_scalar_atan(double a) { + return (double)StrictMath.atan((double)a); + } + + static double strict_scalar_cbrt(double a) { + return (double)StrictMath.cbrt((double)a); + } + + static double strict_scalar_sqrt(double a) { + return (double)StrictMath.sqrt((double)a); + } + + static double strict_scalar_hypot(double a, double b) { + return (double)StrictMath.hypot((double)a, (double)b); + } + + static double strict_scalar_pow(double a, double b) { + return (double)StrictMath.pow((double)a, (double)b); + } + + static double strict_scalar_atan2(double a, double b) { + return (double)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(double a) { + return Double.isNaN(a); + } + static boolean isFinite(double a) { + return Double.isFinite(a); + } + static boolean isInfinite(double a) { + return Double.isInfinite(a); + } + @Test static void smokeTest1() { DoubleVector three = DoubleVector.broadcast(SPECIES, (byte)-3); @@ -1677,7 +1876,7 @@ relativeError)); } static double ADD(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1698,7 +1897,7 @@ relativeError)); } static double add(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1755,7 +1954,7 @@ relativeError)); } static double SUB(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1776,7 +1975,7 @@ relativeError)); } static double sub(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1833,7 +2032,7 @@ relativeError)); } static double MUL(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1854,7 +2053,7 @@ relativeError)); } static double mul(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1911,7 +2110,7 @@ relativeError)); } static double DIV(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1932,7 +2131,7 @@ relativeError)); } static double div(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1989,7 +2188,7 @@ relativeError)); } static double FIRST_NONZERO(double a, double b) { - return (double)(Double.doubleToLongBits(a)!=0?a:b); + return (double)(firstNonZero(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2291,7 +2490,7 @@ relativeError)); } static double MIN(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2312,7 +2511,7 @@ relativeError)); } static double min(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2331,7 +2530,7 @@ relativeError)); } static double MAX(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2352,7 +2551,7 @@ relativeError)); } static double max(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2429,7 +2628,7 @@ relativeError)); static double ADDReduce(double[] a, int idx) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2438,7 +2637,7 @@ relativeError)); static double ADDReduceAll(double[] a) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2456,7 +2655,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2469,20 +2668,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = ADD_IDENTITY; - assertEquals((double) (id + id), id, + assertEquals((double) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id + x), x); - assertEquals((double) (x + id), x); + assertEquals((double) (scalar_add(id, x)), x); + assertEquals((double) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id + x), x, + assertEquals((double) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x + id), x, + assertEquals((double) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2491,7 +2690,7 @@ relativeError)); double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2500,7 +2699,7 @@ relativeError)); static double ADDReduceAllMasked(double[] a, boolean[] mask) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2520,7 +2719,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2531,7 +2730,7 @@ relativeError)); static double MULReduce(double[] a, int idx) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2540,7 +2739,7 @@ relativeError)); static double MULReduceAll(double[] a) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2558,7 +2757,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2571,20 +2770,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MUL_IDENTITY; - assertEquals((double) (id * id), id, + assertEquals((double) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id * x), x); - assertEquals((double) (x * id), x); + assertEquals((double) (scalar_mul(id, x)), x); + assertEquals((double) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id * x), x, + assertEquals((double) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x * id), x, + assertEquals((double) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2593,7 +2792,7 @@ relativeError)); double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2602,7 +2801,7 @@ relativeError)); static double MULReduceAllMasked(double[] a, boolean[] mask) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2622,7 +2821,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2633,7 +2832,7 @@ relativeError)); static double MINReduce(double[] a, int idx) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2642,7 +2841,7 @@ relativeError)); static double MINReduceAll(double[] a) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2660,7 +2859,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2673,20 +2872,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MIN_IDENTITY; - assertEquals((double) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.min(id, x), x); - assertEquals((double) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2695,7 +2894,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2704,7 +2903,7 @@ relativeError)); static double MINReduceAllMasked(double[] a, boolean[] mask) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2724,7 +2923,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2735,7 +2934,7 @@ relativeError)); static double MAXReduce(double[] a, int idx) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2744,7 +2943,7 @@ relativeError)); static double MAXReduceAll(double[] a) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2762,7 +2961,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2775,20 +2974,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MAX_IDENTITY; - assertEquals((double) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.max(id, x), x); - assertEquals((double) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2797,7 +2996,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2806,7 +3005,7 @@ relativeError)); static double MAXReduceAllMasked(double[] a, boolean[] mask) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2826,7 +3025,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3038,7 +3237,7 @@ relativeError)); } static boolean testIS_FINITE(double a) { - return Double.isFinite(a); + return isFinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3079,7 +3278,7 @@ relativeError)); } static boolean testIS_NAN(double a) { - return Double.isNaN(a); + return isNaN(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3120,7 +3319,7 @@ relativeError)); } static boolean testIS_INFINITE(double a) { - return Double.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3461,7 +3660,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3481,7 +3680,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3497,7 +3696,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (double)((long)b[i]))); } } } @@ -3517,7 +3716,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (double)((long)b[i])))); } } } @@ -3533,7 +3732,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3553,7 +3752,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3569,7 +3768,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (double)((long)b[i]))); } } } @@ -3589,7 +3788,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (double)((long)b[i])))); } } } @@ -4089,11 +4288,11 @@ relativeError)); } static double SIN(double a) { - return (double)(Math.sin((double)a)); + return (double)(scalar_sin(a)); } static double strictSIN(double a) { - return (double)(StrictMath.sin((double)a)); + return (double)(strict_scalar_sin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4112,11 +4311,11 @@ relativeError)); } static double EXP(double a) { - return (double)(Math.exp((double)a)); + return (double)(scalar_exp(a)); } static double strictEXP(double a) { - return (double)(StrictMath.exp((double)a)); + return (double)(strict_scalar_exp(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4135,11 +4334,11 @@ relativeError)); } static double LOG1P(double a) { - return (double)(Math.log1p((double)a)); + return (double)(scalar_log1p(a)); } static double strictLOG1P(double a) { - return (double)(StrictMath.log1p((double)a)); + return (double)(strict_scalar_log1p(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4158,11 +4357,11 @@ relativeError)); } static double LOG(double a) { - return (double)(Math.log((double)a)); + return (double)(scalar_log(a)); } static double strictLOG(double a) { - return (double)(StrictMath.log((double)a)); + return (double)(strict_scalar_log(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4181,11 +4380,11 @@ relativeError)); } static double LOG10(double a) { - return (double)(Math.log10((double)a)); + return (double)(scalar_log10(a)); } static double strictLOG10(double a) { - return (double)(StrictMath.log10((double)a)); + return (double)(strict_scalar_log10(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4204,11 +4403,11 @@ relativeError)); } static double EXPM1(double a) { - return (double)(Math.expm1((double)a)); + return (double)(scalar_expm1(a)); } static double strictEXPM1(double a) { - return (double)(StrictMath.expm1((double)a)); + return (double)(strict_scalar_expm1(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4227,11 +4426,11 @@ relativeError)); } static double COS(double a) { - return (double)(Math.cos((double)a)); + return (double)(scalar_cos(a)); } static double strictCOS(double a) { - return (double)(StrictMath.cos((double)a)); + return (double)(strict_scalar_cos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4250,11 +4449,11 @@ relativeError)); } static double TAN(double a) { - return (double)(Math.tan((double)a)); + return (double)(scalar_tan(a)); } static double strictTAN(double a) { - return (double)(StrictMath.tan((double)a)); + return (double)(strict_scalar_tan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4273,11 +4472,11 @@ relativeError)); } static double SINH(double a) { - return (double)(Math.sinh((double)a)); + return (double)(scalar_sinh(a)); } static double strictSINH(double a) { - return (double)(StrictMath.sinh((double)a)); + return (double)(strict_scalar_sinh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4296,11 +4495,11 @@ relativeError)); } static double COSH(double a) { - return (double)(Math.cosh((double)a)); + return (double)(scalar_cosh(a)); } static double strictCOSH(double a) { - return (double)(StrictMath.cosh((double)a)); + return (double)(strict_scalar_cosh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4319,11 +4518,11 @@ relativeError)); } static double TANH(double a) { - return (double)(Math.tanh((double)a)); + return (double)(scalar_tanh(a)); } static double strictTANH(double a) { - return (double)(StrictMath.tanh((double)a)); + return (double)(strict_scalar_tanh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4342,11 +4541,11 @@ relativeError)); } static double ASIN(double a) { - return (double)(Math.asin((double)a)); + return (double)(scalar_asin(a)); } static double strictASIN(double a) { - return (double)(StrictMath.asin((double)a)); + return (double)(strict_scalar_asin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4365,11 +4564,11 @@ relativeError)); } static double ACOS(double a) { - return (double)(Math.acos((double)a)); + return (double)(scalar_acos(a)); } static double strictACOS(double a) { - return (double)(StrictMath.acos((double)a)); + return (double)(strict_scalar_acos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4388,11 +4587,11 @@ relativeError)); } static double ATAN(double a) { - return (double)(Math.atan((double)a)); + return (double)(scalar_atan(a)); } static double strictATAN(double a) { - return (double)(StrictMath.atan((double)a)); + return (double)(strict_scalar_atan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4411,11 +4610,11 @@ relativeError)); } static double CBRT(double a) { - return (double)(Math.cbrt((double)a)); + return (double)(scalar_cbrt(a)); } static double strictCBRT(double a) { - return (double)(StrictMath.cbrt((double)a)); + return (double)(strict_scalar_cbrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4434,11 +4633,11 @@ relativeError)); } static double HYPOT(double a, double b) { - return (double)(Math.hypot((double)a, (double)b)); + return (double)(scalar_hypot(a, b)); } static double strictHYPOT(double a, double b) { - return (double)(StrictMath.hypot((double)a, (double)b)); + return (double)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4460,11 +4659,11 @@ relativeError)); static double POW(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictPOW(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4486,11 +4685,11 @@ relativeError)); static double pow(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictpow(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4512,11 +4711,11 @@ relativeError)); static double ATAN2(double a, double b) { - return (double)(Math.atan2((double)a, (double)b)); + return (double)(scalar_atan2(a, b)); } static double strictATAN2(double a, double b) { - return (double)(StrictMath.atan2((double)a, (double)b)); + return (double)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4568,11 +4767,11 @@ relativeError)); static double FMA(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } static double fma(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } @Test(dataProvider = "doubleTernaryOpProvider") @@ -4792,11 +4991,11 @@ relativeError)); } static double NEG(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } static double neg(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4848,11 +5047,11 @@ relativeError)); } static double ABS(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } static double abs(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4904,11 +5103,11 @@ relativeError)); } static double SQRT(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } static double sqrt(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -5121,7 +5320,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5137,7 +5336,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5196,7 +5395,7 @@ relativeError)); static long ADDReduceLong(double[] a, int idx) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5205,7 +5404,7 @@ relativeError)); static long ADDReduceAllLong(double[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((double)res, (double)ADDReduceLong(a, i)); } return res; @@ -5223,8 +5422,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5234,8 +5433,9 @@ relativeError)); static long ADDReduceLongMasked(double[] a, int idx, boolean[] mask) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5244,7 +5444,7 @@ relativeError)); static long ADDReduceAllLongMasked(double[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((double)res, (double)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5264,8 +5464,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/DoubleVector64Tests.java b/test/jdk/jdk/incubator/vector/DoubleVector64Tests.java index 7f9f8986f1f..d2aff0b7ea5 100644 --- a/test/jdk/jdk/incubator/vector/DoubleVector64Tests.java +++ b/test/jdk/jdk/incubator/vector/DoubleVector64Tests.java @@ -1584,6 +1584,205 @@ relativeError)); return Double.compare(a, (double) 0) != 0 ? a : b; } + + static double scalar_add(double a, double b) { + return (double)(a + b); + } + + static double scalar_sub(double a, double b) { + return (double)(a - b); + } + + static double scalar_mul(double a, double b) { + return (double)(a * b); + } + + static double scalar_min(double a, double b) { + return (double)(Math.min(a, b)); + } + + static double scalar_max(double a, double b) { + return (double)(Math.max(a, b)); + } + + static double scalar_div(double a, double b) { + return (double)(a / b); + } + + static double scalar_fma(double a, double b, double c) { + return (double)(Math.fma(a, b, c)); + } + + static double scalar_abs(double a) { + return (double)(Math.abs(a)); + } + + static double scalar_neg(double a) { + return ((double)-a); + } + + static double scalar_sin(double a) { + return (double)Math.sin((double)a); + } + + static double scalar_exp(double a) { + return (double)Math.exp((double)a); + } + + static double scalar_log1p(double a) { + return (double)Math.log1p((double)a); + } + + static double scalar_log(double a) { + return (double)Math.log((double)a); + } + + static double scalar_log10(double a) { + return (double)Math.log10((double)a); + } + + static double scalar_expm1(double a) { + return (double)Math.expm1((double)a); + } + + static double scalar_cos(double a) { + return (double)Math.cos((double)a); + } + + static double scalar_tan(double a) { + return (double)Math.tan((double)a); + } + + static double scalar_sinh(double a) { + return (double)Math.sinh((double)a); + } + + static double scalar_cosh(double a) { + return (double)Math.cosh((double)a); + } + + static double scalar_tanh(double a) { + return (double)Math.tanh((double)a); + } + + static double scalar_asin(double a) { + return (double)Math.asin((double)a); + } + + static double scalar_acos(double a) { + return (double)Math.acos((double)a); + } + + static double scalar_atan(double a) { + return (double)Math.atan((double)a); + } + + static double scalar_cbrt(double a) { + return (double)Math.cbrt((double)a); + } + + static double scalar_sqrt(double a) { + return (double)Math.sqrt((double)a); + } + + static double scalar_hypot(double a, double b) { + return (double)Math.hypot((double)a, (double)b); + } + + static double scalar_pow(double a, double b) { + return (double)Math.pow((double)a, (double)b); + } + + static double scalar_atan2(double a, double b) { + return (double)Math.atan2((double)a, (double)b); + } + + static double strict_scalar_sin(double a) { + return (double)StrictMath.sin((double)a); + } + + static double strict_scalar_exp(double a) { + return (double)StrictMath.exp((double)a); + } + + static double strict_scalar_log1p(double a) { + return (double)StrictMath.log1p((double)a); + } + + static double strict_scalar_log(double a) { + return (double)StrictMath.log((double)a); + } + + static double strict_scalar_log10(double a) { + return (double)StrictMath.log10((double)a); + } + + static double strict_scalar_expm1(double a) { + return (double)StrictMath.expm1((double)a); + } + + static double strict_scalar_cos(double a) { + return (double)StrictMath.cos((double)a); + } + + static double strict_scalar_tan(double a) { + return (double)StrictMath.tan((double)a); + } + + static double strict_scalar_sinh(double a) { + return (double)StrictMath.sinh((double)a); + } + + static double strict_scalar_cosh(double a) { + return (double)StrictMath.cosh((double)a); + } + + static double strict_scalar_tanh(double a) { + return (double)StrictMath.tanh((double)a); + } + + static double strict_scalar_asin(double a) { + return (double)StrictMath.asin((double)a); + } + + static double strict_scalar_acos(double a) { + return (double)StrictMath.acos((double)a); + } + + static double strict_scalar_atan(double a) { + return (double)StrictMath.atan((double)a); + } + + static double strict_scalar_cbrt(double a) { + return (double)StrictMath.cbrt((double)a); + } + + static double strict_scalar_sqrt(double a) { + return (double)StrictMath.sqrt((double)a); + } + + static double strict_scalar_hypot(double a, double b) { + return (double)StrictMath.hypot((double)a, (double)b); + } + + static double strict_scalar_pow(double a, double b) { + return (double)StrictMath.pow((double)a, (double)b); + } + + static double strict_scalar_atan2(double a, double b) { + return (double)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(double a) { + return Double.isNaN(a); + } + static boolean isFinite(double a) { + return Double.isFinite(a); + } + static boolean isInfinite(double a) { + return Double.isInfinite(a); + } + @Test static void smokeTest1() { DoubleVector three = DoubleVector.broadcast(SPECIES, (byte)-3); @@ -1677,7 +1876,7 @@ relativeError)); } static double ADD(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1698,7 +1897,7 @@ relativeError)); } static double add(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1755,7 +1954,7 @@ relativeError)); } static double SUB(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1776,7 +1975,7 @@ relativeError)); } static double sub(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1833,7 +2032,7 @@ relativeError)); } static double MUL(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1854,7 +2053,7 @@ relativeError)); } static double mul(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1911,7 +2110,7 @@ relativeError)); } static double DIV(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1932,7 +2131,7 @@ relativeError)); } static double div(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1989,7 +2188,7 @@ relativeError)); } static double FIRST_NONZERO(double a, double b) { - return (double)(Double.doubleToLongBits(a)!=0?a:b); + return (double)(firstNonZero(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2291,7 +2490,7 @@ relativeError)); } static double MIN(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2312,7 +2511,7 @@ relativeError)); } static double min(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2331,7 +2530,7 @@ relativeError)); } static double MAX(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2352,7 +2551,7 @@ relativeError)); } static double max(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2429,7 +2628,7 @@ relativeError)); static double ADDReduce(double[] a, int idx) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2438,7 +2637,7 @@ relativeError)); static double ADDReduceAll(double[] a) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2456,7 +2655,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2469,20 +2668,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = ADD_IDENTITY; - assertEquals((double) (id + id), id, + assertEquals((double) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id + x), x); - assertEquals((double) (x + id), x); + assertEquals((double) (scalar_add(id, x)), x); + assertEquals((double) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id + x), x, + assertEquals((double) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x + id), x, + assertEquals((double) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2491,7 +2690,7 @@ relativeError)); double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2500,7 +2699,7 @@ relativeError)); static double ADDReduceAllMasked(double[] a, boolean[] mask) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2520,7 +2719,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2531,7 +2730,7 @@ relativeError)); static double MULReduce(double[] a, int idx) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2540,7 +2739,7 @@ relativeError)); static double MULReduceAll(double[] a) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2558,7 +2757,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2571,20 +2770,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MUL_IDENTITY; - assertEquals((double) (id * id), id, + assertEquals((double) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id * x), x); - assertEquals((double) (x * id), x); + assertEquals((double) (scalar_mul(id, x)), x); + assertEquals((double) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id * x), x, + assertEquals((double) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x * id), x, + assertEquals((double) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2593,7 +2792,7 @@ relativeError)); double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2602,7 +2801,7 @@ relativeError)); static double MULReduceAllMasked(double[] a, boolean[] mask) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2622,7 +2821,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2633,7 +2832,7 @@ relativeError)); static double MINReduce(double[] a, int idx) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2642,7 +2841,7 @@ relativeError)); static double MINReduceAll(double[] a) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2660,7 +2859,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2673,20 +2872,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MIN_IDENTITY; - assertEquals((double) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.min(id, x), x); - assertEquals((double) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2695,7 +2894,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2704,7 +2903,7 @@ relativeError)); static double MINReduceAllMasked(double[] a, boolean[] mask) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2724,7 +2923,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2735,7 +2934,7 @@ relativeError)); static double MAXReduce(double[] a, int idx) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2744,7 +2943,7 @@ relativeError)); static double MAXReduceAll(double[] a) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2762,7 +2961,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2775,20 +2974,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MAX_IDENTITY; - assertEquals((double) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.max(id, x), x); - assertEquals((double) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2797,7 +2996,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2806,7 +3005,7 @@ relativeError)); static double MAXReduceAllMasked(double[] a, boolean[] mask) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2826,7 +3025,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3038,7 +3237,7 @@ relativeError)); } static boolean testIS_FINITE(double a) { - return Double.isFinite(a); + return isFinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3079,7 +3278,7 @@ relativeError)); } static boolean testIS_NAN(double a) { - return Double.isNaN(a); + return isNaN(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3120,7 +3319,7 @@ relativeError)); } static boolean testIS_INFINITE(double a) { - return Double.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3461,7 +3660,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3481,7 +3680,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3497,7 +3696,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (double)((long)b[i]))); } } } @@ -3517,7 +3716,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (double)((long)b[i])))); } } } @@ -3533,7 +3732,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3553,7 +3752,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3569,7 +3768,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (double)((long)b[i]))); } } } @@ -3589,7 +3788,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (double)((long)b[i])))); } } } @@ -4089,11 +4288,11 @@ relativeError)); } static double SIN(double a) { - return (double)(Math.sin((double)a)); + return (double)(scalar_sin(a)); } static double strictSIN(double a) { - return (double)(StrictMath.sin((double)a)); + return (double)(strict_scalar_sin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4112,11 +4311,11 @@ relativeError)); } static double EXP(double a) { - return (double)(Math.exp((double)a)); + return (double)(scalar_exp(a)); } static double strictEXP(double a) { - return (double)(StrictMath.exp((double)a)); + return (double)(strict_scalar_exp(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4135,11 +4334,11 @@ relativeError)); } static double LOG1P(double a) { - return (double)(Math.log1p((double)a)); + return (double)(scalar_log1p(a)); } static double strictLOG1P(double a) { - return (double)(StrictMath.log1p((double)a)); + return (double)(strict_scalar_log1p(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4158,11 +4357,11 @@ relativeError)); } static double LOG(double a) { - return (double)(Math.log((double)a)); + return (double)(scalar_log(a)); } static double strictLOG(double a) { - return (double)(StrictMath.log((double)a)); + return (double)(strict_scalar_log(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4181,11 +4380,11 @@ relativeError)); } static double LOG10(double a) { - return (double)(Math.log10((double)a)); + return (double)(scalar_log10(a)); } static double strictLOG10(double a) { - return (double)(StrictMath.log10((double)a)); + return (double)(strict_scalar_log10(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4204,11 +4403,11 @@ relativeError)); } static double EXPM1(double a) { - return (double)(Math.expm1((double)a)); + return (double)(scalar_expm1(a)); } static double strictEXPM1(double a) { - return (double)(StrictMath.expm1((double)a)); + return (double)(strict_scalar_expm1(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4227,11 +4426,11 @@ relativeError)); } static double COS(double a) { - return (double)(Math.cos((double)a)); + return (double)(scalar_cos(a)); } static double strictCOS(double a) { - return (double)(StrictMath.cos((double)a)); + return (double)(strict_scalar_cos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4250,11 +4449,11 @@ relativeError)); } static double TAN(double a) { - return (double)(Math.tan((double)a)); + return (double)(scalar_tan(a)); } static double strictTAN(double a) { - return (double)(StrictMath.tan((double)a)); + return (double)(strict_scalar_tan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4273,11 +4472,11 @@ relativeError)); } static double SINH(double a) { - return (double)(Math.sinh((double)a)); + return (double)(scalar_sinh(a)); } static double strictSINH(double a) { - return (double)(StrictMath.sinh((double)a)); + return (double)(strict_scalar_sinh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4296,11 +4495,11 @@ relativeError)); } static double COSH(double a) { - return (double)(Math.cosh((double)a)); + return (double)(scalar_cosh(a)); } static double strictCOSH(double a) { - return (double)(StrictMath.cosh((double)a)); + return (double)(strict_scalar_cosh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4319,11 +4518,11 @@ relativeError)); } static double TANH(double a) { - return (double)(Math.tanh((double)a)); + return (double)(scalar_tanh(a)); } static double strictTANH(double a) { - return (double)(StrictMath.tanh((double)a)); + return (double)(strict_scalar_tanh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4342,11 +4541,11 @@ relativeError)); } static double ASIN(double a) { - return (double)(Math.asin((double)a)); + return (double)(scalar_asin(a)); } static double strictASIN(double a) { - return (double)(StrictMath.asin((double)a)); + return (double)(strict_scalar_asin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4365,11 +4564,11 @@ relativeError)); } static double ACOS(double a) { - return (double)(Math.acos((double)a)); + return (double)(scalar_acos(a)); } static double strictACOS(double a) { - return (double)(StrictMath.acos((double)a)); + return (double)(strict_scalar_acos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4388,11 +4587,11 @@ relativeError)); } static double ATAN(double a) { - return (double)(Math.atan((double)a)); + return (double)(scalar_atan(a)); } static double strictATAN(double a) { - return (double)(StrictMath.atan((double)a)); + return (double)(strict_scalar_atan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4411,11 +4610,11 @@ relativeError)); } static double CBRT(double a) { - return (double)(Math.cbrt((double)a)); + return (double)(scalar_cbrt(a)); } static double strictCBRT(double a) { - return (double)(StrictMath.cbrt((double)a)); + return (double)(strict_scalar_cbrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4434,11 +4633,11 @@ relativeError)); } static double HYPOT(double a, double b) { - return (double)(Math.hypot((double)a, (double)b)); + return (double)(scalar_hypot(a, b)); } static double strictHYPOT(double a, double b) { - return (double)(StrictMath.hypot((double)a, (double)b)); + return (double)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4460,11 +4659,11 @@ relativeError)); static double POW(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictPOW(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4486,11 +4685,11 @@ relativeError)); static double pow(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictpow(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4512,11 +4711,11 @@ relativeError)); static double ATAN2(double a, double b) { - return (double)(Math.atan2((double)a, (double)b)); + return (double)(scalar_atan2(a, b)); } static double strictATAN2(double a, double b) { - return (double)(StrictMath.atan2((double)a, (double)b)); + return (double)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4568,11 +4767,11 @@ relativeError)); static double FMA(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } static double fma(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } @Test(dataProvider = "doubleTernaryOpProvider") @@ -4792,11 +4991,11 @@ relativeError)); } static double NEG(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } static double neg(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4848,11 +5047,11 @@ relativeError)); } static double ABS(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } static double abs(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4904,11 +5103,11 @@ relativeError)); } static double SQRT(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } static double sqrt(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -5121,7 +5320,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5137,7 +5336,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5196,7 +5395,7 @@ relativeError)); static long ADDReduceLong(double[] a, int idx) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5205,7 +5404,7 @@ relativeError)); static long ADDReduceAllLong(double[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((double)res, (double)ADDReduceLong(a, i)); } return res; @@ -5223,8 +5422,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5234,8 +5433,9 @@ relativeError)); static long ADDReduceLongMasked(double[] a, int idx, boolean[] mask) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5244,7 +5444,7 @@ relativeError)); static long ADDReduceAllLongMasked(double[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((double)res, (double)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5264,8 +5464,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/DoubleVectorMaxTests.java b/test/jdk/jdk/incubator/vector/DoubleVectorMaxTests.java index c4dda942e83..2684ae2d0c6 100644 --- a/test/jdk/jdk/incubator/vector/DoubleVectorMaxTests.java +++ b/test/jdk/jdk/incubator/vector/DoubleVectorMaxTests.java @@ -1590,6 +1590,205 @@ relativeError)); return Double.compare(a, (double) 0) != 0 ? a : b; } + + static double scalar_add(double a, double b) { + return (double)(a + b); + } + + static double scalar_sub(double a, double b) { + return (double)(a - b); + } + + static double scalar_mul(double a, double b) { + return (double)(a * b); + } + + static double scalar_min(double a, double b) { + return (double)(Math.min(a, b)); + } + + static double scalar_max(double a, double b) { + return (double)(Math.max(a, b)); + } + + static double scalar_div(double a, double b) { + return (double)(a / b); + } + + static double scalar_fma(double a, double b, double c) { + return (double)(Math.fma(a, b, c)); + } + + static double scalar_abs(double a) { + return (double)(Math.abs(a)); + } + + static double scalar_neg(double a) { + return ((double)-a); + } + + static double scalar_sin(double a) { + return (double)Math.sin((double)a); + } + + static double scalar_exp(double a) { + return (double)Math.exp((double)a); + } + + static double scalar_log1p(double a) { + return (double)Math.log1p((double)a); + } + + static double scalar_log(double a) { + return (double)Math.log((double)a); + } + + static double scalar_log10(double a) { + return (double)Math.log10((double)a); + } + + static double scalar_expm1(double a) { + return (double)Math.expm1((double)a); + } + + static double scalar_cos(double a) { + return (double)Math.cos((double)a); + } + + static double scalar_tan(double a) { + return (double)Math.tan((double)a); + } + + static double scalar_sinh(double a) { + return (double)Math.sinh((double)a); + } + + static double scalar_cosh(double a) { + return (double)Math.cosh((double)a); + } + + static double scalar_tanh(double a) { + return (double)Math.tanh((double)a); + } + + static double scalar_asin(double a) { + return (double)Math.asin((double)a); + } + + static double scalar_acos(double a) { + return (double)Math.acos((double)a); + } + + static double scalar_atan(double a) { + return (double)Math.atan((double)a); + } + + static double scalar_cbrt(double a) { + return (double)Math.cbrt((double)a); + } + + static double scalar_sqrt(double a) { + return (double)Math.sqrt((double)a); + } + + static double scalar_hypot(double a, double b) { + return (double)Math.hypot((double)a, (double)b); + } + + static double scalar_pow(double a, double b) { + return (double)Math.pow((double)a, (double)b); + } + + static double scalar_atan2(double a, double b) { + return (double)Math.atan2((double)a, (double)b); + } + + static double strict_scalar_sin(double a) { + return (double)StrictMath.sin((double)a); + } + + static double strict_scalar_exp(double a) { + return (double)StrictMath.exp((double)a); + } + + static double strict_scalar_log1p(double a) { + return (double)StrictMath.log1p((double)a); + } + + static double strict_scalar_log(double a) { + return (double)StrictMath.log((double)a); + } + + static double strict_scalar_log10(double a) { + return (double)StrictMath.log10((double)a); + } + + static double strict_scalar_expm1(double a) { + return (double)StrictMath.expm1((double)a); + } + + static double strict_scalar_cos(double a) { + return (double)StrictMath.cos((double)a); + } + + static double strict_scalar_tan(double a) { + return (double)StrictMath.tan((double)a); + } + + static double strict_scalar_sinh(double a) { + return (double)StrictMath.sinh((double)a); + } + + static double strict_scalar_cosh(double a) { + return (double)StrictMath.cosh((double)a); + } + + static double strict_scalar_tanh(double a) { + return (double)StrictMath.tanh((double)a); + } + + static double strict_scalar_asin(double a) { + return (double)StrictMath.asin((double)a); + } + + static double strict_scalar_acos(double a) { + return (double)StrictMath.acos((double)a); + } + + static double strict_scalar_atan(double a) { + return (double)StrictMath.atan((double)a); + } + + static double strict_scalar_cbrt(double a) { + return (double)StrictMath.cbrt((double)a); + } + + static double strict_scalar_sqrt(double a) { + return (double)StrictMath.sqrt((double)a); + } + + static double strict_scalar_hypot(double a, double b) { + return (double)StrictMath.hypot((double)a, (double)b); + } + + static double strict_scalar_pow(double a, double b) { + return (double)StrictMath.pow((double)a, (double)b); + } + + static double strict_scalar_atan2(double a, double b) { + return (double)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(double a) { + return Double.isNaN(a); + } + static boolean isFinite(double a) { + return Double.isFinite(a); + } + static boolean isInfinite(double a) { + return Double.isInfinite(a); + } + @Test static void smokeTest1() { DoubleVector three = DoubleVector.broadcast(SPECIES, (byte)-3); @@ -1683,7 +1882,7 @@ relativeError)); } static double ADD(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1704,7 +1903,7 @@ relativeError)); } static double add(double a, double b) { - return (double)(a + b); + return (double)(scalar_add(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1761,7 +1960,7 @@ relativeError)); } static double SUB(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1782,7 +1981,7 @@ relativeError)); } static double sub(double a, double b) { - return (double)(a - b); + return (double)(scalar_sub(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1839,7 +2038,7 @@ relativeError)); } static double MUL(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1860,7 +2059,7 @@ relativeError)); } static double mul(double a, double b) { - return (double)(a * b); + return (double)(scalar_mul(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1917,7 +2116,7 @@ relativeError)); } static double DIV(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1938,7 +2137,7 @@ relativeError)); } static double div(double a, double b) { - return (double)(a / b); + return (double)(scalar_div(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -1995,7 +2194,7 @@ relativeError)); } static double FIRST_NONZERO(double a, double b) { - return (double)(Double.doubleToLongBits(a)!=0?a:b); + return (double)(firstNonZero(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2297,7 +2496,7 @@ relativeError)); } static double MIN(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2318,7 +2517,7 @@ relativeError)); } static double min(double a, double b) { - return (double)(Math.min(a, b)); + return (double)(scalar_min(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2337,7 +2536,7 @@ relativeError)); } static double MAX(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2358,7 +2557,7 @@ relativeError)); } static double max(double a, double b) { - return (double)(Math.max(a, b)); + return (double)(scalar_max(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -2435,7 +2634,7 @@ relativeError)); static double ADDReduce(double[] a, int idx) { double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2444,7 +2643,7 @@ relativeError)); static double ADDReduceAll(double[] a) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2462,7 +2661,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2475,20 +2674,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = ADD_IDENTITY; - assertEquals((double) (id + id), id, + assertEquals((double) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id + x), x); - assertEquals((double) (x + id), x); + assertEquals((double) (scalar_add(id, x)), x); + assertEquals((double) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id + x), x, + assertEquals((double) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x + id), x, + assertEquals((double) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2497,7 +2696,7 @@ relativeError)); double res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2506,7 +2705,7 @@ relativeError)); static double ADDReduceAllMasked(double[] a, boolean[] mask) { double res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2526,7 +2725,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2537,7 +2736,7 @@ relativeError)); static double MULReduce(double[] a, int idx) { double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2546,7 +2745,7 @@ relativeError)); static double MULReduceAll(double[] a) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2564,7 +2763,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2577,20 +2776,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MUL_IDENTITY; - assertEquals((double) (id * id), id, + assertEquals((double) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) (id * x), x); - assertEquals((double) (x * id), x); + assertEquals((double) (scalar_mul(id, x)), x); + assertEquals((double) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((double) (id * x), x, + assertEquals((double) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((double) (x * id), x, + assertEquals((double) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2599,7 +2798,7 @@ relativeError)); double res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2608,7 +2807,7 @@ relativeError)); static double MULReduceAllMasked(double[] a, boolean[] mask) { double res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2628,7 +2827,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2639,7 +2838,7 @@ relativeError)); static double MINReduce(double[] a, int idx) { double res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2648,7 +2847,7 @@ relativeError)); static double MINReduceAll(double[] a) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2666,7 +2865,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2679,20 +2878,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MIN_IDENTITY; - assertEquals((double) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.min(id, x), x); - assertEquals((double) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2701,7 +2900,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2710,7 +2909,7 @@ relativeError)); static double MINReduceAllMasked(double[] a, boolean[] mask) { double res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2730,7 +2929,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (double) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2741,7 +2940,7 @@ relativeError)); static double MAXReduce(double[] a, int idx) { double res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (double) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2750,7 +2949,7 @@ relativeError)); static double MAXReduceAll(double[] a) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2768,7 +2967,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2781,20 +2980,20 @@ relativeError)); double[] a = fa.apply(SPECIES.length()); double id = MAX_IDENTITY; - assertEquals((double) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); double x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((double) Math.max(id, x), x); - assertEquals((double) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((double) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((double) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2803,7 +3002,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2812,7 +3011,7 @@ relativeError)); static double MAXReduceAllMasked(double[] a, boolean[] mask) { double res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2832,7 +3031,7 @@ relativeError)); DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); double v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (double) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3044,7 +3243,7 @@ relativeError)); } static boolean testIS_FINITE(double a) { - return Double.isFinite(a); + return isFinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3085,7 +3284,7 @@ relativeError)); } static boolean testIS_NAN(double a) { - return Double.isNaN(a); + return isNaN(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3126,7 +3325,7 @@ relativeError)); } static boolean testIS_INFINITE(double a) { - return Double.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "doubleTestOpProvider") @@ -3467,7 +3666,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3487,7 +3686,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3503,7 +3702,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (double)((long)b[i]))); } } } @@ -3523,7 +3722,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (double)((long)b[i])))); } } } @@ -3539,7 +3738,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3559,7 +3758,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3575,7 +3774,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (double)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (double)((long)b[i]))); } } } @@ -3595,7 +3794,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (double)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (double)((long)b[i])))); } } } @@ -4095,11 +4294,11 @@ relativeError)); } static double SIN(double a) { - return (double)(Math.sin((double)a)); + return (double)(scalar_sin(a)); } static double strictSIN(double a) { - return (double)(StrictMath.sin((double)a)); + return (double)(strict_scalar_sin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4118,11 +4317,11 @@ relativeError)); } static double EXP(double a) { - return (double)(Math.exp((double)a)); + return (double)(scalar_exp(a)); } static double strictEXP(double a) { - return (double)(StrictMath.exp((double)a)); + return (double)(strict_scalar_exp(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4141,11 +4340,11 @@ relativeError)); } static double LOG1P(double a) { - return (double)(Math.log1p((double)a)); + return (double)(scalar_log1p(a)); } static double strictLOG1P(double a) { - return (double)(StrictMath.log1p((double)a)); + return (double)(strict_scalar_log1p(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4164,11 +4363,11 @@ relativeError)); } static double LOG(double a) { - return (double)(Math.log((double)a)); + return (double)(scalar_log(a)); } static double strictLOG(double a) { - return (double)(StrictMath.log((double)a)); + return (double)(strict_scalar_log(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4187,11 +4386,11 @@ relativeError)); } static double LOG10(double a) { - return (double)(Math.log10((double)a)); + return (double)(scalar_log10(a)); } static double strictLOG10(double a) { - return (double)(StrictMath.log10((double)a)); + return (double)(strict_scalar_log10(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4210,11 +4409,11 @@ relativeError)); } static double EXPM1(double a) { - return (double)(Math.expm1((double)a)); + return (double)(scalar_expm1(a)); } static double strictEXPM1(double a) { - return (double)(StrictMath.expm1((double)a)); + return (double)(strict_scalar_expm1(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4233,11 +4432,11 @@ relativeError)); } static double COS(double a) { - return (double)(Math.cos((double)a)); + return (double)(scalar_cos(a)); } static double strictCOS(double a) { - return (double)(StrictMath.cos((double)a)); + return (double)(strict_scalar_cos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4256,11 +4455,11 @@ relativeError)); } static double TAN(double a) { - return (double)(Math.tan((double)a)); + return (double)(scalar_tan(a)); } static double strictTAN(double a) { - return (double)(StrictMath.tan((double)a)); + return (double)(strict_scalar_tan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4279,11 +4478,11 @@ relativeError)); } static double SINH(double a) { - return (double)(Math.sinh((double)a)); + return (double)(scalar_sinh(a)); } static double strictSINH(double a) { - return (double)(StrictMath.sinh((double)a)); + return (double)(strict_scalar_sinh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4302,11 +4501,11 @@ relativeError)); } static double COSH(double a) { - return (double)(Math.cosh((double)a)); + return (double)(scalar_cosh(a)); } static double strictCOSH(double a) { - return (double)(StrictMath.cosh((double)a)); + return (double)(strict_scalar_cosh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4325,11 +4524,11 @@ relativeError)); } static double TANH(double a) { - return (double)(Math.tanh((double)a)); + return (double)(scalar_tanh(a)); } static double strictTANH(double a) { - return (double)(StrictMath.tanh((double)a)); + return (double)(strict_scalar_tanh(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4348,11 +4547,11 @@ relativeError)); } static double ASIN(double a) { - return (double)(Math.asin((double)a)); + return (double)(scalar_asin(a)); } static double strictASIN(double a) { - return (double)(StrictMath.asin((double)a)); + return (double)(strict_scalar_asin(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4371,11 +4570,11 @@ relativeError)); } static double ACOS(double a) { - return (double)(Math.acos((double)a)); + return (double)(scalar_acos(a)); } static double strictACOS(double a) { - return (double)(StrictMath.acos((double)a)); + return (double)(strict_scalar_acos(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4394,11 +4593,11 @@ relativeError)); } static double ATAN(double a) { - return (double)(Math.atan((double)a)); + return (double)(scalar_atan(a)); } static double strictATAN(double a) { - return (double)(StrictMath.atan((double)a)); + return (double)(strict_scalar_atan(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4417,11 +4616,11 @@ relativeError)); } static double CBRT(double a) { - return (double)(Math.cbrt((double)a)); + return (double)(scalar_cbrt(a)); } static double strictCBRT(double a) { - return (double)(StrictMath.cbrt((double)a)); + return (double)(strict_scalar_cbrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4440,11 +4639,11 @@ relativeError)); } static double HYPOT(double a, double b) { - return (double)(Math.hypot((double)a, (double)b)); + return (double)(scalar_hypot(a, b)); } static double strictHYPOT(double a, double b) { - return (double)(StrictMath.hypot((double)a, (double)b)); + return (double)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4466,11 +4665,11 @@ relativeError)); static double POW(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictPOW(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4492,11 +4691,11 @@ relativeError)); static double pow(double a, double b) { - return (double)(Math.pow((double)a, (double)b)); + return (double)(scalar_pow(a, b)); } static double strictpow(double a, double b) { - return (double)(StrictMath.pow((double)a, (double)b)); + return (double)(strict_scalar_pow(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4518,11 +4717,11 @@ relativeError)); static double ATAN2(double a, double b) { - return (double)(Math.atan2((double)a, (double)b)); + return (double)(scalar_atan2(a, b)); } static double strictATAN2(double a, double b) { - return (double)(StrictMath.atan2((double)a, (double)b)); + return (double)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "doubleBinaryOpProvider") @@ -4574,11 +4773,11 @@ relativeError)); static double FMA(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } static double fma(double a, double b, double c) { - return (double)(Math.fma(a, b, c)); + return (double)(scalar_fma(a, b, c)); } @Test(dataProvider = "doubleTernaryOpProvider") @@ -4798,11 +4997,11 @@ relativeError)); } static double NEG(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } static double neg(double a) { - return (double)(-((double)a)); + return (double)(scalar_neg((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4854,11 +5053,11 @@ relativeError)); } static double ABS(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } static double abs(double a) { - return (double)(Math.abs((double)a)); + return (double)(scalar_abs((double)a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -4910,11 +5109,11 @@ relativeError)); } static double SQRT(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } static double sqrt(double a) { - return (double)(Math.sqrt((double)a)); + return (double)(scalar_sqrt(a)); } @Test(dataProvider = "doubleUnaryOpProvider") @@ -5127,7 +5326,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5143,7 +5342,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5202,7 +5401,7 @@ relativeError)); static long ADDReduceLong(double[] a, int idx) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5211,7 +5410,7 @@ relativeError)); static long ADDReduceAllLong(double[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((double)res, (double)ADDReduceLong(a, i)); } return res; @@ -5229,8 +5428,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5240,8 +5439,9 @@ relativeError)); static long ADDReduceLongMasked(double[] a, int idx, boolean[] mask) { double res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5250,7 +5450,7 @@ relativeError)); static long ADDReduceAllLongMasked(double[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((double)res, (double)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5270,8 +5470,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((double)ra, (double)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/FloatVector128Tests.java b/test/jdk/jdk/incubator/vector/FloatVector128Tests.java index 51e6365b01b..151ea17a886 100644 --- a/test/jdk/jdk/incubator/vector/FloatVector128Tests.java +++ b/test/jdk/jdk/incubator/vector/FloatVector128Tests.java @@ -1601,6 +1601,205 @@ relativeError)); return Float.compare(a, (float) 0) != 0 ? a : b; } + + static float scalar_add(float a, float b) { + return (float)(a + b); + } + + static float scalar_sub(float a, float b) { + return (float)(a - b); + } + + static float scalar_mul(float a, float b) { + return (float)(a * b); + } + + static float scalar_min(float a, float b) { + return (float)(Math.min(a, b)); + } + + static float scalar_max(float a, float b) { + return (float)(Math.max(a, b)); + } + + static float scalar_div(float a, float b) { + return (float)(a / b); + } + + static float scalar_fma(float a, float b, float c) { + return (float)(Math.fma(a, b, c)); + } + + static float scalar_abs(float a) { + return (float)(Math.abs(a)); + } + + static float scalar_neg(float a) { + return ((float)-a); + } + + static float scalar_sin(float a) { + return (float)Math.sin((double)a); + } + + static float scalar_exp(float a) { + return (float)Math.exp((double)a); + } + + static float scalar_log1p(float a) { + return (float)Math.log1p((double)a); + } + + static float scalar_log(float a) { + return (float)Math.log((double)a); + } + + static float scalar_log10(float a) { + return (float)Math.log10((double)a); + } + + static float scalar_expm1(float a) { + return (float)Math.expm1((double)a); + } + + static float scalar_cos(float a) { + return (float)Math.cos((double)a); + } + + static float scalar_tan(float a) { + return (float)Math.tan((double)a); + } + + static float scalar_sinh(float a) { + return (float)Math.sinh((double)a); + } + + static float scalar_cosh(float a) { + return (float)Math.cosh((double)a); + } + + static float scalar_tanh(float a) { + return (float)Math.tanh((double)a); + } + + static float scalar_asin(float a) { + return (float)Math.asin((double)a); + } + + static float scalar_acos(float a) { + return (float)Math.acos((double)a); + } + + static float scalar_atan(float a) { + return (float)Math.atan((double)a); + } + + static float scalar_cbrt(float a) { + return (float)Math.cbrt((double)a); + } + + static float scalar_sqrt(float a) { + return (float)Math.sqrt((double)a); + } + + static float scalar_hypot(float a, float b) { + return (float)Math.hypot((double)a, (double)b); + } + + static float scalar_pow(float a, float b) { + return (float)Math.pow((double)a, (double)b); + } + + static float scalar_atan2(float a, float b) { + return (float)Math.atan2((double)a, (double)b); + } + + static float strict_scalar_sin(float a) { + return (float)StrictMath.sin((double)a); + } + + static float strict_scalar_exp(float a) { + return (float)StrictMath.exp((double)a); + } + + static float strict_scalar_log1p(float a) { + return (float)StrictMath.log1p((double)a); + } + + static float strict_scalar_log(float a) { + return (float)StrictMath.log((double)a); + } + + static float strict_scalar_log10(float a) { + return (float)StrictMath.log10((double)a); + } + + static float strict_scalar_expm1(float a) { + return (float)StrictMath.expm1((double)a); + } + + static float strict_scalar_cos(float a) { + return (float)StrictMath.cos((double)a); + } + + static float strict_scalar_tan(float a) { + return (float)StrictMath.tan((double)a); + } + + static float strict_scalar_sinh(float a) { + return (float)StrictMath.sinh((double)a); + } + + static float strict_scalar_cosh(float a) { + return (float)StrictMath.cosh((double)a); + } + + static float strict_scalar_tanh(float a) { + return (float)StrictMath.tanh((double)a); + } + + static float strict_scalar_asin(float a) { + return (float)StrictMath.asin((double)a); + } + + static float strict_scalar_acos(float a) { + return (float)StrictMath.acos((double)a); + } + + static float strict_scalar_atan(float a) { + return (float)StrictMath.atan((double)a); + } + + static float strict_scalar_cbrt(float a) { + return (float)StrictMath.cbrt((double)a); + } + + static float strict_scalar_sqrt(float a) { + return (float)StrictMath.sqrt((double)a); + } + + static float strict_scalar_hypot(float a, float b) { + return (float)StrictMath.hypot((double)a, (double)b); + } + + static float strict_scalar_pow(float a, float b) { + return (float)StrictMath.pow((double)a, (double)b); + } + + static float strict_scalar_atan2(float a, float b) { + return (float)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(float a) { + return Float.isNaN(a); + } + static boolean isFinite(float a) { + return Float.isFinite(a); + } + static boolean isInfinite(float a) { + return Float.isInfinite(a); + } + @Test static void smokeTest1() { FloatVector three = FloatVector.broadcast(SPECIES, (byte)-3); @@ -1694,7 +1893,7 @@ relativeError)); } static float ADD(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1715,7 +1914,7 @@ relativeError)); } static float add(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1772,7 +1971,7 @@ relativeError)); } static float SUB(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1793,7 +1992,7 @@ relativeError)); } static float sub(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1850,7 +2049,7 @@ relativeError)); } static float MUL(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1871,7 +2070,7 @@ relativeError)); } static float mul(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1928,7 +2127,7 @@ relativeError)); } static float DIV(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1949,7 +2148,7 @@ relativeError)); } static float div(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2006,7 +2205,7 @@ relativeError)); } static float FIRST_NONZERO(float a, float b) { - return (float)(Double.doubleToLongBits(a)!=0?a:b); + return (float)(firstNonZero(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2308,7 +2507,7 @@ relativeError)); } static float MIN(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2329,7 +2528,7 @@ relativeError)); } static float min(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2348,7 +2547,7 @@ relativeError)); } static float MAX(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2369,7 +2568,7 @@ relativeError)); } static float max(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2446,7 +2645,7 @@ relativeError)); static float ADDReduce(float[] a, int idx) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2455,7 +2654,7 @@ relativeError)); static float ADDReduceAll(float[] a) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2473,7 +2672,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2486,20 +2685,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = ADD_IDENTITY; - assertEquals((float) (id + id), id, + assertEquals((float) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id + x), x); - assertEquals((float) (x + id), x); + assertEquals((float) (scalar_add(id, x)), x); + assertEquals((float) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id + x), x, + assertEquals((float) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x + id), x, + assertEquals((float) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2508,7 +2707,7 @@ relativeError)); float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2517,7 +2716,7 @@ relativeError)); static float ADDReduceAllMasked(float[] a, boolean[] mask) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2537,7 +2736,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2548,7 +2747,7 @@ relativeError)); static float MULReduce(float[] a, int idx) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2557,7 +2756,7 @@ relativeError)); static float MULReduceAll(float[] a) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2575,7 +2774,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2588,20 +2787,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MUL_IDENTITY; - assertEquals((float) (id * id), id, + assertEquals((float) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id * x), x); - assertEquals((float) (x * id), x); + assertEquals((float) (scalar_mul(id, x)), x); + assertEquals((float) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id * x), x, + assertEquals((float) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x * id), x, + assertEquals((float) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2610,7 +2809,7 @@ relativeError)); float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2619,7 +2818,7 @@ relativeError)); static float MULReduceAllMasked(float[] a, boolean[] mask) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2639,7 +2838,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2650,7 +2849,7 @@ relativeError)); static float MINReduce(float[] a, int idx) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2659,7 +2858,7 @@ relativeError)); static float MINReduceAll(float[] a) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2677,7 +2876,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2690,20 +2889,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MIN_IDENTITY; - assertEquals((float) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.min(id, x), x); - assertEquals((float) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2712,7 +2911,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2721,7 +2920,7 @@ relativeError)); static float MINReduceAllMasked(float[] a, boolean[] mask) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2741,7 +2940,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2752,7 +2951,7 @@ relativeError)); static float MAXReduce(float[] a, int idx) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2761,7 +2960,7 @@ relativeError)); static float MAXReduceAll(float[] a) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2779,7 +2978,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2792,20 +2991,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MAX_IDENTITY; - assertEquals((float) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.max(id, x), x); - assertEquals((float) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2814,7 +3013,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2823,7 +3022,7 @@ relativeError)); static float MAXReduceAllMasked(float[] a, boolean[] mask) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2843,7 +3042,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3055,7 +3254,7 @@ relativeError)); } static boolean testIS_FINITE(float a) { - return Float.isFinite(a); + return isFinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3096,7 +3295,7 @@ relativeError)); } static boolean testIS_NAN(float a) { - return Float.isNaN(a); + return isNaN(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3137,7 +3336,7 @@ relativeError)); } static boolean testIS_INFINITE(float a) { - return Float.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3478,7 +3677,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3498,7 +3697,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3514,7 +3713,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (float)((long)b[i]))); } } } @@ -3534,7 +3733,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (float)((long)b[i])))); } } } @@ -3550,7 +3749,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3570,7 +3769,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3586,7 +3785,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (float)((long)b[i]))); } } } @@ -3606,7 +3805,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (float)((long)b[i])))); } } } @@ -4106,11 +4305,11 @@ relativeError)); } static float SIN(float a) { - return (float)(Math.sin((double)a)); + return (float)(scalar_sin(a)); } static float strictSIN(float a) { - return (float)(StrictMath.sin((double)a)); + return (float)(strict_scalar_sin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4129,11 +4328,11 @@ relativeError)); } static float EXP(float a) { - return (float)(Math.exp((double)a)); + return (float)(scalar_exp(a)); } static float strictEXP(float a) { - return (float)(StrictMath.exp((double)a)); + return (float)(strict_scalar_exp(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4152,11 +4351,11 @@ relativeError)); } static float LOG1P(float a) { - return (float)(Math.log1p((double)a)); + return (float)(scalar_log1p(a)); } static float strictLOG1P(float a) { - return (float)(StrictMath.log1p((double)a)); + return (float)(strict_scalar_log1p(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4175,11 +4374,11 @@ relativeError)); } static float LOG(float a) { - return (float)(Math.log((double)a)); + return (float)(scalar_log(a)); } static float strictLOG(float a) { - return (float)(StrictMath.log((double)a)); + return (float)(strict_scalar_log(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4198,11 +4397,11 @@ relativeError)); } static float LOG10(float a) { - return (float)(Math.log10((double)a)); + return (float)(scalar_log10(a)); } static float strictLOG10(float a) { - return (float)(StrictMath.log10((double)a)); + return (float)(strict_scalar_log10(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4221,11 +4420,11 @@ relativeError)); } static float EXPM1(float a) { - return (float)(Math.expm1((double)a)); + return (float)(scalar_expm1(a)); } static float strictEXPM1(float a) { - return (float)(StrictMath.expm1((double)a)); + return (float)(strict_scalar_expm1(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4244,11 +4443,11 @@ relativeError)); } static float COS(float a) { - return (float)(Math.cos((double)a)); + return (float)(scalar_cos(a)); } static float strictCOS(float a) { - return (float)(StrictMath.cos((double)a)); + return (float)(strict_scalar_cos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4267,11 +4466,11 @@ relativeError)); } static float TAN(float a) { - return (float)(Math.tan((double)a)); + return (float)(scalar_tan(a)); } static float strictTAN(float a) { - return (float)(StrictMath.tan((double)a)); + return (float)(strict_scalar_tan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4290,11 +4489,11 @@ relativeError)); } static float SINH(float a) { - return (float)(Math.sinh((double)a)); + return (float)(scalar_sinh(a)); } static float strictSINH(float a) { - return (float)(StrictMath.sinh((double)a)); + return (float)(strict_scalar_sinh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4313,11 +4512,11 @@ relativeError)); } static float COSH(float a) { - return (float)(Math.cosh((double)a)); + return (float)(scalar_cosh(a)); } static float strictCOSH(float a) { - return (float)(StrictMath.cosh((double)a)); + return (float)(strict_scalar_cosh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4336,11 +4535,11 @@ relativeError)); } static float TANH(float a) { - return (float)(Math.tanh((double)a)); + return (float)(scalar_tanh(a)); } static float strictTANH(float a) { - return (float)(StrictMath.tanh((double)a)); + return (float)(strict_scalar_tanh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4359,11 +4558,11 @@ relativeError)); } static float ASIN(float a) { - return (float)(Math.asin((double)a)); + return (float)(scalar_asin(a)); } static float strictASIN(float a) { - return (float)(StrictMath.asin((double)a)); + return (float)(strict_scalar_asin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4382,11 +4581,11 @@ relativeError)); } static float ACOS(float a) { - return (float)(Math.acos((double)a)); + return (float)(scalar_acos(a)); } static float strictACOS(float a) { - return (float)(StrictMath.acos((double)a)); + return (float)(strict_scalar_acos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4405,11 +4604,11 @@ relativeError)); } static float ATAN(float a) { - return (float)(Math.atan((double)a)); + return (float)(scalar_atan(a)); } static float strictATAN(float a) { - return (float)(StrictMath.atan((double)a)); + return (float)(strict_scalar_atan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4428,11 +4627,11 @@ relativeError)); } static float CBRT(float a) { - return (float)(Math.cbrt((double)a)); + return (float)(scalar_cbrt(a)); } static float strictCBRT(float a) { - return (float)(StrictMath.cbrt((double)a)); + return (float)(strict_scalar_cbrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4451,11 +4650,11 @@ relativeError)); } static float HYPOT(float a, float b) { - return (float)(Math.hypot((double)a, (double)b)); + return (float)(scalar_hypot(a, b)); } static float strictHYPOT(float a, float b) { - return (float)(StrictMath.hypot((double)a, (double)b)); + return (float)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4477,11 +4676,11 @@ relativeError)); static float POW(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictPOW(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4503,11 +4702,11 @@ relativeError)); static float pow(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictpow(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4529,11 +4728,11 @@ relativeError)); static float ATAN2(float a, float b) { - return (float)(Math.atan2((double)a, (double)b)); + return (float)(scalar_atan2(a, b)); } static float strictATAN2(float a, float b) { - return (float)(StrictMath.atan2((double)a, (double)b)); + return (float)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4585,11 +4784,11 @@ relativeError)); static float FMA(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } static float fma(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } @Test(dataProvider = "floatTernaryOpProvider") @@ -4767,11 +4966,11 @@ relativeError)); } static float NEG(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } static float neg(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4823,11 +5022,11 @@ relativeError)); } static float ABS(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } static float abs(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4879,11 +5078,11 @@ relativeError)); } static float SQRT(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } static float sqrt(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -5096,7 +5295,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5112,7 +5311,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5181,7 +5380,7 @@ relativeError)); static long ADDReduceLong(float[] a, int idx) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5190,7 +5389,7 @@ relativeError)); static long ADDReduceAllLong(float[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((float)res, (float)ADDReduceLong(a, i)); } return res; @@ -5208,8 +5407,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5219,8 +5418,9 @@ relativeError)); static long ADDReduceLongMasked(float[] a, int idx, boolean[] mask) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5229,7 +5429,7 @@ relativeError)); static long ADDReduceAllLongMasked(float[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((float)res, (float)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5249,8 +5449,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/FloatVector256Tests.java b/test/jdk/jdk/incubator/vector/FloatVector256Tests.java index b7d16ecc7f7..5315b69a5b6 100644 --- a/test/jdk/jdk/incubator/vector/FloatVector256Tests.java +++ b/test/jdk/jdk/incubator/vector/FloatVector256Tests.java @@ -1601,6 +1601,205 @@ relativeError)); return Float.compare(a, (float) 0) != 0 ? a : b; } + + static float scalar_add(float a, float b) { + return (float)(a + b); + } + + static float scalar_sub(float a, float b) { + return (float)(a - b); + } + + static float scalar_mul(float a, float b) { + return (float)(a * b); + } + + static float scalar_min(float a, float b) { + return (float)(Math.min(a, b)); + } + + static float scalar_max(float a, float b) { + return (float)(Math.max(a, b)); + } + + static float scalar_div(float a, float b) { + return (float)(a / b); + } + + static float scalar_fma(float a, float b, float c) { + return (float)(Math.fma(a, b, c)); + } + + static float scalar_abs(float a) { + return (float)(Math.abs(a)); + } + + static float scalar_neg(float a) { + return ((float)-a); + } + + static float scalar_sin(float a) { + return (float)Math.sin((double)a); + } + + static float scalar_exp(float a) { + return (float)Math.exp((double)a); + } + + static float scalar_log1p(float a) { + return (float)Math.log1p((double)a); + } + + static float scalar_log(float a) { + return (float)Math.log((double)a); + } + + static float scalar_log10(float a) { + return (float)Math.log10((double)a); + } + + static float scalar_expm1(float a) { + return (float)Math.expm1((double)a); + } + + static float scalar_cos(float a) { + return (float)Math.cos((double)a); + } + + static float scalar_tan(float a) { + return (float)Math.tan((double)a); + } + + static float scalar_sinh(float a) { + return (float)Math.sinh((double)a); + } + + static float scalar_cosh(float a) { + return (float)Math.cosh((double)a); + } + + static float scalar_tanh(float a) { + return (float)Math.tanh((double)a); + } + + static float scalar_asin(float a) { + return (float)Math.asin((double)a); + } + + static float scalar_acos(float a) { + return (float)Math.acos((double)a); + } + + static float scalar_atan(float a) { + return (float)Math.atan((double)a); + } + + static float scalar_cbrt(float a) { + return (float)Math.cbrt((double)a); + } + + static float scalar_sqrt(float a) { + return (float)Math.sqrt((double)a); + } + + static float scalar_hypot(float a, float b) { + return (float)Math.hypot((double)a, (double)b); + } + + static float scalar_pow(float a, float b) { + return (float)Math.pow((double)a, (double)b); + } + + static float scalar_atan2(float a, float b) { + return (float)Math.atan2((double)a, (double)b); + } + + static float strict_scalar_sin(float a) { + return (float)StrictMath.sin((double)a); + } + + static float strict_scalar_exp(float a) { + return (float)StrictMath.exp((double)a); + } + + static float strict_scalar_log1p(float a) { + return (float)StrictMath.log1p((double)a); + } + + static float strict_scalar_log(float a) { + return (float)StrictMath.log((double)a); + } + + static float strict_scalar_log10(float a) { + return (float)StrictMath.log10((double)a); + } + + static float strict_scalar_expm1(float a) { + return (float)StrictMath.expm1((double)a); + } + + static float strict_scalar_cos(float a) { + return (float)StrictMath.cos((double)a); + } + + static float strict_scalar_tan(float a) { + return (float)StrictMath.tan((double)a); + } + + static float strict_scalar_sinh(float a) { + return (float)StrictMath.sinh((double)a); + } + + static float strict_scalar_cosh(float a) { + return (float)StrictMath.cosh((double)a); + } + + static float strict_scalar_tanh(float a) { + return (float)StrictMath.tanh((double)a); + } + + static float strict_scalar_asin(float a) { + return (float)StrictMath.asin((double)a); + } + + static float strict_scalar_acos(float a) { + return (float)StrictMath.acos((double)a); + } + + static float strict_scalar_atan(float a) { + return (float)StrictMath.atan((double)a); + } + + static float strict_scalar_cbrt(float a) { + return (float)StrictMath.cbrt((double)a); + } + + static float strict_scalar_sqrt(float a) { + return (float)StrictMath.sqrt((double)a); + } + + static float strict_scalar_hypot(float a, float b) { + return (float)StrictMath.hypot((double)a, (double)b); + } + + static float strict_scalar_pow(float a, float b) { + return (float)StrictMath.pow((double)a, (double)b); + } + + static float strict_scalar_atan2(float a, float b) { + return (float)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(float a) { + return Float.isNaN(a); + } + static boolean isFinite(float a) { + return Float.isFinite(a); + } + static boolean isInfinite(float a) { + return Float.isInfinite(a); + } + @Test static void smokeTest1() { FloatVector three = FloatVector.broadcast(SPECIES, (byte)-3); @@ -1694,7 +1893,7 @@ relativeError)); } static float ADD(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1715,7 +1914,7 @@ relativeError)); } static float add(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1772,7 +1971,7 @@ relativeError)); } static float SUB(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1793,7 +1992,7 @@ relativeError)); } static float sub(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1850,7 +2049,7 @@ relativeError)); } static float MUL(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1871,7 +2070,7 @@ relativeError)); } static float mul(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1928,7 +2127,7 @@ relativeError)); } static float DIV(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1949,7 +2148,7 @@ relativeError)); } static float div(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2006,7 +2205,7 @@ relativeError)); } static float FIRST_NONZERO(float a, float b) { - return (float)(Double.doubleToLongBits(a)!=0?a:b); + return (float)(firstNonZero(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2308,7 +2507,7 @@ relativeError)); } static float MIN(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2329,7 +2528,7 @@ relativeError)); } static float min(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2348,7 +2547,7 @@ relativeError)); } static float MAX(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2369,7 +2568,7 @@ relativeError)); } static float max(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2446,7 +2645,7 @@ relativeError)); static float ADDReduce(float[] a, int idx) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2455,7 +2654,7 @@ relativeError)); static float ADDReduceAll(float[] a) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2473,7 +2672,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2486,20 +2685,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = ADD_IDENTITY; - assertEquals((float) (id + id), id, + assertEquals((float) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id + x), x); - assertEquals((float) (x + id), x); + assertEquals((float) (scalar_add(id, x)), x); + assertEquals((float) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id + x), x, + assertEquals((float) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x + id), x, + assertEquals((float) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2508,7 +2707,7 @@ relativeError)); float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2517,7 +2716,7 @@ relativeError)); static float ADDReduceAllMasked(float[] a, boolean[] mask) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2537,7 +2736,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2548,7 +2747,7 @@ relativeError)); static float MULReduce(float[] a, int idx) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2557,7 +2756,7 @@ relativeError)); static float MULReduceAll(float[] a) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2575,7 +2774,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2588,20 +2787,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MUL_IDENTITY; - assertEquals((float) (id * id), id, + assertEquals((float) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id * x), x); - assertEquals((float) (x * id), x); + assertEquals((float) (scalar_mul(id, x)), x); + assertEquals((float) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id * x), x, + assertEquals((float) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x * id), x, + assertEquals((float) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2610,7 +2809,7 @@ relativeError)); float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2619,7 +2818,7 @@ relativeError)); static float MULReduceAllMasked(float[] a, boolean[] mask) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2639,7 +2838,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2650,7 +2849,7 @@ relativeError)); static float MINReduce(float[] a, int idx) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2659,7 +2858,7 @@ relativeError)); static float MINReduceAll(float[] a) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2677,7 +2876,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2690,20 +2889,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MIN_IDENTITY; - assertEquals((float) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.min(id, x), x); - assertEquals((float) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2712,7 +2911,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2721,7 +2920,7 @@ relativeError)); static float MINReduceAllMasked(float[] a, boolean[] mask) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2741,7 +2940,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2752,7 +2951,7 @@ relativeError)); static float MAXReduce(float[] a, int idx) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2761,7 +2960,7 @@ relativeError)); static float MAXReduceAll(float[] a) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2779,7 +2978,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2792,20 +2991,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MAX_IDENTITY; - assertEquals((float) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.max(id, x), x); - assertEquals((float) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2814,7 +3013,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2823,7 +3022,7 @@ relativeError)); static float MAXReduceAllMasked(float[] a, boolean[] mask) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2843,7 +3042,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3055,7 +3254,7 @@ relativeError)); } static boolean testIS_FINITE(float a) { - return Float.isFinite(a); + return isFinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3096,7 +3295,7 @@ relativeError)); } static boolean testIS_NAN(float a) { - return Float.isNaN(a); + return isNaN(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3137,7 +3336,7 @@ relativeError)); } static boolean testIS_INFINITE(float a) { - return Float.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3478,7 +3677,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3498,7 +3697,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3514,7 +3713,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (float)((long)b[i]))); } } } @@ -3534,7 +3733,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (float)((long)b[i])))); } } } @@ -3550,7 +3749,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3570,7 +3769,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3586,7 +3785,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (float)((long)b[i]))); } } } @@ -3606,7 +3805,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (float)((long)b[i])))); } } } @@ -4106,11 +4305,11 @@ relativeError)); } static float SIN(float a) { - return (float)(Math.sin((double)a)); + return (float)(scalar_sin(a)); } static float strictSIN(float a) { - return (float)(StrictMath.sin((double)a)); + return (float)(strict_scalar_sin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4129,11 +4328,11 @@ relativeError)); } static float EXP(float a) { - return (float)(Math.exp((double)a)); + return (float)(scalar_exp(a)); } static float strictEXP(float a) { - return (float)(StrictMath.exp((double)a)); + return (float)(strict_scalar_exp(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4152,11 +4351,11 @@ relativeError)); } static float LOG1P(float a) { - return (float)(Math.log1p((double)a)); + return (float)(scalar_log1p(a)); } static float strictLOG1P(float a) { - return (float)(StrictMath.log1p((double)a)); + return (float)(strict_scalar_log1p(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4175,11 +4374,11 @@ relativeError)); } static float LOG(float a) { - return (float)(Math.log((double)a)); + return (float)(scalar_log(a)); } static float strictLOG(float a) { - return (float)(StrictMath.log((double)a)); + return (float)(strict_scalar_log(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4198,11 +4397,11 @@ relativeError)); } static float LOG10(float a) { - return (float)(Math.log10((double)a)); + return (float)(scalar_log10(a)); } static float strictLOG10(float a) { - return (float)(StrictMath.log10((double)a)); + return (float)(strict_scalar_log10(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4221,11 +4420,11 @@ relativeError)); } static float EXPM1(float a) { - return (float)(Math.expm1((double)a)); + return (float)(scalar_expm1(a)); } static float strictEXPM1(float a) { - return (float)(StrictMath.expm1((double)a)); + return (float)(strict_scalar_expm1(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4244,11 +4443,11 @@ relativeError)); } static float COS(float a) { - return (float)(Math.cos((double)a)); + return (float)(scalar_cos(a)); } static float strictCOS(float a) { - return (float)(StrictMath.cos((double)a)); + return (float)(strict_scalar_cos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4267,11 +4466,11 @@ relativeError)); } static float TAN(float a) { - return (float)(Math.tan((double)a)); + return (float)(scalar_tan(a)); } static float strictTAN(float a) { - return (float)(StrictMath.tan((double)a)); + return (float)(strict_scalar_tan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4290,11 +4489,11 @@ relativeError)); } static float SINH(float a) { - return (float)(Math.sinh((double)a)); + return (float)(scalar_sinh(a)); } static float strictSINH(float a) { - return (float)(StrictMath.sinh((double)a)); + return (float)(strict_scalar_sinh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4313,11 +4512,11 @@ relativeError)); } static float COSH(float a) { - return (float)(Math.cosh((double)a)); + return (float)(scalar_cosh(a)); } static float strictCOSH(float a) { - return (float)(StrictMath.cosh((double)a)); + return (float)(strict_scalar_cosh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4336,11 +4535,11 @@ relativeError)); } static float TANH(float a) { - return (float)(Math.tanh((double)a)); + return (float)(scalar_tanh(a)); } static float strictTANH(float a) { - return (float)(StrictMath.tanh((double)a)); + return (float)(strict_scalar_tanh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4359,11 +4558,11 @@ relativeError)); } static float ASIN(float a) { - return (float)(Math.asin((double)a)); + return (float)(scalar_asin(a)); } static float strictASIN(float a) { - return (float)(StrictMath.asin((double)a)); + return (float)(strict_scalar_asin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4382,11 +4581,11 @@ relativeError)); } static float ACOS(float a) { - return (float)(Math.acos((double)a)); + return (float)(scalar_acos(a)); } static float strictACOS(float a) { - return (float)(StrictMath.acos((double)a)); + return (float)(strict_scalar_acos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4405,11 +4604,11 @@ relativeError)); } static float ATAN(float a) { - return (float)(Math.atan((double)a)); + return (float)(scalar_atan(a)); } static float strictATAN(float a) { - return (float)(StrictMath.atan((double)a)); + return (float)(strict_scalar_atan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4428,11 +4627,11 @@ relativeError)); } static float CBRT(float a) { - return (float)(Math.cbrt((double)a)); + return (float)(scalar_cbrt(a)); } static float strictCBRT(float a) { - return (float)(StrictMath.cbrt((double)a)); + return (float)(strict_scalar_cbrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4451,11 +4650,11 @@ relativeError)); } static float HYPOT(float a, float b) { - return (float)(Math.hypot((double)a, (double)b)); + return (float)(scalar_hypot(a, b)); } static float strictHYPOT(float a, float b) { - return (float)(StrictMath.hypot((double)a, (double)b)); + return (float)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4477,11 +4676,11 @@ relativeError)); static float POW(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictPOW(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4503,11 +4702,11 @@ relativeError)); static float pow(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictpow(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4529,11 +4728,11 @@ relativeError)); static float ATAN2(float a, float b) { - return (float)(Math.atan2((double)a, (double)b)); + return (float)(scalar_atan2(a, b)); } static float strictATAN2(float a, float b) { - return (float)(StrictMath.atan2((double)a, (double)b)); + return (float)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4585,11 +4784,11 @@ relativeError)); static float FMA(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } static float fma(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } @Test(dataProvider = "floatTernaryOpProvider") @@ -4767,11 +4966,11 @@ relativeError)); } static float NEG(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } static float neg(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4823,11 +5022,11 @@ relativeError)); } static float ABS(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } static float abs(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4879,11 +5078,11 @@ relativeError)); } static float SQRT(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } static float sqrt(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -5096,7 +5295,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5112,7 +5311,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5181,7 +5380,7 @@ relativeError)); static long ADDReduceLong(float[] a, int idx) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5190,7 +5389,7 @@ relativeError)); static long ADDReduceAllLong(float[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((float)res, (float)ADDReduceLong(a, i)); } return res; @@ -5208,8 +5407,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5219,8 +5418,9 @@ relativeError)); static long ADDReduceLongMasked(float[] a, int idx, boolean[] mask) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5229,7 +5429,7 @@ relativeError)); static long ADDReduceAllLongMasked(float[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((float)res, (float)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5249,8 +5449,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/FloatVector512Tests.java b/test/jdk/jdk/incubator/vector/FloatVector512Tests.java index 17493778826..6a958511439 100644 --- a/test/jdk/jdk/incubator/vector/FloatVector512Tests.java +++ b/test/jdk/jdk/incubator/vector/FloatVector512Tests.java @@ -1601,6 +1601,205 @@ relativeError)); return Float.compare(a, (float) 0) != 0 ? a : b; } + + static float scalar_add(float a, float b) { + return (float)(a + b); + } + + static float scalar_sub(float a, float b) { + return (float)(a - b); + } + + static float scalar_mul(float a, float b) { + return (float)(a * b); + } + + static float scalar_min(float a, float b) { + return (float)(Math.min(a, b)); + } + + static float scalar_max(float a, float b) { + return (float)(Math.max(a, b)); + } + + static float scalar_div(float a, float b) { + return (float)(a / b); + } + + static float scalar_fma(float a, float b, float c) { + return (float)(Math.fma(a, b, c)); + } + + static float scalar_abs(float a) { + return (float)(Math.abs(a)); + } + + static float scalar_neg(float a) { + return ((float)-a); + } + + static float scalar_sin(float a) { + return (float)Math.sin((double)a); + } + + static float scalar_exp(float a) { + return (float)Math.exp((double)a); + } + + static float scalar_log1p(float a) { + return (float)Math.log1p((double)a); + } + + static float scalar_log(float a) { + return (float)Math.log((double)a); + } + + static float scalar_log10(float a) { + return (float)Math.log10((double)a); + } + + static float scalar_expm1(float a) { + return (float)Math.expm1((double)a); + } + + static float scalar_cos(float a) { + return (float)Math.cos((double)a); + } + + static float scalar_tan(float a) { + return (float)Math.tan((double)a); + } + + static float scalar_sinh(float a) { + return (float)Math.sinh((double)a); + } + + static float scalar_cosh(float a) { + return (float)Math.cosh((double)a); + } + + static float scalar_tanh(float a) { + return (float)Math.tanh((double)a); + } + + static float scalar_asin(float a) { + return (float)Math.asin((double)a); + } + + static float scalar_acos(float a) { + return (float)Math.acos((double)a); + } + + static float scalar_atan(float a) { + return (float)Math.atan((double)a); + } + + static float scalar_cbrt(float a) { + return (float)Math.cbrt((double)a); + } + + static float scalar_sqrt(float a) { + return (float)Math.sqrt((double)a); + } + + static float scalar_hypot(float a, float b) { + return (float)Math.hypot((double)a, (double)b); + } + + static float scalar_pow(float a, float b) { + return (float)Math.pow((double)a, (double)b); + } + + static float scalar_atan2(float a, float b) { + return (float)Math.atan2((double)a, (double)b); + } + + static float strict_scalar_sin(float a) { + return (float)StrictMath.sin((double)a); + } + + static float strict_scalar_exp(float a) { + return (float)StrictMath.exp((double)a); + } + + static float strict_scalar_log1p(float a) { + return (float)StrictMath.log1p((double)a); + } + + static float strict_scalar_log(float a) { + return (float)StrictMath.log((double)a); + } + + static float strict_scalar_log10(float a) { + return (float)StrictMath.log10((double)a); + } + + static float strict_scalar_expm1(float a) { + return (float)StrictMath.expm1((double)a); + } + + static float strict_scalar_cos(float a) { + return (float)StrictMath.cos((double)a); + } + + static float strict_scalar_tan(float a) { + return (float)StrictMath.tan((double)a); + } + + static float strict_scalar_sinh(float a) { + return (float)StrictMath.sinh((double)a); + } + + static float strict_scalar_cosh(float a) { + return (float)StrictMath.cosh((double)a); + } + + static float strict_scalar_tanh(float a) { + return (float)StrictMath.tanh((double)a); + } + + static float strict_scalar_asin(float a) { + return (float)StrictMath.asin((double)a); + } + + static float strict_scalar_acos(float a) { + return (float)StrictMath.acos((double)a); + } + + static float strict_scalar_atan(float a) { + return (float)StrictMath.atan((double)a); + } + + static float strict_scalar_cbrt(float a) { + return (float)StrictMath.cbrt((double)a); + } + + static float strict_scalar_sqrt(float a) { + return (float)StrictMath.sqrt((double)a); + } + + static float strict_scalar_hypot(float a, float b) { + return (float)StrictMath.hypot((double)a, (double)b); + } + + static float strict_scalar_pow(float a, float b) { + return (float)StrictMath.pow((double)a, (double)b); + } + + static float strict_scalar_atan2(float a, float b) { + return (float)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(float a) { + return Float.isNaN(a); + } + static boolean isFinite(float a) { + return Float.isFinite(a); + } + static boolean isInfinite(float a) { + return Float.isInfinite(a); + } + @Test static void smokeTest1() { FloatVector three = FloatVector.broadcast(SPECIES, (byte)-3); @@ -1694,7 +1893,7 @@ relativeError)); } static float ADD(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1715,7 +1914,7 @@ relativeError)); } static float add(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1772,7 +1971,7 @@ relativeError)); } static float SUB(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1793,7 +1992,7 @@ relativeError)); } static float sub(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1850,7 +2049,7 @@ relativeError)); } static float MUL(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1871,7 +2070,7 @@ relativeError)); } static float mul(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1928,7 +2127,7 @@ relativeError)); } static float DIV(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1949,7 +2148,7 @@ relativeError)); } static float div(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2006,7 +2205,7 @@ relativeError)); } static float FIRST_NONZERO(float a, float b) { - return (float)(Double.doubleToLongBits(a)!=0?a:b); + return (float)(firstNonZero(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2308,7 +2507,7 @@ relativeError)); } static float MIN(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2329,7 +2528,7 @@ relativeError)); } static float min(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2348,7 +2547,7 @@ relativeError)); } static float MAX(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2369,7 +2568,7 @@ relativeError)); } static float max(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2446,7 +2645,7 @@ relativeError)); static float ADDReduce(float[] a, int idx) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2455,7 +2654,7 @@ relativeError)); static float ADDReduceAll(float[] a) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2473,7 +2672,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2486,20 +2685,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = ADD_IDENTITY; - assertEquals((float) (id + id), id, + assertEquals((float) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id + x), x); - assertEquals((float) (x + id), x); + assertEquals((float) (scalar_add(id, x)), x); + assertEquals((float) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id + x), x, + assertEquals((float) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x + id), x, + assertEquals((float) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2508,7 +2707,7 @@ relativeError)); float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2517,7 +2716,7 @@ relativeError)); static float ADDReduceAllMasked(float[] a, boolean[] mask) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2537,7 +2736,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2548,7 +2747,7 @@ relativeError)); static float MULReduce(float[] a, int idx) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2557,7 +2756,7 @@ relativeError)); static float MULReduceAll(float[] a) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2575,7 +2774,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2588,20 +2787,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MUL_IDENTITY; - assertEquals((float) (id * id), id, + assertEquals((float) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id * x), x); - assertEquals((float) (x * id), x); + assertEquals((float) (scalar_mul(id, x)), x); + assertEquals((float) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id * x), x, + assertEquals((float) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x * id), x, + assertEquals((float) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2610,7 +2809,7 @@ relativeError)); float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2619,7 +2818,7 @@ relativeError)); static float MULReduceAllMasked(float[] a, boolean[] mask) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2639,7 +2838,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2650,7 +2849,7 @@ relativeError)); static float MINReduce(float[] a, int idx) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2659,7 +2858,7 @@ relativeError)); static float MINReduceAll(float[] a) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2677,7 +2876,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2690,20 +2889,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MIN_IDENTITY; - assertEquals((float) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.min(id, x), x); - assertEquals((float) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2712,7 +2911,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2721,7 +2920,7 @@ relativeError)); static float MINReduceAllMasked(float[] a, boolean[] mask) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2741,7 +2940,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2752,7 +2951,7 @@ relativeError)); static float MAXReduce(float[] a, int idx) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2761,7 +2960,7 @@ relativeError)); static float MAXReduceAll(float[] a) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2779,7 +2978,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2792,20 +2991,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MAX_IDENTITY; - assertEquals((float) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.max(id, x), x); - assertEquals((float) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2814,7 +3013,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2823,7 +3022,7 @@ relativeError)); static float MAXReduceAllMasked(float[] a, boolean[] mask) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2843,7 +3042,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3055,7 +3254,7 @@ relativeError)); } static boolean testIS_FINITE(float a) { - return Float.isFinite(a); + return isFinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3096,7 +3295,7 @@ relativeError)); } static boolean testIS_NAN(float a) { - return Float.isNaN(a); + return isNaN(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3137,7 +3336,7 @@ relativeError)); } static boolean testIS_INFINITE(float a) { - return Float.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3478,7 +3677,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3498,7 +3697,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3514,7 +3713,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (float)((long)b[i]))); } } } @@ -3534,7 +3733,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (float)((long)b[i])))); } } } @@ -3550,7 +3749,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3570,7 +3769,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3586,7 +3785,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (float)((long)b[i]))); } } } @@ -3606,7 +3805,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (float)((long)b[i])))); } } } @@ -4106,11 +4305,11 @@ relativeError)); } static float SIN(float a) { - return (float)(Math.sin((double)a)); + return (float)(scalar_sin(a)); } static float strictSIN(float a) { - return (float)(StrictMath.sin((double)a)); + return (float)(strict_scalar_sin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4129,11 +4328,11 @@ relativeError)); } static float EXP(float a) { - return (float)(Math.exp((double)a)); + return (float)(scalar_exp(a)); } static float strictEXP(float a) { - return (float)(StrictMath.exp((double)a)); + return (float)(strict_scalar_exp(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4152,11 +4351,11 @@ relativeError)); } static float LOG1P(float a) { - return (float)(Math.log1p((double)a)); + return (float)(scalar_log1p(a)); } static float strictLOG1P(float a) { - return (float)(StrictMath.log1p((double)a)); + return (float)(strict_scalar_log1p(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4175,11 +4374,11 @@ relativeError)); } static float LOG(float a) { - return (float)(Math.log((double)a)); + return (float)(scalar_log(a)); } static float strictLOG(float a) { - return (float)(StrictMath.log((double)a)); + return (float)(strict_scalar_log(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4198,11 +4397,11 @@ relativeError)); } static float LOG10(float a) { - return (float)(Math.log10((double)a)); + return (float)(scalar_log10(a)); } static float strictLOG10(float a) { - return (float)(StrictMath.log10((double)a)); + return (float)(strict_scalar_log10(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4221,11 +4420,11 @@ relativeError)); } static float EXPM1(float a) { - return (float)(Math.expm1((double)a)); + return (float)(scalar_expm1(a)); } static float strictEXPM1(float a) { - return (float)(StrictMath.expm1((double)a)); + return (float)(strict_scalar_expm1(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4244,11 +4443,11 @@ relativeError)); } static float COS(float a) { - return (float)(Math.cos((double)a)); + return (float)(scalar_cos(a)); } static float strictCOS(float a) { - return (float)(StrictMath.cos((double)a)); + return (float)(strict_scalar_cos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4267,11 +4466,11 @@ relativeError)); } static float TAN(float a) { - return (float)(Math.tan((double)a)); + return (float)(scalar_tan(a)); } static float strictTAN(float a) { - return (float)(StrictMath.tan((double)a)); + return (float)(strict_scalar_tan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4290,11 +4489,11 @@ relativeError)); } static float SINH(float a) { - return (float)(Math.sinh((double)a)); + return (float)(scalar_sinh(a)); } static float strictSINH(float a) { - return (float)(StrictMath.sinh((double)a)); + return (float)(strict_scalar_sinh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4313,11 +4512,11 @@ relativeError)); } static float COSH(float a) { - return (float)(Math.cosh((double)a)); + return (float)(scalar_cosh(a)); } static float strictCOSH(float a) { - return (float)(StrictMath.cosh((double)a)); + return (float)(strict_scalar_cosh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4336,11 +4535,11 @@ relativeError)); } static float TANH(float a) { - return (float)(Math.tanh((double)a)); + return (float)(scalar_tanh(a)); } static float strictTANH(float a) { - return (float)(StrictMath.tanh((double)a)); + return (float)(strict_scalar_tanh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4359,11 +4558,11 @@ relativeError)); } static float ASIN(float a) { - return (float)(Math.asin((double)a)); + return (float)(scalar_asin(a)); } static float strictASIN(float a) { - return (float)(StrictMath.asin((double)a)); + return (float)(strict_scalar_asin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4382,11 +4581,11 @@ relativeError)); } static float ACOS(float a) { - return (float)(Math.acos((double)a)); + return (float)(scalar_acos(a)); } static float strictACOS(float a) { - return (float)(StrictMath.acos((double)a)); + return (float)(strict_scalar_acos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4405,11 +4604,11 @@ relativeError)); } static float ATAN(float a) { - return (float)(Math.atan((double)a)); + return (float)(scalar_atan(a)); } static float strictATAN(float a) { - return (float)(StrictMath.atan((double)a)); + return (float)(strict_scalar_atan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4428,11 +4627,11 @@ relativeError)); } static float CBRT(float a) { - return (float)(Math.cbrt((double)a)); + return (float)(scalar_cbrt(a)); } static float strictCBRT(float a) { - return (float)(StrictMath.cbrt((double)a)); + return (float)(strict_scalar_cbrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4451,11 +4650,11 @@ relativeError)); } static float HYPOT(float a, float b) { - return (float)(Math.hypot((double)a, (double)b)); + return (float)(scalar_hypot(a, b)); } static float strictHYPOT(float a, float b) { - return (float)(StrictMath.hypot((double)a, (double)b)); + return (float)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4477,11 +4676,11 @@ relativeError)); static float POW(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictPOW(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4503,11 +4702,11 @@ relativeError)); static float pow(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictpow(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4529,11 +4728,11 @@ relativeError)); static float ATAN2(float a, float b) { - return (float)(Math.atan2((double)a, (double)b)); + return (float)(scalar_atan2(a, b)); } static float strictATAN2(float a, float b) { - return (float)(StrictMath.atan2((double)a, (double)b)); + return (float)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4585,11 +4784,11 @@ relativeError)); static float FMA(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } static float fma(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } @Test(dataProvider = "floatTernaryOpProvider") @@ -4767,11 +4966,11 @@ relativeError)); } static float NEG(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } static float neg(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4823,11 +5022,11 @@ relativeError)); } static float ABS(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } static float abs(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4879,11 +5078,11 @@ relativeError)); } static float SQRT(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } static float sqrt(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -5096,7 +5295,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5112,7 +5311,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5181,7 +5380,7 @@ relativeError)); static long ADDReduceLong(float[] a, int idx) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5190,7 +5389,7 @@ relativeError)); static long ADDReduceAllLong(float[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((float)res, (float)ADDReduceLong(a, i)); } return res; @@ -5208,8 +5407,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5219,8 +5418,9 @@ relativeError)); static long ADDReduceLongMasked(float[] a, int idx, boolean[] mask) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5229,7 +5429,7 @@ relativeError)); static long ADDReduceAllLongMasked(float[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((float)res, (float)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5249,8 +5449,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/FloatVector64Tests.java b/test/jdk/jdk/incubator/vector/FloatVector64Tests.java index 663a56dfe26..b06dff18194 100644 --- a/test/jdk/jdk/incubator/vector/FloatVector64Tests.java +++ b/test/jdk/jdk/incubator/vector/FloatVector64Tests.java @@ -1601,6 +1601,205 @@ relativeError)); return Float.compare(a, (float) 0) != 0 ? a : b; } + + static float scalar_add(float a, float b) { + return (float)(a + b); + } + + static float scalar_sub(float a, float b) { + return (float)(a - b); + } + + static float scalar_mul(float a, float b) { + return (float)(a * b); + } + + static float scalar_min(float a, float b) { + return (float)(Math.min(a, b)); + } + + static float scalar_max(float a, float b) { + return (float)(Math.max(a, b)); + } + + static float scalar_div(float a, float b) { + return (float)(a / b); + } + + static float scalar_fma(float a, float b, float c) { + return (float)(Math.fma(a, b, c)); + } + + static float scalar_abs(float a) { + return (float)(Math.abs(a)); + } + + static float scalar_neg(float a) { + return ((float)-a); + } + + static float scalar_sin(float a) { + return (float)Math.sin((double)a); + } + + static float scalar_exp(float a) { + return (float)Math.exp((double)a); + } + + static float scalar_log1p(float a) { + return (float)Math.log1p((double)a); + } + + static float scalar_log(float a) { + return (float)Math.log((double)a); + } + + static float scalar_log10(float a) { + return (float)Math.log10((double)a); + } + + static float scalar_expm1(float a) { + return (float)Math.expm1((double)a); + } + + static float scalar_cos(float a) { + return (float)Math.cos((double)a); + } + + static float scalar_tan(float a) { + return (float)Math.tan((double)a); + } + + static float scalar_sinh(float a) { + return (float)Math.sinh((double)a); + } + + static float scalar_cosh(float a) { + return (float)Math.cosh((double)a); + } + + static float scalar_tanh(float a) { + return (float)Math.tanh((double)a); + } + + static float scalar_asin(float a) { + return (float)Math.asin((double)a); + } + + static float scalar_acos(float a) { + return (float)Math.acos((double)a); + } + + static float scalar_atan(float a) { + return (float)Math.atan((double)a); + } + + static float scalar_cbrt(float a) { + return (float)Math.cbrt((double)a); + } + + static float scalar_sqrt(float a) { + return (float)Math.sqrt((double)a); + } + + static float scalar_hypot(float a, float b) { + return (float)Math.hypot((double)a, (double)b); + } + + static float scalar_pow(float a, float b) { + return (float)Math.pow((double)a, (double)b); + } + + static float scalar_atan2(float a, float b) { + return (float)Math.atan2((double)a, (double)b); + } + + static float strict_scalar_sin(float a) { + return (float)StrictMath.sin((double)a); + } + + static float strict_scalar_exp(float a) { + return (float)StrictMath.exp((double)a); + } + + static float strict_scalar_log1p(float a) { + return (float)StrictMath.log1p((double)a); + } + + static float strict_scalar_log(float a) { + return (float)StrictMath.log((double)a); + } + + static float strict_scalar_log10(float a) { + return (float)StrictMath.log10((double)a); + } + + static float strict_scalar_expm1(float a) { + return (float)StrictMath.expm1((double)a); + } + + static float strict_scalar_cos(float a) { + return (float)StrictMath.cos((double)a); + } + + static float strict_scalar_tan(float a) { + return (float)StrictMath.tan((double)a); + } + + static float strict_scalar_sinh(float a) { + return (float)StrictMath.sinh((double)a); + } + + static float strict_scalar_cosh(float a) { + return (float)StrictMath.cosh((double)a); + } + + static float strict_scalar_tanh(float a) { + return (float)StrictMath.tanh((double)a); + } + + static float strict_scalar_asin(float a) { + return (float)StrictMath.asin((double)a); + } + + static float strict_scalar_acos(float a) { + return (float)StrictMath.acos((double)a); + } + + static float strict_scalar_atan(float a) { + return (float)StrictMath.atan((double)a); + } + + static float strict_scalar_cbrt(float a) { + return (float)StrictMath.cbrt((double)a); + } + + static float strict_scalar_sqrt(float a) { + return (float)StrictMath.sqrt((double)a); + } + + static float strict_scalar_hypot(float a, float b) { + return (float)StrictMath.hypot((double)a, (double)b); + } + + static float strict_scalar_pow(float a, float b) { + return (float)StrictMath.pow((double)a, (double)b); + } + + static float strict_scalar_atan2(float a, float b) { + return (float)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(float a) { + return Float.isNaN(a); + } + static boolean isFinite(float a) { + return Float.isFinite(a); + } + static boolean isInfinite(float a) { + return Float.isInfinite(a); + } + @Test static void smokeTest1() { FloatVector three = FloatVector.broadcast(SPECIES, (byte)-3); @@ -1694,7 +1893,7 @@ relativeError)); } static float ADD(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1715,7 +1914,7 @@ relativeError)); } static float add(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1772,7 +1971,7 @@ relativeError)); } static float SUB(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1793,7 +1992,7 @@ relativeError)); } static float sub(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1850,7 +2049,7 @@ relativeError)); } static float MUL(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1871,7 +2070,7 @@ relativeError)); } static float mul(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1928,7 +2127,7 @@ relativeError)); } static float DIV(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1949,7 +2148,7 @@ relativeError)); } static float div(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2006,7 +2205,7 @@ relativeError)); } static float FIRST_NONZERO(float a, float b) { - return (float)(Double.doubleToLongBits(a)!=0?a:b); + return (float)(firstNonZero(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2308,7 +2507,7 @@ relativeError)); } static float MIN(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2329,7 +2528,7 @@ relativeError)); } static float min(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2348,7 +2547,7 @@ relativeError)); } static float MAX(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2369,7 +2568,7 @@ relativeError)); } static float max(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2446,7 +2645,7 @@ relativeError)); static float ADDReduce(float[] a, int idx) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2455,7 +2654,7 @@ relativeError)); static float ADDReduceAll(float[] a) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2473,7 +2672,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2486,20 +2685,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = ADD_IDENTITY; - assertEquals((float) (id + id), id, + assertEquals((float) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id + x), x); - assertEquals((float) (x + id), x); + assertEquals((float) (scalar_add(id, x)), x); + assertEquals((float) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id + x), x, + assertEquals((float) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x + id), x, + assertEquals((float) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2508,7 +2707,7 @@ relativeError)); float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2517,7 +2716,7 @@ relativeError)); static float ADDReduceAllMasked(float[] a, boolean[] mask) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2537,7 +2736,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2548,7 +2747,7 @@ relativeError)); static float MULReduce(float[] a, int idx) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2557,7 +2756,7 @@ relativeError)); static float MULReduceAll(float[] a) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2575,7 +2774,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2588,20 +2787,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MUL_IDENTITY; - assertEquals((float) (id * id), id, + assertEquals((float) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id * x), x); - assertEquals((float) (x * id), x); + assertEquals((float) (scalar_mul(id, x)), x); + assertEquals((float) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id * x), x, + assertEquals((float) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x * id), x, + assertEquals((float) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2610,7 +2809,7 @@ relativeError)); float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2619,7 +2818,7 @@ relativeError)); static float MULReduceAllMasked(float[] a, boolean[] mask) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2639,7 +2838,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2650,7 +2849,7 @@ relativeError)); static float MINReduce(float[] a, int idx) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2659,7 +2858,7 @@ relativeError)); static float MINReduceAll(float[] a) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2677,7 +2876,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2690,20 +2889,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MIN_IDENTITY; - assertEquals((float) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.min(id, x), x); - assertEquals((float) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2712,7 +2911,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2721,7 +2920,7 @@ relativeError)); static float MINReduceAllMasked(float[] a, boolean[] mask) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2741,7 +2940,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2752,7 +2951,7 @@ relativeError)); static float MAXReduce(float[] a, int idx) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2761,7 +2960,7 @@ relativeError)); static float MAXReduceAll(float[] a) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2779,7 +2978,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2792,20 +2991,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MAX_IDENTITY; - assertEquals((float) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.max(id, x), x); - assertEquals((float) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2814,7 +3013,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2823,7 +3022,7 @@ relativeError)); static float MAXReduceAllMasked(float[] a, boolean[] mask) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2843,7 +3042,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3055,7 +3254,7 @@ relativeError)); } static boolean testIS_FINITE(float a) { - return Float.isFinite(a); + return isFinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3096,7 +3295,7 @@ relativeError)); } static boolean testIS_NAN(float a) { - return Float.isNaN(a); + return isNaN(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3137,7 +3336,7 @@ relativeError)); } static boolean testIS_INFINITE(float a) { - return Float.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3478,7 +3677,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3498,7 +3697,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3514,7 +3713,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (float)((long)b[i]))); } } } @@ -3534,7 +3733,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (float)((long)b[i])))); } } } @@ -3550,7 +3749,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3570,7 +3769,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3586,7 +3785,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (float)((long)b[i]))); } } } @@ -3606,7 +3805,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (float)((long)b[i])))); } } } @@ -4106,11 +4305,11 @@ relativeError)); } static float SIN(float a) { - return (float)(Math.sin((double)a)); + return (float)(scalar_sin(a)); } static float strictSIN(float a) { - return (float)(StrictMath.sin((double)a)); + return (float)(strict_scalar_sin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4129,11 +4328,11 @@ relativeError)); } static float EXP(float a) { - return (float)(Math.exp((double)a)); + return (float)(scalar_exp(a)); } static float strictEXP(float a) { - return (float)(StrictMath.exp((double)a)); + return (float)(strict_scalar_exp(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4152,11 +4351,11 @@ relativeError)); } static float LOG1P(float a) { - return (float)(Math.log1p((double)a)); + return (float)(scalar_log1p(a)); } static float strictLOG1P(float a) { - return (float)(StrictMath.log1p((double)a)); + return (float)(strict_scalar_log1p(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4175,11 +4374,11 @@ relativeError)); } static float LOG(float a) { - return (float)(Math.log((double)a)); + return (float)(scalar_log(a)); } static float strictLOG(float a) { - return (float)(StrictMath.log((double)a)); + return (float)(strict_scalar_log(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4198,11 +4397,11 @@ relativeError)); } static float LOG10(float a) { - return (float)(Math.log10((double)a)); + return (float)(scalar_log10(a)); } static float strictLOG10(float a) { - return (float)(StrictMath.log10((double)a)); + return (float)(strict_scalar_log10(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4221,11 +4420,11 @@ relativeError)); } static float EXPM1(float a) { - return (float)(Math.expm1((double)a)); + return (float)(scalar_expm1(a)); } static float strictEXPM1(float a) { - return (float)(StrictMath.expm1((double)a)); + return (float)(strict_scalar_expm1(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4244,11 +4443,11 @@ relativeError)); } static float COS(float a) { - return (float)(Math.cos((double)a)); + return (float)(scalar_cos(a)); } static float strictCOS(float a) { - return (float)(StrictMath.cos((double)a)); + return (float)(strict_scalar_cos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4267,11 +4466,11 @@ relativeError)); } static float TAN(float a) { - return (float)(Math.tan((double)a)); + return (float)(scalar_tan(a)); } static float strictTAN(float a) { - return (float)(StrictMath.tan((double)a)); + return (float)(strict_scalar_tan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4290,11 +4489,11 @@ relativeError)); } static float SINH(float a) { - return (float)(Math.sinh((double)a)); + return (float)(scalar_sinh(a)); } static float strictSINH(float a) { - return (float)(StrictMath.sinh((double)a)); + return (float)(strict_scalar_sinh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4313,11 +4512,11 @@ relativeError)); } static float COSH(float a) { - return (float)(Math.cosh((double)a)); + return (float)(scalar_cosh(a)); } static float strictCOSH(float a) { - return (float)(StrictMath.cosh((double)a)); + return (float)(strict_scalar_cosh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4336,11 +4535,11 @@ relativeError)); } static float TANH(float a) { - return (float)(Math.tanh((double)a)); + return (float)(scalar_tanh(a)); } static float strictTANH(float a) { - return (float)(StrictMath.tanh((double)a)); + return (float)(strict_scalar_tanh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4359,11 +4558,11 @@ relativeError)); } static float ASIN(float a) { - return (float)(Math.asin((double)a)); + return (float)(scalar_asin(a)); } static float strictASIN(float a) { - return (float)(StrictMath.asin((double)a)); + return (float)(strict_scalar_asin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4382,11 +4581,11 @@ relativeError)); } static float ACOS(float a) { - return (float)(Math.acos((double)a)); + return (float)(scalar_acos(a)); } static float strictACOS(float a) { - return (float)(StrictMath.acos((double)a)); + return (float)(strict_scalar_acos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4405,11 +4604,11 @@ relativeError)); } static float ATAN(float a) { - return (float)(Math.atan((double)a)); + return (float)(scalar_atan(a)); } static float strictATAN(float a) { - return (float)(StrictMath.atan((double)a)); + return (float)(strict_scalar_atan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4428,11 +4627,11 @@ relativeError)); } static float CBRT(float a) { - return (float)(Math.cbrt((double)a)); + return (float)(scalar_cbrt(a)); } static float strictCBRT(float a) { - return (float)(StrictMath.cbrt((double)a)); + return (float)(strict_scalar_cbrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4451,11 +4650,11 @@ relativeError)); } static float HYPOT(float a, float b) { - return (float)(Math.hypot((double)a, (double)b)); + return (float)(scalar_hypot(a, b)); } static float strictHYPOT(float a, float b) { - return (float)(StrictMath.hypot((double)a, (double)b)); + return (float)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4477,11 +4676,11 @@ relativeError)); static float POW(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictPOW(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4503,11 +4702,11 @@ relativeError)); static float pow(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictpow(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4529,11 +4728,11 @@ relativeError)); static float ATAN2(float a, float b) { - return (float)(Math.atan2((double)a, (double)b)); + return (float)(scalar_atan2(a, b)); } static float strictATAN2(float a, float b) { - return (float)(StrictMath.atan2((double)a, (double)b)); + return (float)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4585,11 +4784,11 @@ relativeError)); static float FMA(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } static float fma(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } @Test(dataProvider = "floatTernaryOpProvider") @@ -4767,11 +4966,11 @@ relativeError)); } static float NEG(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } static float neg(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4823,11 +5022,11 @@ relativeError)); } static float ABS(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } static float abs(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4879,11 +5078,11 @@ relativeError)); } static float SQRT(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } static float sqrt(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -5096,7 +5295,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5112,7 +5311,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5181,7 +5380,7 @@ relativeError)); static long ADDReduceLong(float[] a, int idx) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5190,7 +5389,7 @@ relativeError)); static long ADDReduceAllLong(float[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((float)res, (float)ADDReduceLong(a, i)); } return res; @@ -5208,8 +5407,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5219,8 +5418,9 @@ relativeError)); static long ADDReduceLongMasked(float[] a, int idx, boolean[] mask) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5229,7 +5429,7 @@ relativeError)); static long ADDReduceAllLongMasked(float[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((float)res, (float)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5249,8 +5449,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/FloatVectorMaxTests.java b/test/jdk/jdk/incubator/vector/FloatVectorMaxTests.java index 9d272f43863..9b84e852c1c 100644 --- a/test/jdk/jdk/incubator/vector/FloatVectorMaxTests.java +++ b/test/jdk/jdk/incubator/vector/FloatVectorMaxTests.java @@ -1607,6 +1607,205 @@ relativeError)); return Float.compare(a, (float) 0) != 0 ? a : b; } + + static float scalar_add(float a, float b) { + return (float)(a + b); + } + + static float scalar_sub(float a, float b) { + return (float)(a - b); + } + + static float scalar_mul(float a, float b) { + return (float)(a * b); + } + + static float scalar_min(float a, float b) { + return (float)(Math.min(a, b)); + } + + static float scalar_max(float a, float b) { + return (float)(Math.max(a, b)); + } + + static float scalar_div(float a, float b) { + return (float)(a / b); + } + + static float scalar_fma(float a, float b, float c) { + return (float)(Math.fma(a, b, c)); + } + + static float scalar_abs(float a) { + return (float)(Math.abs(a)); + } + + static float scalar_neg(float a) { + return ((float)-a); + } + + static float scalar_sin(float a) { + return (float)Math.sin((double)a); + } + + static float scalar_exp(float a) { + return (float)Math.exp((double)a); + } + + static float scalar_log1p(float a) { + return (float)Math.log1p((double)a); + } + + static float scalar_log(float a) { + return (float)Math.log((double)a); + } + + static float scalar_log10(float a) { + return (float)Math.log10((double)a); + } + + static float scalar_expm1(float a) { + return (float)Math.expm1((double)a); + } + + static float scalar_cos(float a) { + return (float)Math.cos((double)a); + } + + static float scalar_tan(float a) { + return (float)Math.tan((double)a); + } + + static float scalar_sinh(float a) { + return (float)Math.sinh((double)a); + } + + static float scalar_cosh(float a) { + return (float)Math.cosh((double)a); + } + + static float scalar_tanh(float a) { + return (float)Math.tanh((double)a); + } + + static float scalar_asin(float a) { + return (float)Math.asin((double)a); + } + + static float scalar_acos(float a) { + return (float)Math.acos((double)a); + } + + static float scalar_atan(float a) { + return (float)Math.atan((double)a); + } + + static float scalar_cbrt(float a) { + return (float)Math.cbrt((double)a); + } + + static float scalar_sqrt(float a) { + return (float)Math.sqrt((double)a); + } + + static float scalar_hypot(float a, float b) { + return (float)Math.hypot((double)a, (double)b); + } + + static float scalar_pow(float a, float b) { + return (float)Math.pow((double)a, (double)b); + } + + static float scalar_atan2(float a, float b) { + return (float)Math.atan2((double)a, (double)b); + } + + static float strict_scalar_sin(float a) { + return (float)StrictMath.sin((double)a); + } + + static float strict_scalar_exp(float a) { + return (float)StrictMath.exp((double)a); + } + + static float strict_scalar_log1p(float a) { + return (float)StrictMath.log1p((double)a); + } + + static float strict_scalar_log(float a) { + return (float)StrictMath.log((double)a); + } + + static float strict_scalar_log10(float a) { + return (float)StrictMath.log10((double)a); + } + + static float strict_scalar_expm1(float a) { + return (float)StrictMath.expm1((double)a); + } + + static float strict_scalar_cos(float a) { + return (float)StrictMath.cos((double)a); + } + + static float strict_scalar_tan(float a) { + return (float)StrictMath.tan((double)a); + } + + static float strict_scalar_sinh(float a) { + return (float)StrictMath.sinh((double)a); + } + + static float strict_scalar_cosh(float a) { + return (float)StrictMath.cosh((double)a); + } + + static float strict_scalar_tanh(float a) { + return (float)StrictMath.tanh((double)a); + } + + static float strict_scalar_asin(float a) { + return (float)StrictMath.asin((double)a); + } + + static float strict_scalar_acos(float a) { + return (float)StrictMath.acos((double)a); + } + + static float strict_scalar_atan(float a) { + return (float)StrictMath.atan((double)a); + } + + static float strict_scalar_cbrt(float a) { + return (float)StrictMath.cbrt((double)a); + } + + static float strict_scalar_sqrt(float a) { + return (float)StrictMath.sqrt((double)a); + } + + static float strict_scalar_hypot(float a, float b) { + return (float)StrictMath.hypot((double)a, (double)b); + } + + static float strict_scalar_pow(float a, float b) { + return (float)StrictMath.pow((double)a, (double)b); + } + + static float strict_scalar_atan2(float a, float b) { + return (float)StrictMath.atan2((double)a, (double)b); + } + + static boolean isNaN(float a) { + return Float.isNaN(a); + } + static boolean isFinite(float a) { + return Float.isFinite(a); + } + static boolean isInfinite(float a) { + return Float.isInfinite(a); + } + @Test static void smokeTest1() { FloatVector three = FloatVector.broadcast(SPECIES, (byte)-3); @@ -1700,7 +1899,7 @@ relativeError)); } static float ADD(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1721,7 +1920,7 @@ relativeError)); } static float add(float a, float b) { - return (float)(a + b); + return (float)(scalar_add(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1778,7 +1977,7 @@ relativeError)); } static float SUB(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1799,7 +1998,7 @@ relativeError)); } static float sub(float a, float b) { - return (float)(a - b); + return (float)(scalar_sub(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1856,7 +2055,7 @@ relativeError)); } static float MUL(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1877,7 +2076,7 @@ relativeError)); } static float mul(float a, float b) { - return (float)(a * b); + return (float)(scalar_mul(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1934,7 +2133,7 @@ relativeError)); } static float DIV(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -1955,7 +2154,7 @@ relativeError)); } static float div(float a, float b) { - return (float)(a / b); + return (float)(scalar_div(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2012,7 +2211,7 @@ relativeError)); } static float FIRST_NONZERO(float a, float b) { - return (float)(Double.doubleToLongBits(a)!=0?a:b); + return (float)(firstNonZero(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2314,7 +2513,7 @@ relativeError)); } static float MIN(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2335,7 +2534,7 @@ relativeError)); } static float min(float a, float b) { - return (float)(Math.min(a, b)); + return (float)(scalar_min(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2354,7 +2553,7 @@ relativeError)); } static float MAX(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2375,7 +2574,7 @@ relativeError)); } static float max(float a, float b) { - return (float)(Math.max(a, b)); + return (float)(scalar_max(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -2452,7 +2651,7 @@ relativeError)); static float ADDReduce(float[] a, int idx) { float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2461,7 +2660,7 @@ relativeError)); static float ADDReduceAll(float[] a) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -2479,7 +2678,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2492,20 +2691,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = ADD_IDENTITY; - assertEquals((float) (id + id), id, + assertEquals((float) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id + x), x); - assertEquals((float) (x + id), x); + assertEquals((float) (scalar_add(id, x)), x); + assertEquals((float) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id + x), x, + assertEquals((float) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x + id), x, + assertEquals((float) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -2514,7 +2713,7 @@ relativeError)); float res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -2523,7 +2722,7 @@ relativeError)); static float ADDReduceAllMasked(float[] a, boolean[] mask) { float res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -2543,7 +2742,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -2554,7 +2753,7 @@ relativeError)); static float MULReduce(float[] a, int idx) { float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2563,7 +2762,7 @@ relativeError)); static float MULReduceAll(float[] a) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -2581,7 +2780,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2594,20 +2793,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MUL_IDENTITY; - assertEquals((float) (id * id), id, + assertEquals((float) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) (id * x), x); - assertEquals((float) (x * id), x); + assertEquals((float) (scalar_mul(id, x)), x); + assertEquals((float) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((float) (id * x), x, + assertEquals((float) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((float) (x * id), x, + assertEquals((float) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -2616,7 +2815,7 @@ relativeError)); float res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -2625,7 +2824,7 @@ relativeError)); static float MULReduceAllMasked(float[] a, boolean[] mask) { float res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -2645,7 +2844,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -2656,7 +2855,7 @@ relativeError)); static float MINReduce(float[] a, int idx) { float res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -2665,7 +2864,7 @@ relativeError)); static float MINReduceAll(float[] a) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -2683,7 +2882,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2696,20 +2895,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MIN_IDENTITY; - assertEquals((float) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.min(id, x), x); - assertEquals((float) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -2718,7 +2917,7 @@ relativeError)); 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]); + res = scalar_min(res, a[i]); } return res; @@ -2727,7 +2926,7 @@ relativeError)); static float MINReduceAllMasked(float[] a, boolean[] mask) { float res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -2747,7 +2946,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (float) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -2758,7 +2957,7 @@ relativeError)); static float MAXReduce(float[] a, int idx) { float res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (float) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -2767,7 +2966,7 @@ relativeError)); static float MAXReduceAll(float[] a) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -2785,7 +2984,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -2798,20 +2997,20 @@ relativeError)); float[] a = fa.apply(SPECIES.length()); float id = MAX_IDENTITY; - assertEquals((float) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); float x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((float) Math.max(id, x), x); - assertEquals((float) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((float) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((float) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -2820,7 +3019,7 @@ relativeError)); 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]); + res = scalar_max(res, a[i]); } return res; @@ -2829,7 +3028,7 @@ relativeError)); static float MAXReduceAllMasked(float[] a, boolean[] mask) { float res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (float) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -2849,7 +3048,7 @@ relativeError)); FloatVector av = FloatVector.fromArray(SPECIES, a, i); float v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (float) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -3061,7 +3260,7 @@ relativeError)); } static boolean testIS_FINITE(float a) { - return Float.isFinite(a); + return isFinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3102,7 +3301,7 @@ relativeError)); } static boolean testIS_NAN(float a) { - return Float.isNaN(a); + return isNaN(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3143,7 +3342,7 @@ relativeError)); } static boolean testIS_INFINITE(float a) { - return Float.isInfinite(a); + return isInfinite(a); } @Test(dataProvider = "floatTestOpProvider") @@ -3484,7 +3683,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -3504,7 +3703,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -3520,7 +3719,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (float)((long)b[i]))); } } } @@ -3540,7 +3739,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (float)((long)b[i])))); } } } @@ -3556,7 +3755,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -3576,7 +3775,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -3592,7 +3791,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (float)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (float)((long)b[i]))); } } } @@ -3612,7 +3811,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (float)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (float)((long)b[i])))); } } } @@ -4112,11 +4311,11 @@ relativeError)); } static float SIN(float a) { - return (float)(Math.sin((double)a)); + return (float)(scalar_sin(a)); } static float strictSIN(float a) { - return (float)(StrictMath.sin((double)a)); + return (float)(strict_scalar_sin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4135,11 +4334,11 @@ relativeError)); } static float EXP(float a) { - return (float)(Math.exp((double)a)); + return (float)(scalar_exp(a)); } static float strictEXP(float a) { - return (float)(StrictMath.exp((double)a)); + return (float)(strict_scalar_exp(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4158,11 +4357,11 @@ relativeError)); } static float LOG1P(float a) { - return (float)(Math.log1p((double)a)); + return (float)(scalar_log1p(a)); } static float strictLOG1P(float a) { - return (float)(StrictMath.log1p((double)a)); + return (float)(strict_scalar_log1p(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4181,11 +4380,11 @@ relativeError)); } static float LOG(float a) { - return (float)(Math.log((double)a)); + return (float)(scalar_log(a)); } static float strictLOG(float a) { - return (float)(StrictMath.log((double)a)); + return (float)(strict_scalar_log(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4204,11 +4403,11 @@ relativeError)); } static float LOG10(float a) { - return (float)(Math.log10((double)a)); + return (float)(scalar_log10(a)); } static float strictLOG10(float a) { - return (float)(StrictMath.log10((double)a)); + return (float)(strict_scalar_log10(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4227,11 +4426,11 @@ relativeError)); } static float EXPM1(float a) { - return (float)(Math.expm1((double)a)); + return (float)(scalar_expm1(a)); } static float strictEXPM1(float a) { - return (float)(StrictMath.expm1((double)a)); + return (float)(strict_scalar_expm1(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4250,11 +4449,11 @@ relativeError)); } static float COS(float a) { - return (float)(Math.cos((double)a)); + return (float)(scalar_cos(a)); } static float strictCOS(float a) { - return (float)(StrictMath.cos((double)a)); + return (float)(strict_scalar_cos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4273,11 +4472,11 @@ relativeError)); } static float TAN(float a) { - return (float)(Math.tan((double)a)); + return (float)(scalar_tan(a)); } static float strictTAN(float a) { - return (float)(StrictMath.tan((double)a)); + return (float)(strict_scalar_tan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4296,11 +4495,11 @@ relativeError)); } static float SINH(float a) { - return (float)(Math.sinh((double)a)); + return (float)(scalar_sinh(a)); } static float strictSINH(float a) { - return (float)(StrictMath.sinh((double)a)); + return (float)(strict_scalar_sinh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4319,11 +4518,11 @@ relativeError)); } static float COSH(float a) { - return (float)(Math.cosh((double)a)); + return (float)(scalar_cosh(a)); } static float strictCOSH(float a) { - return (float)(StrictMath.cosh((double)a)); + return (float)(strict_scalar_cosh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4342,11 +4541,11 @@ relativeError)); } static float TANH(float a) { - return (float)(Math.tanh((double)a)); + return (float)(scalar_tanh(a)); } static float strictTANH(float a) { - return (float)(StrictMath.tanh((double)a)); + return (float)(strict_scalar_tanh(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4365,11 +4564,11 @@ relativeError)); } static float ASIN(float a) { - return (float)(Math.asin((double)a)); + return (float)(scalar_asin(a)); } static float strictASIN(float a) { - return (float)(StrictMath.asin((double)a)); + return (float)(strict_scalar_asin(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4388,11 +4587,11 @@ relativeError)); } static float ACOS(float a) { - return (float)(Math.acos((double)a)); + return (float)(scalar_acos(a)); } static float strictACOS(float a) { - return (float)(StrictMath.acos((double)a)); + return (float)(strict_scalar_acos(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4411,11 +4610,11 @@ relativeError)); } static float ATAN(float a) { - return (float)(Math.atan((double)a)); + return (float)(scalar_atan(a)); } static float strictATAN(float a) { - return (float)(StrictMath.atan((double)a)); + return (float)(strict_scalar_atan(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4434,11 +4633,11 @@ relativeError)); } static float CBRT(float a) { - return (float)(Math.cbrt((double)a)); + return (float)(scalar_cbrt(a)); } static float strictCBRT(float a) { - return (float)(StrictMath.cbrt((double)a)); + return (float)(strict_scalar_cbrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4457,11 +4656,11 @@ relativeError)); } static float HYPOT(float a, float b) { - return (float)(Math.hypot((double)a, (double)b)); + return (float)(scalar_hypot(a, b)); } static float strictHYPOT(float a, float b) { - return (float)(StrictMath.hypot((double)a, (double)b)); + return (float)(strict_scalar_hypot(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4483,11 +4682,11 @@ relativeError)); static float POW(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictPOW(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4509,11 +4708,11 @@ relativeError)); static float pow(float a, float b) { - return (float)(Math.pow((double)a, (double)b)); + return (float)(scalar_pow(a, b)); } static float strictpow(float a, float b) { - return (float)(StrictMath.pow((double)a, (double)b)); + return (float)(strict_scalar_pow(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4535,11 +4734,11 @@ relativeError)); static float ATAN2(float a, float b) { - return (float)(Math.atan2((double)a, (double)b)); + return (float)(scalar_atan2(a, b)); } static float strictATAN2(float a, float b) { - return (float)(StrictMath.atan2((double)a, (double)b)); + return (float)(strict_scalar_atan2(a, b)); } @Test(dataProvider = "floatBinaryOpProvider") @@ -4591,11 +4790,11 @@ relativeError)); static float FMA(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } static float fma(float a, float b, float c) { - return (float)(Math.fma(a, b, c)); + return (float)(scalar_fma(a, b, c)); } @Test(dataProvider = "floatTernaryOpProvider") @@ -4773,11 +4972,11 @@ relativeError)); } static float NEG(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } static float neg(float a) { - return (float)(-((float)a)); + return (float)(scalar_neg((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4829,11 +5028,11 @@ relativeError)); } static float ABS(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } static float abs(float a) { - return (float)(Math.abs((float)a)); + return (float)(scalar_abs((float)a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -4885,11 +5084,11 @@ relativeError)); } static float SQRT(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } static float sqrt(float a) { - return (float)(Math.sqrt((double)a)); + return (float)(scalar_sqrt(a)); } @Test(dataProvider = "floatUnaryOpProvider") @@ -5102,7 +5301,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5118,7 +5317,7 @@ relativeError)); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5187,7 +5386,7 @@ relativeError)); static long ADDReduceLong(float[] a, int idx) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -5196,7 +5395,7 @@ relativeError)); static long ADDReduceAllLong(float[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((float)res, (float)ADDReduceLong(a, i)); } return res; @@ -5214,8 +5413,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -5225,8 +5424,9 @@ relativeError)); static long ADDReduceLongMasked(float[] a, int idx, boolean[] mask) { float res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -5235,7 +5435,7 @@ relativeError)); static long ADDReduceAllLongMasked(float[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((float)res, (float)ADDReduceLongMasked(a, i, mask)); } return res; @@ -5255,8 +5455,8 @@ relativeError)); } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((float)ra, (float)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/IntVector128Tests.java b/test/jdk/jdk/incubator/vector/IntVector128Tests.java index ecdb23eb40d..d62f5d8df00 100644 --- a/test/jdk/jdk/incubator/vector/IntVector128Tests.java +++ b/test/jdk/jdk/incubator/vector/IntVector128Tests.java @@ -1531,6 +1531,59 @@ public class IntVector128Tests extends AbstractVectorTest { return a >= b; } + static int firstNonZero(int a, int b) { + return Integer.compare(a, (int) 0) != 0 ? a : b; + } + + static int scalar_or(int a, int b) { + return (int)(a | b); + } + + static int scalar_and(int a, int b) { + return (int)(a & b); + } + + static int scalar_xor(int a, int b) { + return (int)(a ^ b); + } + + static int scalar_add(int a, int b) { + return (int)(a + b); + } + + static int scalar_sub(int a, int b) { + return (int)(a - b); + } + + static int scalar_mul(int a, int b) { + return (int)(a * b); + } + + static int scalar_min(int a, int b) { + return (int)(Math.min(a, b)); + } + + static int scalar_max(int a, int b) { + return (int)(Math.max(a, b)); + } + + static int scalar_div(int a, int b) { + return (int)(a / b); + } + + static int scalar_fma(int a, int b, int c) { + return (int)(Math.fma(a, b, c)); + } + + static int scalar_abs(int a) { + return (int)(Math.abs(a)); + } + + static int scalar_neg(int a) { + return ((int)-a); + } + + static boolean ult(int a, int b) { return Integer.compareUnsigned(a, b) < 0; } @@ -1547,9 +1600,6 @@ public class IntVector128Tests extends AbstractVectorTest { return Integer.compareUnsigned(a, b) >= 0; } - static int firstNonZero(int a, int b) { - return Integer.compare(a, (int) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1663,7 +1713,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int ADD(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1684,7 +1734,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int add(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1741,7 +1791,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int SUB(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1762,7 +1812,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int sub(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1819,7 +1869,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int MUL(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1840,7 +1890,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int mul(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1987,7 +2037,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int FIRST_NONZERO(int a, int b) { - return (int)((a)!=0?a:b); + return (int)(firstNonZero(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3283,7 +3333,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int MIN(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3304,7 +3354,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int min(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3323,7 +3373,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int MAX(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3344,7 +3394,7 @@ public class IntVector128Tests extends AbstractVectorTest { } static int max(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3712,7 +3762,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ANDReduce(int[] a, int idx) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3721,7 +3771,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ANDReduceAll(int[] a) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3739,7 +3789,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3752,20 +3802,20 @@ public class IntVector128Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = AND_IDENTITY; - assertEquals((int) (id & id), id, + assertEquals((int) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id & x), x); - assertEquals((int) (x & id), x); + assertEquals((int) (scalar_and(id, x)), x); + assertEquals((int) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id & x), x, + assertEquals((int) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x & id), x, + assertEquals((int) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3774,7 +3824,7 @@ public class IntVector128Tests extends AbstractVectorTest { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3783,7 +3833,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ANDReduceAllMasked(int[] a, boolean[] mask) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3803,7 +3853,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3814,7 +3864,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ORReduce(int[] a, int idx) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3823,7 +3873,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ORReduceAll(int[] a) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3841,7 +3891,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3854,20 +3904,20 @@ public class IntVector128Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = OR_IDENTITY; - assertEquals((int) (id | id), id, + assertEquals((int) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id | x), x); - assertEquals((int) (x | id), x); + assertEquals((int) (scalar_or(id, x)), x); + assertEquals((int) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id | x), x, + assertEquals((int) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x | id), x, + assertEquals((int) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3876,7 +3926,7 @@ public class IntVector128Tests extends AbstractVectorTest { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3885,7 +3935,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ORReduceAllMasked(int[] a, boolean[] mask) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3905,7 +3955,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3916,7 +3966,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int XORReduce(int[] a, int idx) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3925,7 +3975,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int XORReduceAll(int[] a) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3943,7 +3993,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3956,20 +4006,20 @@ public class IntVector128Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = XOR_IDENTITY; - assertEquals((int) (id ^ id), id, + assertEquals((int) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id ^ x), x); - assertEquals((int) (x ^ id), x); + assertEquals((int) (scalar_xor(id, x)), x); + assertEquals((int) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id ^ x), x, + assertEquals((int) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x ^ id), x, + assertEquals((int) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3978,7 +4028,7 @@ public class IntVector128Tests extends AbstractVectorTest { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3987,7 +4037,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int XORReduceAllMasked(int[] a, boolean[] mask) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4007,7 +4057,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4018,7 +4068,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ADDReduce(int[] a, int idx) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4027,7 +4077,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ADDReduceAll(int[] a) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4045,7 +4095,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4058,20 +4108,20 @@ public class IntVector128Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = ADD_IDENTITY; - assertEquals((int) (id + id), id, + assertEquals((int) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id + x), x); - assertEquals((int) (x + id), x); + assertEquals((int) (scalar_add(id, x)), x); + assertEquals((int) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id + x), x, + assertEquals((int) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x + id), x, + assertEquals((int) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4080,7 +4130,7 @@ public class IntVector128Tests extends AbstractVectorTest { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4089,7 +4139,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int ADDReduceAllMasked(int[] a, boolean[] mask) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4109,7 +4159,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4120,7 +4170,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MULReduce(int[] a, int idx) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4129,7 +4179,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MULReduceAll(int[] a) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4147,7 +4197,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4160,20 +4210,20 @@ public class IntVector128Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MUL_IDENTITY; - assertEquals((int) (id * id), id, + assertEquals((int) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id * x), x); - assertEquals((int) (x * id), x); + assertEquals((int) (scalar_mul(id, x)), x); + assertEquals((int) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id * x), x, + assertEquals((int) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x * id), x, + assertEquals((int) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4182,7 +4232,7 @@ public class IntVector128Tests extends AbstractVectorTest { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4191,7 +4241,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MULReduceAllMasked(int[] a, boolean[] mask) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4211,7 +4261,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4222,7 +4272,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MINReduce(int[] a, int idx) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4231,7 +4281,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MINReduceAll(int[] a) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4249,7 +4299,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4262,20 +4312,20 @@ public class IntVector128Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MIN_IDENTITY; - assertEquals((int) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.min(id, x), x); - assertEquals((int) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4284,7 +4334,7 @@ public class IntVector128Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4293,7 +4343,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MINReduceAllMasked(int[] a, boolean[] mask) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4313,7 +4363,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4324,7 +4374,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MAXReduce(int[] a, int idx) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4333,7 +4383,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MAXReduceAll(int[] a) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4351,7 +4401,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4364,20 +4414,20 @@ public class IntVector128Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MAX_IDENTITY; - assertEquals((int) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.max(id, x), x); - assertEquals((int) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4386,7 +4436,7 @@ public class IntVector128Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4395,7 +4445,7 @@ public class IntVector128Tests extends AbstractVectorTest { static int MAXReduceAllMasked(int[] a, boolean[] mask) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4415,7 +4465,7 @@ public class IntVector128Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5448,7 +5498,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5468,7 +5518,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5484,7 +5534,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (int)((long)b[i]))); } } } @@ -5504,7 +5554,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (int)((long)b[i])))); } } } @@ -5520,7 +5570,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5540,7 +5590,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5556,7 +5606,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (int)((long)b[i]))); } } } @@ -5576,7 +5626,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (int)((long)b[i])))); } } } @@ -6288,11 +6338,11 @@ public class IntVector128Tests extends AbstractVectorTest { } static int NEG(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } static int neg(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6344,11 +6394,11 @@ public class IntVector128Tests extends AbstractVectorTest { } static int ABS(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } static int abs(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6839,7 +6889,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6855,7 +6905,7 @@ public class IntVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6924,7 +6974,7 @@ public class IntVector128Tests extends AbstractVectorTest { static long ADDReduceLong(int[] a, int idx) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6933,7 +6983,7 @@ public class IntVector128Tests extends AbstractVectorTest { static long ADDReduceAllLong(int[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((int)res, (int)ADDReduceLong(a, i)); } return res; @@ -6951,8 +7001,8 @@ public class IntVector128Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6962,8 +7012,9 @@ public class IntVector128Tests extends AbstractVectorTest { static long ADDReduceLongMasked(int[] a, int idx, boolean[] mask) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6972,7 +7023,7 @@ public class IntVector128Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(int[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((int)res, (int)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6992,8 +7043,8 @@ public class IntVector128Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/IntVector256Tests.java b/test/jdk/jdk/incubator/vector/IntVector256Tests.java index 7100ebd1693..bb2d1d717f4 100644 --- a/test/jdk/jdk/incubator/vector/IntVector256Tests.java +++ b/test/jdk/jdk/incubator/vector/IntVector256Tests.java @@ -1531,6 +1531,59 @@ public class IntVector256Tests extends AbstractVectorTest { return a >= b; } + static int firstNonZero(int a, int b) { + return Integer.compare(a, (int) 0) != 0 ? a : b; + } + + static int scalar_or(int a, int b) { + return (int)(a | b); + } + + static int scalar_and(int a, int b) { + return (int)(a & b); + } + + static int scalar_xor(int a, int b) { + return (int)(a ^ b); + } + + static int scalar_add(int a, int b) { + return (int)(a + b); + } + + static int scalar_sub(int a, int b) { + return (int)(a - b); + } + + static int scalar_mul(int a, int b) { + return (int)(a * b); + } + + static int scalar_min(int a, int b) { + return (int)(Math.min(a, b)); + } + + static int scalar_max(int a, int b) { + return (int)(Math.max(a, b)); + } + + static int scalar_div(int a, int b) { + return (int)(a / b); + } + + static int scalar_fma(int a, int b, int c) { + return (int)(Math.fma(a, b, c)); + } + + static int scalar_abs(int a) { + return (int)(Math.abs(a)); + } + + static int scalar_neg(int a) { + return ((int)-a); + } + + static boolean ult(int a, int b) { return Integer.compareUnsigned(a, b) < 0; } @@ -1547,9 +1600,6 @@ public class IntVector256Tests extends AbstractVectorTest { return Integer.compareUnsigned(a, b) >= 0; } - static int firstNonZero(int a, int b) { - return Integer.compare(a, (int) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1663,7 +1713,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int ADD(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1684,7 +1734,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int add(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1741,7 +1791,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int SUB(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1762,7 +1812,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int sub(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1819,7 +1869,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int MUL(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1840,7 +1890,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int mul(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1987,7 +2037,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int FIRST_NONZERO(int a, int b) { - return (int)((a)!=0?a:b); + return (int)(firstNonZero(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3283,7 +3333,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int MIN(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3304,7 +3354,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int min(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3323,7 +3373,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int MAX(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3344,7 +3394,7 @@ public class IntVector256Tests extends AbstractVectorTest { } static int max(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3712,7 +3762,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ANDReduce(int[] a, int idx) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3721,7 +3771,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ANDReduceAll(int[] a) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3739,7 +3789,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3752,20 +3802,20 @@ public class IntVector256Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = AND_IDENTITY; - assertEquals((int) (id & id), id, + assertEquals((int) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id & x), x); - assertEquals((int) (x & id), x); + assertEquals((int) (scalar_and(id, x)), x); + assertEquals((int) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id & x), x, + assertEquals((int) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x & id), x, + assertEquals((int) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3774,7 +3824,7 @@ public class IntVector256Tests extends AbstractVectorTest { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3783,7 +3833,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ANDReduceAllMasked(int[] a, boolean[] mask) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3803,7 +3853,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3814,7 +3864,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ORReduce(int[] a, int idx) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3823,7 +3873,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ORReduceAll(int[] a) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3841,7 +3891,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3854,20 +3904,20 @@ public class IntVector256Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = OR_IDENTITY; - assertEquals((int) (id | id), id, + assertEquals((int) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id | x), x); - assertEquals((int) (x | id), x); + assertEquals((int) (scalar_or(id, x)), x); + assertEquals((int) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id | x), x, + assertEquals((int) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x | id), x, + assertEquals((int) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3876,7 +3926,7 @@ public class IntVector256Tests extends AbstractVectorTest { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3885,7 +3935,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ORReduceAllMasked(int[] a, boolean[] mask) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3905,7 +3955,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3916,7 +3966,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int XORReduce(int[] a, int idx) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3925,7 +3975,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int XORReduceAll(int[] a) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3943,7 +3993,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3956,20 +4006,20 @@ public class IntVector256Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = XOR_IDENTITY; - assertEquals((int) (id ^ id), id, + assertEquals((int) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id ^ x), x); - assertEquals((int) (x ^ id), x); + assertEquals((int) (scalar_xor(id, x)), x); + assertEquals((int) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id ^ x), x, + assertEquals((int) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x ^ id), x, + assertEquals((int) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3978,7 +4028,7 @@ public class IntVector256Tests extends AbstractVectorTest { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3987,7 +4037,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int XORReduceAllMasked(int[] a, boolean[] mask) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4007,7 +4057,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4018,7 +4068,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ADDReduce(int[] a, int idx) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4027,7 +4077,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ADDReduceAll(int[] a) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4045,7 +4095,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4058,20 +4108,20 @@ public class IntVector256Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = ADD_IDENTITY; - assertEquals((int) (id + id), id, + assertEquals((int) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id + x), x); - assertEquals((int) (x + id), x); + assertEquals((int) (scalar_add(id, x)), x); + assertEquals((int) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id + x), x, + assertEquals((int) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x + id), x, + assertEquals((int) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4080,7 +4130,7 @@ public class IntVector256Tests extends AbstractVectorTest { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4089,7 +4139,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int ADDReduceAllMasked(int[] a, boolean[] mask) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4109,7 +4159,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4120,7 +4170,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MULReduce(int[] a, int idx) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4129,7 +4179,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MULReduceAll(int[] a) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4147,7 +4197,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4160,20 +4210,20 @@ public class IntVector256Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MUL_IDENTITY; - assertEquals((int) (id * id), id, + assertEquals((int) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id * x), x); - assertEquals((int) (x * id), x); + assertEquals((int) (scalar_mul(id, x)), x); + assertEquals((int) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id * x), x, + assertEquals((int) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x * id), x, + assertEquals((int) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4182,7 +4232,7 @@ public class IntVector256Tests extends AbstractVectorTest { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4191,7 +4241,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MULReduceAllMasked(int[] a, boolean[] mask) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4211,7 +4261,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4222,7 +4272,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MINReduce(int[] a, int idx) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4231,7 +4281,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MINReduceAll(int[] a) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4249,7 +4299,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4262,20 +4312,20 @@ public class IntVector256Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MIN_IDENTITY; - assertEquals((int) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.min(id, x), x); - assertEquals((int) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4284,7 +4334,7 @@ public class IntVector256Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4293,7 +4343,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MINReduceAllMasked(int[] a, boolean[] mask) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4313,7 +4363,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4324,7 +4374,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MAXReduce(int[] a, int idx) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4333,7 +4383,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MAXReduceAll(int[] a) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4351,7 +4401,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4364,20 +4414,20 @@ public class IntVector256Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MAX_IDENTITY; - assertEquals((int) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.max(id, x), x); - assertEquals((int) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4386,7 +4436,7 @@ public class IntVector256Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4395,7 +4445,7 @@ public class IntVector256Tests extends AbstractVectorTest { static int MAXReduceAllMasked(int[] a, boolean[] mask) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4415,7 +4465,7 @@ public class IntVector256Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5448,7 +5498,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5468,7 +5518,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5484,7 +5534,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (int)((long)b[i]))); } } } @@ -5504,7 +5554,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (int)((long)b[i])))); } } } @@ -5520,7 +5570,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5540,7 +5590,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5556,7 +5606,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (int)((long)b[i]))); } } } @@ -5576,7 +5626,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (int)((long)b[i])))); } } } @@ -6288,11 +6338,11 @@ public class IntVector256Tests extends AbstractVectorTest { } static int NEG(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } static int neg(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6344,11 +6394,11 @@ public class IntVector256Tests extends AbstractVectorTest { } static int ABS(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } static int abs(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6839,7 +6889,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6855,7 +6905,7 @@ public class IntVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6924,7 +6974,7 @@ public class IntVector256Tests extends AbstractVectorTest { static long ADDReduceLong(int[] a, int idx) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6933,7 +6983,7 @@ public class IntVector256Tests extends AbstractVectorTest { static long ADDReduceAllLong(int[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((int)res, (int)ADDReduceLong(a, i)); } return res; @@ -6951,8 +7001,8 @@ public class IntVector256Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6962,8 +7012,9 @@ public class IntVector256Tests extends AbstractVectorTest { static long ADDReduceLongMasked(int[] a, int idx, boolean[] mask) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6972,7 +7023,7 @@ public class IntVector256Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(int[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((int)res, (int)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6992,8 +7043,8 @@ public class IntVector256Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/IntVector512Tests.java b/test/jdk/jdk/incubator/vector/IntVector512Tests.java index 468d3b15efe..5ceba4e88ec 100644 --- a/test/jdk/jdk/incubator/vector/IntVector512Tests.java +++ b/test/jdk/jdk/incubator/vector/IntVector512Tests.java @@ -1531,6 +1531,59 @@ public class IntVector512Tests extends AbstractVectorTest { return a >= b; } + static int firstNonZero(int a, int b) { + return Integer.compare(a, (int) 0) != 0 ? a : b; + } + + static int scalar_or(int a, int b) { + return (int)(a | b); + } + + static int scalar_and(int a, int b) { + return (int)(a & b); + } + + static int scalar_xor(int a, int b) { + return (int)(a ^ b); + } + + static int scalar_add(int a, int b) { + return (int)(a + b); + } + + static int scalar_sub(int a, int b) { + return (int)(a - b); + } + + static int scalar_mul(int a, int b) { + return (int)(a * b); + } + + static int scalar_min(int a, int b) { + return (int)(Math.min(a, b)); + } + + static int scalar_max(int a, int b) { + return (int)(Math.max(a, b)); + } + + static int scalar_div(int a, int b) { + return (int)(a / b); + } + + static int scalar_fma(int a, int b, int c) { + return (int)(Math.fma(a, b, c)); + } + + static int scalar_abs(int a) { + return (int)(Math.abs(a)); + } + + static int scalar_neg(int a) { + return ((int)-a); + } + + static boolean ult(int a, int b) { return Integer.compareUnsigned(a, b) < 0; } @@ -1547,9 +1600,6 @@ public class IntVector512Tests extends AbstractVectorTest { return Integer.compareUnsigned(a, b) >= 0; } - static int firstNonZero(int a, int b) { - return Integer.compare(a, (int) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1663,7 +1713,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int ADD(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1684,7 +1734,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int add(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1741,7 +1791,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int SUB(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1762,7 +1812,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int sub(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1819,7 +1869,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int MUL(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1840,7 +1890,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int mul(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1987,7 +2037,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int FIRST_NONZERO(int a, int b) { - return (int)((a)!=0?a:b); + return (int)(firstNonZero(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3283,7 +3333,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int MIN(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3304,7 +3354,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int min(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3323,7 +3373,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int MAX(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3344,7 +3394,7 @@ public class IntVector512Tests extends AbstractVectorTest { } static int max(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3712,7 +3762,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ANDReduce(int[] a, int idx) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3721,7 +3771,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ANDReduceAll(int[] a) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3739,7 +3789,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3752,20 +3802,20 @@ public class IntVector512Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = AND_IDENTITY; - assertEquals((int) (id & id), id, + assertEquals((int) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id & x), x); - assertEquals((int) (x & id), x); + assertEquals((int) (scalar_and(id, x)), x); + assertEquals((int) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id & x), x, + assertEquals((int) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x & id), x, + assertEquals((int) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3774,7 +3824,7 @@ public class IntVector512Tests extends AbstractVectorTest { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3783,7 +3833,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ANDReduceAllMasked(int[] a, boolean[] mask) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3803,7 +3853,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3814,7 +3864,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ORReduce(int[] a, int idx) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3823,7 +3873,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ORReduceAll(int[] a) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3841,7 +3891,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3854,20 +3904,20 @@ public class IntVector512Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = OR_IDENTITY; - assertEquals((int) (id | id), id, + assertEquals((int) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id | x), x); - assertEquals((int) (x | id), x); + assertEquals((int) (scalar_or(id, x)), x); + assertEquals((int) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id | x), x, + assertEquals((int) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x | id), x, + assertEquals((int) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3876,7 +3926,7 @@ public class IntVector512Tests extends AbstractVectorTest { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3885,7 +3935,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ORReduceAllMasked(int[] a, boolean[] mask) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3905,7 +3955,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3916,7 +3966,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int XORReduce(int[] a, int idx) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3925,7 +3975,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int XORReduceAll(int[] a) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3943,7 +3993,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3956,20 +4006,20 @@ public class IntVector512Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = XOR_IDENTITY; - assertEquals((int) (id ^ id), id, + assertEquals((int) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id ^ x), x); - assertEquals((int) (x ^ id), x); + assertEquals((int) (scalar_xor(id, x)), x); + assertEquals((int) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id ^ x), x, + assertEquals((int) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x ^ id), x, + assertEquals((int) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3978,7 +4028,7 @@ public class IntVector512Tests extends AbstractVectorTest { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3987,7 +4037,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int XORReduceAllMasked(int[] a, boolean[] mask) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4007,7 +4057,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4018,7 +4068,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ADDReduce(int[] a, int idx) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4027,7 +4077,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ADDReduceAll(int[] a) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4045,7 +4095,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4058,20 +4108,20 @@ public class IntVector512Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = ADD_IDENTITY; - assertEquals((int) (id + id), id, + assertEquals((int) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id + x), x); - assertEquals((int) (x + id), x); + assertEquals((int) (scalar_add(id, x)), x); + assertEquals((int) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id + x), x, + assertEquals((int) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x + id), x, + assertEquals((int) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4080,7 +4130,7 @@ public class IntVector512Tests extends AbstractVectorTest { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4089,7 +4139,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int ADDReduceAllMasked(int[] a, boolean[] mask) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4109,7 +4159,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4120,7 +4170,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MULReduce(int[] a, int idx) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4129,7 +4179,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MULReduceAll(int[] a) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4147,7 +4197,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4160,20 +4210,20 @@ public class IntVector512Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MUL_IDENTITY; - assertEquals((int) (id * id), id, + assertEquals((int) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id * x), x); - assertEquals((int) (x * id), x); + assertEquals((int) (scalar_mul(id, x)), x); + assertEquals((int) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id * x), x, + assertEquals((int) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x * id), x, + assertEquals((int) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4182,7 +4232,7 @@ public class IntVector512Tests extends AbstractVectorTest { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4191,7 +4241,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MULReduceAllMasked(int[] a, boolean[] mask) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4211,7 +4261,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4222,7 +4272,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MINReduce(int[] a, int idx) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4231,7 +4281,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MINReduceAll(int[] a) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4249,7 +4299,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4262,20 +4312,20 @@ public class IntVector512Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MIN_IDENTITY; - assertEquals((int) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.min(id, x), x); - assertEquals((int) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4284,7 +4334,7 @@ public class IntVector512Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4293,7 +4343,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MINReduceAllMasked(int[] a, boolean[] mask) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4313,7 +4363,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4324,7 +4374,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MAXReduce(int[] a, int idx) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4333,7 +4383,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MAXReduceAll(int[] a) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4351,7 +4401,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4364,20 +4414,20 @@ public class IntVector512Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MAX_IDENTITY; - assertEquals((int) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.max(id, x), x); - assertEquals((int) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4386,7 +4436,7 @@ public class IntVector512Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4395,7 +4445,7 @@ public class IntVector512Tests extends AbstractVectorTest { static int MAXReduceAllMasked(int[] a, boolean[] mask) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4415,7 +4465,7 @@ public class IntVector512Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5448,7 +5498,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5468,7 +5518,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5484,7 +5534,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (int)((long)b[i]))); } } } @@ -5504,7 +5554,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (int)((long)b[i])))); } } } @@ -5520,7 +5570,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5540,7 +5590,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5556,7 +5606,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (int)((long)b[i]))); } } } @@ -5576,7 +5626,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (int)((long)b[i])))); } } } @@ -6288,11 +6338,11 @@ public class IntVector512Tests extends AbstractVectorTest { } static int NEG(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } static int neg(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6344,11 +6394,11 @@ public class IntVector512Tests extends AbstractVectorTest { } static int ABS(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } static int abs(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6839,7 +6889,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6855,7 +6905,7 @@ public class IntVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6924,7 +6974,7 @@ public class IntVector512Tests extends AbstractVectorTest { static long ADDReduceLong(int[] a, int idx) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6933,7 +6983,7 @@ public class IntVector512Tests extends AbstractVectorTest { static long ADDReduceAllLong(int[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((int)res, (int)ADDReduceLong(a, i)); } return res; @@ -6951,8 +7001,8 @@ public class IntVector512Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6962,8 +7012,9 @@ public class IntVector512Tests extends AbstractVectorTest { static long ADDReduceLongMasked(int[] a, int idx, boolean[] mask) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6972,7 +7023,7 @@ public class IntVector512Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(int[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((int)res, (int)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6992,8 +7043,8 @@ public class IntVector512Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/IntVector64Tests.java b/test/jdk/jdk/incubator/vector/IntVector64Tests.java index 0715981e050..9d3849a2c04 100644 --- a/test/jdk/jdk/incubator/vector/IntVector64Tests.java +++ b/test/jdk/jdk/incubator/vector/IntVector64Tests.java @@ -1531,6 +1531,59 @@ public class IntVector64Tests extends AbstractVectorTest { return a >= b; } + static int firstNonZero(int a, int b) { + return Integer.compare(a, (int) 0) != 0 ? a : b; + } + + static int scalar_or(int a, int b) { + return (int)(a | b); + } + + static int scalar_and(int a, int b) { + return (int)(a & b); + } + + static int scalar_xor(int a, int b) { + return (int)(a ^ b); + } + + static int scalar_add(int a, int b) { + return (int)(a + b); + } + + static int scalar_sub(int a, int b) { + return (int)(a - b); + } + + static int scalar_mul(int a, int b) { + return (int)(a * b); + } + + static int scalar_min(int a, int b) { + return (int)(Math.min(a, b)); + } + + static int scalar_max(int a, int b) { + return (int)(Math.max(a, b)); + } + + static int scalar_div(int a, int b) { + return (int)(a / b); + } + + static int scalar_fma(int a, int b, int c) { + return (int)(Math.fma(a, b, c)); + } + + static int scalar_abs(int a) { + return (int)(Math.abs(a)); + } + + static int scalar_neg(int a) { + return ((int)-a); + } + + static boolean ult(int a, int b) { return Integer.compareUnsigned(a, b) < 0; } @@ -1547,9 +1600,6 @@ public class IntVector64Tests extends AbstractVectorTest { return Integer.compareUnsigned(a, b) >= 0; } - static int firstNonZero(int a, int b) { - return Integer.compare(a, (int) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1663,7 +1713,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int ADD(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1684,7 +1734,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int add(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1741,7 +1791,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int SUB(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1762,7 +1812,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int sub(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1819,7 +1869,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int MUL(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1840,7 +1890,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int mul(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1987,7 +2037,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int FIRST_NONZERO(int a, int b) { - return (int)((a)!=0?a:b); + return (int)(firstNonZero(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3283,7 +3333,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int MIN(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3304,7 +3354,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int min(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3323,7 +3373,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int MAX(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3344,7 +3394,7 @@ public class IntVector64Tests extends AbstractVectorTest { } static int max(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3712,7 +3762,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ANDReduce(int[] a, int idx) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3721,7 +3771,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ANDReduceAll(int[] a) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3739,7 +3789,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3752,20 +3802,20 @@ public class IntVector64Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = AND_IDENTITY; - assertEquals((int) (id & id), id, + assertEquals((int) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id & x), x); - assertEquals((int) (x & id), x); + assertEquals((int) (scalar_and(id, x)), x); + assertEquals((int) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id & x), x, + assertEquals((int) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x & id), x, + assertEquals((int) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3774,7 +3824,7 @@ public class IntVector64Tests extends AbstractVectorTest { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3783,7 +3833,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ANDReduceAllMasked(int[] a, boolean[] mask) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3803,7 +3853,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3814,7 +3864,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ORReduce(int[] a, int idx) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3823,7 +3873,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ORReduceAll(int[] a) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3841,7 +3891,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3854,20 +3904,20 @@ public class IntVector64Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = OR_IDENTITY; - assertEquals((int) (id | id), id, + assertEquals((int) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id | x), x); - assertEquals((int) (x | id), x); + assertEquals((int) (scalar_or(id, x)), x); + assertEquals((int) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id | x), x, + assertEquals((int) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x | id), x, + assertEquals((int) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3876,7 +3926,7 @@ public class IntVector64Tests extends AbstractVectorTest { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3885,7 +3935,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ORReduceAllMasked(int[] a, boolean[] mask) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3905,7 +3955,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3916,7 +3966,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int XORReduce(int[] a, int idx) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3925,7 +3975,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int XORReduceAll(int[] a) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3943,7 +3993,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3956,20 +4006,20 @@ public class IntVector64Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = XOR_IDENTITY; - assertEquals((int) (id ^ id), id, + assertEquals((int) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id ^ x), x); - assertEquals((int) (x ^ id), x); + assertEquals((int) (scalar_xor(id, x)), x); + assertEquals((int) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id ^ x), x, + assertEquals((int) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x ^ id), x, + assertEquals((int) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3978,7 +4028,7 @@ public class IntVector64Tests extends AbstractVectorTest { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3987,7 +4037,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int XORReduceAllMasked(int[] a, boolean[] mask) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4007,7 +4057,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4018,7 +4068,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ADDReduce(int[] a, int idx) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4027,7 +4077,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ADDReduceAll(int[] a) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4045,7 +4095,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4058,20 +4108,20 @@ public class IntVector64Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = ADD_IDENTITY; - assertEquals((int) (id + id), id, + assertEquals((int) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id + x), x); - assertEquals((int) (x + id), x); + assertEquals((int) (scalar_add(id, x)), x); + assertEquals((int) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id + x), x, + assertEquals((int) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x + id), x, + assertEquals((int) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4080,7 +4130,7 @@ public class IntVector64Tests extends AbstractVectorTest { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4089,7 +4139,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int ADDReduceAllMasked(int[] a, boolean[] mask) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4109,7 +4159,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4120,7 +4170,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MULReduce(int[] a, int idx) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4129,7 +4179,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MULReduceAll(int[] a) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4147,7 +4197,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4160,20 +4210,20 @@ public class IntVector64Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MUL_IDENTITY; - assertEquals((int) (id * id), id, + assertEquals((int) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id * x), x); - assertEquals((int) (x * id), x); + assertEquals((int) (scalar_mul(id, x)), x); + assertEquals((int) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id * x), x, + assertEquals((int) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x * id), x, + assertEquals((int) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4182,7 +4232,7 @@ public class IntVector64Tests extends AbstractVectorTest { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4191,7 +4241,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MULReduceAllMasked(int[] a, boolean[] mask) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4211,7 +4261,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4222,7 +4272,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MINReduce(int[] a, int idx) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4231,7 +4281,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MINReduceAll(int[] a) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4249,7 +4299,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4262,20 +4312,20 @@ public class IntVector64Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MIN_IDENTITY; - assertEquals((int) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.min(id, x), x); - assertEquals((int) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4284,7 +4334,7 @@ public class IntVector64Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4293,7 +4343,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MINReduceAllMasked(int[] a, boolean[] mask) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4313,7 +4363,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4324,7 +4374,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MAXReduce(int[] a, int idx) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4333,7 +4383,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MAXReduceAll(int[] a) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4351,7 +4401,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4364,20 +4414,20 @@ public class IntVector64Tests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MAX_IDENTITY; - assertEquals((int) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.max(id, x), x); - assertEquals((int) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4386,7 +4436,7 @@ public class IntVector64Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4395,7 +4445,7 @@ public class IntVector64Tests extends AbstractVectorTest { static int MAXReduceAllMasked(int[] a, boolean[] mask) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4415,7 +4465,7 @@ public class IntVector64Tests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5448,7 +5498,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5468,7 +5518,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5484,7 +5534,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (int)((long)b[i]))); } } } @@ -5504,7 +5554,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (int)((long)b[i])))); } } } @@ -5520,7 +5570,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5540,7 +5590,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5556,7 +5606,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (int)((long)b[i]))); } } } @@ -5576,7 +5626,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (int)((long)b[i])))); } } } @@ -6288,11 +6338,11 @@ public class IntVector64Tests extends AbstractVectorTest { } static int NEG(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } static int neg(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6344,11 +6394,11 @@ public class IntVector64Tests extends AbstractVectorTest { } static int ABS(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } static int abs(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6839,7 +6889,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6855,7 +6905,7 @@ public class IntVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6924,7 +6974,7 @@ public class IntVector64Tests extends AbstractVectorTest { static long ADDReduceLong(int[] a, int idx) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6933,7 +6983,7 @@ public class IntVector64Tests extends AbstractVectorTest { static long ADDReduceAllLong(int[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((int)res, (int)ADDReduceLong(a, i)); } return res; @@ -6951,8 +7001,8 @@ public class IntVector64Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6962,8 +7012,9 @@ public class IntVector64Tests extends AbstractVectorTest { static long ADDReduceLongMasked(int[] a, int idx, boolean[] mask) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6972,7 +7023,7 @@ public class IntVector64Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(int[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((int)res, (int)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6992,8 +7043,8 @@ public class IntVector64Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/IntVectorMaxTests.java b/test/jdk/jdk/incubator/vector/IntVectorMaxTests.java index ad519b36dc9..6c671a81bf1 100644 --- a/test/jdk/jdk/incubator/vector/IntVectorMaxTests.java +++ b/test/jdk/jdk/incubator/vector/IntVectorMaxTests.java @@ -1537,6 +1537,59 @@ public class IntVectorMaxTests extends AbstractVectorTest { return a >= b; } + static int firstNonZero(int a, int b) { + return Integer.compare(a, (int) 0) != 0 ? a : b; + } + + static int scalar_or(int a, int b) { + return (int)(a | b); + } + + static int scalar_and(int a, int b) { + return (int)(a & b); + } + + static int scalar_xor(int a, int b) { + return (int)(a ^ b); + } + + static int scalar_add(int a, int b) { + return (int)(a + b); + } + + static int scalar_sub(int a, int b) { + return (int)(a - b); + } + + static int scalar_mul(int a, int b) { + return (int)(a * b); + } + + static int scalar_min(int a, int b) { + return (int)(Math.min(a, b)); + } + + static int scalar_max(int a, int b) { + return (int)(Math.max(a, b)); + } + + static int scalar_div(int a, int b) { + return (int)(a / b); + } + + static int scalar_fma(int a, int b, int c) { + return (int)(Math.fma(a, b, c)); + } + + static int scalar_abs(int a) { + return (int)(Math.abs(a)); + } + + static int scalar_neg(int a) { + return ((int)-a); + } + + static boolean ult(int a, int b) { return Integer.compareUnsigned(a, b) < 0; } @@ -1553,9 +1606,6 @@ public class IntVectorMaxTests extends AbstractVectorTest { return Integer.compareUnsigned(a, b) >= 0; } - static int firstNonZero(int a, int b) { - return Integer.compare(a, (int) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1669,7 +1719,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int ADD(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1690,7 +1740,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int add(int a, int b) { - return (int)(a + b); + return (int)(scalar_add(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1747,7 +1797,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int SUB(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1768,7 +1818,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int sub(int a, int b) { - return (int)(a - b); + return (int)(scalar_sub(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1825,7 +1875,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int MUL(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1846,7 +1896,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int mul(int a, int b) { - return (int)(a * b); + return (int)(scalar_mul(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -1993,7 +2043,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int FIRST_NONZERO(int a, int b) { - return (int)((a)!=0?a:b); + return (int)(firstNonZero(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3289,7 +3339,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int MIN(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3310,7 +3360,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int min(int a, int b) { - return (int)(Math.min(a, b)); + return (int)(scalar_min(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3329,7 +3379,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int MAX(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3350,7 +3400,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int max(int a, int b) { - return (int)(Math.max(a, b)); + return (int)(scalar_max(a, b)); } @Test(dataProvider = "intBinaryOpProvider") @@ -3718,7 +3768,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ANDReduce(int[] a, int idx) { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3727,7 +3777,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ANDReduceAll(int[] a) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3745,7 +3795,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3758,20 +3808,20 @@ public class IntVectorMaxTests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = AND_IDENTITY; - assertEquals((int) (id & id), id, + assertEquals((int) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id & x), x); - assertEquals((int) (x & id), x); + assertEquals((int) (scalar_and(id, x)), x); + assertEquals((int) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id & x), x, + assertEquals((int) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x & id), x, + assertEquals((int) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3780,7 +3830,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { int res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3789,7 +3839,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ANDReduceAllMasked(int[] a, boolean[] mask) { int res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3809,7 +3859,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3820,7 +3870,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ORReduce(int[] a, int idx) { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3829,7 +3879,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ORReduceAll(int[] a) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3847,7 +3897,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3860,20 +3910,20 @@ public class IntVectorMaxTests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = OR_IDENTITY; - assertEquals((int) (id | id), id, + assertEquals((int) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id | x), x); - assertEquals((int) (x | id), x); + assertEquals((int) (scalar_or(id, x)), x); + assertEquals((int) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id | x), x, + assertEquals((int) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x | id), x, + assertEquals((int) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3882,7 +3932,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { int res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3891,7 +3941,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ORReduceAllMasked(int[] a, boolean[] mask) { int res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3911,7 +3961,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3922,7 +3972,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int XORReduce(int[] a, int idx) { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3931,7 +3981,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int XORReduceAll(int[] a) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3949,7 +3999,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3962,20 +4012,20 @@ public class IntVectorMaxTests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = XOR_IDENTITY; - assertEquals((int) (id ^ id), id, + assertEquals((int) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id ^ x), x); - assertEquals((int) (x ^ id), x); + assertEquals((int) (scalar_xor(id, x)), x); + assertEquals((int) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id ^ x), x, + assertEquals((int) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x ^ id), x, + assertEquals((int) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3984,7 +4034,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { int res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3993,7 +4043,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int XORReduceAllMasked(int[] a, boolean[] mask) { int res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4013,7 +4063,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4024,7 +4074,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ADDReduce(int[] a, int idx) { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4033,7 +4083,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ADDReduceAll(int[] a) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4051,7 +4101,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4064,20 +4114,20 @@ public class IntVectorMaxTests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = ADD_IDENTITY; - assertEquals((int) (id + id), id, + assertEquals((int) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id + x), x); - assertEquals((int) (x + id), x); + assertEquals((int) (scalar_add(id, x)), x); + assertEquals((int) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id + x), x, + assertEquals((int) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x + id), x, + assertEquals((int) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4086,7 +4136,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { int res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4095,7 +4145,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int ADDReduceAllMasked(int[] a, boolean[] mask) { int res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4115,7 +4165,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4126,7 +4176,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MULReduce(int[] a, int idx) { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4135,7 +4185,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MULReduceAll(int[] a) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4153,7 +4203,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4166,20 +4216,20 @@ public class IntVectorMaxTests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MUL_IDENTITY; - assertEquals((int) (id * id), id, + assertEquals((int) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) (id * x), x); - assertEquals((int) (x * id), x); + assertEquals((int) (scalar_mul(id, x)), x); + assertEquals((int) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((int) (id * x), x, + assertEquals((int) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((int) (x * id), x, + assertEquals((int) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4188,7 +4238,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { int res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4197,7 +4247,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MULReduceAllMasked(int[] a, boolean[] mask) { int res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4217,7 +4267,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4228,7 +4278,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MINReduce(int[] a, int idx) { int res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4237,7 +4287,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MINReduceAll(int[] a) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4255,7 +4305,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4268,20 +4318,20 @@ public class IntVectorMaxTests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MIN_IDENTITY; - assertEquals((int) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.min(id, x), x); - assertEquals((int) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4290,7 +4340,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4299,7 +4349,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MINReduceAllMasked(int[] a, boolean[] mask) { int res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4319,7 +4369,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (int) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4330,7 +4380,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MAXReduce(int[] a, int idx) { int res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (int) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4339,7 +4389,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MAXReduceAll(int[] a) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4357,7 +4407,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4370,20 +4420,20 @@ public class IntVectorMaxTests extends AbstractVectorTest { int[] a = fa.apply(SPECIES.length()); int id = MAX_IDENTITY; - assertEquals((int) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); int x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((int) Math.max(id, x), x); - assertEquals((int) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((int) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((int) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4392,7 +4442,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4401,7 +4451,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static int MAXReduceAllMasked(int[] a, boolean[] mask) { int res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (int) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4421,7 +4471,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { IntVector av = IntVector.fromArray(SPECIES, a, i); int v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (int) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5454,7 +5504,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5474,7 +5524,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5490,7 +5540,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (int)((long)b[i]))); } } } @@ -5510,7 +5560,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (int)((long)b[i])))); } } } @@ -5526,7 +5576,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5546,7 +5596,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5562,7 +5612,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (int)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (int)((long)b[i]))); } } } @@ -5582,7 +5632,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (int)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (int)((long)b[i])))); } } } @@ -6294,11 +6344,11 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int NEG(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } static int neg(int a) { - return (int)(-((int)a)); + return (int)(scalar_neg((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6350,11 +6400,11 @@ public class IntVectorMaxTests extends AbstractVectorTest { } static int ABS(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } static int abs(int a) { - return (int)(Math.abs((int)a)); + return (int)(scalar_abs((int)a)); } @Test(dataProvider = "intUnaryOpProvider") @@ -6845,7 +6895,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6861,7 +6911,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6930,7 +6980,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static long ADDReduceLong(int[] a, int idx) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6939,7 +6989,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static long ADDReduceAllLong(int[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((int)res, (int)ADDReduceLong(a, i)); } return res; @@ -6957,8 +7007,8 @@ public class IntVectorMaxTests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6968,8 +7018,9 @@ public class IntVectorMaxTests extends AbstractVectorTest { static long ADDReduceLongMasked(int[] a, int idx, boolean[] mask) { int res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6978,7 +7029,7 @@ public class IntVectorMaxTests extends AbstractVectorTest { static long ADDReduceAllLongMasked(int[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((int)res, (int)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6998,8 +7049,8 @@ public class IntVectorMaxTests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((int)ra, (int)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/LongVector128Tests.java b/test/jdk/jdk/incubator/vector/LongVector128Tests.java index 1d3af1684b9..49e2e1a0078 100644 --- a/test/jdk/jdk/incubator/vector/LongVector128Tests.java +++ b/test/jdk/jdk/incubator/vector/LongVector128Tests.java @@ -1547,6 +1547,59 @@ public class LongVector128Tests extends AbstractVectorTest { return a >= b; } + static long firstNonZero(long a, long b) { + return Long.compare(a, (long) 0) != 0 ? a : b; + } + + static long scalar_or(long a, long b) { + return (long)(a | b); + } + + static long scalar_and(long a, long b) { + return (long)(a & b); + } + + static long scalar_xor(long a, long b) { + return (long)(a ^ b); + } + + static long scalar_add(long a, long b) { + return (long)(a + b); + } + + static long scalar_sub(long a, long b) { + return (long)(a - b); + } + + static long scalar_mul(long a, long b) { + return (long)(a * b); + } + + static long scalar_min(long a, long b) { + return (long)(Math.min(a, b)); + } + + static long scalar_max(long a, long b) { + return (long)(Math.max(a, b)); + } + + static long scalar_div(long a, long b) { + return (long)(a / b); + } + + static long scalar_fma(long a, long b, long c) { + return (long)(Math.fma(a, b, c)); + } + + static long scalar_abs(long a) { + return (long)(Math.abs(a)); + } + + static long scalar_neg(long a) { + return ((long)-a); + } + + static boolean ult(long a, long b) { return Long.compareUnsigned(a, b) < 0; } @@ -1563,9 +1616,6 @@ public class LongVector128Tests extends AbstractVectorTest { return Long.compareUnsigned(a, b) >= 0; } - static long firstNonZero(long a, long b) { - return Long.compare(a, (long) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1679,7 +1729,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long ADD(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1700,7 +1750,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long add(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1757,7 +1807,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long SUB(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1778,7 +1828,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long sub(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1835,7 +1885,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long MUL(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1856,7 +1906,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long mul(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -2003,7 +2053,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long FIRST_NONZERO(long a, long b) { - return (long)((a)!=0?a:b); + return (long)(firstNonZero(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3299,7 +3349,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long MIN(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3320,7 +3370,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long min(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3339,7 +3389,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long MAX(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3360,7 +3410,7 @@ public class LongVector128Tests extends AbstractVectorTest { } static long max(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3728,7 +3778,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ANDReduce(long[] a, int idx) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3737,7 +3787,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ANDReduceAll(long[] a) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3755,7 +3805,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3768,20 +3818,20 @@ public class LongVector128Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = AND_IDENTITY; - assertEquals((long) (id & id), id, + assertEquals((long) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id & x), x); - assertEquals((long) (x & id), x); + assertEquals((long) (scalar_and(id, x)), x); + assertEquals((long) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id & x), x, + assertEquals((long) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x & id), x, + assertEquals((long) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3790,7 +3840,7 @@ public class LongVector128Tests extends AbstractVectorTest { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3799,7 +3849,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ANDReduceAllMasked(long[] a, boolean[] mask) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3819,7 +3869,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3830,7 +3880,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ORReduce(long[] a, int idx) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3839,7 +3889,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ORReduceAll(long[] a) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3857,7 +3907,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3870,20 +3920,20 @@ public class LongVector128Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = OR_IDENTITY; - assertEquals((long) (id | id), id, + assertEquals((long) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id | x), x); - assertEquals((long) (x | id), x); + assertEquals((long) (scalar_or(id, x)), x); + assertEquals((long) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id | x), x, + assertEquals((long) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x | id), x, + assertEquals((long) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3892,7 +3942,7 @@ public class LongVector128Tests extends AbstractVectorTest { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3901,7 +3951,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ORReduceAllMasked(long[] a, boolean[] mask) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3921,7 +3971,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3932,7 +3982,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long XORReduce(long[] a, int idx) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3941,7 +3991,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long XORReduceAll(long[] a) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3959,7 +4009,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3972,20 +4022,20 @@ public class LongVector128Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = XOR_IDENTITY; - assertEquals((long) (id ^ id), id, + assertEquals((long) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id ^ x), x); - assertEquals((long) (x ^ id), x); + assertEquals((long) (scalar_xor(id, x)), x); + assertEquals((long) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id ^ x), x, + assertEquals((long) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x ^ id), x, + assertEquals((long) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3994,7 +4044,7 @@ public class LongVector128Tests extends AbstractVectorTest { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -4003,7 +4053,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long XORReduceAllMasked(long[] a, boolean[] mask) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4023,7 +4073,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4034,7 +4084,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ADDReduce(long[] a, int idx) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4043,7 +4093,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ADDReduceAll(long[] a) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4061,7 +4111,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4074,20 +4124,20 @@ public class LongVector128Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = ADD_IDENTITY; - assertEquals((long) (id + id), id, + assertEquals((long) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id + x), x); - assertEquals((long) (x + id), x); + assertEquals((long) (scalar_add(id, x)), x); + assertEquals((long) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id + x), x, + assertEquals((long) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x + id), x, + assertEquals((long) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4096,7 +4146,7 @@ public class LongVector128Tests extends AbstractVectorTest { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4105,7 +4155,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long ADDReduceAllMasked(long[] a, boolean[] mask) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4125,7 +4175,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4136,7 +4186,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MULReduce(long[] a, int idx) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4145,7 +4195,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MULReduceAll(long[] a) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4163,7 +4213,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4176,20 +4226,20 @@ public class LongVector128Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MUL_IDENTITY; - assertEquals((long) (id * id), id, + assertEquals((long) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id * x), x); - assertEquals((long) (x * id), x); + assertEquals((long) (scalar_mul(id, x)), x); + assertEquals((long) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id * x), x, + assertEquals((long) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x * id), x, + assertEquals((long) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4198,7 +4248,7 @@ public class LongVector128Tests extends AbstractVectorTest { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4207,7 +4257,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MULReduceAllMasked(long[] a, boolean[] mask) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4227,7 +4277,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4238,7 +4288,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MINReduce(long[] a, int idx) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4247,7 +4297,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MINReduceAll(long[] a) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4265,7 +4315,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4278,20 +4328,20 @@ public class LongVector128Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MIN_IDENTITY; - assertEquals((long) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.min(id, x), x); - assertEquals((long) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4300,7 +4350,7 @@ public class LongVector128Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4309,7 +4359,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MINReduceAllMasked(long[] a, boolean[] mask) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4329,7 +4379,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4340,7 +4390,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MAXReduce(long[] a, int idx) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4349,7 +4399,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MAXReduceAll(long[] a) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4367,7 +4417,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4380,20 +4430,20 @@ public class LongVector128Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MAX_IDENTITY; - assertEquals((long) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.max(id, x), x); - assertEquals((long) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4402,7 +4452,7 @@ public class LongVector128Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4411,7 +4461,7 @@ public class LongVector128Tests extends AbstractVectorTest { static long MAXReduceAllMasked(long[] a, boolean[] mask) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4431,7 +4481,7 @@ public class LongVector128Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5464,7 +5514,7 @@ public class LongVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5484,7 +5534,7 @@ public class LongVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5501,7 +5551,7 @@ public class LongVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5521,7 +5571,7 @@ public class LongVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -6234,11 +6284,11 @@ public class LongVector128Tests extends AbstractVectorTest { } static long NEG(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } static long neg(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6290,11 +6340,11 @@ public class LongVector128Tests extends AbstractVectorTest { } static long ABS(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } static long abs(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6785,7 +6835,7 @@ public class LongVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6801,7 +6851,7 @@ public class LongVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } diff --git a/test/jdk/jdk/incubator/vector/LongVector256Tests.java b/test/jdk/jdk/incubator/vector/LongVector256Tests.java index a766abe920f..84c8da4e800 100644 --- a/test/jdk/jdk/incubator/vector/LongVector256Tests.java +++ b/test/jdk/jdk/incubator/vector/LongVector256Tests.java @@ -1547,6 +1547,59 @@ public class LongVector256Tests extends AbstractVectorTest { return a >= b; } + static long firstNonZero(long a, long b) { + return Long.compare(a, (long) 0) != 0 ? a : b; + } + + static long scalar_or(long a, long b) { + return (long)(a | b); + } + + static long scalar_and(long a, long b) { + return (long)(a & b); + } + + static long scalar_xor(long a, long b) { + return (long)(a ^ b); + } + + static long scalar_add(long a, long b) { + return (long)(a + b); + } + + static long scalar_sub(long a, long b) { + return (long)(a - b); + } + + static long scalar_mul(long a, long b) { + return (long)(a * b); + } + + static long scalar_min(long a, long b) { + return (long)(Math.min(a, b)); + } + + static long scalar_max(long a, long b) { + return (long)(Math.max(a, b)); + } + + static long scalar_div(long a, long b) { + return (long)(a / b); + } + + static long scalar_fma(long a, long b, long c) { + return (long)(Math.fma(a, b, c)); + } + + static long scalar_abs(long a) { + return (long)(Math.abs(a)); + } + + static long scalar_neg(long a) { + return ((long)-a); + } + + static boolean ult(long a, long b) { return Long.compareUnsigned(a, b) < 0; } @@ -1563,9 +1616,6 @@ public class LongVector256Tests extends AbstractVectorTest { return Long.compareUnsigned(a, b) >= 0; } - static long firstNonZero(long a, long b) { - return Long.compare(a, (long) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1679,7 +1729,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long ADD(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1700,7 +1750,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long add(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1757,7 +1807,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long SUB(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1778,7 +1828,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long sub(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1835,7 +1885,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long MUL(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1856,7 +1906,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long mul(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -2003,7 +2053,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long FIRST_NONZERO(long a, long b) { - return (long)((a)!=0?a:b); + return (long)(firstNonZero(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3299,7 +3349,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long MIN(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3320,7 +3370,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long min(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3339,7 +3389,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long MAX(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3360,7 +3410,7 @@ public class LongVector256Tests extends AbstractVectorTest { } static long max(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3728,7 +3778,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ANDReduce(long[] a, int idx) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3737,7 +3787,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ANDReduceAll(long[] a) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3755,7 +3805,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3768,20 +3818,20 @@ public class LongVector256Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = AND_IDENTITY; - assertEquals((long) (id & id), id, + assertEquals((long) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id & x), x); - assertEquals((long) (x & id), x); + assertEquals((long) (scalar_and(id, x)), x); + assertEquals((long) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id & x), x, + assertEquals((long) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x & id), x, + assertEquals((long) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3790,7 +3840,7 @@ public class LongVector256Tests extends AbstractVectorTest { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3799,7 +3849,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ANDReduceAllMasked(long[] a, boolean[] mask) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3819,7 +3869,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3830,7 +3880,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ORReduce(long[] a, int idx) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3839,7 +3889,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ORReduceAll(long[] a) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3857,7 +3907,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3870,20 +3920,20 @@ public class LongVector256Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = OR_IDENTITY; - assertEquals((long) (id | id), id, + assertEquals((long) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id | x), x); - assertEquals((long) (x | id), x); + assertEquals((long) (scalar_or(id, x)), x); + assertEquals((long) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id | x), x, + assertEquals((long) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x | id), x, + assertEquals((long) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3892,7 +3942,7 @@ public class LongVector256Tests extends AbstractVectorTest { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3901,7 +3951,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ORReduceAllMasked(long[] a, boolean[] mask) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3921,7 +3971,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3932,7 +3982,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long XORReduce(long[] a, int idx) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3941,7 +3991,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long XORReduceAll(long[] a) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3959,7 +4009,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3972,20 +4022,20 @@ public class LongVector256Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = XOR_IDENTITY; - assertEquals((long) (id ^ id), id, + assertEquals((long) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id ^ x), x); - assertEquals((long) (x ^ id), x); + assertEquals((long) (scalar_xor(id, x)), x); + assertEquals((long) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id ^ x), x, + assertEquals((long) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x ^ id), x, + assertEquals((long) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3994,7 +4044,7 @@ public class LongVector256Tests extends AbstractVectorTest { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -4003,7 +4053,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long XORReduceAllMasked(long[] a, boolean[] mask) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4023,7 +4073,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4034,7 +4084,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ADDReduce(long[] a, int idx) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4043,7 +4093,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ADDReduceAll(long[] a) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4061,7 +4111,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4074,20 +4124,20 @@ public class LongVector256Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = ADD_IDENTITY; - assertEquals((long) (id + id), id, + assertEquals((long) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id + x), x); - assertEquals((long) (x + id), x); + assertEquals((long) (scalar_add(id, x)), x); + assertEquals((long) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id + x), x, + assertEquals((long) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x + id), x, + assertEquals((long) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4096,7 +4146,7 @@ public class LongVector256Tests extends AbstractVectorTest { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4105,7 +4155,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long ADDReduceAllMasked(long[] a, boolean[] mask) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4125,7 +4175,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4136,7 +4186,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MULReduce(long[] a, int idx) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4145,7 +4195,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MULReduceAll(long[] a) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4163,7 +4213,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4176,20 +4226,20 @@ public class LongVector256Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MUL_IDENTITY; - assertEquals((long) (id * id), id, + assertEquals((long) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id * x), x); - assertEquals((long) (x * id), x); + assertEquals((long) (scalar_mul(id, x)), x); + assertEquals((long) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id * x), x, + assertEquals((long) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x * id), x, + assertEquals((long) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4198,7 +4248,7 @@ public class LongVector256Tests extends AbstractVectorTest { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4207,7 +4257,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MULReduceAllMasked(long[] a, boolean[] mask) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4227,7 +4277,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4238,7 +4288,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MINReduce(long[] a, int idx) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4247,7 +4297,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MINReduceAll(long[] a) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4265,7 +4315,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4278,20 +4328,20 @@ public class LongVector256Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MIN_IDENTITY; - assertEquals((long) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.min(id, x), x); - assertEquals((long) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4300,7 +4350,7 @@ public class LongVector256Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4309,7 +4359,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MINReduceAllMasked(long[] a, boolean[] mask) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4329,7 +4379,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4340,7 +4390,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MAXReduce(long[] a, int idx) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4349,7 +4399,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MAXReduceAll(long[] a) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4367,7 +4417,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4380,20 +4430,20 @@ public class LongVector256Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MAX_IDENTITY; - assertEquals((long) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.max(id, x), x); - assertEquals((long) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4402,7 +4452,7 @@ public class LongVector256Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4411,7 +4461,7 @@ public class LongVector256Tests extends AbstractVectorTest { static long MAXReduceAllMasked(long[] a, boolean[] mask) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4431,7 +4481,7 @@ public class LongVector256Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5464,7 +5514,7 @@ public class LongVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5484,7 +5534,7 @@ public class LongVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5501,7 +5551,7 @@ public class LongVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5521,7 +5571,7 @@ public class LongVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -6234,11 +6284,11 @@ public class LongVector256Tests extends AbstractVectorTest { } static long NEG(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } static long neg(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6290,11 +6340,11 @@ public class LongVector256Tests extends AbstractVectorTest { } static long ABS(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } static long abs(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6785,7 +6835,7 @@ public class LongVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6801,7 +6851,7 @@ public class LongVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } diff --git a/test/jdk/jdk/incubator/vector/LongVector512Tests.java b/test/jdk/jdk/incubator/vector/LongVector512Tests.java index 503bd7942f2..00d8c4b010a 100644 --- a/test/jdk/jdk/incubator/vector/LongVector512Tests.java +++ b/test/jdk/jdk/incubator/vector/LongVector512Tests.java @@ -1547,6 +1547,59 @@ public class LongVector512Tests extends AbstractVectorTest { return a >= b; } + static long firstNonZero(long a, long b) { + return Long.compare(a, (long) 0) != 0 ? a : b; + } + + static long scalar_or(long a, long b) { + return (long)(a | b); + } + + static long scalar_and(long a, long b) { + return (long)(a & b); + } + + static long scalar_xor(long a, long b) { + return (long)(a ^ b); + } + + static long scalar_add(long a, long b) { + return (long)(a + b); + } + + static long scalar_sub(long a, long b) { + return (long)(a - b); + } + + static long scalar_mul(long a, long b) { + return (long)(a * b); + } + + static long scalar_min(long a, long b) { + return (long)(Math.min(a, b)); + } + + static long scalar_max(long a, long b) { + return (long)(Math.max(a, b)); + } + + static long scalar_div(long a, long b) { + return (long)(a / b); + } + + static long scalar_fma(long a, long b, long c) { + return (long)(Math.fma(a, b, c)); + } + + static long scalar_abs(long a) { + return (long)(Math.abs(a)); + } + + static long scalar_neg(long a) { + return ((long)-a); + } + + static boolean ult(long a, long b) { return Long.compareUnsigned(a, b) < 0; } @@ -1563,9 +1616,6 @@ public class LongVector512Tests extends AbstractVectorTest { return Long.compareUnsigned(a, b) >= 0; } - static long firstNonZero(long a, long b) { - return Long.compare(a, (long) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1679,7 +1729,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long ADD(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1700,7 +1750,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long add(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1757,7 +1807,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long SUB(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1778,7 +1828,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long sub(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1835,7 +1885,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long MUL(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1856,7 +1906,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long mul(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -2003,7 +2053,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long FIRST_NONZERO(long a, long b) { - return (long)((a)!=0?a:b); + return (long)(firstNonZero(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3299,7 +3349,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long MIN(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3320,7 +3370,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long min(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3339,7 +3389,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long MAX(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3360,7 +3410,7 @@ public class LongVector512Tests extends AbstractVectorTest { } static long max(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3728,7 +3778,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ANDReduce(long[] a, int idx) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3737,7 +3787,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ANDReduceAll(long[] a) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3755,7 +3805,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3768,20 +3818,20 @@ public class LongVector512Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = AND_IDENTITY; - assertEquals((long) (id & id), id, + assertEquals((long) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id & x), x); - assertEquals((long) (x & id), x); + assertEquals((long) (scalar_and(id, x)), x); + assertEquals((long) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id & x), x, + assertEquals((long) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x & id), x, + assertEquals((long) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3790,7 +3840,7 @@ public class LongVector512Tests extends AbstractVectorTest { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3799,7 +3849,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ANDReduceAllMasked(long[] a, boolean[] mask) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3819,7 +3869,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3830,7 +3880,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ORReduce(long[] a, int idx) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3839,7 +3889,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ORReduceAll(long[] a) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3857,7 +3907,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3870,20 +3920,20 @@ public class LongVector512Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = OR_IDENTITY; - assertEquals((long) (id | id), id, + assertEquals((long) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id | x), x); - assertEquals((long) (x | id), x); + assertEquals((long) (scalar_or(id, x)), x); + assertEquals((long) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id | x), x, + assertEquals((long) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x | id), x, + assertEquals((long) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3892,7 +3942,7 @@ public class LongVector512Tests extends AbstractVectorTest { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3901,7 +3951,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ORReduceAllMasked(long[] a, boolean[] mask) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3921,7 +3971,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3932,7 +3982,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long XORReduce(long[] a, int idx) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3941,7 +3991,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long XORReduceAll(long[] a) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3959,7 +4009,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3972,20 +4022,20 @@ public class LongVector512Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = XOR_IDENTITY; - assertEquals((long) (id ^ id), id, + assertEquals((long) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id ^ x), x); - assertEquals((long) (x ^ id), x); + assertEquals((long) (scalar_xor(id, x)), x); + assertEquals((long) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id ^ x), x, + assertEquals((long) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x ^ id), x, + assertEquals((long) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3994,7 +4044,7 @@ public class LongVector512Tests extends AbstractVectorTest { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -4003,7 +4053,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long XORReduceAllMasked(long[] a, boolean[] mask) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4023,7 +4073,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4034,7 +4084,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ADDReduce(long[] a, int idx) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4043,7 +4093,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ADDReduceAll(long[] a) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4061,7 +4111,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4074,20 +4124,20 @@ public class LongVector512Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = ADD_IDENTITY; - assertEquals((long) (id + id), id, + assertEquals((long) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id + x), x); - assertEquals((long) (x + id), x); + assertEquals((long) (scalar_add(id, x)), x); + assertEquals((long) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id + x), x, + assertEquals((long) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x + id), x, + assertEquals((long) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4096,7 +4146,7 @@ public class LongVector512Tests extends AbstractVectorTest { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4105,7 +4155,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long ADDReduceAllMasked(long[] a, boolean[] mask) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4125,7 +4175,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4136,7 +4186,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MULReduce(long[] a, int idx) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4145,7 +4195,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MULReduceAll(long[] a) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4163,7 +4213,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4176,20 +4226,20 @@ public class LongVector512Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MUL_IDENTITY; - assertEquals((long) (id * id), id, + assertEquals((long) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id * x), x); - assertEquals((long) (x * id), x); + assertEquals((long) (scalar_mul(id, x)), x); + assertEquals((long) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id * x), x, + assertEquals((long) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x * id), x, + assertEquals((long) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4198,7 +4248,7 @@ public class LongVector512Tests extends AbstractVectorTest { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4207,7 +4257,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MULReduceAllMasked(long[] a, boolean[] mask) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4227,7 +4277,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4238,7 +4288,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MINReduce(long[] a, int idx) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4247,7 +4297,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MINReduceAll(long[] a) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4265,7 +4315,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4278,20 +4328,20 @@ public class LongVector512Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MIN_IDENTITY; - assertEquals((long) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.min(id, x), x); - assertEquals((long) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4300,7 +4350,7 @@ public class LongVector512Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4309,7 +4359,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MINReduceAllMasked(long[] a, boolean[] mask) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4329,7 +4379,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4340,7 +4390,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MAXReduce(long[] a, int idx) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4349,7 +4399,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MAXReduceAll(long[] a) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4367,7 +4417,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4380,20 +4430,20 @@ public class LongVector512Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MAX_IDENTITY; - assertEquals((long) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.max(id, x), x); - assertEquals((long) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4402,7 +4452,7 @@ public class LongVector512Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4411,7 +4461,7 @@ public class LongVector512Tests extends AbstractVectorTest { static long MAXReduceAllMasked(long[] a, boolean[] mask) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4431,7 +4481,7 @@ public class LongVector512Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5464,7 +5514,7 @@ public class LongVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5484,7 +5534,7 @@ public class LongVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5501,7 +5551,7 @@ public class LongVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5521,7 +5571,7 @@ public class LongVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -6234,11 +6284,11 @@ public class LongVector512Tests extends AbstractVectorTest { } static long NEG(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } static long neg(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6290,11 +6340,11 @@ public class LongVector512Tests extends AbstractVectorTest { } static long ABS(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } static long abs(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6785,7 +6835,7 @@ public class LongVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6801,7 +6851,7 @@ public class LongVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } diff --git a/test/jdk/jdk/incubator/vector/LongVector64Tests.java b/test/jdk/jdk/incubator/vector/LongVector64Tests.java index 6ca3c63054a..d4cdfe54ad2 100644 --- a/test/jdk/jdk/incubator/vector/LongVector64Tests.java +++ b/test/jdk/jdk/incubator/vector/LongVector64Tests.java @@ -1547,6 +1547,59 @@ public class LongVector64Tests extends AbstractVectorTest { return a >= b; } + static long firstNonZero(long a, long b) { + return Long.compare(a, (long) 0) != 0 ? a : b; + } + + static long scalar_or(long a, long b) { + return (long)(a | b); + } + + static long scalar_and(long a, long b) { + return (long)(a & b); + } + + static long scalar_xor(long a, long b) { + return (long)(a ^ b); + } + + static long scalar_add(long a, long b) { + return (long)(a + b); + } + + static long scalar_sub(long a, long b) { + return (long)(a - b); + } + + static long scalar_mul(long a, long b) { + return (long)(a * b); + } + + static long scalar_min(long a, long b) { + return (long)(Math.min(a, b)); + } + + static long scalar_max(long a, long b) { + return (long)(Math.max(a, b)); + } + + static long scalar_div(long a, long b) { + return (long)(a / b); + } + + static long scalar_fma(long a, long b, long c) { + return (long)(Math.fma(a, b, c)); + } + + static long scalar_abs(long a) { + return (long)(Math.abs(a)); + } + + static long scalar_neg(long a) { + return ((long)-a); + } + + static boolean ult(long a, long b) { return Long.compareUnsigned(a, b) < 0; } @@ -1563,9 +1616,6 @@ public class LongVector64Tests extends AbstractVectorTest { return Long.compareUnsigned(a, b) >= 0; } - static long firstNonZero(long a, long b) { - return Long.compare(a, (long) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1679,7 +1729,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long ADD(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1700,7 +1750,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long add(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1757,7 +1807,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long SUB(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1778,7 +1828,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long sub(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1835,7 +1885,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long MUL(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1856,7 +1906,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long mul(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -2003,7 +2053,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long FIRST_NONZERO(long a, long b) { - return (long)((a)!=0?a:b); + return (long)(firstNonZero(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3299,7 +3349,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long MIN(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3320,7 +3370,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long min(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3339,7 +3389,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long MAX(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3360,7 +3410,7 @@ public class LongVector64Tests extends AbstractVectorTest { } static long max(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3728,7 +3778,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ANDReduce(long[] a, int idx) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3737,7 +3787,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ANDReduceAll(long[] a) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3755,7 +3805,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3768,20 +3818,20 @@ public class LongVector64Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = AND_IDENTITY; - assertEquals((long) (id & id), id, + assertEquals((long) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id & x), x); - assertEquals((long) (x & id), x); + assertEquals((long) (scalar_and(id, x)), x); + assertEquals((long) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id & x), x, + assertEquals((long) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x & id), x, + assertEquals((long) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3790,7 +3840,7 @@ public class LongVector64Tests extends AbstractVectorTest { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3799,7 +3849,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ANDReduceAllMasked(long[] a, boolean[] mask) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3819,7 +3869,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3830,7 +3880,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ORReduce(long[] a, int idx) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3839,7 +3889,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ORReduceAll(long[] a) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3857,7 +3907,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3870,20 +3920,20 @@ public class LongVector64Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = OR_IDENTITY; - assertEquals((long) (id | id), id, + assertEquals((long) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id | x), x); - assertEquals((long) (x | id), x); + assertEquals((long) (scalar_or(id, x)), x); + assertEquals((long) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id | x), x, + assertEquals((long) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x | id), x, + assertEquals((long) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3892,7 +3942,7 @@ public class LongVector64Tests extends AbstractVectorTest { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3901,7 +3951,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ORReduceAllMasked(long[] a, boolean[] mask) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3921,7 +3971,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3932,7 +3982,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long XORReduce(long[] a, int idx) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3941,7 +3991,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long XORReduceAll(long[] a) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3959,7 +4009,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3972,20 +4022,20 @@ public class LongVector64Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = XOR_IDENTITY; - assertEquals((long) (id ^ id), id, + assertEquals((long) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id ^ x), x); - assertEquals((long) (x ^ id), x); + assertEquals((long) (scalar_xor(id, x)), x); + assertEquals((long) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id ^ x), x, + assertEquals((long) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x ^ id), x, + assertEquals((long) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3994,7 +4044,7 @@ public class LongVector64Tests extends AbstractVectorTest { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -4003,7 +4053,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long XORReduceAllMasked(long[] a, boolean[] mask) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4023,7 +4073,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4034,7 +4084,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ADDReduce(long[] a, int idx) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4043,7 +4093,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ADDReduceAll(long[] a) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4061,7 +4111,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4074,20 +4124,20 @@ public class LongVector64Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = ADD_IDENTITY; - assertEquals((long) (id + id), id, + assertEquals((long) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id + x), x); - assertEquals((long) (x + id), x); + assertEquals((long) (scalar_add(id, x)), x); + assertEquals((long) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id + x), x, + assertEquals((long) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x + id), x, + assertEquals((long) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4096,7 +4146,7 @@ public class LongVector64Tests extends AbstractVectorTest { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4105,7 +4155,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long ADDReduceAllMasked(long[] a, boolean[] mask) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4125,7 +4175,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4136,7 +4186,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MULReduce(long[] a, int idx) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4145,7 +4195,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MULReduceAll(long[] a) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4163,7 +4213,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4176,20 +4226,20 @@ public class LongVector64Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MUL_IDENTITY; - assertEquals((long) (id * id), id, + assertEquals((long) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id * x), x); - assertEquals((long) (x * id), x); + assertEquals((long) (scalar_mul(id, x)), x); + assertEquals((long) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id * x), x, + assertEquals((long) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x * id), x, + assertEquals((long) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4198,7 +4248,7 @@ public class LongVector64Tests extends AbstractVectorTest { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4207,7 +4257,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MULReduceAllMasked(long[] a, boolean[] mask) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4227,7 +4277,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4238,7 +4288,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MINReduce(long[] a, int idx) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4247,7 +4297,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MINReduceAll(long[] a) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4265,7 +4315,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4278,20 +4328,20 @@ public class LongVector64Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MIN_IDENTITY; - assertEquals((long) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.min(id, x), x); - assertEquals((long) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4300,7 +4350,7 @@ public class LongVector64Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4309,7 +4359,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MINReduceAllMasked(long[] a, boolean[] mask) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4329,7 +4379,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4340,7 +4390,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MAXReduce(long[] a, int idx) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4349,7 +4399,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MAXReduceAll(long[] a) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4367,7 +4417,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4380,20 +4430,20 @@ public class LongVector64Tests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MAX_IDENTITY; - assertEquals((long) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.max(id, x), x); - assertEquals((long) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4402,7 +4452,7 @@ public class LongVector64Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4411,7 +4461,7 @@ public class LongVector64Tests extends AbstractVectorTest { static long MAXReduceAllMasked(long[] a, boolean[] mask) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4431,7 +4481,7 @@ public class LongVector64Tests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5464,7 +5514,7 @@ public class LongVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5484,7 +5534,7 @@ public class LongVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5501,7 +5551,7 @@ public class LongVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5521,7 +5571,7 @@ public class LongVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -6234,11 +6284,11 @@ public class LongVector64Tests extends AbstractVectorTest { } static long NEG(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } static long neg(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6290,11 +6340,11 @@ public class LongVector64Tests extends AbstractVectorTest { } static long ABS(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } static long abs(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6785,7 +6835,7 @@ public class LongVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6801,7 +6851,7 @@ public class LongVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } diff --git a/test/jdk/jdk/incubator/vector/LongVectorMaxTests.java b/test/jdk/jdk/incubator/vector/LongVectorMaxTests.java index aef89af5893..597169b00f5 100644 --- a/test/jdk/jdk/incubator/vector/LongVectorMaxTests.java +++ b/test/jdk/jdk/incubator/vector/LongVectorMaxTests.java @@ -1553,6 +1553,59 @@ public class LongVectorMaxTests extends AbstractVectorTest { return a >= b; } + static long firstNonZero(long a, long b) { + return Long.compare(a, (long) 0) != 0 ? a : b; + } + + static long scalar_or(long a, long b) { + return (long)(a | b); + } + + static long scalar_and(long a, long b) { + return (long)(a & b); + } + + static long scalar_xor(long a, long b) { + return (long)(a ^ b); + } + + static long scalar_add(long a, long b) { + return (long)(a + b); + } + + static long scalar_sub(long a, long b) { + return (long)(a - b); + } + + static long scalar_mul(long a, long b) { + return (long)(a * b); + } + + static long scalar_min(long a, long b) { + return (long)(Math.min(a, b)); + } + + static long scalar_max(long a, long b) { + return (long)(Math.max(a, b)); + } + + static long scalar_div(long a, long b) { + return (long)(a / b); + } + + static long scalar_fma(long a, long b, long c) { + return (long)(Math.fma(a, b, c)); + } + + static long scalar_abs(long a) { + return (long)(Math.abs(a)); + } + + static long scalar_neg(long a) { + return ((long)-a); + } + + static boolean ult(long a, long b) { return Long.compareUnsigned(a, b) < 0; } @@ -1569,9 +1622,6 @@ public class LongVectorMaxTests extends AbstractVectorTest { return Long.compareUnsigned(a, b) >= 0; } - static long firstNonZero(long a, long b) { - return Long.compare(a, (long) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1685,7 +1735,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long ADD(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1706,7 +1756,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long add(long a, long b) { - return (long)(a + b); + return (long)(scalar_add(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1763,7 +1813,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long SUB(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1784,7 +1834,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long sub(long a, long b) { - return (long)(a - b); + return (long)(scalar_sub(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1841,7 +1891,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long MUL(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -1862,7 +1912,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long mul(long a, long b) { - return (long)(a * b); + return (long)(scalar_mul(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -2009,7 +2059,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long FIRST_NONZERO(long a, long b) { - return (long)((a)!=0?a:b); + return (long)(firstNonZero(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3305,7 +3355,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long MIN(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3326,7 +3376,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long min(long a, long b) { - return (long)(Math.min(a, b)); + return (long)(scalar_min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3345,7 +3395,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long MAX(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3366,7 +3416,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long max(long a, long b) { - return (long)(Math.max(a, b)); + return (long)(scalar_max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") @@ -3734,7 +3784,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ANDReduce(long[] a, int idx) { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3743,7 +3793,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ANDReduceAll(long[] a) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3761,7 +3811,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3774,20 +3824,20 @@ public class LongVectorMaxTests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = AND_IDENTITY; - assertEquals((long) (id & id), id, + assertEquals((long) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id & x), x); - assertEquals((long) (x & id), x); + assertEquals((long) (scalar_and(id, x)), x); + assertEquals((long) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id & x), x, + assertEquals((long) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x & id), x, + assertEquals((long) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3796,7 +3846,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { long res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3805,7 +3855,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ANDReduceAllMasked(long[] a, boolean[] mask) { long res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3825,7 +3875,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3836,7 +3886,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ORReduce(long[] a, int idx) { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3845,7 +3895,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ORReduceAll(long[] a) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3863,7 +3913,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3876,20 +3926,20 @@ public class LongVectorMaxTests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = OR_IDENTITY; - assertEquals((long) (id | id), id, + assertEquals((long) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id | x), x); - assertEquals((long) (x | id), x); + assertEquals((long) (scalar_or(id, x)), x); + assertEquals((long) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id | x), x, + assertEquals((long) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x | id), x, + assertEquals((long) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3898,7 +3948,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { long res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3907,7 +3957,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ORReduceAllMasked(long[] a, boolean[] mask) { long res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3927,7 +3977,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3938,7 +3988,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long XORReduce(long[] a, int idx) { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3947,7 +3997,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long XORReduceAll(long[] a) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3965,7 +4015,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3978,20 +4028,20 @@ public class LongVectorMaxTests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = XOR_IDENTITY; - assertEquals((long) (id ^ id), id, + assertEquals((long) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id ^ x), x); - assertEquals((long) (x ^ id), x); + assertEquals((long) (scalar_xor(id, x)), x); + assertEquals((long) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id ^ x), x, + assertEquals((long) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x ^ id), x, + assertEquals((long) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -4000,7 +4050,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { long res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -4009,7 +4059,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long XORReduceAllMasked(long[] a, boolean[] mask) { long res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -4029,7 +4079,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -4040,7 +4090,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ADDReduce(long[] a, int idx) { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4049,7 +4099,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ADDReduceAll(long[] a) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -4067,7 +4117,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4080,20 +4130,20 @@ public class LongVectorMaxTests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = ADD_IDENTITY; - assertEquals((long) (id + id), id, + assertEquals((long) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id + x), x); - assertEquals((long) (x + id), x); + assertEquals((long) (scalar_add(id, x)), x); + assertEquals((long) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id + x), x, + assertEquals((long) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x + id), x, + assertEquals((long) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4102,7 +4152,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { long res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4111,7 +4161,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long ADDReduceAllMasked(long[] a, boolean[] mask) { long res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4131,7 +4181,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4142,7 +4192,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MULReduce(long[] a, int idx) { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4151,7 +4201,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MULReduceAll(long[] a) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4169,7 +4219,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4182,20 +4232,20 @@ public class LongVectorMaxTests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MUL_IDENTITY; - assertEquals((long) (id * id), id, + assertEquals((long) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) (id * x), x); - assertEquals((long) (x * id), x); + assertEquals((long) (scalar_mul(id, x)), x); + assertEquals((long) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((long) (id * x), x, + assertEquals((long) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((long) (x * id), x, + assertEquals((long) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4204,7 +4254,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { long res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4213,7 +4263,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MULReduceAllMasked(long[] a, boolean[] mask) { long res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4233,7 +4283,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4244,7 +4294,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MINReduce(long[] a, int idx) { long res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4253,7 +4303,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MINReduceAll(long[] a) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4271,7 +4321,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4284,20 +4334,20 @@ public class LongVectorMaxTests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MIN_IDENTITY; - assertEquals((long) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.min(id, x), x); - assertEquals((long) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4306,7 +4356,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4315,7 +4365,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MINReduceAllMasked(long[] a, boolean[] mask) { long res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4335,7 +4385,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (long) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4346,7 +4396,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MAXReduce(long[] a, int idx) { long res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (long) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4355,7 +4405,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MAXReduceAll(long[] a) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4373,7 +4423,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4386,20 +4436,20 @@ public class LongVectorMaxTests extends AbstractVectorTest { long[] a = fa.apply(SPECIES.length()); long id = MAX_IDENTITY; - assertEquals((long) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); long x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((long) Math.max(id, x), x); - assertEquals((long) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((long) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((long) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4408,7 +4458,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4417,7 +4467,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { static long MAXReduceAllMasked(long[] a, boolean[] mask) { long res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (long) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4437,7 +4487,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { LongVector av = LongVector.fromArray(SPECIES, a, i); long v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (long) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5470,7 +5520,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5490,7 +5540,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5507,7 +5557,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5527,7 +5577,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -6240,11 +6290,11 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long NEG(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } static long neg(long a) { - return (long)(-((long)a)); + return (long)(scalar_neg((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6296,11 +6346,11 @@ public class LongVectorMaxTests extends AbstractVectorTest { } static long ABS(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } static long abs(long a) { - return (long)(Math.abs((long)a)); + return (long)(scalar_abs((long)a)); } @Test(dataProvider = "longUnaryOpProvider") @@ -6791,7 +6841,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6807,7 +6857,7 @@ public class LongVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } diff --git a/test/jdk/jdk/incubator/vector/ShortVector128Tests.java b/test/jdk/jdk/incubator/vector/ShortVector128Tests.java index 7cf49513620..85e7d715182 100644 --- a/test/jdk/jdk/incubator/vector/ShortVector128Tests.java +++ b/test/jdk/jdk/incubator/vector/ShortVector128Tests.java @@ -1565,6 +1565,59 @@ public class ShortVector128Tests extends AbstractVectorTest { return a >= b; } + static short firstNonZero(short a, short b) { + return Short.compare(a, (short) 0) != 0 ? a : b; + } + + static short scalar_or(short a, short b) { + return (short)(a | b); + } + + static short scalar_and(short a, short b) { + return (short)(a & b); + } + + static short scalar_xor(short a, short b) { + return (short)(a ^ b); + } + + static short scalar_add(short a, short b) { + return (short)(a + b); + } + + static short scalar_sub(short a, short b) { + return (short)(a - b); + } + + static short scalar_mul(short a, short b) { + return (short)(a * b); + } + + static short scalar_min(short a, short b) { + return (short)(Math.min(a, b)); + } + + static short scalar_max(short a, short b) { + return (short)(Math.max(a, b)); + } + + static short scalar_div(short a, short b) { + return (short)(a / b); + } + + static short scalar_fma(short a, short b, short c) { + return (short)(Math.fma(a, b, c)); + } + + static short scalar_abs(short a) { + return (short)(Math.abs(a)); + } + + static short scalar_neg(short a) { + return ((short)-a); + } + + static boolean ult(short a, short b) { return Short.compareUnsigned(a, b) < 0; } @@ -1581,9 +1634,6 @@ public class ShortVector128Tests extends AbstractVectorTest { return Short.compareUnsigned(a, b) >= 0; } - static short firstNonZero(short a, short b) { - return Short.compare(a, (short) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1692,7 +1742,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short ADD(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1713,7 +1763,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short add(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1770,7 +1820,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short SUB(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1791,7 +1841,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short sub(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1848,7 +1898,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short MUL(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1869,7 +1919,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short mul(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -2016,7 +2066,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short FIRST_NONZERO(short a, short b) { - return (short)((a)!=0?a:b); + return (short)(firstNonZero(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3230,7 +3280,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short MIN(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3251,7 +3301,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short min(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3270,7 +3320,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short MAX(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3291,7 +3341,7 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short max(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3659,7 +3709,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ANDReduce(short[] a, int idx) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3668,7 +3718,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ANDReduceAll(short[] a) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3686,7 +3736,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3699,20 +3749,20 @@ public class ShortVector128Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = AND_IDENTITY; - assertEquals((short) (id & id), id, + assertEquals((short) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id & x), x); - assertEquals((short) (x & id), x); + assertEquals((short) (scalar_and(id, x)), x); + assertEquals((short) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id & x), x, + assertEquals((short) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x & id), x, + assertEquals((short) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3721,7 +3771,7 @@ public class ShortVector128Tests extends AbstractVectorTest { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3730,7 +3780,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ANDReduceAllMasked(short[] a, boolean[] mask) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3750,7 +3800,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3761,7 +3811,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ORReduce(short[] a, int idx) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3770,7 +3820,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ORReduceAll(short[] a) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3788,7 +3838,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3801,20 +3851,20 @@ public class ShortVector128Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = OR_IDENTITY; - assertEquals((short) (id | id), id, + assertEquals((short) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id | x), x); - assertEquals((short) (x | id), x); + assertEquals((short) (scalar_or(id, x)), x); + assertEquals((short) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id | x), x, + assertEquals((short) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x | id), x, + assertEquals((short) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3823,7 +3873,7 @@ public class ShortVector128Tests extends AbstractVectorTest { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3832,7 +3882,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ORReduceAllMasked(short[] a, boolean[] mask) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3852,7 +3902,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3863,7 +3913,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short XORReduce(short[] a, int idx) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3872,7 +3922,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short XORReduceAll(short[] a) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3890,7 +3940,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3903,20 +3953,20 @@ public class ShortVector128Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = XOR_IDENTITY; - assertEquals((short) (id ^ id), id, + assertEquals((short) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id ^ x), x); - assertEquals((short) (x ^ id), x); + assertEquals((short) (scalar_xor(id, x)), x); + assertEquals((short) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id ^ x), x, + assertEquals((short) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x ^ id), x, + assertEquals((short) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3925,7 +3975,7 @@ public class ShortVector128Tests extends AbstractVectorTest { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3934,7 +3984,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short XORReduceAllMasked(short[] a, boolean[] mask) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3954,7 +4004,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3965,7 +4015,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ADDReduce(short[] a, int idx) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3974,7 +4024,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ADDReduceAll(short[] a) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -3992,7 +4042,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4005,20 +4055,20 @@ public class ShortVector128Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = ADD_IDENTITY; - assertEquals((short) (id + id), id, + assertEquals((short) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id + x), x); - assertEquals((short) (x + id), x); + assertEquals((short) (scalar_add(id, x)), x); + assertEquals((short) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id + x), x, + assertEquals((short) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x + id), x, + assertEquals((short) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4027,7 +4077,7 @@ public class ShortVector128Tests extends AbstractVectorTest { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4036,7 +4086,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short ADDReduceAllMasked(short[] a, boolean[] mask) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4056,7 +4106,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4067,7 +4117,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MULReduce(short[] a, int idx) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4076,7 +4126,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MULReduceAll(short[] a) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4094,7 +4144,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4107,20 +4157,20 @@ public class ShortVector128Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MUL_IDENTITY; - assertEquals((short) (id * id), id, + assertEquals((short) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id * x), x); - assertEquals((short) (x * id), x); + assertEquals((short) (scalar_mul(id, x)), x); + assertEquals((short) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id * x), x, + assertEquals((short) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x * id), x, + assertEquals((short) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4129,7 +4179,7 @@ public class ShortVector128Tests extends AbstractVectorTest { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4138,7 +4188,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MULReduceAllMasked(short[] a, boolean[] mask) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4158,7 +4208,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4169,7 +4219,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MINReduce(short[] a, int idx) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4178,7 +4228,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MINReduceAll(short[] a) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4196,7 +4246,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4209,20 +4259,20 @@ public class ShortVector128Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MIN_IDENTITY; - assertEquals((short) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.min(id, x), x); - assertEquals((short) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4231,7 +4281,7 @@ public class ShortVector128Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4240,7 +4290,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MINReduceAllMasked(short[] a, boolean[] mask) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4260,7 +4310,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4271,7 +4321,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MAXReduce(short[] a, int idx) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4280,7 +4330,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MAXReduceAll(short[] a) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4298,7 +4348,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4311,20 +4361,20 @@ public class ShortVector128Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MAX_IDENTITY; - assertEquals((short) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.max(id, x), x); - assertEquals((short) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4333,7 +4383,7 @@ public class ShortVector128Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4342,7 +4392,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static short MAXReduceAllMasked(short[] a, boolean[] mask) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4362,7 +4412,7 @@ public class ShortVector128Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5395,7 +5445,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5415,7 +5465,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5431,7 +5481,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (short)((long)b[i]))); } } } @@ -5451,7 +5501,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (short)((long)b[i])))); } } } @@ -5467,7 +5517,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5487,7 +5537,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5503,7 +5553,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (short)((long)b[i]))); } } } @@ -5523,7 +5573,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (short)((long)b[i])))); } } } @@ -6235,11 +6285,11 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short NEG(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } static short neg(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6291,11 +6341,11 @@ public class ShortVector128Tests extends AbstractVectorTest { } static short ABS(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } static short abs(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6786,7 +6836,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6802,7 +6852,7 @@ public class ShortVector128Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6871,7 +6921,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static long ADDReduceLong(short[] a, int idx) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6880,7 +6930,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static long ADDReduceAllLong(short[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((short)res, (short)ADDReduceLong(a, i)); } return res; @@ -6898,8 +6948,8 @@ public class ShortVector128Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6909,8 +6959,9 @@ public class ShortVector128Tests extends AbstractVectorTest { static long ADDReduceLongMasked(short[] a, int idx, boolean[] mask) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6919,7 +6970,7 @@ public class ShortVector128Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(short[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((short)res, (short)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6939,8 +6990,8 @@ public class ShortVector128Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/ShortVector256Tests.java b/test/jdk/jdk/incubator/vector/ShortVector256Tests.java index 5104e3724f7..df379b64e3a 100644 --- a/test/jdk/jdk/incubator/vector/ShortVector256Tests.java +++ b/test/jdk/jdk/incubator/vector/ShortVector256Tests.java @@ -1565,6 +1565,59 @@ public class ShortVector256Tests extends AbstractVectorTest { return a >= b; } + static short firstNonZero(short a, short b) { + return Short.compare(a, (short) 0) != 0 ? a : b; + } + + static short scalar_or(short a, short b) { + return (short)(a | b); + } + + static short scalar_and(short a, short b) { + return (short)(a & b); + } + + static short scalar_xor(short a, short b) { + return (short)(a ^ b); + } + + static short scalar_add(short a, short b) { + return (short)(a + b); + } + + static short scalar_sub(short a, short b) { + return (short)(a - b); + } + + static short scalar_mul(short a, short b) { + return (short)(a * b); + } + + static short scalar_min(short a, short b) { + return (short)(Math.min(a, b)); + } + + static short scalar_max(short a, short b) { + return (short)(Math.max(a, b)); + } + + static short scalar_div(short a, short b) { + return (short)(a / b); + } + + static short scalar_fma(short a, short b, short c) { + return (short)(Math.fma(a, b, c)); + } + + static short scalar_abs(short a) { + return (short)(Math.abs(a)); + } + + static short scalar_neg(short a) { + return ((short)-a); + } + + static boolean ult(short a, short b) { return Short.compareUnsigned(a, b) < 0; } @@ -1581,9 +1634,6 @@ public class ShortVector256Tests extends AbstractVectorTest { return Short.compareUnsigned(a, b) >= 0; } - static short firstNonZero(short a, short b) { - return Short.compare(a, (short) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1692,7 +1742,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short ADD(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1713,7 +1763,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short add(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1770,7 +1820,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short SUB(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1791,7 +1841,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short sub(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1848,7 +1898,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short MUL(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1869,7 +1919,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short mul(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -2016,7 +2066,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short FIRST_NONZERO(short a, short b) { - return (short)((a)!=0?a:b); + return (short)(firstNonZero(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3230,7 +3280,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short MIN(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3251,7 +3301,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short min(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3270,7 +3320,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short MAX(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3291,7 +3341,7 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short max(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3659,7 +3709,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ANDReduce(short[] a, int idx) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3668,7 +3718,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ANDReduceAll(short[] a) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3686,7 +3736,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3699,20 +3749,20 @@ public class ShortVector256Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = AND_IDENTITY; - assertEquals((short) (id & id), id, + assertEquals((short) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id & x), x); - assertEquals((short) (x & id), x); + assertEquals((short) (scalar_and(id, x)), x); + assertEquals((short) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id & x), x, + assertEquals((short) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x & id), x, + assertEquals((short) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3721,7 +3771,7 @@ public class ShortVector256Tests extends AbstractVectorTest { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3730,7 +3780,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ANDReduceAllMasked(short[] a, boolean[] mask) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3750,7 +3800,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3761,7 +3811,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ORReduce(short[] a, int idx) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3770,7 +3820,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ORReduceAll(short[] a) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3788,7 +3838,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3801,20 +3851,20 @@ public class ShortVector256Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = OR_IDENTITY; - assertEquals((short) (id | id), id, + assertEquals((short) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id | x), x); - assertEquals((short) (x | id), x); + assertEquals((short) (scalar_or(id, x)), x); + assertEquals((short) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id | x), x, + assertEquals((short) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x | id), x, + assertEquals((short) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3823,7 +3873,7 @@ public class ShortVector256Tests extends AbstractVectorTest { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3832,7 +3882,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ORReduceAllMasked(short[] a, boolean[] mask) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3852,7 +3902,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3863,7 +3913,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short XORReduce(short[] a, int idx) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3872,7 +3922,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short XORReduceAll(short[] a) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3890,7 +3940,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3903,20 +3953,20 @@ public class ShortVector256Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = XOR_IDENTITY; - assertEquals((short) (id ^ id), id, + assertEquals((short) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id ^ x), x); - assertEquals((short) (x ^ id), x); + assertEquals((short) (scalar_xor(id, x)), x); + assertEquals((short) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id ^ x), x, + assertEquals((short) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x ^ id), x, + assertEquals((short) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3925,7 +3975,7 @@ public class ShortVector256Tests extends AbstractVectorTest { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3934,7 +3984,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short XORReduceAllMasked(short[] a, boolean[] mask) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3954,7 +4004,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3965,7 +4015,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ADDReduce(short[] a, int idx) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3974,7 +4024,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ADDReduceAll(short[] a) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -3992,7 +4042,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4005,20 +4055,20 @@ public class ShortVector256Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = ADD_IDENTITY; - assertEquals((short) (id + id), id, + assertEquals((short) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id + x), x); - assertEquals((short) (x + id), x); + assertEquals((short) (scalar_add(id, x)), x); + assertEquals((short) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id + x), x, + assertEquals((short) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x + id), x, + assertEquals((short) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4027,7 +4077,7 @@ public class ShortVector256Tests extends AbstractVectorTest { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4036,7 +4086,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short ADDReduceAllMasked(short[] a, boolean[] mask) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4056,7 +4106,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4067,7 +4117,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MULReduce(short[] a, int idx) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4076,7 +4126,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MULReduceAll(short[] a) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4094,7 +4144,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4107,20 +4157,20 @@ public class ShortVector256Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MUL_IDENTITY; - assertEquals((short) (id * id), id, + assertEquals((short) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id * x), x); - assertEquals((short) (x * id), x); + assertEquals((short) (scalar_mul(id, x)), x); + assertEquals((short) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id * x), x, + assertEquals((short) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x * id), x, + assertEquals((short) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4129,7 +4179,7 @@ public class ShortVector256Tests extends AbstractVectorTest { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4138,7 +4188,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MULReduceAllMasked(short[] a, boolean[] mask) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4158,7 +4208,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4169,7 +4219,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MINReduce(short[] a, int idx) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4178,7 +4228,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MINReduceAll(short[] a) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4196,7 +4246,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4209,20 +4259,20 @@ public class ShortVector256Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MIN_IDENTITY; - assertEquals((short) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.min(id, x), x); - assertEquals((short) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4231,7 +4281,7 @@ public class ShortVector256Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4240,7 +4290,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MINReduceAllMasked(short[] a, boolean[] mask) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4260,7 +4310,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4271,7 +4321,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MAXReduce(short[] a, int idx) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4280,7 +4330,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MAXReduceAll(short[] a) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4298,7 +4348,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4311,20 +4361,20 @@ public class ShortVector256Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MAX_IDENTITY; - assertEquals((short) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.max(id, x), x); - assertEquals((short) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4333,7 +4383,7 @@ public class ShortVector256Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4342,7 +4392,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static short MAXReduceAllMasked(short[] a, boolean[] mask) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4362,7 +4412,7 @@ public class ShortVector256Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5395,7 +5445,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5415,7 +5465,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5431,7 +5481,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (short)((long)b[i]))); } } } @@ -5451,7 +5501,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (short)((long)b[i])))); } } } @@ -5467,7 +5517,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5487,7 +5537,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5503,7 +5553,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (short)((long)b[i]))); } } } @@ -5523,7 +5573,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (short)((long)b[i])))); } } } @@ -6235,11 +6285,11 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short NEG(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } static short neg(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6291,11 +6341,11 @@ public class ShortVector256Tests extends AbstractVectorTest { } static short ABS(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } static short abs(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6786,7 +6836,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6802,7 +6852,7 @@ public class ShortVector256Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6871,7 +6921,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static long ADDReduceLong(short[] a, int idx) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6880,7 +6930,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static long ADDReduceAllLong(short[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((short)res, (short)ADDReduceLong(a, i)); } return res; @@ -6898,8 +6948,8 @@ public class ShortVector256Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6909,8 +6959,9 @@ public class ShortVector256Tests extends AbstractVectorTest { static long ADDReduceLongMasked(short[] a, int idx, boolean[] mask) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6919,7 +6970,7 @@ public class ShortVector256Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(short[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((short)res, (short)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6939,8 +6990,8 @@ public class ShortVector256Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/ShortVector512Tests.java b/test/jdk/jdk/incubator/vector/ShortVector512Tests.java index 69dc6d8019f..ae5804c3688 100644 --- a/test/jdk/jdk/incubator/vector/ShortVector512Tests.java +++ b/test/jdk/jdk/incubator/vector/ShortVector512Tests.java @@ -1565,6 +1565,59 @@ public class ShortVector512Tests extends AbstractVectorTest { return a >= b; } + static short firstNonZero(short a, short b) { + return Short.compare(a, (short) 0) != 0 ? a : b; + } + + static short scalar_or(short a, short b) { + return (short)(a | b); + } + + static short scalar_and(short a, short b) { + return (short)(a & b); + } + + static short scalar_xor(short a, short b) { + return (short)(a ^ b); + } + + static short scalar_add(short a, short b) { + return (short)(a + b); + } + + static short scalar_sub(short a, short b) { + return (short)(a - b); + } + + static short scalar_mul(short a, short b) { + return (short)(a * b); + } + + static short scalar_min(short a, short b) { + return (short)(Math.min(a, b)); + } + + static short scalar_max(short a, short b) { + return (short)(Math.max(a, b)); + } + + static short scalar_div(short a, short b) { + return (short)(a / b); + } + + static short scalar_fma(short a, short b, short c) { + return (short)(Math.fma(a, b, c)); + } + + static short scalar_abs(short a) { + return (short)(Math.abs(a)); + } + + static short scalar_neg(short a) { + return ((short)-a); + } + + static boolean ult(short a, short b) { return Short.compareUnsigned(a, b) < 0; } @@ -1581,9 +1634,6 @@ public class ShortVector512Tests extends AbstractVectorTest { return Short.compareUnsigned(a, b) >= 0; } - static short firstNonZero(short a, short b) { - return Short.compare(a, (short) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1692,7 +1742,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short ADD(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1713,7 +1763,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short add(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1770,7 +1820,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short SUB(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1791,7 +1841,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short sub(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1848,7 +1898,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short MUL(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1869,7 +1919,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short mul(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -2016,7 +2066,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short FIRST_NONZERO(short a, short b) { - return (short)((a)!=0?a:b); + return (short)(firstNonZero(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3230,7 +3280,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short MIN(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3251,7 +3301,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short min(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3270,7 +3320,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short MAX(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3291,7 +3341,7 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short max(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3659,7 +3709,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ANDReduce(short[] a, int idx) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3668,7 +3718,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ANDReduceAll(short[] a) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3686,7 +3736,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3699,20 +3749,20 @@ public class ShortVector512Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = AND_IDENTITY; - assertEquals((short) (id & id), id, + assertEquals((short) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id & x), x); - assertEquals((short) (x & id), x); + assertEquals((short) (scalar_and(id, x)), x); + assertEquals((short) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id & x), x, + assertEquals((short) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x & id), x, + assertEquals((short) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3721,7 +3771,7 @@ public class ShortVector512Tests extends AbstractVectorTest { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3730,7 +3780,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ANDReduceAllMasked(short[] a, boolean[] mask) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3750,7 +3800,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3761,7 +3811,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ORReduce(short[] a, int idx) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3770,7 +3820,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ORReduceAll(short[] a) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3788,7 +3838,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3801,20 +3851,20 @@ public class ShortVector512Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = OR_IDENTITY; - assertEquals((short) (id | id), id, + assertEquals((short) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id | x), x); - assertEquals((short) (x | id), x); + assertEquals((short) (scalar_or(id, x)), x); + assertEquals((short) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id | x), x, + assertEquals((short) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x | id), x, + assertEquals((short) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3823,7 +3873,7 @@ public class ShortVector512Tests extends AbstractVectorTest { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3832,7 +3882,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ORReduceAllMasked(short[] a, boolean[] mask) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3852,7 +3902,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3863,7 +3913,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short XORReduce(short[] a, int idx) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3872,7 +3922,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short XORReduceAll(short[] a) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3890,7 +3940,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3903,20 +3953,20 @@ public class ShortVector512Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = XOR_IDENTITY; - assertEquals((short) (id ^ id), id, + assertEquals((short) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id ^ x), x); - assertEquals((short) (x ^ id), x); + assertEquals((short) (scalar_xor(id, x)), x); + assertEquals((short) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id ^ x), x, + assertEquals((short) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x ^ id), x, + assertEquals((short) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3925,7 +3975,7 @@ public class ShortVector512Tests extends AbstractVectorTest { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3934,7 +3984,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short XORReduceAllMasked(short[] a, boolean[] mask) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3954,7 +4004,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3965,7 +4015,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ADDReduce(short[] a, int idx) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3974,7 +4024,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ADDReduceAll(short[] a) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -3992,7 +4042,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4005,20 +4055,20 @@ public class ShortVector512Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = ADD_IDENTITY; - assertEquals((short) (id + id), id, + assertEquals((short) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id + x), x); - assertEquals((short) (x + id), x); + assertEquals((short) (scalar_add(id, x)), x); + assertEquals((short) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id + x), x, + assertEquals((short) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x + id), x, + assertEquals((short) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4027,7 +4077,7 @@ public class ShortVector512Tests extends AbstractVectorTest { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4036,7 +4086,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short ADDReduceAllMasked(short[] a, boolean[] mask) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4056,7 +4106,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4067,7 +4117,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MULReduce(short[] a, int idx) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4076,7 +4126,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MULReduceAll(short[] a) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4094,7 +4144,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4107,20 +4157,20 @@ public class ShortVector512Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MUL_IDENTITY; - assertEquals((short) (id * id), id, + assertEquals((short) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id * x), x); - assertEquals((short) (x * id), x); + assertEquals((short) (scalar_mul(id, x)), x); + assertEquals((short) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id * x), x, + assertEquals((short) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x * id), x, + assertEquals((short) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4129,7 +4179,7 @@ public class ShortVector512Tests extends AbstractVectorTest { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4138,7 +4188,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MULReduceAllMasked(short[] a, boolean[] mask) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4158,7 +4208,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4169,7 +4219,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MINReduce(short[] a, int idx) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4178,7 +4228,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MINReduceAll(short[] a) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4196,7 +4246,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4209,20 +4259,20 @@ public class ShortVector512Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MIN_IDENTITY; - assertEquals((short) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.min(id, x), x); - assertEquals((short) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4231,7 +4281,7 @@ public class ShortVector512Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4240,7 +4290,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MINReduceAllMasked(short[] a, boolean[] mask) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4260,7 +4310,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4271,7 +4321,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MAXReduce(short[] a, int idx) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4280,7 +4330,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MAXReduceAll(short[] a) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4298,7 +4348,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4311,20 +4361,20 @@ public class ShortVector512Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MAX_IDENTITY; - assertEquals((short) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.max(id, x), x); - assertEquals((short) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4333,7 +4383,7 @@ public class ShortVector512Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4342,7 +4392,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static short MAXReduceAllMasked(short[] a, boolean[] mask) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4362,7 +4412,7 @@ public class ShortVector512Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5395,7 +5445,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5415,7 +5465,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5431,7 +5481,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (short)((long)b[i]))); } } } @@ -5451,7 +5501,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (short)((long)b[i])))); } } } @@ -5467,7 +5517,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5487,7 +5537,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5503,7 +5553,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (short)((long)b[i]))); } } } @@ -5523,7 +5573,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (short)((long)b[i])))); } } } @@ -6235,11 +6285,11 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short NEG(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } static short neg(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6291,11 +6341,11 @@ public class ShortVector512Tests extends AbstractVectorTest { } static short ABS(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } static short abs(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6786,7 +6836,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6802,7 +6852,7 @@ public class ShortVector512Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6871,7 +6921,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static long ADDReduceLong(short[] a, int idx) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6880,7 +6930,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static long ADDReduceAllLong(short[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((short)res, (short)ADDReduceLong(a, i)); } return res; @@ -6898,8 +6948,8 @@ public class ShortVector512Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6909,8 +6959,9 @@ public class ShortVector512Tests extends AbstractVectorTest { static long ADDReduceLongMasked(short[] a, int idx, boolean[] mask) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6919,7 +6970,7 @@ public class ShortVector512Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(short[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((short)res, (short)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6939,8 +6990,8 @@ public class ShortVector512Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/ShortVector64Tests.java b/test/jdk/jdk/incubator/vector/ShortVector64Tests.java index dd9f7125853..5f84682f02f 100644 --- a/test/jdk/jdk/incubator/vector/ShortVector64Tests.java +++ b/test/jdk/jdk/incubator/vector/ShortVector64Tests.java @@ -1565,6 +1565,59 @@ public class ShortVector64Tests extends AbstractVectorTest { return a >= b; } + static short firstNonZero(short a, short b) { + return Short.compare(a, (short) 0) != 0 ? a : b; + } + + static short scalar_or(short a, short b) { + return (short)(a | b); + } + + static short scalar_and(short a, short b) { + return (short)(a & b); + } + + static short scalar_xor(short a, short b) { + return (short)(a ^ b); + } + + static short scalar_add(short a, short b) { + return (short)(a + b); + } + + static short scalar_sub(short a, short b) { + return (short)(a - b); + } + + static short scalar_mul(short a, short b) { + return (short)(a * b); + } + + static short scalar_min(short a, short b) { + return (short)(Math.min(a, b)); + } + + static short scalar_max(short a, short b) { + return (short)(Math.max(a, b)); + } + + static short scalar_div(short a, short b) { + return (short)(a / b); + } + + static short scalar_fma(short a, short b, short c) { + return (short)(Math.fma(a, b, c)); + } + + static short scalar_abs(short a) { + return (short)(Math.abs(a)); + } + + static short scalar_neg(short a) { + return ((short)-a); + } + + static boolean ult(short a, short b) { return Short.compareUnsigned(a, b) < 0; } @@ -1581,9 +1634,6 @@ public class ShortVector64Tests extends AbstractVectorTest { return Short.compareUnsigned(a, b) >= 0; } - static short firstNonZero(short a, short b) { - return Short.compare(a, (short) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1692,7 +1742,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short ADD(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1713,7 +1763,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short add(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1770,7 +1820,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short SUB(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1791,7 +1841,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short sub(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1848,7 +1898,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short MUL(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1869,7 +1919,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short mul(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -2016,7 +2066,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short FIRST_NONZERO(short a, short b) { - return (short)((a)!=0?a:b); + return (short)(firstNonZero(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3230,7 +3280,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short MIN(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3251,7 +3301,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short min(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3270,7 +3320,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short MAX(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3291,7 +3341,7 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short max(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3659,7 +3709,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ANDReduce(short[] a, int idx) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3668,7 +3718,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ANDReduceAll(short[] a) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3686,7 +3736,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3699,20 +3749,20 @@ public class ShortVector64Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = AND_IDENTITY; - assertEquals((short) (id & id), id, + assertEquals((short) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id & x), x); - assertEquals((short) (x & id), x); + assertEquals((short) (scalar_and(id, x)), x); + assertEquals((short) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id & x), x, + assertEquals((short) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x & id), x, + assertEquals((short) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3721,7 +3771,7 @@ public class ShortVector64Tests extends AbstractVectorTest { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3730,7 +3780,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ANDReduceAllMasked(short[] a, boolean[] mask) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3750,7 +3800,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3761,7 +3811,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ORReduce(short[] a, int idx) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3770,7 +3820,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ORReduceAll(short[] a) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3788,7 +3838,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3801,20 +3851,20 @@ public class ShortVector64Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = OR_IDENTITY; - assertEquals((short) (id | id), id, + assertEquals((short) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id | x), x); - assertEquals((short) (x | id), x); + assertEquals((short) (scalar_or(id, x)), x); + assertEquals((short) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id | x), x, + assertEquals((short) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x | id), x, + assertEquals((short) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3823,7 +3873,7 @@ public class ShortVector64Tests extends AbstractVectorTest { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3832,7 +3882,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ORReduceAllMasked(short[] a, boolean[] mask) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3852,7 +3902,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3863,7 +3913,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short XORReduce(short[] a, int idx) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3872,7 +3922,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short XORReduceAll(short[] a) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3890,7 +3940,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3903,20 +3953,20 @@ public class ShortVector64Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = XOR_IDENTITY; - assertEquals((short) (id ^ id), id, + assertEquals((short) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id ^ x), x); - assertEquals((short) (x ^ id), x); + assertEquals((short) (scalar_xor(id, x)), x); + assertEquals((short) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id ^ x), x, + assertEquals((short) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x ^ id), x, + assertEquals((short) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3925,7 +3975,7 @@ public class ShortVector64Tests extends AbstractVectorTest { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3934,7 +3984,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short XORReduceAllMasked(short[] a, boolean[] mask) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3954,7 +4004,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3965,7 +4015,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ADDReduce(short[] a, int idx) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3974,7 +4024,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ADDReduceAll(short[] a) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -3992,7 +4042,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4005,20 +4055,20 @@ public class ShortVector64Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = ADD_IDENTITY; - assertEquals((short) (id + id), id, + assertEquals((short) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id + x), x); - assertEquals((short) (x + id), x); + assertEquals((short) (scalar_add(id, x)), x); + assertEquals((short) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id + x), x, + assertEquals((short) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x + id), x, + assertEquals((short) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4027,7 +4077,7 @@ public class ShortVector64Tests extends AbstractVectorTest { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4036,7 +4086,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short ADDReduceAllMasked(short[] a, boolean[] mask) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4056,7 +4106,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4067,7 +4117,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MULReduce(short[] a, int idx) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4076,7 +4126,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MULReduceAll(short[] a) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4094,7 +4144,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4107,20 +4157,20 @@ public class ShortVector64Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MUL_IDENTITY; - assertEquals((short) (id * id), id, + assertEquals((short) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id * x), x); - assertEquals((short) (x * id), x); + assertEquals((short) (scalar_mul(id, x)), x); + assertEquals((short) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id * x), x, + assertEquals((short) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x * id), x, + assertEquals((short) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4129,7 +4179,7 @@ public class ShortVector64Tests extends AbstractVectorTest { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4138,7 +4188,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MULReduceAllMasked(short[] a, boolean[] mask) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4158,7 +4208,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4169,7 +4219,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MINReduce(short[] a, int idx) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4178,7 +4228,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MINReduceAll(short[] a) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4196,7 +4246,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4209,20 +4259,20 @@ public class ShortVector64Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MIN_IDENTITY; - assertEquals((short) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.min(id, x), x); - assertEquals((short) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4231,7 +4281,7 @@ public class ShortVector64Tests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4240,7 +4290,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MINReduceAllMasked(short[] a, boolean[] mask) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4260,7 +4310,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4271,7 +4321,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MAXReduce(short[] a, int idx) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4280,7 +4330,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MAXReduceAll(short[] a) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4298,7 +4348,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4311,20 +4361,20 @@ public class ShortVector64Tests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MAX_IDENTITY; - assertEquals((short) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.max(id, x), x); - assertEquals((short) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4333,7 +4383,7 @@ public class ShortVector64Tests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4342,7 +4392,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static short MAXReduceAllMasked(short[] a, boolean[] mask) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4362,7 +4412,7 @@ public class ShortVector64Tests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5395,7 +5445,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5415,7 +5465,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5431,7 +5481,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (short)((long)b[i]))); } } } @@ -5451,7 +5501,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (short)((long)b[i])))); } } } @@ -5467,7 +5517,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5487,7 +5537,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5503,7 +5553,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (short)((long)b[i]))); } } } @@ -5523,7 +5573,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (short)((long)b[i])))); } } } @@ -6235,11 +6285,11 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short NEG(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } static short neg(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6291,11 +6341,11 @@ public class ShortVector64Tests extends AbstractVectorTest { } static short ABS(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } static short abs(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6786,7 +6836,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6802,7 +6852,7 @@ public class ShortVector64Tests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6871,7 +6921,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static long ADDReduceLong(short[] a, int idx) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6880,7 +6930,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static long ADDReduceAllLong(short[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((short)res, (short)ADDReduceLong(a, i)); } return res; @@ -6898,8 +6948,8 @@ public class ShortVector64Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6909,8 +6959,9 @@ public class ShortVector64Tests extends AbstractVectorTest { static long ADDReduceLongMasked(short[] a, int idx, boolean[] mask) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6919,7 +6970,7 @@ public class ShortVector64Tests extends AbstractVectorTest { static long ADDReduceAllLongMasked(short[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((short)res, (short)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6939,8 +6990,8 @@ public class ShortVector64Tests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/ShortVectorMaxTests.java b/test/jdk/jdk/incubator/vector/ShortVectorMaxTests.java index 65234fb3173..5451ad6c50e 100644 --- a/test/jdk/jdk/incubator/vector/ShortVectorMaxTests.java +++ b/test/jdk/jdk/incubator/vector/ShortVectorMaxTests.java @@ -1571,6 +1571,59 @@ public class ShortVectorMaxTests extends AbstractVectorTest { return a >= b; } + static short firstNonZero(short a, short b) { + return Short.compare(a, (short) 0) != 0 ? a : b; + } + + static short scalar_or(short a, short b) { + return (short)(a | b); + } + + static short scalar_and(short a, short b) { + return (short)(a & b); + } + + static short scalar_xor(short a, short b) { + return (short)(a ^ b); + } + + static short scalar_add(short a, short b) { + return (short)(a + b); + } + + static short scalar_sub(short a, short b) { + return (short)(a - b); + } + + static short scalar_mul(short a, short b) { + return (short)(a * b); + } + + static short scalar_min(short a, short b) { + return (short)(Math.min(a, b)); + } + + static short scalar_max(short a, short b) { + return (short)(Math.max(a, b)); + } + + static short scalar_div(short a, short b) { + return (short)(a / b); + } + + static short scalar_fma(short a, short b, short c) { + return (short)(Math.fma(a, b, c)); + } + + static short scalar_abs(short a) { + return (short)(Math.abs(a)); + } + + static short scalar_neg(short a) { + return ((short)-a); + } + + static boolean ult(short a, short b) { return Short.compareUnsigned(a, b) < 0; } @@ -1587,9 +1640,6 @@ public class ShortVectorMaxTests extends AbstractVectorTest { return Short.compareUnsigned(a, b) >= 0; } - static short firstNonZero(short a, short b) { - return Short.compare(a, (short) 0) != 0 ? a : b; - } @Test static void smokeTest1() { @@ -1698,7 +1748,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short ADD(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1719,7 +1769,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short add(short a, short b) { - return (short)(a + b); + return (short)(scalar_add(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1776,7 +1826,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short SUB(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1797,7 +1847,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short sub(short a, short b) { - return (short)(a - b); + return (short)(scalar_sub(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1854,7 +1904,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short MUL(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -1875,7 +1925,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short mul(short a, short b) { - return (short)(a * b); + return (short)(scalar_mul(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -2022,7 +2072,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short FIRST_NONZERO(short a, short b) { - return (short)((a)!=0?a:b); + return (short)(firstNonZero(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3236,7 +3286,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short MIN(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3257,7 +3307,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short min(short a, short b) { - return (short)(Math.min(a, b)); + return (short)(scalar_min(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3276,7 +3326,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short MAX(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3297,7 +3347,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short max(short a, short b) { - return (short)(Math.max(a, b)); + return (short)(scalar_max(a, b)); } @Test(dataProvider = "shortBinaryOpProvider") @@ -3665,7 +3715,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ANDReduce(short[] a, int idx) { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3674,7 +3724,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ANDReduceAll(short[] a) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduce(a, i); + res = scalar_and(res, ANDReduce(a, i)); } return res; @@ -3692,7 +3742,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3705,20 +3755,20 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = AND_IDENTITY; - assertEquals((short) (id & id), id, + assertEquals((short) (scalar_and(id, id)), id, "AND(AND_IDENTITY, AND_IDENTITY) != AND_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id & x), x); - assertEquals((short) (x & id), x); + assertEquals((short) (scalar_and(id, x)), x); + assertEquals((short) (scalar_and(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id & x), x, + assertEquals((short) (scalar_and(id, x)), x, "AND(AND_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x & id), x, + assertEquals((short) (scalar_and(x, id)), x, "AND(" + x + ", AND_IDENTITY) != " + x); } } @@ -3727,7 +3777,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short res = AND_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res &= a[i]; + res = scalar_and(res, a[i]); } return res; @@ -3736,7 +3786,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ANDReduceAllMasked(short[] a, boolean[] mask) { short res = AND_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res &= ANDReduceMasked(a, i, mask); + res = scalar_and(res, ANDReduceMasked(a, i, mask)); } return res; @@ -3756,7 +3806,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.AND, vmask); r[i] = v; - ra &= v; + ra = scalar_and(ra, v); } } @@ -3767,7 +3817,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ORReduce(short[] a, int idx) { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3776,7 +3826,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ORReduceAll(short[] a) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduce(a, i); + res = scalar_or(res, ORReduce(a, i)); } return res; @@ -3794,7 +3844,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3807,20 +3857,20 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = OR_IDENTITY; - assertEquals((short) (id | id), id, + assertEquals((short) (scalar_or(id, id)), id, "OR(OR_IDENTITY, OR_IDENTITY) != OR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id | x), x); - assertEquals((short) (x | id), x); + assertEquals((short) (scalar_or(id, x)), x); + assertEquals((short) (scalar_or(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id | x), x, + assertEquals((short) (scalar_or(id, x)), x, "OR(OR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x | id), x, + assertEquals((short) (scalar_or(x, id)), x, "OR(" + x + ", OR_IDENTITY) != " + x); } } @@ -3829,7 +3879,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short res = OR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res |= a[i]; + res = scalar_or(res, a[i]); } return res; @@ -3838,7 +3888,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ORReduceAllMasked(short[] a, boolean[] mask) { short res = OR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res |= ORReduceMasked(a, i, mask); + res = scalar_or(res, ORReduceMasked(a, i, mask)); } return res; @@ -3858,7 +3908,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.OR, vmask); r[i] = v; - ra |= v; + ra = scalar_or(ra, v); } } @@ -3869,7 +3919,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short XORReduce(short[] a, int idx) { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3878,7 +3928,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short XORReduceAll(short[] a) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduce(a, i); + res = scalar_xor(res, XORReduce(a, i)); } return res; @@ -3896,7 +3946,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3909,20 +3959,20 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = XOR_IDENTITY; - assertEquals((short) (id ^ id), id, + assertEquals((short) (scalar_xor(id, id)), id, "XOR(XOR_IDENTITY, XOR_IDENTITY) != XOR_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id ^ x), x); - assertEquals((short) (x ^ id), x); + assertEquals((short) (scalar_xor(id, x)), x); + assertEquals((short) (scalar_xor(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id ^ x), x, + assertEquals((short) (scalar_xor(id, x)), x, "XOR(XOR_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x ^ id), x, + assertEquals((short) (scalar_xor(x, id)), x, "XOR(" + x + ", XOR_IDENTITY) != " + x); } } @@ -3931,7 +3981,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short res = XOR_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res ^= a[i]; + res = scalar_xor(res, a[i]); } return res; @@ -3940,7 +3990,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short XORReduceAllMasked(short[] a, boolean[] mask) { short res = XOR_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res ^= XORReduceMasked(a, i, mask); + res = scalar_xor(res, XORReduceMasked(a, i, mask)); } return res; @@ -3960,7 +4010,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.XOR, vmask); r[i] = v; - ra ^= v; + ra = scalar_xor(ra, v); } } @@ -3971,7 +4021,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ADDReduce(short[] a, int idx) { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -3980,7 +4030,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ADDReduceAll(short[] a) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduce(a, i); + res = scalar_add(res, ADDReduce(a, i)); } return res; @@ -3998,7 +4048,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4011,20 +4061,20 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = ADD_IDENTITY; - assertEquals((short) (id + id), id, + assertEquals((short) (scalar_add(id, id)), id, "ADD(ADD_IDENTITY, ADD_IDENTITY) != ADD_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id + x), x); - assertEquals((short) (x + id), x); + assertEquals((short) (scalar_add(id, x)), x); + assertEquals((short) (scalar_add(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id + x), x, + assertEquals((short) (scalar_add(id, x)), x, "ADD(ADD_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x + id), x, + assertEquals((short) (scalar_add(x, id)), x, "ADD(" + x + ", ADD_IDENTITY) != " + x); } } @@ -4033,7 +4083,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short res = ADD_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res += a[i]; + res = scalar_add(res, a[i]); } return res; @@ -4042,7 +4092,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short ADDReduceAllMasked(short[] a, boolean[] mask) { short res = ADD_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceMasked(a, i, mask); + res = scalar_add(res, ADDReduceMasked(a, i, mask)); } return res; @@ -4062,7 +4112,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.ADD, vmask); r[i] = v; - ra += v; + ra = scalar_add(ra, v); } } @@ -4073,7 +4123,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MULReduce(short[] a, int idx) { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4082,7 +4132,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MULReduceAll(short[] a) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduce(a, i); + res = scalar_mul(res, MULReduce(a, i)); } return res; @@ -4100,7 +4150,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4113,20 +4163,20 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MUL_IDENTITY; - assertEquals((short) (id * id), id, + assertEquals((short) (scalar_mul(id, id)), id, "MUL(MUL_IDENTITY, MUL_IDENTITY) != MUL_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) (id * x), x); - assertEquals((short) (x * id), x); + assertEquals((short) (scalar_mul(id, x)), x); + assertEquals((short) (scalar_mul(x, id)), x); } } catch (AssertionError e) { - assertEquals((short) (id * x), x, + assertEquals((short) (scalar_mul(id, x)), x, "MUL(MUL_IDENTITY, " + x + ") != " + x); - assertEquals((short) (x * id), x, + assertEquals((short) (scalar_mul(x, id)), x, "MUL(" + x + ", MUL_IDENTITY) != " + x); } } @@ -4135,7 +4185,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short res = MUL_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res *= a[i]; + res = scalar_mul(res, a[i]); } return res; @@ -4144,7 +4194,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MULReduceAllMasked(short[] a, boolean[] mask) { short res = MUL_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res *= MULReduceMasked(a, i, mask); + res = scalar_mul(res, MULReduceMasked(a, i, mask)); } return res; @@ -4164,7 +4214,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MUL, vmask); r[i] = v; - ra *= v; + ra = scalar_mul(ra, v); } } @@ -4175,7 +4225,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MINReduce(short[] a, int idx) { short res = MIN_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.min(res, a[i]); + res = scalar_min(res, a[i]); } return res; @@ -4184,7 +4234,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MINReduceAll(short[] a) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduce(a, i)); + res = scalar_min(res, MINReduce(a, i)); } return res; @@ -4202,7 +4252,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4215,20 +4265,20 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MIN_IDENTITY; - assertEquals((short) Math.min(id, id), id, + assertEquals(scalar_min(id, id), id, "MIN(MIN_IDENTITY, MIN_IDENTITY) != MIN_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.min(id, x), x); - assertEquals((short) Math.min(x, id), x); + assertEquals(scalar_min(id, x), x); + assertEquals(scalar_min(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.min(id, x), x, + assertEquals(scalar_min(id, x), x, "MIN(MIN_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.min(x, id), x, + assertEquals(scalar_min(x, id), x, "MIN(" + x + ", MIN_IDENTITY) != " + x); } } @@ -4237,7 +4287,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { 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]); + res = scalar_min(res, a[i]); } return res; @@ -4246,7 +4296,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MINReduceAllMasked(short[] a, boolean[] mask) { short res = MIN_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.min(res, MINReduceMasked(a, i, mask)); + res = scalar_min(res, MINReduceMasked(a, i, mask)); } return res; @@ -4266,7 +4316,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MIN, vmask); r[i] = v; - ra = (short) Math.min(ra, v); + ra = scalar_min(ra, v); } } @@ -4277,7 +4327,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MAXReduce(short[] a, int idx) { short res = MAX_IDENTITY; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res = (short) Math.max(res, a[i]); + res = scalar_max(res, a[i]); } return res; @@ -4286,7 +4336,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MAXReduceAll(short[] a) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduce(a, i)); + res = scalar_max(res, MAXReduce(a, i)); } return res; @@ -4304,7 +4354,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -4317,20 +4367,20 @@ public class ShortVectorMaxTests extends AbstractVectorTest { short[] a = fa.apply(SPECIES.length()); short id = MAX_IDENTITY; - assertEquals((short) Math.max(id, id), id, + assertEquals(scalar_max(id, id), id, "MAX(MAX_IDENTITY, MAX_IDENTITY) != MAX_IDENTITY"); short x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals((short) Math.max(id, x), x); - assertEquals((short) Math.max(x, id), x); + assertEquals(scalar_max(id, x), x); + assertEquals(scalar_max(x, id), x); } } catch (AssertionError e) { - assertEquals((short) Math.max(id, x), x, + assertEquals(scalar_max(id, x), x, "MAX(MAX_IDENTITY, " + x + ") != " + x); - assertEquals((short) Math.max(x, id), x, + assertEquals(scalar_max(x, id), x, "MAX(" + x + ", MAX_IDENTITY) != " + x); } } @@ -4339,7 +4389,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { 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]); + res = scalar_max(res, a[i]); } return res; @@ -4348,7 +4398,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static short MAXReduceAllMasked(short[] a, boolean[] mask) { short res = MAX_IDENTITY; for (int i = 0; i < a.length; i += SPECIES.length()) { - res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); + res = scalar_max(res, MAXReduceMasked(a, i, mask)); } return res; @@ -4368,7 +4418,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { ShortVector av = ShortVector.fromArray(SPECIES, a, i); short v = av.reduceLanes(VectorOperators.MAX, vmask); r[i] = v; - ra = (short) Math.max(ra, v); + ra = scalar_max(ra, v); } } @@ -5401,7 +5451,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -5421,7 +5471,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], b[i]))); } } } @@ -5437,7 +5487,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), lt(a[i + j], (short)((long)b[i]))); } } } @@ -5457,7 +5507,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (lt(a[i + j], (short)((long)b[i])))); } } } @@ -5473,7 +5523,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -5493,7 +5543,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], b[i]))); } } } @@ -5509,7 +5559,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == (short)((long)b[i])); + assertEquals(mv.laneIsSet(j), eq(a[i + j], (short)((long)b[i]))); } } } @@ -5529,7 +5579,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (short)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && (eq(a[i + j], (short)((long)b[i])))); } } } @@ -6241,11 +6291,11 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short NEG(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } static short neg(short a) { - return (short)(-((short)a)); + return (short)(scalar_neg((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6297,11 +6347,11 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } static short ABS(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } static short abs(short a) { - return (short)(Math.abs((short)a)); + return (short)(scalar_abs((short)a)); } @Test(dataProvider = "shortUnaryOpProvider") @@ -6792,7 +6842,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -6808,7 +6858,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -6877,7 +6927,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static long ADDReduceLong(short[] a, int idx) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -6886,7 +6936,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static long ADDReduceAllLong(short[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add((short)res, (short)ADDReduceLong(a, i)); } return res; @@ -6904,8 +6954,8 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -6915,8 +6965,9 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static long ADDReduceLongMasked(short[] a, int idx, boolean[] mask) { short res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -6925,7 +6976,7 @@ public class ShortVectorMaxTests extends AbstractVectorTest { static long ADDReduceAllLongMasked(short[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add((short)res, (short)ADDReduceLongMasked(a, i, mask)); } return res; @@ -6945,8 +6996,8 @@ public class ShortVectorMaxTests extends AbstractVectorTest { } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add((short)ra, (short)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/gen-template.sh b/test/jdk/jdk/incubator/vector/gen-template.sh index d2528b13b78..4e961e2f2b0 100644 --- a/test/jdk/jdk/incubator/vector/gen-template.sh +++ b/test/jdk/jdk/incubator/vector/gen-template.sh @@ -383,6 +383,7 @@ function gen_bool_reduction_op { gen_op_tmpl $bool_reduction_scalar "$@" gen_op_tmpl $bool_reduction_template "$@" } + function gen_saturating_reduction_op { echo "Generating saturating reduction op $1 ($2)..." gen_op_tmpl $reduction_scalar_func "$@" @@ -434,13 +435,13 @@ fi # ALU binary ops. # Here "ADD+add+withMask" says VectorOperator name is "ADD", and we have a dedicate method too named 'add', and add() is also available with mask variant. -gen_binary_alu_op "ADD+add+withMask" "a + b" -gen_binary_alu_op "SUB+sub+withMask" "a - b" -gen_binary_alu_op "MUL+mul+withMask" "a \* b" -gen_binary_alu_op "DIV+div+withMask" "a \/ b" "FP" +gen_binary_alu_op "ADD+add+withMask" "scalar_add(a, b)" +gen_binary_alu_op "SUB+sub+withMask" "scalar_sub(a, b)" +gen_binary_alu_op "MUL+mul+withMask" "scalar_mul(a, b)" +gen_binary_alu_op "DIV+div+withMask" "scalar_div(a, b)" "FP" gen_op_tmpl "Binary-op_bitwise-div" "DIV+div+withMask" "a \/ b" "BITWISE" gen_op_tmpl "Binary-Masked-op_bitwise-div" "DIV+div+withMask" "a \/ b" "BITWISE" -gen_binary_alu_op "FIRST_NONZERO" "{#if[FP]?Double.doubleToLongBits}(a)!=0?a:b" +gen_binary_alu_op "FIRST_NONZERO" "firstNonZero(a, b)" gen_binary_alu_op "AND+and" "a \& b" "BITWISE" gen_binary_alu_op "AND_NOT" "a \& ~b" "BITWISE" gen_binary_alu_op "OR+or" "a | b" "BITWISE" @@ -449,16 +450,16 @@ gen_binary_alu_op "XOR" "a ^ b" "BITWISE" gen_binary_alu_op "COMPRESS_BITS" "\$Boxtype\$.compress(a, b)" "intOrLong" gen_binary_alu_op "EXPAND_BITS" "\$Boxtype\$.expand(a, b)" "intOrLong" # Generate the broadcast versions -gen_binary_alu_bcst_op "add+withMask" "a + b" -gen_binary_alu_bcst_op "sub+withMask" "a - b" -gen_binary_alu_bcst_op "mul+withMask" "a \* b" -gen_binary_alu_bcst_op "div+withMask" "a \/ b" "FP" +gen_binary_alu_bcst_op "add+withMask" "scalar_add(a, b)" +gen_binary_alu_bcst_op "sub+withMask" "scalar_sub(a, b)" +gen_binary_alu_bcst_op "mul+withMask" "scalar_mul(a, b)" +gen_binary_alu_bcst_op "div+withMask" "scalar_div(a, b)" "FP" gen_op_tmpl "Binary-Broadcast-op_bitwise-div" "div+withMask" "a \/ b" "BITWISE" gen_op_tmpl "Binary-Broadcast-Masked-op_bitwise-div" "div+withMask" "a \/ b" "BITWISE" gen_binary_alu_bcst_op "OR+or" "a | b" "BITWISE" gen_binary_alu_bcst_op "AND+and" "a \& b" "BITWISE" gen_binary_alu_bcst_long_op "OR" "a | b" "BITWISE" -gen_binary_alu_bcst_long_op "ADD" "a + b" +gen_binary_alu_bcst_long_op "ADD" "scalar_add(a, b)" # Shifts gen_binary_alu_op "LSHL" "(a << b)" "intOrLong" @@ -494,30 +495,30 @@ gen_shift_cst_op "ROR" "ROR_scalar(a, CONST_SHIFT)" "BITWISE" gen_shift_cst_op "ROL" "ROL_scalar(a, CONST_SHIFT)" "BITWISE" # Binary operation with one memory operand -gen_binary_alu_mem_op "MIN+min+withMask", "Math.min(a, b)" -gen_binary_alu_mem_op "MAX+max+withMask", "Math.max(a, b)" +gen_binary_alu_mem_op "MIN+min+withMask", "scalar_min(a, b)" +gen_binary_alu_mem_op "MAX+max+withMask", "scalar_max(a, b)" # Masked reductions. -gen_binary_op_no_masked "MIN+min" "Math.min(a, b)" -gen_binary_op_no_masked "MAX+max" "Math.max(a, b)" +gen_binary_op_no_masked "MIN+min" "scalar_min(a, b)" +gen_binary_op_no_masked "MAX+max" "scalar_max(a, b)" gen_binary_op "UMIN" "VectorMath.minUnsigned(a, b)" "BITWISE" gen_binary_op "UMAX" "VectorMath.maxUnsigned(a, b)" "BITWISE" gen_saturating_binary_op "SADD" "VectorMath.addSaturating(a, b)" "BITWISE" gen_saturating_binary_op "SSUB" "VectorMath.subSaturating(a, b)" "BITWISE" gen_saturating_binary_op "SUADD" "VectorMath.addSaturatingUnsigned(a, b)" "BITWISE" gen_saturating_binary_op "SUSUB" "VectorMath.subSaturatingUnsigned(a, b)" "BITWISE" -gen_binary_bcst_op_no_masked "MIN+min" "Math.min(a, b)" -gen_binary_bcst_op_no_masked "MAX+max" "Math.max(a, b)" +gen_binary_bcst_op_no_masked "MIN+min" "scalar_min(a, b)" +gen_binary_bcst_op_no_masked "MAX+max" "scalar_max(a, b)" gen_saturating_binary_op_associative "SUADD" "VectorMath.addSaturatingUnsigned(a, b)" "BITWISE" # Reductions. -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 "AND" "scalar_and" "BITWISE" "AND_IDENTITY" +gen_reduction_op "OR" "scalar_or" "BITWISE" "OR_IDENTITY" +gen_reduction_op "XOR" "scalar_xor" "BITWISE" "XOR_IDENTITY" +gen_reduction_op "ADD" "scalar_add" "" "ADD_IDENTITY" +gen_reduction_op "MUL" "scalar_mul" "" "MUL_IDENTITY" +gen_reduction_op_func "MIN" "scalar_min" "" "MIN_IDENTITY" +gen_reduction_op_func "MAX" "scalar_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" @@ -535,9 +536,9 @@ gen_with_op "withLane" "" "" "" # Tests gen_op_tmpl $test_template "IS_DEFAULT" "bits(a)==0" gen_op_tmpl $test_template "IS_NEGATIVE" "bits(a)<0" -gen_op_tmpl $test_template "IS_FINITE" "\$Boxtype\$.isFinite(a)" "FP" -gen_op_tmpl $test_template "IS_NAN" "\$Boxtype\$.isNaN(a)" "FP" -gen_op_tmpl $test_template "IS_INFINITE" "\$Boxtype\$.isInfinite(a)" "FP" +gen_op_tmpl $test_template "IS_FINITE" "isFinite(a)" "FP" +gen_op_tmpl $test_template "IS_NAN" "isNaN(a)" "FP" +gen_op_tmpl $test_template "IS_INFINITE" "isInfinite(a)" "FP" # Compares gen_compare_op "LT+lt" "lt" @@ -553,8 +554,8 @@ gen_compare_op "ULE" "ule" "BITWISE" gen_compare_op "UGE" "uge" "BITWISE" -gen_compare_bcst_op "LT" "<" -gen_compare_bcst_op "EQ" "==" +gen_compare_bcst_op "LT" "lt" +gen_compare_bcst_op "EQ" "eq" # Blend. gen_op_tmpl $blend "blend" "" @@ -585,28 +586,28 @@ gen_op_tmpl $unslice1_template "unsliceBinary" "" gen_op_tmpl $unslice1_masked_template "unslice" "" # Math -gen_op_tmpl $unary_math_template "SIN" "Math.sin((double)a)" "FP" -gen_op_tmpl $unary_math_template "EXP" "Math.exp((double)a)" "FP" -gen_op_tmpl $unary_math_template "LOG1P" "Math.log1p((double)a)" "FP" -gen_op_tmpl $unary_math_template "LOG" "Math.log((double)a)" "FP" -gen_op_tmpl $unary_math_template "LOG10" "Math.log10((double)a)" "FP" -gen_op_tmpl $unary_math_template "EXPM1" "Math.expm1((double)a)" "FP" -gen_op_tmpl $unary_math_template "COS" "Math.cos((double)a)" "FP" -gen_op_tmpl $unary_math_template "TAN" "Math.tan((double)a)" "FP" -gen_op_tmpl $unary_math_template "SINH" "Math.sinh((double)a)" "FP" -gen_op_tmpl $unary_math_template "COSH" "Math.cosh((double)a)" "FP" -gen_op_tmpl $unary_math_template "TANH" "Math.tanh((double)a)" "FP" -gen_op_tmpl $unary_math_template "ASIN" "Math.asin((double)a)" "FP" -gen_op_tmpl $unary_math_template "ACOS" "Math.acos((double)a)" "FP" -gen_op_tmpl $unary_math_template "ATAN" "Math.atan((double)a)" "FP" -gen_op_tmpl $unary_math_template "CBRT" "Math.cbrt((double)a)" "FP" -gen_op_tmpl $binary_math_template "HYPOT" "Math.hypot((double)a, (double)b)" "FP" -gen_op_tmpl $binary_math_template "POW+pow" "Math.pow((double)a, (double)b)" "FP" -gen_op_tmpl $binary_math_template "ATAN2" "Math.atan2((double)a, (double)b)" "FP" -gen_op_tmpl $binary_math_broadcast_template "POW+pow" "Math.pow((double)a, (double)b)" "FP" +gen_op_tmpl $unary_math_template "SIN" "scalar_sin(a)" "FP" +gen_op_tmpl $unary_math_template "EXP" "scalar_exp(a)" "FP" +gen_op_tmpl $unary_math_template "LOG1P" "scalar_log1p(a)" "FP" +gen_op_tmpl $unary_math_template "LOG" "scalar_log(a)" "FP" +gen_op_tmpl $unary_math_template "LOG10" "scalar_log10(a)" "FP" +gen_op_tmpl $unary_math_template "EXPM1" "scalar_expm1(a)" "FP" +gen_op_tmpl $unary_math_template "COS" "scalar_cos(a)" "FP" +gen_op_tmpl $unary_math_template "TAN" "scalar_tan(a)" "FP" +gen_op_tmpl $unary_math_template "SINH" "scalar_sinh(a)" "FP" +gen_op_tmpl $unary_math_template "COSH" "scalar_cosh(a)" "FP" +gen_op_tmpl $unary_math_template "TANH" "scalar_tanh(a)" "FP" +gen_op_tmpl $unary_math_template "ASIN" "scalar_asin(a)" "FP" +gen_op_tmpl $unary_math_template "ACOS" "scalar_acos(a)" "FP" +gen_op_tmpl $unary_math_template "ATAN" "scalar_atan(a)" "FP" +gen_op_tmpl $unary_math_template "CBRT" "scalar_cbrt(a)" "FP" +gen_op_tmpl $binary_math_template "HYPOT" "scalar_hypot(a, b)" "FP" +gen_op_tmpl $binary_math_template "POW+pow" "scalar_pow(a, b)" "FP" +gen_op_tmpl $binary_math_template "ATAN2" "scalar_atan2(a, b)" "FP" +gen_op_tmpl $binary_math_broadcast_template "POW+pow" "scalar_pow(a, b)" "FP" # Ternary operations. -gen_ternary_alu_op "FMA+fma" "Math.fma(a, b, c)" "FP" +gen_ternary_alu_op "FMA+fma" "scalar_fma(a, b, c)" "FP" gen_ternary_alu_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE" gen_ternary_alu_bcst_op "FMA" "Math.fma(a, b, c)" "FP" gen_ternary_alu_bcst_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE" @@ -614,11 +615,11 @@ gen_ternary_alu_double_bcst_op "FMA+fma" "Math.fma(a, b, c)" "FP" gen_ternary_alu_double_bcst_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE" # Unary operations. -gen_unary_alu_op "NEG+neg" "-((\$type\$)a)" -gen_unary_alu_op "ABS+abs" "Math.abs((\$type\$)a)" +gen_unary_alu_op "NEG+neg" "scalar_neg((\$type\$)a)" +gen_unary_alu_op "ABS+abs" "scalar_abs((\$type\$)a)" gen_unary_alu_op "NOT+not" "~((\$type\$)a)" "BITWISE" gen_unary_alu_op "ZOMO" "(a==0?0:-1)" "BITWISE" -gen_unary_alu_op "SQRT+sqrt" "Math.sqrt((double)a)" "FP" +gen_unary_alu_op "SQRT+sqrt" "scalar_sqrt(a)" "FP" gen_unary_alu_op "BIT_COUNT" "\$Boxtype\$.bitCount(a)" "intOrLong" gen_unary_alu_op "BIT_COUNT" "Integer.bitCount((int)a \& 0xFF)" "byte" gen_unary_alu_op "BIT_COUNT" "Integer.bitCount((int)a \& 0xFFFF)" "short" 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 82e20d594b6..73e02bf68dd 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 @@ -10,7 +10,7 @@ $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); $type$ v = av.reduceLanes(VectorOperators.[[TEST]], vmask); r[i] = v; - ra [[TEST_OP]]= 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 3edc2b27e3e..94fae420cdd 100644 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Kernel-Reduction-op.template @@ -8,7 +8,7 @@ $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i); $type$ v = av.reduceLanes(VectorOperators.[[TEST]]); r[i] = v; - ra [[TEST_OP]]= v; + ra = [[TEST_OP]](ra, v); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Binary-op-math.template b/test/jdk/jdk/incubator/vector/templates/Unit-Binary-op-math.template index a3d44526db9..1866c28e2ba 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Binary-op-math.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Binary-op-math.template @@ -4,7 +4,7 @@ } static $type$ strict[[TEST]]($type$ a, $type$ b) { - return ($type$)(Strict[[TEST_OP]]); + return ($type$)(strict_[[TEST_OP]]); } @Test(dataProvider = "$type$BinaryOpProvider") diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Compare-Broadcast.template b/test/jdk/jdk/incubator/vector/templates/Unit-Compare-Broadcast.template index 92e612e8184..faae74426e7 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Compare-Broadcast.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Compare-Broadcast.template @@ -10,7 +10,7 @@ // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] [[TEST_OP]] b[i]); + assertEquals(mv.laneIsSet(j), [[TEST_OP]](a[i + j], b[i])); } } } @@ -30,7 +30,7 @@ // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] [[TEST_OP]] b[i])); + assertEquals(mv.laneIsSet(j), mask[j] && ([[TEST_OP]](a[i + j], b[i]))); } } } @@ -47,7 +47,7 @@ // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] [[TEST_OP]] ($type$)((long)b[i])); + assertEquals(mv.laneIsSet(j), [[TEST_OP]](a[i + j], ($type$)((long)b[i]))); } } } @@ -67,7 +67,7 @@ // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] [[TEST_OP]] ($type$)((long)b[i]))); + assertEquals(mv.laneIsSet(j), mask[j] && ([[TEST_OP]](a[i + j], ($type$)((long)b[i])))); } } } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Miscellaneous.template b/test/jdk/jdk/incubator/vector/templates/Unit-Miscellaneous.template index 8411565628d..5ad7623d2c0 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Miscellaneous.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Miscellaneous.template @@ -10,7 +10,7 @@ // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); + assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i])); } } } @@ -26,7 +26,7 @@ // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { - assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); + assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i])); } } } @@ -123,7 +123,7 @@ static long ADDReduceLong($type$[] a, int idx) { $type$ res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res += a[i]; + res = scalar_add(res, a[i]); } return (long)res; @@ -132,7 +132,7 @@ static long ADDReduceAllLong($type$[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLong(a, i); + res = (long)scalar_add(($type$)res, ($type$)ADDReduceLong(a, i)); } return res; @@ -150,8 +150,8 @@ } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add(($type$)ra, ($type$)r[i]); } assertReductionLongArraysEquals(r, ra, a, @@ -161,8 +161,9 @@ static long ADDReduceLongMasked($type$[] a, int idx, boolean[] mask) { $type$ res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { - if(mask[i % SPECIES.length()]) - res += a[i]; + if (mask[i % SPECIES.length()]) { + res = scalar_add(res, a[i]); + } } return (long)res; @@ -171,7 +172,7 @@ static long ADDReduceAllLongMasked($type$[] a, boolean[] mask) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { - res += ADDReduceLongMasked(a, i, mask); + res = (long)scalar_add(($type$)res, ($type$)ADDReduceLongMasked(a, i, mask)); } return res; @@ -191,8 +192,8 @@ } ra = 0; - for (int i = 0; i < a.length; i ++) { - ra += r[i]; + for (int i = 0; i < a.length; i++) { + ra = (long)scalar_add(($type$)ra, ($type$)r[i]); } assertReductionLongArraysEqualsMasked(r, ra, a, mask, diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-Scalar-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-Scalar-Masked-op.template index ab383e61256..1565c9f3551 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-Scalar-Masked-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-Scalar-Masked-op.template @@ -3,7 +3,7 @@ $type$ res = [[TEST_INIT]]; for (int i = idx; i < (idx + SPECIES.length()); i++) { if (mask[i % SPECIES.length()]) - res [[TEST_OP]]= a[i]; + res = [[TEST_OP]](res, a[i]); } return res; @@ -12,7 +12,7 @@ static $type$ [[TEST]]ReduceAllMasked($type$[] a, boolean[] mask) { $type$ res = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { - res [[TEST_OP]]= [[TEST]]ReduceMasked(a, i, mask); + res = [[TEST_OP]](res, [[TEST]]ReduceMasked(a, i, mask)); } return res; diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-Scalar-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-Scalar-op.template index 88586fa8129..63d154df112 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-Scalar-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-Scalar-op.template @@ -2,7 +2,7 @@ static $type$ [[TEST]]Reduce($type$[] a, int idx) { $type$ res = [[TEST_INIT]]; for (int i = idx; i < (idx + SPECIES.length()); i++) { - res [[TEST_OP]]= a[i]; + res = [[TEST_OP]](res, a[i]); } return res; @@ -11,7 +11,7 @@ static $type$ [[TEST]]ReduceAll($type$[] a) { $type$ res = [[TEST_INIT]]; for (int i = 0; i < a.length; i += SPECIES.length()) { - res [[TEST_OP]]= [[TEST]]Reduce(a, i); + res = [[TEST_OP]](res, [[TEST]]Reduce(a, i)); } return res; 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 25ae3ba2f12..d82b5533c4f 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Reduction-op.template @@ -15,20 +15,20 @@ $type$[] a = fa.apply(SPECIES.length()); $type$ id = [[TEST_INIT]]; - assertEquals(($type$) (id [[TEST_OP]] id), id, + assertEquals(($type$) ([[TEST_OP]](id, id)), id, "[[TEST]]([[TEST_INIT]], [[TEST_INIT]]) != [[TEST_INIT]]"); $type$ x = 0; try { for (int i = 0; i < a.length; i++) { x = a[i]; - assertEquals(($type$) (id [[TEST_OP]] x), x); - assertEquals(($type$) (x [[TEST_OP]] id), x); + assertEquals(($type$) ([[TEST_OP]](id, x)), x); + assertEquals(($type$) ([[TEST_OP]](x, id)), x); } } catch (AssertionError e) { - assertEquals(($type$) (id [[TEST_OP]] x), x, + assertEquals(($type$) ([[TEST_OP]](id, x)), x, "[[TEST]]([[TEST_INIT]], " + x + ") != " + x); - assertEquals(($type$) (x [[TEST_OP]] id), x, + assertEquals(($type$) ([[TEST_OP]](x, id)), x, "[[TEST]](" + x + ", [[TEST_INIT]]) != " + x); } } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Unary-op-math.template b/test/jdk/jdk/incubator/vector/templates/Unit-Unary-op-math.template index 52293d9f614..f6943a0b40b 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Unary-op-math.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Unary-op-math.template @@ -4,7 +4,7 @@ } static $type$ strict[[TEST]]($type$ a) { - return ($type$)(Strict[[TEST_OP]]); + return ($type$)(strict_[[TEST_OP]]); } @Test(dataProvider = "$type$UnaryOpProvider") diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-header.template b/test/jdk/jdk/incubator/vector/templates/Unit-header.template index 00a7766492c..e1434dccb2b 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-header.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-header.template @@ -1943,6 +1943,214 @@ relativeError)); static boolean ge($type$ a, $type$ b) { return a >= b; } + + static $type$ firstNonZero($type$ a, $type$ b) { + return $Wideboxtype$.compare(a, ($type$) 0) != 0 ? a : b; + } + +#if[BITWISE] + static $type$ scalar_or($type$ a, $type$ b) { + return ($type$)(a | b); + } + + static $type$ scalar_and($type$ a, $type$ b) { + return ($type$)(a & b); + } + + static $type$ scalar_xor($type$ a, $type$ b) { + return ($type$)(a ^ b); + } +#end[BITWISE]; + + static $type$ scalar_add($type$ a, $type$ b) { + return ($type$)(a + b); + } + + static $type$ scalar_sub($type$ a, $type$ b) { + return ($type$)(a - b); + } + + static $type$ scalar_mul($type$ a, $type$ b) { + return ($type$)(a * b); + } + + static $type$ scalar_min($type$ a, $type$ b) { + return ($type$)(Math.min(a, b)); + } + + static $type$ scalar_max($type$ a, $type$ b) { + return ($type$)(Math.max(a, b)); + } + + static $type$ scalar_div($type$ a, $type$ b) { + return ($type$)(a / b); + } + + static $type$ scalar_fma($type$ a, $type$ b, $type$ c) { + return ($type$)(Math.fma(a, b, c)); + } + + static $type$ scalar_abs($type$ a) { + return ($type$)(Math.abs(a)); + } + + static $type$ scalar_neg($type$ a) { + return (($type$)-a); + } + +#if[!BITWISE] + static $type$ scalar_sin($type$ a) { + return ($type$)Math.sin((double)a); + } + + static $type$ scalar_exp($type$ a) { + return ($type$)Math.exp((double)a); + } + + static $type$ scalar_log1p($type$ a) { + return ($type$)Math.log1p((double)a); + } + + static $type$ scalar_log($type$ a) { + return ($type$)Math.log((double)a); + } + + static $type$ scalar_log10($type$ a) { + return ($type$)Math.log10((double)a); + } + + static $type$ scalar_expm1($type$ a) { + return ($type$)Math.expm1((double)a); + } + + static $type$ scalar_cos($type$ a) { + return ($type$)Math.cos((double)a); + } + + static $type$ scalar_tan($type$ a) { + return ($type$)Math.tan((double)a); + } + + static $type$ scalar_sinh($type$ a) { + return ($type$)Math.sinh((double)a); + } + + static $type$ scalar_cosh($type$ a) { + return ($type$)Math.cosh((double)a); + } + + static $type$ scalar_tanh($type$ a) { + return ($type$)Math.tanh((double)a); + } + + static $type$ scalar_asin($type$ a) { + return ($type$)Math.asin((double)a); + } + + static $type$ scalar_acos($type$ a) { + return ($type$)Math.acos((double)a); + } + + static $type$ scalar_atan($type$ a) { + return ($type$)Math.atan((double)a); + } + + static $type$ scalar_cbrt($type$ a) { + return ($type$)Math.cbrt((double)a); + } + + static $type$ scalar_sqrt($type$ a) { + return ($type$)Math.sqrt((double)a); + } + + static $type$ scalar_hypot($type$ a, $type$ b) { + return ($type$)Math.hypot((double)a, (double)b); + } + + static $type$ scalar_pow($type$ a, $type$ b) { + return ($type$)Math.pow((double)a, (double)b); + } + + static $type$ scalar_atan2($type$ a, $type$ b) { + return ($type$)Math.atan2((double)a, (double)b); + } + + static $type$ strict_scalar_sin($type$ a) { + return ($type$)StrictMath.sin((double)a); + } + + static $type$ strict_scalar_exp($type$ a) { + return ($type$)StrictMath.exp((double)a); + } + + static $type$ strict_scalar_log1p($type$ a) { + return ($type$)StrictMath.log1p((double)a); + } + + static $type$ strict_scalar_log($type$ a) { + return ($type$)StrictMath.log((double)a); + } + + static $type$ strict_scalar_log10($type$ a) { + return ($type$)StrictMath.log10((double)a); + } + + static $type$ strict_scalar_expm1($type$ a) { + return ($type$)StrictMath.expm1((double)a); + } + + static $type$ strict_scalar_cos($type$ a) { + return ($type$)StrictMath.cos((double)a); + } + + static $type$ strict_scalar_tan($type$ a) { + return ($type$)StrictMath.tan((double)a); + } + + static $type$ strict_scalar_sinh($type$ a) { + return ($type$)StrictMath.sinh((double)a); + } + + static $type$ strict_scalar_cosh($type$ a) { + return ($type$)StrictMath.cosh((double)a); + } + + static $type$ strict_scalar_tanh($type$ a) { + return ($type$)StrictMath.tanh((double)a); + } + + static $type$ strict_scalar_asin($type$ a) { + return ($type$)StrictMath.asin((double)a); + } + + static $type$ strict_scalar_acos($type$ a) { + return ($type$)StrictMath.acos((double)a); + } + + static $type$ strict_scalar_atan($type$ a) { + return ($type$)StrictMath.atan((double)a); + } + + static $type$ strict_scalar_cbrt($type$ a) { + return ($type$)StrictMath.cbrt((double)a); + } + + static $type$ strict_scalar_sqrt($type$ a) { + return ($type$)StrictMath.sqrt((double)a); + } + + static $type$ strict_scalar_hypot($type$ a, $type$ b) { + return ($type$)StrictMath.hypot((double)a, (double)b); + } + + static $type$ strict_scalar_pow($type$ a, $type$ b) { + return ($type$)StrictMath.pow((double)a, (double)b); + } + + static $type$ strict_scalar_atan2($type$ a, $type$ b) { + return ($type$)StrictMath.atan2((double)a, (double)b); + } +#end[!BITWISE] #if[!FP] static boolean ult($type$ a, $type$ b) { @@ -1962,9 +2170,17 @@ relativeError)); } #end[!FP] - static $type$ firstNonZero($type$ a, $type$ b) { - return $Boxtype$.compare(a, ($type$) 0) != 0 ? a : b; +#if[FP] + static boolean isNaN($type$ a) { + return $Wideboxtype$.isNaN(a); } + static boolean isFinite($type$ a) { + return $Wideboxtype$.isFinite(a); + } + static boolean isInfinite($type$ a) { + return $Wideboxtype$.isInfinite(a); + } +#end[FP] @Test static void smokeTest1() {