From 2b20778225527a3ccd3ced2a4246c5943f467e06 Mon Sep 17 00:00:00 2001 From: Xiaohong Gong Date: Tue, 6 Jul 2021 08:17:27 +0000 Subject: [PATCH] 8269568: JVM crashes when running VectorMask query tests Co-authored-by: Sandhya Viswanathan Reviewed-by: psandoz, jiefu, jbhateja, sviswanathan --- src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp | 3 + src/hotspot/share/opto/vectornode.hpp | 2 +- .../incubator/vector/Byte128VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Byte256VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Byte512VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Byte64VectorTests.java | 89 +++++++++++++------ .../incubator/vector/ByteMaxVectorTests.java | 89 +++++++++++++------ .../vector/Double128VectorTests.java | 89 +++++++++++++------ .../vector/Double256VectorTests.java | 89 +++++++++++++------ .../vector/Double512VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Double64VectorTests.java | 89 +++++++++++++------ .../vector/DoubleMaxVectorTests.java | 89 +++++++++++++------ .../incubator/vector/Float128VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Float256VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Float512VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Float64VectorTests.java | 89 +++++++++++++------ .../incubator/vector/FloatMaxVectorTests.java | 89 +++++++++++++------ .../incubator/vector/Int128VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Int256VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Int512VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Int64VectorTests.java | 89 +++++++++++++------ .../incubator/vector/IntMaxVectorTests.java | 89 +++++++++++++------ .../incubator/vector/Long128VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Long256VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Long512VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Long64VectorTests.java | 89 +++++++++++++------ .../incubator/vector/LongMaxVectorTests.java | 89 +++++++++++++------ .../incubator/vector/Short128VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Short256VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Short512VectorTests.java | 89 +++++++++++++------ .../incubator/vector/Short64VectorTests.java | 89 +++++++++++++------ .../incubator/vector/ShortMaxVectorTests.java | 89 +++++++++++++------ .../templates/Unit-Miscellaneous.template | 74 +++++++++------ .../vector/templates/Unit-header.template | 15 ++++ 34 files changed, 1957 insertions(+), 807 deletions(-) diff --git a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp index 147bcb8aa3e..e951e808af0 100644 --- a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp @@ -3894,6 +3894,9 @@ void C2_MacroAssembler::vector_mask_operation(int opc, Register dst, XMMRegister vpxor(xtmp, xtmp, xtmp, vec_enc); vpsubb(xtmp, xtmp, mask, vec_enc); vpmovmskb(tmp, xtmp, vec_enc); + if (masklen < 64) { + andq(tmp, (((jlong)1 << masklen) - 1)); + } switch(opc) { case Op_VectorMaskTrueCount: popcntq(dst, tmp); diff --git a/src/hotspot/share/opto/vectornode.hpp b/src/hotspot/share/opto/vectornode.hpp index 08827ecc6d6..7ba0149777f 100644 --- a/src/hotspot/share/opto/vectornode.hpp +++ b/src/hotspot/share/opto/vectornode.hpp @@ -876,7 +876,7 @@ class VectorMaskOpNode : public TypeNode { public: VectorMaskOpNode(Node* mask, const Type* ty, int mopc): TypeNode(ty, 2), _mopc(mopc) { - assert(mask->Opcode() == Op_VectorStoreMask, ""); + assert(mask->bottom_type()->is_vect()->element_basic_type() == T_BOOLEAN, ""); init_req(1, mask); } diff --git a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java index e9c5cf363c9..00ebad48021 100644 --- a/test/jdk/jdk/incubator/vector/Byte128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte128VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) { int i = 0; try { @@ -5230,55 +5245,77 @@ static void maskHashCodeByte128VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountByte128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueByte128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueByte128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java index 52b32f835b5..32c67f72e56 100644 --- a/test/jdk/jdk/incubator/vector/Byte256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte256VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) { int i = 0; try { @@ -5230,55 +5245,77 @@ static void maskHashCodeByte256VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountByte256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueByte256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueByte256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java index 8f123b1ee6a..eab4d8226d3 100644 --- a/test/jdk/jdk/incubator/vector/Byte512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte512VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) { int i = 0; try { @@ -5230,55 +5245,77 @@ static void maskHashCodeByte512VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountByte512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueByte512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueByte512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java index 0a7a6ed4ed5..75aaf7b1b80 100644 --- a/test/jdk/jdk/incubator/vector/Byte64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Byte64VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) { int i = 0; try { @@ -5230,55 +5245,77 @@ static void maskHashCodeByte64VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountByte64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Byte64VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueByte64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Byte64VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueByte64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Byte64VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java index 5e8e02ea3df..20a7cccfdd7 100644 --- a/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java @@ -216,6 +216,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) { int i = 0; try { @@ -5235,55 +5250,77 @@ static void maskHashCodeByteMaxVectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountByteMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueByteMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueByteMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskFirstTrue); } diff --git a/test/jdk/jdk/incubator/vector/Double128VectorTests.java b/test/jdk/jdk/incubator/vector/Double128VectorTests.java index 22d1799a427..a5f9cad0921 100644 --- a/test/jdk/jdk/incubator/vector/Double128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double128VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) { int i = 0; try { @@ -4781,55 +4796,77 @@ static void maskHashCodeDouble128VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountDouble128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Double128VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueDouble128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Double128VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueDouble128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Double128VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Double256VectorTests.java b/test/jdk/jdk/incubator/vector/Double256VectorTests.java index ff3be7723ca..b27d568fc8b 100644 --- a/test/jdk/jdk/incubator/vector/Double256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double256VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) { int i = 0; try { @@ -4781,55 +4796,77 @@ static void maskHashCodeDouble256VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountDouble256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Double256VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueDouble256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Double256VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueDouble256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Double256VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Double512VectorTests.java b/test/jdk/jdk/incubator/vector/Double512VectorTests.java index 9af4e20d601..5d5d53b57e6 100644 --- a/test/jdk/jdk/incubator/vector/Double512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double512VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) { int i = 0; try { @@ -4781,55 +4796,77 @@ static void maskHashCodeDouble512VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountDouble512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Double512VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueDouble512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Double512VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueDouble512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Double512VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Double64VectorTests.java b/test/jdk/jdk/incubator/vector/Double64VectorTests.java index 2e05caf6421..d17308715bc 100644 --- a/test/jdk/jdk/incubator/vector/Double64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Double64VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) { int i = 0; try { @@ -4781,55 +4796,77 @@ static void maskHashCodeDouble64VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountDouble64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Double64VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueDouble64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Double64VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueDouble64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Double64VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java index ab8787fec09..7f6ae5860eb 100644 --- a/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java @@ -216,6 +216,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) { int i = 0; try { @@ -4786,55 +4801,77 @@ static void maskHashCodeDoubleMaxVectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountDoubleMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, DoubleMaxVectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueDoubleMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, DoubleMaxVectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueDoubleMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, DoubleMaxVectorTests::maskFirstTrue); } diff --git a/test/jdk/jdk/incubator/vector/Float128VectorTests.java b/test/jdk/jdk/incubator/vector/Float128VectorTests.java index cb4fc673802..465817c6c54 100644 --- a/test/jdk/jdk/incubator/vector/Float128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float128VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(float[] r, float[] a, float element, int index) { int i = 0; try { @@ -4759,55 +4774,77 @@ static void maskHashCodeFloat128VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountFloat128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Float128VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueFloat128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Float128VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueFloat128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Float128VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Float256VectorTests.java b/test/jdk/jdk/incubator/vector/Float256VectorTests.java index fbe27a2e47a..661b9d8a590 100644 --- a/test/jdk/jdk/incubator/vector/Float256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float256VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(float[] r, float[] a, float element, int index) { int i = 0; try { @@ -4759,55 +4774,77 @@ static void maskHashCodeFloat256VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountFloat256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Float256VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueFloat256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Float256VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueFloat256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Float256VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Float512VectorTests.java b/test/jdk/jdk/incubator/vector/Float512VectorTests.java index 599145bd63d..a2bd05921bc 100644 --- a/test/jdk/jdk/incubator/vector/Float512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float512VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(float[] r, float[] a, float element, int index) { int i = 0; try { @@ -4759,55 +4774,77 @@ static void maskHashCodeFloat512VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountFloat512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Float512VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueFloat512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Float512VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueFloat512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Float512VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Float64VectorTests.java b/test/jdk/jdk/incubator/vector/Float64VectorTests.java index 0d82853a62d..6d325336941 100644 --- a/test/jdk/jdk/incubator/vector/Float64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Float64VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(float[] r, float[] a, float element, int index) { int i = 0; try { @@ -4759,55 +4774,77 @@ static void maskHashCodeFloat64VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountFloat64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Float64VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueFloat64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Float64VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueFloat64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Float64VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java index 88d60d1fe72..ee8ac1ab8f0 100644 --- a/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java @@ -216,6 +216,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(float[] r, float[] a, float element, int index) { int i = 0; try { @@ -4764,55 +4779,77 @@ static void maskHashCodeFloatMaxVectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountFloatMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, FloatMaxVectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueFloatMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, FloatMaxVectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueFloatMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, FloatMaxVectorTests::maskFirstTrue); } diff --git a/test/jdk/jdk/incubator/vector/Int128VectorTests.java b/test/jdk/jdk/incubator/vector/Int128VectorTests.java index e991e9fa73c..c45ea61f830 100644 --- a/test/jdk/jdk/incubator/vector/Int128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int128VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(int[] r, int[] a, int element, int index) { int i = 0; try { @@ -5184,55 +5199,77 @@ static void maskHashCodeInt128VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountInt128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Int128VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueInt128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Int128VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueInt128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Int128VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Int256VectorTests.java b/test/jdk/jdk/incubator/vector/Int256VectorTests.java index 13f3b43ce7e..121b5c37f5f 100644 --- a/test/jdk/jdk/incubator/vector/Int256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int256VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(int[] r, int[] a, int element, int index) { int i = 0; try { @@ -5184,55 +5199,77 @@ static void maskHashCodeInt256VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountInt256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Int256VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueInt256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Int256VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueInt256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Int256VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Int512VectorTests.java b/test/jdk/jdk/incubator/vector/Int512VectorTests.java index 318e1ccf17d..23dcf6464e3 100644 --- a/test/jdk/jdk/incubator/vector/Int512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int512VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(int[] r, int[] a, int element, int index) { int i = 0; try { @@ -5184,55 +5199,77 @@ static void maskHashCodeInt512VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountInt512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Int512VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueInt512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Int512VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueInt512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Int512VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Int64VectorTests.java b/test/jdk/jdk/incubator/vector/Int64VectorTests.java index 87456e78857..0a442077f23 100644 --- a/test/jdk/jdk/incubator/vector/Int64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Int64VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(int[] r, int[] a, int element, int index) { int i = 0; try { @@ -5184,55 +5199,77 @@ static void maskHashCodeInt64VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountInt64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Int64VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueInt64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Int64VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueInt64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Int64VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java index 24f5b8b64df..f8257ccbf92 100644 --- a/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/IntMaxVectorTests.java @@ -216,6 +216,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(int[] r, int[] a, int element, int index) { int i = 0; try { @@ -5189,55 +5204,77 @@ static void maskHashCodeIntMaxVectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountIntMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, IntMaxVectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueIntMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, IntMaxVectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueIntMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, IntMaxVectorTests::maskFirstTrue); } diff --git a/test/jdk/jdk/incubator/vector/Long128VectorTests.java b/test/jdk/jdk/incubator/vector/Long128VectorTests.java index 7ec1bfb340f..20a1bfe900b 100644 --- a/test/jdk/jdk/incubator/vector/Long128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long128VectorTests.java @@ -168,6 +168,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(long[] r, long[] a, long element, int index) { int i = 0; try { @@ -5068,55 +5083,77 @@ static void maskHashCodeLong128VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountLong128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Long128VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueLong128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Long128VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueLong128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Long128VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Long256VectorTests.java b/test/jdk/jdk/incubator/vector/Long256VectorTests.java index 9ef54fa5ad1..fd8493eff22 100644 --- a/test/jdk/jdk/incubator/vector/Long256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long256VectorTests.java @@ -168,6 +168,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(long[] r, long[] a, long element, int index) { int i = 0; try { @@ -5068,55 +5083,77 @@ static void maskHashCodeLong256VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountLong256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Long256VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueLong256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Long256VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueLong256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Long256VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Long512VectorTests.java b/test/jdk/jdk/incubator/vector/Long512VectorTests.java index e4e008c1acd..05fcf160be2 100644 --- a/test/jdk/jdk/incubator/vector/Long512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long512VectorTests.java @@ -168,6 +168,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(long[] r, long[] a, long element, int index) { int i = 0; try { @@ -5068,55 +5083,77 @@ static void maskHashCodeLong512VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountLong512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Long512VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueLong512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Long512VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueLong512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Long512VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Long64VectorTests.java b/test/jdk/jdk/incubator/vector/Long64VectorTests.java index 1bf9a24bce2..1ed9c4895fc 100644 --- a/test/jdk/jdk/incubator/vector/Long64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Long64VectorTests.java @@ -168,6 +168,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(long[] r, long[] a, long element, int index) { int i = 0; try { @@ -5068,55 +5083,77 @@ static void maskHashCodeLong64VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountLong64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Long64VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueLong64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Long64VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueLong64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Long64VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java index fc18a81a8d7..c3612dab831 100644 --- a/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/LongMaxVectorTests.java @@ -173,6 +173,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(long[] r, long[] a, long element, int index) { int i = 0; try { @@ -5073,55 +5088,77 @@ static void maskHashCodeLongMaxVectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountLongMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, LongMaxVectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueLongMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, LongMaxVectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueLongMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, LongMaxVectorTests::maskFirstTrue); } diff --git a/test/jdk/jdk/incubator/vector/Short128VectorTests.java b/test/jdk/jdk/incubator/vector/Short128VectorTests.java index d1dc6b9b4ee..50dc41bc7db 100644 --- a/test/jdk/jdk/incubator/vector/Short128VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short128VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(short[] r, short[] a, short element, int index) { int i = 0; try { @@ -5209,55 +5224,77 @@ static void maskHashCodeShort128VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountShort128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Short128VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueShort128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Short128VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueShort128VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Short128VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Short256VectorTests.java b/test/jdk/jdk/incubator/vector/Short256VectorTests.java index 51a47225af6..6c1d460b1a2 100644 --- a/test/jdk/jdk/incubator/vector/Short256VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short256VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(short[] r, short[] a, short element, int index) { int i = 0; try { @@ -5209,55 +5224,77 @@ static void maskHashCodeShort256VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountShort256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Short256VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueShort256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Short256VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueShort256VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Short256VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Short512VectorTests.java b/test/jdk/jdk/incubator/vector/Short512VectorTests.java index 05d3d8059e2..9410b3c8579 100644 --- a/test/jdk/jdk/incubator/vector/Short512VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short512VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(short[] r, short[] a, short element, int index) { int i = 0; try { @@ -5209,55 +5224,77 @@ static void maskHashCodeShort512VectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountShort512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Short512VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueShort512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Short512VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueShort512VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Short512VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/Short64VectorTests.java b/test/jdk/jdk/incubator/vector/Short64VectorTests.java index 5cc7f66cb1f..a6fc3dd3e03 100644 --- a/test/jdk/jdk/incubator/vector/Short64VectorTests.java +++ b/test/jdk/jdk/incubator/vector/Short64VectorTests.java @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(short[] r, short[] a, short element, int index) { int i = 0; try { @@ -5209,55 +5224,77 @@ static void maskHashCodeShort64VectorTestsSmokeTest(IntFunction fa) { } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountShort64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, Short64VectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueShort64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, Short64VectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueShort64VectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, Short64VectorTests::maskFirstTrue); } @DataProvider diff --git a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java index 731b69fcaea..4653a8fb32a 100644 --- a/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java +++ b/test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java @@ -216,6 +216,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals(short[] r, short[] a, short element, int index) { int i = 0; try { @@ -5214,55 +5229,77 @@ static void maskHashCodeShortMaxVectorTestsSmokeTest(IntFunction fa) } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCountShortMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, ShortMaxVectorTests::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrueShortMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, ShortMaxVectorTests::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrueShortMaxVectorTestsSmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, ShortMaxVectorTests::maskFirstTrue); } diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-Miscellaneous.template b/test/jdk/jdk/incubator/vector/templates/Unit-Miscellaneous.template index 93ca2065752..a75a6842bd3 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-Miscellaneous.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-Miscellaneous.template @@ -411,55 +411,77 @@ } } + static int maskTrueCount(boolean[] a, int idx) { + int trueCount = 0; + for (int i = idx; i < idx + SPECIES.length(); i++) { + trueCount += a[i] ? 1 : 0; + } + return trueCount; + } + @Test(dataProvider = "maskProvider") static void maskTrueCount$vectorteststype$SmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int tcount = vmask.trueCount(); - int expectedTcount = 0; - for (int j = i; j < i + SPECIES.length(); j++) { - expectedTcount += a[j] ? 1 : 0; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.trueCount(); } - Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); } + + assertMaskReductionArraysEquals(r, a, $vectorteststype$::maskTrueCount); + } + + static int maskLastTrue(boolean[] a, int idx) { + int i = idx + SPECIES.length() - 1; + for (; i >= idx; i--) { + if (a[i]) { + break; + } + } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskLastTrue$vectorteststype$SmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ltrue = vmask.lastTrue(); - int j = i + SPECIES.length() - 1; - for (; j >= i; j--) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.lastTrue(); } - int expectedLtrue = j - i; + } - Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + - ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); + assertMaskReductionArraysEquals(r, a, $vectorteststype$::maskLastTrue); + } + + static int maskFirstTrue(boolean[] a, int idx) { + int i = idx; + for (; i < idx + SPECIES.length(); i++) { + if (a[i]) { + break; + } } + return i - idx; } @Test(dataProvider = "maskProvider") static void maskFirstTrue$vectorteststype$SmokeTest(IntFunction fa) { boolean[] a = fa.apply(SPECIES.length()); + int[] r = new int[a.length]; - for (int i = 0; i < a.length; i += SPECIES.length()) { - var vmask = SPECIES.loadMask(a, i); - int ftrue = vmask.firstTrue(); - int j = i; - for (; j < i + SPECIES.length() ; j++) { - if (a[j]) break; + for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { + for (int i = 0; i < a.length; i += SPECIES.length()) { + var vmask = SPECIES.loadMask(a, i); + r[i] = vmask.firstTrue(); } - int expectedFtrue = j - i; - - Assert.assertTrue(ftrue == expectedFtrue, "at index " + i + - ", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue); } + + assertMaskReductionArraysEquals(r, a, $vectorteststype$::maskFirstTrue); } #if[!MaxBit] diff --git a/test/jdk/jdk/incubator/vector/templates/Unit-header.template b/test/jdk/jdk/incubator/vector/templates/Unit-header.template index 5afe4f91932..4c0fd5bdfb9 100644 --- a/test/jdk/jdk/incubator/vector/templates/Unit-header.template +++ b/test/jdk/jdk/incubator/vector/templates/Unit-header.template @@ -242,6 +242,21 @@ public class $vectorteststype$ extends AbstractVectorTest { } } + interface FMaskReductionOp { + int apply(boolean[] a, int idx); + } + + static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { + int i = 0; + try { + for (; i < a.length; i += SPECIES.length()) { + Assert.assertEquals(r[i], f.apply(a, i)); + } + } catch (AssertionError e) { + Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); + } + } + static void assertInsertArraysEquals($type$[] r, $type$[] a, $type$ element, int index) { int i = 0; try {