224 225 interface FBinMaskOp { 226 long apply(long a, long 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(long[] a, long[] b, long[] 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(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 245 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 246 } 247 248 static void assertArraysEquals(long[] a, long[] b, long[] 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(long[] a, long[] b, long[] 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(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 274 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 275 } 276 277 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 278 int i = 0; 1357 static long OR(long a, long b) { 1358 return (long)(a | b); 1359 } 1360 1361 @Test(dataProvider = "longBinaryOpProvider") 1362 static void ORLong256VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1363 long[] a = fa.apply(SPECIES.length()); 1364 long[] b = fb.apply(SPECIES.length()); 1365 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1370 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1371 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1372 } 1373 } 1374 1375 assertArraysEquals(a, b, r, Long256VectorTests::OR); 1376 } 1377 1378 1379 1380 @Test(dataProvider = "longBinaryOpMaskProvider") 1381 static void ORLong256VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1382 IntFunction<boolean[]> fm) { 1383 long[] a = fa.apply(SPECIES.length()); 1384 long[] b = fb.apply(SPECIES.length()); 1385 long[] r = fr.apply(SPECIES.length()); 1386 boolean[] mask = fm.apply(SPECIES.length()); 1387 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1392 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1393 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1394 } 1395 } 1396 1425 static void XORLong256VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1426 IntFunction<boolean[]> fm) { 1427 long[] a = fa.apply(SPECIES.length()); 1428 long[] b = fb.apply(SPECIES.length()); 1429 long[] r = fr.apply(SPECIES.length()); 1430 boolean[] mask = fm.apply(SPECIES.length()); 1431 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1436 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1437 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1438 } 1439 } 1440 1441 assertArraysEquals(a, b, r, mask, Long256VectorTests::XOR); 1442 } 1443 1444 1445 static long LSHL(long a, long b) { 1446 return (long)((a << b)); 1447 } 1448 1449 @Test(dataProvider = "longBinaryOpProvider") 1450 static void LSHLLong256VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1451 long[] a = fa.apply(SPECIES.length()); 1452 long[] b = fb.apply(SPECIES.length()); 1453 long[] r = fr.apply(SPECIES.length()); 1454 1455 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1456 for (int i = 0; i < a.length; i += SPECIES.length()) { 1457 LongVector av = LongVector.fromArray(SPECIES, a, i); 1458 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1459 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1460 } 1461 } 1462 1463 assertArraysEquals(a, b, r, Long256VectorTests::LSHL); 1464 } 1787 return (long)(Math.max(a, b)); 1788 } 1789 1790 @Test(dataProvider = "longBinaryOpProvider") 1791 static void maxLong256VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1792 long[] a = fa.apply(SPECIES.length()); 1793 long[] b = fb.apply(SPECIES.length()); 1794 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1799 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1800 av.max(bv).intoArray(r, i); 1801 } 1802 } 1803 1804 assertArraysEquals(a, b, r, Long256VectorTests::max); 1805 } 1806 1807 static long AND(long[] a, int idx) { 1808 long 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 long AND(long[] a) { 1817 long res = -1; 1818 for (int i = 0; i < a.length; i += SPECIES.length()) { 1819 long 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<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3237 LongVector bv = LongVector.fromArray(SPECIES, b, i); 3238 LongVector cv = LongVector.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, Long256VectorTests::BITWISE_BLEND); 3244 } 3245 3246 3247 static long NEG(long a) { 3248 return (long)(-((long)a)); 3249 } 3250 3251 @Test(dataProvider = "longUnaryOpProvider") 3252 static void NEGLong256VectorTests(IntFunction<long[]> fa) { 3253 long[] a = fa.apply(SPECIES.length()); 3254 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3259 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3260 } 3261 } 3262 3263 assertArraysEquals(a, r, Long256VectorTests::NEG); 3264 } 3265 3266 @Test(dataProvider = "longUnaryOpMaskProvider") 3267 static void NEGMaskedLong256VectorTests(IntFunction<long[]> fa, 3268 IntFunction<boolean[]> fm) { 3269 long[] a = fa.apply(SPECIES.length()); 3270 long[] r = fr.apply(SPECIES.length()); 3271 boolean[] mask = fm.apply(SPECIES.length()); 3272 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3277 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3278 } 3279 } 3280 3281 assertArraysEquals(a, r, mask, Long256VectorTests::NEG); 3282 } 3283 3284 static long ABS(long a) { 3285 return (long)(Math.abs((long)a)); 3325 long[] a = fa.apply(SPECIES.length()); 3326 long[] r = fr.apply(SPECIES.length()); 3327 boolean[] mask = fm.apply(SPECIES.length()); 3328 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3333 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3334 } 3335 } 3336 3337 assertArraysEquals(a, r, mask, Long256VectorTests::ABS); 3338 } 3339 3340 3341 static long NOT(long a) { 3342 return (long)(~((long)a)); 3343 } 3344 3345 3346 3347 @Test(dataProvider = "longUnaryOpProvider") 3348 static void NOTLong256VectorTests(IntFunction<long[]> fa) { 3349 long[] a = fa.apply(SPECIES.length()); 3350 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3355 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3356 } 3357 } 3358 3359 assertArraysEquals(a, r, Long256VectorTests::NOT); 3360 } 3361 3362 3363 3364 @Test(dataProvider = "longUnaryOpMaskProvider") 3365 static void NOTMaskedLong256VectorTests(IntFunction<long[]> fa, 3366 IntFunction<boolean[]> fm) { 3367 long[] a = fa.apply(SPECIES.length()); 3368 long[] r = fr.apply(SPECIES.length()); 3369 boolean[] mask = fm.apply(SPECIES.length()); 3370 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3375 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3376 } 3377 } 3378 3379 assertArraysEquals(a, r, mask, Long256VectorTests::NOT); | 224 225 interface FBinMaskOp { 226 long apply(long a, long 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(long[] a, long[] b, long[] 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(long[] a, long[] b, long[] 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()]), 252 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 253 } 254 } 255 256 static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 257 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 258 } 259 260 static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 261 int i = 0; 262 try { 263 for (; i < a.length; i++) { 264 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 265 } 266 } catch (AssertionError err) { 267 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()]); 268 } 269 } 270 271 static void assertBroadcastArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 272 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 273 } 274 275 static void assertBroadcastArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 276 int i = 0; 277 try { 278 for (; i < a.length; i++) { 279 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 280 } 281 } catch (AssertionError err) { 282 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 283 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 284 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 285 mask[i % SPECIES.length()]); 286 } 287 } 288 289 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, FBinOp f) { 290 int i = 0; 291 int j = 0; 292 try { 293 for (; j < a.length; j += SPECIES.length()) { 294 for (i = 0; i < SPECIES.length(); i++) { 295 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 296 } 297 } 298 } catch (AssertionError e) { 299 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 300 } 301 } 302 303 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 304 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 305 } 306 307 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 308 int i = 0; 1387 static long OR(long a, long b) { 1388 return (long)(a | b); 1389 } 1390 1391 @Test(dataProvider = "longBinaryOpProvider") 1392 static void ORLong256VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1393 long[] a = fa.apply(SPECIES.length()); 1394 long[] b = fb.apply(SPECIES.length()); 1395 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1400 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1401 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1402 } 1403 } 1404 1405 assertArraysEquals(a, b, r, Long256VectorTests::OR); 1406 } 1407 static long or(long a, long b) { 1408 return (long)(a | b); 1409 } 1410 1411 @Test(dataProvider = "longBinaryOpProvider") 1412 static void orLong256VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1413 long[] a = fa.apply(SPECIES.length()); 1414 long[] b = fb.apply(SPECIES.length()); 1415 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1420 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1421 av.or(bv).intoArray(r, i); 1422 } 1423 } 1424 1425 assertArraysEquals(a, b, r, Long256VectorTests::or); 1426 } 1427 1428 1429 1430 @Test(dataProvider = "longBinaryOpMaskProvider") 1431 static void ORLong256VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1432 IntFunction<boolean[]> fm) { 1433 long[] a = fa.apply(SPECIES.length()); 1434 long[] b = fb.apply(SPECIES.length()); 1435 long[] r = fr.apply(SPECIES.length()); 1436 boolean[] mask = fm.apply(SPECIES.length()); 1437 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1442 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1443 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1444 } 1445 } 1446 1475 static void XORLong256VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1476 IntFunction<boolean[]> fm) { 1477 long[] a = fa.apply(SPECIES.length()); 1478 long[] b = fb.apply(SPECIES.length()); 1479 long[] r = fr.apply(SPECIES.length()); 1480 boolean[] mask = fm.apply(SPECIES.length()); 1481 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1486 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1487 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1488 } 1489 } 1490 1491 assertArraysEquals(a, b, r, mask, Long256VectorTests::XOR); 1492 } 1493 1494 1495 @Test(dataProvider = "longBinaryOpProvider") 1496 static void addLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1497 long[] a = fa.apply(SPECIES.length()); 1498 long[] b = fb.apply(SPECIES.length()); 1499 long[] r = fr.apply(SPECIES.length()); 1500 1501 for (int i = 0; i < a.length; i += SPECIES.length()) { 1502 LongVector av = LongVector.fromArray(SPECIES, a, i); 1503 av.add(b[i]).intoArray(r, i); 1504 } 1505 1506 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::add); 1507 } 1508 1509 @Test(dataProvider = "longBinaryOpMaskProvider") 1510 static void addLong256VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1511 IntFunction<boolean[]> fm) { 1512 long[] a = fa.apply(SPECIES.length()); 1513 long[] b = fb.apply(SPECIES.length()); 1514 long[] r = fr.apply(SPECIES.length()); 1515 boolean[] mask = fm.apply(SPECIES.length()); 1516 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1517 1518 for (int i = 0; i < a.length; i += SPECIES.length()) { 1519 LongVector av = LongVector.fromArray(SPECIES, a, i); 1520 av.add(b[i], vmask).intoArray(r, i); 1521 } 1522 1523 assertBroadcastArraysEquals(a, b, r, mask, Long256VectorTests::add); 1524 } 1525 1526 @Test(dataProvider = "longBinaryOpProvider") 1527 static void subLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1528 long[] a = fa.apply(SPECIES.length()); 1529 long[] b = fb.apply(SPECIES.length()); 1530 long[] r = fr.apply(SPECIES.length()); 1531 1532 for (int i = 0; i < a.length; i += SPECIES.length()) { 1533 LongVector av = LongVector.fromArray(SPECIES, a, i); 1534 av.sub(b[i]).intoArray(r, i); 1535 } 1536 1537 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::sub); 1538 } 1539 1540 @Test(dataProvider = "longBinaryOpMaskProvider") 1541 static void subLong256VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1542 IntFunction<boolean[]> fm) { 1543 long[] a = fa.apply(SPECIES.length()); 1544 long[] b = fb.apply(SPECIES.length()); 1545 long[] r = fr.apply(SPECIES.length()); 1546 boolean[] mask = fm.apply(SPECIES.length()); 1547 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1548 1549 for (int i = 0; i < a.length; i += SPECIES.length()) { 1550 LongVector av = LongVector.fromArray(SPECIES, a, i); 1551 av.sub(b[i], vmask).intoArray(r, i); 1552 } 1553 1554 assertBroadcastArraysEquals(a, b, r, mask, Long256VectorTests::sub); 1555 } 1556 1557 @Test(dataProvider = "longBinaryOpProvider") 1558 static void mulLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1559 long[] a = fa.apply(SPECIES.length()); 1560 long[] b = fb.apply(SPECIES.length()); 1561 long[] r = fr.apply(SPECIES.length()); 1562 1563 for (int i = 0; i < a.length; i += SPECIES.length()) { 1564 LongVector av = LongVector.fromArray(SPECIES, a, i); 1565 av.mul(b[i]).intoArray(r, i); 1566 } 1567 1568 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::mul); 1569 } 1570 1571 @Test(dataProvider = "longBinaryOpMaskProvider") 1572 static void mulLong256VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1573 IntFunction<boolean[]> fm) { 1574 long[] a = fa.apply(SPECIES.length()); 1575 long[] b = fb.apply(SPECIES.length()); 1576 long[] r = fr.apply(SPECIES.length()); 1577 boolean[] mask = fm.apply(SPECIES.length()); 1578 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1579 1580 for (int i = 0; i < a.length; i += SPECIES.length()) { 1581 LongVector av = LongVector.fromArray(SPECIES, a, i); 1582 av.mul(b[i], vmask).intoArray(r, i); 1583 } 1584 1585 assertBroadcastArraysEquals(a, b, r, mask, Long256VectorTests::mul); 1586 } 1587 1588 1589 1590 1591 @Test(dataProvider = "longBinaryOpProvider") 1592 static void divLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1593 long[] a = fa.apply(SPECIES.length()); 1594 long[] b = fb.apply(SPECIES.length()); 1595 long[] r = fr.apply(SPECIES.length()); 1596 1597 replaceZero(b, (long) 1); 1598 1599 for (int i = 0; i < a.length; i += SPECIES.length()) { 1600 LongVector av = LongVector.fromArray(SPECIES, a, i); 1601 av.div(b[i]).intoArray(r, i); 1602 } 1603 1604 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::div); 1605 } 1606 1607 1608 1609 @Test(dataProvider = "longBinaryOpMaskProvider") 1610 static void divLong256VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1611 IntFunction<boolean[]> fm) { 1612 long[] a = fa.apply(SPECIES.length()); 1613 long[] b = fb.apply(SPECIES.length()); 1614 long[] r = fr.apply(SPECIES.length()); 1615 boolean[] mask = fm.apply(SPECIES.length()); 1616 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1617 1618 replaceZero(b, (long) 1); 1619 1620 for (int i = 0; i < a.length; i += SPECIES.length()) { 1621 LongVector av = LongVector.fromArray(SPECIES, a, i); 1622 av.div(b[i], vmask).intoArray(r, i); 1623 } 1624 1625 assertBroadcastArraysEquals(a, b, r, mask, Long256VectorTests::div); 1626 } 1627 1628 1629 1630 @Test(dataProvider = "longBinaryOpProvider") 1631 static void ORLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1632 long[] a = fa.apply(SPECIES.length()); 1633 long[] b = fb.apply(SPECIES.length()); 1634 long[] r = fr.apply(SPECIES.length()); 1635 1636 for (int i = 0; i < a.length; i += SPECIES.length()) { 1637 LongVector av = LongVector.fromArray(SPECIES, a, i); 1638 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); 1639 } 1640 1641 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::OR); 1642 } 1643 1644 @Test(dataProvider = "longBinaryOpProvider") 1645 static void orLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1646 long[] a = fa.apply(SPECIES.length()); 1647 long[] b = fb.apply(SPECIES.length()); 1648 long[] r = fr.apply(SPECIES.length()); 1649 1650 for (int i = 0; i < a.length; i += SPECIES.length()) { 1651 LongVector av = LongVector.fromArray(SPECIES, a, i); 1652 av.or(b[i]).intoArray(r, i); 1653 } 1654 1655 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::or); 1656 } 1657 1658 1659 1660 @Test(dataProvider = "longBinaryOpMaskProvider") 1661 static void ORLong256VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1662 IntFunction<boolean[]> fm) { 1663 long[] a = fa.apply(SPECIES.length()); 1664 long[] b = fb.apply(SPECIES.length()); 1665 long[] r = fr.apply(SPECIES.length()); 1666 boolean[] mask = fm.apply(SPECIES.length()); 1667 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1668 1669 for (int i = 0; i < a.length; i += SPECIES.length()) { 1670 LongVector av = LongVector.fromArray(SPECIES, a, i); 1671 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); 1672 } 1673 1674 assertBroadcastArraysEquals(a, b, r, mask, Long256VectorTests::OR); 1675 } 1676 1677 1678 static long LSHL(long a, long b) { 1679 return (long)((a << b)); 1680 } 1681 1682 @Test(dataProvider = "longBinaryOpProvider") 1683 static void LSHLLong256VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1684 long[] a = fa.apply(SPECIES.length()); 1685 long[] b = fb.apply(SPECIES.length()); 1686 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 1691 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1692 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1693 } 1694 } 1695 1696 assertArraysEquals(a, b, r, Long256VectorTests::LSHL); 1697 } 2020 return (long)(Math.max(a, b)); 2021 } 2022 2023 @Test(dataProvider = "longBinaryOpProvider") 2024 static void maxLong256VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2025 long[] a = fa.apply(SPECIES.length()); 2026 long[] b = fb.apply(SPECIES.length()); 2027 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 2032 LongVector bv = LongVector.fromArray(SPECIES, b, i); 2033 av.max(bv).intoArray(r, i); 2034 } 2035 } 2036 2037 assertArraysEquals(a, b, r, Long256VectorTests::max); 2038 } 2039 2040 @Test(dataProvider = "longBinaryOpProvider") 2041 static void MINLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2042 long[] a = fa.apply(SPECIES.length()); 2043 long[] b = fb.apply(SPECIES.length()); 2044 long[] r = fr.apply(SPECIES.length()); 2045 2046 for (int i = 0; i < a.length; i += SPECIES.length()) { 2047 LongVector av = LongVector.fromArray(SPECIES, a, i); 2048 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2049 } 2050 2051 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::MIN); 2052 } 2053 2054 @Test(dataProvider = "longBinaryOpProvider") 2055 static void minLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2056 long[] a = fa.apply(SPECIES.length()); 2057 long[] b = fb.apply(SPECIES.length()); 2058 long[] r = fr.apply(SPECIES.length()); 2059 2060 for (int i = 0; i < a.length; i += SPECIES.length()) { 2061 LongVector av = LongVector.fromArray(SPECIES, a, i); 2062 av.min(b[i]).intoArray(r, i); 2063 } 2064 2065 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::min); 2066 } 2067 2068 @Test(dataProvider = "longBinaryOpProvider") 2069 static void MAXLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2070 long[] a = fa.apply(SPECIES.length()); 2071 long[] b = fb.apply(SPECIES.length()); 2072 long[] r = fr.apply(SPECIES.length()); 2073 2074 for (int i = 0; i < a.length; i += SPECIES.length()) { 2075 LongVector av = LongVector.fromArray(SPECIES, a, i); 2076 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2077 } 2078 2079 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::MAX); 2080 } 2081 2082 @Test(dataProvider = "longBinaryOpProvider") 2083 static void maxLong256VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2084 long[] a = fa.apply(SPECIES.length()); 2085 long[] b = fb.apply(SPECIES.length()); 2086 long[] r = fr.apply(SPECIES.length()); 2087 2088 for (int i = 0; i < a.length; i += SPECIES.length()) { 2089 LongVector av = LongVector.fromArray(SPECIES, a, i); 2090 av.max(b[i]).intoArray(r, i); 2091 } 2092 2093 assertBroadcastArraysEquals(a, b, r, Long256VectorTests::max); 2094 } 2095 2096 static long AND(long[] a, int idx) { 2097 long 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 long AND(long[] a) { 2106 long res = -1; 2107 for (int i = 0; i < a.length; i += SPECIES.length()) { 2108 long 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<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3526 LongVector bv = LongVector.fromArray(SPECIES, b, i); 3527 LongVector cv = LongVector.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, Long256VectorTests::BITWISE_BLEND); 3533 } 3534 3535 3536 static long NEG(long a) { 3537 return (long)(-((long)a)); 3538 } 3539 3540 static long neg(long a) { 3541 return (long)(-((long)a)); 3542 } 3543 3544 @Test(dataProvider = "longUnaryOpProvider") 3545 static void NEGLong256VectorTests(IntFunction<long[]> fa) { 3546 long[] a = fa.apply(SPECIES.length()); 3547 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3552 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3553 } 3554 } 3555 3556 assertArraysEquals(a, r, Long256VectorTests::NEG); 3557 } 3558 3559 @Test(dataProvider = "longUnaryOpProvider") 3560 static void negLong256VectorTests(IntFunction<long[]> fa) { 3561 long[] a = fa.apply(SPECIES.length()); 3562 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3567 av.neg().intoArray(r, i); 3568 } 3569 } 3570 3571 assertArraysEquals(a, r, Long256VectorTests::neg); 3572 } 3573 3574 @Test(dataProvider = "longUnaryOpMaskProvider") 3575 static void NEGMaskedLong256VectorTests(IntFunction<long[]> fa, 3576 IntFunction<boolean[]> fm) { 3577 long[] a = fa.apply(SPECIES.length()); 3578 long[] r = fr.apply(SPECIES.length()); 3579 boolean[] mask = fm.apply(SPECIES.length()); 3580 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3585 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3586 } 3587 } 3588 3589 assertArraysEquals(a, r, mask, Long256VectorTests::NEG); 3590 } 3591 3592 static long ABS(long a) { 3593 return (long)(Math.abs((long)a)); 3633 long[] a = fa.apply(SPECIES.length()); 3634 long[] r = fr.apply(SPECIES.length()); 3635 boolean[] mask = fm.apply(SPECIES.length()); 3636 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3641 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3642 } 3643 } 3644 3645 assertArraysEquals(a, r, mask, Long256VectorTests::ABS); 3646 } 3647 3648 3649 static long NOT(long a) { 3650 return (long)(~((long)a)); 3651 } 3652 3653 static long not(long a) { 3654 return (long)(~((long)a)); 3655 } 3656 3657 3658 3659 @Test(dataProvider = "longUnaryOpProvider") 3660 static void NOTLong256VectorTests(IntFunction<long[]> fa) { 3661 long[] a = fa.apply(SPECIES.length()); 3662 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3667 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3668 } 3669 } 3670 3671 assertArraysEquals(a, r, Long256VectorTests::NOT); 3672 } 3673 3674 @Test(dataProvider = "longUnaryOpProvider") 3675 static void notLong256VectorTests(IntFunction<long[]> fa) { 3676 long[] a = fa.apply(SPECIES.length()); 3677 long[] 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3682 av.not().intoArray(r, i); 3683 } 3684 } 3685 3686 assertArraysEquals(a, r, Long256VectorTests::not); 3687 } 3688 3689 3690 3691 @Test(dataProvider = "longUnaryOpMaskProvider") 3692 static void NOTMaskedLong256VectorTests(IntFunction<long[]> fa, 3693 IntFunction<boolean[]> fm) { 3694 long[] a = fa.apply(SPECIES.length()); 3695 long[] r = fr.apply(SPECIES.length()); 3696 boolean[] mask = fm.apply(SPECIES.length()); 3697 VectorMask<Long> 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 LongVector av = LongVector.fromArray(SPECIES, a, i); 3702 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3703 } 3704 } 3705 3706 assertArraysEquals(a, r, mask, Long256VectorTests::NOT); |