OLD | NEW |
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/wasm/wasm-macro-gen.h" | 7 #include "src/wasm/wasm-macro-gen.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 TEST_F(WasmMacroGenTest, Statements) { | 50 TEST_F(WasmMacroGenTest, Statements) { |
51 EXPECT_SIZE(1, WASM_NOP); | 51 EXPECT_SIZE(1, WASM_NOP); |
52 | 52 |
53 EXPECT_SIZE(4, WASM_SET_LOCAL(0, WASM_ZERO)); | 53 EXPECT_SIZE(4, WASM_SET_LOCAL(0, WASM_ZERO)); |
54 | 54 |
55 EXPECT_SIZE(4, WASM_SET_GLOBAL(0, WASM_ZERO)); | 55 EXPECT_SIZE(4, WASM_SET_GLOBAL(0, WASM_ZERO)); |
56 | 56 |
57 EXPECT_SIZE(7, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, WASM_ZERO)); | 57 EXPECT_SIZE(7, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, WASM_ZERO)); |
58 | 58 |
59 EXPECT_SIZE(5, WASM_IF(WASM_ZERO, WASM_NOP)); | 59 EXPECT_SIZE(6, WASM_IF(WASM_ZERO, WASM_NOP)); |
60 | 60 |
61 EXPECT_SIZE(7, WASM_IF_ELSE(WASM_ZERO, WASM_NOP, WASM_NOP)); | 61 EXPECT_SIZE(8, WASM_IF_ELSE(WASM_ZERO, WASM_NOP, WASM_NOP)); |
62 | 62 |
63 EXPECT_SIZE(5, WASM_SELECT(WASM_ZERO, WASM_NOP, WASM_NOP)); | 63 EXPECT_SIZE(5, WASM_SELECT(WASM_ZERO, WASM_NOP, WASM_NOP)); |
64 | 64 |
65 EXPECT_SIZE(3, WASM_BR(0)); | 65 EXPECT_SIZE(2, WASM_BR(0)); |
66 EXPECT_SIZE(5, WASM_BR_IF(0, WASM_ZERO)); | 66 EXPECT_SIZE(4, WASM_BR_IF(0, WASM_ZERO)); |
67 | 67 |
68 EXPECT_SIZE(3, WASM_BLOCK(WASM_NOP)); | 68 EXPECT_SIZE(4, WASM_BLOCK(WASM_NOP)); |
69 EXPECT_SIZE(4, WASM_BLOCK(WASM_NOP, WASM_NOP)); | 69 EXPECT_SIZE(5, WASM_BLOCK(WASM_NOP, WASM_NOP)); |
70 EXPECT_SIZE(5, WASM_BLOCK(WASM_NOP, WASM_NOP, WASM_NOP)); | 70 EXPECT_SIZE(6, WASM_BLOCK(WASM_NOP, WASM_NOP, WASM_NOP)); |
71 | 71 |
72 EXPECT_SIZE(5, WASM_INFINITE_LOOP); | 72 EXPECT_SIZE(5, WASM_INFINITE_LOOP); |
73 | 73 |
74 EXPECT_SIZE(3, WASM_LOOP(WASM_NOP)); | 74 EXPECT_SIZE(4, WASM_LOOP(WASM_NOP)); |
75 EXPECT_SIZE(4, WASM_LOOP(WASM_NOP, WASM_NOP)); | 75 EXPECT_SIZE(5, WASM_LOOP(WASM_NOP, WASM_NOP)); |
76 EXPECT_SIZE(5, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); | 76 EXPECT_SIZE(6, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); |
77 EXPECT_SIZE(5, WASM_LOOP(WASM_BR(0))); | 77 EXPECT_SIZE(5, WASM_LOOP(WASM_BR(0))); |
78 EXPECT_SIZE(7, WASM_LOOP(WASM_BR_IF(0, WASM_ZERO))); | 78 EXPECT_SIZE(7, WASM_LOOP(WASM_BR_IF(0, WASM_ZERO))); |
79 | 79 |
80 EXPECT_SIZE(2, WASM_RETURN0); | 80 EXPECT_SIZE(1, WASM_RETURN0); |
81 EXPECT_SIZE(4, WASM_RETURN1(WASM_ZERO)); | 81 EXPECT_SIZE(3, WASM_RETURN1(WASM_ZERO)); |
82 | 82 |
83 EXPECT_SIZE(1, WASM_UNREACHABLE); | 83 EXPECT_SIZE(1, WASM_UNREACHABLE); |
84 } | 84 } |
85 | 85 |
86 TEST_F(WasmMacroGenTest, MacroStatements) { | 86 TEST_F(WasmMacroGenTest, MacroStatements) { |
87 EXPECT_SIZE(10, WASM_WHILE(WASM_I8(0), WASM_NOP)); | 87 EXPECT_SIZE(11, WASM_WHILE(WASM_I8(0), WASM_NOP)); |
88 EXPECT_SIZE(7, WASM_INC_LOCAL(0)); | 88 EXPECT_SIZE(7, WASM_INC_LOCAL(0)); |
89 EXPECT_SIZE(7, WASM_INC_LOCAL_BY(0, 3)); | 89 EXPECT_SIZE(7, WASM_INC_LOCAL_BY(0, 3)); |
90 | 90 |
91 EXPECT_SIZE(3, WASM_BREAK(0)); | 91 EXPECT_SIZE(2, WASM_CONTINUE(0)); |
92 EXPECT_SIZE(3, WASM_CONTINUE(0)); | |
93 } | 92 } |
94 | 93 |
95 TEST_F(WasmMacroGenTest, BrTable) { | 94 TEST_F(WasmMacroGenTest, BrTable) { |
96 EXPECT_SIZE(9, WASM_BR_TABLE(WASM_ZERO, 1, BR_TARGET(1))); | 95 EXPECT_SIZE(5, WASM_BR_TABLE(WASM_ZERO, 1, BR_TARGET(0))); |
97 EXPECT_SIZE(11, WASM_BR_TABLEV(WASM_ZERO, WASM_ZERO, 1, BR_TARGET(1))); | 96 EXPECT_SIZE(6, WASM_BR_TABLE(WASM_ZERO, 2, BR_TARGET(0), BR_TARGET(0))); |
98 } | 97 } |
99 | 98 |
100 TEST_F(WasmMacroGenTest, Expressions) { | 99 TEST_F(WasmMacroGenTest, Expressions) { |
101 EXPECT_SIZE(2, WASM_GET_LOCAL(0)); | 100 EXPECT_SIZE(2, WASM_GET_LOCAL(0)); |
102 EXPECT_SIZE(2, WASM_GET_LOCAL(1)); | 101 EXPECT_SIZE(2, WASM_GET_LOCAL(1)); |
103 EXPECT_SIZE(2, WASM_GET_LOCAL(12)); | 102 EXPECT_SIZE(2, WASM_GET_LOCAL(12)); |
104 EXPECT_SIZE(2, WASM_GET_GLOBAL(0)); | 103 EXPECT_SIZE(2, WASM_GET_GLOBAL(0)); |
105 EXPECT_SIZE(2, WASM_GET_GLOBAL(1)); | 104 EXPECT_SIZE(2, WASM_GET_GLOBAL(1)); |
106 EXPECT_SIZE(2, WASM_GET_GLOBAL(12)); | 105 EXPECT_SIZE(2, WASM_GET_GLOBAL(12)); |
107 EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)); | 106 EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)); |
108 EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)); | 107 EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)); |
109 EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)); | 108 EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)); |
110 | 109 |
111 EXPECT_SIZE(3, WASM_NOT(WASM_ZERO)); | 110 EXPECT_SIZE(3, WASM_NOT(WASM_ZERO)); |
112 | 111 |
113 EXPECT_SIZE(5, WASM_BRV(1, WASM_ZERO)); | 112 EXPECT_SIZE(4, WASM_BRV(1, WASM_ZERO)); |
114 EXPECT_SIZE(7, WASM_BRV_IF(1, WASM_ZERO, WASM_ZERO)); | 113 EXPECT_SIZE(6, WASM_BRV_IF(1, WASM_ZERO, WASM_ZERO)); |
115 | 114 |
116 EXPECT_SIZE(4, WASM_BLOCK(WASM_ZERO)); | 115 EXPECT_SIZE(5, WASM_BLOCK(WASM_ZERO)); |
117 EXPECT_SIZE(5, WASM_BLOCK(WASM_NOP, WASM_ZERO)); | 116 EXPECT_SIZE(6, WASM_BLOCK(WASM_NOP, WASM_ZERO)); |
118 EXPECT_SIZE(6, WASM_BLOCK(WASM_NOP, WASM_NOP, WASM_ZERO)); | 117 EXPECT_SIZE(7, WASM_BLOCK(WASM_NOP, WASM_NOP, WASM_ZERO)); |
119 | 118 |
120 EXPECT_SIZE(4, WASM_LOOP(WASM_ZERO)); | 119 EXPECT_SIZE(5, WASM_LOOP(WASM_ZERO)); |
121 EXPECT_SIZE(5, WASM_LOOP(WASM_NOP, WASM_ZERO)); | 120 EXPECT_SIZE(6, WASM_LOOP(WASM_NOP, WASM_ZERO)); |
122 EXPECT_SIZE(6, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_ZERO)); | 121 EXPECT_SIZE(7, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_ZERO)); |
123 } | 122 } |
124 | 123 |
125 TEST_F(WasmMacroGenTest, CallFunction) { | 124 TEST_F(WasmMacroGenTest, CallFunction) { |
126 EXPECT_SIZE(3, WASM_CALL_FUNCTION0(0)); | 125 EXPECT_SIZE(2, WASM_CALL_FUNCTION0(0)); |
127 EXPECT_SIZE(3, WASM_CALL_FUNCTION0(1)); | 126 EXPECT_SIZE(2, WASM_CALL_FUNCTION0(1)); |
128 EXPECT_SIZE(3, WASM_CALL_FUNCTION0(11)); | 127 EXPECT_SIZE(2, WASM_CALL_FUNCTION0(11)); |
129 | 128 |
130 EXPECT_SIZE(5, WASM_CALL_FUNCTION1(0, WASM_ZERO)); | 129 EXPECT_SIZE(4, WASM_CALL_FUNCTION(0, WASM_ZERO)); |
131 EXPECT_SIZE(7, WASM_CALL_FUNCTION2(1, WASM_ZERO, WASM_ZERO)); | 130 EXPECT_SIZE(6, WASM_CALL_FUNCTION(1, WASM_ZERO, WASM_ZERO)); |
132 } | |
133 | |
134 TEST_F(WasmMacroGenTest, CallImport) { | |
135 EXPECT_SIZE(3, WASM_CALL_IMPORT0(0)); | |
136 EXPECT_SIZE(3, WASM_CALL_IMPORT0(1)); | |
137 EXPECT_SIZE(3, WASM_CALL_IMPORT0(11)); | |
138 | |
139 EXPECT_SIZE(5, WASM_CALL_IMPORT1(0, WASM_ZERO)); | |
140 EXPECT_SIZE(7, WASM_CALL_IMPORT2(1, WASM_ZERO, WASM_ZERO)); | |
141 } | 131 } |
142 | 132 |
143 TEST_F(WasmMacroGenTest, CallIndirect) { | 133 TEST_F(WasmMacroGenTest, CallIndirect) { |
144 EXPECT_SIZE(5, WASM_CALL_INDIRECT0(0, WASM_ZERO)); | 134 EXPECT_SIZE(4, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
145 EXPECT_SIZE(5, WASM_CALL_INDIRECT0(1, WASM_ZERO)); | 135 EXPECT_SIZE(4, WASM_CALL_INDIRECT0(1, WASM_ZERO)); |
146 EXPECT_SIZE(5, WASM_CALL_INDIRECT0(11, WASM_ZERO)); | 136 EXPECT_SIZE(4, WASM_CALL_INDIRECT0(11, WASM_ZERO)); |
147 | 137 |
148 EXPECT_SIZE(7, WASM_CALL_INDIRECT1(0, WASM_ZERO, WASM_ZERO)); | 138 EXPECT_SIZE(6, WASM_CALL_INDIRECT1(0, WASM_ZERO, WASM_ZERO)); |
149 EXPECT_SIZE(9, WASM_CALL_INDIRECT2(1, WASM_ZERO, WASM_ZERO, WASM_ZERO)); | 139 EXPECT_SIZE(8, WASM_CALL_INDIRECT2(1, WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
150 } | 140 } |
151 | 141 |
152 TEST_F(WasmMacroGenTest, Int32Ops) { | 142 TEST_F(WasmMacroGenTest, Int32Ops) { |
153 EXPECT_SIZE(5, WASM_I32_ADD(WASM_ZERO, WASM_ZERO)); | 143 EXPECT_SIZE(5, WASM_I32_ADD(WASM_ZERO, WASM_ZERO)); |
154 EXPECT_SIZE(5, WASM_I32_SUB(WASM_ZERO, WASM_ZERO)); | 144 EXPECT_SIZE(5, WASM_I32_SUB(WASM_ZERO, WASM_ZERO)); |
155 EXPECT_SIZE(5, WASM_I32_MUL(WASM_ZERO, WASM_ZERO)); | 145 EXPECT_SIZE(5, WASM_I32_MUL(WASM_ZERO, WASM_ZERO)); |
156 EXPECT_SIZE(5, WASM_I32_DIVS(WASM_ZERO, WASM_ZERO)); | 146 EXPECT_SIZE(5, WASM_I32_DIVS(WASM_ZERO, WASM_ZERO)); |
157 EXPECT_SIZE(5, WASM_I32_DIVU(WASM_ZERO, WASM_ZERO)); | 147 EXPECT_SIZE(5, WASM_I32_DIVU(WASM_ZERO, WASM_ZERO)); |
158 EXPECT_SIZE(5, WASM_I32_REMS(WASM_ZERO, WASM_ZERO)); | 148 EXPECT_SIZE(5, WASM_I32_REMS(WASM_ZERO, WASM_ZERO)); |
159 EXPECT_SIZE(5, WASM_I32_REMU(WASM_ZERO, WASM_ZERO)); | 149 EXPECT_SIZE(5, WASM_I32_REMU(WASM_ZERO, WASM_ZERO)); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 EXPECT_SIZE(5, WASM_LOAD_MEM_OFFSET(kMemTypes[i], 11, WASM_ZERO)); | 303 EXPECT_SIZE(5, WASM_LOAD_MEM_OFFSET(kMemTypes[i], 11, WASM_ZERO)); |
314 } | 304 } |
315 for (size_t i = 0; i < arraysize(kMemTypes); i++) { | 305 for (size_t i = 0; i < arraysize(kMemTypes); i++) { |
316 EXPECT_SIZE(7, WASM_STORE_MEM_OFFSET(kMemTypes[i], 13, WASM_ZERO, | 306 EXPECT_SIZE(7, WASM_STORE_MEM_OFFSET(kMemTypes[i], 13, WASM_ZERO, |
317 WASM_GET_LOCAL(0))); | 307 WASM_GET_LOCAL(0))); |
318 } | 308 } |
319 } | 309 } |
320 } // namespace wasm | 310 } // namespace wasm |
321 } // namespace internal | 311 } // namespace internal |
322 } // namespace v8 | 312 } // namespace v8 |
OLD | NEW |