OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/assembler-inl.h" | 5 #include "src/assembler-inl.h" |
6 #include "src/wasm/wasm-macro-gen.h" | 6 #include "src/wasm/wasm-macro-gen.h" |
7 #include "test/cctest/cctest.h" | 7 #include "test/cctest/cctest.h" |
8 #include "test/cctest/compiler/value-helper.h" | 8 #include "test/cctest/compiler/value-helper.h" |
9 #include "test/cctest/wasm/wasm-run-utils.h" | 9 #include "test/cctest/wasm/wasm-run-utils.h" |
10 | 10 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 T Xor(T a, T b) { | 206 T Xor(T a, T b) { |
207 return a ^ b; | 207 return a ^ b; |
208 } | 208 } |
209 | 209 |
210 template <typename T> | 210 template <typename T> |
211 T Not(T a) { | 211 T Not(T a) { |
212 return ~a; | 212 return ~a; |
213 } | 213 } |
214 | 214 |
215 template <typename T> | 215 template <typename T> |
| 216 T LogicalNot(T a) { |
| 217 return a == 0 ? 1 : 0; |
| 218 } |
| 219 |
| 220 template <typename T> |
216 T Sqrt(T a) { | 221 T Sqrt(T a) { |
217 return std::sqrt(a); | 222 return std::sqrt(a); |
218 } | 223 } |
219 | 224 |
220 } // namespace | 225 } // namespace |
221 | 226 |
222 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 | 227 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 |
223 #define SIMD_LOWERING_TARGET 1 | 228 #define SIMD_LOWERING_TARGET 1 |
224 #else | 229 #else |
225 #define SIMD_LOWERING_TARGET 0 | 230 #define SIMD_LOWERING_TARGET 0 |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ | 1338 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ |
1334 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ | 1339 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ |
1335 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ | 1340 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ |
1336 \ | 1341 \ |
1337 CHECK_EQ(1, r.Call(0x12, 0x34)); \ | 1342 CHECK_EQ(1, r.Call(0x12, 0x34)); \ |
1338 } | 1343 } |
1339 | 1344 |
1340 WASM_SIMD_SELECT_TEST(32x4) | 1345 WASM_SIMD_SELECT_TEST(32x4) |
1341 WASM_SIMD_SELECT_TEST(16x8) | 1346 WASM_SIMD_SELECT_TEST(16x8) |
1342 WASM_SIMD_SELECT_TEST(8x16) | 1347 WASM_SIMD_SELECT_TEST(8x16) |
| 1348 |
| 1349 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer |
| 1350 // result. Use relational ops on numeric vectors to create the boolean vector |
| 1351 // test inputs. Test inputs with all true, all false, one true, and one false. |
| 1352 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ |
| 1353 WASM_EXEC_TEST(ReductionTest##lanes) { \ |
| 1354 FLAG_wasm_simd_prototype = true; \ |
| 1355 WasmRunner<int32_t> r(kExecuteCompiled); \ |
| 1356 byte zero = r.AllocateLocal(kWasmS128); \ |
| 1357 byte one_one = r.AllocateLocal(kWasmS128); \ |
| 1358 byte reduced = r.AllocateLocal(kWasmI32); \ |
| 1359 BUILD(r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ |
| 1360 WASM_SET_LOCAL( \ |
| 1361 reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \ |
| 1362 WASM_SIMD_BINOP(kExprI##format##Eq, \ |
| 1363 WASM_GET_LOCAL(zero), \ |
| 1364 WASM_GET_LOCAL(zero)))), \ |
| 1365 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1366 WASM_RETURN1(WASM_ZERO)), \ |
| 1367 WASM_SET_LOCAL( \ |
| 1368 reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \ |
| 1369 WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 1370 WASM_GET_LOCAL(zero), \ |
| 1371 WASM_GET_LOCAL(zero)))), \ |
| 1372 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1373 WASM_RETURN1(WASM_ZERO)), \ |
| 1374 WASM_SET_LOCAL( \ |
| 1375 reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \ |
| 1376 WASM_SIMD_BINOP(kExprI##format##Eq, \ |
| 1377 WASM_GET_LOCAL(zero), \ |
| 1378 WASM_GET_LOCAL(zero)))), \ |
| 1379 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1380 WASM_RETURN1(WASM_ZERO)), \ |
| 1381 WASM_SET_LOCAL( \ |
| 1382 reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \ |
| 1383 WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 1384 WASM_GET_LOCAL(zero), \ |
| 1385 WASM_GET_LOCAL(zero)))), \ |
| 1386 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1387 WASM_RETURN1(WASM_ZERO)), \ |
| 1388 WASM_SET_LOCAL(one_one, \ |
| 1389 WASM_SIMD_I##format##_REPLACE_LANE( \ |
| 1390 lanes - 1, WASM_GET_LOCAL(zero), WASM_ONE)), \ |
| 1391 WASM_SET_LOCAL( \ |
| 1392 reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \ |
| 1393 WASM_SIMD_BINOP(kExprI##format##Eq, \ |
| 1394 WASM_GET_LOCAL(one_one), \ |
| 1395 WASM_GET_LOCAL(zero)))), \ |
| 1396 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1397 WASM_RETURN1(WASM_ZERO)), \ |
| 1398 WASM_SET_LOCAL( \ |
| 1399 reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \ |
| 1400 WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 1401 WASM_GET_LOCAL(one_one), \ |
| 1402 WASM_GET_LOCAL(zero)))), \ |
| 1403 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1404 WASM_RETURN1(WASM_ZERO)), \ |
| 1405 WASM_SET_LOCAL( \ |
| 1406 reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \ |
| 1407 WASM_SIMD_BINOP(kExprI##format##Eq, \ |
| 1408 WASM_GET_LOCAL(one_one), \ |
| 1409 WASM_GET_LOCAL(zero)))), \ |
| 1410 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1411 WASM_RETURN1(WASM_ZERO)), \ |
| 1412 WASM_SET_LOCAL( \ |
| 1413 reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \ |
| 1414 WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 1415 WASM_GET_LOCAL(one_one), \ |
| 1416 WASM_GET_LOCAL(zero)))), \ |
| 1417 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1418 WASM_RETURN1(WASM_ZERO)), \ |
| 1419 WASM_ONE); \ |
| 1420 CHECK_EQ(1, r.Call()); \ |
| 1421 } |
| 1422 |
| 1423 WASM_SIMD_BOOL_REDUCTION_TEST(32x4, 4) |
| 1424 WASM_SIMD_BOOL_REDUCTION_TEST(16x8, 8) |
| 1425 WASM_SIMD_BOOL_REDUCTION_TEST(8x16, 16) |
| 1426 |
| 1427 #define WASM_SIMD_UNOP_HELPER(format, lanes, lane_size) \ |
| 1428 void RunS1x##lanes##UnOpTest(WasmOpcode simd_op, \ |
| 1429 Int##lane_size##UnOp expected_op) { \ |
| 1430 FLAG_wasm_simd_prototype = true; \ |
| 1431 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \ |
| 1432 byte a = 0; \ |
| 1433 byte expected = 1; \ |
| 1434 byte zero = r.AllocateLocal(kWasmS128); \ |
| 1435 byte simd = r.AllocateLocal(kWasmS128); \ |
| 1436 BUILD( \ |
| 1437 r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ |
| 1438 WASM_SET_LOCAL(simd, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(a))), \ |
| 1439 WASM_SET_LOCAL( \ |
| 1440 simd, \ |
| 1441 WASM_SIMD_MATERIALIZE_BOOLS( \ |
| 1442 format, WASM_SIMD_UNOP( \ |
| 1443 simd_op, WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 1444 WASM_GET_LOCAL(simd), \ |
| 1445 WASM_GET_LOCAL(zero))))), \ |
| 1446 WASM_SIMD_CHECK_SPLAT##lanes(I##format, simd, I32, expected), \ |
| 1447 WASM_ONE); \ |
| 1448 \ |
| 1449 for (int i = 0; i <= 1; i++) { \ |
| 1450 CHECK_EQ(1, r.Call(i, expected_op(i))); \ |
| 1451 } \ |
| 1452 } |
| 1453 WASM_SIMD_UNOP_HELPER(32x4, 4, 32); |
| 1454 WASM_SIMD_UNOP_HELPER(16x8, 8, 16); |
| 1455 WASM_SIMD_UNOP_HELPER(8x16, 16, 8); |
| 1456 #undef WASM_SIMD_UNOP_HELPER |
| 1457 |
| 1458 WASM_EXEC_COMPILED_TEST(S1x4Not) { RunS1x4UnOpTest(kExprS1x4Not, LogicalNot); } |
| 1459 |
| 1460 WASM_EXEC_COMPILED_TEST(S1x8Not) { RunS1x8UnOpTest(kExprS1x8Not, LogicalNot); } |
| 1461 |
| 1462 WASM_EXEC_COMPILED_TEST(S1x16Not) { |
| 1463 RunS1x16UnOpTest(kExprS1x16Not, LogicalNot); |
| 1464 } |
| 1465 |
| 1466 #define WASM_SIMD_BINOP_HELPER(format, lanes, lane_size) \ |
| 1467 void RunS1x##lanes##BinOpTest(WasmOpcode simd_op, \ |
| 1468 Int##lane_size##BinOp expected_op) { \ |
| 1469 FLAG_wasm_simd_prototype = true; \ |
| 1470 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); \ |
| 1471 byte a = 0; \ |
| 1472 byte b = 1; \ |
| 1473 byte expected = 2; \ |
| 1474 byte zero = r.AllocateLocal(kWasmS128); \ |
| 1475 byte simd0 = r.AllocateLocal(kWasmS128); \ |
| 1476 byte simd1 = r.AllocateLocal(kWasmS128); \ |
| 1477 BUILD( \ |
| 1478 r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ |
| 1479 WASM_SET_LOCAL(simd0, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(a))), \ |
| 1480 WASM_SET_LOCAL(simd1, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(b))), \ |
| 1481 WASM_SET_LOCAL( \ |
| 1482 simd1, \ |
| 1483 WASM_SIMD_MATERIALIZE_BOOLS( \ |
| 1484 format, \ |
| 1485 WASM_SIMD_BINOP( \ |
| 1486 simd_op, \ |
| 1487 WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(simd0), \ |
| 1488 WASM_GET_LOCAL(zero)), \ |
| 1489 WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(simd1), \ |
| 1490 WASM_GET_LOCAL(zero))))), \ |
| 1491 WASM_SIMD_CHECK_SPLAT##lanes(I##format, simd1, I32, expected), \ |
| 1492 WASM_ONE); \ |
| 1493 \ |
| 1494 for (int i = 0; i <= 1; i++) { \ |
| 1495 for (int j = 0; j <= 1; j++) { \ |
| 1496 CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); \ |
| 1497 } \ |
| 1498 } \ |
| 1499 } |
| 1500 |
| 1501 WASM_SIMD_BINOP_HELPER(32x4, 4, 32); |
| 1502 WASM_SIMD_BINOP_HELPER(16x8, 8, 16); |
| 1503 WASM_SIMD_BINOP_HELPER(8x16, 16, 8); |
| 1504 #undef WASM_SIMD_BINOP_HELPER |
| 1505 |
| 1506 WASM_EXEC_COMPILED_TEST(S1x4And) { RunS1x4BinOpTest(kExprS1x4And, And); } |
| 1507 |
| 1508 WASM_EXEC_COMPILED_TEST(S1x4Or) { RunS1x4BinOpTest(kExprS1x4Or, Or); } |
| 1509 |
| 1510 WASM_EXEC_COMPILED_TEST(S1x4Xor) { RunS1x4BinOpTest(kExprS1x4Xor, Xor); } |
| 1511 |
| 1512 WASM_EXEC_COMPILED_TEST(S1x8And) { RunS1x8BinOpTest(kExprS1x8And, And); } |
| 1513 |
| 1514 WASM_EXEC_COMPILED_TEST(S1x8Or) { RunS1x8BinOpTest(kExprS1x8Or, Or); } |
| 1515 |
| 1516 WASM_EXEC_COMPILED_TEST(S1x8Xor) { RunS1x8BinOpTest(kExprS1x8Xor, Xor); } |
| 1517 |
| 1518 WASM_EXEC_COMPILED_TEST(S1x16And) { RunS1x16BinOpTest(kExprS1x16And, And); } |
| 1519 |
| 1520 WASM_EXEC_COMPILED_TEST(S1x16Or) { RunS1x16BinOpTest(kExprS1x16Or, Or); } |
| 1521 |
| 1522 WASM_EXEC_COMPILED_TEST(S1x16Xor) { RunS1x16BinOpTest(kExprS1x16Xor, Xor); } |
| 1523 |
1343 #endif // V8_TARGET_ARCH_ARM | 1524 #endif // V8_TARGET_ARCH_ARM |
1344 | 1525 |
1345 #if SIMD_LOWERING_TARGET | 1526 #if SIMD_LOWERING_TARGET |
1346 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { | 1527 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { |
1347 FLAG_wasm_simd_prototype = true; | 1528 FLAG_wasm_simd_prototype = true; |
1348 WasmRunner<int32_t> r(kExecuteCompiled); | 1529 WasmRunner<int32_t> r(kExecuteCompiled); |
1349 BUILD(r, WASM_IF_ELSE_I( | 1530 BUILD(r, WASM_IF_ELSE_I( |
1350 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( | 1531 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( |
1351 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), | 1532 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), |
1352 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), | 1533 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 1749 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
1569 WASM_F32(65.0))), | 1750 WASM_F32(65.0))), |
1570 WASM_I32V(1)); | 1751 WASM_I32V(1)); |
1571 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 1752 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
1572 CHECK_EQ(*global, 13.5); | 1753 CHECK_EQ(*global, 13.5); |
1573 CHECK_EQ(*(global + 1), 45.5); | 1754 CHECK_EQ(*(global + 1), 45.5); |
1574 CHECK_EQ(*(global + 2), 32.25); | 1755 CHECK_EQ(*(global + 2), 32.25); |
1575 CHECK_EQ(*(global + 3), 65.0); | 1756 CHECK_EQ(*(global + 3), 65.0); |
1576 } | 1757 } |
1577 #endif // SIMD_LOWERING_TARGET | 1758 #endif // SIMD_LOWERING_TARGET |
OLD | NEW |