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()]), 257 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 258 } 259 } 260 261 static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 262 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 263 } 264 265 static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 266 int i = 0; 267 try { 268 for (; i < a.length; i++) { 269 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 270 } 271 } catch (AssertionError err) { 272 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 273 } 274 } 275 276 static void assertBroadcastArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 277 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 278 } 279 280 static void assertBroadcastArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 281 int i = 0; 282 try { 283 for (; i < a.length; i++) { 284 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 285 } 286 } catch (AssertionError err) { 287 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 288 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 289 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 290 mask[i % SPECIES.length()]); 291 } 292 } 293 294 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, FBinOp f) { 295 int i = 0; 296 int j = 0; 297 try { 298 for (; j < a.length; j += SPECIES.length()) { 299 for (i = 0; i < SPECIES.length(); i++) { 300 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 301 } 302 } 303 } catch (AssertionError e) { 304 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 305 } 306 } 307 308 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 309 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 310 } 311 312 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 313 int i = 0; 1387 static short OR(short a, short b) { 1388 return (short)(a | b); 1389 } 1390 1391 @Test(dataProvider = "shortBinaryOpProvider") 1392 static void ORShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1393 short[] a = fa.apply(SPECIES.length()); 1394 short[] b = fb.apply(SPECIES.length()); 1395 short[] r = fr.apply(SPECIES.length()); 1396 1397 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1398 for (int i = 0; i < a.length; i += SPECIES.length()) { 1399 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1400 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1401 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1402 } 1403 } 1404 1405 assertArraysEquals(a, b, r, ShortMaxVectorTests::OR); 1406 } 1407 static short or(short a, short b) { 1408 return (short)(a | b); 1409 } 1410 1411 @Test(dataProvider = "shortBinaryOpProvider") 1412 static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1413 short[] a = fa.apply(SPECIES.length()); 1414 short[] b = fb.apply(SPECIES.length()); 1415 short[] r = fr.apply(SPECIES.length()); 1416 1417 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1418 for (int i = 0; i < a.length; i += SPECIES.length()) { 1419 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1420 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1421 av.or(bv).intoArray(r, i); 1422 } 1423 } 1424 1425 assertArraysEquals(a, b, r, ShortMaxVectorTests::or); 1426 } 1427 1428 1429 1430 @Test(dataProvider = "shortBinaryOpMaskProvider") 1431 static void ORShortMaxVectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1432 IntFunction<boolean[]> fm) { 1433 short[] a = fa.apply(SPECIES.length()); 1434 short[] b = fb.apply(SPECIES.length()); 1435 short[] r = fr.apply(SPECIES.length()); 1436 boolean[] mask = fm.apply(SPECIES.length()); 1437 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1438 1439 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1440 for (int i = 0; i < a.length; i += SPECIES.length()) { 1441 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1442 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1443 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1444 } 1445 } 1446 1475 static void XORShortMaxVectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1476 IntFunction<boolean[]> fm) { 1477 short[] a = fa.apply(SPECIES.length()); 1478 short[] b = fb.apply(SPECIES.length()); 1479 short[] r = fr.apply(SPECIES.length()); 1480 boolean[] mask = fm.apply(SPECIES.length()); 1481 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1482 1483 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1484 for (int i = 0; i < a.length; i += SPECIES.length()) { 1485 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1486 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1487 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1488 } 1489 } 1490 1491 assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::XOR); 1492 } 1493 1494 1495 @Test(dataProvider = "shortBinaryOpProvider") 1496 static void addShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1497 short[] a = fa.apply(SPECIES.length()); 1498 short[] b = fb.apply(SPECIES.length()); 1499 short[] r = fr.apply(SPECIES.length()); 1500 1501 for (int i = 0; i < a.length; i += SPECIES.length()) { 1502 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1503 av.add(b[i]).intoArray(r, i); 1504 } 1505 1506 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::add); 1507 } 1508 1509 @Test(dataProvider = "shortBinaryOpMaskProvider") 1510 static void addShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1511 IntFunction<boolean[]> fm) { 1512 short[] a = fa.apply(SPECIES.length()); 1513 short[] b = fb.apply(SPECIES.length()); 1514 short[] r = fr.apply(SPECIES.length()); 1515 boolean[] mask = fm.apply(SPECIES.length()); 1516 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1517 1518 for (int i = 0; i < a.length; i += SPECIES.length()) { 1519 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1520 av.add(b[i], vmask).intoArray(r, i); 1521 } 1522 1523 assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::add); 1524 } 1525 1526 @Test(dataProvider = "shortBinaryOpProvider") 1527 static void subShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1528 short[] a = fa.apply(SPECIES.length()); 1529 short[] b = fb.apply(SPECIES.length()); 1530 short[] r = fr.apply(SPECIES.length()); 1531 1532 for (int i = 0; i < a.length; i += SPECIES.length()) { 1533 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1534 av.sub(b[i]).intoArray(r, i); 1535 } 1536 1537 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::sub); 1538 } 1539 1540 @Test(dataProvider = "shortBinaryOpMaskProvider") 1541 static void subShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1542 IntFunction<boolean[]> fm) { 1543 short[] a = fa.apply(SPECIES.length()); 1544 short[] b = fb.apply(SPECIES.length()); 1545 short[] r = fr.apply(SPECIES.length()); 1546 boolean[] mask = fm.apply(SPECIES.length()); 1547 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1548 1549 for (int i = 0; i < a.length; i += SPECIES.length()) { 1550 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1551 av.sub(b[i], vmask).intoArray(r, i); 1552 } 1553 1554 assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::sub); 1555 } 1556 1557 @Test(dataProvider = "shortBinaryOpProvider") 1558 static void mulShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1559 short[] a = fa.apply(SPECIES.length()); 1560 short[] b = fb.apply(SPECIES.length()); 1561 short[] r = fr.apply(SPECIES.length()); 1562 1563 for (int i = 0; i < a.length; i += SPECIES.length()) { 1564 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1565 av.mul(b[i]).intoArray(r, i); 1566 } 1567 1568 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::mul); 1569 } 1570 1571 @Test(dataProvider = "shortBinaryOpMaskProvider") 1572 static void mulShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1573 IntFunction<boolean[]> fm) { 1574 short[] a = fa.apply(SPECIES.length()); 1575 short[] b = fb.apply(SPECIES.length()); 1576 short[] r = fr.apply(SPECIES.length()); 1577 boolean[] mask = fm.apply(SPECIES.length()); 1578 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1579 1580 for (int i = 0; i < a.length; i += SPECIES.length()) { 1581 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1582 av.mul(b[i], vmask).intoArray(r, i); 1583 } 1584 1585 assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::mul); 1586 } 1587 1588 1589 1590 1591 @Test(dataProvider = "shortBinaryOpProvider") 1592 static void divShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1593 short[] a = fa.apply(SPECIES.length()); 1594 short[] b = fb.apply(SPECIES.length()); 1595 short[] r = fr.apply(SPECIES.length()); 1596 1597 replaceZero(b, (short) 1); 1598 1599 for (int i = 0; i < a.length; i += SPECIES.length()) { 1600 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1601 av.div(b[i]).intoArray(r, i); 1602 } 1603 1604 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::div); 1605 } 1606 1607 1608 1609 @Test(dataProvider = "shortBinaryOpMaskProvider") 1610 static void divShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1611 IntFunction<boolean[]> fm) { 1612 short[] a = fa.apply(SPECIES.length()); 1613 short[] b = fb.apply(SPECIES.length()); 1614 short[] r = fr.apply(SPECIES.length()); 1615 boolean[] mask = fm.apply(SPECIES.length()); 1616 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1617 1618 replaceZero(b, (short) 1); 1619 1620 for (int i = 0; i < a.length; i += SPECIES.length()) { 1621 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1622 av.div(b[i], vmask).intoArray(r, i); 1623 } 1624 1625 assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::div); 1626 } 1627 1628 1629 1630 @Test(dataProvider = "shortBinaryOpProvider") 1631 static void ORShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1632 short[] a = fa.apply(SPECIES.length()); 1633 short[] b = fb.apply(SPECIES.length()); 1634 short[] r = fr.apply(SPECIES.length()); 1635 1636 for (int i = 0; i < a.length; i += SPECIES.length()) { 1637 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1638 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); 1639 } 1640 1641 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::OR); 1642 } 1643 1644 @Test(dataProvider = "shortBinaryOpProvider") 1645 static void orShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1646 short[] a = fa.apply(SPECIES.length()); 1647 short[] b = fb.apply(SPECIES.length()); 1648 short[] r = fr.apply(SPECIES.length()); 1649 1650 for (int i = 0; i < a.length; i += SPECIES.length()) { 1651 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1652 av.or(b[i]).intoArray(r, i); 1653 } 1654 1655 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::or); 1656 } 1657 1658 1659 1660 @Test(dataProvider = "shortBinaryOpMaskProvider") 1661 static void ORShortMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1662 IntFunction<boolean[]> fm) { 1663 short[] a = fa.apply(SPECIES.length()); 1664 short[] b = fb.apply(SPECIES.length()); 1665 short[] r = fr.apply(SPECIES.length()); 1666 boolean[] mask = fm.apply(SPECIES.length()); 1667 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1668 1669 for (int i = 0; i < a.length; i += SPECIES.length()) { 1670 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1671 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); 1672 } 1673 1674 assertBroadcastArraysEquals(a, b, r, mask, ShortMaxVectorTests::OR); 1675 } 1676 1677 1678 1679 1680 1681 1682 static short LSHL(short a, short b) { 1683 return (short)((a << (b & 0xF))); 1684 } 1685 1686 @Test(dataProvider = "shortBinaryOpProvider") 1687 static void LSHLShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1688 short[] a = fa.apply(SPECIES.length()); 1689 short[] b = fb.apply(SPECIES.length()); 1690 short[] r = fr.apply(SPECIES.length()); 1691 1692 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1693 for (int i = 0; i < a.length; i += SPECIES.length()) { 1694 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1695 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1696 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1697 } 2020 return (short)(Math.max(a, b)); 2021 } 2022 2023 @Test(dataProvider = "shortBinaryOpProvider") 2024 static void maxShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2025 short[] a = fa.apply(SPECIES.length()); 2026 short[] b = fb.apply(SPECIES.length()); 2027 short[] r = fr.apply(SPECIES.length()); 2028 2029 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2030 for (int i = 0; i < a.length; i += SPECIES.length()) { 2031 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2032 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2033 av.max(bv).intoArray(r, i); 2034 } 2035 } 2036 2037 assertArraysEquals(a, b, r, ShortMaxVectorTests::max); 2038 } 2039 2040 @Test(dataProvider = "shortBinaryOpProvider") 2041 static void MINShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2042 short[] a = fa.apply(SPECIES.length()); 2043 short[] b = fb.apply(SPECIES.length()); 2044 short[] r = fr.apply(SPECIES.length()); 2045 2046 for (int i = 0; i < a.length; i += SPECIES.length()) { 2047 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2048 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2049 } 2050 2051 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::MIN); 2052 } 2053 2054 @Test(dataProvider = "shortBinaryOpProvider") 2055 static void minShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2056 short[] a = fa.apply(SPECIES.length()); 2057 short[] b = fb.apply(SPECIES.length()); 2058 short[] r = fr.apply(SPECIES.length()); 2059 2060 for (int i = 0; i < a.length; i += SPECIES.length()) { 2061 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2062 av.min(b[i]).intoArray(r, i); 2063 } 2064 2065 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::min); 2066 } 2067 2068 @Test(dataProvider = "shortBinaryOpProvider") 2069 static void MAXShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2070 short[] a = fa.apply(SPECIES.length()); 2071 short[] b = fb.apply(SPECIES.length()); 2072 short[] r = fr.apply(SPECIES.length()); 2073 2074 for (int i = 0; i < a.length; i += SPECIES.length()) { 2075 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2076 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2077 } 2078 2079 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::MAX); 2080 } 2081 2082 @Test(dataProvider = "shortBinaryOpProvider") 2083 static void maxShortMaxVectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2084 short[] a = fa.apply(SPECIES.length()); 2085 short[] b = fb.apply(SPECIES.length()); 2086 short[] r = fr.apply(SPECIES.length()); 2087 2088 for (int i = 0; i < a.length; i += SPECIES.length()) { 2089 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2090 av.max(b[i]).intoArray(r, i); 2091 } 2092 2093 assertBroadcastArraysEquals(a, b, r, ShortMaxVectorTests::max); 2094 } 2095 2096 static short AND(short[] a, int idx) { 2097 short res = -1; 2098 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2099 res &= a[i]; 2100 } 2101 2102 return res; 2103 } 2104 2105 static short AND(short[] a) { 2106 short res = -1; 2107 for (int i = 0; i < a.length; i += SPECIES.length()) { 2108 short tmp = -1; 2109 for (int j = 0; j < SPECIES.length(); j++) { 2110 tmp &= a[i + j]; 2111 } 2112 res &= tmp; 2113 } 2114 2115 return res; 3520 boolean[] mask = fm.apply(SPECIES.length()); 3521 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3522 3523 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3524 for (int i = 0; i < a.length; i += SPECIES.length()) { 3525 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3526 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3527 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 3528 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 3529 } 3530 } 3531 3532 assertArraysEquals(a, b, c, r, mask, ShortMaxVectorTests::BITWISE_BLEND); 3533 } 3534 3535 3536 static short NEG(short a) { 3537 return (short)(-((short)a)); 3538 } 3539 3540 static short neg(short a) { 3541 return (short)(-((short)a)); 3542 } 3543 3544 @Test(dataProvider = "shortUnaryOpProvider") 3545 static void NEGShortMaxVectorTests(IntFunction<short[]> fa) { 3546 short[] a = fa.apply(SPECIES.length()); 3547 short[] r = fr.apply(SPECIES.length()); 3548 3549 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3550 for (int i = 0; i < a.length; i += SPECIES.length()) { 3551 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3552 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3553 } 3554 } 3555 3556 assertArraysEquals(a, r, ShortMaxVectorTests::NEG); 3557 } 3558 3559 @Test(dataProvider = "shortUnaryOpProvider") 3560 static void negShortMaxVectorTests(IntFunction<short[]> fa) { 3561 short[] a = fa.apply(SPECIES.length()); 3562 short[] r = fr.apply(SPECIES.length()); 3563 3564 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3565 for (int i = 0; i < a.length; i += SPECIES.length()) { 3566 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3567 av.neg().intoArray(r, i); 3568 } 3569 } 3570 3571 assertArraysEquals(a, r, ShortMaxVectorTests::neg); 3572 } 3573 3574 @Test(dataProvider = "shortUnaryOpMaskProvider") 3575 static void NEGMaskedShortMaxVectorTests(IntFunction<short[]> fa, 3576 IntFunction<boolean[]> fm) { 3577 short[] a = fa.apply(SPECIES.length()); 3578 short[] r = fr.apply(SPECIES.length()); 3579 boolean[] mask = fm.apply(SPECIES.length()); 3580 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3581 3582 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3583 for (int i = 0; i < a.length; i += SPECIES.length()) { 3584 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3585 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3586 } 3587 } 3588 3589 assertArraysEquals(a, r, mask, ShortMaxVectorTests::NEG); 3590 } 3591 3592 static short ABS(short a) { 3593 return (short)(Math.abs((short)a)); 3633 short[] a = fa.apply(SPECIES.length()); 3634 short[] r = fr.apply(SPECIES.length()); 3635 boolean[] mask = fm.apply(SPECIES.length()); 3636 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3637 3638 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3639 for (int i = 0; i < a.length; i += SPECIES.length()) { 3640 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3641 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3642 } 3643 } 3644 3645 assertArraysEquals(a, r, mask, ShortMaxVectorTests::ABS); 3646 } 3647 3648 3649 static short NOT(short a) { 3650 return (short)(~((short)a)); 3651 } 3652 3653 static short not(short a) { 3654 return (short)(~((short)a)); 3655 } 3656 3657 3658 3659 @Test(dataProvider = "shortUnaryOpProvider") 3660 static void NOTShortMaxVectorTests(IntFunction<short[]> fa) { 3661 short[] a = fa.apply(SPECIES.length()); 3662 short[] r = fr.apply(SPECIES.length()); 3663 3664 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3665 for (int i = 0; i < a.length; i += SPECIES.length()) { 3666 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3667 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3668 } 3669 } 3670 3671 assertArraysEquals(a, r, ShortMaxVectorTests::NOT); 3672 } 3673 3674 @Test(dataProvider = "shortUnaryOpProvider") 3675 static void notShortMaxVectorTests(IntFunction<short[]> fa) { 3676 short[] a = fa.apply(SPECIES.length()); 3677 short[] r = fr.apply(SPECIES.length()); 3678 3679 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3680 for (int i = 0; i < a.length; i += SPECIES.length()) { 3681 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3682 av.not().intoArray(r, i); 3683 } 3684 } 3685 3686 assertArraysEquals(a, r, ShortMaxVectorTests::not); 3687 } 3688 3689 3690 3691 @Test(dataProvider = "shortUnaryOpMaskProvider") 3692 static void NOTMaskedShortMaxVectorTests(IntFunction<short[]> fa, 3693 IntFunction<boolean[]> fm) { 3694 short[] a = fa.apply(SPECIES.length()); 3695 short[] r = fr.apply(SPECIES.length()); 3696 boolean[] mask = fm.apply(SPECIES.length()); 3697 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3698 3699 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3700 for (int i = 0; i < a.length; i += SPECIES.length()) { 3701 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3702 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3703 } 3704 } 3705 3706 assertArraysEquals(a, r, mask, ShortMaxVectorTests::NOT); |