< prev index next >

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

Print this page




 229 
 230     interface FBinMaskOp {
 231         long apply(long a, long b, boolean m);
 232 
 233         static FBinMaskOp lift(FBinOp f) {
 234             return (a, b, m) -> m ? f.apply(a, b) : a;
 235         }
 236     }
 237 
 238     static void assertArraysEquals(long[] a, long[] b, long[] r, FBinOp f) {
 239         int i = 0;
 240         try {
 241             for (; i < a.length; i++) {
 242                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 243             }
 244         } catch (AssertionError e) {
 245             Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
 246         }
 247     }
 248 











 249     static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) {
 250         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 251     }
 252 
 253     static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) {
 254         int i = 0;
 255         try {
 256             for (; i < a.length; i++) {
 257                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 258             }
 259         } catch (AssertionError err) {
 260             Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]);
 261         }
 262     }
 263 















 264     static void assertShiftArraysEquals(long[] a, long[] b, long[] r, FBinOp f) {
 265         int i = 0;
 266         int j = 0;
 267         try {
 268             for (; j < a.length; j += SPECIES.length()) {
 269                 for (i = 0; i < SPECIES.length(); i++) {
 270                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
 271                 }
 272             }
 273         } catch (AssertionError e) {
 274             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
 275         }
 276     }
 277 
 278     static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) {
 279         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 280     }
 281 
 282     static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) {
 283         int i = 0;


1362     static long OR(long a, long b) {
1363         return (long)(a | b);
1364     }
1365 
1366     @Test(dataProvider = "longBinaryOpProvider")
1367     static void ORLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1368         long[] a = fa.apply(SPECIES.length());
1369         long[] b = fb.apply(SPECIES.length());
1370         long[] r = fr.apply(SPECIES.length());
1371 
1372         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1373             for (int i = 0; i < a.length; i += SPECIES.length()) {
1374                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1375                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1376                 av.lanewise(VectorOperators.OR, bv).intoArray(r, i);
1377             }
1378         }
1379 
1380         assertArraysEquals(a, b, r, LongMaxVectorTests::OR);
1381     }




















1382 
1383 
1384 
1385     @Test(dataProvider = "longBinaryOpMaskProvider")
1386     static void ORLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
1387                                           IntFunction<boolean[]> fm) {
1388         long[] a = fa.apply(SPECIES.length());
1389         long[] b = fb.apply(SPECIES.length());
1390         long[] r = fr.apply(SPECIES.length());
1391         boolean[] mask = fm.apply(SPECIES.length());
1392         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1393 
1394         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1395             for (int i = 0; i < a.length; i += SPECIES.length()) {
1396                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1397                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1398                 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i);
1399             }
1400         }
1401 


1430     static void XORLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
1431                                           IntFunction<boolean[]> fm) {
1432         long[] a = fa.apply(SPECIES.length());
1433         long[] b = fb.apply(SPECIES.length());
1434         long[] r = fr.apply(SPECIES.length());
1435         boolean[] mask = fm.apply(SPECIES.length());
1436         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1437 
1438         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1439             for (int i = 0; i < a.length; i += SPECIES.length()) {
1440                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1441                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1442                 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i);
1443             }
1444         }
1445 
1446         assertArraysEquals(a, b, r, mask, LongMaxVectorTests::XOR);
1447     }
1448 
1449 























































































































































































1450     static long LSHL(long a, long b) {
1451         return (long)((a << b));
1452     }
1453 
1454     @Test(dataProvider = "longBinaryOpProvider")
1455     static void LSHLLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1456         long[] a = fa.apply(SPECIES.length());
1457         long[] b = fb.apply(SPECIES.length());
1458         long[] r = fr.apply(SPECIES.length());
1459 
1460         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1461             for (int i = 0; i < a.length; i += SPECIES.length()) {
1462                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1463                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1464                 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i);
1465             }
1466         }
1467 
1468         assertArraysEquals(a, b, r, LongMaxVectorTests::LSHL);
1469     }


