< prev index next >

test/jdk/jdk/incubator/vector/Double64VectorTests.java

Print this page

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

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




































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

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

















4880     @DataProvider
4881     public static Object[][] longMaskProvider() {
4882         return new Object[][]{
4883                 {0xFFFFFFFFFFFFFFFFL},
4884                 {0x0000000000000000L},
4885                 {0x5555555555555555L},
4886                 {0x0123456789abcdefL},
4887         };
4888     }
4889 
4890     @Test(dataProvider = "longMaskProvider")
4891     static void maskFromToLongDouble64VectorTestsSmokeTest(long inputLong) {
4892         var vmask = VectorMask.fromLong(SPECIES, inputLong);
4893         long outputLong = vmask.toLong();
4894         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
4895     }
4896 
4897     @DataProvider
4898     public static Object[][] offsetProvider() {
4899         return new Object[][]{

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

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

4945             }
4946         }
4947         return i - idx;
4948     }
4949 
4950     @Test(dataProvider = "maskProvider")
4951     static void maskFirstTrueDouble64VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4952         boolean[] a = fa.apply(SPECIES.length());
4953         int[] r = new int[a.length];
4954 
4955         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4956             for (int i = 0; i < a.length; i += SPECIES.length()) {
4957                 var vmask = SPECIES.loadMask(a, i);
4958                 r[i] = vmask.firstTrue();
4959             }
4960         }
4961 
4962         assertMaskReductionArraysEquals(r, a, Double64VectorTests::maskFirstTrue);
4963     }
4964 
4965     @Test(dataProvider = "maskProvider")
4966     static void maskCompressDouble64VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4967         int trueCount = 0;
4968         boolean[] a = fa.apply(SPECIES.length());
4969 
4970         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4971             for (int i = 0; i < a.length; i += SPECIES.length()) {
4972                 var vmask = SPECIES.loadMask(a, i);
4973                 trueCount = vmask.trueCount();
4974                 var rmask = vmask.compress();
4975                 for (int j = 0; j < SPECIES.length(); j++)  {
4976                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
4977                 }
4978             }
4979         }
4980     }
4981 
4982     @DataProvider
4983     public static Object[][] longMaskProvider() {
4984         return new Object[][]{
4985                 {0xFFFFFFFFFFFFFFFFL},
4986                 {0x0000000000000000L},
4987                 {0x5555555555555555L},
4988                 {0x0123456789abcdefL},
4989         };
4990     }
4991 
4992     @Test(dataProvider = "longMaskProvider")
4993     static void maskFromToLongDouble64VectorTestsSmokeTest(long inputLong) {
4994         var vmask = VectorMask.fromLong(SPECIES, inputLong);
4995         long outputLong = vmask.toLong();
4996         Assert.assertEquals(outputLong, inputLong & (((1L << (SPECIES.length() - 1)) << 1) - 1));
4997     }
4998 
4999     @DataProvider
5000     public static Object[][] offsetProvider() {
5001         return new Object[][]{
< prev index next >