< prev index next >

test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java

Print this page

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

















































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

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




































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

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

















5506 
5507     @DataProvider
5508     public static Object[][] offsetProvider() {
5509         return new Object[][]{
5510                 {0},
5511                 {-1},
5512                 {+1},
5513                 {+2},
5514                 {-2},
5515         };
5516     }
5517 
5518     @Test(dataProvider = "offsetProvider")
5519     static void indexInRangeByteMaxVectorTestsSmokeTest(int offset) {
5520         int limit = SPECIES.length() * BUFFER_REPS;
5521         for (int i = 0; i < limit; i += SPECIES.length()) {
5522             var actualMask = SPECIES.indexInRange(i + offset, limit);
5523             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5524             assert(actualMask.equals(expectedMask));
5525             for (int j = 0; j < SPECIES.length(); j++)  {

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

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

5571             }
5572         }
5573         return i - idx;
5574     }
5575 
5576     @Test(dataProvider = "maskProvider")
5577     static void maskFirstTrueByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5578         boolean[] a = fa.apply(SPECIES.length());
5579         int[] r = new int[a.length];
5580 
5581         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5582             for (int i = 0; i < a.length; i += SPECIES.length()) {
5583                 var vmask = SPECIES.loadMask(a, i);
5584                 r[i] = vmask.firstTrue();
5585             }
5586         }
5587 
5588         assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskFirstTrue);
5589     }
5590 
5591     @Test(dataProvider = "maskProvider")
5592     static void maskCompressByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5593         int trueCount = 0;
5594         boolean[] a = fa.apply(SPECIES.length());
5595 
5596         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5597             for (int i = 0; i < a.length; i += SPECIES.length()) {
5598                 var vmask = SPECIES.loadMask(a, i);
5599                 trueCount = vmask.trueCount();
5600                 var rmask = vmask.compress();
5601                 for (int j = 0; j < SPECIES.length(); j++)  {
5602                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5603                 }
5604             }
5605         }
5606     }
5607 
5608 
5609     @DataProvider
5610     public static Object[][] offsetProvider() {
5611         return new Object[][]{
5612                 {0},
5613                 {-1},
5614                 {+1},
5615                 {+2},
5616                 {-2},
5617         };
5618     }
5619 
5620     @Test(dataProvider = "offsetProvider")
5621     static void indexInRangeByteMaxVectorTestsSmokeTest(int offset) {
5622         int limit = SPECIES.length() * BUFFER_REPS;
5623         for (int i = 0; i < limit; i += SPECIES.length()) {
5624             var actualMask = SPECIES.indexInRange(i + offset, limit);
5625             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5626             assert(actualMask.equals(expectedMask));
5627             for (int j = 0; j < SPECIES.length(); j++)  {
< prev index next >