< prev index next >

test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java

Print this page




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


1357     static short OR(short a, short b) {
1358         return (short)(a | b);
1359     }
1360 
1361     @Test(dataProvider = "shortBinaryOpProvider")
1362     static void ORShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1363         short[] a = fa.apply(SPECIES.length());
1364         short[] b = fb.apply(SPECIES.length());
1365         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1370                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1371                 av.lanewise(VectorOperators.OR, bv).intoArray(r, i);
1372             }
1373         }
1374 
1375         assertArraysEquals(a, b, r, ShortMaxVectorTests::OR);
1376     }




















1377 
1378 
1379 
1380     @Test(dataProvider = "shortBinaryOpMaskProvider")
1381     static void ORShortMaxVectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
1382                                           IntFunction<boolean[]> fm) {
1383         short[] a = fa.apply(SPECIES.length());
1384         short[] b = fb.apply(SPECIES.length());
1385         short[] r = fr.apply(SPECIES.length());
1386         boolean[] mask = fm.apply(SPECIES.length());
1387         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1392                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1393                 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i);
1394             }
1395         }
1396 


1425     static void XORShortMaxVectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
1426                                           IntFunction<boolean[]> fm) {
1427         short[] a = fa.apply(SPECIES.length());
1428         short[] b = fb.apply(SPECIES.length());
1429         short[] r = fr.apply(SPECIES.length());
1430         boolean[] mask = fm.apply(SPECIES.length());
1431         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1436                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1437                 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i);
1438             }
1439         }
1440 
1441         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::XOR);
1442     }
1443 
1444 























































































































































































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


1787         return (short)(Math.max(a, b));
1788     }
1789 
1790     @Test(dataProvider = "shortBinaryOpProvider")
1791     static void maxShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1792         short[] a = fa.apply(SPECIES.length());
1793         short[] b = fb.apply(SPECIES.length());
1794         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1799                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1800                 av.max(bv).intoArray(r, i);
1801             }
1802         }
1803 
1804         assertArraysEquals(a, b, r, ShortMaxVectorTests::max);
1805     }
1806 
























































1807     static short AND(short[] a, int idx) {
1808         short 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 short AND(short[] a) {
1817         short res = -1;
1818         for (int i = 0; i < a.length; i += SPECIES.length()) {
1819             short 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<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3237                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
3238                 ShortVector cv = ShortVector.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, ShortMaxVectorTests::BITWISE_BLEND);
3244     }
3245 
3246 
3247     static short NEG(short a) {
3248         return (short)(-((short)a));
3249     }
3250 




3251     @Test(dataProvider = "shortUnaryOpProvider")
3252     static void NEGShortMaxVectorTests(IntFunction<short[]> fa) {
3253         short[] a = fa.apply(SPECIES.length());
3254         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3259                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
3260             }
3261         }
3262 
3263         assertArraysEquals(a, r, ShortMaxVectorTests::NEG);
3264     }
3265 















3266     @Test(dataProvider = "shortUnaryOpMaskProvider")
3267     static void NEGMaskedShortMaxVectorTests(IntFunction<short[]> fa,
3268                                                 IntFunction<boolean[]> fm) {
3269         short[] a = fa.apply(SPECIES.length());
3270         short[] r = fr.apply(SPECIES.length());
3271         boolean[] mask = fm.apply(SPECIES.length());
3272         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3277                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
3278             }
3279         }
3280 
3281         assertArraysEquals(a, r, mask, ShortMaxVectorTests::NEG);
3282     }
3283 
3284     static short ABS(short a) {
3285         return (short)(Math.abs((short)a));


3325         short[] a = fa.apply(SPECIES.length());
3326         short[] r = fr.apply(SPECIES.length());
3327         boolean[] mask = fm.apply(SPECIES.length());
3328         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3333                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
3334             }
3335         }
3336 
3337         assertArraysEquals(a, r, mask, ShortMaxVectorTests::ABS);
3338     }
3339 
3340 
3341     static short NOT(short a) {
3342         return (short)(~((short)a));
3343     }
3344 




3345 
3346 
3347     @Test(dataProvider = "shortUnaryOpProvider")
3348     static void NOTShortMaxVectorTests(IntFunction<short[]> fa) {
3349         short[] a = fa.apply(SPECIES.length());
3350         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3355                 av.lanewise(VectorOperators.NOT).intoArray(r, i);
3356             }
3357         }
3358 
3359         assertArraysEquals(a, r, ShortMaxVectorTests::NOT);















