< prev index next >

test/jdk/jdk/incubator/vector/Float128VectorTests.java

Print this page

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

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




































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

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

















4858     @DataProvider
4859     public static Object[][] longMaskProvider() {
4860         return new Object[][]{
4861                 {0xFFFFFFFFFFFFFFFFL},
4862                 {0x0000000000000000L},
4863                 {0x5555555555555555L},
4864                 {0x0123456789abcdefL},
4865         };
4866     }
4867 
4868     @Test(dataProvider = "longMaskProvider")
4869     static void maskFromToLongFloat128VectorTestsSmokeTest(long inputLong) {
4870         var vmask = VectorMask.fromLong(SPECIES, inputLong);
4871         long outputLong = vmask.toLong();
4872         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
4873     }
4874 
4875     @DataProvider
4876     public static Object[][] offsetProvider() {
4877         return new Object[][]{

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

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

4923             }
4924         }
4925         return i - idx;
4926     }
4927 
4928     @Test(dataProvider = "maskProvider")
4929     static void maskFirstTrueFloat128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4930         boolean[] a = fa.apply(SPECIES.length());
4931         int[] r = new int[a.length];
4932 
4933         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4934             for (int i = 0; i < a.length; i += SPECIES.length()) {
4935                 var vmask = SPECIES.loadMask(a, i);
4936                 r[i] = vmask.firstTrue();
4937             }
4938         }
4939 
4940         assertMaskReductionArraysEquals(r, a, Float128VectorTests::maskFirstTrue);
4941     }
4942 
4943     @Test(dataProvider = "maskProvider")
4944     static void maskCompressFloat128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4945         int trueCount = 0;
4946         boolean[] a = fa.apply(SPECIES.length());
4947 
4948         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4949             for (int i = 0; i < a.length; i += SPECIES.length()) {
4950                 var vmask = SPECIES.loadMask(a, i);
4951                 trueCount = vmask.trueCount();
4952                 var rmask = vmask.compress();
4953                 for (int j = 0; j < SPECIES.length(); j++)  {
4954                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
4955                 }
4956             }
4957         }
4958     }
4959 
4960     @DataProvider
4961     public static Object[][] longMaskProvider() {
4962         return new Object[][]{
4963                 {0xFFFFFFFFFFFFFFFFL},
4964                 {0x0000000000000000L},
4965                 {0x5555555555555555L},
4966                 {0x0123456789abcdefL},
4967         };
4968     }
4969 
4970     @Test(dataProvider = "longMaskProvider")
4971     static void maskFromToLongFloat128VectorTestsSmokeTest(long inputLong) {
4972         var vmask = VectorMask.fromLong(SPECIES, inputLong);
4973         long outputLong = vmask.toLong();
4974         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
4975     }
4976 
4977     @DataProvider
4978     public static Object[][] offsetProvider() {
4979         return new Object[][]{
< prev index next >