< prev index next >

test/jdk/jdk/incubator/vector/IntMaxVectorTests.java

Print this page

 247             } else {
 248                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 249             }
 250         }
 251     }
 252 
 253     static void assertRearrangeArraysEquals(int[] r, int[] 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(int[] r, int[] a, int[] 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(int[] r, int[] 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()])

4177         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
4178     }
4179 
4180     @Test(dataProvider = "intUnaryOpShuffleMaskProvider")
4181     static void RearrangeIntMaxVectorTestsMaskedSmokeTest(IntFunction<int[]> fa,
4182                                                           BiFunction<Integer,Integer,int[]> fs,
4183                                                           IntFunction<boolean[]> fm) {
4184         int[] a = fa.apply(SPECIES.length());
4185         int[] order = fs.apply(a.length, SPECIES.length());
4186         int[] r = fr.apply(SPECIES.length());
4187         boolean[] mask = fm.apply(SPECIES.length());
4188         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4189 
4190         for (int i = 0; i < a.length; i += SPECIES.length()) {
4191             IntVector av = IntVector.fromArray(SPECIES, a, i);
4192             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
4193         }
4194 
4195         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
4196     }




































4197     @Test(dataProvider = "intUnaryOpProvider")
4198     static void getIntMaxVectorTests(IntFunction<int[]> fa) {
4199         int[] a = fa.apply(SPECIES.length());
4200         int[] r = fr.apply(SPECIES.length());
4201 
4202         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4203             for (int i = 0; i < a.length; i += SPECIES.length()) {
4204                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4205                 int num_lanes = SPECIES.length();
4206                 // Manually unroll because full unroll happens after intrinsification.
4207                 // Unroll is needed because get intrinsic requires for index to be a known constant.
4208                 if (num_lanes == 1) {
4209                     r[i]=av.lane(0);
4210                 } else if (num_lanes == 2) {
4211                     r[i]=av.lane(0);
4212                     r[i+1]=av.lane(1);
4213                 } else if (num_lanes == 4) {
4214                     r[i]=av.lane(0);
4215                     r[i+1]=av.lane(1);
4216                     r[i+2]=av.lane(2);

5440             }
5441         }
5442         return i - idx;
5443     }
5444 
5445     @Test(dataProvider = "maskProvider")
5446     static void maskFirstTrueIntMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5447         boolean[] a = fa.apply(SPECIES.length());
5448         int[] r = new int[a.length];
5449 
5450         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5451             for (int i = 0; i < a.length; i += SPECIES.length()) {
5452                 var vmask = SPECIES.loadMask(a, i);
5453                 r[i] = vmask.firstTrue();
5454             }
5455         }
5456 
5457         assertMaskReductionArraysEquals(r, a, IntMaxVectorTests::maskFirstTrue);
5458     }
5459 

















5460 
5461     @DataProvider
5462     public static Object[][] offsetProvider() {
5463         return new Object[][]{
5464                 {0},
5465                 {-1},
5466                 {+1},
5467                 {+2},
5468                 {-2},
5469         };
5470     }
5471 
5472     @Test(dataProvider = "offsetProvider")
5473     static void indexInRangeIntMaxVectorTestsSmokeTest(int offset) {
5474         int limit = SPECIES.length() * BUFFER_REPS;
5475         for (int i = 0; i < limit; i += SPECIES.length()) {
5476             var actualMask = SPECIES.indexInRange(i + offset, limit);
5477             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5478             assert(actualMask.equals(expectedMask));
5479             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(int[] r, int[] 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(int[] r, int[] 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], (int)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], (int)0, "at index #" + idx);
 288             }
 289         }
 290     }
 291 
 292     static void assertexpandArraysEquals(int[] r, int[] 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], (int)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], (int)0, "at index #" + idx);
 312             }
 313         }
 314     }
 315 
 316     static void assertSelectFromArraysEquals(int[] r, int[] a, int[] 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(int[] r, int[] 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()])

