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 ORLong64VectorTests(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, Long64VectorTests::OR); 1376 } 1377 1378 1379 1380 @Test(dataProvider = "longBinaryOpMaskProvider") 1381 static void ORLong64VectorTestsMasked(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 XORLong64VectorTestsMasked(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, Long64VectorTests::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 LSHLLong64VectorTests(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, Long64VectorTests::LSHL); 1464 } 1787 return (long)(Math.max(a, b)); 1788 } 1789 1790 @Test(dataProvider = "longBinaryOpProvider") 1791 static void maxLong64VectorTests(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, Long64VectorTests::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, Long64VectorTests::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 NEGLong64VectorTests(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, Long64VectorTests::NEG); 3264 } 3265 3266 @Test(dataProvider = "longUnaryOpMaskProvider") 3267 static void NEGMaskedLong64VectorTests(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, Long64VectorTests::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, Long64VectorTests::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 NOTLong64VectorTests(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, Long64VectorTests::NOT); 3360 } 3361 3362 3363 3364 @Test(dataProvider = "longUnaryOpMaskProvider") 3365 static void NOTMaskedLong64VectorTests(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, Long64VectorTests::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()]), "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 252 } 253 } 254 255 static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 256 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 257 } 258 259 static void assertArraysEquals(long[] a, long[] b, long[] 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(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 271 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 272 } 273 274 static void assertBroadcastArraysEquals(long[] a, long[] b, long[] 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(long[] a, long[] b, long[] 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(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 300 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 301 } 302 303 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 304 int i = 0; 1383 static long OR(long a, long b) { 1384 return (long)(a | b); 1385 } 1386 1387 @Test(dataProvider = "longBinaryOpProvider") 1388 static void ORLong64VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1389 long[] a = fa.apply(SPECIES.length()); 1390 long[] b = fb.apply(SPECIES.length()); 1391 long[] r = fr.apply(SPECIES.length()); 1392 1393 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1394 for (int i = 0; i < a.length; i += SPECIES.length()) { 1395 LongVector av = LongVector.fromArray(SPECIES, a, i); 1396 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1397 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1398 } 1399 } 1400 1401 assertArraysEquals(a, b, r, Long64VectorTests::OR); 1402 } 1403 static long or(long a, long b) { 1404 return (long)(a | b); 1405 } 1406 1407 @Test(dataProvider = "longBinaryOpProvider") 1408 static void orLong64VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1409 long[] a = fa.apply(SPECIES.length()); 1410 long[] b = fb.apply(SPECIES.length()); 1411 long[] r = fr.apply(SPECIES.length()); 1412 1413 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1414 for (int i = 0; i < a.length; i += SPECIES.length()) { 1415 LongVector av = LongVector.fromArray(SPECIES, a, i); 1416 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1417 av.or(bv).intoArray(r, i); 1418 } 1419 } 1420 1421 assertArraysEquals(a, b, r, Long64VectorTests::or); 1422 } 1423 1424 1425 1426 @Test(dataProvider = "longBinaryOpMaskProvider") 1427 static void ORLong64VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1428 IntFunction<boolean[]> fm) { 1429 long[] a = fa.apply(SPECIES.length()); 1430 long[] b = fb.apply(SPECIES.length()); 1431 long[] r = fr.apply(SPECIES.length()); 1432 boolean[] mask = fm.apply(SPECIES.length()); 1433 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1434 1435 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1436 for (int i = 0; i < a.length; i += SPECIES.length()) { 1437 LongVector av = LongVector.fromArray(SPECIES, a, i); 1438 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1439 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1440 } 1441 } 1442 1471 static void XORLong64VectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1472 IntFunction<boolean[]> fm) { 1473 long[] a = fa.apply(SPECIES.length()); 1474 long[] b = fb.apply(SPECIES.length()); 1475 long[] r = fr.apply(SPECIES.length()); 1476 boolean[] mask = fm.apply(SPECIES.length()); 1477 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1478 1479 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1480 for (int i = 0; i < a.length; i += SPECIES.length()) { 1481 LongVector av = LongVector.fromArray(SPECIES, a, i); 1482 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1483 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1484 } 1485 } 1486 1487 assertArraysEquals(a, b, r, mask, Long64VectorTests::XOR); 1488 } 1489 1490 1491 @Test(dataProvider = "longBinaryOpProvider") 1492 static void addLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1493 long[] a = fa.apply(SPECIES.length()); 1494 long[] b = fb.apply(SPECIES.length()); 1495 long[] r = fr.apply(SPECIES.length()); 1496 1497 for (int i = 0; i < a.length; i += SPECIES.length()) { 1498 LongVector av = LongVector.fromArray(SPECIES, a, i); 1499 av.add(b[i]).intoArray(r, i); 1500 } 1501 1502 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::add); 1503 } 1504 1505 @Test(dataProvider = "longBinaryOpMaskProvider") 1506 static void addLong64VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1507 IntFunction<boolean[]> fm) { 1508 long[] a = fa.apply(SPECIES.length()); 1509 long[] b = fb.apply(SPECIES.length()); 1510 long[] r = fr.apply(SPECIES.length()); 1511 boolean[] mask = fm.apply(SPECIES.length()); 1512 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1513 1514 for (int i = 0; i < a.length; i += SPECIES.length()) { 1515 LongVector av = LongVector.fromArray(SPECIES, a, i); 1516 av.add(b[i], vmask).intoArray(r, i); 1517 } 1518 1519 assertBroadcastArraysEquals(a, b, r, mask, Long64VectorTests::add); 1520 } 1521 1522 @Test(dataProvider = "longBinaryOpProvider") 1523 static void subLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1524 long[] a = fa.apply(SPECIES.length()); 1525 long[] b = fb.apply(SPECIES.length()); 1526 long[] r = fr.apply(SPECIES.length()); 1527 1528 for (int i = 0; i < a.length; i += SPECIES.length()) { 1529 LongVector av = LongVector.fromArray(SPECIES, a, i); 1530 av.sub(b[i]).intoArray(r, i); 1531 } 1532 1533 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::sub); 1534 } 1535 1536 @Test(dataProvider = "longBinaryOpMaskProvider") 1537 static void subLong64VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1538 IntFunction<boolean[]> fm) { 1539 long[] a = fa.apply(SPECIES.length()); 1540 long[] b = fb.apply(SPECIES.length()); 1541 long[] r = fr.apply(SPECIES.length()); 1542 boolean[] mask = fm.apply(SPECIES.length()); 1543 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1544 1545 for (int i = 0; i < a.length; i += SPECIES.length()) { 1546 LongVector av = LongVector.fromArray(SPECIES, a, i); 1547 av.sub(b[i], vmask).intoArray(r, i); 1548 } 1549 1550 assertBroadcastArraysEquals(a, b, r, mask, Long64VectorTests::sub); 1551 } 1552 1553 @Test(dataProvider = "longBinaryOpProvider") 1554 static void mulLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1555 long[] a = fa.apply(SPECIES.length()); 1556 long[] b = fb.apply(SPECIES.length()); 1557 long[] r = fr.apply(SPECIES.length()); 1558 1559 for (int i = 0; i < a.length; i += SPECIES.length()) { 1560 LongVector av = LongVector.fromArray(SPECIES, a, i); 1561 av.mul(b[i]).intoArray(r, i); 1562 } 1563 1564 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::mul); 1565 } 1566 1567 @Test(dataProvider = "longBinaryOpMaskProvider") 1568 static void mulLong64VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1569 IntFunction<boolean[]> fm) { 1570 long[] a = fa.apply(SPECIES.length()); 1571 long[] b = fb.apply(SPECIES.length()); 1572 long[] r = fr.apply(SPECIES.length()); 1573 boolean[] mask = fm.apply(SPECIES.length()); 1574 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1575 1576 for (int i = 0; i < a.length; i += SPECIES.length()) { 1577 LongVector av = LongVector.fromArray(SPECIES, a, i); 1578 av.mul(b[i], vmask).intoArray(r, i); 1579 } 1580 1581 assertBroadcastArraysEquals(a, b, r, mask, Long64VectorTests::mul); 1582 } 1583 1584 1585 1586 1587 @Test(dataProvider = "longBinaryOpProvider") 1588 static void divLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1589 long[] a = fa.apply(SPECIES.length()); 1590 long[] b = fb.apply(SPECIES.length()); 1591 long[] r = fr.apply(SPECIES.length()); 1592 1593 replaceZero(b, (long) 1); 1594 1595 for (int i = 0; i < a.length; i += SPECIES.length()) { 1596 LongVector av = LongVector.fromArray(SPECIES, a, i); 1597 av.div(b[i]).intoArray(r, i); 1598 } 1599 1600 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::div); 1601 } 1602 1603 1604 1605 @Test(dataProvider = "longBinaryOpMaskProvider") 1606 static void divLong64VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1607 IntFunction<boolean[]> fm) { 1608 long[] a = fa.apply(SPECIES.length()); 1609 long[] b = fb.apply(SPECIES.length()); 1610 long[] r = fr.apply(SPECIES.length()); 1611 boolean[] mask = fm.apply(SPECIES.length()); 1612 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1613 1614 replaceZero(b, (long) 1); 1615 1616 for (int i = 0; i < a.length; i += SPECIES.length()) { 1617 LongVector av = LongVector.fromArray(SPECIES, a, i); 1618 av.div(b[i], vmask).intoArray(r, i); 1619 } 1620 1621 assertBroadcastArraysEquals(a, b, r, mask, Long64VectorTests::div); 1622 } 1623 1624 1625 1626 @Test(dataProvider = "longBinaryOpProvider") 1627 static void ORLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1628 long[] a = fa.apply(SPECIES.length()); 1629 long[] b = fb.apply(SPECIES.length()); 1630 long[] r = fr.apply(SPECIES.length()); 1631 1632 for (int i = 0; i < a.length; i += SPECIES.length()) { 1633 LongVector av = LongVector.fromArray(SPECIES, a, i); 1634 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); 1635 } 1636 1637 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::OR); 1638 } 1639 1640 @Test(dataProvider = "longBinaryOpProvider") 1641 static void orLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1642 long[] a = fa.apply(SPECIES.length()); 1643 long[] b = fb.apply(SPECIES.length()); 1644 long[] r = fr.apply(SPECIES.length()); 1645 1646 for (int i = 0; i < a.length; i += SPECIES.length()) { 1647 LongVector av = LongVector.fromArray(SPECIES, a, i); 1648 av.or(b[i]).intoArray(r, i); 1649 } 1650 1651 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::or); 1652 } 1653 1654 1655 1656 @Test(dataProvider = "longBinaryOpMaskProvider") 1657 static void ORLong64VectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1658 IntFunction<boolean[]> fm) { 1659 long[] a = fa.apply(SPECIES.length()); 1660 long[] b = fb.apply(SPECIES.length()); 1661 long[] r = fr.apply(SPECIES.length()); 1662 boolean[] mask = fm.apply(SPECIES.length()); 1663 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1664 1665 for (int i = 0; i < a.length; i += SPECIES.length()) { 1666 LongVector av = LongVector.fromArray(SPECIES, a, i); 1667 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); 1668 } 1669 1670 assertBroadcastArraysEquals(a, b, r, mask, Long64VectorTests::OR); 1671 } 1672 1673 1674 static long LSHL(long a, long b) { 1675 return (long)((a << b)); 1676 } 1677 1678 @Test(dataProvider = "longBinaryOpProvider") 1679 static void LSHLLong64VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1680 long[] a = fa.apply(SPECIES.length()); 1681 long[] b = fb.apply(SPECIES.length()); 1682 long[] r = fr.apply(SPECIES.length()); 1683 1684 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1685 for (int i = 0; i < a.length; i += SPECIES.length()) { 1686 LongVector av = LongVector.fromArray(SPECIES, a, i); 1687 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1688 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1689 } 1690 } 1691 1692 assertArraysEquals(a, b, r, Long64VectorTests::LSHL); 1693 } 2016 return (long)(Math.max(a, b)); 2017 } 2018 2019 @Test(dataProvider = "longBinaryOpProvider") 2020 static void maxLong64VectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2021 long[] a = fa.apply(SPECIES.length()); 2022 long[] b = fb.apply(SPECIES.length()); 2023 long[] r = fr.apply(SPECIES.length()); 2024 2025 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2026 for (int i = 0; i < a.length; i += SPECIES.length()) { 2027 LongVector av = LongVector.fromArray(SPECIES, a, i); 2028 LongVector bv = LongVector.fromArray(SPECIES, b, i); 2029 av.max(bv).intoArray(r, i); 2030 } 2031 } 2032 2033 assertArraysEquals(a, b, r, Long64VectorTests::max); 2034 } 2035 2036 @Test(dataProvider = "longBinaryOpProvider") 2037 static void MINLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2038 long[] a = fa.apply(SPECIES.length()); 2039 long[] b = fb.apply(SPECIES.length()); 2040 long[] r = fr.apply(SPECIES.length()); 2041 2042 for (int i = 0; i < a.length; i += SPECIES.length()) { 2043 LongVector av = LongVector.fromArray(SPECIES, a, i); 2044 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2045 } 2046 2047 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::MIN); 2048 } 2049 2050 @Test(dataProvider = "longBinaryOpProvider") 2051 static void minLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2052 long[] a = fa.apply(SPECIES.length()); 2053 long[] b = fb.apply(SPECIES.length()); 2054 long[] r = fr.apply(SPECIES.length()); 2055 2056 for (int i = 0; i < a.length; i += SPECIES.length()) { 2057 LongVector av = LongVector.fromArray(SPECIES, a, i); 2058 av.min(b[i]).intoArray(r, i); 2059 } 2060 2061 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::min); 2062 } 2063 2064 @Test(dataProvider = "longBinaryOpProvider") 2065 static void MAXLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2066 long[] a = fa.apply(SPECIES.length()); 2067 long[] b = fb.apply(SPECIES.length()); 2068 long[] r = fr.apply(SPECIES.length()); 2069 2070 for (int i = 0; i < a.length; i += SPECIES.length()) { 2071 LongVector av = LongVector.fromArray(SPECIES, a, i); 2072 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2073 } 2074 2075 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::MAX); 2076 } 2077 2078 @Test(dataProvider = "longBinaryOpProvider") 2079 static void maxLong64VectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2080 long[] a = fa.apply(SPECIES.length()); 2081 long[] b = fb.apply(SPECIES.length()); 2082 long[] r = fr.apply(SPECIES.length()); 2083 2084 for (int i = 0; i < a.length; i += SPECIES.length()) { 2085 LongVector av = LongVector.fromArray(SPECIES, a, i); 2086 av.max(b[i]).intoArray(r, i); 2087 } 2088 2089 assertBroadcastArraysEquals(a, b, r, Long64VectorTests::max); 2090 } 2091 2092 static long AND(long[] a, int idx) { 2093 long res = -1; 2094 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2095 res &= a[i]; 2096 } 2097 2098 return res; 2099 } 2100 2101 static long AND(long[] a) { 2102 long res = -1; 2103 for (int i = 0; i < a.length; i += SPECIES.length()) { 2104 long tmp = -1; 2105 for (int j = 0; j < SPECIES.length(); j++) { 2106 tmp &= a[i + j]; 2107 } 2108 res &= tmp; 2109 } 2110 2111 return res; 3516 boolean[] mask = fm.apply(SPECIES.length()); 3517 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3518 3519 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3520 for (int i = 0; i < a.length; i += SPECIES.length()) { 3521 LongVector av = LongVector.fromArray(SPECIES, a, i); 3522 LongVector bv = LongVector.fromArray(SPECIES, b, i); 3523 LongVector cv = LongVector.fromArray(SPECIES, c, i); 3524 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 3525 } 3526 } 3527 3528 assertArraysEquals(a, b, c, r, mask, Long64VectorTests::BITWISE_BLEND); 3529 } 3530 3531 3532 static long NEG(long a) { 3533 return (long)(-((long)a)); 3534 } 3535 3536 static long neg(long a) { 3537 return (long)(-((long)a)); 3538 } 3539 3540 @Test(dataProvider = "longUnaryOpProvider") 3541 static void NEGLong64VectorTests(IntFunction<long[]> fa) { 3542 long[] a = fa.apply(SPECIES.length()); 3543 long[] r = fr.apply(SPECIES.length()); 3544 3545 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3546 for (int i = 0; i < a.length; i += SPECIES.length()) { 3547 LongVector av = LongVector.fromArray(SPECIES, a, i); 3548 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3549 } 3550 } 3551 3552 assertArraysEquals(a, r, Long64VectorTests::NEG); 3553 } 3554 3555 @Test(dataProvider = "longUnaryOpProvider") 3556 static void negLong64VectorTests(IntFunction<long[]> fa) { 3557 long[] a = fa.apply(SPECIES.length()); 3558 long[] r = fr.apply(SPECIES.length()); 3559 3560 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3561 for (int i = 0; i < a.length; i += SPECIES.length()) { 3562 LongVector av = LongVector.fromArray(SPECIES, a, i); 3563 av.neg().intoArray(r, i); 3564 } 3565 } 3566 3567 assertArraysEquals(a, r, Long64VectorTests::neg); 3568 } 3569 3570 @Test(dataProvider = "longUnaryOpMaskProvider") 3571 static void NEGMaskedLong64VectorTests(IntFunction<long[]> fa, 3572 IntFunction<boolean[]> fm) { 3573 long[] a = fa.apply(SPECIES.length()); 3574 long[] r = fr.apply(SPECIES.length()); 3575 boolean[] mask = fm.apply(SPECIES.length()); 3576 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3577 3578 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3579 for (int i = 0; i < a.length; i += SPECIES.length()) { 3580 LongVector av = LongVector.fromArray(SPECIES, a, i); 3581 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3582 } 3583 } 3584 3585 assertArraysEquals(a, r, mask, Long64VectorTests::NEG); 3586 } 3587 3588 static long ABS(long a) { 3589 return (long)(Math.abs((long)a)); 3629 long[] a = fa.apply(SPECIES.length()); 3630 long[] r = fr.apply(SPECIES.length()); 3631 boolean[] mask = fm.apply(SPECIES.length()); 3632 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3633 3634 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3635 for (int i = 0; i < a.length; i += SPECIES.length()) { 3636 LongVector av = LongVector.fromArray(SPECIES, a, i); 3637 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3638 } 3639 } 3640 3641 assertArraysEquals(a, r, mask, Long64VectorTests::ABS); 3642 } 3643 3644 3645 static long NOT(long a) { 3646 return (long)(~((long)a)); 3647 } 3648 3649 static long not(long a) { 3650 return (long)(~((long)a)); 3651 } 3652 3653 3654 3655 @Test(dataProvider = "longUnaryOpProvider") 3656 static void NOTLong64VectorTests(IntFunction<long[]> fa) { 3657 long[] a = fa.apply(SPECIES.length()); 3658 long[] r = fr.apply(SPECIES.length()); 3659 3660 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3661 for (int i = 0; i < a.length; i += SPECIES.length()) { 3662 LongVector av = LongVector.fromArray(SPECIES, a, i); 3663 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3664 } 3665 } 3666 3667 assertArraysEquals(a, r, Long64VectorTests::NOT); 3668 } 3669 3670 @Test(dataProvider = "longUnaryOpProvider") 3671 static void notLong64VectorTests(IntFunction<long[]> fa) { 3672 long[] a = fa.apply(SPECIES.length()); 3673 long[] r = fr.apply(SPECIES.length()); 3674 3675 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3676 for (int i = 0; i < a.length; i += SPECIES.length()) { 3677 LongVector av = LongVector.fromArray(SPECIES, a, i); 3678 av.not().intoArray(r, i); 3679 } 3680 } 3681 3682 assertArraysEquals(a, r, Long64VectorTests::not); 3683 } 3684 3685 3686 3687 @Test(dataProvider = "longUnaryOpMaskProvider") 3688 static void NOTMaskedLong64VectorTests(IntFunction<long[]> fa, 3689 IntFunction<boolean[]> fm) { 3690 long[] a = fa.apply(SPECIES.length()); 3691 long[] r = fr.apply(SPECIES.length()); 3692 boolean[] mask = fm.apply(SPECIES.length()); 3693 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3694 3695 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3696 for (int i = 0; i < a.length; i += SPECIES.length()) { 3697 LongVector av = LongVector.fromArray(SPECIES, a, i); 3698 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3699 } 3700 } 3701 3702 assertArraysEquals(a, r, mask, Long64VectorTests::NOT); |