Skip to content

Commit bc57a7b

Browse files
update
1 parent 1b84e69 commit bc57a7b

34 files changed

Lines changed: 864 additions & 883 deletions

test/jdk/jdk/incubator/vector/AbstractVectorTest.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,43 +138,52 @@ static int[] fillInts(int[] a, IntOp f) {
138138
flatMap(fa -> BOOLEAN_MASK_GENERATORS.stream().skip(1).map(
139139
fb -> List.of(fa, fb))).collect(Collectors.toList());
140140

141-
static long pack_booleans_to_long(boolean[] mask) {
142-
long bits = 0L;
143-
// pack up to 64 bits/lane indices, least significant bit is lane 0
144-
int bound = Math.min(mask.length, 64);
145-
for (int i = 0; i < bound; i++) {
141+
static long[] pack_booleans_to_longs(boolean[] mask) {
142+
int totalLongs = (mask.length + 63) / 64; // ceil division
143+
long[] packed = new long[totalLongs];
144+
for (int i = 0; i < mask.length; i++) {
145+
int longIndex = i / 64;
146+
int bitIndex = i % 64;
146147
if (mask[i]) {
147-
bits |= 1L << i;
148+
packed[longIndex] |= 1L << bitIndex;
148149
}
149150
}
150-
return bits;
151+
return packed;
151152
}
152153

153-
static final List<IntFunction<Long>> LONG_MASK_GENERATORS = List.of(
154+
static final List<IntFunction<long[]>> LONG_MASK_GENERATORS = List.of(
154155
withToString("mask[random]", (int l) -> {
155156
boolean[] a = new boolean[l];
156157
for (int i = 0; i < l; i++) {
157158
a[i] = RAND.nextBoolean();
158159
}
159-
return pack_booleans_to_long(a);
160+
return pack_booleans_to_longs(a);
160161
}),
161162
withToString("mask[i % 2]", (int l) -> {
162163
boolean[] a = new boolean[l];
163164
for (int i = 0; i < l; i++) {
164165
a[i] = (i % 2 == 0);
165166
}
166-
return pack_booleans_to_long(a);
167+
return pack_booleans_to_longs(a);
168+
}),
169+
withToString("mask[i % 5]", (int l) -> {
170+
boolean[] a = new boolean[l];
171+
for (int i = 0; i < l; i++) {
172+
a[i] = (i % 2 == 0);
173+
}
174+
return pack_booleans_to_longs(a);
167175
}),
168176
withToString("mask[true]", (int l) -> {
169177
boolean[] a = new boolean[l];
170178
Arrays.fill(a, true);
171-
return pack_booleans_to_long(a);
179+
return pack_booleans_to_longs(a);
172180
}),
173-
withToString("mask[false]", Long::new),
174-
withToString("mask[0xFFFFFFFFFFFFFFFFL]", (_l) -> 0xFFFFFFFFFFFFFFFFL), // true
175-
withToString("mask[0x0000000000000000L]", (_l) -> 0x0000000000000000L), // false
176-
withToString("mask[0x5555555555555555L]", (_l) -> 0x5555555555555555L),
177-
withToString("mask[0x0123456789abcdefL]", (_l) -> 0x0123456789abcdefL)
181+
withToString("mask[false]", (int l) ->
182+
pack_booleans_to_longs(new boolean[l])),
183+
withToString("mask[0xFFFFFFFFFFFFFFFFL]", (_l) -> new long[] { 0xFFFFFFFFFFFFFFFFL }),
184+
withToString("mask[0x0000000000000000L]", (_l) -> new long[] { 0x0000000000000000L }),
185+
withToString("mask[0x5555555555555555L]", (_l) -> new long[] { 0x5555555555555555L }),
186+
withToString("mask[0x0123456789abcdefL]", (_l) -> new long[] { 0x0123456789abcdefL })
178187
);
179188

180189
static final List<BiFunction<Integer,Integer,int[]>> INT_SHUFFLE_GENERATORS = List.of(

test/jdk/jdk/incubator/vector/Byte128VectorTests.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6551,6 +6551,33 @@ static void masknotByte128VectorTests(IntFunction<boolean[]> fa, IntFunction<boo
65516551
assertArraysEquals(r, a, Byte128VectorTests::unot);
65526552
}
65536553

6554+
private static final long LONG_MASK_BITS = 0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length());
6555+
6556+
static void assertArraysEquals(long[] r, long[] a, long bits) {
6557+
int i = 0;
6558+
try {
6559+
for (; i < a.length; i++) {
6560+
Assert.assertEquals(r[i], a[i] & bits);
6561+
}
6562+
} catch (AssertionError e) {
6563+
Assert.assertEquals(r[i], a[i] & bits, "(" + a[i] + ") at index #" + i);
6564+
}
6565+
}
6566+
6567+
@Test(dataProvider = "maskLongProvider")
6568+
static void maskfromToLongByte128VectorTests(IntFunction<long[]> fa) {
6569+
long[] a = fa.apply(SPECIES.length());
6570+
long[] r = new long[a.length];
6571+
6572+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6573+
for (int i = 0; i < a.length; i++) {
6574+
VectorMask vmask = VectorMask.fromLong(SPECIES, a[i]);
6575+
r[i] = vmask.toLong();
6576+
}
6577+
}
6578+
assertArraysEquals(r, a, LONG_MASK_BITS);
6579+
}
6580+
65546581
@Test(dataProvider = "byteCompareOpProvider")
65556582
static void ltByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
65566583
byte[] a = fa.apply(SPECIES.length());
@@ -6981,37 +7008,6 @@ static void maskCompressByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
69817008
}
69827009
}
69837010

6984-
private static final long LONG_MASK_BITS = 0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length());
6985-
6986-
@Test(dataProvider = "maskLongProvider")
6987-
static void maskFromToLongByte128VectorTests(IntFunction<Long> fa) {
6988-
long a = fa.apply(SPECIES.length());
6989-
long r = -1;
6990-
6991-
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6992-
var vmask = VectorMask.fromLong(SPECIES, a);
6993-
r = vmask.toLong();
6994-
}
6995-
Assert.assertEquals(r, (a & LONG_MASK_BITS));
6996-
}
6997-
6998-
@DataProvider
6999-
public static Object[][] longMaskProvider() {
7000-
return new Object[][]{
7001-
{0xFFFFFFFFFFFFFFFFL},
7002-
{0x0000000000000000L},
7003-
{0x5555555555555555L},
7004-
{0x0123456789abcdefL},
7005-
};
7006-
}
7007-
7008-
@Test(dataProvider = "longMaskProvider")
7009-
static void maskFromToLongByte128VectorTestsSmokeTest(long inputLong) {
7010-
var vmask = VectorMask.fromLong(SPECIES, inputLong);
7011-
long outputLong = vmask.toLong();
7012-
Assert.assertEquals(outputLong, (inputLong & LONG_MASK_BITS));
7013-
}
7014-
70157011
@DataProvider
70167012
public static Object[][] offsetProvider() {
70177013
return new Object[][]{

test/jdk/jdk/incubator/vector/Byte256VectorTests.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6551,6 +6551,33 @@ static void masknotByte256VectorTests(IntFunction<boolean[]> fa, IntFunction<boo
65516551
assertArraysEquals(r, a, Byte256VectorTests::unot);
65526552
}
65536553

6554+
private static final long LONG_MASK_BITS = 0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length());
6555+
6556+
static void assertArraysEquals(long[] r, long[] a, long bits) {
6557+
int i = 0;
6558+
try {
6559+
for (; i < a.length; i++) {
6560+
Assert.assertEquals(r[i], a[i] & bits);
6561+
}
6562+
} catch (AssertionError e) {
6563+
Assert.assertEquals(r[i], a[i] & bits, "(" + a[i] + ") at index #" + i);
6564+
}
6565+
}
6566+
6567+
@Test(dataProvider = "maskLongProvider")
6568+
static void maskfromToLongByte256VectorTests(IntFunction<long[]> fa) {
6569+
long[] a = fa.apply(SPECIES.length());
6570+
long[] r = new long[a.length];
6571+
6572+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6573+
for (int i = 0; i < a.length; i++) {
6574+
VectorMask vmask = VectorMask.fromLong(SPECIES, a[i]);
6575+
r[i] = vmask.toLong();
6576+
}
6577+
}
6578+
assertArraysEquals(r, a, LONG_MASK_BITS);
6579+
}
6580+
65546581
@Test(dataProvider = "byteCompareOpProvider")
65556582
static void ltByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
65566583
byte[] a = fa.apply(SPECIES.length());
@@ -6981,37 +7008,6 @@ static void maskCompressByte256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
69817008
}
69827009
}
69837010

