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


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


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


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


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


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


< prev index next >