1792         return (long)(Math.max(a, b));
1793     }
1794 
1795     @Test(dataProvider = "longBinaryOpProvider")
1796     static void maxLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1797         long[] a = fa.apply(SPECIES.length());
1798         long[] b = fb.apply(SPECIES.length());
1799         long[] r = fr.apply(SPECIES.length());
1800 
1801         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1802             for (int i = 0; i < a.length; i += SPECIES.length()) {
1803                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1804                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1805                 av.max(bv).intoArray(r, i);
1806             }
1807         }
1808 
1809         assertArraysEquals(a, b, r, LongMaxVectorTests::max);
1810     }
1811 
























































1812     static long AND(long[] a, int idx) {
1813         long res = -1;
1814         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1815             res &= a[i];
1816         }
1817 
1818         return res;
1819     }
1820 
1821     static long AND(long[] a) {
1822         long res = -1;
1823         for (int i = 0; i < a.length; i += SPECIES.length()) {
1824             long tmp = -1;
1825             for (int j = 0; j < SPECIES.length(); j++) {
1826                 tmp &= a[i + j];
1827             }
1828             res &= tmp;
1829         }
1830 
1831         return res;


3236         boolean[] mask = fm.apply(SPECIES.length());
3237         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3238 
3239         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3240             for (int i = 0; i < a.length; i += SPECIES.length()) {
3241                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3242                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
3243                 LongVector cv = LongVector.fromArray(SPECIES, c, i);
3244                 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i);
3245             }
3246         }
3247 
3248         assertArraysEquals(a, b, c, r, mask, LongMaxVectorTests::BITWISE_BLEND);
3249     }
3250 
3251 
3252     static long NEG(long a) {
3253         return (long)(-((long)a));
3254     }
3255 




3256     @Test(dataProvider = "longUnaryOpProvider")
3257     static void NEGLongMaxVectorTests(IntFunction<long[]> fa) {
3258         long[] a = fa.apply(SPECIES.length());
3259         long[] r = fr.apply(SPECIES.length());
3260 
3261         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3262             for (int i = 0; i < a.length; i += SPECIES.length()) {
3263                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3264                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
3265             }
3266         }
3267 
3268         assertArraysEquals(a, r, LongMaxVectorTests::NEG);
3269     }
3270 















3271     @Test(dataProvider = "longUnaryOpMaskProvider")
3272     static void NEGMaskedLongMaxVectorTests(IntFunction<long[]> fa,
3273                                                 IntFunction<boolean[]> fm) {
3274         long[] a = fa.apply(SPECIES.length());
3275         long[] r = fr.apply(SPECIES.length());
3276         boolean[] mask = fm.apply(SPECIES.length());
3277         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3278 
3279         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3280             for (int i = 0; i < a.length; i += SPECIES.length()) {
3281                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3282                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
3283             }
3284         }
3285 
3286         assertArraysEquals(a, r, mask, LongMaxVectorTests::NEG);
3287     }
3288 
3289     static long ABS(long a) {
3290         return (long)(Math.abs((long)a));


3330         long[] a = fa.apply(SPECIES.length());
3331         long[] r = fr.apply(SPECIES.length());
3332         boolean[] mask = fm.apply(SPECIES.length());
3333         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3334 
3335         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3336             for (int i = 0; i < a.length; i += SPECIES.length()) {
3337                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3338                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
3339             }
3340         }
3341 
3342         assertArraysEquals(a, r, mask, LongMaxVectorTests::ABS);
3343     }
3344 
3345 
3346     static long NOT(long a) {
3347         return (long)(~((long)a));
3348     }
3349 




3350 
3351 
3352     @Test(dataProvider = "longUnaryOpProvider")
3353     static void NOTLongMaxVectorTests(IntFunction<long[]> fa) {
3354         long[] a = fa.apply(SPECIES.length());
3355         long[] r = fr.apply(SPECIES.length());
3356 
3357         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3358             for (int i = 0; i < a.length; i += SPECIES.length()) {
3359                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3360                 av.lanewise(VectorOperators.NOT).intoArray(r, i);
3361             }
3362         }
3363 
3364         assertArraysEquals(a, r, LongMaxVectorTests::NOT);