6984-
private static final long LONG_MASK_BITS = 0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length());
6985-
6986-
@Test(dataProvider = "maskLongProvider")
6987-
static void maskFromToLongByte256VectorTests(IntFunction<Long> fa) {
6988-
long a = fa.apply(SPECIES.length());
6989-
long r = -1;
6990-
6991-
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6992-
var vmask = VectorMask.fromLong(SPECIES, a);
6993-
r = vmask.toLong();
6994-
}
6995-
Assert.assertEquals(r, (a & LONG_MASK_BITS));
6996-
}
6997-
6998-
@DataProvider
6999-
public static Object[][] longMaskProvider() {
7000-
return new Object[][]{
7001-
{0xFFFFFFFFFFFFFFFFL},
7002-
{0x0000000000000000L},
7003-
{0x5555555555555555L},
7004-
{0x0123456789abcdefL},
7005-
};
7006-
}
7007-
7008-
@Test(dataProvider = "longMaskProvider")
7009-
static void maskFromToLongByte256VectorTestsSmokeTest(long inputLong) {
7010-
var vmask = VectorMask.fromLong(SPECIES, inputLong);
7011-
long outputLong = vmask.toLong();
7012-
Assert.assertEquals(outputLong, (inputLong & LONG_MASK_BITS));
7013-
}
7014-
70157011
@DataProvider
70167012
public static Object[][] offsetProvider() {
70177013
return new Object[][]{

test/jdk/jdk/incubator/vector/Byte512VectorTests.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6551,6 +6551,33 @@ static void masknotByte512VectorTests(IntFunction<boolean[]> fa, IntFunction<boo
65516551
assertArraysEquals(r, a, Byte512VectorTests::unot);
65526552
}
65536553

6554+
private static final long LONG_MASK_BITS = 0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length());
6555+
6556+
static void assertArraysEquals(long[] r, long[] a, long bits) {
6557+
int i = 0;
6558+
try {
6559+
for (; i < a.length; i++) {
6560+
Assert.assertEquals(r[i], a[i] & bits);
6561+
}
6562+
} catch (AssertionError e) {
6563+
Assert.assertEquals(r[i], a[i] & bits, "(" + a[i] + ") at index #" + i);
6564+
}
6565+
}
6566+
6567+
@Test(dataProvider = "maskLongProvider")
6568+
static void maskfromToLongByte512VectorTests(IntFunction<long[]> fa) {
6569+
long[] a = fa.apply(SPECIES.length());
6570+
long[] r = new long[a.length];
6571+
6572+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6573+
for (int i = 0; i < a.length; i++) {
6574+
VectorMask vmask = VectorMask.fromLong(SPECIES, a[i]);
6575+
r[i] = vmask.toLong();
6576+
}
6577+
}
6578+
assertArraysEquals(r, a, LONG_MASK_BITS);
6579+
}
6580+
65546581
@Test(dataProvider = "byteCompareOpProvider")
65556582
static void ltByte512VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
65566583
byte[] a = fa.apply(SPECIES.length());
@@ -6981,37 +7008,6 @@ static void maskCompressByte512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
69817008
}
69827009
}
69837010

