229 230 interface FBinMaskOp { 231 long apply(long a, long b, boolean m); 232 233 static FBinMaskOp lift(FBinOp f) { 234 return (a, b, m) -> m ? f.apply(a, b) : a; 235 } 236 } 237 238 static void assertArraysEquals(long[] a, long[] b, long[] r, FBinOp f) { 239 int i = 0; 240 try { 241 for (; i < a.length; i++) { 242 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 243 } 244 } catch (AssertionError e) { 245 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 246 } 247 } 248 249 static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 250 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 251 } 252 253 static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 254 int i = 0; 255 try { 256 for (; i < a.length; i++) { 257 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 258 } 259 } catch (AssertionError err) { 260 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 261 } 262 } 263 264 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, FBinOp f) { 265 int i = 0; 266 int j = 0; 267 try { 268 for (; j < a.length; j += SPECIES.length()) { 269 for (i = 0; i < SPECIES.length(); i++) { 270 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 271 } 272 } 273 } catch (AssertionError e) { 274 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 275 } 276 } 277 278 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 279 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 280 } 281 282 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 283 int i = 0; 1362 static long OR(long a, long b) { 1363 return (long)(a | b); 1364 } 1365 1366 @Test(dataProvider = "longBinaryOpProvider") 1367 static void ORLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1368 long[] a = fa.apply(SPECIES.length()); 1369 long[] b = fb.apply(SPECIES.length()); 1370 long[] r = fr.apply(SPECIES.length()); 1371 1372 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1373 for (int i = 0; i < a.length; i += SPECIES.length()) { 1374 LongVector av = LongVector.fromArray(SPECIES, a, i); 1375 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1376 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1377 } 1378 } 1379 1380 assertArraysEquals(a, b, r, LongMaxVectorTests::OR); 1381 } 1382 1383 1384 1385 @Test(dataProvider = "longBinaryOpMaskProvider") 1386 static void ORLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1387 IntFunction<boolean[]> fm) { 1388 long[] a = fa.apply(SPECIES.length()); 1389 long[] b = fb.apply(SPECIES.length()); 1390 long[] r = fr.apply(SPECIES.length()); 1391 boolean[] mask = fm.apply(SPECIES.length()); 1392 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1393 1394 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1395 for (int i = 0; i < a.length; i += SPECIES.length()) { 1396 LongVector av = LongVector.fromArray(SPECIES, a, i); 1397 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1398 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1399 } 1400 } 1401 1430 static void XORLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1431 IntFunction<boolean[]> fm) { 1432 long[] a = fa.apply(SPECIES.length()); 1433 long[] b = fb.apply(SPECIES.length()); 1434 long[] r = fr.apply(SPECIES.length()); 1435 boolean[] mask = fm.apply(SPECIES.length()); 1436 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1437 1438 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1439 for (int i = 0; i < a.length; i += SPECIES.length()) { 1440 LongVector av = LongVector.fromArray(SPECIES, a, i); 1441 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1442 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1443 } 1444 } 1445 1446 assertArraysEquals(a, b, r, mask, LongMaxVectorTests::XOR); 1447 } 1448 1449 1450 static long LSHL(long a, long b) { 1451 return (long)((a << b)); 1452 } 1453 1454 @Test(dataProvider = "longBinaryOpProvider") 1455 static void LSHLLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1456 long[] a = fa.apply(SPECIES.length()); 1457 long[] b = fb.apply(SPECIES.length()); 1458 long[] r = fr.apply(SPECIES.length()); 1459 1460 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1461 for (int i = 0; i < a.length; i += SPECIES.length()) { 1462 LongVector av = LongVector.fromArray(SPECIES, a, i); 1463 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1464 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1465 } 1466 } 1467 1468 assertArraysEquals(a, b, r, LongMaxVectorTests::LSHL); 1469 } 1792 return (long)(Math.max(a, b)); 1793 } 1794 1795 @Test(dataProvider = "longBinaryOpProvider") 1796 static void maxLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1797 long[] a = fa.apply(SPECIES.length()); 1798 long[] b = fb.apply(SPECIES.length()); 1799 long[] r = fr.apply(SPECIES.length()); 1800 1801 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1802 for (int i = 0; i < a.length; i += SPECIES.length()) { 1803 LongVector av = LongVector.fromArray(SPECIES, a, i); 1804 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1805 av.max(bv).intoArray(r, i); 1806 } 1807 } 1808 1809 assertArraysEquals(a, b, r, LongMaxVectorTests::max); 1810 } 1811 1812 static long AND(long[] a, int idx) { 1813 long res = -1; 1814 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1815 res &= a[i]; 1816 } 1817 1818 return res; 1819 } 1820 1821 static long AND(long[] a) { 1822 long res = -1; 1823 for (int i = 0; i < a.length; i += SPECIES.length()) { 1824 long tmp = -1; 1825 for (int j = 0; j < SPECIES.length(); j++) { 1826 tmp &= a[i + j]; 1827 } 1828 res &= tmp; 1829 } 1830 1831 return res; 3236 boolean[] mask = fm.apply(SPECIES.length()); 3237 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3238 3239 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3240 for (int i = 0; i < a.length; i += SPECIES.length()) { 3241 LongVector av = LongVector.fromArray(SPECIES, a, i); 3242 LongVector bv = LongVector.fromArray(SPECIES, b, i); 3243 LongVector cv = LongVector.fromArray(SPECIES, c, i); 3244 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 3245 } 3246 } 3247 3248 assertArraysEquals(a, b, c, r, mask, LongMaxVectorTests::BITWISE_BLEND); 3249 } 3250 3251 3252 static long NEG(long a) { 3253 return (long)(-((long)a)); 3254 } 3255 3256 @Test(dataProvider = "longUnaryOpProvider") 3257 static void NEGLongMaxVectorTests(IntFunction<long[]> fa) { 3258 long[] a = fa.apply(SPECIES.length()); 3259 long[] r = fr.apply(SPECIES.length()); 3260 3261 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3262 for (int i = 0; i < a.length; i += SPECIES.length()) { 3263 LongVector av = LongVector.fromArray(SPECIES, a, i); 3264 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3265 } 3266 } 3267 3268 assertArraysEquals(a, r, LongMaxVectorTests::NEG); 3269 } 3270 3271 @Test(dataProvider = "longUnaryOpMaskProvider") 3272 static void NEGMaskedLongMaxVectorTests(IntFunction<long[]> fa, 3273 IntFunction<boolean[]> fm) { 3274 long[] a = fa.apply(SPECIES.length()); 3275 long[] r = fr.apply(SPECIES.length()); 3276 boolean[] mask = fm.apply(SPECIES.length()); 3277 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3278 3279 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3280 for (int i = 0; i < a.length; i += SPECIES.length()) { 3281 LongVector av = LongVector.fromArray(SPECIES, a, i); 3282 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3283 } 3284 } 3285 3286 assertArraysEquals(a, r, mask, LongMaxVectorTests::NEG); 3287 } 3288 3289 static long ABS(long a) { 3290 return (long)(Math.abs((long)a)); 3330 long[] a = fa.apply(SPECIES.length()); 3331 long[] r = fr.apply(SPECIES.length()); 3332 boolean[] mask = fm.apply(SPECIES.length()); 3333 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3334 3335 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3336 for (int i = 0; i < a.length; i += SPECIES.length()) { 3337 LongVector av = LongVector.fromArray(SPECIES, a, i); 3338 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3339 } 3340 } 3341 3342 assertArraysEquals(a, r, mask, LongMaxVectorTests::ABS); 3343 } 3344 3345 3346 static long NOT(long a) { 3347 return (long)(~((long)a)); 3348 } 3349 3350 3351 3352 @Test(dataProvider = "longUnaryOpProvider") 3353 static void NOTLongMaxVectorTests(IntFunction<long[]> fa) { 3354 long[] a = fa.apply(SPECIES.length()); 3355 long[] r = fr.apply(SPECIES.length()); 3356 3357 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3358 for (int i = 0; i < a.length; i += SPECIES.length()) { 3359 LongVector av = LongVector.fromArray(SPECIES, a, i); 3360 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3361 } 3362 } 3363 3364 assertArraysEquals(a, r, LongMaxVectorTests::NOT); 3365 } 3366 3367 3368 3369 @Test(dataProvider = "longUnaryOpMaskProvider") 3370 static void NOTMaskedLongMaxVectorTests(IntFunction<long[]> fa, 3371 IntFunction<boolean[]> fm) { 3372 long[] a = fa.apply(SPECIES.length()); 3373 long[] r = fr.apply(SPECIES.length()); 3374 boolean[] mask = fm.apply(SPECIES.length()); 3375 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3376 3377 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3378 for (int i = 0; i < a.length; i += SPECIES.length()) { 3379 LongVector av = LongVector.fromArray(SPECIES, a, i); 3380 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3381 } 3382 } 3383 3384 assertArraysEquals(a, r, mask, LongMaxVectorTests::NOT); | 229 230 interface FBinMaskOp { 231 long apply(long a, long b, boolean m); 232 233 static FBinMaskOp lift(FBinOp f) { 234 return (a, b, m) -> m ? f.apply(a, b) : a; 235 } 236 } 237 238 static void assertArraysEquals(long[] a, long[] b, long[] r, FBinOp f) { 239 int i = 0; 240 try { 241 for (; i < a.length; i++) { 242 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 243 } 244 } catch (AssertionError e) { 245 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 246 } 247 } 248 249 static void assertBroadcastArraysEquals(long[] a, long[] b, long[] r, FBinOp f) { 250 int i = 0; 251 try { 252 for (; i < a.length; i++) { 253 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 254 } 255 } catch (AssertionError e) { 256 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), 257 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 258 } 259 } 260 261 static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 262 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 263 } 264 265 static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 266 int i = 0; 267 try { 268 for (; i < a.length; i++) { 269 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 270 } 271 } catch (AssertionError err) { 272 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 273 } 274 } 275 276 static void assertBroadcastArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 277 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 278 } 279 280 static void assertBroadcastArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 281 int i = 0; 282 try { 283 for (; i < a.length; i++) { 284 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 285 } 286 } catch (AssertionError err) { 287 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 288 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 289 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 290 mask[i % SPECIES.length()]); 291 } 292 } 293 294 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, FBinOp f) { 295 int i = 0; 296 int j = 0; 297 try { 298 for (; j < a.length; j += SPECIES.length()) { 299 for (i = 0; i < SPECIES.length(); i++) { 300 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 301 } 302 } 303 } catch (AssertionError e) { 304 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 305 } 306 } 307 308 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { 309 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 310 } 311 312 static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { 313 int i = 0; 1392 static long OR(long a, long b) { 1393 return (long)(a | b); 1394 } 1395 1396 @Test(dataProvider = "longBinaryOpProvider") 1397 static void ORLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1398 long[] a = fa.apply(SPECIES.length()); 1399 long[] b = fb.apply(SPECIES.length()); 1400 long[] r = fr.apply(SPECIES.length()); 1401 1402 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1403 for (int i = 0; i < a.length; i += SPECIES.length()) { 1404 LongVector av = LongVector.fromArray(SPECIES, a, i); 1405 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1406 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1407 } 1408 } 1409 1410 assertArraysEquals(a, b, r, LongMaxVectorTests::OR); 1411 } 1412 static long or(long a, long b) { 1413 return (long)(a | b); 1414 } 1415 1416 @Test(dataProvider = "longBinaryOpProvider") 1417 static void orLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1418 long[] a = fa.apply(SPECIES.length()); 1419 long[] b = fb.apply(SPECIES.length()); 1420 long[] r = fr.apply(SPECIES.length()); 1421 1422 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1423 for (int i = 0; i < a.length; i += SPECIES.length()) { 1424 LongVector av = LongVector.fromArray(SPECIES, a, i); 1425 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1426 av.or(bv).intoArray(r, i); 1427 } 1428 } 1429 1430 assertArraysEquals(a, b, r, LongMaxVectorTests::or); 1431 } 1432 1433 1434 1435 @Test(dataProvider = "longBinaryOpMaskProvider") 1436 static void ORLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1437 IntFunction<boolean[]> fm) { 1438 long[] a = fa.apply(SPECIES.length()); 1439 long[] b = fb.apply(SPECIES.length()); 1440 long[] r = fr.apply(SPECIES.length()); 1441 boolean[] mask = fm.apply(SPECIES.length()); 1442 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1443 1444 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1445 for (int i = 0; i < a.length; i += SPECIES.length()) { 1446 LongVector av = LongVector.fromArray(SPECIES, a, i); 1447 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1448 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1449 } 1450 } 1451 1480 static void XORLongMaxVectorTestsMasked(IntFunction<long[]> fa, IntFunction<long[]> fb, 1481 IntFunction<boolean[]> fm) { 1482 long[] a = fa.apply(SPECIES.length()); 1483 long[] b = fb.apply(SPECIES.length()); 1484 long[] r = fr.apply(SPECIES.length()); 1485 boolean[] mask = fm.apply(SPECIES.length()); 1486 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1487 1488 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1489 for (int i = 0; i < a.length; i += SPECIES.length()) { 1490 LongVector av = LongVector.fromArray(SPECIES, a, i); 1491 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1492 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1493 } 1494 } 1495 1496 assertArraysEquals(a, b, r, mask, LongMaxVectorTests::XOR); 1497 } 1498 1499 1500 @Test(dataProvider = "longBinaryOpProvider") 1501 static void addLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1502 long[] a = fa.apply(SPECIES.length()); 1503 long[] b = fb.apply(SPECIES.length()); 1504 long[] r = fr.apply(SPECIES.length()); 1505 1506 for (int i = 0; i < a.length; i += SPECIES.length()) { 1507 LongVector av = LongVector.fromArray(SPECIES, a, i); 1508 av.add(b[i]).intoArray(r, i); 1509 } 1510 1511 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::add); 1512 } 1513 1514 @Test(dataProvider = "longBinaryOpMaskProvider") 1515 static void addLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1516 IntFunction<boolean[]> fm) { 1517 long[] a = fa.apply(SPECIES.length()); 1518 long[] b = fb.apply(SPECIES.length()); 1519 long[] r = fr.apply(SPECIES.length()); 1520 boolean[] mask = fm.apply(SPECIES.length()); 1521 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1522 1523 for (int i = 0; i < a.length; i += SPECIES.length()) { 1524 LongVector av = LongVector.fromArray(SPECIES, a, i); 1525 av.add(b[i], vmask).intoArray(r, i); 1526 } 1527 1528 assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::add); 1529 } 1530 1531 @Test(dataProvider = "longBinaryOpProvider") 1532 static void subLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1533 long[] a = fa.apply(SPECIES.length()); 1534 long[] b = fb.apply(SPECIES.length()); 1535 long[] r = fr.apply(SPECIES.length()); 1536 1537 for (int i = 0; i < a.length; i += SPECIES.length()) { 1538 LongVector av = LongVector.fromArray(SPECIES, a, i); 1539 av.sub(b[i]).intoArray(r, i); 1540 } 1541 1542 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::sub); 1543 } 1544 1545 @Test(dataProvider = "longBinaryOpMaskProvider") 1546 static void subLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1547 IntFunction<boolean[]> fm) { 1548 long[] a = fa.apply(SPECIES.length()); 1549 long[] b = fb.apply(SPECIES.length()); 1550 long[] r = fr.apply(SPECIES.length()); 1551 boolean[] mask = fm.apply(SPECIES.length()); 1552 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1553 1554 for (int i = 0; i < a.length; i += SPECIES.length()) { 1555 LongVector av = LongVector.fromArray(SPECIES, a, i); 1556 av.sub(b[i], vmask).intoArray(r, i); 1557 } 1558 1559 assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::sub); 1560 } 1561 1562 @Test(dataProvider = "longBinaryOpProvider") 1563 static void mulLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1564 long[] a = fa.apply(SPECIES.length()); 1565 long[] b = fb.apply(SPECIES.length()); 1566 long[] r = fr.apply(SPECIES.length()); 1567 1568 for (int i = 0; i < a.length; i += SPECIES.length()) { 1569 LongVector av = LongVector.fromArray(SPECIES, a, i); 1570 av.mul(b[i]).intoArray(r, i); 1571 } 1572 1573 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::mul); 1574 } 1575 1576 @Test(dataProvider = "longBinaryOpMaskProvider") 1577 static void mulLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1578 IntFunction<boolean[]> fm) { 1579 long[] a = fa.apply(SPECIES.length()); 1580 long[] b = fb.apply(SPECIES.length()); 1581 long[] r = fr.apply(SPECIES.length()); 1582 boolean[] mask = fm.apply(SPECIES.length()); 1583 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1584 1585 for (int i = 0; i < a.length; i += SPECIES.length()) { 1586 LongVector av = LongVector.fromArray(SPECIES, a, i); 1587 av.mul(b[i], vmask).intoArray(r, i); 1588 } 1589 1590 assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::mul); 1591 } 1592 1593 1594 1595 1596 @Test(dataProvider = "longBinaryOpProvider") 1597 static void divLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1598 long[] a = fa.apply(SPECIES.length()); 1599 long[] b = fb.apply(SPECIES.length()); 1600 long[] r = fr.apply(SPECIES.length()); 1601 1602 replaceZero(b, (long) 1); 1603 1604 for (int i = 0; i < a.length; i += SPECIES.length()) { 1605 LongVector av = LongVector.fromArray(SPECIES, a, i); 1606 av.div(b[i]).intoArray(r, i); 1607 } 1608 1609 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::div); 1610 } 1611 1612 1613 1614 @Test(dataProvider = "longBinaryOpMaskProvider") 1615 static void divLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1616 IntFunction<boolean[]> fm) { 1617 long[] a = fa.apply(SPECIES.length()); 1618 long[] b = fb.apply(SPECIES.length()); 1619 long[] r = fr.apply(SPECIES.length()); 1620 boolean[] mask = fm.apply(SPECIES.length()); 1621 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1622 1623 replaceZero(b, (long) 1); 1624 1625 for (int i = 0; i < a.length; i += SPECIES.length()) { 1626 LongVector av = LongVector.fromArray(SPECIES, a, i); 1627 av.div(b[i], vmask).intoArray(r, i); 1628 } 1629 1630 assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::div); 1631 } 1632 1633 1634 1635 @Test(dataProvider = "longBinaryOpProvider") 1636 static void ORLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1637 long[] a = fa.apply(SPECIES.length()); 1638 long[] b = fb.apply(SPECIES.length()); 1639 long[] r = fr.apply(SPECIES.length()); 1640 1641 for (int i = 0; i < a.length; i += SPECIES.length()) { 1642 LongVector av = LongVector.fromArray(SPECIES, a, i); 1643 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); 1644 } 1645 1646 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::OR); 1647 } 1648 1649 @Test(dataProvider = "longBinaryOpProvider") 1650 static void orLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1651 long[] a = fa.apply(SPECIES.length()); 1652 long[] b = fb.apply(SPECIES.length()); 1653 long[] r = fr.apply(SPECIES.length()); 1654 1655 for (int i = 0; i < a.length; i += SPECIES.length()) { 1656 LongVector av = LongVector.fromArray(SPECIES, a, i); 1657 av.or(b[i]).intoArray(r, i); 1658 } 1659 1660 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::or); 1661 } 1662 1663 1664 1665 @Test(dataProvider = "longBinaryOpMaskProvider") 1666 static void ORLongMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb, 1667 IntFunction<boolean[]> fm) { 1668 long[] a = fa.apply(SPECIES.length()); 1669 long[] b = fb.apply(SPECIES.length()); 1670 long[] r = fr.apply(SPECIES.length()); 1671 boolean[] mask = fm.apply(SPECIES.length()); 1672 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1673 1674 for (int i = 0; i < a.length; i += SPECIES.length()) { 1675 LongVector av = LongVector.fromArray(SPECIES, a, i); 1676 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); 1677 } 1678 1679 assertBroadcastArraysEquals(a, b, r, mask, LongMaxVectorTests::OR); 1680 } 1681 1682 1683 static long LSHL(long a, long b) { 1684 return (long)((a << b)); 1685 } 1686 1687 @Test(dataProvider = "longBinaryOpProvider") 1688 static void LSHLLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 1689 long[] a = fa.apply(SPECIES.length()); 1690 long[] b = fb.apply(SPECIES.length()); 1691 long[] r = fr.apply(SPECIES.length()); 1692 1693 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1694 for (int i = 0; i < a.length; i += SPECIES.length()) { 1695 LongVector av = LongVector.fromArray(SPECIES, a, i); 1696 LongVector bv = LongVector.fromArray(SPECIES, b, i); 1697 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1698 } 1699 } 1700 1701 assertArraysEquals(a, b, r, LongMaxVectorTests::LSHL); 1702 } 2025 return (long)(Math.max(a, b)); 2026 } 2027 2028 @Test(dataProvider = "longBinaryOpProvider") 2029 static void maxLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2030 long[] a = fa.apply(SPECIES.length()); 2031 long[] b = fb.apply(SPECIES.length()); 2032 long[] r = fr.apply(SPECIES.length()); 2033 2034 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2035 for (int i = 0; i < a.length; i += SPECIES.length()) { 2036 LongVector av = LongVector.fromArray(SPECIES, a, i); 2037 LongVector bv = LongVector.fromArray(SPECIES, b, i); 2038 av.max(bv).intoArray(r, i); 2039 } 2040 } 2041 2042 assertArraysEquals(a, b, r, LongMaxVectorTests::max); 2043 } 2044 2045 @Test(dataProvider = "longBinaryOpProvider") 2046 static void MINLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2047 long[] a = fa.apply(SPECIES.length()); 2048 long[] b = fb.apply(SPECIES.length()); 2049 long[] r = fr.apply(SPECIES.length()); 2050 2051 for (int i = 0; i < a.length; i += SPECIES.length()) { 2052 LongVector av = LongVector.fromArray(SPECIES, a, i); 2053 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2054 } 2055 2056 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::MIN); 2057 } 2058 2059 @Test(dataProvider = "longBinaryOpProvider") 2060 static void minLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2061 long[] a = fa.apply(SPECIES.length()); 2062 long[] b = fb.apply(SPECIES.length()); 2063 long[] r = fr.apply(SPECIES.length()); 2064 2065 for (int i = 0; i < a.length; i += SPECIES.length()) { 2066 LongVector av = LongVector.fromArray(SPECIES, a, i); 2067 av.min(b[i]).intoArray(r, i); 2068 } 2069 2070 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::min); 2071 } 2072 2073 @Test(dataProvider = "longBinaryOpProvider") 2074 static void MAXLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2075 long[] a = fa.apply(SPECIES.length()); 2076 long[] b = fb.apply(SPECIES.length()); 2077 long[] r = fr.apply(SPECIES.length()); 2078 2079 for (int i = 0; i < a.length; i += SPECIES.length()) { 2080 LongVector av = LongVector.fromArray(SPECIES, a, i); 2081 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2082 } 2083 2084 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::MAX); 2085 } 2086 2087 @Test(dataProvider = "longBinaryOpProvider") 2088 static void maxLongMaxVectorTestsBroadcastSmokeTest(IntFunction<long[]> fa, IntFunction<long[]> fb) { 2089 long[] a = fa.apply(SPECIES.length()); 2090 long[] b = fb.apply(SPECIES.length()); 2091 long[] r = fr.apply(SPECIES.length()); 2092 2093 for (int i = 0; i < a.length; i += SPECIES.length()) { 2094 LongVector av = LongVector.fromArray(SPECIES, a, i); 2095 av.max(b[i]).intoArray(r, i); 2096 } 2097 2098 assertBroadcastArraysEquals(a, b, r, LongMaxVectorTests::max); 2099 } 2100 2101 static long AND(long[] a, int idx) { 2102 long res = -1; 2103 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2104 res &= a[i]; 2105 } 2106 2107 return res; 2108 } 2109 2110 static long AND(long[] a) { 2111 long res = -1; 2112 for (int i = 0; i < a.length; i += SPECIES.length()) { 2113 long tmp = -1; 2114 for (int j = 0; j < SPECIES.length(); j++) { 2115 tmp &= a[i + j]; 2116 } 2117 res &= tmp; 2118 } 2119 2120 return res; 3525 boolean[] mask = fm.apply(SPECIES.length()); 3526 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3527 3528 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3529 for (int i = 0; i < a.length; i += SPECIES.length()) { 3530 LongVector av = LongVector.fromArray(SPECIES, a, i); 3531 LongVector bv = LongVector.fromArray(SPECIES, b, i); 3532 LongVector cv = LongVector.fromArray(SPECIES, c, i); 3533 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 3534 } 3535 } 3536 3537 assertArraysEquals(a, b, c, r, mask, LongMaxVectorTests::BITWISE_BLEND); 3538 } 3539 3540 3541 static long NEG(long a) { 3542 return (long)(-((long)a)); 3543 } 3544 3545 static long neg(long a) { 3546 return (long)(-((long)a)); 3547 } 3548 3549 @Test(dataProvider = "longUnaryOpProvider") 3550 static void NEGLongMaxVectorTests(IntFunction<long[]> fa) { 3551 long[] a = fa.apply(SPECIES.length()); 3552 long[] r = fr.apply(SPECIES.length()); 3553 3554 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3555 for (int i = 0; i < a.length; i += SPECIES.length()) { 3556 LongVector av = LongVector.fromArray(SPECIES, a, i); 3557 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3558 } 3559 } 3560 3561 assertArraysEquals(a, r, LongMaxVectorTests::NEG); 3562 } 3563 3564 @Test(dataProvider = "longUnaryOpProvider") 3565 static void negLongMaxVectorTests(IntFunction<long[]> fa) { 3566 long[] a = fa.apply(SPECIES.length()); 3567 long[] r = fr.apply(SPECIES.length()); 3568 3569 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3570 for (int i = 0; i < a.length; i += SPECIES.length()) { 3571 LongVector av = LongVector.fromArray(SPECIES, a, i); 3572 av.neg().intoArray(r, i); 3573 } 3574 } 3575 3576 assertArraysEquals(a, r, LongMaxVectorTests::neg); 3577 } 3578 3579 @Test(dataProvider = "longUnaryOpMaskProvider") 3580 static void NEGMaskedLongMaxVectorTests(IntFunction<long[]> fa, 3581 IntFunction<boolean[]> fm) { 3582 long[] a = fa.apply(SPECIES.length()); 3583 long[] r = fr.apply(SPECIES.length()); 3584 boolean[] mask = fm.apply(SPECIES.length()); 3585 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3586 3587 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3588 for (int i = 0; i < a.length; i += SPECIES.length()) { 3589 LongVector av = LongVector.fromArray(SPECIES, a, i); 3590 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3591 } 3592 } 3593 3594 assertArraysEquals(a, r, mask, LongMaxVectorTests::NEG); 3595 } 3596 3597 static long ABS(long a) { 3598 return (long)(Math.abs((long)a)); 3638 long[] a = fa.apply(SPECIES.length()); 3639 long[] r = fr.apply(SPECIES.length()); 3640 boolean[] mask = fm.apply(SPECIES.length()); 3641 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3642 3643 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3644 for (int i = 0; i < a.length; i += SPECIES.length()) { 3645 LongVector av = LongVector.fromArray(SPECIES, a, i); 3646 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3647 } 3648 } 3649 3650 assertArraysEquals(a, r, mask, LongMaxVectorTests::ABS); 3651 } 3652 3653 3654 static long NOT(long a) { 3655 return (long)(~((long)a)); 3656 } 3657 3658 static long not(long a) { 3659 return (long)(~((long)a)); 3660 } 3661 3662 3663 3664 @Test(dataProvider = "longUnaryOpProvider") 3665 static void NOTLongMaxVectorTests(IntFunction<long[]> fa) { 3666 long[] a = fa.apply(SPECIES.length()); 3667 long[] r = fr.apply(SPECIES.length()); 3668 3669 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3670 for (int i = 0; i < a.length; i += SPECIES.length()) { 3671 LongVector av = LongVector.fromArray(SPECIES, a, i); 3672 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3673 } 3674 } 3675 3676 assertArraysEquals(a, r, LongMaxVectorTests::NOT); 3677 } 3678 3679 @Test(dataProvider = "longUnaryOpProvider") 3680 static void notLongMaxVectorTests(IntFunction<long[]> fa) { 3681 long[] a = fa.apply(SPECIES.length()); 3682 long[] r = fr.apply(SPECIES.length()); 3683 3684 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3685 for (int i = 0; i < a.length; i += SPECIES.length()) { 3686 LongVector av = LongVector.fromArray(SPECIES, a, i); 3687 av.not().intoArray(r, i); 3688 } 3689 } 3690 3691 assertArraysEquals(a, r, LongMaxVectorTests::not); 3692 } 3693 3694 3695 3696 @Test(dataProvider = "longUnaryOpMaskProvider") 3697 static void NOTMaskedLongMaxVectorTests(IntFunction<long[]> fa, 3698 IntFunction<boolean[]> fm) { 3699 long[] a = fa.apply(SPECIES.length()); 3700 long[] r = fr.apply(SPECIES.length()); 3701 boolean[] mask = fm.apply(SPECIES.length()); 3702 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3703 3704 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3705 for (int i = 0; i < a.length; i += SPECIES.length()) { 3706 LongVector av = LongVector.fromArray(SPECIES, a, i); 3707 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3708 } 3709 } 3710 3711 assertArraysEquals(a, r, mask, LongMaxVectorTests::NOT); |