3365     }
3366 
3367 
3368 
3369     @Test(dataProvider = "longUnaryOpMaskProvider")
3370     static void NOTMaskedLongMaxVectorTests(IntFunction<long[]> fa,
3371                                                 IntFunction<boolean[]> fm) {
3372         long[] a = fa.apply(SPECIES.length());
3373         long[] r = fr.apply(SPECIES.length());
3374         boolean[] mask = fm.apply(SPECIES.length());
3375         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3376 
3377         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3378             for (int i = 0; i < a.length; i += SPECIES.length()) {
3379                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3380                 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i);
3381             }
3382         }
3383 
3384         assertArraysEquals(a, r, mask, LongMaxVectorTests::NOT);




 229 
 230     interface FBinMaskOp {
 231         long apply(long a, long b, boolean m);
 232 
 233         static FBinMaskOp lift(FBinOp f) {
 234             return (a, b, m) -> m ? f.apply(a, b) : a;
 235         }
 236     }
 237 
 238     static void assertArraysEquals(long[] a, long[] b, long[] r, FBinOp f) {
 239         int i = 0;
 240         try {
 241             for (; i < a.length; i++) {
 242                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 243             }
 244         } catch (AssertionError e) {
 245             Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
 246         }
 247     }
 248 
 249     static void assertBroadcastArraysEquals(long[] a, long[] b, long[] r, FBinOp f) {
 250         int i = 0;
 251         try {
 252             for (; i < a.length; i++) {
 253                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
 254             }
 255         } catch (AssertionError e) {
 256             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 257         }
 258     }
 259 
 260     static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) {
 261         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 262     }
 263 
 264     static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) {
 265         int i = 0;
 266         try {
 267             for (; i < a.length; i++) {
 268                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 269             }
 270         } catch (AssertionError err) {
 271             Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]);
 272         }
 273     }
 274 
 275     static void assertBroadcastArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) {
 276         assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 277     }
 278 
 279     static void assertBroadcastArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) {
 280         int i = 0;
 281         try {
 282             for (; i < a.length; i++) {
 283                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 284             }
 285         } catch (AssertionError err) {
 286             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + mask[i % SPECIES.length()]);
 287         }
 288     }
 289 
 290     static void assertShiftArraysEquals(long[] a, long[] b, long[] r, FBinOp f) {
 291         int i = 0;
 292         int j = 0;
 293         try {
 294             for (; j < a.length; j += SPECIES.length()) {
 295                 for (i = 0; i < SPECIES.length(); i++) {
 296                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
 297                 }
 298             }
 299         } catch (AssertionError e) {
 300             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
 301         }
 302     }
 303 
 304     static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) {
 305         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 306     }
 307 
 308     static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) {
 309         int i = 0;


1388     static long OR(long a, long b) {
1389         return (long)(a | b);
1390     }
1391 
1392     @Test(dataProvider = "longBinaryOpProvider")
1393     static void ORLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1394         long[] a = fa.apply(SPECIES.length());
1395         long[] b = fb.apply(SPECIES.length());
1396         long[] r = fr.apply(SPECIES.length());
1397 
1398         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1399             for (int i = 0; i < a.length; i += SPECIES.length()) {
1400                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1401                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1402                 av.lanewise(VectorOperators.OR, bv).intoArray(r, i);
1403             }
1404         }
1405 
1406         assertArraysEquals(a, b, r, LongMaxVectorTests::OR);
1407     }
1408     static long or(long a, long b) {
1409         return (long)(a | b);
1410     }
1411 
1412     @Test(dataProvider = "longBinaryOpProvider")
1413     static void orLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1414         long[] a = fa.apply(SPECIES.length());
1415         long[] b = fb.apply(SPECIES.length());
1416         long[] r = fr.apply(SPECIES.length());
1417 
1418         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1419             for (int i = 0; i < a.length; i += SPECIES.length()) {
1420                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1421                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1422                 av.or(bv).intoArray(r, i);
1423             }
1424         }
1425 
1426         assertArraysEquals(a, b, r, LongMaxVectorTests::or);
1427     }
1428 
1429 
1430 
1431     @Test(dataProvider = "longBinaryOpMaskProvider")
1432     static void ORLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
1433                                           IntFunction<boolean[]> fm) {
1434         long[] a = fa.apply(SPECIES.length());
1435         long[] b = fb.apply(SPECIES.length());
1436         long[] r = fr.apply(SPECIES.length());
1437         boolean[] mask = fm.apply(SPECIES.length());
1438         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1439 
1440         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1441             for (int i = 0; i < a.length; i += SPECIES.length()) {
1442                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1443                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1444                 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i);
1445             }
1446         }
1447 


