< prev index next >

test/jdk/jdk/incubator/vector/Byte128VectorTests.java

Print this page




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












 244     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 245         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 246     }
 247 
 248     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 249         int i = 0;
 250         try {
 251             for (; i < a.length; i++) {
 252                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 253             }
 254         } catch (AssertionError err) {
 255             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()]);
 256         }
 257     }
 258 


















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


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




















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


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























































































































































































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


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
























































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


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




3246     @Test(dataProvider = "byteUnaryOpProvider")
3247     static void NEGByte128VectorTests(IntFunction<byte[]> fa) {
3248         byte[] a = fa.apply(SPECIES.length());
3249         byte[] r = fr.apply(SPECIES.length());
3250 
3251         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3252             for (int i = 0; i < a.length; i += SPECIES.length()) {
3253                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3254                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
3255             }
3256         }
3257 
3258         assertArraysEquals(a, r, Byte128VectorTests::NEG);
3259     }
3260 















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


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




3340 
3341 
3342     @Test(dataProvider = "byteUnaryOpProvider")
3343     static void NOTByte128VectorTests(IntFunction<byte[]> fa) {
3344         byte[] a = fa.apply(SPECIES.length());
3345         byte[] r = fr.apply(SPECIES.length());
3346 
3347         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3348             for (int i = 0; i < a.length; i += SPECIES.length()) {
3349                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3350                 av.lanewise(VectorOperators.NOT).intoArray(r, i);
3351             }
3352         }
3353 
3354         assertArraysEquals(a, r, Byte128VectorTests::NOT);















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




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


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


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


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


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


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


< prev index next >