mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-15 02:13:19 +00:00
8358768: [vectorapi] Make VectorOperators.SUADD an Associative
Reviewed-by: psandoz
This commit is contained in:
parent
d2082c58ff
commit
b65fdf5af0
@ -577,7 +577,7 @@ public abstract class VectorOperators {
|
||||
/** Produce saturating unsigned {@code a+b}. Integral only.
|
||||
* @see VectorMath#addSaturatingUnsigned(int, int)
|
||||
*/
|
||||
public static final Binary SUADD = binary("SUADD", "+", VectorSupport.VECTOR_OP_SUADD, VO_NOFP);
|
||||
public static final Associative SUADD = assoc("SUADD", "+", VectorSupport.VECTOR_OP_SUADD, VO_NOFP+VO_ASSOC);
|
||||
/** Produce saturating {@code a-b}. Integral only.
|
||||
* @see VectorMath#subSaturating(int, int)
|
||||
*/
|
||||
|
||||
@ -405,6 +405,52 @@ public class Byte128VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1016,6 +1062,21 @@ public class Byte128VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<byte[]>> BYTE_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("byte[Byte.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE));
|
||||
}),
|
||||
withToString("byte[Byte.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("byte[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
|
||||
@ -1028,6 +1089,12 @@ public class Byte128VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> BYTE_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(BYTE_GENERATORS.get(1))
|
||||
.flatMap(fa -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1064,6 +1131,22 @@ public class Byte128VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocProvider() {
|
||||
return BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteIndexedOpProvider() {
|
||||
return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3420,6 +3503,51 @@ public class Byte128VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Byte128VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = 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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Byte128VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
|
||||
IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Byte128VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static byte ANDReduce(byte[] a, int idx) {
|
||||
byte res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Byte256VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1016,6 +1062,21 @@ public class Byte256VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<byte[]>> BYTE_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("byte[Byte.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE));
|
||||
}),
|
||||
withToString("byte[Byte.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("byte[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
|
||||
@ -1028,6 +1089,12 @@ public class Byte256VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> BYTE_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(BYTE_GENERATORS.get(1))
|
||||
.flatMap(fa -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1064,6 +1131,22 @@ public class Byte256VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocProvider() {
|
||||
return BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteIndexedOpProvider() {
|
||||
return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3420,6 +3503,51 @@ public class Byte256VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Byte256VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = 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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Byte256VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
|
||||
IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Byte256VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static byte ANDReduce(byte[] a, int idx) {
|
||||
byte res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Byte512VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1016,6 +1062,21 @@ public class Byte512VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<byte[]>> BYTE_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("byte[Byte.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE));
|
||||
}),
|
||||
withToString("byte[Byte.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("byte[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
|
||||
@ -1028,6 +1089,12 @@ public class Byte512VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> BYTE_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(BYTE_GENERATORS.get(1))
|
||||
.flatMap(fa -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1064,6 +1131,22 @@ public class Byte512VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocProvider() {
|
||||
return BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteIndexedOpProvider() {
|
||||
return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3420,6 +3503,51 @@ public class Byte512VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Byte512VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocByte512VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = 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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Byte512VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocByte512VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
|
||||
IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Byte512VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static byte ANDReduce(byte[] a, int idx) {
|
||||
byte res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Byte64VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1016,6 +1062,21 @@ public class Byte64VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<byte[]>> BYTE_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("byte[Byte.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE));
|
||||
}),
|
||||
withToString("byte[Byte.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("byte[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
|
||||
@ -1028,6 +1089,12 @@ public class Byte64VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> BYTE_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(BYTE_GENERATORS.get(1))
|
||||
.flatMap(fa -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1064,6 +1131,22 @@ public class Byte64VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocProvider() {
|
||||
return BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteIndexedOpProvider() {
|
||||
return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3420,6 +3503,51 @@ public class Byte64VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Byte64VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = 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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Byte64VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocByte64VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
|
||||
IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Byte64VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static byte ANDReduce(byte[] a, int idx) {
|
||||
byte res = -1;
|
||||
|
||||
@ -410,6 +410,52 @@ public class ByteMaxVectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1021,6 +1067,21 @@ public class ByteMaxVectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<byte[]>> BYTE_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("byte[Byte.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE));
|
||||
}),
|
||||
withToString("byte[Byte.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(Byte.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("byte[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (byte)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
|
||||
@ -1033,6 +1094,12 @@ public class ByteMaxVectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> BYTE_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<byte[]>>> BYTE_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(BYTE_GENERATORS.get(1))
|
||||
.flatMap(fa -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1069,6 +1136,22 @@ public class ByteMaxVectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocProvider() {
|
||||
return BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] byteIndexedOpProvider() {
|
||||
return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3425,6 +3508,51 @@ public class ByteMaxVectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = 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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, ByteMaxVectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "byteSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
|
||||
IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
|
||||
byte[] a = fa.apply(SPECIES.length());
|
||||
byte[] b = fb.apply(SPECIES.length());
|
||||
byte[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
byte[] rl = fr.apply(SPECIES.length());
|
||||
byte[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, ByteMaxVectorTests::SUADD);
|
||||
}
|
||||
|
||||
static byte ANDReduce(byte[] a, int idx) {
|
||||
byte res = -1;
|
||||
|
||||
@ -423,6 +423,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -423,6 +423,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -423,6 +423,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -423,6 +423,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -428,6 +428,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(double[] rl, double[] rr, double[] a, double[] b, double[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -423,6 +423,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(float[] r, float[] a, float[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -423,6 +423,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(float[] r, float[] a, float[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -423,6 +423,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(float[] r, float[] a, float[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -423,6 +423,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(float[] r, float[] a, float[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -428,6 +428,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(float[] rl, float[] rr, float[] a, float[] b, float[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(float[] r, float[] a, float[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
|
||||
@ -405,6 +405,52 @@ public class Int128VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1006,6 +1052,21 @@ public class Int128VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<int[]>> INT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("int[Integer.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE));
|
||||
}),
|
||||
withToString("int[Integer.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("int[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<int[]>>> INT_GENERATOR_PAIRS =
|
||||
@ -1018,6 +1079,12 @@ public class Int128VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> INT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<int[]>>> INT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(INT_GENERATORS.get(1))
|
||||
.flatMap(fa -> INT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> INT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1054,6 +1121,22 @@ public class Int128VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocProvider() {
|
||||
return INT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> INT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intIndexedOpProvider() {
|
||||
return INT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3464,6 +3547,51 @@ public class Int128VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Int128VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Int128VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocInt128VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
|
||||
IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Int128VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static int ANDReduce(int[] a, int idx) {
|
||||
int res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Int256VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1006,6 +1052,21 @@ public class Int256VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<int[]>> INT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("int[Integer.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE));
|
||||
}),
|
||||
withToString("int[Integer.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("int[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<int[]>>> INT_GENERATOR_PAIRS =
|
||||
@ -1018,6 +1079,12 @@ public class Int256VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> INT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<int[]>>> INT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(INT_GENERATORS.get(1))
|
||||
.flatMap(fa -> INT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> INT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1054,6 +1121,22 @@ public class Int256VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocProvider() {
|
||||
return INT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> INT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intIndexedOpProvider() {
|
||||
return INT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3464,6 +3547,51 @@ public class Int256VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Int256VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocInt256VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Int256VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocInt256VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
|
||||
IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Int256VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static int ANDReduce(int[] a, int idx) {
|
||||
int res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Int512VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1006,6 +1052,21 @@ public class Int512VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<int[]>> INT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("int[Integer.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE));
|
||||
}),
|
||||
withToString("int[Integer.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("int[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<int[]>>> INT_GENERATOR_PAIRS =
|
||||
@ -1018,6 +1079,12 @@ public class Int512VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> INT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<int[]>>> INT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(INT_GENERATORS.get(1))
|
||||
.flatMap(fa -> INT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> INT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1054,6 +1121,22 @@ public class Int512VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocProvider() {
|
||||
return INT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> INT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intIndexedOpProvider() {
|
||||
return INT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3464,6 +3547,51 @@ public class Int512VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Int512VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Int512VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
|
||||
IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Int512VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static int ANDReduce(int[] a, int idx) {
|
||||
int res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Int64VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1006,6 +1052,21 @@ public class Int64VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<int[]>> INT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("int[Integer.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE));
|
||||
}),
|
||||
withToString("int[Integer.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("int[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<int[]>>> INT_GENERATOR_PAIRS =
|
||||
@ -1018,6 +1079,12 @@ public class Int64VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> INT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<int[]>>> INT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(INT_GENERATORS.get(1))
|
||||
.flatMap(fa -> INT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> INT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1054,6 +1121,22 @@ public class Int64VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocProvider() {
|
||||
return INT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> INT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intIndexedOpProvider() {
|
||||
return INT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3464,6 +3547,51 @@ public class Int64VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Int64VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocInt64VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Int64VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocInt64VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
|
||||
IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Int64VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static int ANDReduce(int[] a, int idx) {
|
||||
int res = -1;
|
||||
|
||||
@ -410,6 +410,52 @@ public class IntMaxVectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(int[] rl, int[] rr, int[] a, int[] b, int[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1011,6 +1057,21 @@ public class IntMaxVectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<int[]>> INT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("int[Integer.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE));
|
||||
}),
|
||||
withToString("int[Integer.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(Integer.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("int[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (int)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<int[]>>> INT_GENERATOR_PAIRS =
|
||||
@ -1023,6 +1084,12 @@ public class IntMaxVectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> INT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<int[]>>> INT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(INT_GENERATORS.get(1))
|
||||
.flatMap(fa -> INT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> INT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1059,6 +1126,22 @@ public class IntMaxVectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocProvider() {
|
||||
return INT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> INT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] intIndexedOpProvider() {
|
||||
return INT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3469,6 +3552,51 @@ public class IntMaxVectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, IntMaxVectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocIntMaxVectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, IntMaxVectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "intSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocIntMaxVectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
|
||||
IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
|
||||
int[] a = fa.apply(SPECIES.length());
|
||||
int[] b = fb.apply(SPECIES.length());
|
||||
int[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
int[] rl = fr.apply(SPECIES.length());
|
||||
int[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
IntVector av = IntVector.fromArray(SPECIES, a, i);
|
||||
IntVector bv = IntVector.fromArray(SPECIES, b, i);
|
||||
IntVector cv = IntVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, IntMaxVectorTests::SUADD);
|
||||
}
|
||||
|
||||
static int ANDReduce(int[] a, int idx) {
|
||||
int res = -1;
|
||||
|
||||
@ -362,6 +362,52 @@ public class Long128VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(long[] r, long[] a, long[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -996,6 +1042,21 @@ public class Long128VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<long[]>> LONG_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("long[Long.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE));
|
||||
}),
|
||||
withToString("long[Long.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("long[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<long[]>>> LONG_GENERATOR_PAIRS =
|
||||
@ -1008,6 +1069,12 @@ public class Long128VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> LONG_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<long[]>>> LONG_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(LONG_GENERATORS.get(1))
|
||||
.flatMap(fa -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1044,6 +1111,22 @@ public class Long128VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocProvider() {
|
||||
return LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longIndexedOpProvider() {
|
||||
return LONG_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3486,6 +3569,51 @@ public class Long128VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Long128VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocLong128VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb, IntFunction<long[]> fc) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Long128VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocLong128VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
|
||||
IntFunction<long[]> fc, IntFunction<boolean[]> fm) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Long128VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static long ANDReduce(long[] a, int idx) {
|
||||
long res = -1;
|
||||
|
||||
@ -362,6 +362,52 @@ public class Long256VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(long[] r, long[] a, long[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -996,6 +1042,21 @@ public class Long256VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<long[]>> LONG_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("long[Long.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE));
|
||||
}),
|
||||
withToString("long[Long.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("long[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<long[]>>> LONG_GENERATOR_PAIRS =
|
||||
@ -1008,6 +1069,12 @@ public class Long256VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> LONG_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<long[]>>> LONG_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(LONG_GENERATORS.get(1))
|
||||
.flatMap(fa -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1044,6 +1111,22 @@ public class Long256VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocProvider() {
|
||||
return LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longIndexedOpProvider() {
|
||||
return LONG_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3486,6 +3569,51 @@ public class Long256VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Long256VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocLong256VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb, IntFunction<long[]> fc) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Long256VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocLong256VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
|
||||
IntFunction<long[]> fc, IntFunction<boolean[]> fm) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Long256VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static long ANDReduce(long[] a, int idx) {
|
||||
long res = -1;
|
||||
|
||||
@ -362,6 +362,52 @@ public class Long512VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(long[] r, long[] a, long[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -996,6 +1042,21 @@ public class Long512VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<long[]>> LONG_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("long[Long.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE));
|
||||
}),
|
||||
withToString("long[Long.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("long[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<long[]>>> LONG_GENERATOR_PAIRS =
|
||||
@ -1008,6 +1069,12 @@ public class Long512VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> LONG_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<long[]>>> LONG_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(LONG_GENERATORS.get(1))
|
||||
.flatMap(fa -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1044,6 +1111,22 @@ public class Long512VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocProvider() {
|
||||
return LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longIndexedOpProvider() {
|
||||
return LONG_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3486,6 +3569,51 @@ public class Long512VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Long512VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocLong512VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb, IntFunction<long[]> fc) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Long512VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocLong512VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
|
||||
IntFunction<long[]> fc, IntFunction<boolean[]> fm) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Long512VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static long ANDReduce(long[] a, int idx) {
|
||||
long res = -1;
|
||||
|
||||
@ -362,6 +362,52 @@ public class Long64VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(long[] r, long[] a, long[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -996,6 +1042,21 @@ public class Long64VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<long[]>> LONG_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("long[Long.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE));
|
||||
}),
|
||||
withToString("long[Long.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("long[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<long[]>>> LONG_GENERATOR_PAIRS =
|
||||
@ -1008,6 +1069,12 @@ public class Long64VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> LONG_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<long[]>>> LONG_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(LONG_GENERATORS.get(1))
|
||||
.flatMap(fa -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1044,6 +1111,22 @@ public class Long64VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocProvider() {
|
||||
return LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longIndexedOpProvider() {
|
||||
return LONG_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3486,6 +3569,51 @@ public class Long64VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Long64VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocLong64VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb, IntFunction<long[]> fc) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Long64VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocLong64VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
|
||||
IntFunction<long[]> fc, IntFunction<boolean[]> fm) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Long64VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static long ANDReduce(long[] a, int idx) {
|
||||
long res = -1;
|
||||
|
||||
@ -367,6 +367,52 @@ public class LongMaxVectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(long[] rl, long[] rr, long[] a, long[] b, long[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(long[] r, long[] a, long[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1001,6 +1047,21 @@ public class LongMaxVectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<long[]>> LONG_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("long[Long.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE));
|
||||
}),
|
||||
withToString("long[Long.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(Long.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("long[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (long)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<long[]>>> LONG_GENERATOR_PAIRS =
|
||||
@ -1013,6 +1074,12 @@ public class LongMaxVectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> LONG_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<long[]>>> LONG_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(LONG_GENERATORS.get(1))
|
||||
.flatMap(fa -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> LONG_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1049,6 +1116,22 @@ public class LongMaxVectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocProvider() {
|
||||
return LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> LONG_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] longIndexedOpProvider() {
|
||||
return LONG_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3491,6 +3574,51 @@ public class LongMaxVectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, LongMaxVectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb, IntFunction<long[]> fc) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, LongMaxVectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "longSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
|
||||
IntFunction<long[]> fc, IntFunction<boolean[]> fm) {
|
||||
long[] a = fa.apply(SPECIES.length());
|
||||
long[] b = fb.apply(SPECIES.length());
|
||||
long[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
long[] rl = fr.apply(SPECIES.length());
|
||||
long[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
LongVector av = LongVector.fromArray(SPECIES, a, i);
|
||||
LongVector bv = LongVector.fromArray(SPECIES, b, i);
|
||||
LongVector cv = LongVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, LongMaxVectorTests::SUADD);
|
||||
}
|
||||
|
||||
static long ANDReduce(long[] a, int idx) {
|
||||
long res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Short128VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(short[] r, short[] a, short[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1006,6 +1052,21 @@ public class Short128VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<short[]>> SHORT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("short[Short.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE));
|
||||
}),
|
||||
withToString("short[Short.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("short[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_PAIRS =
|
||||
@ -1018,6 +1079,12 @@ public class Short128VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> SHORT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<short[]>>> SHORT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(SHORT_GENERATORS.get(1))
|
||||
.flatMap(fa -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1054,6 +1121,22 @@ public class Short128VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocProvider() {
|
||||
return SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortIndexedOpProvider() {
|
||||
return SHORT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3411,6 +3494,51 @@ public class Short128VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Short128VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = 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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Short128VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocShort128VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
|
||||
IntFunction<short[]> fc, IntFunction<boolean[]> fm) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Short128VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static short ANDReduce(short[] a, int idx) {
|
||||
short res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Short256VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(short[] r, short[] a, short[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1006,6 +1052,21 @@ public class Short256VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<short[]>> SHORT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("short[Short.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE));
|
||||
}),
|
||||
withToString("short[Short.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("short[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_PAIRS =
|
||||
@ -1018,6 +1079,12 @@ public class Short256VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> SHORT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<short[]>>> SHORT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(SHORT_GENERATORS.get(1))
|
||||
.flatMap(fa -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1054,6 +1121,22 @@ public class Short256VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocProvider() {
|
||||
return SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortIndexedOpProvider() {
|
||||
return SHORT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3411,6 +3494,51 @@ public class Short256VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Short256VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocShort256VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = 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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Short256VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocShort256VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
|
||||
IntFunction<short[]> fc, IntFunction<boolean[]> fm) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Short256VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static short ANDReduce(short[] a, int idx) {
|
||||
short res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Short512VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(short[] r, short[] a, short[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1006,6 +1052,21 @@ public class Short512VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<short[]>> SHORT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("short[Short.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE));
|
||||
}),
|
||||
withToString("short[Short.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("short[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_PAIRS =
|
||||
@ -1018,6 +1079,12 @@ public class Short512VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> SHORT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<short[]>>> SHORT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(SHORT_GENERATORS.get(1))
|
||||
.flatMap(fa -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1054,6 +1121,22 @@ public class Short512VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocProvider() {
|
||||
return SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortIndexedOpProvider() {
|
||||
return SHORT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3411,6 +3494,51 @@ public class Short512VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Short512VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = 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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Short512VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
|
||||
IntFunction<short[]> fc, IntFunction<boolean[]> fm) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Short512VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static short ANDReduce(short[] a, int idx) {
|
||||
short res = -1;
|
||||
|
||||
@ -405,6 +405,52 @@ public class Short64VectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(short[] r, short[] a, short[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1006,6 +1052,21 @@ public class Short64VectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<short[]>> SHORT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("short[Short.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE));
|
||||
}),
|
||||
withToString("short[Short.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("short[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_PAIRS =
|
||||
@ -1018,6 +1079,12 @@ public class Short64VectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> SHORT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<short[]>>> SHORT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(SHORT_GENERATORS.get(1))
|
||||
.flatMap(fa -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1054,6 +1121,22 @@ public class Short64VectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocProvider() {
|
||||
return SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortIndexedOpProvider() {
|
||||
return SHORT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3411,6 +3494,51 @@ public class Short64VectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, Short64VectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = 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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, Short64VectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocShort64VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
|
||||
IntFunction<short[]> fc, IntFunction<boolean[]> fm) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Short64VectorTests::SUADD);
|
||||
}
|
||||
|
||||
static short ANDReduce(short[] a, int idx) {
|
||||
short res = -1;
|
||||
|
||||
@ -410,6 +410,52 @@ public class ShortMaxVectorTests extends AbstractVectorTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals(short[] r, short[] a, short[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1011,6 +1057,21 @@ public class ShortMaxVectorTests extends AbstractVectorTest {
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<short[]>> SHORT_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("short[Short.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE));
|
||||
}),
|
||||
withToString("short[Short.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(Short.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("short[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> (short)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_PAIRS =
|
||||
@ -1023,6 +1084,12 @@ public class ShortMaxVectorTests extends AbstractVectorTest {
|
||||
flatMap(fa -> SHORT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<short[]>>> SHORT_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of(SHORT_GENERATORS.get(1))
|
||||
.flatMap(fa -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
return BOOL_ARRAY_GENERATORS.stream().
|
||||
@ -1059,6 +1126,22 @@ public class ShortMaxVectorTests extends AbstractVectorTest {
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocProvider() {
|
||||
return SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortSaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] shortIndexedOpProvider() {
|
||||
return SHORT_GENERATOR_PAIRS.stream().map(List::toArray).
|
||||
@ -3416,6 +3499,51 @@ public class ShortMaxVectorTests extends AbstractVectorTest {
|
||||
|
||||
assertBroadcastArraysEquals(r, a, b, ShortMaxVectorTests::max);
|
||||
}
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocProvider")
|
||||
static void SUADDAssocShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = 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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, ShortMaxVectorTests::SUADD);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "shortSaturatingBinaryOpAssocMaskProvider")
|
||||
static void SUADDAssocShortMaxVectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
|
||||
IntFunction<short[]> fc, IntFunction<boolean[]> fm) {
|
||||
short[] a = fa.apply(SPECIES.length());
|
||||
short[] b = fb.apply(SPECIES.length());
|
||||
short[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
short[] rl = fr.apply(SPECIES.length());
|
||||
short[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
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);
|
||||
ShortVector cv = ShortVector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, ShortMaxVectorTests::SUADD);
|
||||
}
|
||||
|
||||
static short ANDReduce(short[] a, int idx) {
|
||||
short res = -1;
|
||||
|
||||
@ -46,6 +46,8 @@ binary_memop="Binary-mem-op"
|
||||
binary_masked_memop="Binary-Masked-mem-op"
|
||||
saturating_binary="SaturatingBinary-op"
|
||||
saturating_binary_masked="SaturatingBinary-Masked-op"
|
||||
saturating_binary_assocative="SaturatingBinary-op-associative"
|
||||
saturating_binary_assocative_masked="SaturatingBinary-Masked-op-associative"
|
||||
binary_broadcast="Binary-Broadcast-op"
|
||||
binary_broadcast_masked="Binary-Broadcast-Masked-op"
|
||||
binary_broadcast_long="Binary-Broadcast-Long-op"
|
||||
@ -326,6 +328,12 @@ function gen_saturating_binary_op {
|
||||
gen_op_tmpl $saturating_binary_masked "$@"
|
||||
}
|
||||
|
||||
function gen_saturating_binary_op_associative {
|
||||
echo "Generating saturating binary associative op $1 ($2)..."
|
||||
gen_op_tmpl $saturating_binary_assocative "$@"
|
||||
gen_op_tmpl $saturating_binary_assocative_masked "$@"
|
||||
}
|
||||
|
||||
function gen_binary_op_no_masked {
|
||||
echo "Generating binary op $1 ($2)..."
|
||||
# gen_op_tmpl $binary_scalar "$@"
|
||||
@ -487,6 +495,7 @@ gen_saturating_binary_op "SUADD" "VectorMath.addSaturatingUnsigned(a, b)" "BITWI
|
||||
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_saturating_binary_op_associative "SUADD" "VectorMath.addSaturatingUnsigned(a, b)" "BITWISE"
|
||||
|
||||
# Reductions.
|
||||
gen_reduction_op "AND" "\&" "BITWISE" "-1"
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
$type$[] a = fa.apply(SPECIES.length());
|
||||
$type$[] b = fb.apply(SPECIES.length());
|
||||
$type$[] c = fc.apply(SPECIES.length());
|
||||
boolean[] mask = fm.apply(SPECIES.length());
|
||||
$type$[] rl = fr.apply(SPECIES.length());
|
||||
$type$[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
VectorMask<$Wideboxtype$> vmask = VectorMask.fromArray(SPECIES, mask, 0);
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
$abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i);
|
||||
$abstractvectortype$ bv = $abstractvectortype$.fromArray(SPECIES, b, i);
|
||||
$abstractvectortype$ cv = $abstractvectortype$.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
$type$[] a = fa.apply(SPECIES.length());
|
||||
$type$[] b = fb.apply(SPECIES.length());
|
||||
$type$[] c = fc.apply(SPECIES.length());
|
||||
$type$[] rl = fr.apply(SPECIES.length());
|
||||
$type$[] rr = fr.apply(SPECIES.length());
|
||||
|
||||
for (int ic = 0; ic < INVOC_COUNT; ic++) {
|
||||
for (int i = 0; i < a.length; i += SPECIES.length()) {
|
||||
$Type$Vector av = $Type$Vector.fromArray(SPECIES, a, i);
|
||||
$Type$Vector bv = $Type$Vector.fromArray(SPECIES, b, i);
|
||||
$Type$Vector cv = $Type$Vector.fromArray(SPECIES, c, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
|
||||
av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
|
||||
@Test(dataProvider = "$type$SaturatingBinaryOpAssocMaskProvider")
|
||||
static void [[TEST]]Assoc$vectorteststype$Masked(IntFunction<$type$[]> fa, IntFunction<$type$[]> fb,
|
||||
IntFunction<$type$[]> fc, IntFunction<boolean[]> fm) {
|
||||
[[KERNEL]]
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, $vectorteststype$::[[TEST]]);
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
@Test(dataProvider = "$type$SaturatingBinaryOpAssocProvider")
|
||||
static void [[TEST]]Assoc$vectorteststype$(IntFunction<$type$[]> fa, IntFunction<$type$[]> fb, IntFunction<$type$[]> fc) {
|
||||
[[KERNEL]]
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, $vectorteststype$::[[TEST]]);
|
||||
}
|
||||
@ -502,6 +502,52 @@ relativeError));
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative($type$[] rl, $type$[] rr, $type$[] a, $type$[] b, $type$[] c, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative($type$[] rl, $type$[] rr, $type$[] a, $type$[] b, $type$[] c, boolean[] mask, FBinOp f) {
|
||||
assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
|
||||
}
|
||||
|
||||
static void assertArraysEqualsAssociative($type$[] rl, $type$[] rr, $type$[] a, $type$[] b, $type$[] c, boolean[] mask, FBinMaskOp f) {
|
||||
int i = 0;
|
||||
boolean mask_bit = false;
|
||||
try {
|
||||
for (; i < a.length; i++) {
|
||||
mask_bit = mask[i % SPECIES.length()];
|
||||
//Left associative
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
|
||||
|
||||
//Right associative
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
|
||||
|
||||
//Results equal sanity check
|
||||
Assert.assertEquals(rl[i], rr[i]);
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit);
|
||||
Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, FBinOp f) {
|
||||
int i = 0;
|
||||
try {
|
||||
@ -1278,6 +1324,21 @@ relativeError));
|
||||
})
|
||||
);
|
||||
|
||||
static final List<IntFunction<$type$[]>> $TYPE$_SATURATING_GENERATORS_ASSOC = List.of(
|
||||
withToString("$type$[$Boxtype$.MAX_VALUE]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> ($type$)($Boxtype$.MAX_VALUE));
|
||||
}),
|
||||
withToString("$type$[$Boxtype$.MAX_VALUE - 100]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> ($type$)($Boxtype$.MAX_VALUE - 100));
|
||||
}),
|
||||
withToString("$type$[-1]", (int s) -> {
|
||||
return fill(s * BUFFER_REPS,
|
||||
i -> ($type$)(-1));
|
||||
})
|
||||
);
|
||||
|
||||
#end[!FP]
|
||||
// Create combinations of pairs
|
||||
// @@@ Might be sensitive to order e.g. div by 0
|
||||
@ -1292,6 +1353,12 @@ relativeError));
|
||||
flatMap(fa -> $TYPE$_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
|
||||
collect(Collectors.toList());
|
||||
|
||||
static final List<List<IntFunction<$type$[]>>> $TYPE$_SATURATING_GENERATOR_TRIPLETS =
|
||||
Stream.of($TYPE$_GENERATORS.get(1))
|
||||
.flatMap(fa -> $TYPE$_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
|
||||
.flatMap(pair -> $TYPE$_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
#end[!FP]
|
||||
@DataProvider
|
||||
public Object[][] boolUnaryOpProvider() {
|
||||
@ -1330,6 +1397,22 @@ relativeError));
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] $type$SaturatingBinaryOpAssocProvider() {
|
||||
return $TYPE$_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] $type$SaturatingBinaryOpAssocMaskProvider() {
|
||||
return BOOLEAN_MASK_GENERATORS.stream().
|
||||
flatMap(fm -> $TYPE$_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
|
||||
return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
|
||||
})).
|
||||
toArray(Object[][]::new);
|
||||
}
|
||||
|
||||
|
||||
#end[!FP]
|
||||
@DataProvider
|
||||
public Object[][] $type$IndexedOpProvider() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user