4226         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
4227     }
4228 
4229     @Test(dataProvider = "intUnaryOpShuffleMaskProvider")
4230     static void RearrangeIntMaxVectorTestsMaskedSmokeTest(IntFunction<int[]> fa,
4231                                                           BiFunction<Integer,Integer,int[]> fs,
4232                                                           IntFunction<boolean[]> fm) {
4233         int[] a = fa.apply(SPECIES.length());
4234         int[] order = fs.apply(a.length, SPECIES.length());
4235         int[] r = fr.apply(SPECIES.length());
4236         boolean[] mask = fm.apply(SPECIES.length());
4237         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4238 
4239         for (int i = 0; i < a.length; i += SPECIES.length()) {
4240             IntVector av = IntVector.fromArray(SPECIES, a, i);
4241             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
4242         }
4243 
4244         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
4245     }
4246 
4247     @Test(dataProvider = "intUnaryOpMaskProvider")
4248     static void compressIntMaxVectorTests(IntFunction<int[]> fa,
4249                                                 IntFunction<boolean[]> fm) {
4250         int[] a = fa.apply(SPECIES.length());
4251         int[] r = fr.apply(SPECIES.length());
4252         boolean[] mask = fm.apply(SPECIES.length());
4253         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4254 
4255         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4256             for (int i = 0; i < a.length; i += SPECIES.length()) {
4257                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4258                 av.compress(vmask).intoArray(r, i);
4259             }
4260         }
4261 
4262         assertcompressArraysEquals(r, a, mask, SPECIES.length());
4263     }
4264 
4265     @Test(dataProvider = "intUnaryOpMaskProvider")
4266     static void expandIntMaxVectorTests(IntFunction<int[]> fa,
4267                                                 IntFunction<boolean[]> fm) {
4268         int[] a = fa.apply(SPECIES.length());
4269         int[] r = fr.apply(SPECIES.length());
4270         boolean[] mask = fm.apply(SPECIES.length());
4271         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4272 
4273         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4274             for (int i = 0; i < a.length; i += SPECIES.length()) {
4275                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4276                 av.expand(vmask).intoArray(r, i);
4277             }
4278         }
4279 
4280         assertexpandArraysEquals(r, a, mask, SPECIES.length());
4281     }
4282     @Test(dataProvider = "intUnaryOpProvider")
4283     static void getIntMaxVectorTests(IntFunction<int[]> fa) {
4284         int[] a = fa.apply(SPECIES.length());
4285         int[] r = fr.apply(SPECIES.length());
4286 
4287         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4288             for (int i = 0; i < a.length; i += SPECIES.length()) {
4289                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4290                 int num_lanes = SPECIES.length();
4291                 // Manually unroll because full unroll happens after intrinsification.
4292                 // Unroll is needed because get intrinsic requires for index to be a known constant.
4293                 if (num_lanes == 1) {
4294                     r[i]=av.lane(0);
4295                 } else if (num_lanes == 2) {
4296                     r[i]=av.lane(0);
4297                     r[i+1]=av.lane(1);
4298                 } else if (num_lanes == 4) {
4299                     r[i]=av.lane(0);
4300                     r[i+1]=av.lane(1);
4301                     r[i+2]=av.lane(2);

5525             }
5526         }
5527         return i - idx;
5528     }
5529 
5530     @Test(dataProvider = "maskProvider")
5531     static void maskFirstTrueIntMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5532         boolean[] a = fa.apply(SPECIES.length());
5533         int[] r = new int[a.length];
5534 
5535         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5536             for (int i = 0; i < a.length; i += SPECIES.length()) {
5537                 var vmask = SPECIES.loadMask(a, i);
5538                 r[i] = vmask.firstTrue();
5539             }
5540         }
5541 
5542         assertMaskReductionArraysEquals(r, a, IntMaxVectorTests::maskFirstTrue);
5543     }
5544 
5545     @Test(dataProvider = "maskProvider")
5546     static void maskCompressIntMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5547         int trueCount = 0;
5548         boolean[] a = fa.apply(SPECIES.length());
5549 
5550         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5551             for (int i = 0; i < a.length; i += SPECIES.length()) {
5552                 var vmask = SPECIES.loadMask(a, i);
5553                 trueCount = vmask.trueCount();
5554                 var rmask = vmask.compress();
5555                 for (int j = 0; j < SPECIES.length(); j++)  {
5556                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5557                 }
5558             }
5559         }
5560     }
5561 
5562 
5563     @DataProvider
5564     public static Object[][] offsetProvider() {
5565         return new Object[][]{
5566                 {0},
5567                 {-1},
5568                 {+1},
5569                 {+2},
5570                 {-2},
5571         };
5572     }
5573 
5574     @Test(dataProvider = "offsetProvider")
5575     static void indexInRangeIntMaxVectorTestsSmokeTest(int offset) {
5576         int limit = SPECIES.length() * BUFFER_REPS;
5577         for (int i = 0; i < limit; i += SPECIES.length()) {
5578             var actualMask = SPECIES.indexInRange(i + offset, limit);
5579             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5580             assert(actualMask.equals(expectedMask));
5581             for (int j = 0; j < SPECIES.length(); j++)  {
< prev index next >