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


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


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


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


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


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


< prev index next >