6984-
private static final long LONG_MASK_BITS = 0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length());
6985-
6986-
@Test(dataProvider = "maskLongProvider")
6987-
static void maskFromToLongByte512VectorTests(IntFunction<Long> fa) {
6988-
long a = fa.apply(SPECIES.length());
6989-
long r = -1;
6990-
6991-
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6992-
var vmask = VectorMask.fromLong(SPECIES, a);
6993-
r = vmask.toLong();
6994-
}
6995-
Assert.assertEquals(r, (a & LONG_MASK_BITS));
6996-
}
6997-
6998-
@DataProvider
6999-
public static Object[][] longMaskProvider() {
7000-
return new Object[][]{
7001-
{0xFFFFFFFFFFFFFFFFL},
7002-
{0x0000000000000000L},
7003-
{0x5555555555555555L},
7004-
{0x0123456789abcdefL},
7005-
};
7006-
}
7007-
7008-
@Test(dataProvider = "longMaskProvider")
7009-
static void maskFromToLongByte512VectorTestsSmokeTest(long inputLong) {
7010-
var vmask = VectorMask.fromLong(SPECIES, inputLong);
7011-
long outputLong = vmask.toLong();
7012-
Assert.assertEquals(outputLong, (inputLong & LONG_MASK_BITS));
7013-
}
7014-
70157011
@DataProvider
70167012
public static Object[][] offsetProvider() {
70177013
return new Object[][]{

test/jdk/jdk/incubator/vector/Byte64VectorTests.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6551,6 +6551,33 @@ static void masknotByte64VectorTests(IntFunction<boolean[]> fa, IntFunction<bool
65516551
assertArraysEquals(r, a, Byte64VectorTests::unot);
65526552
}
65536553

6554+
private static final long LONG_MASK_BITS = 0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length());
6555+
6556+
static void assertArraysEquals(long[] r, long[] a, long bits) {
6557+
int i = 0;
6558+
try {
6559+
for (; i < a.length; i++) {
6560+
Assert.assertEquals(r[i], a[i] & bits);
6561+
}
6562+
} catch (AssertionError e) {
6563+
Assert.assertEquals(r[i], a[i] & bits, "(" + a[i] + ") at index #" + i);
6564+
}
6565+
}
6566+
6567+
@Test(dataProvider = "maskLongProvider")
6568+
static void maskfromToLongByte64VectorTests(IntFunction<long[]> fa) {
6569+
long[] a = fa.apply(SPECIES.length());
6570+
long[] r = new long[a.length];
6571+
6572+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6573+
for (int i = 0; i < a.length; i++) {
6574+
VectorMask vmask = VectorMask.fromLong(SPECIES, a[i]);
6575+
r[i] = vmask.toLong();
6576+
}
6577+
}
6578+
assertArraysEquals(r, a, LONG_MASK_BITS);
6579+
}
6580+
65546581
@Test(dataProvider = "byteCompareOpProvider")
65556582
static void ltByte64VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
65566583
byte[] a = fa.apply(SPECIES.length());
@@ -6981,37 +7008,6 @@ static void maskCompressByte64VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
69817008
}
69827009
}
69837010

