< prev index next >

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

Print this page

 242             } else {
 243                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 244             }
 245         }
 246     }
 247 
 248     static void assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, int vector_len) {
 249         int i = 0, j = 0;
 250         try {
 251             for (; i < a.length; i += vector_len) {
 252                 for (j = 0; j < vector_len; j++) {
 253                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 254                 }
 255             }
 256         } catch (AssertionError e) {
 257             int idx = i + j;
 258             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 259         }
 260     }
 261 

















































 262     static void assertSelectFromArraysEquals(byte[] r, byte[] a, byte[] order, int vector_len) {
 263         int i = 0, j = 0;
 264         try {
 265             for (; i < a.length; i += vector_len) {
 266                 for (j = 0; j < vector_len; j++) {
 267                     Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 268                 }
 269             }
 270         } catch (AssertionError e) {
 271             int idx = i + j;
 272             Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
 273         }
 274     }
 275 
 276     static void assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, boolean[] mask, int vector_len) {
 277         int i = 0, j = 0;
 278         try {
 279             for (; i < a.length; i += vector_len) {
 280                 for (j = 0; j < vector_len; j++) {
 281                     if (mask[j % SPECIES.length()])

4207         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
4208     }
4209 
4210     @Test(dataProvider = "byteUnaryOpShuffleMaskProvider")
4211     static void RearrangeByte128VectorTestsMaskedSmokeTest(IntFunction<byte[]> fa,
4212                                                           BiFunction<Integer,Integer,int[]> fs,
4213                                                           IntFunction<boolean[]> fm) {
4214         byte[] a = fa.apply(SPECIES.length());
4215         int[] order = fs.apply(a.length, SPECIES.length());
4216         byte[] r = fr.apply(SPECIES.length());
4217         boolean[] mask = fm.apply(SPECIES.length());
4218         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4219 
4220         for (int i = 0; i < a.length; i += SPECIES.length()) {
4221             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4222             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
4223         }
4224 
4225         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
4226     }




































4227     @Test(dataProvider = "byteUnaryOpProvider")
4228     static void getByte128VectorTests(IntFunction<byte[]> fa) {
4229         byte[] a = fa.apply(SPECIES.length());
4230         byte[] r = fr.apply(SPECIES.length());
4231 
4232         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4233             for (int i = 0; i < a.length; i += SPECIES.length()) {
4234                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4235                 int num_lanes = SPECIES.length();
4236                 // Manually unroll because full unroll happens after intrinsification.
4237                 // Unroll is needed because get intrinsic requires for index to be a known constant.
4238                 if (num_lanes == 1) {
4239                     r[i]=av.lane(0);
4240                 } else if (num_lanes == 2) {
4241                     r[i]=av.lane(0);
4242                     r[i+1]=av.lane(1);
4243                 } else if (num_lanes == 4) {
4244                     r[i]=av.lane(0);
4245                     r[i+1]=av.lane(1);
4246                     r[i+2]=av.lane(2);

5481             }
5482         }
5483         return i - idx;
5484     }
5485 
5486     @Test(dataProvider = "maskProvider")
5487     static void maskFirstTrueByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5488         boolean[] a = fa.apply(SPECIES.length());
5489         int[] r = new int[a.length];
5490 
5491         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5492             for (int i = 0; i < a.length; i += SPECIES.length()) {
5493                 var vmask = SPECIES.loadMask(a, i);
5494                 r[i] = vmask.firstTrue();
5495             }
5496         }
5497 
5498         assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskFirstTrue);
5499     }
5500 

















