< prev index next >

test/jdk/jdk/incubator/vector/Short128VectorTests.java

Print this page

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

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




































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

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

















5480     @DataProvider
5481     public static Object[][] longMaskProvider() {
5482         return new Object[][]{
5483                 {0xFFFFFFFFFFFFFFFFL},
5484                 {0x0000000000000000L},
5485                 {0x5555555555555555L},
5486                 {0x0123456789abcdefL},
5487         };
5488     }
5489 
5490     @Test(dataProvider = "longMaskProvider")
5491     static void maskFromToLongShort128VectorTestsSmokeTest(long inputLong) {
5492         var vmask = VectorMask.fromLong(SPECIES, inputLong);
5493         long outputLong = vmask.toLong();
5494         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
5495     }
5496 
5497     @DataProvider
5498     public static Object[][] offsetProvider() {
5499         return new Object[][]{

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

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

5545             }
5546         }
5547         return i - idx;
5548     }
5549 
5550     @Test(dataProvider = "maskProvider")
5551     static void maskFirstTrueShort128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5552         boolean[] a = fa.apply(SPECIES.length());
5553         int[] r = new int[a.length];
5554 
5555         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5556             for (int i = 0; i < a.length; i += SPECIES.length()) {
5557                 var vmask = SPECIES.loadMask(a, i);
5558                 r[i] = vmask.firstTrue();
5559             }
5560         }
5561 
5562         assertMaskReductionArraysEquals(r, a, Short128VectorTests::maskFirstTrue);
5563     }
5564 
5565     @Test(dataProvider = "maskProvider")
5566     static void maskCompressShort128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5567         int trueCount = 0;
5568         boolean[] a = fa.apply(SPECIES.length());
5569 
5570         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5571             for (int i = 0; i < a.length; i += SPECIES.length()) {
5572                 var vmask = SPECIES.loadMask(a, i);
5573                 trueCount = vmask.trueCount();
5574                 var rmask = vmask.compress();
5575                 for (int j = 0; j < SPECIES.length(); j++)  {
5576                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5577                 }
5578             }
5579         }
5580     }
5581 
5582     @DataProvider
5583     public static Object[][] longMaskProvider() {
5584         return new Object[][]{
5585                 {0xFFFFFFFFFFFFFFFFL},
5586                 {0x0000000000000000L},
5587                 {0x5555555555555555L},
5588                 {0x0123456789abcdefL},
5589         };
5590     }
5591 
5592     @Test(dataProvider = "longMaskProvider")
5593     static void maskFromToLongShort128VectorTestsSmokeTest(long inputLong) {
5594         var vmask = VectorMask.fromLong(SPECIES, inputLong);
5595         long outputLong = vmask.toLong();
5596         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
5597     }
5598 
5599     @DataProvider
5600     public static Object[][] offsetProvider() {
5601         return new Object[][]{
< prev index next >