6984-
private static final long LONG_MASK_BITS = 0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length());
6985-
6986-
@Test(dataProvider = "maskLongProvider")
6987-
static void maskFromToLongByte64VectorTests(IntFunction<Long> fa) {
6988-
long a = fa.apply(SPECIES.length());
6989-
long r = -1;
6990-
6991-
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6992-
var vmask = VectorMask.fromLong(SPECIES, a);
6993-
r = vmask.toLong();
6994-
}
6995-
Assert.assertEquals(r, (a & LONG_MASK_BITS));
6996-
}
6997-
6998-
@DataProvider
6999-
public static Object[][] longMaskProvider() {
7000-
return new Object[][]{
7001-
{0xFFFFFFFFFFFFFFFFL},
7002-
{0x0000000000000000L},
7003-
{0x5555555555555555L},
7004-
{0x0123456789abcdefL},
7005-
};
7006-
}
7007-
7008-
@Test(dataProvider = "longMaskProvider")
7009-
static void maskFromToLongByte64VectorTestsSmokeTest(long inputLong) {
7010-
var vmask = VectorMask.fromLong(SPECIES, inputLong);
7011-
long outputLong = vmask.toLong();
7012-
Assert.assertEquals(outputLong, (inputLong & LONG_MASK_BITS));
7013-
}
7014-
70157011
@DataProvider
70167012
public static Object[][] offsetProvider() {
70177013
return new Object[][]{

0 commit comments

Comments
 (0)