diff --git a/test/jdk/jdk/incubator/vector/AbstractVectorTest.java b/test/jdk/jdk/incubator/vector/AbstractVectorTest.java index cf1c8eff20a..5e137d34ef4 100644 --- a/test/jdk/jdk/incubator/vector/AbstractVectorTest.java +++ b/test/jdk/jdk/incubator/vector/AbstractVectorTest.java @@ -108,20 +108,6 @@ public String toString() { i -> ((i % 5) == 0)); }) ); - static final List> INDEX_GENERATORS = List.of( - withToString("index[i -> i]", (int s) -> { - return fillInts(s, - i -> i); - }), - withToString("index[i -> size - i - 1]", (int s) -> { - return fillInts(s, - i -> s - i - 1); - }), - withToString("index[i -> (i % 2) == 0 ? i : s - i - 1]", (int s) -> { - return fillInts(s, - i -> (i % 2) == 0 ? i : s - i - 1); - }) - ); interface IntOp { int apply(int i); @@ -161,9 +147,8 @@ static int[] fillInts(int[] a, IntOp f) { fb -> List.of(fa, fb))).collect(Collectors.toList()); static final List> INT_SHUFFLE_GENERATORS = List.of( - withToStringBi("shuffle[random]", (Integer l, Integer m) -> { - return RAND.ints(l, 0, m).toArray(); - }) + withToStringBi("shuffle[random]", + (Integer l, Integer m) -> RAND.ints(l, 0, m).toArray()) ); interface RangeIntOp { @@ -202,17 +187,10 @@ static int[] fillRangeInts(int[] a, int min, int max, RangeIntOp f) { ); static final List> INT_INDEX_GENERATORS = List.of( - withToStringBi("index[random]", (Integer l, Integer m) -> { - return RAND.ints(l, 0, m).toArray(); - }) + withToStringBi("index[random]", + (Integer l, Integer m) -> RAND.ints(l, 0, m).toArray()) ); - static int countTrailingFalse(boolean[] m) { - int i; - for (i = m.length - 1; i >= 0 && !m[i]; i--); - return m.length - 1 - i; - } - static boolean isIndexOutOfBoundsForMask(boolean[] mask, int offset, int length) { return isIndexOutOfBoundsForMask(mask, offset, length, 1); } diff --git a/test/jdk/jdk/incubator/vector/Byte128VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Byte128VectorLoadStoreTests.java index 3f6a56f3f31..11472254ec2 100644 --- a/test/jdk/jdk/incubator/vector/Byte128VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Byte128VectorLoadStoreTests.java @@ -42,6 +42,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -50,13 +51,11 @@ public class Byte128VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ByteVector.SPECIES_128; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - static void assertArraysEquals(byte[] r, byte[] a, boolean[] mask) { int i = 0; try { @@ -178,25 +177,6 @@ public Object[][] byteMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] byteIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] byteByteBufferProvider() { return BYTE_GENERATORS.stream(). @@ -1038,4 +1018,281 @@ static void loadStoreMaskBooleanArray(IntFunction fa, } assertArraysEquals(r, a, mask); } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false, "at index #" + j); + } + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanGather(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i, b, i); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i, b, i, vmask); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanScatter(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + } diff --git a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java index bddd2663eaa..e9c5cf363c9 100644 --- a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java @@ -62,8 +62,6 @@ public class Byte128VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - interface FUnOp { byte apply(byte a); } @@ -1008,36 +1006,6 @@ public Object[][] byteUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] byteUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().flatMap(fn -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> BYTE_COMPARE_GENERATORS = List.of( withToString("byte[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4922,122 +4890,6 @@ static void ZOMOMaskedByte128VectorTests(IntFunction fa, - static byte[] gather(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void gatherByte128VectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Byte128VectorTests::gather); - } - static byte[] gatherMasked(byte a[], int ix, boolean[] mask, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "byteUnaryMaskedOpIndexProvider") - static void gatherMaskedByte128VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Byte128VectorTests::gatherMasked); - } - - static byte[] scatter(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void scatterByte128VectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Byte128VectorTests::scatter); - } - - static byte[] scatterMasked(byte r[], byte a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - byte[] oldVal = gather(r, ix, b, iy); - byte[] newVal = new byte[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - byte[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedByte128VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Byte128VectorTests::scatterMasked); - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByte128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Byte256VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Byte256VectorLoadStoreTests.java index b1313a16699..a986dd80256 100644 --- a/test/jdk/jdk/incubator/vector/Byte256VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Byte256VectorLoadStoreTests.java @@ -42,6 +42,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -50,13 +51,11 @@ public class Byte256VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ByteVector.SPECIES_256; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - static void assertArraysEquals(byte[] r, byte[] a, boolean[] mask) { int i = 0; try { @@ -178,25 +177,6 @@ public Object[][] byteMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] byteIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] byteByteBufferProvider() { return BYTE_GENERATORS.stream(). @@ -1038,4 +1018,281 @@ static void loadStoreMaskBooleanArray(IntFunction fa, } assertArraysEquals(r, a, mask); } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false, "at index #" + j); + } + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanGather(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i, b, i); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i, b, i, vmask); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanScatter(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + } diff --git a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java index 0b96fc50f90..52b32f835b5 100644 --- a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java @@ -62,8 +62,6 @@ public class Byte256VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - interface FUnOp { byte apply(byte a); } @@ -1008,36 +1006,6 @@ public Object[][] byteUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] byteUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().flatMap(fn -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> BYTE_COMPARE_GENERATORS = List.of( withToString("byte[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4922,122 +4890,6 @@ static void ZOMOMaskedByte256VectorTests(IntFunction fa, - static byte[] gather(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void gatherByte256VectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Byte256VectorTests::gather); - } - static byte[] gatherMasked(byte a[], int ix, boolean[] mask, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "byteUnaryMaskedOpIndexProvider") - static void gatherMaskedByte256VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Byte256VectorTests::gatherMasked); - } - - static byte[] scatter(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void scatterByte256VectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Byte256VectorTests::scatter); - } - - static byte[] scatterMasked(byte r[], byte a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - byte[] oldVal = gather(r, ix, b, iy); - byte[] newVal = new byte[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - byte[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedByte256VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Byte256VectorTests::scatterMasked); - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByte256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Byte512VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Byte512VectorLoadStoreTests.java index 0083716d365..b5a472d15e6 100644 --- a/test/jdk/jdk/incubator/vector/Byte512VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Byte512VectorLoadStoreTests.java @@ -42,6 +42,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -50,13 +51,11 @@ public class Byte512VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ByteVector.SPECIES_512; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - static void assertArraysEquals(byte[] r, byte[] a, boolean[] mask) { int i = 0; try { @@ -178,25 +177,6 @@ public Object[][] byteMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] byteIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] byteByteBufferProvider() { return BYTE_GENERATORS.stream(). @@ -1038,4 +1018,281 @@ static void loadStoreMaskBooleanArray(IntFunction fa, } assertArraysEquals(r, a, mask); } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false, "at index #" + j); + } + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanGather(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i, b, i); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i, b, i, vmask); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanScatter(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + } diff --git a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java index a47b67ba616..8f123b1ee6a 100644 --- a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java @@ -62,8 +62,6 @@ public class Byte512VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - interface FUnOp { byte apply(byte a); } @@ -1008,36 +1006,6 @@ public Object[][] byteUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] byteUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().flatMap(fn -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> BYTE_COMPARE_GENERATORS = List.of( withToString("byte[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4922,122 +4890,6 @@ static void ZOMOMaskedByte512VectorTests(IntFunction fa, - static byte[] gather(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void gatherByte512VectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Byte512VectorTests::gather); - } - static byte[] gatherMasked(byte a[], int ix, boolean[] mask, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "byteUnaryMaskedOpIndexProvider") - static void gatherMaskedByte512VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Byte512VectorTests::gatherMasked); - } - - static byte[] scatter(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void scatterByte512VectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Byte512VectorTests::scatter); - } - - static byte[] scatterMasked(byte r[], byte a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - byte[] oldVal = gather(r, ix, b, iy); - byte[] newVal = new byte[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - byte[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedByte512VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Byte512VectorTests::scatterMasked); - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByte512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Byte64VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Byte64VectorLoadStoreTests.java index a671c14f078..384be4ab8fc 100644 --- a/test/jdk/jdk/incubator/vector/Byte64VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Byte64VectorLoadStoreTests.java @@ -42,6 +42,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -50,13 +51,11 @@ public class Byte64VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ByteVector.SPECIES_64; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - static void assertArraysEquals(byte[] r, byte[] a, boolean[] mask) { int i = 0; try { @@ -178,25 +177,6 @@ public Object[][] byteMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] byteIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] byteByteBufferProvider() { return BYTE_GENERATORS.stream(). @@ -1038,4 +1018,281 @@ static void loadStoreMaskBooleanArray(IntFunction fa, } assertArraysEquals(r, a, mask); } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false, "at index #" + j); + } + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanGather(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i, b, i); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i, b, i, vmask); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanScatter(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + } diff --git a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java index c5db8ab1b06..0a7a6ed4ed5 100644 --- a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java @@ -62,8 +62,6 @@ public class Byte64VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - interface FUnOp { byte apply(byte a); } @@ -1008,36 +1006,6 @@ public Object[][] byteUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] byteUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().flatMap(fn -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> BYTE_COMPARE_GENERATORS = List.of( withToString("byte[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4922,122 +4890,6 @@ static void ZOMOMaskedByte64VectorTests(IntFunction fa, - static byte[] gather(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void gatherByte64VectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Byte64VectorTests::gather); - } - static byte[] gatherMasked(byte a[], int ix, boolean[] mask, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "byteUnaryMaskedOpIndexProvider") - static void gatherMaskedByte64VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Byte64VectorTests::gatherMasked); - } - - static byte[] scatter(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void scatterByte64VectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Byte64VectorTests::scatter); - } - - static byte[] scatterMasked(byte r[], byte a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - byte[] oldVal = gather(r, ix, b, iy); - byte[] newVal = new byte[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - byte[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedByte64VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Byte64VectorTests::scatterMasked); - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByte64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/ByteMaxVectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/ByteMaxVectorLoadStoreTests.java index 5660ed05778..203fe85cbe4 100644 --- a/test/jdk/jdk/incubator/vector/ByteMaxVectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/ByteMaxVectorLoadStoreTests.java @@ -46,6 +46,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -54,7 +55,7 @@ public class ByteMaxVectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ByteVector.SPECIES_MAX; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static VectorShape getMaxBit() { return VectorShape.S_Max_BIT; @@ -64,8 +65,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - static void assertArraysEquals(byte[] r, byte[] a, boolean[] mask) { int i = 0; try { @@ -187,25 +186,6 @@ public Object[][] byteMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] byteIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] byteByteBufferProvider() { return BYTE_GENERATORS.stream(). @@ -1047,4 +1027,281 @@ static void loadStoreMaskBooleanArray(IntFunction fa, } assertArraysEquals(r, a, mask); } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (byte) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap, boolean[] mask) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(byte[] r, byte[] a, int[] indexMap) { + byte[] expected = new byte[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + BYTE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + byte[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + byte[] r = new byte[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false, "at index #" + j); + } + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanGather(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i, b, i); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i, b, i, vmask); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanScatter(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ByteVector av = ByteVector.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + } diff --git a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java index 8e4fca80857..5e8e02ea3df 100644 --- a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java @@ -67,8 +67,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - interface FUnOp { byte apply(byte a); } @@ -1013,36 +1011,6 @@ public Object[][] byteUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] byteUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] byteUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - BYTE_GENERATORS.stream().flatMap(fn -> - BYTE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> BYTE_COMPARE_GENERATORS = List.of( withToString("byte[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4927,122 +4895,6 @@ static void ZOMOMaskedByteMaxVectorTests(IntFunction fa, - static byte[] gather(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void gatherByteMaxVectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, ByteMaxVectorTests::gather); - } - static byte[] gatherMasked(byte a[], int ix, boolean[] mask, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "byteUnaryMaskedOpIndexProvider") - static void gatherMaskedByteMaxVectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::gatherMasked); - } - - static byte[] scatter(byte a[], int ix, int[] b, int iy) { - byte[] res = new byte[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "byteUnaryOpIndexProvider") - static void scatterByteMaxVectorTests(IntFunction fa, BiFunction fs) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = new byte[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ByteVector av = ByteVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, ByteMaxVectorTests::scatter); - } - - static byte[] scatterMasked(byte r[], byte a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - byte[] oldVal = gather(r, ix, b, iy); - byte[] newVal = new byte[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - byte[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedByteMaxVectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - byte[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - byte[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::scatterMasked); - } - @Test(dataProvider = "byteCompareOpProvider") static void ltByteMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Double128VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Double128VectorLoadStoreTests.java index fefadd1bba2..28ac74b331f 100644 --- a/test/jdk/jdk/incubator/vector/Double128VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Double128VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.DoubleBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Double128VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = DoubleVector.SPECIES_128; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - static void assertArraysEquals(double[] r, double[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] doubleMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] doubleIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] doubleByteBufferProvider() { return DOUBLE_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Double128VectorTests.java b/test/jdk/jdk/incubator/vector/Double128VectorTests.java index 880b9bab374..22d1799a427 100644 --- a/test/jdk/jdk/incubator/vector/Double128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double128VectorTests.java @@ -62,8 +62,6 @@ public class Double128VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - interface FUnOp { double apply(double a); } @@ -1140,36 +1138,6 @@ public Object[][] doubleUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] doubleUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().flatMap(fn -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> DOUBLE_COMPARE_GENERATORS = List.of( withToString("double[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4494,122 +4462,6 @@ static void SQRTMaskedDouble128VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Double128VectorTests::SQRT); } - static double[] gather(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void gatherDouble128VectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Double128VectorTests::gather); - } - static double[] gatherMasked(double a[], int ix, boolean[] mask, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "doubleUnaryMaskedOpIndexProvider") - static void gatherMaskedDouble128VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Double128VectorTests::gatherMasked); - } - - static double[] scatter(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void scatterDouble128VectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Double128VectorTests::scatter); - } - - static double[] scatterMasked(double r[], double a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - double[] oldVal = gather(r, ix, b, iy); - double[] newVal = new double[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - double[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedDouble128VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Double128VectorTests::scatterMasked); - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Double256VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Double256VectorLoadStoreTests.java index 60de8a747d9..366b3d523f6 100644 --- a/test/jdk/jdk/incubator/vector/Double256VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Double256VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.DoubleBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Double256VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = DoubleVector.SPECIES_256; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - static void assertArraysEquals(double[] r, double[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] doubleMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] doubleIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] doubleByteBufferProvider() { return DOUBLE_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Double256VectorTests.java b/test/jdk/jdk/incubator/vector/Double256VectorTests.java index 7919a57e4c2..ff3be7723ca 100644 --- a/test/jdk/jdk/incubator/vector/Double256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double256VectorTests.java @@ -62,8 +62,6 @@ public class Double256VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - interface FUnOp { double apply(double a); } @@ -1140,36 +1138,6 @@ public Object[][] doubleUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] doubleUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().flatMap(fn -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> DOUBLE_COMPARE_GENERATORS = List.of( withToString("double[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4494,122 +4462,6 @@ static void SQRTMaskedDouble256VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Double256VectorTests::SQRT); } - static double[] gather(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void gatherDouble256VectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Double256VectorTests::gather); - } - static double[] gatherMasked(double a[], int ix, boolean[] mask, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "doubleUnaryMaskedOpIndexProvider") - static void gatherMaskedDouble256VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Double256VectorTests::gatherMasked); - } - - static double[] scatter(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void scatterDouble256VectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Double256VectorTests::scatter); - } - - static double[] scatterMasked(double r[], double a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - double[] oldVal = gather(r, ix, b, iy); - double[] newVal = new double[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - double[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedDouble256VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Double256VectorTests::scatterMasked); - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Double512VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Double512VectorLoadStoreTests.java index a0cba0231d5..8a100b947a7 100644 --- a/test/jdk/jdk/incubator/vector/Double512VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Double512VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.DoubleBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Double512VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = DoubleVector.SPECIES_512; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - static void assertArraysEquals(double[] r, double[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] doubleMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] doubleIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] doubleByteBufferProvider() { return DOUBLE_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Double512VectorTests.java b/test/jdk/jdk/incubator/vector/Double512VectorTests.java index e53714ce294..9af4e20d601 100644 --- a/test/jdk/jdk/incubator/vector/Double512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double512VectorTests.java @@ -62,8 +62,6 @@ public class Double512VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - interface FUnOp { double apply(double a); } @@ -1140,36 +1138,6 @@ public Object[][] doubleUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] doubleUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().flatMap(fn -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> DOUBLE_COMPARE_GENERATORS = List.of( withToString("double[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4494,122 +4462,6 @@ static void SQRTMaskedDouble512VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Double512VectorTests::SQRT); } - static double[] gather(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void gatherDouble512VectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Double512VectorTests::gather); - } - static double[] gatherMasked(double a[], int ix, boolean[] mask, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "doubleUnaryMaskedOpIndexProvider") - static void gatherMaskedDouble512VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Double512VectorTests::gatherMasked); - } - - static double[] scatter(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void scatterDouble512VectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Double512VectorTests::scatter); - } - - static double[] scatterMasked(double r[], double a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - double[] oldVal = gather(r, ix, b, iy); - double[] newVal = new double[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - double[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedDouble512VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Double512VectorTests::scatterMasked); - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Double64VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Double64VectorLoadStoreTests.java index be07de5f63b..7e0883933a7 100644 --- a/test/jdk/jdk/incubator/vector/Double64VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Double64VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.DoubleBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Double64VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = DoubleVector.SPECIES_64; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - static void assertArraysEquals(double[] r, double[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] doubleMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] doubleIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] doubleByteBufferProvider() { return DOUBLE_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Double64VectorTests.java b/test/jdk/jdk/incubator/vector/Double64VectorTests.java index 37c43a119ba..2e05caf6421 100644 --- a/test/jdk/jdk/incubator/vector/Double64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double64VectorTests.java @@ -62,8 +62,6 @@ public class Double64VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - interface FUnOp { double apply(double a); } @@ -1140,36 +1138,6 @@ public Object[][] doubleUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] doubleUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().flatMap(fn -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> DOUBLE_COMPARE_GENERATORS = List.of( withToString("double[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4494,122 +4462,6 @@ static void SQRTMaskedDouble64VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Double64VectorTests::SQRT); } - static double[] gather(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void gatherDouble64VectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Double64VectorTests::gather); - } - static double[] gatherMasked(double a[], int ix, boolean[] mask, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "doubleUnaryMaskedOpIndexProvider") - static void gatherMaskedDouble64VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Double64VectorTests::gatherMasked); - } - - static double[] scatter(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void scatterDouble64VectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Double64VectorTests::scatter); - } - - static double[] scatterMasked(double r[], double a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - double[] oldVal = gather(r, ix, b, iy); - double[] newVal = new double[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - double[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedDouble64VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Double64VectorTests::scatterMasked); - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDouble64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/DoubleMaxVectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/DoubleMaxVectorLoadStoreTests.java index b25ca80efb4..71d8b20eff8 100644 --- a/test/jdk/jdk/incubator/vector/DoubleMaxVectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/DoubleMaxVectorLoadStoreTests.java @@ -47,6 +47,7 @@ import java.nio.DoubleBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -55,7 +56,7 @@ public class DoubleMaxVectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = DoubleVector.SPECIES_MAX; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static VectorShape getMaxBit() { return VectorShape.S_Max_BIT; @@ -65,8 +66,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - static void assertArraysEquals(double[] r, double[] a, boolean[] mask) { int i = 0; try { @@ -198,25 +197,6 @@ public Object[][] doubleMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] doubleIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] doubleByteBufferProvider() { return DOUBLE_GENERATORS.stream(). @@ -971,4 +951,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (double) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap, boolean[] mask) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(double[] r, double[] a, int[] indexMap) { + double[] expected = new double[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + DOUBLE_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + double[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + double[] r = new double[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java index 09189a2b103..ab8787fec09 100644 --- a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java @@ -67,8 +67,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - interface FUnOp { double apply(double a); } @@ -1145,36 +1143,6 @@ public Object[][] doubleUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] doubleUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] doubleUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - DOUBLE_GENERATORS.stream().flatMap(fn -> - DOUBLE_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> DOUBLE_COMPARE_GENERATORS = List.of( withToString("double[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4499,122 +4467,6 @@ static void SQRTMaskedDoubleMaxVectorTests(IntFunction fa, assertArraysEquals(r, a, mask, DoubleMaxVectorTests::SQRT); } - static double[] gather(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void gatherDoubleMaxVectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, DoubleMaxVectorTests::gather); - } - static double[] gatherMasked(double a[], int ix, boolean[] mask, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "doubleUnaryMaskedOpIndexProvider") - static void gatherMaskedDoubleMaxVectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::gatherMasked); - } - - static double[] scatter(double a[], int ix, int[] b, int iy) { - double[] res = new double[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "doubleUnaryOpIndexProvider") - static void scatterDoubleMaxVectorTests(IntFunction fa, BiFunction fs) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = new double[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, DoubleMaxVectorTests::scatter); - } - - static double[] scatterMasked(double r[], double a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - double[] oldVal = gather(r, ix, b, iy); - double[] newVal = new double[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - double[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedDoubleMaxVectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - double[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - double[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::scatterMasked); - } - @Test(dataProvider = "doubleCompareOpProvider") static void ltDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Float128VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Float128VectorLoadStoreTests.java index 4480f7db190..7be10f051f6 100644 --- a/test/jdk/jdk/incubator/vector/Float128VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Float128VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.FloatBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Float128VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = FloatVector.SPECIES_128; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - static void assertArraysEquals(float[] r, float[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] floatMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] floatIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] floatByteBufferProvider() { return FLOAT_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Float128VectorTests.java b/test/jdk/jdk/incubator/vector/Float128VectorTests.java index 30ebec15bea..cb4fc673802 100644 --- a/test/jdk/jdk/incubator/vector/Float128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float128VectorTests.java @@ -62,8 +62,6 @@ public class Float128VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - interface FUnOp { float apply(float a); } @@ -1150,36 +1148,6 @@ public Object[][] floatUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] floatUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().flatMap(fn -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> FLOAT_COMPARE_GENERATORS = List.of( withToString("float[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4462,122 +4430,6 @@ static void SQRTMaskedFloat128VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Float128VectorTests::SQRT); } - static float[] gather(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void gatherFloat128VectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Float128VectorTests::gather); - } - static float[] gatherMasked(float a[], int ix, boolean[] mask, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "floatUnaryMaskedOpIndexProvider") - static void gatherMaskedFloat128VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Float128VectorTests::gatherMasked); - } - - static float[] scatter(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void scatterFloat128VectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Float128VectorTests::scatter); - } - - static float[] scatterMasked(float r[], float a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - float[] oldVal = gather(r, ix, b, iy); - float[] newVal = new float[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - float[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedFloat128VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Float128VectorTests::scatterMasked); - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloat128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Float256VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Float256VectorLoadStoreTests.java index a9d08982f42..a7b53dd1ac7 100644 --- a/test/jdk/jdk/incubator/vector/Float256VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Float256VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.FloatBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Float256VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = FloatVector.SPECIES_256; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - static void assertArraysEquals(float[] r, float[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] floatMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] floatIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] floatByteBufferProvider() { return FLOAT_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Float256VectorTests.java b/test/jdk/jdk/incubator/vector/Float256VectorTests.java index 2f4beda5c93..fbe27a2e47a 100644 --- a/test/jdk/jdk/incubator/vector/Float256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float256VectorTests.java @@ -62,8 +62,6 @@ public class Float256VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - interface FUnOp { float apply(float a); } @@ -1150,36 +1148,6 @@ public Object[][] floatUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] floatUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().flatMap(fn -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> FLOAT_COMPARE_GENERATORS = List.of( withToString("float[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4462,122 +4430,6 @@ static void SQRTMaskedFloat256VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Float256VectorTests::SQRT); } - static float[] gather(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void gatherFloat256VectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Float256VectorTests::gather); - } - static float[] gatherMasked(float a[], int ix, boolean[] mask, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "floatUnaryMaskedOpIndexProvider") - static void gatherMaskedFloat256VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Float256VectorTests::gatherMasked); - } - - static float[] scatter(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void scatterFloat256VectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Float256VectorTests::scatter); - } - - static float[] scatterMasked(float r[], float a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - float[] oldVal = gather(r, ix, b, iy); - float[] newVal = new float[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - float[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedFloat256VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Float256VectorTests::scatterMasked); - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloat256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Float512VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Float512VectorLoadStoreTests.java index 49a4af21578..67d12a11c3d 100644 --- a/test/jdk/jdk/incubator/vector/Float512VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Float512VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.FloatBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Float512VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = FloatVector.SPECIES_512; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - static void assertArraysEquals(float[] r, float[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] floatMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] floatIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] floatByteBufferProvider() { return FLOAT_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Float512VectorTests.java b/test/jdk/jdk/incubator/vector/Float512VectorTests.java index 3f2fbf8455d..599145bd63d 100644 --- a/test/jdk/jdk/incubator/vector/Float512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float512VectorTests.java @@ -62,8 +62,6 @@ public class Float512VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - interface FUnOp { float apply(float a); } @@ -1150,36 +1148,6 @@ public Object[][] floatUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] floatUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().flatMap(fn -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> FLOAT_COMPARE_GENERATORS = List.of( withToString("float[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4462,122 +4430,6 @@ static void SQRTMaskedFloat512VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Float512VectorTests::SQRT); } - static float[] gather(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void gatherFloat512VectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Float512VectorTests::gather); - } - static float[] gatherMasked(float a[], int ix, boolean[] mask, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "floatUnaryMaskedOpIndexProvider") - static void gatherMaskedFloat512VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Float512VectorTests::gatherMasked); - } - - static float[] scatter(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void scatterFloat512VectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Float512VectorTests::scatter); - } - - static float[] scatterMasked(float r[], float a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - float[] oldVal = gather(r, ix, b, iy); - float[] newVal = new float[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - float[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedFloat512VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Float512VectorTests::scatterMasked); - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloat512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Float64VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Float64VectorLoadStoreTests.java index d4cebe5dd07..2993195195f 100644 --- a/test/jdk/jdk/incubator/vector/Float64VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Float64VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.FloatBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Float64VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = FloatVector.SPECIES_64; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - static void assertArraysEquals(float[] r, float[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] floatMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] floatIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] floatByteBufferProvider() { return FLOAT_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Float64VectorTests.java b/test/jdk/jdk/incubator/vector/Float64VectorTests.java index 3e30005710f..0d82853a62d 100644 --- a/test/jdk/jdk/incubator/vector/Float64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float64VectorTests.java @@ -62,8 +62,6 @@ public class Float64VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - interface FUnOp { float apply(float a); } @@ -1150,36 +1148,6 @@ public Object[][] floatUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] floatUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().flatMap(fn -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> FLOAT_COMPARE_GENERATORS = List.of( withToString("float[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4462,122 +4430,6 @@ static void SQRTMaskedFloat64VectorTests(IntFunction fa, assertArraysEquals(r, a, mask, Float64VectorTests::SQRT); } - static float[] gather(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void gatherFloat64VectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Float64VectorTests::gather); - } - static float[] gatherMasked(float a[], int ix, boolean[] mask, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "floatUnaryMaskedOpIndexProvider") - static void gatherMaskedFloat64VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Float64VectorTests::gatherMasked); - } - - static float[] scatter(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void scatterFloat64VectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Float64VectorTests::scatter); - } - - static float[] scatterMasked(float r[], float a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - float[] oldVal = gather(r, ix, b, iy); - float[] newVal = new float[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - float[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedFloat64VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Float64VectorTests::scatterMasked); - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloat64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/FloatMaxVectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/FloatMaxVectorLoadStoreTests.java index 442ebbfc185..2bd9b13ea5f 100644 --- a/test/jdk/jdk/incubator/vector/FloatMaxVectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/FloatMaxVectorLoadStoreTests.java @@ -47,6 +47,7 @@ import java.nio.FloatBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -55,7 +56,7 @@ public class FloatMaxVectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = FloatVector.SPECIES_MAX; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static VectorShape getMaxBit() { return VectorShape.S_Max_BIT; @@ -65,8 +66,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - static void assertArraysEquals(float[] r, float[] a, boolean[] mask) { int i = 0; try { @@ -198,25 +197,6 @@ public Object[][] floatMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] floatIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] floatByteBufferProvider() { return FLOAT_GENERATORS.stream(). @@ -971,4 +951,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (float) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap, boolean[] mask) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(float[] r, float[] a, int[] indexMap) { + float[] expected = new float[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + FLOAT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + float[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + float[] r = new float[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + FloatVector av = FloatVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java index 1563496bac3..88d60d1fe72 100644 --- a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java @@ -67,8 +67,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - interface FUnOp { float apply(float a); } @@ -1155,36 +1153,6 @@ public Object[][] floatUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] floatUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] floatUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - FLOAT_GENERATORS.stream().flatMap(fn -> - FLOAT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> FLOAT_COMPARE_GENERATORS = List.of( withToString("float[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4467,122 +4435,6 @@ static void SQRTMaskedFloatMaxVectorTests(IntFunction fa, assertArraysEquals(r, a, mask, FloatMaxVectorTests::SQRT); } - static float[] gather(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void gatherFloatMaxVectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, FloatMaxVectorTests::gather); - } - static float[] gatherMasked(float a[], int ix, boolean[] mask, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "floatUnaryMaskedOpIndexProvider") - static void gatherMaskedFloatMaxVectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, FloatMaxVectorTests::gatherMasked); - } - - static float[] scatter(float a[], int ix, int[] b, int iy) { - float[] res = new float[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "floatUnaryOpIndexProvider") - static void scatterFloatMaxVectorTests(IntFunction fa, BiFunction fs) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = new float[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, FloatMaxVectorTests::scatter); - } - - static float[] scatterMasked(float r[], float a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - float[] oldVal = gather(r, ix, b, iy); - float[] newVal = new float[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - float[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedFloatMaxVectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - float[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - float[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask vmask = VectorMask.fromArray(SPECIES, mask, 0); - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - FloatVector av = FloatVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, FloatMaxVectorTests::scatterMasked); - } - @Test(dataProvider = "floatCompareOpProvider") static void ltFloatMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Int128VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Int128VectorLoadStoreTests.java index b902681a3b0..afebe565a65 100644 --- a/test/jdk/jdk/incubator/vector/Int128VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Int128VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.IntBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Int128VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = IntVector.SPECIES_128; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - static void assertArraysEquals(int[] r, int[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] intMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] intIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] intByteBufferProvider() { return INT_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Int128VectorTests.java b/test/jdk/jdk/incubator/vector/Int128VectorTests.java index 2f6437c806d..e991e9fa73c 100644 --- a/test/jdk/jdk/incubator/vector/Int128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int128VectorTests.java @@ -62,8 +62,6 @@ public class Int128VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - interface FUnOp { int apply(int a); } @@ -968,36 +966,6 @@ public Object[][] intUnaryOpShuffleMaskProvider() { } - @DataProvider - public Object[][] intUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().flatMap(fn -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> INT_COMPARE_GENERATORS = List.of( withToString("int[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4887,122 +4855,6 @@ static void ZOMOMaskedInt128VectorTests(IntFunction fa, - static int[] gather(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void gatherInt128VectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Int128VectorTests::gather); - } - static int[] gatherMasked(int a[], int ix, boolean[] mask, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "intUnaryMaskedOpIndexProvider") - static void gatherMaskedInt128VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Int128VectorTests::gatherMasked); - } - - static int[] scatter(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void scatterInt128VectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Int128VectorTests::scatter); - } - - static int[] scatterMasked(int r[], int a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - int[] oldVal = gather(r, ix, b, iy); - int[] newVal = new int[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - int[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedInt128VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Int128VectorTests::scatterMasked); - } - @Test(dataProvider = "intCompareOpProvider") static void ltInt128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Int256VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Int256VectorLoadStoreTests.java index 3297ab9dece..1bb1e992aea 100644 --- a/test/jdk/jdk/incubator/vector/Int256VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Int256VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.IntBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Int256VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = IntVector.SPECIES_256; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - static void assertArraysEquals(int[] r, int[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] intMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] intIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] intByteBufferProvider() { return INT_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Int256VectorTests.java b/test/jdk/jdk/incubator/vector/Int256VectorTests.java index 45dad70dbf5..13f3b43ce7e 100644 --- a/test/jdk/jdk/incubator/vector/Int256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int256VectorTests.java @@ -62,8 +62,6 @@ public class Int256VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - interface FUnOp { int apply(int a); } @@ -968,36 +966,6 @@ public Object[][] intUnaryOpShuffleMaskProvider() { } - @DataProvider - public Object[][] intUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().flatMap(fn -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> INT_COMPARE_GENERATORS = List.of( withToString("int[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4887,122 +4855,6 @@ static void ZOMOMaskedInt256VectorTests(IntFunction fa, - static int[] gather(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void gatherInt256VectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Int256VectorTests::gather); - } - static int[] gatherMasked(int a[], int ix, boolean[] mask, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "intUnaryMaskedOpIndexProvider") - static void gatherMaskedInt256VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Int256VectorTests::gatherMasked); - } - - static int[] scatter(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void scatterInt256VectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Int256VectorTests::scatter); - } - - static int[] scatterMasked(int r[], int a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - int[] oldVal = gather(r, ix, b, iy); - int[] newVal = new int[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - int[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedInt256VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Int256VectorTests::scatterMasked); - } - @Test(dataProvider = "intCompareOpProvider") static void ltInt256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Int512VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Int512VectorLoadStoreTests.java index 8363c3d0bb3..4ecce9322a4 100644 --- a/test/jdk/jdk/incubator/vector/Int512VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Int512VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.IntBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Int512VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = IntVector.SPECIES_512; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - static void assertArraysEquals(int[] r, int[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] intMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] intIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] intByteBufferProvider() { return INT_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Int512VectorTests.java b/test/jdk/jdk/incubator/vector/Int512VectorTests.java index 66eab1a77d6..318e1ccf17d 100644 --- a/test/jdk/jdk/incubator/vector/Int512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int512VectorTests.java @@ -62,8 +62,6 @@ public class Int512VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - interface FUnOp { int apply(int a); } @@ -968,36 +966,6 @@ public Object[][] intUnaryOpShuffleMaskProvider() { } - @DataProvider - public Object[][] intUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().flatMap(fn -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> INT_COMPARE_GENERATORS = List.of( withToString("int[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4887,122 +4855,6 @@ static void ZOMOMaskedInt512VectorTests(IntFunction fa, - static int[] gather(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void gatherInt512VectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Int512VectorTests::gather); - } - static int[] gatherMasked(int a[], int ix, boolean[] mask, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "intUnaryMaskedOpIndexProvider") - static void gatherMaskedInt512VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Int512VectorTests::gatherMasked); - } - - static int[] scatter(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void scatterInt512VectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Int512VectorTests::scatter); - } - - static int[] scatterMasked(int r[], int a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - int[] oldVal = gather(r, ix, b, iy); - int[] newVal = new int[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - int[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedInt512VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Int512VectorTests::scatterMasked); - } - @Test(dataProvider = "intCompareOpProvider") static void ltInt512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Int64VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Int64VectorLoadStoreTests.java index 3d8aa86eef8..6122a398519 100644 --- a/test/jdk/jdk/incubator/vector/Int64VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Int64VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.IntBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Int64VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = IntVector.SPECIES_64; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - static void assertArraysEquals(int[] r, int[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] intMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] intIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] intByteBufferProvider() { return INT_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Int64VectorTests.java b/test/jdk/jdk/incubator/vector/Int64VectorTests.java index 43e796cdc18..87456e78857 100644 --- a/test/jdk/jdk/incubator/vector/Int64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int64VectorTests.java @@ -62,8 +62,6 @@ public class Int64VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - interface FUnOp { int apply(int a); } @@ -968,36 +966,6 @@ public Object[][] intUnaryOpShuffleMaskProvider() { } - @DataProvider - public Object[][] intUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().flatMap(fn -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> INT_COMPARE_GENERATORS = List.of( withToString("int[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4887,122 +4855,6 @@ static void ZOMOMaskedInt64VectorTests(IntFunction fa, - static int[] gather(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void gatherInt64VectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Int64VectorTests::gather); - } - static int[] gatherMasked(int a[], int ix, boolean[] mask, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "intUnaryMaskedOpIndexProvider") - static void gatherMaskedInt64VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Int64VectorTests::gatherMasked); - } - - static int[] scatter(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void scatterInt64VectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Int64VectorTests::scatter); - } - - static int[] scatterMasked(int r[], int a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - int[] oldVal = gather(r, ix, b, iy); - int[] newVal = new int[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - int[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedInt64VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Int64VectorTests::scatterMasked); - } - @Test(dataProvider = "intCompareOpProvider") static void ltInt64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/IntMaxVectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/IntMaxVectorLoadStoreTests.java index 837ca50a0e0..db2840a947a 100644 --- a/test/jdk/jdk/incubator/vector/IntMaxVectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/IntMaxVectorLoadStoreTests.java @@ -47,6 +47,7 @@ import java.nio.IntBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -55,7 +56,7 @@ public class IntMaxVectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = IntVector.SPECIES_MAX; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static VectorShape getMaxBit() { return VectorShape.S_Max_BIT; @@ -65,8 +66,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - static void assertArraysEquals(int[] r, int[] a, boolean[] mask) { int i = 0; try { @@ -198,25 +197,6 @@ public Object[][] intMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] intIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] intByteBufferProvider() { return INT_GENERATORS.stream(). @@ -971,4 +951,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (int) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap, boolean[] mask) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(int[] r, int[] a, int[] indexMap) { + int[] expected = new int[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + INT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + int[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + int[] r = new int[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java index 345bbda2db3..24f5b8b64df 100644 --- a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java @@ -67,8 +67,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - interface FUnOp { int apply(int a); } @@ -973,36 +971,6 @@ public Object[][] intUnaryOpShuffleMaskProvider() { } - @DataProvider - public Object[][] intUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] intUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - INT_GENERATORS.stream().flatMap(fn -> - INT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> INT_COMPARE_GENERATORS = List.of( withToString("int[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4892,122 +4860,6 @@ static void ZOMOMaskedIntMaxVectorTests(IntFunction fa, - static int[] gather(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void gatherIntMaxVectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, IntMaxVectorTests::gather); - } - static int[] gatherMasked(int a[], int ix, boolean[] mask, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "intUnaryMaskedOpIndexProvider") - static void gatherMaskedIntMaxVectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, IntMaxVectorTests::gatherMasked); - } - - static int[] scatter(int a[], int ix, int[] b, int iy) { - int[] res = new int[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "intUnaryOpIndexProvider") - static void scatterIntMaxVectorTests(IntFunction fa, BiFunction fs) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = new int[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, IntMaxVectorTests::scatter); - } - - static int[] scatterMasked(int r[], int a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - int[] oldVal = gather(r, ix, b, iy); - int[] newVal = new int[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - int[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedIntMaxVectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - int[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - int[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, IntMaxVectorTests::scatterMasked); - } - @Test(dataProvider = "intCompareOpProvider") static void ltIntMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Long128VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Long128VectorLoadStoreTests.java index 3de5e668849..4d3775530c8 100644 --- a/test/jdk/jdk/incubator/vector/Long128VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Long128VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.LongBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Long128VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = LongVector.SPECIES_128; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - static void assertArraysEquals(long[] r, long[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] longMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] longIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] longByteBufferProvider() { return LONG_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Long128VectorTests.java b/test/jdk/jdk/incubator/vector/Long128VectorTests.java index a43ae55535f..7ec1bfb340f 100644 --- a/test/jdk/jdk/incubator/vector/Long128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long128VectorTests.java @@ -62,8 +62,6 @@ public class Long128VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - interface FUnOp { long apply(long a); } @@ -994,36 +992,6 @@ public Object[][] longUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] longUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().flatMap(fn -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> LONG_COMPARE_GENERATORS = List.of( withToString("long[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4837,122 +4805,6 @@ static void ZOMOMaskedLong128VectorTests(IntFunction fa, - static long[] gather(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void gatherLong128VectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Long128VectorTests::gather); - } - static long[] gatherMasked(long a[], int ix, boolean[] mask, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "longUnaryMaskedOpIndexProvider") - static void gatherMaskedLong128VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Long128VectorTests::gatherMasked); - } - - static long[] scatter(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void scatterLong128VectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Long128VectorTests::scatter); - } - - static long[] scatterMasked(long r[], long a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - long[] oldVal = gather(r, ix, b, iy); - long[] newVal = new long[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - long[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedLong128VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Long128VectorTests::scatterMasked); - } - @Test(dataProvider = "longCompareOpProvider") static void ltLong128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Long256VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Long256VectorLoadStoreTests.java index b6f00c569aa..107c5826e69 100644 --- a/test/jdk/jdk/incubator/vector/Long256VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Long256VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.LongBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Long256VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = LongVector.SPECIES_256; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - static void assertArraysEquals(long[] r, long[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] longMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] longIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] longByteBufferProvider() { return LONG_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Long256VectorTests.java b/test/jdk/jdk/incubator/vector/Long256VectorTests.java index b9ca9e09d8f..9ef54fa5ad1 100644 --- a/test/jdk/jdk/incubator/vector/Long256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long256VectorTests.java @@ -62,8 +62,6 @@ public class Long256VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - interface FUnOp { long apply(long a); } @@ -994,36 +992,6 @@ public Object[][] longUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] longUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().flatMap(fn -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> LONG_COMPARE_GENERATORS = List.of( withToString("long[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4837,122 +4805,6 @@ static void ZOMOMaskedLong256VectorTests(IntFunction fa, - static long[] gather(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void gatherLong256VectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Long256VectorTests::gather); - } - static long[] gatherMasked(long a[], int ix, boolean[] mask, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "longUnaryMaskedOpIndexProvider") - static void gatherMaskedLong256VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Long256VectorTests::gatherMasked); - } - - static long[] scatter(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void scatterLong256VectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Long256VectorTests::scatter); - } - - static long[] scatterMasked(long r[], long a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - long[] oldVal = gather(r, ix, b, iy); - long[] newVal = new long[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - long[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedLong256VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Long256VectorTests::scatterMasked); - } - @Test(dataProvider = "longCompareOpProvider") static void ltLong256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Long512VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Long512VectorLoadStoreTests.java index f41d247208e..77a692f8d09 100644 --- a/test/jdk/jdk/incubator/vector/Long512VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Long512VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.LongBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Long512VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = LongVector.SPECIES_512; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - static void assertArraysEquals(long[] r, long[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] longMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] longIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] longByteBufferProvider() { return LONG_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Long512VectorTests.java b/test/jdk/jdk/incubator/vector/Long512VectorTests.java index 4988b87e915..e4e008c1acd 100644 --- a/test/jdk/jdk/incubator/vector/Long512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long512VectorTests.java @@ -62,8 +62,6 @@ public class Long512VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - interface FUnOp { long apply(long a); } @@ -994,36 +992,6 @@ public Object[][] longUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] longUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().flatMap(fn -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> LONG_COMPARE_GENERATORS = List.of( withToString("long[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4837,122 +4805,6 @@ static void ZOMOMaskedLong512VectorTests(IntFunction fa, - static long[] gather(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void gatherLong512VectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Long512VectorTests::gather); - } - static long[] gatherMasked(long a[], int ix, boolean[] mask, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "longUnaryMaskedOpIndexProvider") - static void gatherMaskedLong512VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Long512VectorTests::gatherMasked); - } - - static long[] scatter(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void scatterLong512VectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Long512VectorTests::scatter); - } - - static long[] scatterMasked(long r[], long a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - long[] oldVal = gather(r, ix, b, iy); - long[] newVal = new long[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - long[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedLong512VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Long512VectorTests::scatterMasked); - } - @Test(dataProvider = "longCompareOpProvider") static void ltLong512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Long64VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Long64VectorLoadStoreTests.java index 594dfdd7cd8..f1735b3e87d 100644 --- a/test/jdk/jdk/incubator/vector/Long64VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Long64VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.LongBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Long64VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = LongVector.SPECIES_64; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - static void assertArraysEquals(long[] r, long[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] longMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] longIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] longByteBufferProvider() { return LONG_GENERATORS.stream(). @@ -962,4 +942,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/Long64VectorTests.java b/test/jdk/jdk/incubator/vector/Long64VectorTests.java index abb903b031d..1bf9a24bce2 100644 --- a/test/jdk/jdk/incubator/vector/Long64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long64VectorTests.java @@ -62,8 +62,6 @@ public class Long64VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - interface FUnOp { long apply(long a); } @@ -994,36 +992,6 @@ public Object[][] longUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] longUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().flatMap(fn -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> LONG_COMPARE_GENERATORS = List.of( withToString("long[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4837,122 +4805,6 @@ static void ZOMOMaskedLong64VectorTests(IntFunction fa, - static long[] gather(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void gatherLong64VectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Long64VectorTests::gather); - } - static long[] gatherMasked(long a[], int ix, boolean[] mask, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "longUnaryMaskedOpIndexProvider") - static void gatherMaskedLong64VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Long64VectorTests::gatherMasked); - } - - static long[] scatter(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void scatterLong64VectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Long64VectorTests::scatter); - } - - static long[] scatterMasked(long r[], long a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - long[] oldVal = gather(r, ix, b, iy); - long[] newVal = new long[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - long[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedLong64VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Long64VectorTests::scatterMasked); - } - @Test(dataProvider = "longCompareOpProvider") static void ltLong64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/LongMaxVectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/LongMaxVectorLoadStoreTests.java index 341fdd0c5dd..4e7bfb3dcc4 100644 --- a/test/jdk/jdk/incubator/vector/LongMaxVectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/LongMaxVectorLoadStoreTests.java @@ -47,6 +47,7 @@ import java.nio.LongBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -55,7 +56,7 @@ public class LongMaxVectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = LongVector.SPECIES_MAX; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static VectorShape getMaxBit() { return VectorShape.S_Max_BIT; @@ -65,8 +66,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - static void assertArraysEquals(long[] r, long[] a, boolean[] mask) { int i = 0; try { @@ -198,25 +197,6 @@ public Object[][] longMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] longIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] longByteBufferProvider() { return LONG_GENERATORS.stream(). @@ -971,4 +951,156 @@ static void loadStoreShuffle() { + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (long) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap, boolean[] mask) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(long[] r, long[] a, int[] indexMap) { + long[] expected = new long[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + LONG_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + long[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + long[] r = new long[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + + } diff --git a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java index 31b089e522c..fc18a81a8d7 100644 --- a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java @@ -67,8 +67,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - interface FUnOp { long apply(long a); } @@ -999,36 +997,6 @@ public Object[][] longUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] longUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] longUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - LONG_GENERATORS.stream().flatMap(fn -> - LONG_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> LONG_COMPARE_GENERATORS = List.of( withToString("long[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4842,122 +4810,6 @@ static void ZOMOMaskedLongMaxVectorTests(IntFunction fa, - static long[] gather(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void gatherLongMaxVectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, LongMaxVectorTests::gather); - } - static long[] gatherMasked(long a[], int ix, boolean[] mask, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "longUnaryMaskedOpIndexProvider") - static void gatherMaskedLongMaxVectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, LongMaxVectorTests::gatherMasked); - } - - static long[] scatter(long a[], int ix, int[] b, int iy) { - long[] res = new long[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "longUnaryOpIndexProvider") - static void scatterLongMaxVectorTests(IntFunction fa, BiFunction fs) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = new long[a.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); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, LongMaxVectorTests::scatter); - } - - static long[] scatterMasked(long r[], long a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - long[] oldVal = gather(r, ix, b, iy); - long[] newVal = new long[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - long[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedLongMaxVectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - long[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - long[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, LongMaxVectorTests::scatterMasked); - } - @Test(dataProvider = "longCompareOpProvider") static void ltLongMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Short128VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Short128VectorLoadStoreTests.java index c37355e4f51..c1cc783242e 100644 --- a/test/jdk/jdk/incubator/vector/Short128VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Short128VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.ShortBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Short128VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ShortVector.SPECIES_128; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - static void assertArraysEquals(short[] r, short[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] shortMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] shortIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] shortByteBufferProvider() { return SHORT_GENERATORS.stream(). @@ -1206,4 +1186,301 @@ static void storeCharArrayMaskIOOBE(IntFunction fa, IntFunction } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] charGatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] charGatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "charGatherScatterProvider") + static void charGather(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i, b, i); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i, b, i, vmask); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "charGatherScatterProvider") + static void charScatter(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + } diff --git a/test/jdk/jdk/incubator/vector/Short128VectorTests.java b/test/jdk/jdk/incubator/vector/Short128VectorTests.java index fb7ff14fe77..d1dc6b9b4ee 100644 --- a/test/jdk/jdk/incubator/vector/Short128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short128VectorTests.java @@ -62,8 +62,6 @@ public class Short128VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8)); - interface FUnOp { short apply(short a); } @@ -998,36 +996,6 @@ public Object[][] shortUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] shortUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().flatMap(fn -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> SHORT_COMPARE_GENERATORS = List.of( withToString("short[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4912,122 +4880,6 @@ static void ZOMOMaskedShort128VectorTests(IntFunction fa, - static short[] gather(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void gatherShort128VectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Short128VectorTests::gather); - } - static short[] gatherMasked(short a[], int ix, boolean[] mask, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "shortUnaryMaskedOpIndexProvider") - static void gatherMaskedShort128VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Short128VectorTests::gatherMasked); - } - - static short[] scatter(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void scatterShort128VectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Short128VectorTests::scatter); - } - - static short[] scatterMasked(short r[], short a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - short[] oldVal = gather(r, ix, b, iy); - short[] newVal = new short[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - short[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedShort128VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Short128VectorTests::scatterMasked); - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShort128VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Short256VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Short256VectorLoadStoreTests.java index 76aa919f583..164156bd94b 100644 --- a/test/jdk/jdk/incubator/vector/Short256VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Short256VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.ShortBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Short256VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ShortVector.SPECIES_256; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - static void assertArraysEquals(short[] r, short[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] shortMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] shortIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] shortByteBufferProvider() { return SHORT_GENERATORS.stream(). @@ -1206,4 +1186,301 @@ static void storeCharArrayMaskIOOBE(IntFunction fa, IntFunction } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] charGatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] charGatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "charGatherScatterProvider") + static void charGather(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i, b, i); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i, b, i, vmask); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "charGatherScatterProvider") + static void charScatter(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + } diff --git a/test/jdk/jdk/incubator/vector/Short256VectorTests.java b/test/jdk/jdk/incubator/vector/Short256VectorTests.java index a83cf81ca07..51a47225af6 100644 --- a/test/jdk/jdk/incubator/vector/Short256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short256VectorTests.java @@ -62,8 +62,6 @@ public class Short256VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); - interface FUnOp { short apply(short a); } @@ -998,36 +996,6 @@ public Object[][] shortUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] shortUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().flatMap(fn -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> SHORT_COMPARE_GENERATORS = List.of( withToString("short[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4912,122 +4880,6 @@ static void ZOMOMaskedShort256VectorTests(IntFunction fa, - static short[] gather(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void gatherShort256VectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Short256VectorTests::gather); - } - static short[] gatherMasked(short a[], int ix, boolean[] mask, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "shortUnaryMaskedOpIndexProvider") - static void gatherMaskedShort256VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Short256VectorTests::gatherMasked); - } - - static short[] scatter(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void scatterShort256VectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Short256VectorTests::scatter); - } - - static short[] scatterMasked(short r[], short a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - short[] oldVal = gather(r, ix, b, iy); - short[] newVal = new short[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - short[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedShort256VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Short256VectorTests::scatterMasked); - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShort256VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Short512VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Short512VectorLoadStoreTests.java index 3da5ca3f9bd..5fb455e5881 100644 --- a/test/jdk/jdk/incubator/vector/Short512VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Short512VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.ShortBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Short512VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ShortVector.SPECIES_512; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - static void assertArraysEquals(short[] r, short[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] shortMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] shortIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] shortByteBufferProvider() { return SHORT_GENERATORS.stream(). @@ -1206,4 +1186,301 @@ static void storeCharArrayMaskIOOBE(IntFunction fa, IntFunction } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] charGatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] charGatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "charGatherScatterProvider") + static void charGather(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i, b, i); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i, b, i, vmask); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "charGatherScatterProvider") + static void charScatter(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + } diff --git a/test/jdk/jdk/incubator/vector/Short512VectorTests.java b/test/jdk/jdk/incubator/vector/Short512VectorTests.java index 8313eb16e66..05d3d8059e2 100644 --- a/test/jdk/jdk/incubator/vector/Short512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short512VectorTests.java @@ -62,8 +62,6 @@ public class Short512VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8)); - interface FUnOp { short apply(short a); } @@ -998,36 +996,6 @@ public Object[][] shortUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] shortUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().flatMap(fn -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> SHORT_COMPARE_GENERATORS = List.of( withToString("short[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4912,122 +4880,6 @@ static void ZOMOMaskedShort512VectorTests(IntFunction fa, - static short[] gather(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void gatherShort512VectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Short512VectorTests::gather); - } - static short[] gatherMasked(short a[], int ix, boolean[] mask, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "shortUnaryMaskedOpIndexProvider") - static void gatherMaskedShort512VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Short512VectorTests::gatherMasked); - } - - static short[] scatter(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void scatterShort512VectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Short512VectorTests::scatter); - } - - static short[] scatterMasked(short r[], short a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - short[] oldVal = gather(r, ix, b, iy); - short[] newVal = new short[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - short[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedShort512VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Short512VectorTests::scatterMasked); - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShort512VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/Short64VectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/Short64VectorLoadStoreTests.java index 24a9d1a1f45..9df0a192a29 100644 --- a/test/jdk/jdk/incubator/vector/Short64VectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/Short64VectorLoadStoreTests.java @@ -43,6 +43,7 @@ import java.nio.ShortBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -51,13 +52,11 @@ public class Short64VectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ShortVector.SPECIES_64; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - static void assertArraysEquals(short[] r, short[] a, boolean[] mask) { int i = 0; try { @@ -189,25 +188,6 @@ public Object[][] shortMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] shortIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] shortByteBufferProvider() { return SHORT_GENERATORS.stream(). @@ -1206,4 +1186,301 @@ static void storeCharArrayMaskIOOBE(IntFunction fa, IntFunction } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] charGatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] charGatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "charGatherScatterProvider") + static void charGather(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i, b, i); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i, b, i, vmask); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "charGatherScatterProvider") + static void charScatter(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + } diff --git a/test/jdk/jdk/incubator/vector/Short64VectorTests.java b/test/jdk/jdk/incubator/vector/Short64VectorTests.java index cadee84f5cc..5cc7f66cb1f 100644 --- a/test/jdk/jdk/incubator/vector/Short64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short64VectorTests.java @@ -62,8 +62,6 @@ public class Short64VectorTests extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (64 / 8)); - interface FUnOp { short apply(short a); } @@ -998,36 +996,6 @@ public Object[][] shortUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] shortUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().flatMap(fn -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> SHORT_COMPARE_GENERATORS = List.of( withToString("short[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4912,122 +4880,6 @@ static void ZOMOMaskedShort64VectorTests(IntFunction fa, - static short[] gather(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void gatherShort64VectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, Short64VectorTests::gather); - } - static short[] gatherMasked(short a[], int ix, boolean[] mask, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "shortUnaryMaskedOpIndexProvider") - static void gatherMaskedShort64VectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, Short64VectorTests::gatherMasked); - } - - static short[] scatter(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void scatterShort64VectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, Short64VectorTests::scatter); - } - - static short[] scatterMasked(short r[], short a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - short[] oldVal = gather(r, ix, b, iy); - short[] newVal = new short[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - short[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedShort64VectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, Short64VectorTests::scatterMasked); - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShort64VectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/ShortMaxVectorLoadStoreTests.java b/test/jdk/jdk/incubator/vector/ShortMaxVectorLoadStoreTests.java index 7b34a74c602..0fc39b17f72 100644 --- a/test/jdk/jdk/incubator/vector/ShortMaxVectorLoadStoreTests.java +++ b/test/jdk/jdk/incubator/vector/ShortMaxVectorLoadStoreTests.java @@ -47,6 +47,7 @@ import java.nio.ShortBuffer; import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -55,7 +56,7 @@ public class ShortMaxVectorLoadStoreTests extends AbstractVectorTest { static final VectorSpecies SPECIES = ShortVector.SPECIES_MAX; - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static VectorShape getMaxBit() { return VectorShape.S_Max_BIT; @@ -65,8 +66,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - static void assertArraysEquals(short[] r, short[] a, boolean[] mask) { int i = 0; try { @@ -198,25 +197,6 @@ public Object[][] shortMaskProviderForIOOBE() { toArray(Object[][]::new); } - @DataProvider - public Object[][] shortIndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortIndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] shortByteBufferProvider() { return SHORT_GENERATORS.stream(). @@ -1215,4 +1195,301 @@ static void storeCharArrayMaskIOOBE(IntFunction fa, IntFunction } + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (short) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap, boolean[] mask) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(short[] r, short[] a, int[] indexMap) { + short[] expected = new short[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + SHORT_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction fa, BiFunction fs) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromArray(SPECIES, a, i); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + short[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + short[] r = new short[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] charGatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] charGatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "charGatherScatterProvider") + static void charGather(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i, b, i); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i, b, i, vmask); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "charGatherScatterProvider") + static void charScatter(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + ShortVector av = ShortVector.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.apply(SPECIES.length()); + VectorMask 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.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + + } diff --git a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java index ad3008a536d..731b69fcaea 100644 --- a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java @@ -67,8 +67,6 @@ static VectorShape getMaxBit() { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); - interface FUnOp { short apply(short a); } @@ -1003,36 +1001,6 @@ public Object[][] shortUnaryOpSelectFromMaskProvider() { } - @DataProvider - public Object[][] shortUnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] shortUnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - SHORT_GENERATORS.stream().flatMap(fn -> - SHORT_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> SHORT_COMPARE_GENERATORS = List.of( withToString("short[i]", (int s) -> { return fill(s * BUFFER_REPS, @@ -4917,122 +4885,6 @@ static void ZOMOMaskedShortMaxVectorTests(IntFunction fa, - static short[] gather(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void gatherShortMaxVectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.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, b, i); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, ShortMaxVectorTests::gather); - } - static short[] gatherMasked(short a[], int ix, boolean[] mask, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "shortUnaryMaskedOpIndexProvider") - static void gatherMaskedShortMaxVectorTests(IntFunction fa, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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, b, i, vmask); - av.intoArray(r, i); - } - } - - assertArraysEquals(r, a, b, mask, ShortMaxVectorTests::gatherMasked); - } - - static short[] scatter(short a[], int ix, int[] b, int iy) { - short[] res = new short[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "shortUnaryOpIndexProvider") - static void scatterShortMaxVectorTests(IntFunction fa, BiFunction fs) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = new short[a.length]; - - for (int ic = 0; ic < INVOC_COUNT; ic++) { - for (int i = 0; i < a.length; i += SPECIES.length()) { - ShortVector av = ShortVector.fromArray(SPECIES, a, i); - av.intoArray(r, i, b, i); - } - } - - assertArraysEquals(r, a, b, ShortMaxVectorTests::scatter); - } - - static short[] scatterMasked(short r[], short a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - short[] oldVal = gather(r, ix, b, iy); - short[] newVal = new short[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - short[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void scatterMaskedShortMaxVectorTests(IntFunction fa, IntFunction fb, BiFunction fs, IntFunction fm) { - short[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - short[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.apply(SPECIES.length()); - VectorMask 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); - av.intoArray(r, i, b, i, vmask); - } - } - - assertArraysEquals(r, a, b, mask, ShortMaxVectorTests::scatterMasked); - } - @Test(dataProvider = "shortCompareOpProvider") static void ltShortMaxVectorTestsBroadcastSmokeTest(IntFunction fa, IntFunction fb) { diff --git a/test/jdk/jdk/incubator/vector/gen-template.sh b/test/jdk/jdk/incubator/vector/gen-template.sh index 22513b31ba9..2f69f7d08af 100644 --- a/test/jdk/jdk/incubator/vector/gen-template.sh +++ b/test/jdk/jdk/incubator/vector/gen-template.sh @@ -74,10 +74,6 @@ bool_reduction_template="BoolReduction-op" with_op_template="With-Op" shift_template="Shift-op" shift_masked_template="Shift-Masked-op" -gather_template="Gather-op" -gather_masked_template="Gather-Masked-op" -scatter_template="Scatter-op" -scatter_masked_template="Scatter-Masked-op" get_template="Get-op" rearrange_template="Rearrange" broadcast_template="Broadcast" @@ -558,12 +554,6 @@ gen_unary_alu_op "NOT+not" "~((\$type\$)a)" "BITWISE" gen_unary_alu_op "ZOMO" "(a==0?0:-1)" "BITWISE" gen_unary_alu_op "SQRT+sqrt" "Math.sqrt((double)a)" "FP" -# Gather Scatter operations. -gen_op_tmpl $gather_template "gather" "" -gen_op_tmpl $gather_masked_template "gather" "" -gen_op_tmpl $scatter_template "scatter" "" -gen_op_tmpl $scatter_masked_template "scatter" "" - # Miscellaneous Smoke Tests gen_op_tmpl $miscellaneous_template "MISC" "" "" diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Gather-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Gather-Masked-op.template deleted file mode 100644 index 94f88881eb4..00000000000 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Gather-Masked-op.template +++ /dev/null @@ -1,12 +0,0 @@ - $type$[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - $type$[] r = new $type$[a.length]; - boolean[] mask = fm.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, b, i, vmask); - av.intoArray(r, i); - } - } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Gather-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Gather-op.template deleted file mode 100644 index 33d70d29dc7..00000000000 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Gather-op.template +++ /dev/null @@ -1,10 +0,0 @@ - $type$[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - $type$[] r = new $type$[a.length]; - - 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, b, i); - av.intoArray(r, i); - } - } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Scatter-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Scatter-Masked-op.template deleted file mode 100644 index cd02afe98d4..00000000000 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Scatter-Masked-op.template +++ /dev/null @@ -1,12 +0,0 @@ - $type$[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - $type$[] r = fb.apply(SPECIES.length()); - boolean[] mask = fm.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); - av.intoArray(r, i, b, i, vmask); - } - } diff --git a/test/jdk/jdk/incubator/vector/templates/Kernel-Scatter-op.template b/test/jdk/jdk/incubator/vector/templates/Kernel-Scatter-op.template deleted file mode 100644 index 1bde7cb3164..00000000000 --- a/test/jdk/jdk/incubator/vector/templates/Kernel-Scatter-op.template +++ /dev/null @@ -1,10 +0,0 @@ - $type$[] a = fa.apply(SPECIES.length()); - int[] b = fs.apply(a.length, SPECIES.length()); - $type$[] r = new $type$[a.length]; - - 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); - av.intoArray(r, i, b, i); - } - } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Gather-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-Gather-Masked-op.template deleted file mode 100644 index 1f106214601..00000000000 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Gather-Masked-op.template +++ /dev/null @@ -1,17 +0,0 @@ - static $type$[] [[TEST]][[TEST_TYPE]]($type$ a[], int ix, boolean[] mask, int[] b, int iy) { - $type$[] res = new $type$[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - if (mask[i]) { - res[i] = a[b[bi] + ix]; - } - } - return res; - } - - @Test(dataProvider = "$type$UnaryMaskedOpIndexProvider") - static void [[TEST]][[TEST_TYPE]]$vectorteststype$(IntFunction<$type$[]> fa, BiFunction fs, IntFunction fm) { -[[KERNEL]] - assertArraysEquals(r, a, b, mask, $vectorteststype$::[[TEST]][[TEST_TYPE]]); - } - diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Gather-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-Gather-op.template deleted file mode 100644 index b16472f8a1c..00000000000 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Gather-op.template +++ /dev/null @@ -1,14 +0,0 @@ - static $type$[] [[TEST]]($type$ a[], int ix, int[] b, int iy) { - $type$[] res = new $type$[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[i] = a[b[bi] + ix]; - } - return res; - } - - @Test(dataProvider = "$type$UnaryOpIndexProvider") - static void [[TEST]]$vectorteststype$(IntFunction<$type$[]> fa, BiFunction fs) { -[[KERNEL]] - assertArraysEquals(r, a, b, $vectorteststype$::[[TEST]]); - } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Scatter-Masked-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-Scatter-Masked-op.template deleted file mode 100644 index e40018bbdfd..00000000000 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Scatter-Masked-op.template +++ /dev/null @@ -1,26 +0,0 @@ - static $type$[] [[TEST]][[TEST_TYPE]]($type$ r[], $type$ a[], int ix, boolean[] mask, int[] b, int iy) { - // First, gather r. - $type$[] oldVal = gather(r, ix, b, iy); - $type$[] newVal = new $type$[SPECIES.length()]; - - // Second, blending it with a. - for (int i = 0; i < SPECIES.length(); i++) { - newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); - } - - // Third, scatter: copy old value of r, and scatter it manually. - $type$[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = newVal[i]; - } - - return res; - } - - @Test(dataProvider = "scatterMaskedOpIndexProvider") - static void [[TEST]][[TEST_TYPE]]$vectorteststype$(IntFunction<$type$[]> fa, IntFunction<$type$[]> fb, BiFunction fs, IntFunction fm) { -[[KERNEL]] - assertArraysEquals(r, a, b, mask, $vectorteststype$::[[TEST]][[TEST_TYPE]]); - } - diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Scatter-op.template b/test/jdk/jdk/incubator/vector/templates/Unit-Scatter-op.template deleted file mode 100644 index db04500e3e7..00000000000 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Scatter-op.template +++ /dev/null @@ -1,15 +0,0 @@ - static $type$[] [[TEST]]($type$ a[], int ix, int[] b, int iy) { - $type$[] res = new $type$[SPECIES.length()]; - for (int i = 0; i < SPECIES.length(); i++) { - int bi = iy + i; - res[b[bi]] = a[i + ix]; - } - return res; - } - - @Test(dataProvider = "$type$UnaryOpIndexProvider") - static void [[TEST]]$vectorteststype$(IntFunction<$type$[]> fa, BiFunction fs) { -[[KERNEL]] - assertArraysEquals(r, a, b, $vectorteststype$::[[TEST]]); - } - diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-header.template b/test/jdk/jdk/incubator/vector/templates/Unit-header.template index 894d3c64c43..5afe4f91932 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-header.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-header.template @@ -91,8 +91,6 @@ public class $vectorteststype$ extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / $bits$); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * ($bits$ / 8)); - interface FUnOp { $type$ apply($type$ a); } @@ -1217,36 +1215,6 @@ public class $vectorteststype$ extends AbstractVectorTest { #end[!Int] - @DataProvider - public Object[][] $type$UnaryOpIndexProvider() { - return INT_INDEX_GENERATORS.stream(). - flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fs}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] $type$UnaryMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - $TYPE$_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fm, fs}; - }))). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] scatterMaskedOpIndexProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> - $TYPE$_GENERATORS.stream().flatMap(fn -> - $TYPE$_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fn, fm, fs}; - })))). - toArray(Object[][]::new); - } - static final List> $TYPE$_COMPARE_GENERATORS = List.of( withToString("$type$[i]", (int s) -> { return fill(s * BUFFER_REPS, diff --git a/test/jdk/jdk/incubator/vector/templates/X-LoadStoreTest.java.template b/test/jdk/jdk/incubator/vector/templates/X-LoadStoreTest.java.template index d87a0303ab9..c64f87c5370 100644 --- a/test/jdk/jdk/incubator/vector/templates/X-LoadStoreTest.java.template +++ b/test/jdk/jdk/incubator/vector/templates/X-LoadStoreTest.java.template @@ -57,6 +57,7 @@ import java.nio.$Type$Buffer; #end[!byte] import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; +import java.util.Arrays; import java.util.List; import java.util.function.*; @@ -70,7 +71,7 @@ public class $vectorteststype$ extends AbstractVectorTest { $Type$Vector.SPECIES_$bits$; #end[MaxBit] - static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10); + static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); #if[MaxBit] static VectorShape getMaxBit() { @@ -82,8 +83,6 @@ public class $vectorteststype$ extends AbstractVectorTest { static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / $bits$); - static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * ($bits$ / 8)); - static void assertArraysEquals($type$[] r, $type$[] a, boolean[] mask) { int i = 0; try { @@ -217,25 +216,6 @@ public class $vectorteststype$ extends AbstractVectorTest { toArray(Object[][]::new); } - @DataProvider - public Object[][] $type$IndexMapProvider() { - return INDEX_GENERATORS.stream(). - flatMap(fim -> $TYPE$_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim}; - })). - toArray(Object[][]::new); - } - - @DataProvider - public Object[][] $type$IndexMapMaskProvider() { - return BOOLEAN_MASK_GENERATORS.stream(). - flatMap(fm -> INDEX_GENERATORS.stream(). - flatMap(fim -> $TYPE$_GENERATORS.stream().map(fa -> { - return new Object[] {fa, fim, fm}; - }))). - toArray(Object[][]::new); - } - @DataProvider public Object[][] $type$ByteBufferProvider() { return $TYPE$_GENERATORS.stream(). @@ -1329,4 +1309,430 @@ public class $vectorteststype$ extends AbstractVectorTest { assertArraysEquals(r, a, mask); } #end[byte] + + + // Gather/Scatter load/store tests + + static void assertGatherArraysEquals($type$[] r, $type$[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals($type$[] r, $type$[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: ($type$) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: ($type$) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals($type$[] r, $type$[] a, int[] indexMap, boolean[] mask) { + $type$[] expected = new $type$[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals($type$[] r, $type$[] a, int[] indexMap) { + $type$[] expected = new $type$[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] gatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] gatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + $TYPE$_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "gatherScatterProvider") + static void gather(IntFunction<$type$[]> fa, BiFunction fs) { + $type$[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + $type$[] r = new $type$[a.length]; + + 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, b, i); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void gatherMask(IntFunction<$type$[]> fa, BiFunction fs, IntFunction fm) { + $type$[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + $type$[] r = new $type$[a.length]; + boolean[] mask = fm.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, b, i, vmask); + av.intoArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void scatter(IntFunction<$type$[]> fa, BiFunction fs) { + $type$[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + $type$[] r = new $type$[a.length]; + + 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); + av.intoArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void scatterMask(IntFunction<$type$[]> fa, BiFunction fs, IntFunction fm) { + $type$[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + $type$[] r = new $type$[a.length]; + boolean[] mask = fm.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); + av.intoArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } + +#if[short] + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: (char) 0, "at index #" + j); + } + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap, boolean[] mask) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(char[] r, char[] a, int[] indexMap) { + char[] expected = new char[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @DataProvider + public Object[][] charGatherScatterProvider() { + return INT_INDEX_GENERATORS.stream(). + flatMap(fs -> CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fs}; + })). + toArray(Object[][]::new); + } + + @DataProvider + public Object[][] charGatherScatterMaskProvider() { + return BOOLEAN_MASK_GENERATORS.stream(). + flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> + CHAR_GENERATORS.stream().map(fa -> { + return new Object[] {fa, fm, fs}; + }))). + toArray(Object[][]::new); + } + + + @Test(dataProvider = "charGatherScatterProvider") + static void charGather(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromCharArray(SPECIES, a, i, b, i); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.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$.fromCharArray(SPECIES, a, i, b, i, vmask); + av.intoCharArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "charGatherScatterProvider") + static void charScatter(IntFunction fa, BiFunction fs) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "charGatherScatterMaskProvider") + static void charScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + char[] a = fa.apply(SPECIES.length()); + int[] b = fs.apply(a.length, SPECIES.length()); + char[] r = new char[a.length]; + boolean[] mask = fm.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$.fromCharArray(SPECIES, a, i); + av.intoCharArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } +#end[short] + +#if[byte] + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], a[i + indexMap[j]]); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[j], a[i + indexMap[j]], "at index #" + j); + } + } + + static void assertGatherArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + int i = 0; + int j = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + j = i; + for (; j < i + SPECIES.length(); j++) { + Assert.assertEquals(r[j], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false); + } + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], mask[j % SPECIES.length()] ? a[i + indexMap[j]]: false, "at index #" + j); + } + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap, boolean[] mask) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + if (mask[j % SPECIES.length()]) { + expected[i + indexMap[j]] = a[j]; + } + } + } + + Assert.assertEquals(r, expected); + } + + static void assertScatterArraysEquals(boolean[] r, boolean[] a, int[] indexMap) { + boolean[] expected = new boolean[r.length]; + + // Store before checking, since the same location may be stored to more than once + for (int i = 0; i < a.length; i += SPECIES.length()) { + for (int j = i; j < i + SPECIES.length(); j++) { + expected[i + indexMap[j]] = a[j]; + } + } + + Assert.assertEquals(r, expected); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanGather(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromBooleanArray(SPECIES, a, i, b, i); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanGatherMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.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$.fromBooleanArray(SPECIES, a, i, b, i, vmask); + av.intoBooleanArray(r, i); + } + } + + assertGatherArraysEquals(r, a, b, mask); + } + + @Test(dataProvider = "gatherScatterProvider") + static void booleanScatter(IntFunction fa, BiFunction fs) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + + for (int ic = 0; ic < INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + $abstractvectortype$ av = $abstractvectortype$.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i); + } + } + + assertScatterArraysEquals(r, a, b); + } + + @Test(dataProvider = "gatherScatterMaskProvider") + static void booleanScatterMask(IntFunction fa, BiFunction fs, IntFunction fm) { + boolean[] a = convertToBooleanArray(fa.apply(SPECIES.length())); + int[] b = fs.apply(a.length, SPECIES.length()); + boolean[] r = new boolean[a.length]; + boolean[] mask = fm.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$.fromBooleanArray(SPECIES, a, i); + av.intoBooleanArray(r, i, b, i, vmask); + } + } + + assertScatterArraysEquals(r, a, b, mask); + } +#end[byte] + }