5501     @DataProvider
5502     public static Object[][] longMaskProvider() {
5503         return new Object[][]{
5504                 {0xFFFFFFFFFFFFFFFFL},
5505                 {0x0000000000000000L},
5506                 {0x5555555555555555L},
5507                 {0x0123456789abcdefL},
5508         };
5509     }
5510 
5511     @Test(dataProvider = "longMaskProvider")
5512     static void maskFromToLongByte128VectorTestsSmokeTest(long inputLong) {
5513         var vmask = VectorMask.fromLong(SPECIES, inputLong);
5514         long outputLong = vmask.toLong();
5515         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
5516     }
5517 
5518     @DataProvider
5519     public static Object[][] offsetProvider() {
5520         return new Object[][]{

 242             } else {
 243                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 244             }
 245         }
 246     }
 247 
 248     static void assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, int vector_len) {
 249         int i = 0, j = 0;
 250         try {
 251             for (; i < a.length; i += vector_len) {
 252                 for (j = 0; j < vector_len; j++) {
 253                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 254                 }
 255             }
 256         } catch (AssertionError e) {
 257             int idx = i + j;
 258             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 259         }
 260     }
 261 
 262     static void assertcompressArraysEquals(byte[] r, byte[] a, boolean[] m, int vector_len) {
 263         int i = 0, j = 0, k = 0;
 264         try {
 265             for (; i < a.length; i += vector_len) {
 266                 k = 0;
 267                 for (j = 0; j < vector_len; j++) {
 268                     if (m[(i + j) % SPECIES.length()]) {
 269                         Assert.assertEquals(r[i + k], a[i + j]);
 270                         k++;
 271                     }
 272                 }
 273                 for (; k < vector_len; k++) {
 274                     Assert.assertEquals(r[i + k], (byte)0);
 275                 }
 276             }
 277         } catch (AssertionError e) {
 278             int idx = i + k;
 279             if (m[(i + j) % SPECIES.length()]) {
 280                 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx);
 281             } else {
 282                 Assert.assertEquals(r[idx], (byte)0, "at index #" + idx);
 283             }
 284         }
 285     }
 286 
 287     static void assertexpandArraysEquals(byte[] r, byte[] a, boolean[] m, int vector_len) {
 288         int i = 0, j = 0, k = 0;
 289         try {
 290             for (; i < a.length; i += vector_len) {
 291                 k = 0;
 292                 for (j = 0; j < vector_len; j++) {
 293                     if (m[(i + j) % SPECIES.length()]) {
 294                         Assert.assertEquals(r[i + j], a[i + k]);
 295                         k++;
 296                     } else {
 297                         Assert.assertEquals(r[i + j], (byte)0);
 298                     }
 299                 }
 300             }
 301         } catch (AssertionError e) {
 302             int idx = i + j;
 303             if (m[idx % SPECIES.length()]) {
 304                 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx);
 305             } else {
 306                 Assert.assertEquals(r[idx], (byte)0, "at index #" + idx);
 307             }
 308         }
 309     }
 310 
 311     static void assertSelectFromArraysEquals(byte[] r, byte[] a, byte[] order, int vector_len) {
 312         int i = 0, j = 0;
 313         try {
 314             for (; i < a.length; i += vector_len) {
 315                 for (j = 0; j < vector_len; j++) {
 316                     Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 317                 }
 318             }
 319         } catch (AssertionError e) {
 320             int idx = i + j;
 321             Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
 322         }
 323     }
 324 
 325     static void assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, boolean[] mask, int vector_len) {
 326         int i = 0, j = 0;
 327         try {
 328             for (; i < a.length; i += vector_len) {
 329                 for (j = 0; j < vector_len; j++) {
 330                     if (mask[j % SPECIES.length()])

4256         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
4257     }
4258 
4259     @Test(dataProvider = "byteUnaryOpShuffleMaskProvider")
4260     static void RearrangeByte128VectorTestsMaskedSmokeTest(IntFunction<byte[]> fa,
4261                                                           BiFunction<Integer,Integer,int[]> fs,
4262                                                           IntFunction<boolean[]> fm) {
4263         byte[] a = fa.apply(SPECIES.length());
4264         int[] order = fs.apply(a.length, SPECIES.length());
4265         byte[] r = fr.apply(SPECIES.length());
4266         boolean[] mask = fm.apply(SPECIES.length());
4267         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4268 
4269         for (int i = 0; i < a.length; i += SPECIES.length()) {
4270             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4271             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
4272         }
4273 
4274         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
4275     }
4276 
4277     @Test(dataProvider = "byteUnaryOpMaskProvider")
4278     static void compressByte128VectorTests(IntFunction<byte[]> fa,
4279                                                 IntFunction<boolean[]> fm) {
4280         byte[] a = fa.apply(SPECIES.length());
4281         byte[] r = fr.apply(SPECIES.length());
4282         boolean[] mask = fm.apply(SPECIES.length());
4283         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4284 
4285         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4286             for (int i = 0; i < a.length; i += SPECIES.length()) {
4287                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4288                 av.compress(vmask).intoArray(r, i);
4289             }
4290         }
4291 
4292         assertcompressArraysEquals(r, a, mask, SPECIES.length());
4293     }
4294 
4295     @Test(dataProvider = "byteUnaryOpMaskProvider")
4296     static void expandByte128VectorTests(IntFunction<byte[]> fa,
4297                                                 IntFunction<boolean[]> fm) {
4298         byte[] a = fa.apply(SPECIES.length());
4299         byte[] r = fr.apply(SPECIES.length());
4300         boolean[] mask = fm.apply(SPECIES.length());
4301         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4302 
4303         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4304             for (int i = 0; i < a.length; i += SPECIES.length()) {
4305                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4306                 av.expand(vmask).intoArray(r, i);
4307             }
4308         }
4309 
4310         assertexpandArraysEquals(r, a, mask, SPECIES.length());
4311     }
4312     @Test(dataProvider = "byteUnaryOpProvider")
4313     static void getByte128VectorTests(IntFunction<byte[]> fa) {
4314         byte[] a = fa.apply(SPECIES.length());
4315         byte[] r = fr.apply(SPECIES.length());
4316 
4317         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4318             for (int i = 0; i < a.length; i += SPECIES.length()) {
4319                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4320                 int num_lanes = SPECIES.length();
4321                 // Manually unroll because full unroll happens after intrinsification.
4322                 // Unroll is needed because get intrinsic requires for index to be a known constant.
4323                 if (num_lanes == 1) {
4324                     r[i]=av.lane(0);
4325                 } else if (num_lanes == 2) {
4326                     r[i]=av.lane(0);
4327                     r[i+1]=av.lane(1);
4328                 } else if (num_lanes == 4) {
4329                     r[i]=av.lane(0);
4330                     r[i+1]=av.lane(1);
4331                     r[i+2]=av.lane(2);

5566             }
5567         }
5568         return i - idx;
5569     }
5570 
5571     @Test(dataProvider = "maskProvider")
5572     static void maskFirstTrueByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5573         boolean[] a = fa.apply(SPECIES.length());
5574         int[] r = new int[a.length];
5575 
5576         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5577             for (int i = 0; i < a.length; i += SPECIES.length()) {
5578                 var vmask = SPECIES.loadMask(a, i);
5579                 r[i] = vmask.firstTrue();
5580             }
5581         }
5582 
5583         assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskFirstTrue);
5584     }
5585 
5586     @Test(dataProvider = "maskProvider")
5587     static void maskCompressByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5588         int trueCount = 0;
5589         boolean[] a = fa.apply(SPECIES.length());
5590 
5591         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5592             for (int i = 0; i < a.length; i += SPECIES.length()) {
5593                 var vmask = SPECIES.loadMask(a, i);
5594                 trueCount = vmask.trueCount();
5595                 var rmask = vmask.compress();
5596                 for (int j = 0; j < SPECIES.length(); j++)  {
5597                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5598                 }
5599             }
5600         }
5601     }
5602 
5603     @DataProvider
5604     public static Object[][] longMaskProvider() {
5605         return new Object[][]{
5606                 {0xFFFFFFFFFFFFFFFFL},
5607                 {0x0000000000000000L},
5608                 {0x5555555555555555L},
5609                 {0x0123456789abcdefL},
5610         };
5611     }
5612 
5613     @Test(dataProvider = "longMaskProvider")
5614     static void maskFromToLongByte128VectorTestsSmokeTest(long inputLong) {
5615         var vmask = VectorMask.fromLong(SPECIES, inputLong);
5616         long outputLong = vmask.toLong();
5617         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
5618     }
5619 
5620     @DataProvider
5621     public static Object[][] offsetProvider() {
5622         return new Object[][]{
< prev index next >