< prev index next >

test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java

Print this page

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

3172         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
3173     }
3174 
3175     @Test(dataProvider = "floatUnaryOpShuffleMaskProvider")
3176     static void RearrangeFloatMaxVectorTestsMaskedSmokeTest(IntFunction<float[]> fa,
3177                                                           BiFunction<Integer,Integer,int[]> fs,
3178                                                           IntFunction<boolean[]> fm) {
3179         float[] a = fa.apply(SPECIES.length());
3180         int[] order = fs.apply(a.length, SPECIES.length());
3181         float[] r = fr.apply(SPECIES.length());
3182         boolean[] mask = fm.apply(SPECIES.length());
3183         VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3184 
3185         for (int i = 0; i < a.length; i += SPECIES.length()) {
3186             FloatVector av = FloatVector.fromArray(SPECIES, a, i);
3187             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
3188         }
3189 
3190         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
3191     }




































3192     @Test(dataProvider = "floatUnaryOpProvider")
3193     static void getFloatMaxVectorTests(IntFunction<float[]> fa) {
3194         float[] a = fa.apply(SPECIES.length());
3195         float[] r = fr.apply(SPECIES.length());
3196 
3197         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3198             for (int i = 0; i < a.length; i += SPECIES.length()) {
3199                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
3200                 int num_lanes = SPECIES.length();
3201                 // Manually unroll because full unroll happens after intrinsification.
3202                 // Unroll is needed because get intrinsic requires for index to be a known constant.
3203                 if (num_lanes == 1) {
3204                     r[i]=av.lane(0);
3205                 } else if (num_lanes == 2) {
3206                     r[i]=av.lane(0);
3207                     r[i+1]=av.lane(1);
3208                 } else if (num_lanes == 4) {
3209                     r[i]=av.lane(0);
3210                     r[i+1]=av.lane(1);
3211                     r[i+2]=av.lane(2);

4843             }
4844         }
4845         return i - idx;
4846     }
4847 
4848     @Test(dataProvider = "maskProvider")
4849     static void maskFirstTrueFloatMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4850         boolean[] a = fa.apply(SPECIES.length());
4851         int[] r = new int[a.length];
4852 
4853         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4854             for (int i = 0; i < a.length; i += SPECIES.length()) {
4855                 var vmask = SPECIES.loadMask(a, i);
4856                 r[i] = vmask.firstTrue();
4857             }
4858         }
4859 
4860         assertMaskReductionArraysEquals(r, a, FloatMaxVectorTests::maskFirstTrue);
4861     }
4862 

















4863 
4864     @DataProvider
4865     public static Object[][] offsetProvider() {
4866         return new Object[][]{
4867                 {0},
4868                 {-1},
4869                 {+1},
4870                 {+2},
4871                 {-2},
4872         };
4873     }
4874 
4875     @Test(dataProvider = "offsetProvider")
4876     static void indexInRangeFloatMaxVectorTestsSmokeTest(int offset) {
4877         int limit = SPECIES.length() * BUFFER_REPS;
4878         for (int i = 0; i < limit; i += SPECIES.length()) {
4879             var actualMask = SPECIES.indexInRange(i + offset, limit);
4880             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
4881             assert(actualMask.equals(expectedMask));
4882             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(float[] r, float[] 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(float[] r, float[] 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], (float)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], (float)0, "at index #" + idx);
 288             }
 289         }
 290     }
 291 
 292     static void assertexpandArraysEquals(float[] r, float[] 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], (float)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], (float)0, "at index #" + idx);
 312             }
 313         }
 314     }
 315 
 316     static void assertSelectFromArraysEquals(float[] r, float[] a, float[] 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(float[] r, float[] 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()])

