--- old/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java 2020-05-28 14:30:38.980740215 -0700 +++ new/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java 2020-05-28 14:30:38.804740215 -0700 @@ -246,6 +246,18 @@ } } + static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) { + int i = 0; + try { + for (; i < a.length; i++) { + Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), + "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); + } + } + static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) { assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); } @@ -261,6 +273,24 @@ } } + static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) { + assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); + } + + static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) { + int i = 0; + try { + for (; i < a.length; i++) { + Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); + } + } catch (AssertionError err) { + Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], + mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + + mask[i % SPECIES.length()]); + } + } + static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) { int i = 0; int j = 0; @@ -1374,6 +1404,26 @@ assertArraysEquals(a, b, r, ByteMaxVectorTests::OR); } + static byte or(byte a, byte b) { + return (byte)(a | b); + } + + @Test(dataProvider = "byteBinaryOpProvider") + static void orByteMaxVectorTests(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + ByteVector bv = ByteVector.fromArray(SPECIES, b, i); + av.or(bv).intoArray(r, i); + } + } + + assertArraysEquals(a, b, r, ByteMaxVectorTests::or); + } @@ -1442,6 +1492,189 @@ } + @Test(dataProvider = "byteBinaryOpProvider") + static void addByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.add(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::add); + } + + @Test(dataProvider = "byteBinaryOpMaskProvider") + static void addByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction fa, IntFunction fb, + IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.add(b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ByteMaxVectorTests::add); + } + + @Test(dataProvider = "byteBinaryOpProvider") + static void subByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.sub(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::sub); + } + + @Test(dataProvider = "byteBinaryOpMaskProvider") + static void subByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction fa, IntFunction fb, + IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.sub(b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ByteMaxVectorTests::sub); + } + + @Test(dataProvider = "byteBinaryOpProvider") + static void mulByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.mul(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::mul); + } + + @Test(dataProvider = "byteBinaryOpMaskProvider") + static void mulByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction fa, IntFunction fb, + IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.mul(b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ByteMaxVectorTests::mul); + } + + + + + @Test(dataProvider = "byteBinaryOpProvider") + static void divByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + replaceZero(b, (byte) 1); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.div(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::div); + } + + + + @Test(dataProvider = "byteBinaryOpMaskProvider") + static void divByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction fa, IntFunction fb, + IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + replaceZero(b, (byte) 1); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.div(b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ByteMaxVectorTests::div); + } + + + + @Test(dataProvider = "byteBinaryOpProvider") + static void ORByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::OR); + } + + @Test(dataProvider = "byteBinaryOpProvider") + static void orByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.or(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::or); + } + + + + @Test(dataProvider = "byteBinaryOpMaskProvider") + static void ORByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction fa, IntFunction fb, + IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ByteMaxVectorTests::OR); + } + + static byte LSHL(byte a, byte b) { @@ -1804,6 +2037,62 @@ assertArraysEquals(a, b, r, ByteMaxVectorTests::max); } + @Test(dataProvider = "byteBinaryOpProvider") + static void MINByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::MIN); + } + + @Test(dataProvider = "byteBinaryOpProvider") + static void minByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.min(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::min); + } + + @Test(dataProvider = "byteBinaryOpProvider") + static void MAXByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::MAX); + } + + @Test(dataProvider = "byteBinaryOpProvider") + static void maxByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { + byte[] a = fa.apply(SPECIES.length()); + byte[] b = fb.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.max(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ByteMaxVectorTests::max); + } + static byte AND(byte[] a, int idx) { byte res = -1; for (int i = idx; i < (idx + SPECIES.length()); i++) { @@ -3248,6 +3537,10 @@ return (byte)(-((byte)a)); } + static byte neg(byte a) { + return (byte)(-((byte)a)); + } + @Test(dataProvider = "byteUnaryOpProvider") static void NEGByteMaxVectorTests(IntFunction fa) { byte[] a = fa.apply(SPECIES.length()); @@ -3263,6 +3556,21 @@ assertArraysEquals(a, r, ByteMaxVectorTests::NEG); } + @Test(dataProvider = "byteUnaryOpProvider") + static void negByteMaxVectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.neg().intoArray(r, i); + } + } + + assertArraysEquals(a, r, ByteMaxVectorTests::neg); + } + @Test(dataProvider = "byteUnaryOpMaskProvider") static void NEGMaskedByteMaxVectorTests(IntFunction fa, IntFunction fm) { @@ -3342,6 +3650,10 @@ return (byte)(~((byte)a)); } + static byte not(byte a) { + return (byte)(~((byte)a)); + } + @Test(dataProvider = "byteUnaryOpProvider") @@ -3359,6 +3671,21 @@ assertArraysEquals(a, r, ByteMaxVectorTests::NOT); } + @Test(dataProvider = "byteUnaryOpProvider") + static void notByteMaxVectorTests(IntFunction fa) { + byte[] a = fa.apply(SPECIES.length()); + byte[] r = fr.apply(SPECIES.length()); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.not().intoArray(r, i); + } + } + + assertArraysEquals(a, r, ByteMaxVectorTests::not); + } + @Test(dataProvider = "byteUnaryOpMaskProvider")