1476     static void XORLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb,
1477                                           IntFunction<boolean[]> fm) {
1478         long[] a = fa.apply(SPECIES.length());
1479         long[] b = fb.apply(SPECIES.length());
1480         long[] r = fr.apply(SPECIES.length());
1481         boolean[] mask = fm.apply(SPECIES.length());
1482         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1483 
1484         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1485             for (int i = 0; i < a.length; i += SPECIES.length()) {
1486                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1487                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1488                 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i);
1489             }
1490         }
1491 
1492         assertArraysEquals(a, b, r, mask, LongMaxVectorTests::XOR);
1493     }
1494 
1495 
1496     @Test(dataProvider = "longBinaryOpProvider")
1497     static void addLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1498         long[] a = fa.apply(SPECIES.length());
1499         long[] b = fb.apply(SPECIES.length());
1500         long[] r = fr.apply(SPECIES.length());
1501 
1502         for (int i = 0; i < a.length; i += SPECIES.length()) {
1503             LongVector av = LongVector.fromArray(SPECIES, a, i);
1504             av.add(b[i]).intoArray(r, i);
1505         }
1506 
1507         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::add);
1508     }
1509 
1510     @Test(dataProvider = "longBinaryOpMaskProvider")
1511     static void addLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb,
1512                                           IntFunction<boolean[]> fm) {
1513         long[] a = fa.apply(SPECIES.length());
1514         long[] b = fb.apply(SPECIES.length());
1515         long[] r = fr.apply(SPECIES.length());
1516         boolean[] mask = fm.apply(SPECIES.length());
1517         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1518 
1519         for (int i = 0; i < a.length; i += SPECIES.length()) {
1520             LongVector av = LongVector.fromArray(SPECIES, a, i);
1521             av.add(b[i], vmask).intoArray(r, i);
1522         }
1523 
1524         assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::add);
1525     }
1526 
1527     @Test(dataProvider = "longBinaryOpProvider")
1528     static void subLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1529         long[] a = fa.apply(SPECIES.length());
1530         long[] b = fb.apply(SPECIES.length());
1531         long[] r = fr.apply(SPECIES.length());
1532 
1533         for (int i = 0; i < a.length; i += SPECIES.length()) {
1534             LongVector av = LongVector.fromArray(SPECIES, a, i);
1535             av.sub(b[i]).intoArray(r, i);
1536         }
1537 
1538         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::sub);
1539     }
1540 
1541     @Test(dataProvider = "longBinaryOpMaskProvider")
1542     static void subLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb,
1543                                           IntFunction<boolean[]> fm) {
1544         long[] a = fa.apply(SPECIES.length());
1545         long[] b = fb.apply(SPECIES.length());
1546         long[] r = fr.apply(SPECIES.length());
1547         boolean[] mask = fm.apply(SPECIES.length());
1548         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1549 
1550         for (int i = 0; i < a.length; i += SPECIES.length()) {
1551             LongVector av = LongVector.fromArray(SPECIES, a, i);
1552             av.sub(b[i], vmask).intoArray(r, i);
1553         }
1554 
1555         assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::sub);
1556     }
1557 
1558     @Test(dataProvider = "longBinaryOpProvider")
1559     static void mulLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1560         long[] a = fa.apply(SPECIES.length());
1561         long[] b = fb.apply(SPECIES.length());
1562         long[] r = fr.apply(SPECIES.length());
1563 
1564         for (int i = 0; i < a.length; i += SPECIES.length()) {
1565             LongVector av = LongVector.fromArray(SPECIES, a, i);
1566             av.mul(b[i]).intoArray(r, i);
1567         }
1568 
1569         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::mul);
1570     }
1571 
1572     @Test(dataProvider = "longBinaryOpMaskProvider")
1573     static void mulLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb,
1574                                           IntFunction<boolean[]> fm) {
1575         long[] a = fa.apply(SPECIES.length());
1576         long[] b = fb.apply(SPECIES.length());
1577         long[] r = fr.apply(SPECIES.length());
1578         boolean[] mask = fm.apply(SPECIES.length());
1579         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1580 
1581         for (int i = 0; i < a.length; i += SPECIES.length()) {
1582             LongVector av = LongVector.fromArray(SPECIES, a, i);
1583             av.mul(b[i], vmask).intoArray(r, i);
1584         }
1585 
1586         assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::mul);
1587     }
1588 
1589 
1590 
1591 
1592     @Test(dataProvider = "longBinaryOpProvider")
1593     static void divLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1594         long[] a = fa.apply(SPECIES.length());
1595         long[] b = fb.apply(SPECIES.length());
1596         long[] r = fr.apply(SPECIES.length());
1597 
1598         replaceZero(b, (long) 1);
1599 
1600         for (int i = 0; i < a.length; i += SPECIES.length()) {
1601             LongVector av = LongVector.fromArray(SPECIES, a, i);
1602             av.div(b[i]).intoArray(r, i);
1603         }
1604 
1605         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::div);
1606     }
1607 
1608 
1609 
1610     @Test(dataProvider = "longBinaryOpMaskProvider")
1611     static void divLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb,
1612                                           IntFunction<boolean[]> fm) {
1613         long[] a = fa.apply(SPECIES.length());
1614         long[] b = fb.apply(SPECIES.length());
1615         long[] r = fr.apply(SPECIES.length());
1616         boolean[] mask = fm.apply(SPECIES.length());
1617         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1618 
1619         replaceZero(b, (long) 1);
1620 
1621        for (int i = 0; i < a.length; i += SPECIES.length()) {
1622            LongVector av = LongVector.fromArray(SPECIES, a, i);
1623            av.div(b[i], vmask).intoArray(r, i);
1624        }
1625 
1626         assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::div);
1627     }
1628 
1629 
1630 
1631     @Test(dataProvider = "longBinaryOpProvider")
1632     static void ORLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1633         long[] a = fa.apply(SPECIES.length());
1634         long[] b = fb.apply(SPECIES.length());
1635         long[] r = fr.apply(SPECIES.length());
1636 
1637         for (int i = 0; i < a.length; i += SPECIES.length()) {
1638             LongVector av = LongVector.fromArray(SPECIES, a, i);
1639             av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i);
1640         }
1641 
1642         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::OR);
1643     }
1644 
1645     @Test(dataProvider = "longBinaryOpProvider")
1646     static void orLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1647         long[] a = fa.apply(SPECIES.length());
1648         long[] b = fb.apply(SPECIES.length());
1649         long[] r = fr.apply(SPECIES.length());
1650 
1651         for (int i = 0; i < a.length; i += SPECIES.length()) {
1652             LongVector av = LongVector.fromArray(SPECIES, a, i);
1653             av.or(b[i]).intoArray(r, i);
1654         }
1655 
1656         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::or);
1657     }
1658 
1659 
1660 
1661     @Test(dataProvider = "longBinaryOpMaskProvider")
1662     static void ORLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb,
1663                                           IntFunction<boolean[]> fm) {
1664         long[] a = fa.apply(SPECIES.length());
1665         long[] b = fb.apply(SPECIES.length());
1666         long[] r = fr.apply(SPECIES.length());
1667         boolean[] mask = fm.apply(SPECIES.length());
1668         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1669 
1670         for (int i = 0; i < a.length; i += SPECIES.length()) {
1671             LongVector av = LongVector.fromArray(SPECIES, a, i);
1672             av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i);
1673         }
1674 
1675         assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::OR);
1676     }
1677 
1678 
1679     static long LSHL(long a, long b) {
1680         return (long)((a << b));
1681     }
1682 
1683     @Test(dataProvider = "longBinaryOpProvider")
1684     static void LSHLLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
1685         long[] a = fa.apply(SPECIES.length());
1686         long[] b = fb.apply(SPECIES.length());
1687         long[] r = fr.apply(SPECIES.length());
1688 
1689         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1690             for (int i = 0; i < a.length; i += SPECIES.length()) {
1691                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1692                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
1693                 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i);
1694             }
1695         }
1696 
1697         assertArraysEquals(a, b, r, LongMaxVectorTests::LSHL);
1698     }


