224 225 interface FBinMaskOp { 226 short apply(short a, short b, boolean m); 227 228 static FBinMaskOp lift(FBinOp f) { 229 return (a, b, m) -> m ? f.apply(a, b) : a; 230 } 231 } 232 233 static void assertArraysEquals(short[] a, short[] b, short[] r, FBinOp f) { 234 int i = 0; 235 try { 236 for (; i < a.length; i++) { 237 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 238 } 239 } catch (AssertionError e) { 240 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 241 } 242 } 243 244 static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 245 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 246 } 247 248 static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 249 int i = 0; 250 try { 251 for (; i < a.length; i++) { 252 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 253 } 254 } catch (AssertionError err) { 255 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 256 } 257 } 258 259 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, FBinOp f) { 260 int i = 0; 261 int j = 0; 262 try { 263 for (; j < a.length; j += SPECIES.length()) { 264 for (i = 0; i < SPECIES.length(); i++) { 265 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 266 } 267 } 268 } catch (AssertionError e) { 269 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 270 } 271 } 272 273 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 274 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 275 } 276 277 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 278 int i = 0; 1352 static short OR(short a, short b) { 1353 return (short)(a | b); 1354 } 1355 1356 @Test(dataProvider = "shortBinaryOpProvider") 1357 static void ORShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1358 short[] a = fa.apply(SPECIES.length()); 1359 short[] b = fb.apply(SPECIES.length()); 1360 short[] r = fr.apply(SPECIES.length()); 1361 1362 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1363 for (int i = 0; i < a.length; i += SPECIES.length()) { 1364 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1365 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1366 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1367 } 1368 } 1369 1370 assertArraysEquals(a, b, r, Short64VectorTests::OR); 1371 } 1372 1373 1374 1375 @Test(dataProvider = "shortBinaryOpMaskProvider") 1376 static void ORShort64VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1377 IntFunction<boolean[]> fm) { 1378 short[] a = fa.apply(SPECIES.length()); 1379 short[] b = fb.apply(SPECIES.length()); 1380 short[] r = fr.apply(SPECIES.length()); 1381 boolean[] mask = fm.apply(SPECIES.length()); 1382 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1383 1384 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1385 for (int i = 0; i < a.length; i += SPECIES.length()) { 1386 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1387 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1388 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1389 } 1390 } 1391 1420 static void XORShort64VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1421 IntFunction<boolean[]> fm) { 1422 short[] a = fa.apply(SPECIES.length()); 1423 short[] b = fb.apply(SPECIES.length()); 1424 short[] r = fr.apply(SPECIES.length()); 1425 boolean[] mask = fm.apply(SPECIES.length()); 1426 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1427 1428 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1429 for (int i = 0; i < a.length; i += SPECIES.length()) { 1430 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1431 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1432 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1433 } 1434 } 1435 1436 assertArraysEquals(a, b, r, mask, Short64VectorTests::XOR); 1437 } 1438 1439 1440 1441 1442 1443 1444 static short LSHL(short a, short b) { 1445 return (short)((a << (b & 0xF))); 1446 } 1447 1448 @Test(dataProvider = "shortBinaryOpProvider") 1449 static void LSHLShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1450 short[] a = fa.apply(SPECIES.length()); 1451 short[] b = fb.apply(SPECIES.length()); 1452 short[] r = fr.apply(SPECIES.length()); 1453 1454 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1455 for (int i = 0; i < a.length; i += SPECIES.length()) { 1456 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1457 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1458 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1459 } 1782 return (short)(Math.max(a, b)); 1783 } 1784 1785 @Test(dataProvider = "shortBinaryOpProvider") 1786 static void maxShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1787 short[] a = fa.apply(SPECIES.length()); 1788 short[] b = fb.apply(SPECIES.length()); 1789 short[] r = fr.apply(SPECIES.length()); 1790 1791 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1792 for (int i = 0; i < a.length; i += SPECIES.length()) { 1793 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1794 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1795 av.max(bv).intoArray(r, i); 1796 } 1797 } 1798 1799 assertArraysEquals(a, b, r, Short64VectorTests::max); 1800 } 1801 1802 static short AND(short[] a, int idx) { 1803 short res = -1; 1804 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1805 res &= a[i]; 1806 } 1807 1808 return res; 1809 } 1810 1811 static short AND(short[] a) { 1812 short res = -1; 1813 for (int i = 0; i < a.length; i += SPECIES.length()) { 1814 short tmp = -1; 1815 for (int j = 0; j < SPECIES.length(); j++) { 1816 tmp &= a[i + j]; 1817 } 1818 res &= tmp; 1819 } 1820 1821 return res; 3226 boolean[] mask = fm.apply(SPECIES.length()); 3227 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3228 3229 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3230 for (int i = 0; i < a.length; i += SPECIES.length()) { 3231 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3232 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3233 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 3234 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 3235 } 3236 } 3237 3238 assertArraysEquals(a, b, c, r, mask, Short64VectorTests::BITWISE_BLEND); 3239 } 3240 3241 3242 static short NEG(short a) { 3243 return (short)(-((short)a)); 3244 } 3245 3246 @Test(dataProvider = "shortUnaryOpProvider") 3247 static void NEGShort64VectorTests(IntFunction<short[]> fa) { 3248 short[] a = fa.apply(SPECIES.length()); 3249 short[] r = fr.apply(SPECIES.length()); 3250 3251 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3252 for (int i = 0; i < a.length; i += SPECIES.length()) { 3253 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3254 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3255 } 3256 } 3257 3258 assertArraysEquals(a, r, Short64VectorTests::NEG); 3259 } 3260 3261 @Test(dataProvider = "shortUnaryOpMaskProvider") 3262 static void NEGMaskedShort64VectorTests(IntFunction<short[]> fa, 3263 IntFunction<boolean[]> fm) { 3264 short[] a = fa.apply(SPECIES.length()); 3265 short[] r = fr.apply(SPECIES.length()); 3266 boolean[] mask = fm.apply(SPECIES.length()); 3267 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3268 3269 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3270 for (int i = 0; i < a.length; i += SPECIES.length()) { 3271 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3272 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3273 } 3274 } 3275 3276 assertArraysEquals(a, r, mask, Short64VectorTests::NEG); 3277 } 3278 3279 static short ABS(short a) { 3280 return (short)(Math.abs((short)a)); 3320 short[] a = fa.apply(SPECIES.length()); 3321 short[] r = fr.apply(SPECIES.length()); 3322 boolean[] mask = fm.apply(SPECIES.length()); 3323 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3324 3325 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3326 for (int i = 0; i < a.length; i += SPECIES.length()) { 3327 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3328 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3329 } 3330 } 3331 3332 assertArraysEquals(a, r, mask, Short64VectorTests::ABS); 3333 } 3334 3335 3336 static short NOT(short a) { 3337 return (short)(~((short)a)); 3338 } 3339 3340 3341 3342 @Test(dataProvider = "shortUnaryOpProvider") 3343 static void NOTShort64VectorTests(IntFunction<short[]> fa) { 3344 short[] a = fa.apply(SPECIES.length()); 3345 short[] r = fr.apply(SPECIES.length()); 3346 3347 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3348 for (int i = 0; i < a.length; i += SPECIES.length()) { 3349 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3350 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3351 } 3352 } 3353 3354 assertArraysEquals(a, r, Short64VectorTests::NOT); 3355 } 3356 3357 3358 3359 @Test(dataProvider = "shortUnaryOpMaskProvider") 3360 static void NOTMaskedShort64VectorTests(IntFunction<short[]> fa, 3361 IntFunction<boolean[]> fm) { 3362 short[] a = fa.apply(SPECIES.length()); 3363 short[] r = fr.apply(SPECIES.length()); 3364 boolean[] mask = fm.apply(SPECIES.length()); 3365 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3366 3367 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3368 for (int i = 0; i < a.length; i += SPECIES.length()) { 3369 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3370 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3371 } 3372 } 3373 3374 assertArraysEquals(a, r, mask, Short64VectorTests::NOT); | 224 225 interface FBinMaskOp { 226 short apply(short a, short b, boolean m); 227 228 static FBinMaskOp lift(FBinOp f) { 229 return (a, b, m) -> m ? f.apply(a, b) : a; 230 } 231 } 232 233 static void assertArraysEquals(short[] a, short[] b, short[] r, FBinOp f) { 234 int i = 0; 235 try { 236 for (; i < a.length; i++) { 237 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 238 } 239 } catch (AssertionError e) { 240 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 241 } 242 } 243 244 static void assertBroadcastArraysEquals(short[] a, short[] b, short[] r, FBinOp f) { 245 int i = 0; 246 try { 247 for (; i < a.length; i++) { 248 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 249 } 250 } catch (AssertionError e) { 251 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 252 } 253 } 254 255 static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 256 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 257 } 258 259 static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 260 int i = 0; 261 try { 262 for (; i < a.length; i++) { 263 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 264 } 265 } catch (AssertionError err) { 266 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 267 } 268 } 269 270 static void assertBroadcastArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 271 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 272 } 273 274 static void assertBroadcastArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 275 int i = 0; 276 try { 277 for (; i < a.length; i++) { 278 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 279 } 280 } catch (AssertionError err) { 281 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + mask[i % SPECIES.length()]); 282 } 283 } 284 285 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, FBinOp f) { 286 int i = 0; 287 int j = 0; 288 try { 289 for (; j < a.length; j += SPECIES.length()) { 290 for (i = 0; i < SPECIES.length(); i++) { 291 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 292 } 293 } 294 } catch (AssertionError e) { 295 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 296 } 297 } 298 299 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 300 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 301 } 302 303 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 304 int i = 0; 1378 static short OR(short a, short b) { 1379 return (short)(a | b); 1380 } 1381 1382 @Test(dataProvider = "shortBinaryOpProvider") 1383 static void ORShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1384 short[] a = fa.apply(SPECIES.length()); 1385 short[] b = fb.apply(SPECIES.length()); 1386 short[] r = fr.apply(SPECIES.length()); 1387 1388 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1389 for (int i = 0; i < a.length; i += SPECIES.length()) { 1390 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1391 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1392 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1393 } 1394 } 1395 1396 assertArraysEquals(a, b, r, Short64VectorTests::OR); 1397 } 1398 static short or(short a, short b) { 1399 return (short)(a | b); 1400 } 1401 1402 @Test(dataProvider = "shortBinaryOpProvider") 1403 static void orShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1404 short[] a = fa.apply(SPECIES.length()); 1405 short[] b = fb.apply(SPECIES.length()); 1406 short[] r = fr.apply(SPECIES.length()); 1407 1408 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1409 for (int i = 0; i < a.length; i += SPECIES.length()) { 1410 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1411 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1412 av.or(bv).intoArray(r, i); 1413 } 1414 } 1415 1416 assertArraysEquals(a, b, r, Short64VectorTests::or); 1417 } 1418 1419 1420 1421 @Test(dataProvider = "shortBinaryOpMaskProvider") 1422 static void ORShort64VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1423 IntFunction<boolean[]> fm) { 1424 short[] a = fa.apply(SPECIES.length()); 1425 short[] b = fb.apply(SPECIES.length()); 1426 short[] r = fr.apply(SPECIES.length()); 1427 boolean[] mask = fm.apply(SPECIES.length()); 1428 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1429 1430 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1431 for (int i = 0; i < a.length; i += SPECIES.length()) { 1432 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1433 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1434 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1435 } 1436 } 1437 1466 static void XORShort64VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1467 IntFunction<boolean[]> fm) { 1468 short[] a = fa.apply(SPECIES.length()); 1469 short[] b = fb.apply(SPECIES.length()); 1470 short[] r = fr.apply(SPECIES.length()); 1471 boolean[] mask = fm.apply(SPECIES.length()); 1472 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1473 1474 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1475 for (int i = 0; i < a.length; i += SPECIES.length()) { 1476 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1477 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1478 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1479 } 1480 } 1481 1482 assertArraysEquals(a, b, r, mask, Short64VectorTests::XOR); 1483 } 1484 1485 1486 @Test(dataProvider = "shortBinaryOpProvider") 1487 static void addShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1488 short[] a = fa.apply(SPECIES.length()); 1489 short[] b = fb.apply(SPECIES.length()); 1490 short[] r = fr.apply(SPECIES.length()); 1491 1492 for (int i = 0; i < a.length; i += SPECIES.length()) { 1493 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1494 av.add(b[i]).intoArray(r, i); 1495 } 1496 1497 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::add); 1498 } 1499 1500 @Test(dataProvider = "shortBinaryOpMaskProvider") 1501 static void addShort64VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1502 IntFunction<boolean[]> fm) { 1503 short[] a = fa.apply(SPECIES.length()); 1504 short[] b = fb.apply(SPECIES.length()); 1505 short[] r = fr.apply(SPECIES.length()); 1506 boolean[] mask = fm.apply(SPECIES.length()); 1507 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1508 1509 for (int i = 0; i < a.length; i += SPECIES.length()) { 1510 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1511 av.add(b[i], vmask).intoArray(r, i); 1512 } 1513 1514 assertBroadcastArraysEquals(a, b, r, mask, Short64VectorTests::add); 1515 } 1516 1517 @Test(dataProvider = "shortBinaryOpProvider") 1518 static void subShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1519 short[] a = fa.apply(SPECIES.length()); 1520 short[] b = fb.apply(SPECIES.length()); 1521 short[] r = fr.apply(SPECIES.length()); 1522 1523 for (int i = 0; i < a.length; i += SPECIES.length()) { 1524 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1525 av.sub(b[i]).intoArray(r, i); 1526 } 1527 1528 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::sub); 1529 } 1530 1531 @Test(dataProvider = "shortBinaryOpMaskProvider") 1532 static void subShort64VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1533 IntFunction<boolean[]> fm) { 1534 short[] a = fa.apply(SPECIES.length()); 1535 short[] b = fb.apply(SPECIES.length()); 1536 short[] r = fr.apply(SPECIES.length()); 1537 boolean[] mask = fm.apply(SPECIES.length()); 1538 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1539 1540 for (int i = 0; i < a.length; i += SPECIES.length()) { 1541 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1542 av.sub(b[i], vmask).intoArray(r, i); 1543 } 1544 1545 assertBroadcastArraysEquals(a, b, r, mask, Short64VectorTests::sub); 1546 } 1547 1548 @Test(dataProvider = "shortBinaryOpProvider") 1549 static void mulShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1550 short[] a = fa.apply(SPECIES.length()); 1551 short[] b = fb.apply(SPECIES.length()); 1552 short[] r = fr.apply(SPECIES.length()); 1553 1554 for (int i = 0; i < a.length; i += SPECIES.length()) { 1555 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1556 av.mul(b[i]).intoArray(r, i); 1557 } 1558 1559 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::mul); 1560 } 1561 1562 @Test(dataProvider = "shortBinaryOpMaskProvider") 1563 static void mulShort64VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1564 IntFunction<boolean[]> fm) { 1565 short[] a = fa.apply(SPECIES.length()); 1566 short[] b = fb.apply(SPECIES.length()); 1567 short[] r = fr.apply(SPECIES.length()); 1568 boolean[] mask = fm.apply(SPECIES.length()); 1569 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1570 1571 for (int i = 0; i < a.length; i += SPECIES.length()) { 1572 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1573 av.mul(b[i], vmask).intoArray(r, i); 1574 } 1575 1576 assertBroadcastArraysEquals(a, b, r, mask, Short64VectorTests::mul); 1577 } 1578 1579 1580 1581 1582 @Test(dataProvider = "shortBinaryOpProvider") 1583 static void divShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1584 short[] a = fa.apply(SPECIES.length()); 1585 short[] b = fb.apply(SPECIES.length()); 1586 short[] r = fr.apply(SPECIES.length()); 1587 1588 replaceZero(b, (short) 1); 1589 1590 for (int i = 0; i < a.length; i += SPECIES.length()) { 1591 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1592 av.div(b[i]).intoArray(r, i); 1593 } 1594 1595 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::div); 1596 } 1597 1598 1599 1600 @Test(dataProvider = "shortBinaryOpMaskProvider") 1601 static void divShort64VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1602 IntFunction<boolean[]> fm) { 1603 short[] a = fa.apply(SPECIES.length()); 1604 short[] b = fb.apply(SPECIES.length()); 1605 short[] r = fr.apply(SPECIES.length()); 1606 boolean[] mask = fm.apply(SPECIES.length()); 1607 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1608 1609 replaceZero(b, (short) 1); 1610 1611 for (int i = 0; i < a.length; i += SPECIES.length()) { 1612 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1613 av.div(b[i], vmask).intoArray(r, i); 1614 } 1615 1616 assertBroadcastArraysEquals(a, b, r, mask, Short64VectorTests::div); 1617 } 1618 1619 1620 1621 @Test(dataProvider = "shortBinaryOpProvider") 1622 static void ORShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1623 short[] a = fa.apply(SPECIES.length()); 1624 short[] b = fb.apply(SPECIES.length()); 1625 short[] r = fr.apply(SPECIES.length()); 1626 1627 for (int i = 0; i < a.length; i += SPECIES.length()) { 1628 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1629 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); 1630 } 1631 1632 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::OR); 1633 } 1634 1635 @Test(dataProvider = "shortBinaryOpProvider") 1636 static void orShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1637 short[] a = fa.apply(SPECIES.length()); 1638 short[] b = fb.apply(SPECIES.length()); 1639 short[] r = fr.apply(SPECIES.length()); 1640 1641 for (int i = 0; i < a.length; i += SPECIES.length()) { 1642 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1643 av.or(b[i]).intoArray(r, i); 1644 } 1645 1646 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::or); 1647 } 1648 1649 1650 1651 @Test(dataProvider = "shortBinaryOpMaskProvider") 1652 static void ORShort64VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 1653 IntFunction<boolean[]> fm) { 1654 short[] a = fa.apply(SPECIES.length()); 1655 short[] b = fb.apply(SPECIES.length()); 1656 short[] r = fr.apply(SPECIES.length()); 1657 boolean[] mask = fm.apply(SPECIES.length()); 1658 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1659 1660 for (int i = 0; i < a.length; i += SPECIES.length()) { 1661 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1662 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); 1663 } 1664 1665 assertBroadcastArraysEquals(a, b, r, mask, Short64VectorTests::OR); 1666 } 1667 1668 1669 1670 1671 1672 1673 static short LSHL(short a, short b) { 1674 return (short)((a << (b & 0xF))); 1675 } 1676 1677 @Test(dataProvider = "shortBinaryOpProvider") 1678 static void LSHLShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1679 short[] a = fa.apply(SPECIES.length()); 1680 short[] b = fb.apply(SPECIES.length()); 1681 short[] r = fr.apply(SPECIES.length()); 1682 1683 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1684 for (int i = 0; i < a.length; i += SPECIES.length()) { 1685 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1686 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1687 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1688 } 2011 return (short)(Math.max(a, b)); 2012 } 2013 2014 @Test(dataProvider = "shortBinaryOpProvider") 2015 static void maxShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2016 short[] a = fa.apply(SPECIES.length()); 2017 short[] b = fb.apply(SPECIES.length()); 2018 short[] r = fr.apply(SPECIES.length()); 2019 2020 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2021 for (int i = 0; i < a.length; i += SPECIES.length()) { 2022 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2023 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2024 av.max(bv).intoArray(r, i); 2025 } 2026 } 2027 2028 assertArraysEquals(a, b, r, Short64VectorTests::max); 2029 } 2030 2031 @Test(dataProvider = "shortBinaryOpProvider") 2032 static void MINShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2033 short[] a = fa.apply(SPECIES.length()); 2034 short[] b = fb.apply(SPECIES.length()); 2035 short[] r = fr.apply(SPECIES.length()); 2036 2037 for (int i = 0; i < a.length; i += SPECIES.length()) { 2038 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2039 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2040 } 2041 2042 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::MIN); 2043 } 2044 2045 @Test(dataProvider = "shortBinaryOpProvider") 2046 static void minShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2047 short[] a = fa.apply(SPECIES.length()); 2048 short[] b = fb.apply(SPECIES.length()); 2049 short[] r = fr.apply(SPECIES.length()); 2050 2051 for (int i = 0; i < a.length; i += SPECIES.length()) { 2052 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2053 av.min(b[i]).intoArray(r, i); 2054 } 2055 2056 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::min); 2057 } 2058 2059 @Test(dataProvider = "shortBinaryOpProvider") 2060 static void MAXShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2061 short[] a = fa.apply(SPECIES.length()); 2062 short[] b = fb.apply(SPECIES.length()); 2063 short[] r = fr.apply(SPECIES.length()); 2064 2065 for (int i = 0; i < a.length; i += SPECIES.length()) { 2066 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2067 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2068 } 2069 2070 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::MAX); 2071 } 2072 2073 @Test(dataProvider = "shortBinaryOpProvider") 2074 static void maxShort64VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2075 short[] a = fa.apply(SPECIES.length()); 2076 short[] b = fb.apply(SPECIES.length()); 2077 short[] r = fr.apply(SPECIES.length()); 2078 2079 for (int i = 0; i < a.length; i += SPECIES.length()) { 2080 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2081 av.max(b[i]).intoArray(r, i); 2082 } 2083 2084 assertBroadcastArraysEquals(a, b, r, Short64VectorTests::max); 2085 } 2086 2087 static short AND(short[] a, int idx) { 2088 short res = -1; 2089 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2090 res &= a[i]; 2091 } 2092 2093 return res; 2094 } 2095 2096 static short AND(short[] a) { 2097 short res = -1; 2098 for (int i = 0; i < a.length; i += SPECIES.length()) { 2099 short tmp = -1; 2100 for (int j = 0; j < SPECIES.length(); j++) { 2101 tmp &= a[i + j]; 2102 } 2103 res &= tmp; 2104 } 2105 2106 return res; 3511 boolean[] mask = fm.apply(SPECIES.length()); 3512 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3513 3514 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3515 for (int i = 0; i < a.length; i += SPECIES.length()) { 3516 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3517 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3518 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 3519 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 3520 } 3521 } 3522 3523 assertArraysEquals(a, b, c, r, mask, Short64VectorTests::BITWISE_BLEND); 3524 } 3525 3526 3527 static short NEG(short a) { 3528 return (short)(-((short)a)); 3529 } 3530 3531 static short neg(short a) { 3532 return (short)(-((short)a)); 3533 } 3534 3535 @Test(dataProvider = "shortUnaryOpProvider") 3536 static void NEGShort64VectorTests(IntFunction<short[]> fa) { 3537 short[] a = fa.apply(SPECIES.length()); 3538 short[] r = fr.apply(SPECIES.length()); 3539 3540 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3541 for (int i = 0; i < a.length; i += SPECIES.length()) { 3542 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3543 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3544 } 3545 } 3546 3547 assertArraysEquals(a, r, Short64VectorTests::NEG); 3548 } 3549 3550 @Test(dataProvider = "shortUnaryOpProvider") 3551 static void negShort64VectorTests(IntFunction<short[]> fa) { 3552 short[] a = fa.apply(SPECIES.length()); 3553 short[] r = fr.apply(SPECIES.length()); 3554 3555 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3556 for (int i = 0; i < a.length; i += SPECIES.length()) { 3557 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3558 av.neg().intoArray(r, i); 3559 } 3560 } 3561 3562 assertArraysEquals(a, r, Short64VectorTests::neg); 3563 } 3564 3565 @Test(dataProvider = "shortUnaryOpMaskProvider") 3566 static void NEGMaskedShort64VectorTests(IntFunction<short[]> fa, 3567 IntFunction<boolean[]> fm) { 3568 short[] a = fa.apply(SPECIES.length()); 3569 short[] r = fr.apply(SPECIES.length()); 3570 boolean[] mask = fm.apply(SPECIES.length()); 3571 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3572 3573 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3574 for (int i = 0; i < a.length; i += SPECIES.length()) { 3575 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3576 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3577 } 3578 } 3579 3580 assertArraysEquals(a, r, mask, Short64VectorTests::NEG); 3581 } 3582 3583 static short ABS(short a) { 3584 return (short)(Math.abs((short)a)); 3624 short[] a = fa.apply(SPECIES.length()); 3625 short[] r = fr.apply(SPECIES.length()); 3626 boolean[] mask = fm.apply(SPECIES.length()); 3627 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3628 3629 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3630 for (int i = 0; i < a.length; i += SPECIES.length()) { 3631 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3632 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3633 } 3634 } 3635 3636 assertArraysEquals(a, r, mask, Short64VectorTests::ABS); 3637 } 3638 3639 3640 static short NOT(short a) { 3641 return (short)(~((short)a)); 3642 } 3643 3644 static short not(short a) { 3645 return (short)(~((short)a)); 3646 } 3647 3648 3649 3650 @Test(dataProvider = "shortUnaryOpProvider") 3651 static void NOTShort64VectorTests(IntFunction<short[]> fa) { 3652 short[] a = fa.apply(SPECIES.length()); 3653 short[] r = fr.apply(SPECIES.length()); 3654 3655 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3656 for (int i = 0; i < a.length; i += SPECIES.length()) { 3657 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3658 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3659 } 3660 } 3661 3662 assertArraysEquals(a, r, Short64VectorTests::NOT); 3663 } 3664 3665 @Test(dataProvider = "shortUnaryOpProvider") 3666 static void notShort64VectorTests(IntFunction<short[]> fa) { 3667 short[] a = fa.apply(SPECIES.length()); 3668 short[] r = fr.apply(SPECIES.length()); 3669 3670 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3671 for (int i = 0; i < a.length; i += SPECIES.length()) { 3672 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3673 av.not().intoArray(r, i); 3674 } 3675 } 3676 3677 assertArraysEquals(a, r, Short64VectorTests::not); 3678 } 3679 3680 3681 3682 @Test(dataProvider = "shortUnaryOpMaskProvider") 3683 static void NOTMaskedShort64VectorTests(IntFunction<short[]> fa, 3684 IntFunction<boolean[]> fm) { 3685 short[] a = fa.apply(SPECIES.length()); 3686 short[] r = fr.apply(SPECIES.length()); 3687 boolean[] mask = fm.apply(SPECIES.length()); 3688 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3689 3690 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3691 for (int i = 0; i < a.length; i += SPECIES.length()) { 3692 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3693 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3694 } 3695 } 3696 3697 assertArraysEquals(a, r, mask, Short64VectorTests::NOT); |