< prev index next >

test/jdk/jdk/incubator/vector/ShortMaxVectorTests.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(short[] a, short[] b, short[] 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(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); } static void assertArraysEquals(short[] a, short[] b, short[] 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(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { + assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); + } + + static void assertBroadcastArraysEquals(short[] a, short[] b, short[] 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(short[] a, short[] b, short[] 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, ShortMaxVectorTests::OR); } + static short or(short a, short b) { + return (short)(a | b); + } + + @Test(dataProvider = "shortBinaryOpProvider") + static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + ShortVector bv = ShortVector.fromArray(SPECIES, b, i); + av.or(bv).intoArray(r, i); + } + } + + assertArraysEquals(a, b, r, ShortMaxVectorTests::or); + } @Test(dataProvider = "shortBinaryOpMaskProvider") static void ORShortMaxVectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
*** 1440,1449 **** --- 1490,1682 ---- assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::XOR); } + @Test(dataProvider = "shortBinaryOpProvider") + static void addShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.add(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::add); + } + + @Test(dataProvider = "shortBinaryOpMaskProvider") + static void addShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, + IntFunction<boolean[]> fm) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.add(b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::add); + } + + @Test(dataProvider = "shortBinaryOpProvider") + static void subShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.sub(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::sub); + } + + @Test(dataProvider = "shortBinaryOpMaskProvider") + static void subShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, + IntFunction<boolean[]> fm) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.sub(b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::sub); + } + + @Test(dataProvider = "shortBinaryOpProvider") + static void mulShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.mul(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::mul); + } + + @Test(dataProvider = "shortBinaryOpMaskProvider") + static void mulShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, + IntFunction<boolean[]> fm) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.mul(b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::mul); + } + + + + + @Test(dataProvider = "shortBinaryOpProvider") + static void divShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + replaceZero(b, (short) 1); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.div(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::div); + } + + + + @Test(dataProvider = "shortBinaryOpMaskProvider") + static void divShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, + IntFunction<boolean[]> fm) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); + + replaceZero(b, (short) 1); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.div(b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::div); + } + + + + @Test(dataProvider = "shortBinaryOpProvider") + static void ORShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::OR); + } + + @Test(dataProvider = "shortBinaryOpProvider") + static void orShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.or(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::or); + } + + + + @Test(dataProvider = "shortBinaryOpMaskProvider") + static void ORShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, + IntFunction<boolean[]> fm) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::OR); + } + + static short LSHL(short a, short b) {
*** 1802,1811 **** --- 2035,2100 ---- } assertArraysEquals(a, b, r, ShortMaxVectorTests::max); } + @Test(dataProvider = "shortBinaryOpProvider") + static void MINShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::MIN); + } + + @Test(dataProvider = "shortBinaryOpProvider") + static void minShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.min(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::min); + } + + @Test(dataProvider = "shortBinaryOpProvider") + static void MAXShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::MAX); + } + + @Test(dataProvider = "shortBinaryOpProvider") + static void maxShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { + short[] a = fa.apply(SPECIES.length()); + short[] b = fb.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.max(b[i]).intoArray(r, i); + } + + assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::max); + } + static short AND(short[] a, int idx) { short res = -1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; }
*** 3246,3255 **** --- 3535,3548 ---- static short NEG(short a) { return (short)(-((short)a)); } + static short neg(short a) { + return (short)(-((short)a)); + } + @Test(dataProvider = "shortUnaryOpProvider") static void NEGShortMaxVectorTests(IntFunction<short[]> fa) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length());
*** 3261,3270 **** --- 3554,3578 ---- } assertArraysEquals(a, r, ShortMaxVectorTests::NEG); } + @Test(dataProvider = "shortUnaryOpProvider") + static void negShortMaxVectorTests(IntFunction<short[]> fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.neg().intoArray(r, i); + } + } + + assertArraysEquals(a, r, ShortMaxVectorTests::neg); + } + @Test(dataProvider = "shortUnaryOpMaskProvider") static void NEGMaskedShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { short[] a = fa.apply(SPECIES.length()); short[] r = fr.apply(SPECIES.length());
*** 3340,3349 **** --- 3648,3661 ---- static short NOT(short a) { return (short)(~((short)a)); } + static short not(short a) { + return (short)(~((short)a)); + } + @Test(dataProvider = "shortUnaryOpProvider") static void NOTShortMaxVectorTests(IntFunction<short[]> fa) { short[] a = fa.apply(SPECIES.length());
*** 3357,3366 **** --- 3669,3693 ---- } assertArraysEquals(a, r, ShortMaxVectorTests::NOT); } + @Test(dataProvider = "shortUnaryOpProvider") + static void notShortMaxVectorTests(IntFunction<short[]> fa) { + short[] a = fa.apply(SPECIES.length()); + short[] r = fr.apply(SPECIES.length()); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.not().intoArray(r, i); + } + } + + assertArraysEquals(a, r, ShortMaxVectorTests::not); + } + @Test(dataProvider = "shortUnaryOpMaskProvider") static void NOTMaskedShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<boolean[]> fm) {
< prev index next >