< prev index next >

test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java

Print this page




 229 
 230     interface FBinMaskOp {
 231         byte apply(byte a, byte 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(byte[] a, byte[] b, byte[] 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(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 250         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 251     }
 252 
 253     static void assertArraysEquals(byte[] a, byte[] b, byte[] 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(byte[] a, byte[] b, byte[] 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(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 279         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 280     }
 281 
 282     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 283         int i = 0;


1357     static byte OR(byte a, byte b) {
1358         return (byte)(a | b);
1359     }
1360 
1361     @Test(dataProvider = "byteBinaryOpProvider")
1362     static void ORByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1363         byte[] a = fa.apply(SPECIES.length());
1364         byte[] b = fb.apply(SPECIES.length());
1365         byte[] r = fr.apply(SPECIES.length());
1366 
1367         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1368             for (int i = 0; i < a.length; i += SPECIES.length()) {
1369                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1370                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1371                 av.lanewise(VectorOperators.OR, bv).intoArray(r, i);
1372             }
1373         }
1374 
1375         assertArraysEquals(a, b, r, ByteMaxVectorTests::OR);
1376     }




















1377 
1378 
1379 
1380     @Test(dataProvider = "byteBinaryOpMaskProvider")
1381     static void ORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1382                                           IntFunction<boolean[]> fm) {
1383         byte[] a = fa.apply(SPECIES.length());
1384         byte[] b = fb.apply(SPECIES.length());
1385         byte[] r = fr.apply(SPECIES.length());
1386         boolean[] mask = fm.apply(SPECIES.length());
1387         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1388 
1389         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1390             for (int i = 0; i < a.length; i += SPECIES.length()) {
1391                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1392                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1393                 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i);
1394             }
1395         }
1396 


1425     static void XORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1426                                           IntFunction<boolean[]> fm) {
1427         byte[] a = fa.apply(SPECIES.length());
1428         byte[] b = fb.apply(SPECIES.length());
1429         byte[] r = fr.apply(SPECIES.length());
1430         boolean[] mask = fm.apply(SPECIES.length());
1431         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1432 
1433         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1434             for (int i = 0; i < a.length; i += SPECIES.length()) {
1435                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1436                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1437                 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i);
1438             }
1439         }
1440 
1441         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::XOR);
1442     }
1443 
1444 























































































































































































1445 
1446 
1447     static byte LSHL(byte a, byte b) {
1448         return (byte)((a << (b & 0x7)));
1449     }
1450 
1451     @Test(dataProvider = "byteBinaryOpProvider")
1452     static void LSHLByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1453         byte[] a = fa.apply(SPECIES.length());
1454         byte[] b = fb.apply(SPECIES.length());
1455         byte[] r = fr.apply(SPECIES.length());
1456 
1457         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1458             for (int i = 0; i < a.length; i += SPECIES.length()) {
1459                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1460                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1461                 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i);
1462             }
1463         }
1464 


1787         return (byte)(Math.max(a, b));
1788     }
1789 
1790     @Test(dataProvider = "byteBinaryOpProvider")
1791     static void maxByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1792         byte[] a = fa.apply(SPECIES.length());
1793         byte[] b = fb.apply(SPECIES.length());
1794         byte[] r = fr.apply(SPECIES.length());
1795 
1796         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1797             for (int i = 0; i < a.length; i += SPECIES.length()) {
1798                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1799                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1800                 av.max(bv).intoArray(r, i);
1801             }
1802         }
1803 
1804         assertArraysEquals(a, b, r, ByteMaxVectorTests::max);
1805     }
1806 
























































1807     static byte AND(byte[] a, int idx) {
1808         byte res = -1;
1809         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1810             res &= a[i];
1811         }
1812 
1813         return res;
1814     }
1815 
1816     static byte AND(byte[] a) {
1817         byte res = -1;
1818         for (int i = 0; i < a.length; i += SPECIES.length()) {
1819             byte tmp = -1;
1820             for (int j = 0; j < SPECIES.length(); j++) {
1821                 tmp &= a[i + j];
1822             }
1823             res &= tmp;
1824         }
1825 
1826         return res;


3231         boolean[] mask = fm.apply(SPECIES.length());
3232         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3233 
3234         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3235             for (int i = 0; i < a.length; i += SPECIES.length()) {
3236                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3237                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3238                 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
3239                 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i);
3240             }
3241         }
3242 
3243         assertArraysEquals(a, b, c, r, mask, ByteMaxVectorTests::BITWISE_BLEND);
3244     }
3245 
3246 
3247     static byte NEG(byte a) {
3248         return (byte)(-((byte)a));
3249     }
3250 




