< prev index next >

test/jdk/jdk/incubator/vector/Int512VectorTests.java

Print this page

 242             } else {
 243                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 244             }
 245         }
 246     }
 247 
 248     static void assertRearrangeArraysEquals(int[] r, int[] 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(int[] r, int[] a, int[] 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(int[] r, int[] 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()])

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




































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

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

















5455     @DataProvider
5456     public static Object[][] longMaskProvider() {
5457         return new Object[][]{
5458                 {0xFFFFFFFFFFFFFFFFL},
5459                 {0x0000000000000000L},
5460                 {0x5555555555555555L},
5461                 {0x0123456789abcdefL},
5462         };
5463     }
5464 
5465     @Test(dataProvider = "longMaskProvider")
5466     static void maskFromToLongInt512VectorTestsSmokeTest(long inputLong) {
5467         var vmask = VectorMask.fromLong(SPECIES, inputLong);
5468         long outputLong = vmask.toLong();
5469         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
5470     }
5471 
5472     @DataProvider
5473     public static Object[][] offsetProvider() {
5474         return new Object[][]{

 242             } else {
 243                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 244             }
 245         }
 246     }
 247 
 248     static void assertRearrangeArraysEquals(int[] r, int[] 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(int[] r, int[] 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], (int)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], (int)0, "at index #" + idx);
 283             }
 284         }
 285     }
 286 
 287     static void assertexpandArraysEquals(int[] r, int[] 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], (int)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], (int)0, "at index #" + idx);
 307             }
 308         }
 309     }
 310 
 311     static void assertSelectFromArraysEquals(int[] r, int[] a, int[] 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(int[] r, int[] 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()])

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

5520             }
5521         }
5522         return i - idx;
5523     }
5524 
5525     @Test(dataProvider = "maskProvider")
5526     static void maskFirstTrueInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5527         boolean[] a = fa.apply(SPECIES.length());
5528         int[] r = new int[a.length];
5529 
5530         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5531             for (int i = 0; i < a.length; i += SPECIES.length()) {
5532                 var vmask = SPECIES.loadMask(a, i);
5533                 r[i] = vmask.firstTrue();
5534             }
5535         }
5536 
5537         assertMaskReductionArraysEquals(r, a, Int512VectorTests::maskFirstTrue);
5538     }
5539 
5540     @Test(dataProvider = "maskProvider")
5541     static void maskCompressInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5542         int trueCount = 0;
5543         boolean[] a = fa.apply(SPECIES.length());
5544 
5545         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5546             for (int i = 0; i < a.length; i += SPECIES.length()) {
5547                 var vmask = SPECIES.loadMask(a, i);
5548                 trueCount = vmask.trueCount();
5549                 var rmask = vmask.compress();
5550                 for (int j = 0; j < SPECIES.length(); j++)  {
5551                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5552                 }
5553             }
5554         }
5555     }
5556 
5557     @DataProvider
5558     public static Object[][] longMaskProvider() {
5559         return new Object[][]{
5560                 {0xFFFFFFFFFFFFFFFFL},
5561                 {0x0000000000000000L},
5562                 {0x5555555555555555L},
5563                 {0x0123456789abcdefL},
5564         };
5565     }
5566 
5567     @Test(dataProvider = "longMaskProvider")
5568     static void maskFromToLongInt512VectorTestsSmokeTest(long inputLong) {
5569         var vmask = VectorMask.fromLong(SPECIES, inputLong);
5570         long outputLong = vmask.toLong();
5571         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
5572     }
5573 
5574     @DataProvider
5575     public static Object[][] offsetProvider() {
5576         return new Object[][]{
< prev index next >