< prev index next >

test/jdk/jdk/incubator/vector/Long256VectorTests.java

Print this page

 199             } else {
 200                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 201             }
 202         }
 203     }
 204 
 205     static void assertRearrangeArraysEquals(long[] r, long[] a, int[] order, int vector_len) {
 206         int i = 0, j = 0;
 207         try {
 208             for (; i < a.length; i += vector_len) {
 209                 for (j = 0; j < vector_len; j++) {
 210                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 211                 }
 212             }
 213         } catch (AssertionError e) {
 214             int idx = i + j;
 215             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 216         }
 217     }
 218 

















































 219     static void assertSelectFromArraysEquals(long[] r, long[] a, long[] order, int vector_len) {
 220         int i = 0, j = 0;
 221         try {
 222             for (; i < a.length; i += vector_len) {
 223                 for (j = 0; j < vector_len; j++) {
 224                     Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 225                 }
 226             }
 227         } catch (AssertionError e) {
 228             int idx = i + j;
 229             Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
 230         }
 231     }
 232 
 233     static void assertRearrangeArraysEquals(long[] r, long[] a, int[] order, boolean[] mask, int vector_len) {
 234         int i = 0, j = 0;
 235         try {
 236             for (; i < a.length; i += vector_len) {
 237                 for (j = 0; j < vector_len; j++) {
 238                     if (mask[j % SPECIES.length()])

4122         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
4123     }
4124 
4125     @Test(dataProvider = "longUnaryOpShuffleMaskProvider")
4126     static void RearrangeLong256VectorTestsMaskedSmokeTest(IntFunction<long[]> fa,
4127                                                           BiFunction<Integer,Integer,int[]> fs,
4128                                                           IntFunction<boolean[]> fm) {
4129         long[] a = fa.apply(SPECIES.length());
4130         int[] order = fs.apply(a.length, SPECIES.length());
4131         long[] r = fr.apply(SPECIES.length());
4132         boolean[] mask = fm.apply(SPECIES.length());
4133         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4134 
4135         for (int i = 0; i < a.length; i += SPECIES.length()) {
4136             LongVector av = LongVector.fromArray(SPECIES, a, i);
4137             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
4138         }
4139 
4140         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
4141     }




































4142     @Test(dataProvider = "longUnaryOpProvider")
4143     static void getLong256VectorTests(IntFunction<long[]> fa) {
4144         long[] a = fa.apply(SPECIES.length());
4145         long[] r = fr.apply(SPECIES.length());
4146 
4147         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4148             for (int i = 0; i < a.length; i += SPECIES.length()) {
4149                 LongVector av = LongVector.fromArray(SPECIES, a, i);
4150                 int num_lanes = SPECIES.length();
4151                 // Manually unroll because full unroll happens after intrinsification.
4152                 // Unroll is needed because get intrinsic requires for index to be a known constant.
4153                 if (num_lanes == 1) {
4154                     r[i]=av.lane(0);
4155                 } else if (num_lanes == 2) {
4156                     r[i]=av.lane(0);
4157                     r[i+1]=av.lane(1);
4158                 } else if (num_lanes == 4) {
4159                     r[i]=av.lane(0);
4160                     r[i+1]=av.lane(1);
4161                     r[i+2]=av.lane(2);

5319             }
5320         }
5321         return i - idx;
5322     }
5323 
5324     @Test(dataProvider = "maskProvider")
5325     static void maskFirstTrueLong256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5326         boolean[] a = fa.apply(SPECIES.length());
5327         int[] r = new int[a.length];
5328 
5329         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5330             for (int i = 0; i < a.length; i += SPECIES.length()) {
5331                 var vmask = SPECIES.loadMask(a, i);
5332                 r[i] = vmask.firstTrue();
5333             }
5334         }
5335 
5336         assertMaskReductionArraysEquals(r, a, Long256VectorTests::maskFirstTrue);
5337     }
5338 

















5339     @DataProvider
5340     public static Object[][] longMaskProvider() {
5341         return new Object[][]{
5342                 {0xFFFFFFFFFFFFFFFFL},
5343                 {0x0000000000000000L},
5344                 {0x5555555555555555L},
5345                 {0x0123456789abcdefL},
5346         };
5347     }
5348 
5349     @Test(dataProvider = "longMaskProvider")
5350     static void maskFromToLongLong256VectorTestsSmokeTest(long inputLong) {
5351         var vmask = VectorMask.fromLong(SPECIES, inputLong);
5352         long outputLong = vmask.toLong();
5353         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
5354     }
5355 
5356     @DataProvider
5357     public static Object[][] offsetProvider() {
5358         return new Object[][]{

 199             } else {
 200                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 201             }
 202         }
 203     }
 204 
 205     static void assertRearrangeArraysEquals(long[] r, long[] a, int[] order, int vector_len) {
 206         int i = 0, j = 0;
 207         try {
 208             for (; i < a.length; i += vector_len) {
 209                 for (j = 0; j < vector_len; j++) {
 210                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 211                 }
 212             }
 213         } catch (AssertionError e) {
 214             int idx = i + j;
 215             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 216         }
 217     }
 218 
 219     static void assertcompressArraysEquals(long[] r, long[] a, boolean[] m, int vector_len) {
 220         int i = 0, j = 0, k = 0;
 221         try {
 222             for (; i < a.length; i += vector_len) {
 223                 k = 0;
 224                 for (j = 0; j < vector_len; j++) {
 225                     if (m[(i + j) % SPECIES.length()]) {
 226                         Assert.assertEquals(r[i + k], a[i + j]);
 227                         k++;
 228                     }
 229                 }
 230                 for (; k < vector_len; k++) {
 231                     Assert.assertEquals(r[i + k], (long)0);
 232                 }
 233             }
 234         } catch (AssertionError e) {
 235             int idx = i + k;
 236             if (m[(i + j) % SPECIES.length()]) {
 237                 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx);
 238             } else {
 239                 Assert.assertEquals(r[idx], (long)0, "at index #" + idx);
 240             }
 241         }
 242     }
 243 
 244     static void assertexpandArraysEquals(long[] r, long[] a, boolean[] m, int vector_len) {
 245         int i = 0, j = 0, k = 0;
 246         try {
 247             for (; i < a.length; i += vector_len) {
 248                 k = 0;
 249                 for (j = 0; j < vector_len; j++) {
 250                     if (m[(i + j) % SPECIES.length()]) {
 251                         Assert.assertEquals(r[i + j], a[i + k]);
 252                         k++;
 253                     } else {
 254                         Assert.assertEquals(r[i + j], (long)0);
 255                     }
 256                 }
 257             }
 258         } catch (AssertionError e) {
 259             int idx = i + j;
 260             if (m[idx % SPECIES.length()]) {
 261                 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx);
 262             } else {
 263                 Assert.assertEquals(r[idx], (long)0, "at index #" + idx);
 264             }
 265         }
 266     }
 267 
 268     static void assertSelectFromArraysEquals(long[] r, long[] a, long[] order, int vector_len) {
 269         int i = 0, j = 0;
 270         try {
 271             for (; i < a.length; i += vector_len) {
 272                 for (j = 0; j < vector_len; j++) {
 273                     Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 274                 }
 275             }
 276         } catch (AssertionError e) {
 277             int idx = i + j;
 278             Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
 279         }
 280     }
 281 
 282     static void assertRearrangeArraysEquals(long[] r, long[] a, int[] order, boolean[] mask, int vector_len) {
 283         int i = 0, j = 0;
 284         try {
 285             for (; i < a.length; i += vector_len) {
 286                 for (j = 0; j < vector_len; j++) {
 287                     if (mask[j % SPECIES.length()])

4171         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
4172     }
4173 
4174     @Test(dataProvider = "longUnaryOpShuffleMaskProvider")
4175     static void RearrangeLong256VectorTestsMaskedSmokeTest(IntFunction<long[]> fa,
4176                                                           BiFunction<Integer,Integer,int[]> fs,
4177                                                           IntFunction<boolean[]> fm) {
4178         long[] a = fa.apply(SPECIES.length());
4179         int[] order = fs.apply(a.length, SPECIES.length());
4180         long[] r = fr.apply(SPECIES.length());
4181         boolean[] mask = fm.apply(SPECIES.length());
4182         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4183 
4184         for (int i = 0; i < a.length; i += SPECIES.length()) {
4185             LongVector av = LongVector.fromArray(SPECIES, a, i);
4186             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
4187         }
4188 
4189         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
4190     }
4191 
4192     @Test(dataProvider = "longUnaryOpMaskProvider")
4193     static void compressLong256VectorTests(IntFunction<long[]> fa,
4194                                                 IntFunction<boolean[]> fm) {
4195         long[] a = fa.apply(SPECIES.length());
4196         long[] r = fr.apply(SPECIES.length());
4197         boolean[] mask = fm.apply(SPECIES.length());
4198         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4199 
4200         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4201             for (int i = 0; i < a.length; i += SPECIES.length()) {
4202                 LongVector av = LongVector.fromArray(SPECIES, a, i);
4203                 av.compress(vmask).intoArray(r, i);
4204             }
4205         }
4206 
4207         assertcompressArraysEquals(r, a, mask, SPECIES.length());
4208     }
4209 
4210     @Test(dataProvider = "longUnaryOpMaskProvider")
4211     static void expandLong256VectorTests(IntFunction<long[]> fa,
4212                                                 IntFunction<boolean[]> fm) {
4213         long[] a = fa.apply(SPECIES.length());
4214         long[] r = fr.apply(SPECIES.length());
4215         boolean[] mask = fm.apply(SPECIES.length());
4216         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4217 
4218         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4219             for (int i = 0; i < a.length; i += SPECIES.length()) {
4220                 LongVector av = LongVector.fromArray(SPECIES, a, i);
4221                 av.expand(vmask).intoArray(r, i);
4222             }
4223         }
4224 
4225         assertexpandArraysEquals(r, a, mask, SPECIES.length());
4226     }
4227     @Test(dataProvider = "longUnaryOpProvider")
4228     static void getLong256VectorTests(IntFunction<long[]> fa) {
4229         long[] a = fa.apply(SPECIES.length());
4230         long[] r = fr.apply(SPECIES.length());
4231 
4232         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4233             for (int i = 0; i < a.length; i += SPECIES.length()) {
4234                 LongVector av = LongVector.fromArray(SPECIES, a, i);
4235                 int num_lanes = SPECIES.length();
4236                 // Manually unroll because full unroll happens after intrinsification.
4237                 // Unroll is needed because get intrinsic requires for index to be a known constant.
4238                 if (num_lanes == 1) {
4239                     r[i]=av.lane(0);
4240                 } else if (num_lanes == 2) {
4241                     r[i]=av.lane(0);
4242                     r[i+1]=av.lane(1);
4243                 } else if (num_lanes == 4) {
4244                     r[i]=av.lane(0);
4245                     r[i+1]=av.lane(1);
4246                     r[i+2]=av.lane(2);

5404             }
5405         }
5406         return i - idx;
5407     }
5408 
5409     @Test(dataProvider = "maskProvider")
5410     static void maskFirstTrueLong256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5411         boolean[] a = fa.apply(SPECIES.length());
5412         int[] r = new int[a.length];
5413 
5414         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5415             for (int i = 0; i < a.length; i += SPECIES.length()) {
5416                 var vmask = SPECIES.loadMask(a, i);
5417                 r[i] = vmask.firstTrue();
5418             }
5419         }
5420 
5421         assertMaskReductionArraysEquals(r, a, Long256VectorTests::maskFirstTrue);
5422     }
5423 
5424     @Test(dataProvider = "maskProvider")
5425     static void maskCompressLong256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5426         int trueCount = 0;
5427         boolean[] a = fa.apply(SPECIES.length());
5428 
5429         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5430             for (int i = 0; i < a.length; i += SPECIES.length()) {
5431                 var vmask = SPECIES.loadMask(a, i);
5432                 trueCount = vmask.trueCount();
5433                 var rmask = vmask.compress();
5434                 for (int j = 0; j < SPECIES.length(); j++)  {
5435                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5436                 }
5437             }
5438         }
5439     }
5440 
5441     @DataProvider
5442     public static Object[][] longMaskProvider() {
5443         return new Object[][]{
5444                 {0xFFFFFFFFFFFFFFFFL},
5445                 {0x0000000000000000L},
5446                 {0x5555555555555555L},
5447                 {0x0123456789abcdefL},
5448         };
5449     }
5450 
5451     @Test(dataProvider = "longMaskProvider")
5452     static void maskFromToLongLong256VectorTestsSmokeTest(long inputLong) {
5453         var vmask = VectorMask.fromLong(SPECIES, inputLong);
5454         long outputLong = vmask.toLong();
5455         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
5456     }
5457 
5458     @DataProvider
5459     public static Object[][] offsetProvider() {
5460         return new Object[][]{
< prev index next >