3360     }
3361 
3362 
3363 
3364     @Test(dataProvider = "shortUnaryOpMaskProvider")
3365     static void NOTMaskedShortMaxVectorTests(IntFunction<short[]> fa,
3366                                                 IntFunction<boolean[]> fm) {
3367         short[] a = fa.apply(SPECIES.length());
3368         short[] r = fr.apply(SPECIES.length());
3369         boolean[] mask = fm.apply(SPECIES.length());
3370         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3375                 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i);
3376             }
3377         }
3378 
3379         assertArraysEquals(a, r, mask, ShortMaxVectorTests::NOT);




 229 
 230     interface FBinMaskOp {
 231         short apply(short a, short 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(short[] a, short[] b, short[] 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(short[] a, short[] b, short[] 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(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) {
 261         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 262     }
 263 
 264     static void assertArraysEquals(short[] a, short[] b, short[] 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(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) {
 276         assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 277     }
 278 
 279     static void assertBroadcastArraysEquals(short[] a, short[] b, short[] 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(short[] a, short[] b, short[] 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(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) {
 305         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 306     }
 307 
 308     static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) {
 309         int i = 0;


1383     static short OR(short a, short b) {
1384         return (short)(a | b);
1385     }
1386 
1387     @Test(dataProvider = "shortBinaryOpProvider")
1388     static void ORShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1389         short[] a = fa.apply(SPECIES.length());
1390         short[] b = fb.apply(SPECIES.length());
1391         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1396                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1397                 av.lanewise(VectorOperators.OR, bv).intoArray(r, i);
1398             }
1399         }
1400 
1401         assertArraysEquals(a, b, r, ShortMaxVectorTests::OR);
1402     }
1403     static short or(short a, short b) {
1404         return (short)(a | b);
1405     }
1406 
1407     @Test(dataProvider = "shortBinaryOpProvider")
1408     static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1409         short[] a = fa.apply(SPECIES.length());
1410         short[] b = fb.apply(SPECIES.length());
1411         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1416                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1417                 av.or(bv).intoArray(r, i);
1418             }
1419         }
1420 
1421         assertArraysEquals(a, b, r, ShortMaxVectorTests::or);
1422     }
1423 
1424 
1425 
1426     @Test(dataProvider = "shortBinaryOpMaskProvider")
1427     static void ORShortMaxVectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb,
1428                                           IntFunction<boolean[]> fm) {
1429         short[] a = fa.apply(SPECIES.length());
1430         short[] b = fb.apply(SPECIES.length());
1431         short[] r = fr.apply(SPECIES.length());
1432         boolean[] mask = fm.apply(SPECIES.length());
1433         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1438                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1439                 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i);
1440             }
1441         }
1442 


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


