< prev index next >

test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java

Print this page

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

3162         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
3163     }
3164 
3165     @Test(dataProvider = "doubleUnaryOpShuffleMaskProvider")
3166     static void RearrangeDoubleMaxVectorTestsMaskedSmokeTest(IntFunction<double[]> fa,
3167                                                           BiFunction<Integer,Integer,int[]> fs,
3168                                                           IntFunction<boolean[]> fm) {
3169         double[] a = fa.apply(SPECIES.length());
3170         int[] order = fs.apply(a.length, SPECIES.length());
3171         double[] r = fr.apply(SPECIES.length());
3172         boolean[] mask = fm.apply(SPECIES.length());
3173         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3174 
3175         for (int i = 0; i < a.length; i += SPECIES.length()) {
3176             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3177             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
3178         }
3179 
3180         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
3181     }




































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

4865             }
4866         }
4867         return i - idx;
4868     }
4869 
4870     @Test(dataProvider = "maskProvider")
4871     static void maskFirstTrueDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4872         boolean[] a = fa.apply(SPECIES.length());
4873         int[] r = new int[a.length];
4874 
4875         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4876             for (int i = 0; i < a.length; i += SPECIES.length()) {
4877                 var vmask = SPECIES.loadMask(a, i);
4878                 r[i] = vmask.firstTrue();
4879             }
4880         }
4881 
4882         assertMaskReductionArraysEquals(r, a, DoubleMaxVectorTests::maskFirstTrue);
4883     }
4884 

















4885 
4886     @DataProvider
4887     public static Object[][] offsetProvider() {
4888         return new Object[][]{
4889                 {0},
4890                 {-1},
4891                 {+1},
4892                 {+2},
4893                 {-2},
4894         };
4895     }
4896 
4897     @Test(dataProvider = "offsetProvider")
4898     static void indexInRangeDoubleMaxVectorTestsSmokeTest(int offset) {
4899         int limit = SPECIES.length() * BUFFER_REPS;
4900         for (int i = 0; i < limit; i += SPECIES.length()) {
4901             var actualMask = SPECIES.indexInRange(i + offset, limit);
4902             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
4903             assert(actualMask.equals(expectedMask));
4904             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(double[] r, double[] 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(double[] r, double[] 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], (double)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], (double)0, "at index #" + idx);
 288             }
 289         }
 290     }
 291 
 292     static void assertexpandArraysEquals(double[] r, double[] 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], (double)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], (double)0, "at index #" + idx);
 312             }
 313         }
 314     }
 315 
 316     static void assertSelectFromArraysEquals(double[] r, double[] a, double[] 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(double[] r, double[] 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()])

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

4950             }
4951         }
4952         return i - idx;
4953     }
4954 
4955     @Test(dataProvider = "maskProvider")
4956     static void maskFirstTrueDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4957         boolean[] a = fa.apply(SPECIES.length());
4958         int[] r = new int[a.length];
4959 
4960         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4961             for (int i = 0; i < a.length; i += SPECIES.length()) {
4962                 var vmask = SPECIES.loadMask(a, i);
4963                 r[i] = vmask.firstTrue();
4964             }
4965         }
4966 
4967         assertMaskReductionArraysEquals(r, a, DoubleMaxVectorTests::maskFirstTrue);
4968     }
4969 
4970     @Test(dataProvider = "maskProvider")
4971     static void maskCompressDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4972         int trueCount = 0;
4973         boolean[] a = fa.apply(SPECIES.length());
4974 
4975         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4976             for (int i = 0; i < a.length; i += SPECIES.length()) {
4977                 var vmask = SPECIES.loadMask(a, i);
4978                 trueCount = vmask.trueCount();
4979                 var rmask = vmask.compress();
4980                 for (int j = 0; j < SPECIES.length(); j++)  {
4981                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
4982                 }
4983             }
4984         }
4985     }
4986 
4987 
4988     @DataProvider
4989     public static Object[][] offsetProvider() {
4990         return new Object[][]{
4991                 {0},
4992                 {-1},
4993                 {+1},
4994                 {+2},
4995                 {-2},
4996         };
4997     }
4998 
4999     @Test(dataProvider = "offsetProvider")
5000     static void indexInRangeDoubleMaxVectorTestsSmokeTest(int offset) {
5001         int limit = SPECIES.length() * BUFFER_REPS;
5002         for (int i = 0; i < limit; i += SPECIES.length()) {
5003             var actualMask = SPECIES.indexInRange(i + offset, limit);
5004             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5005             assert(actualMask.equals(expectedMask));
5006             for (int j = 0; j < SPECIES.length(); j++)  {
< prev index next >