< prev index next >

test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java

Print this page

        

*** 244,253 **** --- 244,265 ---- } catch (AssertionError e) { Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); } } + 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)); } static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
*** 259,268 **** --- 271,298 ---- } catch (AssertionError err) { Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); } } + 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; try { for (; j < a.length; j += SPECIES.length()) {
*** 1372,1381 **** --- 1402,1431 ---- } } assertArraysEquals(a, b, r, ByteMaxVectorTests::OR); } + static byte or(byte a, byte b) { + return (byte)(a | b); + } + + @Test(dataProvider = "byteBinaryOpProvider") + static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> 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); + } @Test(dataProvider = "byteBinaryOpMaskProvider") static void ORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
*** 1440,1449 **** --- 1490,1682 ---- assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::XOR); } + @Test(dataProvider = "byteBinaryOpProvider") + static void addByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> fb, + IntFunction<boolean[]> 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<Byte> 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<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> fb, + IntFunction<boolean[]> 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<Byte> 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<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> fb, + IntFunction<boolean[]> 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<Byte> 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<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> fb, + IntFunction<boolean[]> 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<Byte> 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<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> fb, + IntFunction<boolean[]> 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<Byte> 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) { return (byte)((a << (b & 0x7))); }
*** 1802,1811 **** --- 2035,2100 ---- } assertArraysEquals(a, b, r, ByteMaxVectorTests::max); } + @Test(dataProvider = "byteBinaryOpProvider") + static void MINByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> 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<byte[]> fa, IntFunction<byte[]> 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++) { res &= a[i]; }
*** 3246,3255 **** --- 3535,3548 ---- static byte NEG(byte a) { return (byte)(-((byte)a)); } + static byte neg(byte a) { + return (byte)(-((byte)a)); + } + @Test(dataProvider = "byteUnaryOpProvider") static void NEGByteMaxVectorTests(IntFunction<byte[]> fa) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
*** 3261,3270 **** --- 3554,3578 ---- } assertArraysEquals(a, r, ByteMaxVectorTests::NEG); } + @Test(dataProvider = "byteUnaryOpProvider") + static void negByteMaxVectorTests(IntFunction<byte[]> 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<byte[]> fa, IntFunction<boolean[]> fm) { byte[] a = fa.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
*** 3340,3349 **** --- 3648,3661 ---- static byte NOT(byte a) { return (byte)(~((byte)a)); } + static byte not(byte a) { + return (byte)(~((byte)a)); + } + @Test(dataProvider = "byteUnaryOpProvider") static void NOTByteMaxVectorTests(IntFunction<byte[]> fa) { byte[] a = fa.apply(SPECIES.length());
*** 3357,3366 **** --- 3669,3693 ---- } assertArraysEquals(a, r, ByteMaxVectorTests::NOT); } + @Test(dataProvider = "byteUnaryOpProvider") + static void notByteMaxVectorTests(IntFunction<byte[]> 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") static void NOTMaskedByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
< prev index next >