2021         return (long)(Math.max(a, b));
2022     }
2023 
2024     @Test(dataProvider = "longBinaryOpProvider")
2025     static void maxLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
2026         long[] a = fa.apply(SPECIES.length());
2027         long[] b = fb.apply(SPECIES.length());
2028         long[] r = fr.apply(SPECIES.length());
2029 
2030         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2031             for (int i = 0; i < a.length; i += SPECIES.length()) {
2032                 LongVector av = LongVector.fromArray(SPECIES, a, i);
2033                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
2034                 av.max(bv).intoArray(r, i);
2035             }
2036         }
2037 
2038         assertArraysEquals(a, b, r, LongMaxVectorTests::max);
2039     }
2040 
2041     @Test(dataProvider = "longBinaryOpProvider")
2042     static void MINLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
2043         long[] a = fa.apply(SPECIES.length());
2044         long[] b = fb.apply(SPECIES.length());
2045         long[] r = fr.apply(SPECIES.length());
2046 
2047         for (int i = 0; i < a.length; i += SPECIES.length()) {
2048             LongVector av = LongVector.fromArray(SPECIES, a, i);
2049             av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i);
2050         }
2051 
2052         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::MIN);
2053     }
2054 
2055     @Test(dataProvider = "longBinaryOpProvider")
2056     static void minLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
2057         long[] a = fa.apply(SPECIES.length());
2058         long[] b = fb.apply(SPECIES.length());
2059         long[] r = fr.apply(SPECIES.length());
2060 
2061         for (int i = 0; i < a.length; i += SPECIES.length()) {
2062             LongVector av = LongVector.fromArray(SPECIES, a, i);
2063             av.min(b[i]).intoArray(r, i);
2064         }
2065 
2066         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::min);
2067     }
2068 
2069     @Test(dataProvider = "longBinaryOpProvider")
2070     static void MAXLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
2071         long[] a = fa.apply(SPECIES.length());
2072         long[] b = fb.apply(SPECIES.length());
2073         long[] r = fr.apply(SPECIES.length());
2074 
2075         for (int i = 0; i < a.length; i += SPECIES.length()) {
2076             LongVector av = LongVector.fromArray(SPECIES, a, i);
2077             av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i);
2078         }
2079 
2080         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::MAX);
2081     }
2082 
2083     @Test(dataProvider = "longBinaryOpProvider")
2084     static void maxLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) {
2085         long[] a = fa.apply(SPECIES.length());
2086         long[] b = fb.apply(SPECIES.length());
2087         long[] r = fr.apply(SPECIES.length());
2088 
2089         for (int i = 0; i < a.length; i += SPECIES.length()) {
2090             LongVector av = LongVector.fromArray(SPECIES, a, i);
2091             av.max(b[i]).intoArray(r, i);
2092         }
2093 
2094         assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::max);
2095     }
2096 
2097     static long AND(long[] a, int idx) {
2098         long res = -1;
2099         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2100             res &= a[i];
2101         }
2102 
2103         return res;
2104     }
2105 
2106     static long AND(long[] a) {
2107         long res = -1;
2108         for (int i = 0; i < a.length; i += SPECIES.length()) {
2109             long tmp = -1;
2110             for (int j = 0; j < SPECIES.length(); j++) {
2111                 tmp &= a[i + j];
2112             }
2113             res &= tmp;
2114         }
2115 
2116         return res;


3521         boolean[] mask = fm.apply(SPECIES.length());
3522         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3523 
3524         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3525             for (int i = 0; i < a.length; i += SPECIES.length()) {
3526                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3527                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
3528                 LongVector cv = LongVector.fromArray(SPECIES, c, i);
3529                 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i);
3530             }
3531         }
3532 
3533         assertArraysEquals(a, b, c, r, mask, LongMaxVectorTests::BITWISE_BLEND);
3534     }
3535 
3536 
3537     static long NEG(long a) {
3538         return (long)(-((long)a));
3539     }
3540 
3541     static long neg(long a) {
3542         return (long)(-((long)a));
3543     }
3544 
3545     @Test(dataProvider = "longUnaryOpProvider")
3546     static void NEGLongMaxVectorTests(IntFunction<long[]> fa) {
3547         long[] a = fa.apply(SPECIES.length());
3548         long[] r = fr.apply(SPECIES.length());
3549 
3550         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3551             for (int i = 0; i < a.length; i += SPECIES.length()) {
3552                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3553                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
3554             }
3555         }
3556 
3557         assertArraysEquals(a, r, LongMaxVectorTests::NEG);
3558     }
3559 
3560     @Test(dataProvider = "longUnaryOpProvider")
3561     static void negLongMaxVectorTests(IntFunction<long[]> fa) {
3562         long[] a = fa.apply(SPECIES.length());
3563         long[] r = fr.apply(SPECIES.length());
3564 
3565         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3566             for (int i = 0; i < a.length; i += SPECIES.length()) {
3567                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3568                 av.neg().intoArray(r, i);
3569             }
3570         }
3571 
3572         assertArraysEquals(a, r, LongMaxVectorTests::neg);
3573     }
3574 
3575     @Test(dataProvider = "longUnaryOpMaskProvider")
3576     static void NEGMaskedLongMaxVectorTests(IntFunction<long[]> fa,
3577                                                 IntFunction<boolean[]> fm) {
3578         long[] a = fa.apply(SPECIES.length());
3579         long[] r = fr.apply(SPECIES.length());
3580         boolean[] mask = fm.apply(SPECIES.length());
3581         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3582 
3583         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3584             for (int i = 0; i < a.length; i += SPECIES.length()) {
3585                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3586                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
3587             }
3588         }
3589 
3590         assertArraysEquals(a, r, mask, LongMaxVectorTests::NEG);
3591     }
3592 
3593     static long ABS(long a) {
3594         return (long)(Math.abs((long)a));


3634         long[] a = fa.apply(SPECIES.length());
3635         long[] r = fr.apply(SPECIES.length());
3636         boolean[] mask = fm.apply(SPECIES.length());
3637         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3638 
3639         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3640             for (int i = 0; i < a.length; i += SPECIES.length()) {
3641                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3642                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
3643             }
3644         }
3645 
3646         assertArraysEquals(a, r, mask, LongMaxVectorTests::ABS);
3647     }
3648 
3649 
3650     static long NOT(long a) {
3651         return (long)(~((long)a));
3652     }
3653 
3654     static long not(long a) {
3655         return (long)(~((long)a));
3656     }
3657 
3658 
3659 
3660     @Test(dataProvider = "longUnaryOpProvider")
3661     static void NOTLongMaxVectorTests(IntFunction<long[]> fa) {
3662         long[] a = fa.apply(SPECIES.length());
3663         long[] r = fr.apply(SPECIES.length());
3664 
3665         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3666             for (int i = 0; i < a.length; i += SPECIES.length()) {
3667                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3668                 av.lanewise(VectorOperators.NOT).intoArray(r, i);
3669             }
3670         }
3671 
3672         assertArraysEquals(a, r, LongMaxVectorTests::NOT);
3673     }
3674 
3675     @Test(dataProvider = "longUnaryOpProvider")
3676     static void notLongMaxVectorTests(IntFunction<long[]> fa) {
3677         long[] a = fa.apply(SPECIES.length());
3678         long[] r = fr.apply(SPECIES.length());
3679 
3680         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3681             for (int i = 0; i < a.length; i += SPECIES.length()) {
3682                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3683                 av.not().intoArray(r, i);
3684             }
3685         }
3686 
3687         assertArraysEquals(a, r, LongMaxVectorTests::not);
3688     }
3689 
3690 
3691 
3692     @Test(dataProvider = "longUnaryOpMaskProvider")
3693     static void NOTMaskedLongMaxVectorTests(IntFunction<long[]> fa,
3694                                                 IntFunction<boolean[]> fm) {
3695         long[] a = fa.apply(SPECIES.length());
3696         long[] r = fr.apply(SPECIES.length());
3697         boolean[] mask = fm.apply(SPECIES.length());
3698         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3699 
3700         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3701             for (int i = 0; i < a.length; i += SPECIES.length()) {
3702                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3703                 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i);
3704             }
3705         }
3706 
3707         assertArraysEquals(a, r, mask, LongMaxVectorTests::NOT);


< prev index next >