Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: test/unittests/wasm/ast-decoder-unittest.cc

Issue 1682443002: [wasm] Put the condition last in kExprBrIf. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/wasm/test-run-wasm.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 17 matching lines...) Expand all
28 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), 28 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
29 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), 29 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
30 MachineType::Float64()}; 30 MachineType::Float64()};
31 31
32 static const WasmOpcode kInt32BinopOpcodes[] = { 32 static const WasmOpcode kInt32BinopOpcodes[] = {
33 kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU, 33 kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU,
34 kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor, 34 kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor,
35 kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS, 35 kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS,
36 kExprI32LeS, kExprI32LtU, kExprI32LeU}; 36 kExprI32LeS, kExprI32LtU, kExprI32LeU};
37 37
38 #define WASM_BRV_IF_ZERO(depth, val) \
39 kExprBrIf, static_cast<byte>(depth), val, WASM_ZERO
38 40
39 #define EXPECT_VERIFIES(env, x) Verify(kSuccess, env, x, x + arraysize(x)) 41 #define EXPECT_VERIFIES(env, x) Verify(kSuccess, env, x, x + arraysize(x))
40 42
41 #define EXPECT_FAILURE(env, x) Verify(kError, env, x, x + arraysize(x)) 43 #define EXPECT_FAILURE(env, x) Verify(kError, env, x, x + arraysize(x))
42 44
43 #define EXPECT_VERIFIES_INLINE(env, ...) \ 45 #define EXPECT_VERIFIES_INLINE(env, ...) \
44 do { \ 46 do { \
45 static byte code[] = {__VA_ARGS__}; \ 47 static byte code[] = {__VA_ARGS__}; \
46 Verify(kSuccess, env, code, code + arraysize(code)); \ 48 Verify(kSuccess, env, code, code + arraysize(code)); \
47 } while (false) 49 } while (false)
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 EXPECT_VERIFIES(&env_v_v, code); 1545 EXPECT_VERIFIES(&env_v_v, code);
1544 } else { 1546 } else {
1545 EXPECT_FAILURE(&env_v_v, code); 1547 EXPECT_FAILURE(&env_v_v, code);
1546 } 1548 }
1547 } 1549 }
1548 } 1550 }
1549 1551
1550 1552
1551 TEST_F(WasmDecoderTest, BreaksWithMultipleTypes) { 1553 TEST_F(WasmDecoderTest, BreaksWithMultipleTypes) {
1552 EXPECT_FAILURE_INLINE( 1554 EXPECT_FAILURE_INLINE(
1553 &env_i_i, 1555 &env_i_i, WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7)));
1554 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(7)), WASM_F32(7.7))); 1556
1555 EXPECT_FAILURE_INLINE(&env_i_i, 1557 EXPECT_FAILURE_INLINE(&env_i_i,
1556 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(7)), 1558 WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)),
1557 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7)))); 1559 WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
1558 EXPECT_FAILURE_INLINE(&env_i_i, 1560 EXPECT_FAILURE_INLINE(&env_i_i,
1559 WASM_BLOCK(3, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(8)), 1561 WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(8)),
1560 WASM_BRV_IF(0, WASM_ZERO, WASM_I8(0)), 1562 WASM_BRV_IF_ZERO(0, WASM_I8(0)),
1561 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7)))); 1563 WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
1562 EXPECT_FAILURE_INLINE(&env_i_i, 1564 EXPECT_FAILURE_INLINE(&env_i_i, WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(9)),
1563 WASM_BLOCK(3, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(9)), 1565 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
1564 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7)), 1566 WASM_BRV_IF_ZERO(0, WASM_I8(11))));
1565 WASM_BRV_IF(0, WASM_ZERO, WASM_I8(11))));
1566 } 1567 }
1567 1568
1568 1569
1569 TEST_F(WasmDecoderTest, BreakNesting_6_levels) { 1570 TEST_F(WasmDecoderTest, BreakNesting_6_levels) {
1570 for (int mask = 0; mask < 64; mask++) { 1571 for (int mask = 0; mask < 64; mask++) {
1571 for (int i = 0; i < 14; i++) { 1572 for (int i = 0; i < 14; i++) {
1572 byte code[] = { 1573 byte code[] = {
1573 kExprBlock, 1, // -- 1574 kExprBlock, 1, // --
1574 kExprBlock, 1, // -- 1575 kExprBlock, 1, // --
1575 kExprBlock, 1, // -- 1576 kExprBlock, 1, // --
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 &env_d_dd, 1619 &env_d_dd,
1619 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1620 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1620 WASM_F64(1.2))); 1621 WASM_F64(1.2)));
1621 } 1622 }
1622 1623
1623 1624
1624 TEST_F(WasmDecoderTest, ExprBreak_TypeCheckAll) { 1625 TEST_F(WasmDecoderTest, ExprBreak_TypeCheckAll) {
1625 byte code1[] = {WASM_BLOCK(2, 1626 byte code1[] = {WASM_BLOCK(2,
1626 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1627 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1627 WASM_GET_LOCAL(1))}; 1628 WASM_GET_LOCAL(1))};
1628 byte code2[] = {WASM_BLOCK( 1629 byte code2[] = {
1629 2, WASM_IF(WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_GET_LOCAL(0))), 1630 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))),
1630 WASM_GET_LOCAL(1))}; 1631 WASM_GET_LOCAL(1))};
1631
1632 1632
1633 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1633 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1634 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 1634 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1635 FunctionEnv env; 1635 FunctionEnv env;
1636 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; 1636 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]};
1637 FunctionSig sig(1, 2, storage); 1637 FunctionSig sig(1, 2, storage);
1638 init_env(&env, &sig); 1638 init_env(&env, &sig);
1639 1639
1640 if (i == j) { 1640 if (i == j) {
1641 EXPECT_VERIFIES(&env, code1); 1641 EXPECT_VERIFIES(&env, code1);
(...skipping 29 matching lines...) Expand all
1671 EXPECT_VERIFIES(&env, code1); 1671 EXPECT_VERIFIES(&env, code1);
1672 EXPECT_VERIFIES(&env, code2); 1672 EXPECT_VERIFIES(&env, code2);
1673 } else { 1673 } else {
1674 EXPECT_FAILURE(&env, code1); 1674 EXPECT_FAILURE(&env, code1);
1675 EXPECT_FAILURE(&env, code2); 1675 EXPECT_FAILURE(&env, code2);
1676 } 1676 }
1677 } 1677 }
1678 } 1678 }
1679 } 1679 }
1680 1680
1681 TEST_F(WasmDecoderTest, ExprBrIf_cond_type) {
1682 FunctionEnv env;
1683 byte code[] = {
1684 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))};
1685 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1686 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1687 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]};
1688 FunctionSig sig(0, 2, types);
1689 init_env(&env, &sig);
1681 1690
1682 TEST_F(WasmDecoderTest, ExprBrIf_type) { 1691 if (types[1] == kAstI32) {
1683 EXPECT_VERIFIES_INLINE( 1692 EXPECT_VERIFIES(&env, code);
1684 &env_i_i, 1693 } else {
1685 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)), 1694 EXPECT_FAILURE(&env, code);
1686 WASM_GET_LOCAL(0))); 1695 }
1687 EXPECT_FAILURE_INLINE(
1688 &env_d_dd,
1689 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)),
1690 WASM_GET_LOCAL(0)));
1691
1692 FunctionEnv env;
1693 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1694 LocalType type = kLocalTypes[i];
1695 LocalType storage[] = {kAstI32, kAstI32, type};
1696 FunctionSig sig(1, 2, storage);
1697 init_env(&env, &sig); // (i32, X) -> i32
1698
1699 byte code1[] = {
1700 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
1701 WASM_GET_LOCAL(0))};
1702
1703 byte code2[] = {
1704 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)),
1705 WASM_GET_LOCAL(0))};
1706 if (type == kAstI32) {
1707 EXPECT_VERIFIES(&env, code1);
1708 EXPECT_VERIFIES(&env, code2);
1709 } else {
1710 EXPECT_FAILURE(&env, code1);
1711 EXPECT_FAILURE(&env, code2);
1712 } 1696 }
1713 } 1697 }
1714 } 1698 }
1699
1700 TEST_F(WasmDecoderTest, ExprBrIf_val_type) {
1701 FunctionEnv env;
1702 byte code[] = {
1703 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)),
1704 WASM_GET_LOCAL(0))};
1705 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1706 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1707 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j],
1708 kAstI32};
1709 FunctionSig sig(1, 3, types);
1710 init_env(&env, &sig);
1711
1712 if (i == j) {
1713 EXPECT_VERIFIES(&env, code);
1714 } else {
1715 EXPECT_FAILURE(&env, code);
1716 }
1717 }
1718 }
1719 }
1715 1720
1716 1721
1717 TEST_F(WasmDecoderTest, ExprBrIf_Unify) { 1722 TEST_F(WasmDecoderTest, ExprBrIf_Unify) {
1718 FunctionEnv env; 1723 FunctionEnv env;
1719 1724
1720 for (int which = 0; which < 2; which++) { 1725 for (int which = 0; which < 2; which++) {
1721 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1726 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1722 LocalType type = kLocalTypes[i]; 1727 LocalType type = kLocalTypes[i];
1723 LocalType storage[] = {kAstI32, kAstI32, type}; 1728 LocalType storage[] = {kAstI32, kAstI32, type};
1724 FunctionSig sig(1, 2, storage); 1729 FunctionSig sig(1, 2, storage);
1725 init_env(&env, &sig); // (i32, X) -> i32 1730 init_env(&env, &sig); // (i32, X) -> i32
1726 1731
1727 byte code1[] = { 1732 byte code1[] = {WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)),
1728 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_ZERO, WASM_GET_LOCAL(which)), 1733 WASM_GET_LOCAL(which ^ 1))};
1729 WASM_GET_LOCAL(which ^ 1))}; 1734 byte code2[] = {WASM_LOOP(2, WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)),
1730 byte code2[] = { 1735 WASM_GET_LOCAL(which ^ 1))};
1731 WASM_LOOP(2, WASM_BRV_IF(1, WASM_ZERO, WASM_GET_LOCAL(which)),
1732 WASM_GET_LOCAL(which ^ 1))};
1733
1734 1736
1735 if (type == kAstI32) { 1737 if (type == kAstI32) {
1736 EXPECT_VERIFIES(&env, code1); 1738 EXPECT_VERIFIES(&env, code1);
1737 EXPECT_VERIFIES(&env, code2); 1739 EXPECT_VERIFIES(&env, code2);
1738 } else { 1740 } else {
1739 EXPECT_FAILURE(&env, code1); 1741 EXPECT_FAILURE(&env, code1);
1740 EXPECT_FAILURE(&env, code2); 1742 EXPECT_FAILURE(&env, code2);
1741 } 1743 }
1742 } 1744 }
1743 } 1745 }
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
2416 EXPECT_ARITY(1, kExprF64SConvertI64); 2418 EXPECT_ARITY(1, kExprF64SConvertI64);
2417 EXPECT_ARITY(1, kExprF64UConvertI64); 2419 EXPECT_ARITY(1, kExprF64UConvertI64);
2418 EXPECT_ARITY(1, kExprF64ConvertF32); 2420 EXPECT_ARITY(1, kExprF64ConvertF32);
2419 EXPECT_ARITY(1, kExprF64ReinterpretI64); 2421 EXPECT_ARITY(1, kExprF64ReinterpretI64);
2420 EXPECT_ARITY(1, kExprI32ReinterpretF32); 2422 EXPECT_ARITY(1, kExprI32ReinterpretF32);
2421 EXPECT_ARITY(1, kExprI64ReinterpretF64); 2423 EXPECT_ARITY(1, kExprI64ReinterpretF64);
2422 } 2424 }
2423 } // namespace wasm 2425 } // namespace wasm
2424 } // namespace internal 2426 } // namespace internal
2425 } // namespace v8 2427 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698