< prev index next >

test/jdk/jdk/incubator/vector/LongMaxVectorTests.java

Print this page

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

















































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

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




































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

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

















5344 
5345     @DataProvider
5346     public static Object[][] offsetProvider() {
5347         return new Object[][]{
5348                 {0},
5349                 {-1},
5350                 {+1},
5351                 {+2},
5352                 {-2},
5353         };
5354     }
5355 
5356     @Test(dataProvider = "offsetProvider")
5357     static void indexInRangeLongMaxVectorTestsSmokeTest(int offset) {
5358         int limit = SPECIES.length() * BUFFER_REPS;
5359         for (int i = 0; i < limit; i += SPECIES.length()) {
5360             var actualMask = SPECIES.indexInRange(i + offset, limit);
5361             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5362             assert(actualMask.equals(expectedMask));
5363             for (int j = 0; j < SPECIES.length(); j++)  {

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

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

5409             }
5410         }
5411         return i - idx;
5412     }
5413 
5414     @Test(dataProvider = "maskProvider")
5415     static void maskFirstTrueLongMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5416         boolean[] a = fa.apply(SPECIES.length());
5417         int[] r = new int[a.length];
5418 
5419         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5420             for (int i = 0; i < a.length; i += SPECIES.length()) {
5421                 var vmask = SPECIES.loadMask(a, i);
5422                 r[i] = vmask.firstTrue();
5423             }
5424         }
5425 
5426         assertMaskReductionArraysEquals(r, a, LongMaxVectorTests::maskFirstTrue);
5427     }
5428 
5429     @Test(dataProvider = "maskProvider")
5430     static void maskCompressLongMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5431         int trueCount = 0;
5432         boolean[] a = fa.apply(SPECIES.length());
5433 
5434         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5435             for (int i = 0; i < a.length; i += SPECIES.length()) {
5436                 var vmask = SPECIES.loadMask(a, i);
5437                 trueCount = vmask.trueCount();
5438                 var rmask = vmask.compress();
5439                 for (int j = 0; j < SPECIES.length(); j++)  {
5440                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5441                 }
5442             }
5443         }
5444     }
5445 
5446 
5447     @DataProvider
5448     public static Object[][] offsetProvider() {
5449         return new Object[][]{
5450                 {0},
5451                 {-1},
5452                 {+1},
5453                 {+2},
5454                 {-2},
5455         };
5456     }
5457 
5458     @Test(dataProvider = "offsetProvider")
5459     static void indexInRangeLongMaxVectorTestsSmokeTest(int offset) {
5460         int limit = SPECIES.length() * BUFFER_REPS;
5461         for (int i = 0; i < limit; i += SPECIES.length()) {
5462             var actualMask = SPECIES.indexInRange(i + offset, limit);
5463             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5464             assert(actualMask.equals(expectedMask));
5465             for (int j = 0; j < SPECIES.length(); j++)  {
< prev index next >