3251     @Test(dataProvider = "byteUnaryOpProvider")
3252     static void NEGByteMaxVectorTests(IntFunction<byte[]> fa) {
3253         byte[] a = fa.apply(SPECIES.length());
3254         byte[] r = fr.apply(SPECIES.length());
3255 
3256         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3257             for (int i = 0; i < a.length; i += SPECIES.length()) {
3258                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3259                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
3260             }
3261         }
3262 
3263         assertArraysEquals(a, r, ByteMaxVectorTests::NEG);
3264     }
3265 















3266     @Test(dataProvider = "byteUnaryOpMaskProvider")
3267     static void NEGMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
3268                                                 IntFunction<boolean[]> fm) {
3269         byte[] a = fa.apply(SPECIES.length());
3270         byte[] r = fr.apply(SPECIES.length());
3271         boolean[] mask = fm.apply(SPECIES.length());
3272         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3273 
3274         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3275             for (int i = 0; i < a.length; i += SPECIES.length()) {
3276                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3277                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
3278             }
3279         }
3280 
3281         assertArraysEquals(a, r, mask, ByteMaxVectorTests::NEG);
3282     }
3283 
3284     static byte ABS(byte a) {
3285         return (byte)(Math.abs((byte)a));


3325         byte[] a = fa.apply(SPECIES.length());
3326         byte[] r = fr.apply(SPECIES.length());
3327         boolean[] mask = fm.apply(SPECIES.length());
3328         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3329 
3330         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3331             for (int i = 0; i < a.length; i += SPECIES.length()) {
3332                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3333                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
3334             }
3335         }
3336 
3337         assertArraysEquals(a, r, mask, ByteMaxVectorTests::ABS);
3338     }
3339 
3340 
3341     static byte NOT(byte a) {
3342         return (byte)(~((byte)a));
3343     }
3344 




3345 
3346 
3347     @Test(dataProvider = "byteUnaryOpProvider")
3348     static void NOTByteMaxVectorTests(IntFunction<byte[]> fa) {
3349         byte[] a = fa.apply(SPECIES.length());
3350         byte[] r = fr.apply(SPECIES.length());
3351 
3352         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3353             for (int i = 0; i < a.length; i += SPECIES.length()) {
3354                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3355                 av.lanewise(VectorOperators.NOT).intoArray(r, i);
3356             }
3357         }
3358 
3359         assertArraysEquals(a, r, ByteMaxVectorTests::NOT);















3360     }
3361 
3362 
3363 
3364     @Test(dataProvider = "byteUnaryOpMaskProvider")
3365     static void NOTMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
3366                                                 IntFunction<boolean[]> fm) {
3367         byte[] a = fa.apply(SPECIES.length());
3368         byte[] r = fr.apply(SPECIES.length());
3369         boolean[] mask = fm.apply(SPECIES.length());
3370         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3371 
3372         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3373             for (int i = 0; i < a.length; i += SPECIES.length()) {
3374                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3375                 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i);
3376             }
3377         }
3378 
3379         assertArraysEquals(a, r, mask, ByteMaxVectorTests::NOT);




 229 
 230     interface FBinMaskOp {
 231         byte apply(byte a, byte 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(byte[] a, byte[] b, byte[] 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(byte[] a, byte[] b, byte[] 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()]),
 257                                 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 258         }
 259     }
 260 
 261     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 262         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 263     }
 264 
 265     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 266         int i = 0;
 267         try {
 268             for (; i < a.length; i++) {
 269                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 270             }
 271         } catch (AssertionError err) {
 272             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()]);
 273         }
 274     }
 275 
 276     static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 277         assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 278     }
 279 
 280     static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 281         int i = 0;
 282         try {
 283             for (; i < a.length; i++) {
 284                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 285             }
 286         } catch (AssertionError err) {
 287             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 
 288                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 
 289                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 290                                 mask[i % SPECIES.length()]);
 291         }
 292     }
 293 
 294     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) {
 295         int i = 0;
 296         int j = 0;
 297         try {
 298             for (; j < a.length; j += SPECIES.length()) {
 299                 for (i = 0; i < SPECIES.length(); i++) {
 300                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
 301                 }
 302             }
 303         } catch (AssertionError e) {
 304             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
 305         }
 306     }
 307 
 308     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 309         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 310     }
 311 
 312     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 313         int i = 0;


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


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


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


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


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


< prev index next >