< prev index next >
test/jdk/jdk/incubator/vector/Short128VectorTests.java
Print this page
@@ -239,10 +239,21 @@
} 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) {
@@ -254,10 +265,25 @@
} 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()) {
@@ -1367,10 +1393,30 @@
}
}
assertArraysEquals(a, b, r, Short128VectorTests::OR);
}
+ static short or(short a, short b) {
+ return (short)(a | b);
+ }
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void orShort128VectorTests(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, Short128VectorTests::or);
+ }
@Test(dataProvider = "shortBinaryOpMaskProvider")
static void ORShort128VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
@@ -1435,10 +1481,193 @@
assertArraysEquals(a, b, r, mask, Short128VectorTests::XOR);
}
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void addShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::add);
+ }
+
+ @Test(dataProvider = "shortBinaryOpMaskProvider")
+ static void addShort128VectorTestsBroadcastMaskedSmokeTest(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, Short128VectorTests::add);
+ }
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void subShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::sub);
+ }
+
+ @Test(dataProvider = "shortBinaryOpMaskProvider")
+ static void subShort128VectorTestsBroadcastMaskedSmokeTest(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, Short128VectorTests::sub);
+ }
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void mulShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::mul);
+ }
+
+ @Test(dataProvider = "shortBinaryOpMaskProvider")
+ static void mulShort128VectorTestsBroadcastMaskedSmokeTest(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, Short128VectorTests::mul);
+ }
+
+
+
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void divShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::div);
+ }
+
+
+
+ @Test(dataProvider = "shortBinaryOpMaskProvider")
+ static void divShort128VectorTestsBroadcastMaskedSmokeTest(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, Short128VectorTests::div);
+ }
+
+
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void ORShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::OR);
+ }
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void orShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::or);
+ }
+
+
+
+ @Test(dataProvider = "shortBinaryOpMaskProvider")
+ static void ORShort128VectorTestsBroadcastMaskedSmokeTest(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, Short128VectorTests::OR);
+ }
+
+
static short LSHL(short a, short b) {
@@ -1797,10 +2026,66 @@
}
assertArraysEquals(a, b, r, Short128VectorTests::max);
}
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void MINShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::MIN);
+ }
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void minShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::min);
+ }
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void MAXShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::MAX);
+ }
+
+ @Test(dataProvider = "shortBinaryOpProvider")
+ static void maxShort128VectorTestsBroadcastSmokeTest(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, Short128VectorTests::max);
+ }
+
static short AND(short[] a, int idx) {
short res = -1;
for (int i = idx; i < (idx + SPECIES.length()); i++) {
res &= a[i];
}
@@ -3241,10 +3526,14 @@
static short NEG(short a) {
return (short)(-((short)a));
}
+ static short neg(short a) {
+ return (short)(-((short)a));
+ }
+
@Test(dataProvider = "shortUnaryOpProvider")
static void NEGShort128VectorTests(IntFunction<short[]> fa) {
short[] a = fa.apply(SPECIES.length());
short[] r = fr.apply(SPECIES.length());
@@ -3256,10 +3545,25 @@
}
assertArraysEquals(a, r, Short128VectorTests::NEG);
}
+ @Test(dataProvider = "shortUnaryOpProvider")
+ static void negShort128VectorTests(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, Short128VectorTests::neg);
+ }
+
@Test(dataProvider = "shortUnaryOpMaskProvider")
static void NEGMaskedShort128VectorTests(IntFunction<short[]> fa,
IntFunction<boolean[]> fm) {
short[] a = fa.apply(SPECIES.length());
short[] r = fr.apply(SPECIES.length());
@@ -3335,10 +3639,14 @@
static short NOT(short a) {
return (short)(~((short)a));
}
+ static short not(short a) {
+ return (short)(~((short)a));
+ }
+
@Test(dataProvider = "shortUnaryOpProvider")
static void NOTShort128VectorTests(IntFunction<short[]> fa) {
short[] a = fa.apply(SPECIES.length());
@@ -3352,10 +3660,25 @@
}
assertArraysEquals(a, r, Short128VectorTests::NOT);
}
+ @Test(dataProvider = "shortUnaryOpProvider")
+ static void notShort128VectorTests(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, Short128VectorTests::not);
+ }
+
@Test(dataProvider = "shortUnaryOpMaskProvider")
static void NOTMaskedShort128VectorTests(IntFunction<short[]> fa,
IntFunction<boolean[]> fm) {
< prev index next >