3221         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
3222     }
3223 
3224     @Test(dataProvider = "floatUnaryOpShuffleMaskProvider")
3225     static void RearrangeFloatMaxVectorTestsMaskedSmokeTest(IntFunction<float[]> fa,
3226                                                           BiFunction<Integer,Integer,int[]> fs,
3227                                                           IntFunction<boolean[]> fm) {
3228         float[] a = fa.apply(SPECIES.length());
3229         int[] order = fs.apply(a.length, SPECIES.length());
3230         float[] r = fr.apply(SPECIES.length());
3231         boolean[] mask = fm.apply(SPECIES.length());
3232         VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3233 
3234         for (int i = 0; i < a.length; i += SPECIES.length()) {
3235             FloatVector av = FloatVector.fromArray(SPECIES, a, i);
3236             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
3237         }
3238 
3239         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
3240     }
3241 
3242     @Test(dataProvider = "floatUnaryOpMaskProvider")
3243     static void compressFloatMaxVectorTests(IntFunction<float[]> fa,
3244                                                 IntFunction<boolean[]> fm) {
3245         float[] a = fa.apply(SPECIES.length());
3246         float[] r = fr.apply(SPECIES.length());
3247         boolean[] mask = fm.apply(SPECIES.length());
3248         VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3249 
3250         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3251             for (int i = 0; i < a.length; i += SPECIES.length()) {
3252                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
3253                 av.compress(vmask).intoArray(r, i);
3254             }
3255         }
3256 
3257         assertcompressArraysEquals(r, a, mask, SPECIES.length());
3258     }
3259 
3260     @Test(dataProvider = "floatUnaryOpMaskProvider")
3261     static void expandFloatMaxVectorTests(IntFunction<float[]> fa,
3262                                                 IntFunction<boolean[]> fm) {
3263         float[] a = fa.apply(SPECIES.length());
3264         float[] r = fr.apply(SPECIES.length());
3265         boolean[] mask = fm.apply(SPECIES.length());
3266         VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3267 
3268         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3269             for (int i = 0; i < a.length; i += SPECIES.length()) {
3270                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
3271                 av.expand(vmask).intoArray(r, i);
3272             }
3273         }
3274 
3275         assertexpandArraysEquals(r, a, mask, SPECIES.length());
3276     }
3277     @Test(dataProvider = "floatUnaryOpProvider")
3278     static void getFloatMaxVectorTests(IntFunction<float[]> fa) {
3279         float[] a = fa.apply(SPECIES.length());
3280         float[] r = fr.apply(SPECIES.length());
3281 
3282         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3283             for (int i = 0; i < a.length; i += SPECIES.length()) {
3284                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
3285                 int num_lanes = SPECIES.length();
3286                 // Manually unroll because full unroll happens after intrinsification.
3287                 // Unroll is needed because get intrinsic requires for index to be a known constant.
3288                 if (num_lanes == 1) {
3289                     r[i]=av.lane(0);
3290                 } else if (num_lanes == 2) {
3291                     r[i]=av.lane(0);
3292                     r[i+1]=av.lane(1);
3293                 } else if (num_lanes == 4) {
3294                     r[i]=av.lane(0);
3295                     r[i+1]=av.lane(1);
3296                     r[i+2]=av.lane(2);

4928             }
4929         }
4930         return i - idx;
4931     }
4932 
4933     @Test(dataProvider = "maskProvider")
4934     static void maskFirstTrueFloatMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4935         boolean[] a = fa.apply(SPECIES.length());
4936         int[] r = new int[a.length];
4937 
4938         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4939             for (int i = 0; i < a.length; i += SPECIES.length()) {
4940                 var vmask = SPECIES.loadMask(a, i);
4941                 r[i] = vmask.firstTrue();
4942             }
4943         }
4944 
4945         assertMaskReductionArraysEquals(r, a, FloatMaxVectorTests::maskFirstTrue);
4946     }
4947 
4948     @Test(dataProvider = "maskProvider")
4949     static void maskCompressFloatMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4950         int trueCount = 0;
4951         boolean[] a = fa.apply(SPECIES.length());
4952 
4953         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4954             for (int i = 0; i < a.length; i += SPECIES.length()) {
4955                 var vmask = SPECIES.loadMask(a, i);
4956                 trueCount = vmask.trueCount();
4957                 var rmask = vmask.compress();
4958                 for (int j = 0; j < SPECIES.length(); j++)  {
4959                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
4960                 }
4961             }
4962         }
4963     }
4964 
4965 
4966     @DataProvider
4967     public static Object[][] offsetProvider() {
4968         return new Object[][]{
4969                 {0},
4970                 {-1},
4971                 {+1},
4972                 {+2},
4973                 {-2},
4974         };
4975     }
4976 
4977     @Test(dataProvider = "offsetProvider")
4978     static void indexInRangeFloatMaxVectorTestsSmokeTest(int offset) {
4979         int limit = SPECIES.length() * BUFFER_REPS;
4980         for (int i = 0; i < limit; i += SPECIES.length()) {
4981             var actualMask = SPECIES.indexInRange(i + offset, limit);
4982             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
4983             assert(actualMask.equals(expectedMask));
4984             for (int j = 0; j < SPECIES.length(); j++)  {
< prev index next >