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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 template <typename T> | 205 template <typename T> |
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> |
| 216 T LogicalNot(T a) { |
| 217 return a == 0 ? 1 : 0; |
| 218 } |
| 219 |
215 } // namespace | 220 } // namespace |
216 | 221 |
217 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 | 222 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 |
218 #define SIMD_LOWERING_TARGET 1 | 223 #define SIMD_LOWERING_TARGET 1 |
219 #else | 224 #else |
220 #define SIMD_LOWERING_TARGET 0 | 225 #define SIMD_LOWERING_TARGET 0 |
221 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 | 226 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 |
222 | 227 |
223 // TODO(gdeepti): These are tests using sample values to verify functional | 228 // TODO(gdeepti): These are tests using sample values to verify functional |
224 // correctness of opcodes, add more tests for a range of values and macroize | 229 // correctness of opcodes, add more tests for a range of values and macroize |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ | 1323 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ |
1319 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ | 1324 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ |
1320 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ | 1325 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ |
1321 \ | 1326 \ |
1322 CHECK_EQ(1, r.Call(0x12, 0x34)); \ | 1327 CHECK_EQ(1, r.Call(0x12, 0x34)); \ |
1323 } | 1328 } |
1324 | 1329 |
1325 WASM_SIMD_SELECT_TEST(32x4) | 1330 WASM_SIMD_SELECT_TEST(32x4) |
1326 WASM_SIMD_SELECT_TEST(16x8) | 1331 WASM_SIMD_SELECT_TEST(16x8) |
1327 WASM_SIMD_SELECT_TEST(8x16) | 1332 WASM_SIMD_SELECT_TEST(8x16) |
| 1333 |
| 1334 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer |
| 1335 // result. Use relational ops on numeric vectors to create the boolean vector |
| 1336 // test inputs. Test inputs with all true, all false, one true, and one false. |
| 1337 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ |
| 1338 WASM_EXEC_TEST(ReductionTest##lanes) { \ |
| 1339 FLAG_wasm_simd_prototype = true; \ |
| 1340 WasmRunner<int32_t> r(kExecuteCompiled); \ |
| 1341 byte zero = r.AllocateLocal(kWasmS128); \ |
| 1342 byte one_one = r.AllocateLocal(kWasmS128); \ |
| 1343 byte reduced = r.AllocateLocal(kWasmI32); \ |
| 1344 BUILD( \ |
| 1345 r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ |
| 1346 WASM_SET_LOCAL(reduced, \ |
| 1347 WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \ |
| 1348 WASM_SIMD_BINOP(kExprI##format##Eq, \ |
| 1349 WASM_GET_LOCAL(zero), \ |
| 1350 WASM_GET_LOCAL(zero)))), \ |
| 1351 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1352 WASM_RETURN1(WASM_ZERO)), \ |
| 1353 WASM_SET_LOCAL(reduced, \ |
| 1354 WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \ |
| 1355 WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 1356 WASM_GET_LOCAL(zero), \ |
| 1357 WASM_GET_LOCAL(zero)))), \ |
| 1358 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1359 WASM_RETURN1(WASM_ZERO)), \ |
| 1360 WASM_SET_LOCAL(reduced, \ |
| 1361 WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \ |
| 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(reduced, \ |
| 1368 WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \ |
| 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(one_one, \ |
| 1375 WASM_SIMD_I##format##_REPLACE_LANE( \ |
| 1376 lanes - 1, WASM_GET_LOCAL(zero), WASM_ONE)), \ |
| 1377 WASM_SET_LOCAL(reduced, \ |
| 1378 WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \ |
| 1379 WASM_SIMD_BINOP(kExprI##format##Eq, \ |
| 1380 WASM_GET_LOCAL(one_one), \ |
| 1381 WASM_GET_LOCAL(zero)))), \ |
| 1382 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1383 WASM_RETURN1(WASM_ZERO)), \ |
| 1384 WASM_SET_LOCAL(reduced, \ |
| 1385 WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \ |
| 1386 WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 1387 WASM_GET_LOCAL(one_one), \ |
| 1388 WASM_GET_LOCAL(zero)))), \ |
| 1389 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1390 WASM_RETURN1(WASM_ZERO)), \ |
| 1391 WASM_SET_LOCAL(reduced, \ |
| 1392 WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \ |
| 1393 WASM_SIMD_BINOP(kExprI##format##Eq, \ |
| 1394 WASM_GET_LOCAL(one_one), \ |
| 1395 WASM_GET_LOCAL(zero)))), \ |
| 1396 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1397 WASM_RETURN1(WASM_ZERO)), \ |
| 1398 WASM_SET_LOCAL(reduced, \ |
| 1399 WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \ |
| 1400 WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 1401 WASM_GET_LOCAL(one_one), \ |
| 1402 WASM_GET_LOCAL(zero)))), \ |
| 1403 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \ |
| 1404 WASM_RETURN1(WASM_ZERO)), \ |
| 1405 WASM_ONE); \ |
| 1406 CHECK_EQ(1, r.Call()); \ |
| 1407 } |
| 1408 |
| 1409 WASM_SIMD_BOOL_REDUCTION_TEST(32x4, 4) |
| 1410 WASM_SIMD_BOOL_REDUCTION_TEST(16x8, 8) |
| 1411 WASM_SIMD_BOOL_REDUCTION_TEST(8x16, 16) |
| 1412 |
| 1413 #define WASM_SIMD_UNOP_HELPER(format, lanes, lane_size) \ |
| 1414 void RunS1x##lanes##UnOpTest(WasmOpcode simd_op, \ |
| 1415 Int##lane_size##UnOp expected_op) { \ |
| 1416 FLAG_wasm_simd_prototype = true; \ |
| 1417 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \ |
| 1418 byte a = 0; \ |
| 1419 byte expected = 1; \ |
| 1420 byte zero = r.AllocateLocal(kWasmS128); \ |
| 1421 byte simd = r.AllocateLocal(kWasmS128); \ |
| 1422 BUILD( \ |
| 1423 r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ |
| 1424 WASM_SET_LOCAL(simd, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(a))), \ |
| 1425 WASM_SET_LOCAL( \ |
| 1426 simd, \ |
| 1427 WASM_SIMD_MATERIALIZE_BOOLS( \ |
| 1428 format, \ |
| 1429 WASM_SIMD_UNOP( \ |
| 1430 simd_op, \ |
| 1431 WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(simd), \ |
| 1432 WASM_GET_LOCAL(zero))))), \ |
| 1433 WASM_SIMD_CHECK_SPLAT##lanes(I##format, simd, I32, expected), \ |
| 1434 WASM_ONE); \ |
| 1435 \ |
| 1436 for (int i = 0; i <= 1; i++) { \ |
| 1437 CHECK_EQ(1, r.Call(i, expected_op(i))); \ |
| 1438 } \ |
| 1439 } |
| 1440 WASM_SIMD_UNOP_HELPER(32x4, 4, 32); |
| 1441 WASM_SIMD_UNOP_HELPER(16x8, 8, 16); |
| 1442 WASM_SIMD_UNOP_HELPER(8x16, 16, 8); |
| 1443 #undef WASM_SIMD_UNOP_HELPER |
| 1444 |
| 1445 WASM_EXEC_COMPILED_TEST(S1x4Not) { RunS1x4UnOpTest(kExprS1x4Not, LogicalNot); } |
| 1446 |
| 1447 WASM_EXEC_COMPILED_TEST(S1x8Not) { RunS1x8UnOpTest(kExprS1x8Not, LogicalNot); } |
| 1448 |
| 1449 WASM_EXEC_COMPILED_TEST(S1x16Not) { |
| 1450 RunS1x16UnOpTest(kExprS1x16Not, LogicalNot); |
| 1451 } |
| 1452 |
| 1453 #define WASM_SIMD_BINOP_HELPER(format, lanes, lane_size) \ |
| 1454 void RunS1x##lanes##BinOpTest(WasmOpcode simd_op, \ |
| 1455 Int##lane_size##BinOp expected_op) { \ |
| 1456 FLAG_wasm_simd_prototype = true; \ |
| 1457 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); \ |
| 1458 byte a = 0; \ |
| 1459 byte b = 1; \ |
| 1460 byte expected = 2; \ |
| 1461 byte zero = r.AllocateLocal(kWasmS128); \ |
| 1462 byte simd0 = r.AllocateLocal(kWasmS128); \ |
| 1463 byte simd1 = r.AllocateLocal(kWasmS128); \ |
| 1464 BUILD( \ |
| 1465 r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ |
| 1466 WASM_SET_LOCAL(simd0, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(a))), \ |
| 1467 WASM_SET_LOCAL(simd1, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(b))), \ |
| 1468 WASM_SET_LOCAL( \ |
| 1469 simd1, \ |
| 1470 WASM_SIMD_MATERIALIZE_BOOLS( \ |
| 1471 format, \ |
| 1472 WASM_SIMD_BINOP( \ |
| 1473 simd_op, \ |
| 1474 WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(simd0), \ |
| 1475 WASM_GET_LOCAL(zero)), \ |
| 1476 WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(simd1), \ |
| 1477 WASM_GET_LOCAL(zero))))), \ |
| 1478 WASM_SIMD_CHECK_SPLAT##lanes(I##format, simd1, I32, expected), \ |
| 1479 WASM_ONE); \ |
| 1480 \ |
| 1481 for (int i = 0; i <= 1; i++) { \ |
| 1482 for (int j = 0; j <= 1; j++) { \ |
| 1483 CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); \ |
| 1484 } \ |
| 1485 } \ |
| 1486 } |
| 1487 |
| 1488 WASM_SIMD_BINOP_HELPER(32x4, 4, 32); |
| 1489 WASM_SIMD_BINOP_HELPER(16x8, 8, 16); |
| 1490 WASM_SIMD_BINOP_HELPER(8x16, 16, 8); |
| 1491 #undef WASM_SIMD_BINOP_HELPER |
| 1492 |
| 1493 WASM_EXEC_COMPILED_TEST(S1x4And) { RunS1x4BinOpTest(kExprS1x4And, And); } |
| 1494 |
| 1495 WASM_EXEC_COMPILED_TEST(S1x4Or) { RunS1x4BinOpTest(kExprS1x4Or, Or); } |
| 1496 |
| 1497 WASM_EXEC_COMPILED_TEST(S1x4Xor) { RunS1x4BinOpTest(kExprS1x4Xor, Xor); } |
| 1498 |
| 1499 WASM_EXEC_COMPILED_TEST(S1x8And) { RunS1x8BinOpTest(kExprS1x8And, And); } |
| 1500 |
| 1501 WASM_EXEC_COMPILED_TEST(S1x8Or) { RunS1x8BinOpTest(kExprS1x8Or, Or); } |
| 1502 |
| 1503 WASM_EXEC_COMPILED_TEST(S1x8Xor) { RunS1x8BinOpTest(kExprS1x8Xor, Xor); } |
| 1504 |
| 1505 WASM_EXEC_COMPILED_TEST(S1x16And) { RunS1x16BinOpTest(kExprS1x16And, And); } |
| 1506 |
| 1507 WASM_EXEC_COMPILED_TEST(S1x16Or) { RunS1x16BinOpTest(kExprS1x16Or, Or); } |
| 1508 |
| 1509 WASM_EXEC_COMPILED_TEST(S1x16Xor) { RunS1x16BinOpTest(kExprS1x16Xor, Xor); } |
| 1510 |
1328 #endif // V8_TARGET_ARCH_ARM | 1511 #endif // V8_TARGET_ARCH_ARM |
1329 | 1512 |
1330 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 1513 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
1331 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { | 1514 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { |
1332 FLAG_wasm_simd_prototype = true; | 1515 FLAG_wasm_simd_prototype = true; |
1333 WasmRunner<int32_t> r(kExecuteCompiled); | 1516 WasmRunner<int32_t> r(kExecuteCompiled); |
1334 BUILD(r, WASM_IF_ELSE_I( | 1517 BUILD(r, WASM_IF_ELSE_I( |
1335 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( | 1518 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( |
1336 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), | 1519 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), |
1337 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), | 1520 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 1734 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
1552 WASM_F32(65.0))), | 1735 WASM_F32(65.0))), |
1553 WASM_I32V(1)); | 1736 WASM_I32V(1)); |
1554 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 1737 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
1555 CHECK_EQ(*global, 13.5); | 1738 CHECK_EQ(*global, 13.5); |
1556 CHECK_EQ(*(global + 1), 45.5); | 1739 CHECK_EQ(*(global + 1), 45.5); |
1557 CHECK_EQ(*(global + 2), 32.25); | 1740 CHECK_EQ(*(global + 2), 32.25); |
1558 CHECK_EQ(*(global + 3), 65.0); | 1741 CHECK_EQ(*(global + 3), 65.0); |
1559 } | 1742 } |
1560 #endif // SIMD_LOWERING_TARGET | 1743 #endif // SIMD_LOWERING_TARGET |
OLD | NEW |