< prev index next >

test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java

Print this page

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

4202         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
4203     }
4204 
4205     @Test(dataProvider = "shortUnaryOpShuffleMaskProvider")
4206     static void RearrangeShortMaxVectorTestsMaskedSmokeTest(IntFunction<short[]> fa,
4207                                                           BiFunction<Integer,Integer,int[]> fs,
4208                                                           IntFunction<boolean[]> fm) {
4209         short[] a = fa.apply(SPECIES.length());
4210         int[] order = fs.apply(a.length, SPECIES.length());
4211         short[] r = fr.apply(SPECIES.length());
4212         boolean[] mask = fm.apply(SPECIES.length());
4213         VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4214 
4215         for (int i = 0; i < a.length; i += SPECIES.length()) {
4216             ShortVector av = ShortVector.fromArray(SPECIES, a, i);
4217             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
4218         }
4219 
4220         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
4221     }




































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

5465             }
5466         }
5467         return i - idx;
5468     }
5469 
5470     @Test(dataProvider = "maskProvider")
5471     static void maskFirstTrueShortMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5472         boolean[] a = fa.apply(SPECIES.length());
5473         int[] r = new int[a.length];
5474 
5475         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5476             for (int i = 0; i < a.length; i += SPECIES.length()) {
5477                 var vmask = SPECIES.loadMask(a, i);
5478                 r[i] = vmask.firstTrue();
5479             }
5480         }
5481 
5482         assertMaskReductionArraysEquals(r, a, ShortMaxVectorTests::maskFirstTrue);
5483     }
5484 

















5485 
5486     @DataProvider
5487     public static Object[][] offsetProvider() {
5488         return new Object[][]{
5489                 {0},
5490                 {-1},
5491                 {+1},
5492                 {+2},
5493                 {-2},
5494         };
5495     }
5496 
5497     @Test(dataProvider = "offsetProvider")
5498     static void indexInRangeShortMaxVectorTestsSmokeTest(int offset) {
5499         int limit = SPECIES.length() * BUFFER_REPS;
5500         for (int i = 0; i < limit; i += SPECIES.length()) {
5501             var actualMask = SPECIES.indexInRange(i + offset, limit);
5502             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5503             assert(actualMask.equals(expectedMask));
5504             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(short[] r, short[] 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(short[] r, short[] 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], (short)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], (short)0, "at index #" + idx);
 288             }
 289         }
 290     }
 291 
 292     static void assertexpandArraysEquals(short[] r, short[] 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], (short)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], (short)0, "at index #" + idx);
 312             }
 313         }
 314     }
 315 
 316     static void assertSelectFromArraysEquals(short[] r, short[] a, short[] 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(short[] r, short[] 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()])

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

5550             }
5551         }
5552         return i - idx;
5553     }
5554 
5555     @Test(dataProvider = "maskProvider")
5556     static void maskFirstTrueShortMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5557         boolean[] a = fa.apply(SPECIES.length());
5558         int[] r = new int[a.length];
5559 
5560         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5561             for (int i = 0; i < a.length; i += SPECIES.length()) {
5562                 var vmask = SPECIES.loadMask(a, i);
5563                 r[i] = vmask.firstTrue();
5564             }
5565         }
5566 
5567         assertMaskReductionArraysEquals(r, a, ShortMaxVectorTests::maskFirstTrue);
5568     }
5569 
5570     @Test(dataProvider = "maskProvider")
5571     static void maskCompressShortMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5572         int trueCount = 0;
5573         boolean[] a = fa.apply(SPECIES.length());
5574 
5575         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5576             for (int i = 0; i < a.length; i += SPECIES.length()) {
5577                 var vmask = SPECIES.loadMask(a, i);
5578                 trueCount = vmask.trueCount();
5579                 var rmask = vmask.compress();
5580                 for (int j = 0; j < SPECIES.length(); j++)  {
5581                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5582                 }
5583             }
5584         }
5585     }
5586 
5587 
5588     @DataProvider
5589     public static Object[][] offsetProvider() {
5590         return new Object[][]{
5591                 {0},
5592                 {-1},
5593                 {+1},
5594                 {+2},
5595                 {-2},
5596         };
5597     }
5598 
5599     @Test(dataProvider = "offsetProvider")
5600     static void indexInRangeShortMaxVectorTestsSmokeTest(int offset) {
5601         int limit = SPECIES.length() * BUFFER_REPS;
5602         for (int i = 0; i < limit; i += SPECIES.length()) {
5603             var actualMask = SPECIES.indexInRange(i + offset, limit);
5604             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5605             assert(actualMask.equals(expectedMask));
5606             for (int j = 0; j < SPECIES.length(); j++)  {
< prev index next >