2016         return (short)(Math.max(a, b));
2017     }
2018 
2019     @Test(dataProvider = "shortBinaryOpProvider")
2020     static void maxShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
2021         short[] a = fa.apply(SPECIES.length());
2022         short[] b = fb.apply(SPECIES.length());
2023         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
2028                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
2029                 av.max(bv).intoArray(r, i);
2030             }
2031         }
2032 
2033         assertArraysEquals(a, b, r, ShortMaxVectorTests::max);
2034     }
2035 
2036     @Test(dataProvider = "shortBinaryOpProvider")
2037     static void MINShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) {
2038         short[] a = fa.apply(SPECIES.length());
2039         short[] b = fb.apply(SPECIES.length());
2040         short[] r = fr.apply(SPECIES.length());
2041 
2042         for (int i = 0; i < a.length; i += SPECIES.length()) {
2043             ShortVector av = ShortVector.fromArray(SPECIES, a, i);
2044             av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i);
2045         }
2046 
2047         assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::MIN);
2048     }
2049 
2050     @Test(dataProvider = "shortBinaryOpProvider")
2051     static void minShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) {
2052         short[] a = fa.apply(SPECIES.length());
2053         short[] b = fb.apply(SPECIES.length());
2054         short[] r = fr.apply(SPECIES.length());
2055 
2056         for (int i = 0; i < a.length; i += SPECIES.length()) {
2057             ShortVector av = ShortVector.fromArray(SPECIES, a, i);
2058             av.min(b[i]).intoArray(r, i);
2059         }
2060 
2061         assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::min);
2062     }
2063 
2064     @Test(dataProvider = "shortBinaryOpProvider")
2065     static void MAXShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) {
2066         short[] a = fa.apply(SPECIES.length());
2067         short[] b = fb.apply(SPECIES.length());
2068         short[] r = fr.apply(SPECIES.length());
2069 
2070         for (int i = 0; i < a.length; i += SPECIES.length()) {
2071             ShortVector av = ShortVector.fromArray(SPECIES, a, i);
2072             av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i);
2073         }
2074 
2075         assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::MAX);
2076     }
2077 
2078     @Test(dataProvider = "shortBinaryOpProvider")
2079     static void maxShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) {
2080         short[] a = fa.apply(SPECIES.length());
2081         short[] b = fb.apply(SPECIES.length());
2082         short[] r = fr.apply(SPECIES.length());
2083 
2084         for (int i = 0; i < a.length; i += SPECIES.length()) {
2085             ShortVector av = ShortVector.fromArray(SPECIES, a, i);
2086             av.max(b[i]).intoArray(r, i);
2087         }
2088 
2089         assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::max);
2090     }
2091 
2092     static short AND(short[] a, int idx) {
2093         short 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 short AND(short[] a) {
2102         short res = -1;
2103         for (int i = 0; i < a.length; i += SPECIES.length()) {
2104             short 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<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3522                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
3523                 ShortVector cv = ShortVector.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, ShortMaxVectorTests::BITWISE_BLEND);
3529     }
3530 
3531 
3532     static short NEG(short a) {
3533         return (short)(-((short)a));
3534     }
3535 
3536     static short neg(short a) {
3537         return (short)(-((short)a));
3538     }
3539 
3540     @Test(dataProvider = "shortUnaryOpProvider")
3541     static void NEGShortMaxVectorTests(IntFunction<short[]> fa) {
3542         short[] a = fa.apply(SPECIES.length());
3543         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3548                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
3549             }
3550         }
3551 
3552         assertArraysEquals(a, r, ShortMaxVectorTests::NEG);
3553     }
3554 
3555     @Test(dataProvider = "shortUnaryOpProvider")
3556     static void negShortMaxVectorTests(IntFunction<short[]> fa) {
3557         short[] a = fa.apply(SPECIES.length());
3558         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3563                 av.neg().intoArray(r, i);
3564             }
3565         }
3566 
3567         assertArraysEquals(a, r, ShortMaxVectorTests::neg);
3568     }
3569 
3570     @Test(dataProvider = "shortUnaryOpMaskProvider")
3571     static void NEGMaskedShortMaxVectorTests(IntFunction<short[]> fa,
3572                                                 IntFunction<boolean[]> fm) {
3573         short[] a = fa.apply(SPECIES.length());
3574         short[] r = fr.apply(SPECIES.length());
3575         boolean[] mask = fm.apply(SPECIES.length());
3576         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3581                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
3582             }
3583         }
3584 
3585         assertArraysEquals(a, r, mask, ShortMaxVectorTests::NEG);
3586     }
3587 
3588     static short ABS(short a) {
3589         return (short)(Math.abs((short)a));


3629         short[] a = fa.apply(SPECIES.length());
3630         short[] r = fr.apply(SPECIES.length());
3631         boolean[] mask = fm.apply(SPECIES.length());
3632         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3637                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
3638             }
3639         }
3640 
3641         assertArraysEquals(a, r, mask, ShortMaxVectorTests::ABS);
3642     }
3643 
3644 
3645     static short NOT(short a) {
3646         return (short)(~((short)a));
3647     }
3648 
3649     static short not(short a) {
3650         return (short)(~((short)a));
3651     }
3652 
3653 
3654 
3655     @Test(dataProvider = "shortUnaryOpProvider")
3656     static void NOTShortMaxVectorTests(IntFunction<short[]> fa) {
3657         short[] a = fa.apply(SPECIES.length());
3658         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3663                 av.lanewise(VectorOperators.NOT).intoArray(r, i);
3664             }
3665         }
3666 
3667         assertArraysEquals(a, r, ShortMaxVectorTests::NOT);
3668     }
3669 
3670     @Test(dataProvider = "shortUnaryOpProvider")
3671     static void notShortMaxVectorTests(IntFunction<short[]> fa) {
3672         short[] a = fa.apply(SPECIES.length());
3673         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3678                 av.not().intoArray(r, i);
3679             }
3680         }
3681 
3682         assertArraysEquals(a, r, ShortMaxVectorTests::not);
3683     }
3684 
3685 
3686 
3687     @Test(dataProvider = "shortUnaryOpMaskProvider")
3688     static void NOTMaskedShortMaxVectorTests(IntFunction<short[]> fa,
3689                                                 IntFunction<boolean[]> fm) {
3690         short[] a = fa.apply(SPECIES.length());
3691         short[] r = fr.apply(SPECIES.length());
3692         boolean[] mask = fm.apply(SPECIES.length());
3693         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
3698                 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i);
3699             }
3700         }
3701 
3702         assertArraysEquals(a, r, mask, ShortMaxVectorTests::NOT);


< prev index next >