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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 WASM_GET_LOCAL(new_val))), | 679 WASM_GET_LOCAL(new_val))), |
680 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, old_val), | 680 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, old_val), |
681 WASM_SET_LOCAL(simd, | 681 WASM_SET_LOCAL(simd, |
682 WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), | 682 WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), |
683 WASM_GET_LOCAL(new_val))), | 683 WASM_GET_LOCAL(new_val))), |
684 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), WASM_ONE); | 684 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), WASM_ONE); |
685 | 685 |
686 CHECK_EQ(1, r.Call(1, 2)); | 686 CHECK_EQ(1, r.Call(1, 2)); |
687 } | 687 } |
688 | 688 |
689 #if V8_TARGET_ARCH_ARM | 689 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
690 | |
691 WASM_EXEC_COMPILED_TEST(I16x8Splat) { | 690 WASM_EXEC_COMPILED_TEST(I16x8Splat) { |
692 FLAG_wasm_simd_prototype = true; | 691 FLAG_wasm_simd_prototype = true; |
693 | 692 |
694 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 693 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
695 byte lane_val = 0; | 694 byte lane_val = 0; |
696 byte simd = r.AllocateLocal(kWasmS128); | 695 byte simd = r.AllocateLocal(kWasmS128); |
697 BUILD(r, | 696 BUILD(r, |
698 WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(lane_val))), | 697 WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(lane_val))), |
699 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, lane_val), WASM_ONE); | 698 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, lane_val), WASM_ONE); |
700 | 699 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 WASM_GET_LOCAL(new_val))), | 742 WASM_GET_LOCAL(new_val))), |
744 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val, | 743 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val, |
745 new_val, new_val, new_val, old_val), | 744 new_val, new_val, new_val, old_val), |
746 WASM_SET_LOCAL(simd, | 745 WASM_SET_LOCAL(simd, |
747 WASM_SIMD_I16x8_REPLACE_LANE(7, WASM_GET_LOCAL(simd), | 746 WASM_SIMD_I16x8_REPLACE_LANE(7, WASM_GET_LOCAL(simd), |
748 WASM_GET_LOCAL(new_val))), | 747 WASM_GET_LOCAL(new_val))), |
749 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, new_val), WASM_ONE); | 748 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, new_val), WASM_ONE); |
750 | 749 |
751 CHECK_EQ(1, r.Call(1, 2)); | 750 CHECK_EQ(1, r.Call(1, 2)); |
752 } | 751 } |
| 752 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
753 | 753 |
| 754 #if V8_TARGET_ARCH_ARM |
754 WASM_EXEC_COMPILED_TEST(I8x16Splat) { | 755 WASM_EXEC_COMPILED_TEST(I8x16Splat) { |
755 FLAG_wasm_simd_prototype = true; | 756 FLAG_wasm_simd_prototype = true; |
756 | 757 |
757 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 758 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
758 byte lane_val = 0; | 759 byte lane_val = 0; |
759 byte simd = r.AllocateLocal(kWasmS128); | 760 byte simd = r.AllocateLocal(kWasmS128); |
760 BUILD(r, | 761 BUILD(r, |
761 WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(lane_val))), | 762 WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(lane_val))), |
762 WASM_SIMD_CHECK_SPLAT8(I8x16, simd, I32, lane_val), WASM_ONE); | 763 WASM_SIMD_CHECK_SPLAT8(I8x16, simd, I32, lane_val), WASM_ONE); |
763 | 764 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 WASM_SIMD_CHECK_SPLAT8(I16x8, simd2, I32, packed_unsigned), WASM_ONE); | 1198 WASM_SIMD_CHECK_SPLAT8(I16x8, simd2, I32, packed_unsigned), WASM_ONE); |
1198 | 1199 |
1199 FOR_INT32_INPUTS(i) { | 1200 FOR_INT32_INPUTS(i) { |
1200 int32_t packed_signed = Narrow<int16_t>(*i); | 1201 int32_t packed_signed = Narrow<int16_t>(*i); |
1201 int32_t packed_unsigned = UnsignedNarrow<int16_t>(*i); | 1202 int32_t packed_unsigned = UnsignedNarrow<int16_t>(*i); |
1202 // Sign-extend here, since ExtractLane sign extends. | 1203 // Sign-extend here, since ExtractLane sign extends. |
1203 if (packed_unsigned & 0x8000) packed_unsigned |= 0xffff0000; | 1204 if (packed_unsigned & 0x8000) packed_unsigned |= 0xffff0000; |
1204 CHECK_EQ(1, r.Call(*i, packed_signed, packed_unsigned)); | 1205 CHECK_EQ(1, r.Call(*i, packed_signed, packed_unsigned)); |
1205 } | 1206 } |
1206 } | 1207 } |
| 1208 #endif // V8_TARGET_ARCH_ARM |
1207 | 1209 |
| 1210 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1208 void RunI16x8BinOpTest(WasmOpcode simd_op, Int16BinOp expected_op) { | 1211 void RunI16x8BinOpTest(WasmOpcode simd_op, Int16BinOp expected_op) { |
1209 FLAG_wasm_simd_prototype = true; | 1212 FLAG_wasm_simd_prototype = true; |
1210 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); | 1213 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); |
1211 byte a = 0; | 1214 byte a = 0; |
1212 byte b = 1; | 1215 byte b = 1; |
1213 byte expected = 2; | 1216 byte expected = 2; |
1214 byte simd0 = r.AllocateLocal(kWasmS128); | 1217 byte simd0 = r.AllocateLocal(kWasmS128); |
1215 byte simd1 = r.AllocateLocal(kWasmS128); | 1218 byte simd1 = r.AllocateLocal(kWasmS128); |
1216 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), | 1219 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), |
1217 WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))), | 1220 WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 FOR_INT16_INPUTS(i) { | 1284 FOR_INT16_INPUTS(i) { |
1282 FOR_INT16_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } | 1285 FOR_INT16_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } |
1283 } | 1286 } |
1284 } | 1287 } |
1285 | 1288 |
1286 WASM_EXEC_COMPILED_TEST(I16x8Eq) { RunI16x8CompareOpTest(kExprI16x8Eq, Equal); } | 1289 WASM_EXEC_COMPILED_TEST(I16x8Eq) { RunI16x8CompareOpTest(kExprI16x8Eq, Equal); } |
1287 | 1290 |
1288 WASM_EXEC_COMPILED_TEST(I16x8Ne) { | 1291 WASM_EXEC_COMPILED_TEST(I16x8Ne) { |
1289 RunI16x8CompareOpTest(kExprI16x8Ne, NotEqual); | 1292 RunI16x8CompareOpTest(kExprI16x8Ne, NotEqual); |
1290 } | 1293 } |
| 1294 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1291 | 1295 |
| 1296 #if V8_TARGET_ARCH_ARM |
1292 WASM_EXEC_COMPILED_TEST(I16x8LtS) { | 1297 WASM_EXEC_COMPILED_TEST(I16x8LtS) { |
1293 RunI16x8CompareOpTest(kExprI16x8LtS, Less); | 1298 RunI16x8CompareOpTest(kExprI16x8LtS, Less); |
1294 } | 1299 } |
1295 | 1300 |
1296 WASM_EXEC_COMPILED_TEST(I16x8LeS) { | 1301 WASM_EXEC_COMPILED_TEST(I16x8LeS) { |
1297 RunI16x8CompareOpTest(kExprI16x8LeS, LessEqual); | 1302 RunI16x8CompareOpTest(kExprI16x8LeS, LessEqual); |
1298 } | 1303 } |
1299 | 1304 |
1300 WASM_EXEC_COMPILED_TEST(I16x8GtS) { | 1305 WASM_EXEC_COMPILED_TEST(I16x8GtS) { |
1301 RunI16x8CompareOpTest(kExprI16x8GtS, Greater); | 1306 RunI16x8CompareOpTest(kExprI16x8GtS, Greater); |
(...skipping 11 matching lines...) Expand all Loading... |
1313 RunI16x8CompareOpTest(kExprI16x8GeU, UnsignedGreaterEqual); | 1318 RunI16x8CompareOpTest(kExprI16x8GeU, UnsignedGreaterEqual); |
1314 } | 1319 } |
1315 | 1320 |
1316 WASM_EXEC_COMPILED_TEST(I16x8LtU) { | 1321 WASM_EXEC_COMPILED_TEST(I16x8LtU) { |
1317 RunI16x8CompareOpTest(kExprI16x8LtU, UnsignedLess); | 1322 RunI16x8CompareOpTest(kExprI16x8LtU, UnsignedLess); |
1318 } | 1323 } |
1319 | 1324 |
1320 WASM_EXEC_COMPILED_TEST(I16x8LeU) { | 1325 WASM_EXEC_COMPILED_TEST(I16x8LeU) { |
1321 RunI16x8CompareOpTest(kExprI16x8LeU, UnsignedLessEqual); | 1326 RunI16x8CompareOpTest(kExprI16x8LeU, UnsignedLessEqual); |
1322 } | 1327 } |
| 1328 #endif // V8_TARGET_ARCH_ARM |
1323 | 1329 |
| 1330 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1324 void RunI16x8ShiftOpTest(WasmOpcode simd_op, Int16ShiftOp expected_op, | 1331 void RunI16x8ShiftOpTest(WasmOpcode simd_op, Int16ShiftOp expected_op, |
1325 int shift) { | 1332 int shift) { |
1326 FLAG_wasm_simd_prototype = true; | 1333 FLAG_wasm_simd_prototype = true; |
1327 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 1334 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
1328 byte a = 0; | 1335 byte a = 0; |
1329 byte expected = 1; | 1336 byte expected = 1; |
1330 byte simd = r.AllocateLocal(kWasmS128); | 1337 byte simd = r.AllocateLocal(kWasmS128); |
1331 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), | 1338 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), |
1332 WASM_SET_LOCAL( | 1339 WASM_SET_LOCAL( |
1333 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), | 1340 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), |
1334 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE); | 1341 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE); |
1335 | 1342 |
1336 FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } | 1343 FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } |
1337 } | 1344 } |
1338 | 1345 |
1339 WASM_EXEC_COMPILED_TEST(I16x8Shl) { | 1346 WASM_EXEC_COMPILED_TEST(I16x8Shl) { |
1340 RunI16x8ShiftOpTest(kExprI16x8Shl, LogicalShiftLeft, 1); | 1347 RunI16x8ShiftOpTest(kExprI16x8Shl, LogicalShiftLeft, 1); |
1341 } | 1348 } |
1342 | 1349 |
1343 WASM_EXEC_COMPILED_TEST(I16x8ShrS) { | 1350 WASM_EXEC_COMPILED_TEST(I16x8ShrS) { |
1344 RunI16x8ShiftOpTest(kExprI16x8ShrS, ArithmeticShiftRight, 1); | 1351 RunI16x8ShiftOpTest(kExprI16x8ShrS, ArithmeticShiftRight, 1); |
1345 } | 1352 } |
1346 | 1353 |
1347 WASM_EXEC_COMPILED_TEST(I16x8ShrU) { | 1354 WASM_EXEC_COMPILED_TEST(I16x8ShrU) { |
1348 RunI16x8ShiftOpTest(kExprI16x8ShrU, LogicalShiftRight, 1); | 1355 RunI16x8ShiftOpTest(kExprI16x8ShrU, LogicalShiftRight, 1); |
1349 } | 1356 } |
| 1357 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1350 | 1358 |
| 1359 #if V8_TARGET_ARCH_ARM |
1351 void RunI8x16UnOpTest(WasmOpcode simd_op, Int8UnOp expected_op) { | 1360 void RunI8x16UnOpTest(WasmOpcode simd_op, Int8UnOp expected_op) { |
1352 FLAG_wasm_simd_prototype = true; | 1361 FLAG_wasm_simd_prototype = true; |
1353 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 1362 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
1354 byte a = 0; | 1363 byte a = 0; |
1355 byte expected = 1; | 1364 byte expected = 1; |
1356 byte simd = r.AllocateLocal(kWasmS128); | 1365 byte simd = r.AllocateLocal(kWasmS128); |
1357 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))), | 1366 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))), |
1358 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), | 1367 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), |
1359 WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected), WASM_ONE); | 1368 WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected), WASM_ONE); |
1360 | 1369 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ | 1579 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ |
1571 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ | 1580 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ |
1572 \ | 1581 \ |
1573 CHECK_EQ(1, r.Call(0x12, 0x34)); \ | 1582 CHECK_EQ(1, r.Call(0x12, 0x34)); \ |
1574 } | 1583 } |
1575 | 1584 |
1576 WASM_SIMD_SELECT_TEST(32x4) | 1585 WASM_SIMD_SELECT_TEST(32x4) |
1577 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_MIPS || | 1586 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_MIPS || |
1578 // V8_TARGET_ARCH_MIPS64 | 1587 // V8_TARGET_ARCH_MIPS64 |
1579 | 1588 |
| 1589 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
| 1590 WASM_SIMD_SELECT_TEST(16x8) |
| 1591 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
| 1592 |
1580 #if V8_TARGET_ARCH_ARM | 1593 #if V8_TARGET_ARCH_ARM |
1581 WASM_SIMD_SELECT_TEST(16x8) | |
1582 WASM_SIMD_SELECT_TEST(8x16) | 1594 WASM_SIMD_SELECT_TEST(8x16) |
1583 | 1595 |
1584 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer | 1596 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer |
1585 // result. Use relational ops on numeric vectors to create the boolean vector | 1597 // result. Use relational ops on numeric vectors to create the boolean vector |
1586 // test inputs. Test inputs with all true, all false, one true, and one false. | 1598 // test inputs. Test inputs with all true, all false, one true, and one false. |
1587 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ | 1599 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ |
1588 WASM_EXEC_TEST(ReductionTest##lanes) { \ | 1600 WASM_EXEC_TEST(ReductionTest##lanes) { \ |
1589 FLAG_wasm_simd_prototype = true; \ | 1601 FLAG_wasm_simd_prototype = true; \ |
1590 WasmRunner<int32_t> r(kExecuteCompiled); \ | 1602 WasmRunner<int32_t> r(kExecuteCompiled); \ |
1591 byte zero = r.AllocateLocal(kWasmS128); \ | 1603 byte zero = r.AllocateLocal(kWasmS128); \ |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 WASM_SIMD_I32x4_EXTRACT_LANE( | 2011 WASM_SIMD_I32x4_EXTRACT_LANE( |
2000 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); | 2012 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); |
2001 | 2013 |
2002 FOR_INT32_INPUTS(i) { | 2014 FOR_INT32_INPUTS(i) { |
2003 int32_t expected = *i; | 2015 int32_t expected = *i; |
2004 r.module().WriteMemory(&memory[0], expected); | 2016 r.module().WriteMemory(&memory[0], expected); |
2005 CHECK_EQ(expected, r.Call()); | 2017 CHECK_EQ(expected, r.Call()); |
2006 } | 2018 } |
2007 } | 2019 } |
2008 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 2020 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
OLD | NEW |