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 <stdint.h> | 5 #include <stdint.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 | 10 |
11 #include "src/wasm/wasm-macro-gen.h" | 11 #include "src/wasm/wasm-macro-gen.h" |
12 | 12 |
13 #include "test/cctest/cctest.h" | 13 #include "test/cctest/cctest.h" |
14 #include "test/cctest/compiler/value-helper.h" | 14 #include "test/cctest/compiler/value-helper.h" |
15 #include "test/cctest/wasm/test-signatures.h" | 15 #include "test/cctest/wasm/test-signatures.h" |
16 #include "test/cctest/wasm/wasm-run-utils.h" | 16 #include "test/cctest/wasm/wasm-run-utils.h" |
17 | 17 |
18 using namespace v8::base; | 18 using namespace v8::base; |
19 using namespace v8::internal; | 19 using namespace v8::internal; |
20 using namespace v8::internal::compiler; | 20 using namespace v8::internal::compiler; |
21 using namespace v8::internal::wasm; | 21 using namespace v8::internal::wasm; |
22 | 22 |
23 // for even shorter tests. | 23 // for even shorter tests. |
24 #define B2(a, b) kExprBlock, a, b, kExprEnd | 24 #define B2(a, b) kExprBlock, a, b, kExprEnd |
25 #define B1(a) kExprBlock, a, kExprEnd | 25 #define B1(a) kExprBlock, a, kExprEnd |
26 #define RET(x) x, kExprReturn, 1 | 26 #define RET(x) x, kExprReturn, 1 |
27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1 | 27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1 |
28 | 28 |
29 TEST(Run_WasmInt8Const) { | 29 WASM_EXEC_TEST(Int8Const) { |
30 WasmRunner<int32_t> r; | 30 WasmRunner<int32_t> r; |
31 const byte kExpectedValue = 121; | 31 const byte kExpectedValue = 121; |
32 // return(kExpectedValue) | 32 // return(kExpectedValue) |
33 BUILD(r, WASM_I8(kExpectedValue)); | 33 BUILD(r, WASM_I8(kExpectedValue)); |
34 CHECK_EQ(kExpectedValue, r.Call()); | 34 CHECK_EQ(kExpectedValue, r.Call()); |
35 } | 35 } |
36 | 36 |
37 TEST(Run_WasmInt8Const_fallthru1) { | 37 WASM_EXEC_TEST(Int8Const_fallthru1) { |
38 WasmRunner<int32_t> r; | 38 WasmRunner<int32_t> r; |
39 const byte kExpectedValue = 122; | 39 const byte kExpectedValue = 122; |
40 // kExpectedValue | 40 // kExpectedValue |
41 BUILD(r, WASM_I8(kExpectedValue)); | 41 BUILD(r, WASM_I8(kExpectedValue)); |
42 CHECK_EQ(kExpectedValue, r.Call()); | 42 CHECK_EQ(kExpectedValue, r.Call()); |
43 } | 43 } |
44 | 44 |
45 TEST(Run_WasmInt8Const_fallthru2) { | 45 WASM_EXEC_TEST(Int8Const_fallthru2) { |
46 WasmRunner<int32_t> r; | 46 WasmRunner<int32_t> r; |
47 const byte kExpectedValue = 123; | 47 const byte kExpectedValue = 123; |
48 // -99 kExpectedValue | 48 // -99 kExpectedValue |
49 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue)); | 49 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue)); |
50 CHECK_EQ(kExpectedValue, r.Call()); | 50 CHECK_EQ(kExpectedValue, r.Call()); |
51 } | 51 } |
52 | 52 |
53 TEST(Run_WasmInt8Const_all) { | 53 WASM_EXEC_TEST(Int8Const_all) { |
54 for (int value = -128; value <= 127; value++) { | 54 for (int value = -128; value <= 127; value++) { |
55 WasmRunner<int32_t> r; | 55 WasmRunner<int32_t> r; |
56 // return(value) | 56 // return(value) |
57 BUILD(r, WASM_I8(value)); | 57 BUILD(r, WASM_I8(value)); |
58 int32_t result = r.Call(); | 58 int32_t result = r.Call(); |
59 CHECK_EQ(value, result); | 59 CHECK_EQ(value, result); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 TEST(Run_WasmInt32Const) { | 63 WASM_EXEC_TEST(Int32Const) { |
64 WasmRunner<int32_t> r; | 64 WasmRunner<int32_t> r; |
65 const int32_t kExpectedValue = 0x11223344; | 65 const int32_t kExpectedValue = 0x11223344; |
66 // return(kExpectedValue) | 66 // return(kExpectedValue) |
67 BUILD(r, WASM_I32V_5(kExpectedValue)); | 67 BUILD(r, WASM_I32V_5(kExpectedValue)); |
68 CHECK_EQ(kExpectedValue, r.Call()); | 68 CHECK_EQ(kExpectedValue, r.Call()); |
69 } | 69 } |
70 | 70 |
71 TEST(Run_WasmInt32Const_many) { | 71 WASM_EXEC_TEST(Int32Const_many) { |
72 FOR_INT32_INPUTS(i) { | 72 FOR_INT32_INPUTS(i) { |
73 WasmRunner<int32_t> r; | 73 WasmRunner<int32_t> r; |
74 const int32_t kExpectedValue = *i; | 74 const int32_t kExpectedValue = *i; |
75 // return(kExpectedValue) | 75 // return(kExpectedValue) |
76 BUILD(r, WASM_I32V(kExpectedValue)); | 76 BUILD(r, WASM_I32V(kExpectedValue)); |
77 CHECK_EQ(kExpectedValue, r.Call()); | 77 CHECK_EQ(kExpectedValue, r.Call()); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 TEST(Run_WasmMemorySize) { | 81 WASM_EXEC_TEST(MemorySize) { |
82 TestingModule module; | 82 TestingModule module; |
83 WasmRunner<int32_t> r(&module); | 83 WasmRunner<int32_t> r(&module); |
84 module.AddMemory(1024); | 84 module.AddMemory(1024); |
85 BUILD(r, kExprMemorySize); | 85 BUILD(r, kExprMemorySize); |
86 CHECK_EQ(1024, r.Call()); | 86 CHECK_EQ(1024, r.Call()); |
87 } | 87 } |
88 | 88 |
89 TEST(Run_WasmInt32Param0) { | 89 WASM_EXEC_TEST(Int32Param0) { |
90 WasmRunner<int32_t> r(MachineType::Int32()); | 90 WasmRunner<int32_t> r(MachineType::Int32()); |
91 // return(local[0]) | 91 // return(local[0]) |
92 BUILD(r, WASM_GET_LOCAL(0)); | 92 BUILD(r, WASM_GET_LOCAL(0)); |
93 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 93 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
94 } | 94 } |
95 | 95 |
96 TEST(Run_WasmInt32Param0_fallthru) { | 96 WASM_EXEC_TEST(Int32Param0_fallthru) { |
97 WasmRunner<int32_t> r(MachineType::Int32()); | 97 WasmRunner<int32_t> r(MachineType::Int32()); |
98 // local[0] | 98 // local[0] |
99 BUILD(r, WASM_GET_LOCAL(0)); | 99 BUILD(r, WASM_GET_LOCAL(0)); |
100 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 100 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
101 } | 101 } |
102 | 102 |
103 TEST(Run_WasmInt32Param1) { | 103 WASM_EXEC_TEST(Int32Param1) { |
104 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 104 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
105 // local[1] | 105 // local[1] |
106 BUILD(r, WASM_GET_LOCAL(1)); | 106 BUILD(r, WASM_GET_LOCAL(1)); |
107 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(-111, *i)); } | 107 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(-111, *i)); } |
108 } | 108 } |
109 | 109 |
110 TEST(Run_WasmInt32Add) { | 110 WASM_EXEC_TEST(Int32Add) { |
111 WasmRunner<int32_t> r; | 111 WasmRunner<int32_t> r; |
112 // 11 + 44 | 112 // 11 + 44 |
113 BUILD(r, WASM_I32_ADD(WASM_I8(11), WASM_I8(44))); | 113 BUILD(r, WASM_I32_ADD(WASM_I8(11), WASM_I8(44))); |
114 CHECK_EQ(55, r.Call()); | 114 CHECK_EQ(55, r.Call()); |
115 } | 115 } |
116 | 116 |
117 TEST(Run_WasmInt32Add_P) { | 117 WASM_EXEC_TEST(Int32Add_P) { |
118 WasmRunner<int32_t> r(MachineType::Int32()); | 118 WasmRunner<int32_t> r(MachineType::Int32()); |
119 // p0 + 13 | 119 // p0 + 13 |
120 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); | 120 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); |
121 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } | 121 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } |
122 } | 122 } |
123 | 123 |
124 TEST(Run_WasmInt32Add_P_fallthru) { | 124 WASM_EXEC_TEST(Int32Add_P_fallthru) { |
125 WasmRunner<int32_t> r(MachineType::Int32()); | 125 WasmRunner<int32_t> r(MachineType::Int32()); |
126 // p0 + 13 | 126 // p0 + 13 |
127 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); | 127 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); |
128 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } | 128 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } |
129 } | 129 } |
130 | 130 |
131 TEST(Run_WasmInt32Add_P2) { | 131 WASM_EXEC_TEST(Int32Add_P2) { |
132 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 132 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
133 // p0 + p1 | 133 // p0 + p1 |
134 BUILD(r, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 134 BUILD(r, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
135 FOR_INT32_INPUTS(i) { | 135 FOR_INT32_INPUTS(i) { |
136 FOR_INT32_INPUTS(j) { | 136 FOR_INT32_INPUTS(j) { |
137 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + | 137 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + |
138 static_cast<uint32_t>(*j)); | 138 static_cast<uint32_t>(*j)); |
139 CHECK_EQ(expected, r.Call(*i, *j)); | 139 CHECK_EQ(expected, r.Call(*i, *j)); |
140 } | 140 } |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 TEST(Run_WasmFloat32Add) { | 144 WASM_EXEC_TEST(Float32Add) { |
145 WasmRunner<int32_t> r; | 145 WasmRunner<int32_t> r; |
146 // int(11.5f + 44.5f) | 146 // int(11.5f + 44.5f) |
147 BUILD(r, | 147 BUILD(r, |
148 WASM_I32_SCONVERT_F32(WASM_F32_ADD(WASM_F32(11.5f), WASM_F32(44.5f)))); | 148 WASM_I32_SCONVERT_F32(WASM_F32_ADD(WASM_F32(11.5f), WASM_F32(44.5f)))); |
149 CHECK_EQ(56, r.Call()); | 149 CHECK_EQ(56, r.Call()); |
150 } | 150 } |
151 | 151 |
152 TEST(Run_WasmFloat64Add) { | 152 WASM_EXEC_TEST(Float64Add) { |
153 WasmRunner<int32_t> r; | 153 WasmRunner<int32_t> r; |
154 // return int(13.5d + 43.5d) | 154 // return int(13.5d + 43.5d) |
155 BUILD(r, WASM_I32_SCONVERT_F64(WASM_F64_ADD(WASM_F64(13.5), WASM_F64(43.5)))); | 155 BUILD(r, WASM_I32_SCONVERT_F64(WASM_F64_ADD(WASM_F64(13.5), WASM_F64(43.5)))); |
156 CHECK_EQ(57, r.Call()); | 156 CHECK_EQ(57, r.Call()); |
157 } | 157 } |
158 | 158 |
159 void TestInt32Binop(WasmOpcode opcode, int32_t expected, int32_t a, int32_t b) { | 159 void TestInt32Binop(WasmOpcode opcode, int32_t expected, int32_t a, int32_t b) { |
160 { | 160 { |
161 WasmRunner<int32_t> r; | 161 WasmRunner<int32_t> r; |
162 // K op K | 162 // K op K |
163 BUILD(r, WASM_BINOP(opcode, WASM_I32V(a), WASM_I32V(b))); | 163 BUILD(r, WASM_BINOP(opcode, WASM_I32V(a), WASM_I32V(b))); |
164 CHECK_EQ(expected, r.Call()); | 164 CHECK_EQ(expected, r.Call()); |
165 } | 165 } |
166 { | 166 { |
167 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 167 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
168 // a op b | 168 // a op b |
169 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 169 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
170 CHECK_EQ(expected, r.Call(a, b)); | 170 CHECK_EQ(expected, r.Call(a, b)); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 TEST(Run_WasmInt32Binops) { | 174 WASM_EXEC_TEST(Int32Binops) { |
175 TestInt32Binop(kExprI32Add, 88888888, 33333333, 55555555); | 175 TestInt32Binop(kExprI32Add, 88888888, 33333333, 55555555); |
176 TestInt32Binop(kExprI32Sub, -1111111, 7777777, 8888888); | 176 TestInt32Binop(kExprI32Sub, -1111111, 7777777, 8888888); |
177 TestInt32Binop(kExprI32Mul, 65130756, 88734, 734); | 177 TestInt32Binop(kExprI32Mul, 65130756, 88734, 734); |
178 TestInt32Binop(kExprI32DivS, -66, -4777344, 72384); | 178 TestInt32Binop(kExprI32DivS, -66, -4777344, 72384); |
179 TestInt32Binop(kExprI32DivU, 805306368, 0xF0000000, 5); | 179 TestInt32Binop(kExprI32DivU, 805306368, 0xF0000000, 5); |
180 TestInt32Binop(kExprI32RemS, -3, -3003, 1000); | 180 TestInt32Binop(kExprI32RemS, -3, -3003, 1000); |
181 TestInt32Binop(kExprI32RemU, 4, 4004, 1000); | 181 TestInt32Binop(kExprI32RemU, 4, 4004, 1000); |
182 TestInt32Binop(kExprI32And, 0xEE, 0xFFEE, 0xFF0000FF); | 182 TestInt32Binop(kExprI32And, 0xEE, 0xFFEE, 0xFF0000FF); |
183 TestInt32Binop(kExprI32Ior, 0xF0FF00FF, 0xF0F000EE, 0x000F0011); | 183 TestInt32Binop(kExprI32Ior, 0xF0FF00FF, 0xF0F000EE, 0x000F0011); |
184 TestInt32Binop(kExprI32Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE); | 184 TestInt32Binop(kExprI32Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE); |
(...skipping 26 matching lines...) Expand all Loading... |
211 CHECK_EQ(expected, r.Call()); | 211 CHECK_EQ(expected, r.Call()); |
212 } | 212 } |
213 { | 213 { |
214 WasmRunner<int32_t> r(MachineType::Int32()); | 214 WasmRunner<int32_t> r(MachineType::Int32()); |
215 // return op a | 215 // return op a |
216 BUILD(r, WASM_UNOP(opcode, WASM_GET_LOCAL(0))); | 216 BUILD(r, WASM_UNOP(opcode, WASM_GET_LOCAL(0))); |
217 CHECK_EQ(expected, r.Call(a)); | 217 CHECK_EQ(expected, r.Call(a)); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 TEST(Run_WasmInt32Clz) { | 221 WASM_EXEC_TEST(Int32Clz) { |
222 TestInt32Unop(kExprI32Clz, 0, 0x80001000); | 222 TestInt32Unop(kExprI32Clz, 0, 0x80001000); |
223 TestInt32Unop(kExprI32Clz, 1, 0x40000500); | 223 TestInt32Unop(kExprI32Clz, 1, 0x40000500); |
224 TestInt32Unop(kExprI32Clz, 2, 0x20000300); | 224 TestInt32Unop(kExprI32Clz, 2, 0x20000300); |
225 TestInt32Unop(kExprI32Clz, 3, 0x10000003); | 225 TestInt32Unop(kExprI32Clz, 3, 0x10000003); |
226 TestInt32Unop(kExprI32Clz, 4, 0x08050000); | 226 TestInt32Unop(kExprI32Clz, 4, 0x08050000); |
227 TestInt32Unop(kExprI32Clz, 5, 0x04006000); | 227 TestInt32Unop(kExprI32Clz, 5, 0x04006000); |
228 TestInt32Unop(kExprI32Clz, 6, 0x02000000); | 228 TestInt32Unop(kExprI32Clz, 6, 0x02000000); |
229 TestInt32Unop(kExprI32Clz, 7, 0x010000a0); | 229 TestInt32Unop(kExprI32Clz, 7, 0x010000a0); |
230 TestInt32Unop(kExprI32Clz, 8, 0x00800c00); | 230 TestInt32Unop(kExprI32Clz, 8, 0x00800c00); |
231 TestInt32Unop(kExprI32Clz, 9, 0x00400000); | 231 TestInt32Unop(kExprI32Clz, 9, 0x00400000); |
(...skipping 15 matching lines...) Expand all Loading... |
247 TestInt32Unop(kExprI32Clz, 25, 0x00000041); | 247 TestInt32Unop(kExprI32Clz, 25, 0x00000041); |
248 TestInt32Unop(kExprI32Clz, 26, 0x00000022); | 248 TestInt32Unop(kExprI32Clz, 26, 0x00000022); |
249 TestInt32Unop(kExprI32Clz, 27, 0x00000013); | 249 TestInt32Unop(kExprI32Clz, 27, 0x00000013); |
250 TestInt32Unop(kExprI32Clz, 28, 0x00000008); | 250 TestInt32Unop(kExprI32Clz, 28, 0x00000008); |
251 TestInt32Unop(kExprI32Clz, 29, 0x00000004); | 251 TestInt32Unop(kExprI32Clz, 29, 0x00000004); |
252 TestInt32Unop(kExprI32Clz, 30, 0x00000002); | 252 TestInt32Unop(kExprI32Clz, 30, 0x00000002); |
253 TestInt32Unop(kExprI32Clz, 31, 0x00000001); | 253 TestInt32Unop(kExprI32Clz, 31, 0x00000001); |
254 TestInt32Unop(kExprI32Clz, 32, 0x00000000); | 254 TestInt32Unop(kExprI32Clz, 32, 0x00000000); |
255 } | 255 } |
256 | 256 |
257 TEST(Run_WasmInt32Ctz) { | 257 WASM_EXEC_TEST(Int32Ctz) { |
258 TestInt32Unop(kExprI32Ctz, 32, 0x00000000); | 258 TestInt32Unop(kExprI32Ctz, 32, 0x00000000); |
259 TestInt32Unop(kExprI32Ctz, 31, 0x80000000); | 259 TestInt32Unop(kExprI32Ctz, 31, 0x80000000); |
260 TestInt32Unop(kExprI32Ctz, 30, 0x40000000); | 260 TestInt32Unop(kExprI32Ctz, 30, 0x40000000); |
261 TestInt32Unop(kExprI32Ctz, 29, 0x20000000); | 261 TestInt32Unop(kExprI32Ctz, 29, 0x20000000); |
262 TestInt32Unop(kExprI32Ctz, 28, 0x10000000); | 262 TestInt32Unop(kExprI32Ctz, 28, 0x10000000); |
263 TestInt32Unop(kExprI32Ctz, 27, 0xa8000000); | 263 TestInt32Unop(kExprI32Ctz, 27, 0xa8000000); |
264 TestInt32Unop(kExprI32Ctz, 26, 0xf4000000); | 264 TestInt32Unop(kExprI32Ctz, 26, 0xf4000000); |
265 TestInt32Unop(kExprI32Ctz, 25, 0x62000000); | 265 TestInt32Unop(kExprI32Ctz, 25, 0x62000000); |
266 TestInt32Unop(kExprI32Ctz, 24, 0x91000000); | 266 TestInt32Unop(kExprI32Ctz, 24, 0x91000000); |
267 TestInt32Unop(kExprI32Ctz, 23, 0xcd800000); | 267 TestInt32Unop(kExprI32Ctz, 23, 0xcd800000); |
(...skipping 15 matching lines...) Expand all Loading... |
283 TestInt32Unop(kExprI32Ctz, 7, 0xdfbec580); | 283 TestInt32Unop(kExprI32Ctz, 7, 0xdfbec580); |
284 TestInt32Unop(kExprI32Ctz, 6, 0x27a9db40); | 284 TestInt32Unop(kExprI32Ctz, 6, 0x27a9db40); |
285 TestInt32Unop(kExprI32Ctz, 5, 0xde3bcb20); | 285 TestInt32Unop(kExprI32Ctz, 5, 0xde3bcb20); |
286 TestInt32Unop(kExprI32Ctz, 4, 0xd7e8a610); | 286 TestInt32Unop(kExprI32Ctz, 4, 0xd7e8a610); |
287 TestInt32Unop(kExprI32Ctz, 3, 0x9afdbc88); | 287 TestInt32Unop(kExprI32Ctz, 3, 0x9afdbc88); |
288 TestInt32Unop(kExprI32Ctz, 2, 0x9afdbc84); | 288 TestInt32Unop(kExprI32Ctz, 2, 0x9afdbc84); |
289 TestInt32Unop(kExprI32Ctz, 1, 0x9afdbc82); | 289 TestInt32Unop(kExprI32Ctz, 1, 0x9afdbc82); |
290 TestInt32Unop(kExprI32Ctz, 0, 0x9afdbc81); | 290 TestInt32Unop(kExprI32Ctz, 0, 0x9afdbc81); |
291 } | 291 } |
292 | 292 |
293 TEST(Run_WasmInt32Popcnt) { | 293 WASM_EXEC_TEST(Int32Popcnt) { |
294 TestInt32Unop(kExprI32Popcnt, 32, 0xffffffff); | 294 TestInt32Unop(kExprI32Popcnt, 32, 0xffffffff); |
295 TestInt32Unop(kExprI32Popcnt, 0, 0x00000000); | 295 TestInt32Unop(kExprI32Popcnt, 0, 0x00000000); |
296 TestInt32Unop(kExprI32Popcnt, 1, 0x00008000); | 296 TestInt32Unop(kExprI32Popcnt, 1, 0x00008000); |
297 TestInt32Unop(kExprI32Popcnt, 13, 0x12345678); | 297 TestInt32Unop(kExprI32Popcnt, 13, 0x12345678); |
298 TestInt32Unop(kExprI32Popcnt, 19, 0xfedcba09); | 298 TestInt32Unop(kExprI32Popcnt, 19, 0xfedcba09); |
299 } | 299 } |
300 | 300 |
301 TEST(Run_WasmI32Eqz) { | 301 WASM_EXEC_TEST(I32Eqz) { |
302 TestInt32Unop(kExprI32Eqz, 0, 1); | 302 TestInt32Unop(kExprI32Eqz, 0, 1); |
303 TestInt32Unop(kExprI32Eqz, 0, -1); | 303 TestInt32Unop(kExprI32Eqz, 0, -1); |
304 TestInt32Unop(kExprI32Eqz, 0, -827343); | 304 TestInt32Unop(kExprI32Eqz, 0, -827343); |
305 TestInt32Unop(kExprI32Eqz, 0, 8888888); | 305 TestInt32Unop(kExprI32Eqz, 0, 8888888); |
306 TestInt32Unop(kExprI32Eqz, 1, 0); | 306 TestInt32Unop(kExprI32Eqz, 1, 0); |
307 } | 307 } |
308 | 308 |
309 TEST(Run_WasmI32Shl) { | 309 WASM_EXEC_TEST(I32Shl) { |
310 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 310 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); |
311 BUILD(r, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 311 BUILD(r, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
312 | 312 |
313 FOR_UINT32_INPUTS(i) { | 313 FOR_UINT32_INPUTS(i) { |
314 FOR_UINT32_INPUTS(j) { | 314 FOR_UINT32_INPUTS(j) { |
315 uint32_t expected = (*i) << (*j & 0x1f); | 315 uint32_t expected = (*i) << (*j & 0x1f); |
316 CHECK_EQ(expected, r.Call(*i, *j)); | 316 CHECK_EQ(expected, r.Call(*i, *j)); |
317 } | 317 } |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 TEST(Run_WasmI32Shr) { | 321 WASM_EXEC_TEST(I32Shr) { |
322 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 322 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); |
323 BUILD(r, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 323 BUILD(r, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
324 | 324 |
325 FOR_UINT32_INPUTS(i) { | 325 FOR_UINT32_INPUTS(i) { |
326 FOR_UINT32_INPUTS(j) { | 326 FOR_UINT32_INPUTS(j) { |
327 uint32_t expected = (*i) >> (*j & 0x1f); | 327 uint32_t expected = (*i) >> (*j & 0x1f); |
328 CHECK_EQ(expected, r.Call(*i, *j)); | 328 CHECK_EQ(expected, r.Call(*i, *j)); |
329 } | 329 } |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 TEST(Run_WasmI32Sar) { | 333 WASM_EXEC_TEST(I32Sar) { |
334 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 334 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
335 BUILD(r, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 335 BUILD(r, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
336 | 336 |
337 FOR_INT32_INPUTS(i) { | 337 FOR_INT32_INPUTS(i) { |
338 FOR_INT32_INPUTS(j) { | 338 FOR_INT32_INPUTS(j) { |
339 int32_t expected = (*i) >> (*j & 0x1f); | 339 int32_t expected = (*i) >> (*j & 0x1f); |
340 CHECK_EQ(expected, r.Call(*i, *j)); | 340 CHECK_EQ(expected, r.Call(*i, *j)); |
341 } | 341 } |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 TEST(Run_WASM_Int32DivS_trap) { | 345 WASM_EXEC_TEST(Int32DivS_trap) { |
346 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 346 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
347 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 347 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
348 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 348 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
349 CHECK_EQ(0, r.Call(0, 100)); | 349 CHECK_EQ(0, r.Call(0, 100)); |
350 CHECK_TRAP(r.Call(100, 0)); | 350 CHECK_TRAP(r.Call(100, 0)); |
351 CHECK_TRAP(r.Call(-1001, 0)); | 351 CHECK_TRAP(r.Call(-1001, 0)); |
352 CHECK_TRAP(r.Call(kMin, -1)); | 352 CHECK_TRAP(r.Call(kMin, -1)); |
353 CHECK_TRAP(r.Call(kMin, 0)); | 353 CHECK_TRAP(r.Call(kMin, 0)); |
354 } | 354 } |
355 | 355 |
356 TEST(Run_WASM_Int32RemS_trap) { | 356 WASM_EXEC_TEST(Int32RemS_trap) { |
357 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 357 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
358 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 358 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
359 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 359 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
360 CHECK_EQ(33, r.Call(133, 100)); | 360 CHECK_EQ(33, r.Call(133, 100)); |
361 CHECK_EQ(0, r.Call(kMin, -1)); | 361 CHECK_EQ(0, r.Call(kMin, -1)); |
362 CHECK_TRAP(r.Call(100, 0)); | 362 CHECK_TRAP(r.Call(100, 0)); |
363 CHECK_TRAP(r.Call(-1001, 0)); | 363 CHECK_TRAP(r.Call(-1001, 0)); |
364 CHECK_TRAP(r.Call(kMin, 0)); | 364 CHECK_TRAP(r.Call(kMin, 0)); |
365 } | 365 } |
366 | 366 |
367 TEST(Run_WASM_Int32DivU_trap) { | 367 WASM_EXEC_TEST(Int32DivU_trap) { |
368 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 368 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
369 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 369 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
370 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 370 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
371 CHECK_EQ(0, r.Call(0, 100)); | 371 CHECK_EQ(0, r.Call(0, 100)); |
372 CHECK_EQ(0, r.Call(kMin, -1)); | 372 CHECK_EQ(0, r.Call(kMin, -1)); |
373 CHECK_TRAP(r.Call(100, 0)); | 373 CHECK_TRAP(r.Call(100, 0)); |
374 CHECK_TRAP(r.Call(-1001, 0)); | 374 CHECK_TRAP(r.Call(-1001, 0)); |
375 CHECK_TRAP(r.Call(kMin, 0)); | 375 CHECK_TRAP(r.Call(kMin, 0)); |
376 } | 376 } |
377 | 377 |
378 TEST(Run_WASM_Int32RemU_trap) { | 378 WASM_EXEC_TEST(Int32RemU_trap) { |
379 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 379 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
380 BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 380 BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
381 CHECK_EQ(17, r.Call(217, 100)); | 381 CHECK_EQ(17, r.Call(217, 100)); |
382 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 382 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
383 CHECK_TRAP(r.Call(100, 0)); | 383 CHECK_TRAP(r.Call(100, 0)); |
384 CHECK_TRAP(r.Call(-1001, 0)); | 384 CHECK_TRAP(r.Call(-1001, 0)); |
385 CHECK_TRAP(r.Call(kMin, 0)); | 385 CHECK_TRAP(r.Call(kMin, 0)); |
386 CHECK_EQ(kMin, r.Call(kMin, -1)); | 386 CHECK_EQ(kMin, r.Call(kMin, -1)); |
387 } | 387 } |
388 | 388 |
389 TEST(Run_WASM_Int32DivS_byzero_const) { | 389 WASM_EXEC_TEST(Int32DivS_byzero_const) { |
390 for (int8_t denom = -2; denom < 8; denom++) { | 390 for (int8_t denom = -2; denom < 8; denom++) { |
391 WasmRunner<int32_t> r(MachineType::Int32()); | 391 WasmRunner<int32_t> r(MachineType::Int32()); |
392 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); | 392 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); |
393 for (int32_t val = -7; val < 8; val++) { | 393 for (int32_t val = -7; val < 8; val++) { |
394 if (denom == 0) { | 394 if (denom == 0) { |
395 CHECK_TRAP(r.Call(val)); | 395 CHECK_TRAP(r.Call(val)); |
396 } else { | 396 } else { |
397 CHECK_EQ(val / denom, r.Call(val)); | 397 CHECK_EQ(val / denom, r.Call(val)); |
398 } | 398 } |
399 } | 399 } |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 TEST(Run_WASM_Int32DivU_byzero_const) { | 403 WASM_EXEC_TEST(Int32DivU_byzero_const) { |
404 for (uint32_t denom = 0xfffffffe; denom < 8; denom++) { | 404 for (uint32_t denom = 0xfffffffe; denom < 8; denom++) { |
405 WasmRunner<uint32_t> r(MachineType::Uint32()); | 405 WasmRunner<uint32_t> r(MachineType::Uint32()); |
406 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); | 406 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); |
407 | 407 |
408 for (uint32_t val = 0xfffffff0; val < 8; val++) { | 408 for (uint32_t val = 0xfffffff0; val < 8; val++) { |
409 if (denom == 0) { | 409 if (denom == 0) { |
410 CHECK_TRAP(r.Call(val)); | 410 CHECK_TRAP(r.Call(val)); |
411 } else { | 411 } else { |
412 CHECK_EQ(val / denom, r.Call(val)); | 412 CHECK_EQ(val / denom, r.Call(val)); |
413 } | 413 } |
414 } | 414 } |
415 } | 415 } |
416 } | 416 } |
417 | 417 |
418 TEST(Run_WASM_Int32DivS_trap_effect) { | 418 WASM_EXEC_TEST(Int32DivS_trap_effect) { |
419 TestingModule module; | 419 TestingModule module; |
420 module.AddMemoryElems<int32_t>(8); | 420 module.AddMemoryElems<int32_t>(8); |
421 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); | 421 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); |
422 | 422 |
423 BUILD(r, | 423 BUILD(r, |
424 WASM_IF_ELSE(WASM_GET_LOCAL(0), | 424 WASM_IF_ELSE(WASM_GET_LOCAL(0), |
425 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), | 425 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), |
426 WASM_ZERO, WASM_GET_LOCAL(0)), | 426 WASM_ZERO, WASM_GET_LOCAL(0)), |
427 WASM_GET_LOCAL(1)), | 427 WASM_GET_LOCAL(1)), |
428 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), | 428 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 CHECK_EQ(expected, r.Call()); | 522 CHECK_EQ(expected, r.Call()); |
523 } | 523 } |
524 { | 524 { |
525 WasmRunner<int32_t> r(MachineType::Float64()); | 525 WasmRunner<int32_t> r(MachineType::Float64()); |
526 // return int(op(a)) | 526 // return int(op(a)) |
527 BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_GET_LOCAL(0)))); | 527 BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_GET_LOCAL(0)))); |
528 CHECK_EQ(expected, r.Call(a)); | 528 CHECK_EQ(expected, r.Call(a)); |
529 } | 529 } |
530 } | 530 } |
531 | 531 |
532 TEST(Run_WasmFloat32Binops) { | 532 WASM_EXEC_TEST(Float32Binops) { |
533 TestFloat32Binop(kExprF32Eq, 1, 8.125f, 8.125f); | 533 TestFloat32Binop(kExprF32Eq, 1, 8.125f, 8.125f); |
534 TestFloat32Binop(kExprF32Ne, 1, 8.125f, 8.127f); | 534 TestFloat32Binop(kExprF32Ne, 1, 8.125f, 8.127f); |
535 TestFloat32Binop(kExprF32Lt, 1, -9.5f, -9.0f); | 535 TestFloat32Binop(kExprF32Lt, 1, -9.5f, -9.0f); |
536 TestFloat32Binop(kExprF32Le, 1, -1111.0f, -1111.0f); | 536 TestFloat32Binop(kExprF32Le, 1, -1111.0f, -1111.0f); |
537 TestFloat32Binop(kExprF32Gt, 1, -9.0f, -9.5f); | 537 TestFloat32Binop(kExprF32Gt, 1, -9.0f, -9.5f); |
538 TestFloat32Binop(kExprF32Ge, 1, -1111.0f, -1111.0f); | 538 TestFloat32Binop(kExprF32Ge, 1, -1111.0f, -1111.0f); |
539 | 539 |
540 TestFloat32BinopWithConvert(kExprF32Add, 10, 3.5f, 6.5f); | 540 TestFloat32BinopWithConvert(kExprF32Add, 10, 3.5f, 6.5f); |
541 TestFloat32BinopWithConvert(kExprF32Sub, 2, 44.5f, 42.5f); | 541 TestFloat32BinopWithConvert(kExprF32Sub, 2, 44.5f, 42.5f); |
542 TestFloat32BinopWithConvert(kExprF32Mul, -66, -132.1f, 0.5f); | 542 TestFloat32BinopWithConvert(kExprF32Mul, -66, -132.1f, 0.5f); |
543 TestFloat32BinopWithConvert(kExprF32Div, 11, 22.1f, 2.0f); | 543 TestFloat32BinopWithConvert(kExprF32Div, 11, 22.1f, 2.0f); |
544 } | 544 } |
545 | 545 |
546 TEST(Run_WasmFloat32Unops) { | 546 WASM_EXEC_TEST(Float32Unops) { |
547 TestFloat32UnopWithConvert(kExprF32Abs, 8, 8.125f); | 547 TestFloat32UnopWithConvert(kExprF32Abs, 8, 8.125f); |
548 TestFloat32UnopWithConvert(kExprF32Abs, 9, -9.125f); | 548 TestFloat32UnopWithConvert(kExprF32Abs, 9, -9.125f); |
549 TestFloat32UnopWithConvert(kExprF32Neg, -213, 213.125f); | 549 TestFloat32UnopWithConvert(kExprF32Neg, -213, 213.125f); |
550 TestFloat32UnopWithConvert(kExprF32Sqrt, 12, 144.4f); | 550 TestFloat32UnopWithConvert(kExprF32Sqrt, 12, 144.4f); |
551 } | 551 } |
552 | 552 |
553 TEST(Run_WasmFloat64Binops) { | 553 WASM_EXEC_TEST(Float64Binops) { |
554 TestFloat64Binop(kExprF64Eq, 1, 16.25, 16.25); | 554 TestFloat64Binop(kExprF64Eq, 1, 16.25, 16.25); |
555 TestFloat64Binop(kExprF64Ne, 1, 16.25, 16.15); | 555 TestFloat64Binop(kExprF64Ne, 1, 16.25, 16.15); |
556 TestFloat64Binop(kExprF64Lt, 1, -32.4, 11.7); | 556 TestFloat64Binop(kExprF64Lt, 1, -32.4, 11.7); |
557 TestFloat64Binop(kExprF64Le, 1, -88.9, -88.9); | 557 TestFloat64Binop(kExprF64Le, 1, -88.9, -88.9); |
558 TestFloat64Binop(kExprF64Gt, 1, 11.7, -32.4); | 558 TestFloat64Binop(kExprF64Gt, 1, 11.7, -32.4); |
559 TestFloat64Binop(kExprF64Ge, 1, -88.9, -88.9); | 559 TestFloat64Binop(kExprF64Ge, 1, -88.9, -88.9); |
560 | 560 |
561 TestFloat64BinopWithConvert(kExprF64Add, 100, 43.5, 56.5); | 561 TestFloat64BinopWithConvert(kExprF64Add, 100, 43.5, 56.5); |
562 TestFloat64BinopWithConvert(kExprF64Sub, 200, 12200.1, 12000.1); | 562 TestFloat64BinopWithConvert(kExprF64Sub, 200, 12200.1, 12000.1); |
563 TestFloat64BinopWithConvert(kExprF64Mul, -33, 134, -0.25); | 563 TestFloat64BinopWithConvert(kExprF64Mul, -33, 134, -0.25); |
564 TestFloat64BinopWithConvert(kExprF64Div, -1111, -2222.3, 2); | 564 TestFloat64BinopWithConvert(kExprF64Div, -1111, -2222.3, 2); |
565 } | 565 } |
566 | 566 |
567 TEST(Run_WasmFloat64Unops) { | 567 WASM_EXEC_TEST(Float64Unops) { |
568 TestFloat64UnopWithConvert(kExprF64Abs, 108, 108.125); | 568 TestFloat64UnopWithConvert(kExprF64Abs, 108, 108.125); |
569 TestFloat64UnopWithConvert(kExprF64Abs, 209, -209.125); | 569 TestFloat64UnopWithConvert(kExprF64Abs, 209, -209.125); |
570 TestFloat64UnopWithConvert(kExprF64Neg, -209, 209.125); | 570 TestFloat64UnopWithConvert(kExprF64Neg, -209, 209.125); |
571 TestFloat64UnopWithConvert(kExprF64Sqrt, 13, 169.4); | 571 TestFloat64UnopWithConvert(kExprF64Sqrt, 13, 169.4); |
572 } | 572 } |
573 | 573 |
574 TEST(Run_WasmFloat32Neg) { | 574 WASM_EXEC_TEST(Float32Neg) { |
575 WasmRunner<float> r(MachineType::Float32()); | 575 WasmRunner<float> r(MachineType::Float32()); |
576 BUILD(r, WASM_F32_NEG(WASM_GET_LOCAL(0))); | 576 BUILD(r, WASM_F32_NEG(WASM_GET_LOCAL(0))); |
577 | 577 |
578 FOR_FLOAT32_INPUTS(i) { | 578 FOR_FLOAT32_INPUTS(i) { |
579 CHECK_EQ(0x80000000, | 579 CHECK_EQ(0x80000000, |
580 bit_cast<uint32_t>(*i) ^ bit_cast<uint32_t>(r.Call(*i))); | 580 bit_cast<uint32_t>(*i) ^ bit_cast<uint32_t>(r.Call(*i))); |
581 } | 581 } |
582 } | 582 } |
583 | 583 |
584 TEST(Run_WasmFloat32SubMinusZero) { | 584 WASM_EXEC_TEST(Float32SubMinusZero) { |
585 WasmRunner<float> r(MachineType::Float32()); | 585 WasmRunner<float> r(MachineType::Float32()); |
586 BUILD(r, WASM_F32_SUB(WASM_F32(-0.0), WASM_GET_LOCAL(0))); | 586 BUILD(r, WASM_F32_SUB(WASM_F32(-0.0), WASM_GET_LOCAL(0))); |
587 | 587 |
588 CHECK_EQ(0x7fe00000, bit_cast<uint32_t>(r.Call(bit_cast<float>(0x7fa00000)))); | 588 CHECK_EQ(0x7fe00000, bit_cast<uint32_t>(r.Call(bit_cast<float>(0x7fa00000)))); |
589 } | 589 } |
590 | 590 |
591 TEST(Run_WasmFloat64SubMinusZero) { | 591 WASM_EXEC_TEST(Float64SubMinusZero) { |
592 WasmRunner<double> r(MachineType::Float64()); | 592 WasmRunner<double> r(MachineType::Float64()); |
593 BUILD(r, WASM_F64_SUB(WASM_F64(-0.0), WASM_GET_LOCAL(0))); | 593 BUILD(r, WASM_F64_SUB(WASM_F64(-0.0), WASM_GET_LOCAL(0))); |
594 | 594 |
595 CHECK_EQ(0x7ff8123456789abc, | 595 CHECK_EQ(0x7ff8123456789abc, |
596 bit_cast<uint64_t>(r.Call(bit_cast<double>(0x7ff0123456789abc)))); | 596 bit_cast<uint64_t>(r.Call(bit_cast<double>(0x7ff0123456789abc)))); |
597 } | 597 } |
598 | 598 |
599 TEST(Run_WasmFloat64Neg) { | 599 WASM_EXEC_TEST(Float64Neg) { |
600 WasmRunner<double> r(MachineType::Float64()); | 600 WasmRunner<double> r(MachineType::Float64()); |
601 BUILD(r, WASM_F64_NEG(WASM_GET_LOCAL(0))); | 601 BUILD(r, WASM_F64_NEG(WASM_GET_LOCAL(0))); |
602 | 602 |
603 FOR_FLOAT64_INPUTS(i) { | 603 FOR_FLOAT64_INPUTS(i) { |
604 CHECK_EQ(0x8000000000000000, | 604 CHECK_EQ(0x8000000000000000, |
605 bit_cast<uint64_t>(*i) ^ bit_cast<uint64_t>(r.Call(*i))); | 605 bit_cast<uint64_t>(*i) ^ bit_cast<uint64_t>(r.Call(*i))); |
606 } | 606 } |
607 } | 607 } |
608 | 608 |
609 TEST(Run_Wasm_IfElse_P) { | 609 WASM_EXEC_TEST(IfElse_P) { |
610 WasmRunner<int32_t> r(MachineType::Int32()); | 610 WasmRunner<int32_t> r(MachineType::Int32()); |
611 // if (p0) return 11; else return 22; | 611 // if (p0) return 11; else return 22; |
612 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 612 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
613 WASM_I8(11), // -- | 613 WASM_I8(11), // -- |
614 WASM_I8(22))); // -- | 614 WASM_I8(22))); // -- |
615 FOR_INT32_INPUTS(i) { | 615 FOR_INT32_INPUTS(i) { |
616 int32_t expected = *i ? 11 : 22; | 616 int32_t expected = *i ? 11 : 22; |
617 CHECK_EQ(expected, r.Call(*i)); | 617 CHECK_EQ(expected, r.Call(*i)); |
618 } | 618 } |
619 } | 619 } |
620 | 620 |
621 TEST(Run_Wasm_If_empty1) { | 621 WASM_EXEC_TEST(If_empty1) { |
622 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 622 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); |
623 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprEnd, WASM_GET_LOCAL(1)); | 623 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprEnd, WASM_GET_LOCAL(1)); |
624 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 9, *i)); } | 624 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 9, *i)); } |
625 } | 625 } |
626 | 626 |
627 TEST(Run_Wasm_IfElse_empty1) { | 627 WASM_EXEC_TEST(IfElse_empty1) { |
628 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 628 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); |
629 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, kExprEnd, WASM_GET_LOCAL(1)); | 629 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, kExprEnd, WASM_GET_LOCAL(1)); |
630 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 8, *i)); } | 630 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 8, *i)); } |
631 } | 631 } |
632 | 632 |
633 TEST(Run_Wasm_IfElse_empty2) { | 633 WASM_EXEC_TEST(IfElse_empty2) { |
634 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 634 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); |
635 BUILD(r, WASM_GET_LOCAL(0), kExprIf, WASM_ZERO, kExprElse, kExprEnd, | 635 BUILD(r, WASM_GET_LOCAL(0), kExprIf, WASM_ZERO, kExprElse, kExprEnd, |
636 WASM_GET_LOCAL(1)); | 636 WASM_GET_LOCAL(1)); |
637 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 7, *i)); } | 637 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 7, *i)); } |
638 } | 638 } |
639 | 639 |
640 TEST(Run_Wasm_IfElse_empty3) { | 640 WASM_EXEC_TEST(IfElse_empty3) { |
641 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 641 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); |
642 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, WASM_ZERO, kExprEnd, | 642 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, WASM_ZERO, kExprEnd, |
643 WASM_GET_LOCAL(1)); | 643 WASM_GET_LOCAL(1)); |
644 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); } | 644 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); } |
645 } | 645 } |
646 | 646 |
647 TEST(Run_Wasm_If_chain) { | 647 WASM_EXEC_TEST(If_chain) { |
648 WasmRunner<int32_t> r(MachineType::Int32()); | 648 WasmRunner<int32_t> r(MachineType::Int32()); |
649 // if (p0) 13; if (p0) 14; 15 | 649 // if (p0) 13; if (p0) 14; 15 |
650 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_I8(13)), | 650 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_I8(13)), |
651 WASM_IF(WASM_GET_LOCAL(0), WASM_I8(14)), WASM_I8(15)); | 651 WASM_IF(WASM_GET_LOCAL(0), WASM_I8(14)), WASM_I8(15)); |
652 FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } | 652 FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } |
653 } | 653 } |
654 | 654 |
655 TEST(Run_Wasm_If_chain_set) { | 655 WASM_EXEC_TEST(If_chain_set) { |
656 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 656 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
657 // if (p0) p1 = 73; if (p0) p1 = 74; p1 | 657 // if (p0) p1 = 73; if (p0) p1 = 74; p1 |
658 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))), | 658 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))), |
659 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))), | 659 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))), |
660 WASM_GET_LOCAL(1)); | 660 WASM_GET_LOCAL(1)); |
661 FOR_INT32_INPUTS(i) { | 661 FOR_INT32_INPUTS(i) { |
662 int32_t expected = *i ? 74 : *i; | 662 int32_t expected = *i ? 74 : *i; |
663 CHECK_EQ(expected, r.Call(*i, *i)); | 663 CHECK_EQ(expected, r.Call(*i, *i)); |
664 } | 664 } |
665 } | 665 } |
666 | 666 |
667 TEST(Run_Wasm_IfElse_Unreachable1) { | 667 WASM_EXEC_TEST(IfElse_Unreachable1) { |
668 WasmRunner<int32_t> r; | 668 WasmRunner<int32_t> r; |
669 // if (0) unreachable; else return 22; | 669 // if (0) unreachable; else return 22; |
670 BUILD(r, WASM_IF_ELSE(WASM_ZERO, // -- | 670 BUILD(r, WASM_IF_ELSE(WASM_ZERO, // -- |
671 WASM_UNREACHABLE, // -- | 671 WASM_UNREACHABLE, // -- |
672 WASM_I8(27))); // -- | 672 WASM_I8(27))); // -- |
673 CHECK_EQ(27, r.Call()); | 673 CHECK_EQ(27, r.Call()); |
674 } | 674 } |
675 | 675 |
676 TEST(Run_Wasm_Return12) { | 676 WASM_EXEC_TEST(Return12) { |
677 WasmRunner<int32_t> r; | 677 WasmRunner<int32_t> r; |
678 | 678 |
679 BUILD(r, RET_I8(12)); | 679 BUILD(r, RET_I8(12)); |
680 CHECK_EQ(12, r.Call()); | 680 CHECK_EQ(12, r.Call()); |
681 } | 681 } |
682 | 682 |
683 TEST(Run_Wasm_Return17) { | 683 WASM_EXEC_TEST(Return17) { |
684 WasmRunner<int32_t> r; | 684 WasmRunner<int32_t> r; |
685 | 685 |
686 BUILD(r, B1(RET_I8(17))); | 686 BUILD(r, B1(RET_I8(17))); |
687 CHECK_EQ(17, r.Call()); | 687 CHECK_EQ(17, r.Call()); |
688 } | 688 } |
689 | 689 |
690 TEST(Run_Wasm_Return_I32) { | 690 WASM_EXEC_TEST(Return_I32) { |
691 WasmRunner<int32_t> r(MachineType::Int32()); | 691 WasmRunner<int32_t> r(MachineType::Int32()); |
692 | 692 |
693 BUILD(r, RET(WASM_GET_LOCAL(0))); | 693 BUILD(r, RET(WASM_GET_LOCAL(0))); |
694 | 694 |
695 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 695 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
696 } | 696 } |
697 | 697 |
698 TEST(Run_Wasm_Return_F32) { | 698 WASM_EXEC_TEST(Return_F32) { |
699 WasmRunner<float> r(MachineType::Float32()); | 699 WasmRunner<float> r(MachineType::Float32()); |
700 | 700 |
701 BUILD(r, RET(WASM_GET_LOCAL(0))); | 701 BUILD(r, RET(WASM_GET_LOCAL(0))); |
702 | 702 |
703 FOR_FLOAT32_INPUTS(i) { | 703 FOR_FLOAT32_INPUTS(i) { |
704 float expect = *i; | 704 float expect = *i; |
705 float result = r.Call(expect); | 705 float result = r.Call(expect); |
706 if (std::isnan(expect)) { | 706 if (std::isnan(expect)) { |
707 CHECK(std::isnan(result)); | 707 CHECK(std::isnan(result)); |
708 } else { | 708 } else { |
709 CHECK_EQ(expect, result); | 709 CHECK_EQ(expect, result); |
710 } | 710 } |
711 } | 711 } |
712 } | 712 } |
713 | 713 |
714 TEST(Run_Wasm_Return_F64) { | 714 WASM_EXEC_TEST(Return_F64) { |
715 WasmRunner<double> r(MachineType::Float64()); | 715 WasmRunner<double> r(MachineType::Float64()); |
716 | 716 |
717 BUILD(r, RET(WASM_GET_LOCAL(0))); | 717 BUILD(r, RET(WASM_GET_LOCAL(0))); |
718 | 718 |
719 FOR_FLOAT64_INPUTS(i) { | 719 FOR_FLOAT64_INPUTS(i) { |
720 double expect = *i; | 720 double expect = *i; |
721 double result = r.Call(expect); | 721 double result = r.Call(expect); |
722 if (std::isnan(expect)) { | 722 if (std::isnan(expect)) { |
723 CHECK(std::isnan(result)); | 723 CHECK(std::isnan(result)); |
724 } else { | 724 } else { |
725 CHECK_EQ(expect, result); | 725 CHECK_EQ(expect, result); |
726 } | 726 } |
727 } | 727 } |
728 } | 728 } |
729 | 729 |
730 TEST(Run_Wasm_Select) { | 730 WASM_EXEC_TEST(Select) { |
731 WasmRunner<int32_t> r(MachineType::Int32()); | 731 WasmRunner<int32_t> r(MachineType::Int32()); |
732 // return select(11, 22, a); | 732 // return select(11, 22, a); |
733 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0))); | 733 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0))); |
734 FOR_INT32_INPUTS(i) { | 734 FOR_INT32_INPUTS(i) { |
735 int32_t expected = *i ? 11 : 22; | 735 int32_t expected = *i ? 11 : 22; |
736 CHECK_EQ(expected, r.Call(*i)); | 736 CHECK_EQ(expected, r.Call(*i)); |
737 } | 737 } |
738 } | 738 } |
739 | 739 |
740 TEST(Run_Wasm_Select_strict1) { | 740 WASM_EXEC_TEST(Select_strict1) { |
741 WasmRunner<int32_t> r(MachineType::Int32()); | 741 WasmRunner<int32_t> r(MachineType::Int32()); |
742 // select(a=0, a=1, a=2); return a | 742 // select(a=0, a=1, a=2); return a |
743 BUILD(r, B2(WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)), | 743 BUILD(r, B2(WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)), |
744 WASM_SET_LOCAL(0, WASM_I8(1)), | 744 WASM_SET_LOCAL(0, WASM_I8(1)), |
745 WASM_SET_LOCAL(0, WASM_I8(2))), | 745 WASM_SET_LOCAL(0, WASM_I8(2))), |
746 WASM_GET_LOCAL(0))); | 746 WASM_GET_LOCAL(0))); |
747 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } | 747 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } |
748 } | 748 } |
749 | 749 |
750 TEST(Run_Wasm_Select_strict2) { | 750 WASM_EXEC_TEST(Select_strict2) { |
751 WasmRunner<int32_t> r(MachineType::Int32()); | 751 WasmRunner<int32_t> r(MachineType::Int32()); |
752 r.AllocateLocal(kAstI32); | 752 r.AllocateLocal(kAstI32); |
753 r.AllocateLocal(kAstI32); | 753 r.AllocateLocal(kAstI32); |
754 // select(b=5, c=6, a) | 754 // select(b=5, c=6, a) |
755 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), | 755 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), |
756 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); | 756 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); |
757 FOR_INT32_INPUTS(i) { | 757 FOR_INT32_INPUTS(i) { |
758 int32_t expected = *i ? 5 : 6; | 758 int32_t expected = *i ? 5 : 6; |
759 CHECK_EQ(expected, r.Call(*i)); | 759 CHECK_EQ(expected, r.Call(*i)); |
760 } | 760 } |
761 } | 761 } |
762 | 762 |
763 TEST(Run_Wasm_Select_strict3) { | 763 WASM_EXEC_TEST(Select_strict3) { |
764 WasmRunner<int32_t> r(MachineType::Int32()); | 764 WasmRunner<int32_t> r(MachineType::Int32()); |
765 r.AllocateLocal(kAstI32); | 765 r.AllocateLocal(kAstI32); |
766 r.AllocateLocal(kAstI32); | 766 r.AllocateLocal(kAstI32); |
767 // select(b=5, c=6, a=b) | 767 // select(b=5, c=6, a=b) |
768 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), | 768 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), |
769 WASM_SET_LOCAL(2, WASM_I8(6)), | 769 WASM_SET_LOCAL(2, WASM_I8(6)), |
770 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1)))); | 770 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1)))); |
771 FOR_INT32_INPUTS(i) { | 771 FOR_INT32_INPUTS(i) { |
772 int32_t expected = 5; | 772 int32_t expected = 5; |
773 CHECK_EQ(expected, r.Call(*i)); | 773 CHECK_EQ(expected, r.Call(*i)); |
774 } | 774 } |
775 } | 775 } |
776 | 776 |
777 TEST(Run_Wasm_BrIf_strict) { | 777 WASM_EXEC_TEST(BrIf_strict) { |
778 WasmRunner<int32_t> r(MachineType::Int32()); | 778 WasmRunner<int32_t> r(MachineType::Int32()); |
779 BUILD( | 779 BUILD( |
780 r, | 780 r, |
781 B2(B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(99)))), | 781 B2(B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(99)))), |
782 WASM_GET_LOCAL(0))); | 782 WASM_GET_LOCAL(0))); |
783 | 783 |
784 FOR_INT32_INPUTS(i) { CHECK_EQ(99, r.Call(*i)); } | 784 FOR_INT32_INPUTS(i) { CHECK_EQ(99, r.Call(*i)); } |
785 } | 785 } |
786 | 786 |
787 TEST(Run_Wasm_BrTable0a) { | 787 WASM_EXEC_TEST(BrTable0a) { |
788 WasmRunner<int32_t> r(MachineType::Int32()); | 788 WasmRunner<int32_t> r(MachineType::Int32()); |
789 BUILD(r, | 789 BUILD(r, |
790 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), WASM_I8(91))); | 790 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), WASM_I8(91))); |
791 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } | 791 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } |
792 } | 792 } |
793 | 793 |
794 TEST(Run_Wasm_BrTable0b) { | 794 WASM_EXEC_TEST(BrTable0b) { |
795 WasmRunner<int32_t> r(MachineType::Int32()); | 795 WasmRunner<int32_t> r(MachineType::Int32()); |
796 BUILD(r, | 796 BUILD(r, |
797 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0))), | 797 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0))), |
798 WASM_I8(92))); | 798 WASM_I8(92))); |
799 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } | 799 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } |
800 } | 800 } |
801 | 801 |
802 TEST(Run_Wasm_BrTable0c) { | 802 WASM_EXEC_TEST(BrTable0c) { |
803 WasmRunner<int32_t> r(MachineType::Int32()); | 803 WasmRunner<int32_t> r(MachineType::Int32()); |
804 BUILD( | 804 BUILD( |
805 r, | 805 r, |
806 B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))), | 806 B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))), |
807 RET_I8(76)), | 807 RET_I8(76)), |
808 WASM_I8(77))); | 808 WASM_I8(77))); |
809 FOR_INT32_INPUTS(i) { | 809 FOR_INT32_INPUTS(i) { |
810 int32_t expected = *i == 0 ? 76 : 77; | 810 int32_t expected = *i == 0 ? 76 : 77; |
811 CHECK_EQ(expected, r.Call(*i)); | 811 CHECK_EQ(expected, r.Call(*i)); |
812 } | 812 } |
813 } | 813 } |
814 | 814 |
815 TEST(Run_Wasm_BrTable1) { | 815 WASM_EXEC_TEST(BrTable1) { |
816 WasmRunner<int32_t> r(MachineType::Int32()); | 816 WasmRunner<int32_t> r(MachineType::Int32()); |
817 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93)); | 817 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93)); |
818 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); } | 818 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); } |
819 } | 819 } |
820 | 820 |
821 TEST(Run_Wasm_BrTable_loop) { | 821 WASM_EXEC_TEST(BrTable_loop) { |
822 WasmRunner<int32_t> r(MachineType::Int32()); | 822 WasmRunner<int32_t> r(MachineType::Int32()); |
823 BUILD(r, | 823 BUILD(r, |
824 B2(WASM_LOOP(1, WASM_BR_TABLE(WASM_INC_LOCAL_BY(0, 1), 2, BR_TARGET(2), | 824 B2(WASM_LOOP(1, WASM_BR_TABLE(WASM_INC_LOCAL_BY(0, 1), 2, BR_TARGET(2), |
825 BR_TARGET(1), BR_TARGET(0))), | 825 BR_TARGET(1), BR_TARGET(0))), |
826 RET_I8(99)), | 826 RET_I8(99)), |
827 WASM_I8(98)); | 827 WASM_I8(98)); |
828 CHECK_EQ(99, r.Call(0)); | 828 CHECK_EQ(99, r.Call(0)); |
829 CHECK_EQ(98, r.Call(-1)); | 829 CHECK_EQ(98, r.Call(-1)); |
830 CHECK_EQ(98, r.Call(-2)); | 830 CHECK_EQ(98, r.Call(-2)); |
831 CHECK_EQ(98, r.Call(-3)); | 831 CHECK_EQ(98, r.Call(-3)); |
832 CHECK_EQ(98, r.Call(-100)); | 832 CHECK_EQ(98, r.Call(-100)); |
833 } | 833 } |
834 | 834 |
835 TEST(Run_Wasm_BrTable_br) { | 835 WASM_EXEC_TEST(BrTable_br) { |
836 WasmRunner<int32_t> r(MachineType::Int32()); | 836 WasmRunner<int32_t> r(MachineType::Int32()); |
837 BUILD(r, | 837 BUILD(r, |
838 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))), | 838 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))), |
839 RET_I8(91)), | 839 RET_I8(91)), |
840 WASM_I8(99)); | 840 WASM_I8(99)); |
841 CHECK_EQ(99, r.Call(0)); | 841 CHECK_EQ(99, r.Call(0)); |
842 CHECK_EQ(91, r.Call(1)); | 842 CHECK_EQ(91, r.Call(1)); |
843 CHECK_EQ(91, r.Call(2)); | 843 CHECK_EQ(91, r.Call(2)); |
844 CHECK_EQ(91, r.Call(3)); | 844 CHECK_EQ(91, r.Call(3)); |
845 } | 845 } |
846 | 846 |
847 TEST(Run_Wasm_BrTable_br2) { | 847 WASM_EXEC_TEST(BrTable_br2) { |
848 WasmRunner<int32_t> r(MachineType::Int32()); | 848 WasmRunner<int32_t> r(MachineType::Int32()); |
849 | 849 |
850 BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1), | 850 BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1), |
851 BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))), | 851 BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))), |
852 RET_I8(85)), | 852 RET_I8(85)), |
853 RET_I8(86)), | 853 RET_I8(86)), |
854 RET_I8(87)), | 854 RET_I8(87)), |
855 WASM_I8(88)); | 855 WASM_I8(88)); |
856 CHECK_EQ(86, r.Call(0)); | 856 CHECK_EQ(86, r.Call(0)); |
857 CHECK_EQ(87, r.Call(1)); | 857 CHECK_EQ(87, r.Call(1)); |
858 CHECK_EQ(88, r.Call(2)); | 858 CHECK_EQ(88, r.Call(2)); |
859 CHECK_EQ(85, r.Call(3)); | 859 CHECK_EQ(85, r.Call(3)); |
860 CHECK_EQ(85, r.Call(4)); | 860 CHECK_EQ(85, r.Call(4)); |
861 CHECK_EQ(85, r.Call(5)); | 861 CHECK_EQ(85, r.Call(5)); |
862 } | 862 } |
863 | 863 |
864 TEST(Run_Wasm_BrTable4) { | 864 WASM_EXEC_TEST(BrTable4) { |
865 for (int i = 0; i < 4; i++) { | 865 for (int i = 0; i < 4; i++) { |
866 for (int t = 0; t < 4; t++) { | 866 for (int t = 0; t < 4; t++) { |
867 uint32_t cases[] = {0, 1, 2, 3}; | 867 uint32_t cases[] = {0, 1, 2, 3}; |
868 cases[i] = t; | 868 cases[i] = t; |
869 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE( | 869 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE( |
870 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), | 870 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), |
871 BR_TARGET(cases[1]), BR_TARGET(cases[2]), | 871 BR_TARGET(cases[1]), BR_TARGET(cases[2]), |
872 BR_TARGET(cases[3]))), | 872 BR_TARGET(cases[3]))), |
873 RET_I8(70)), | 873 RET_I8(70)), |
874 RET_I8(71)), | 874 RET_I8(71)), |
875 RET_I8(72)), | 875 RET_I8(72)), |
876 RET_I8(73)), | 876 RET_I8(73)), |
877 WASM_I8(75)}; | 877 WASM_I8(75)}; |
878 | 878 |
879 WasmRunner<int32_t> r(MachineType::Int32()); | 879 WasmRunner<int32_t> r(MachineType::Int32()); |
880 r.Build(code, code + arraysize(code)); | 880 r.Build(code, code + arraysize(code)); |
881 | 881 |
882 for (int x = -3; x < 50; x++) { | 882 for (int x = -3; x < 50; x++) { |
883 int index = (x > 3 || x < 0) ? 3 : x; | 883 int index = (x > 3 || x < 0) ? 3 : x; |
884 int32_t expected = 70 + cases[index]; | 884 int32_t expected = 70 + cases[index]; |
885 CHECK_EQ(expected, r.Call(x)); | 885 CHECK_EQ(expected, r.Call(x)); |
886 } | 886 } |
887 } | 887 } |
888 } | 888 } |
889 } | 889 } |
890 | 890 |
891 TEST(Run_Wasm_BrTable4x4) { | 891 WASM_EXEC_TEST(BrTable4x4) { |
892 for (byte a = 0; a < 4; a++) { | 892 for (byte a = 0; a < 4; a++) { |
893 for (byte b = 0; b < 4; b++) { | 893 for (byte b = 0; b < 4; b++) { |
894 for (byte c = 0; c < 4; c++) { | 894 for (byte c = 0; c < 4; c++) { |
895 for (byte d = 0; d < 4; d++) { | 895 for (byte d = 0; d < 4; d++) { |
896 for (int i = 0; i < 4; i++) { | 896 for (int i = 0; i < 4; i++) { |
897 uint32_t cases[] = {a, b, c, d}; | 897 uint32_t cases[] = {a, b, c, d}; |
898 byte code[] = { | 898 byte code[] = { |
899 B2(B2(B2(B2(B1(WASM_BR_TABLE( | 899 B2(B2(B2(B2(B1(WASM_BR_TABLE( |
900 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), | 900 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), |
901 BR_TARGET(cases[1]), BR_TARGET(cases[2]), | 901 BR_TARGET(cases[1]), BR_TARGET(cases[2]), |
(...skipping 12 matching lines...) Expand all Loading... |
914 int32_t expected = 50 + cases[index]; | 914 int32_t expected = 50 + cases[index]; |
915 CHECK_EQ(expected, r.Call(x)); | 915 CHECK_EQ(expected, r.Call(x)); |
916 } | 916 } |
917 } | 917 } |
918 } | 918 } |
919 } | 919 } |
920 } | 920 } |
921 } | 921 } |
922 } | 922 } |
923 | 923 |
924 TEST(Run_Wasm_BrTable4_fallthru) { | 924 WASM_EXEC_TEST(BrTable4_fallthru) { |
925 byte code[] = { | 925 byte code[] = { |
926 B2(B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(0), | 926 B2(B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(0), |
927 BR_TARGET(1), BR_TARGET(2), BR_TARGET(3))), | 927 BR_TARGET(1), BR_TARGET(2), BR_TARGET(3))), |
928 WASM_INC_LOCAL_BY(1, 1)), | 928 WASM_INC_LOCAL_BY(1, 1)), |
929 WASM_INC_LOCAL_BY(1, 2)), | 929 WASM_INC_LOCAL_BY(1, 2)), |
930 WASM_INC_LOCAL_BY(1, 4)), | 930 WASM_INC_LOCAL_BY(1, 4)), |
931 WASM_INC_LOCAL_BY(1, 8)), | 931 WASM_INC_LOCAL_BY(1, 8)), |
932 WASM_GET_LOCAL(1)}; | 932 WASM_GET_LOCAL(1)}; |
933 | 933 |
934 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 934 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
935 r.Build(code, code + arraysize(code)); | 935 r.Build(code, code + arraysize(code)); |
936 | 936 |
937 CHECK_EQ(15, r.Call(0, 0)); | 937 CHECK_EQ(15, r.Call(0, 0)); |
938 CHECK_EQ(14, r.Call(1, 0)); | 938 CHECK_EQ(14, r.Call(1, 0)); |
939 CHECK_EQ(12, r.Call(2, 0)); | 939 CHECK_EQ(12, r.Call(2, 0)); |
940 CHECK_EQ(8, r.Call(3, 0)); | 940 CHECK_EQ(8, r.Call(3, 0)); |
941 CHECK_EQ(8, r.Call(4, 0)); | 941 CHECK_EQ(8, r.Call(4, 0)); |
942 | 942 |
943 CHECK_EQ(115, r.Call(0, 100)); | 943 CHECK_EQ(115, r.Call(0, 100)); |
944 CHECK_EQ(114, r.Call(1, 100)); | 944 CHECK_EQ(114, r.Call(1, 100)); |
945 CHECK_EQ(112, r.Call(2, 100)); | 945 CHECK_EQ(112, r.Call(2, 100)); |
946 CHECK_EQ(108, r.Call(3, 100)); | 946 CHECK_EQ(108, r.Call(3, 100)); |
947 CHECK_EQ(108, r.Call(4, 100)); | 947 CHECK_EQ(108, r.Call(4, 100)); |
948 } | 948 } |
949 | 949 |
950 TEST(Run_Wasm_F32ReinterpretI32) { | 950 WASM_EXEC_TEST(F32ReinterpretI32) { |
951 TestingModule module; | 951 TestingModule module; |
952 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 952 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
953 WasmRunner<int32_t> r(&module); | 953 WasmRunner<int32_t> r(&module); |
954 | 954 |
955 BUILD(r, WASM_I32_REINTERPRET_F32( | 955 BUILD(r, WASM_I32_REINTERPRET_F32( |
956 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO))); | 956 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO))); |
957 | 957 |
958 FOR_INT32_INPUTS(i) { | 958 FOR_INT32_INPUTS(i) { |
959 int32_t expected = *i; | 959 int32_t expected = *i; |
960 memory[0] = expected; | 960 memory[0] = expected; |
961 CHECK_EQ(expected, r.Call()); | 961 CHECK_EQ(expected, r.Call()); |
962 } | 962 } |
963 } | 963 } |
964 | 964 |
965 TEST(Run_Wasm_I32ReinterpretF32) { | 965 WASM_EXEC_TEST(I32ReinterpretF32) { |
966 TestingModule module; | 966 TestingModule module; |
967 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 967 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
968 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 968 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
969 | 969 |
970 BUILD(r, WASM_BLOCK( | 970 BUILD(r, WASM_BLOCK( |
971 2, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, | 971 2, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, |
972 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), | 972 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), |
973 WASM_I8(107))); | 973 WASM_I8(107))); |
974 | 974 |
975 FOR_INT32_INPUTS(i) { | 975 FOR_INT32_INPUTS(i) { |
976 int32_t expected = *i; | 976 int32_t expected = *i; |
977 CHECK_EQ(107, r.Call(expected)); | 977 CHECK_EQ(107, r.Call(expected)); |
978 CHECK_EQ(expected, memory[0]); | 978 CHECK_EQ(expected, memory[0]); |
979 } | 979 } |
980 } | 980 } |
981 | 981 |
982 TEST(Run_Wasm_ReturnStore) { | 982 WASM_EXEC_TEST(ReturnStore) { |
983 TestingModule module; | 983 TestingModule module; |
984 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 984 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
985 WasmRunner<int32_t> r(&module); | 985 WasmRunner<int32_t> r(&module); |
986 | 986 |
987 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, | 987 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, |
988 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); | 988 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); |
989 | 989 |
990 FOR_INT32_INPUTS(i) { | 990 FOR_INT32_INPUTS(i) { |
991 int32_t expected = *i; | 991 int32_t expected = *i; |
992 memory[0] = expected; | 992 memory[0] = expected; |
993 CHECK_EQ(expected, r.Call()); | 993 CHECK_EQ(expected, r.Call()); |
994 } | 994 } |
995 } | 995 } |
996 | 996 |
997 TEST(Run_Wasm_VoidReturn1) { | 997 WASM_EXEC_TEST(VoidReturn1) { |
998 // We use a wrapper function because WasmRunner<void> does not exist. | 998 // We use a wrapper function because WasmRunner<void> does not exist. |
999 | 999 |
1000 // Build the test function. | 1000 // Build the test function. |
1001 TestSignatures sigs; | 1001 TestSignatures sigs; |
1002 TestingModule module; | 1002 TestingModule module; |
1003 WasmFunctionCompiler t(sigs.v_v(), &module); | 1003 WasmFunctionCompiler t(sigs.v_v(), &module); |
1004 BUILD(t, kExprNop); | 1004 BUILD(t, kExprNop); |
1005 uint32_t index = t.CompileAndAdd(); | 1005 uint32_t index = t.CompileAndAdd(); |
1006 | 1006 |
1007 const int32_t kExpected = -414444; | 1007 const int32_t kExpected = -414444; |
1008 // Build the calling function. | 1008 // Build the calling function. |
1009 WasmRunner<int32_t> r(&module); | 1009 WasmRunner<int32_t> r(&module); |
1010 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); | 1010 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); |
1011 | 1011 |
1012 int32_t result = r.Call(); | 1012 int32_t result = r.Call(); |
1013 CHECK_EQ(kExpected, result); | 1013 CHECK_EQ(kExpected, result); |
1014 } | 1014 } |
1015 | 1015 |
1016 TEST(Run_Wasm_VoidReturn2) { | 1016 WASM_EXEC_TEST(VoidReturn2) { |
1017 // We use a wrapper function because WasmRunner<void> does not exist. | 1017 // We use a wrapper function because WasmRunner<void> does not exist. |
1018 // Build the test function. | 1018 // Build the test function. |
1019 TestSignatures sigs; | 1019 TestSignatures sigs; |
1020 TestingModule module; | 1020 TestingModule module; |
1021 WasmFunctionCompiler t(sigs.v_v(), &module); | 1021 WasmFunctionCompiler t(sigs.v_v(), &module); |
1022 BUILD(t, WASM_RETURN0); | 1022 BUILD(t, WASM_RETURN0); |
1023 uint32_t index = t.CompileAndAdd(); | 1023 uint32_t index = t.CompileAndAdd(); |
1024 | 1024 |
1025 const int32_t kExpected = -414444; | 1025 const int32_t kExpected = -414444; |
1026 // Build the calling function. | 1026 // Build the calling function. |
1027 WasmRunner<int32_t> r(&module); | 1027 WasmRunner<int32_t> r(&module); |
1028 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); | 1028 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); |
1029 | 1029 |
1030 int32_t result = r.Call(); | 1030 int32_t result = r.Call(); |
1031 CHECK_EQ(kExpected, result); | 1031 CHECK_EQ(kExpected, result); |
1032 } | 1032 } |
1033 | 1033 |
1034 TEST(Run_Wasm_Block_empty) { | 1034 WASM_EXEC_TEST(Block_empty) { |
1035 WasmRunner<int32_t> r(MachineType::Int32()); | 1035 WasmRunner<int32_t> r(MachineType::Int32()); |
1036 BUILD(r, kExprBlock, kExprEnd, WASM_GET_LOCAL(0)); | 1036 BUILD(r, kExprBlock, kExprEnd, WASM_GET_LOCAL(0)); |
1037 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1037 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1038 } | 1038 } |
1039 | 1039 |
1040 TEST(Run_Wasm_Block_empty_br1) { | 1040 WASM_EXEC_TEST(Block_empty_br1) { |
1041 WasmRunner<int32_t> r(MachineType::Int32()); | 1041 WasmRunner<int32_t> r(MachineType::Int32()); |
1042 BUILD(r, B1(WASM_BR(0)), WASM_GET_LOCAL(0)); | 1042 BUILD(r, B1(WASM_BR(0)), WASM_GET_LOCAL(0)); |
1043 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1043 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1044 } | 1044 } |
1045 | 1045 |
1046 TEST(Run_Wasm_Block_empty_brif1) { | 1046 WASM_EXEC_TEST(Block_empty_brif1) { |
1047 WasmRunner<int32_t> r(MachineType::Int32()); | 1047 WasmRunner<int32_t> r(MachineType::Int32()); |
1048 BUILD(r, B1(WASM_BR_IF(0, WASM_ZERO)), WASM_GET_LOCAL(0)); | 1048 BUILD(r, B1(WASM_BR_IF(0, WASM_ZERO)), WASM_GET_LOCAL(0)); |
1049 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1049 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1050 } | 1050 } |
1051 | 1051 |
1052 TEST(Run_Wasm_Block_empty_brif2) { | 1052 WASM_EXEC_TEST(Block_empty_brif2) { |
1053 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 1053 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); |
1054 BUILD(r, B1(WASM_BR_IF(0, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); | 1054 BUILD(r, B1(WASM_BR_IF(0, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); |
1055 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } | 1055 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } |
1056 } | 1056 } |
1057 | 1057 |
1058 TEST(Run_Wasm_Block_br2) { | 1058 WASM_EXEC_TEST(Block_br2) { |
1059 WasmRunner<int32_t> r(MachineType::Int32()); | 1059 WasmRunner<int32_t> r(MachineType::Int32()); |
1060 BUILD(r, B1(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 1060 BUILD(r, B1(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
1061 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1061 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1062 } | 1062 } |
1063 | 1063 |
1064 TEST(Run_Wasm_Block_If_P) { | 1064 WASM_EXEC_TEST(Block_If_P) { |
1065 WasmRunner<int32_t> r(MachineType::Int32()); | 1065 WasmRunner<int32_t> r(MachineType::Int32()); |
1066 // { if (p0) return 51; return 52; } | 1066 // { if (p0) return 51; return 52; } |
1067 BUILD(r, B2( // -- | 1067 BUILD(r, B2( // -- |
1068 WASM_IF(WASM_GET_LOCAL(0), // -- | 1068 WASM_IF(WASM_GET_LOCAL(0), // -- |
1069 WASM_BRV(1, WASM_I8(51))), // -- | 1069 WASM_BRV(1, WASM_I8(51))), // -- |
1070 WASM_I8(52))); // -- | 1070 WASM_I8(52))); // -- |
1071 FOR_INT32_INPUTS(i) { | 1071 FOR_INT32_INPUTS(i) { |
1072 int32_t expected = *i ? 51 : 52; | 1072 int32_t expected = *i ? 51 : 52; |
1073 CHECK_EQ(expected, r.Call(*i)); | 1073 CHECK_EQ(expected, r.Call(*i)); |
1074 } | 1074 } |
1075 } | 1075 } |
1076 | 1076 |
1077 TEST(Run_Wasm_Loop_empty) { | 1077 WASM_EXEC_TEST(Loop_empty) { |
1078 WasmRunner<int32_t> r(MachineType::Int32()); | 1078 WasmRunner<int32_t> r(MachineType::Int32()); |
1079 BUILD(r, kExprLoop, kExprEnd, WASM_GET_LOCAL(0)); | 1079 BUILD(r, kExprLoop, kExprEnd, WASM_GET_LOCAL(0)); |
1080 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1080 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1081 } | 1081 } |
1082 | 1082 |
1083 TEST(Run_Wasm_Loop_empty_br1) { | 1083 WASM_EXEC_TEST(Loop_empty_br1) { |
1084 WasmRunner<int32_t> r(MachineType::Int32()); | 1084 WasmRunner<int32_t> r(MachineType::Int32()); |
1085 BUILD(r, WASM_LOOP(1, WASM_BR(1)), WASM_GET_LOCAL(0)); | 1085 BUILD(r, WASM_LOOP(1, WASM_BR(1)), WASM_GET_LOCAL(0)); |
1086 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1086 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1087 } | 1087 } |
1088 | 1088 |
1089 TEST(Run_Wasm_Loop_empty_brif1) { | 1089 WASM_EXEC_TEST(Loop_empty_brif1) { |
1090 WasmRunner<int32_t> r(MachineType::Int32()); | 1090 WasmRunner<int32_t> r(MachineType::Int32()); |
1091 BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_ZERO)), WASM_GET_LOCAL(0)); | 1091 BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_ZERO)), WASM_GET_LOCAL(0)); |
1092 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1092 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1093 } | 1093 } |
1094 | 1094 |
1095 TEST(Run_Wasm_Loop_empty_brif2) { | 1095 WASM_EXEC_TEST(Loop_empty_brif2) { |
1096 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 1096 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); |
1097 BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); | 1097 BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); |
1098 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } | 1098 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } |
1099 } | 1099 } |
1100 | 1100 |
1101 TEST(Run_Wasm_Block_BrIf_P) { | 1101 WASM_EXEC_TEST(Block_BrIf_P) { |
1102 WasmRunner<int32_t> r(MachineType::Int32()); | 1102 WasmRunner<int32_t> r(MachineType::Int32()); |
1103 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)), WASM_I8(52))); | 1103 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)), WASM_I8(52))); |
1104 FOR_INT32_INPUTS(i) { | 1104 FOR_INT32_INPUTS(i) { |
1105 int32_t expected = *i ? 51 : 52; | 1105 int32_t expected = *i ? 51 : 52; |
1106 CHECK_EQ(expected, r.Call(*i)); | 1106 CHECK_EQ(expected, r.Call(*i)); |
1107 } | 1107 } |
1108 } | 1108 } |
1109 | 1109 |
1110 TEST(Run_Wasm_Block_IfElse_P_assign) { | 1110 WASM_EXEC_TEST(Block_IfElse_P_assign) { |
1111 WasmRunner<int32_t> r(MachineType::Int32()); | 1111 WasmRunner<int32_t> r(MachineType::Int32()); |
1112 // { if (p0) p0 = 71; else p0 = 72; return p0; } | 1112 // { if (p0) p0 = 71; else p0 = 72; return p0; } |
1113 BUILD(r, B2( // -- | 1113 BUILD(r, B2( // -- |
1114 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1114 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1115 WASM_SET_LOCAL(0, WASM_I8(71)), // -- | 1115 WASM_SET_LOCAL(0, WASM_I8(71)), // -- |
1116 WASM_SET_LOCAL(0, WASM_I8(72))), // -- | 1116 WASM_SET_LOCAL(0, WASM_I8(72))), // -- |
1117 WASM_GET_LOCAL(0))); | 1117 WASM_GET_LOCAL(0))); |
1118 FOR_INT32_INPUTS(i) { | 1118 FOR_INT32_INPUTS(i) { |
1119 int32_t expected = *i ? 71 : 72; | 1119 int32_t expected = *i ? 71 : 72; |
1120 CHECK_EQ(expected, r.Call(*i)); | 1120 CHECK_EQ(expected, r.Call(*i)); |
1121 } | 1121 } |
1122 } | 1122 } |
1123 | 1123 |
1124 TEST(Run_Wasm_Block_IfElse_P_return) { | 1124 WASM_EXEC_TEST(Block_IfElse_P_return) { |
1125 WasmRunner<int32_t> r(MachineType::Int32()); | 1125 WasmRunner<int32_t> r(MachineType::Int32()); |
1126 // if (p0) return 81; else return 82; | 1126 // if (p0) return 81; else return 82; |
1127 BUILD(r, // -- | 1127 BUILD(r, // -- |
1128 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1128 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1129 RET_I8(81), // -- | 1129 RET_I8(81), // -- |
1130 RET_I8(82))); // -- | 1130 RET_I8(82))); // -- |
1131 FOR_INT32_INPUTS(i) { | 1131 FOR_INT32_INPUTS(i) { |
1132 int32_t expected = *i ? 81 : 82; | 1132 int32_t expected = *i ? 81 : 82; |
1133 CHECK_EQ(expected, r.Call(*i)); | 1133 CHECK_EQ(expected, r.Call(*i)); |
1134 } | 1134 } |
1135 } | 1135 } |
1136 | 1136 |
1137 TEST(Run_Wasm_Block_If_P_assign) { | 1137 WASM_EXEC_TEST(Block_If_P_assign) { |
1138 WasmRunner<int32_t> r(MachineType::Int32()); | 1138 WasmRunner<int32_t> r(MachineType::Int32()); |
1139 // { if (p0) p0 = 61; p0; } | 1139 // { if (p0) p0 = 61; p0; } |
1140 BUILD(r, WASM_BLOCK( | 1140 BUILD(r, WASM_BLOCK( |
1141 2, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))), | 1141 2, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))), |
1142 WASM_GET_LOCAL(0))); | 1142 WASM_GET_LOCAL(0))); |
1143 FOR_INT32_INPUTS(i) { | 1143 FOR_INT32_INPUTS(i) { |
1144 int32_t expected = *i ? 61 : *i; | 1144 int32_t expected = *i ? 61 : *i; |
1145 CHECK_EQ(expected, r.Call(*i)); | 1145 CHECK_EQ(expected, r.Call(*i)); |
1146 } | 1146 } |
1147 } | 1147 } |
1148 | 1148 |
1149 TEST(Run_Wasm_DanglingAssign) { | 1149 WASM_EXEC_TEST(DanglingAssign) { |
1150 WasmRunner<int32_t> r(MachineType::Int32()); | 1150 WasmRunner<int32_t> r(MachineType::Int32()); |
1151 // { return 0; p0 = 0; } | 1151 // { return 0; p0 = 0; } |
1152 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO))); | 1152 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO))); |
1153 CHECK_EQ(99, r.Call(1)); | 1153 CHECK_EQ(99, r.Call(1)); |
1154 } | 1154 } |
1155 | 1155 |
1156 TEST(Run_Wasm_ExprIf_P) { | 1156 WASM_EXEC_TEST(ExprIf_P) { |
1157 WasmRunner<int32_t> r(MachineType::Int32()); | 1157 WasmRunner<int32_t> r(MachineType::Int32()); |
1158 // p0 ? 11 : 22; | 1158 // p0 ? 11 : 22; |
1159 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1159 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1160 WASM_I8(11), // -- | 1160 WASM_I8(11), // -- |
1161 WASM_I8(22))); // -- | 1161 WASM_I8(22))); // -- |
1162 FOR_INT32_INPUTS(i) { | 1162 FOR_INT32_INPUTS(i) { |
1163 int32_t expected = *i ? 11 : 22; | 1163 int32_t expected = *i ? 11 : 22; |
1164 CHECK_EQ(expected, r.Call(*i)); | 1164 CHECK_EQ(expected, r.Call(*i)); |
1165 } | 1165 } |
1166 } | 1166 } |
1167 | 1167 |
1168 TEST(Run_Wasm_ExprIf_P_fallthru) { | 1168 WASM_EXEC_TEST(ExprIf_P_fallthru) { |
1169 WasmRunner<int32_t> r(MachineType::Int32()); | 1169 WasmRunner<int32_t> r(MachineType::Int32()); |
1170 // p0 ? 11 : 22; | 1170 // p0 ? 11 : 22; |
1171 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1171 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1172 WASM_I8(11), // -- | 1172 WASM_I8(11), // -- |
1173 WASM_I8(22))); // -- | 1173 WASM_I8(22))); // -- |
1174 FOR_INT32_INPUTS(i) { | 1174 FOR_INT32_INPUTS(i) { |
1175 int32_t expected = *i ? 11 : 22; | 1175 int32_t expected = *i ? 11 : 22; |
1176 CHECK_EQ(expected, r.Call(*i)); | 1176 CHECK_EQ(expected, r.Call(*i)); |
1177 } | 1177 } |
1178 } | 1178 } |
1179 | 1179 |
1180 TEST(Run_Wasm_CountDown) { | 1180 WASM_EXEC_TEST(CountDown) { |
1181 WasmRunner<int32_t> r(MachineType::Int32()); | 1181 WasmRunner<int32_t> r(MachineType::Int32()); |
1182 BUILD(r, | 1182 BUILD(r, |
1183 WASM_BLOCK( | 1183 WASM_BLOCK( |
1184 2, WASM_LOOP( | 1184 2, WASM_LOOP( |
1185 1, WASM_IF(WASM_GET_LOCAL(0), | 1185 1, WASM_IF(WASM_GET_LOCAL(0), |
1186 WASM_BRV(1, WASM_SET_LOCAL( | 1186 WASM_BRV(1, WASM_SET_LOCAL( |
1187 0, WASM_I32_SUB(WASM_GET_LOCAL(0), | 1187 0, WASM_I32_SUB(WASM_GET_LOCAL(0), |
1188 WASM_I8(1)))))), | 1188 WASM_I8(1)))))), |
1189 WASM_GET_LOCAL(0))); | 1189 WASM_GET_LOCAL(0))); |
1190 CHECK_EQ(0, r.Call(1)); | 1190 CHECK_EQ(0, r.Call(1)); |
1191 CHECK_EQ(0, r.Call(10)); | 1191 CHECK_EQ(0, r.Call(10)); |
1192 CHECK_EQ(0, r.Call(100)); | 1192 CHECK_EQ(0, r.Call(100)); |
1193 } | 1193 } |
1194 | 1194 |
1195 TEST(Run_Wasm_CountDown_fallthru) { | 1195 WASM_EXEC_TEST(CountDown_fallthru) { |
1196 WasmRunner<int32_t> r(MachineType::Int32()); | 1196 WasmRunner<int32_t> r(MachineType::Int32()); |
1197 BUILD(r, | 1197 BUILD(r, |
1198 WASM_BLOCK( | 1198 WASM_BLOCK( |
1199 2, WASM_LOOP(3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), WASM_BREAK(1)), | 1199 2, WASM_LOOP(3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), WASM_BREAK(1)), |
1200 WASM_SET_LOCAL( | 1200 WASM_SET_LOCAL( |
1201 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), | 1201 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), |
1202 WASM_CONTINUE(0)), | 1202 WASM_CONTINUE(0)), |
1203 WASM_GET_LOCAL(0))); | 1203 WASM_GET_LOCAL(0))); |
1204 CHECK_EQ(0, r.Call(1)); | 1204 CHECK_EQ(0, r.Call(1)); |
1205 CHECK_EQ(0, r.Call(10)); | 1205 CHECK_EQ(0, r.Call(10)); |
1206 CHECK_EQ(0, r.Call(100)); | 1206 CHECK_EQ(0, r.Call(100)); |
1207 } | 1207 } |
1208 | 1208 |
1209 TEST(Run_Wasm_WhileCountDown) { | 1209 WASM_EXEC_TEST(WhileCountDown) { |
1210 WasmRunner<int32_t> r(MachineType::Int32()); | 1210 WasmRunner<int32_t> r(MachineType::Int32()); |
1211 BUILD(r, WASM_BLOCK( | 1211 BUILD(r, WASM_BLOCK( |
1212 2, WASM_WHILE(WASM_GET_LOCAL(0), | 1212 2, WASM_WHILE(WASM_GET_LOCAL(0), |
1213 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), | 1213 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), |
1214 WASM_I8(1)))), | 1214 WASM_I8(1)))), |
1215 WASM_GET_LOCAL(0))); | 1215 WASM_GET_LOCAL(0))); |
1216 CHECK_EQ(0, r.Call(1)); | 1216 CHECK_EQ(0, r.Call(1)); |
1217 CHECK_EQ(0, r.Call(10)); | 1217 CHECK_EQ(0, r.Call(10)); |
1218 CHECK_EQ(0, r.Call(100)); | 1218 CHECK_EQ(0, r.Call(100)); |
1219 } | 1219 } |
1220 | 1220 |
1221 TEST(Run_Wasm_Loop_if_break1) { | 1221 WASM_EXEC_TEST(Loop_if_break1) { |
1222 WasmRunner<int32_t> r(MachineType::Int32()); | 1222 WasmRunner<int32_t> r(MachineType::Int32()); |
1223 BUILD(r, B2(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), | 1223 BUILD(r, B2(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), |
1224 WASM_SET_LOCAL(0, WASM_I8(99))), | 1224 WASM_SET_LOCAL(0, WASM_I8(99))), |
1225 WASM_GET_LOCAL(0))); | 1225 WASM_GET_LOCAL(0))); |
1226 CHECK_EQ(99, r.Call(0)); | 1226 CHECK_EQ(99, r.Call(0)); |
1227 CHECK_EQ(3, r.Call(3)); | 1227 CHECK_EQ(3, r.Call(3)); |
1228 CHECK_EQ(10000, r.Call(10000)); | 1228 CHECK_EQ(10000, r.Call(10000)); |
1229 CHECK_EQ(-29, r.Call(-29)); | 1229 CHECK_EQ(-29, r.Call(-29)); |
1230 } | 1230 } |
1231 | 1231 |
1232 TEST(Run_Wasm_Loop_if_break2) { | 1232 WASM_EXEC_TEST(Loop_if_break2) { |
1233 WasmRunner<int32_t> r(MachineType::Int32()); | 1233 WasmRunner<int32_t> r(MachineType::Int32()); |
1234 BUILD(r, B2(WASM_LOOP(2, WASM_BR_IF(1, WASM_GET_LOCAL(0)), | 1234 BUILD(r, B2(WASM_LOOP(2, WASM_BR_IF(1, WASM_GET_LOCAL(0)), |
1235 WASM_SET_LOCAL(0, WASM_I8(99))), | 1235 WASM_SET_LOCAL(0, WASM_I8(99))), |
1236 WASM_GET_LOCAL(0))); | 1236 WASM_GET_LOCAL(0))); |
1237 CHECK_EQ(99, r.Call(0)); | 1237 CHECK_EQ(99, r.Call(0)); |
1238 CHECK_EQ(3, r.Call(3)); | 1238 CHECK_EQ(3, r.Call(3)); |
1239 CHECK_EQ(10000, r.Call(10000)); | 1239 CHECK_EQ(10000, r.Call(10000)); |
1240 CHECK_EQ(-29, r.Call(-29)); | 1240 CHECK_EQ(-29, r.Call(-29)); |
1241 } | 1241 } |
1242 | 1242 |
1243 TEST(Run_Wasm_Loop_if_break_fallthru) { | 1243 WASM_EXEC_TEST(Loop_if_break_fallthru) { |
1244 WasmRunner<int32_t> r(MachineType::Int32()); | 1244 WasmRunner<int32_t> r(MachineType::Int32()); |
1245 BUILD(r, B1(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), | 1245 BUILD(r, B1(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), |
1246 WASM_SET_LOCAL(0, WASM_I8(93)))), | 1246 WASM_SET_LOCAL(0, WASM_I8(93)))), |
1247 WASM_GET_LOCAL(0)); | 1247 WASM_GET_LOCAL(0)); |
1248 CHECK_EQ(93, r.Call(0)); | 1248 CHECK_EQ(93, r.Call(0)); |
1249 CHECK_EQ(3, r.Call(3)); | 1249 CHECK_EQ(3, r.Call(3)); |
1250 CHECK_EQ(10001, r.Call(10001)); | 1250 CHECK_EQ(10001, r.Call(10001)); |
1251 CHECK_EQ(-22, r.Call(-22)); | 1251 CHECK_EQ(-22, r.Call(-22)); |
1252 } | 1252 } |
1253 | 1253 |
1254 TEST(Run_Wasm_IfBreak1) { | 1254 WASM_EXEC_TEST(IfBreak1) { |
1255 WasmRunner<int32_t> r(MachineType::Int32()); | 1255 WasmRunner<int32_t> r(MachineType::Int32()); |
1256 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)), | 1256 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)), |
1257 WASM_I8(91)); | 1257 WASM_I8(91)); |
1258 CHECK_EQ(91, r.Call(0)); | 1258 CHECK_EQ(91, r.Call(0)); |
1259 CHECK_EQ(91, r.Call(1)); | 1259 CHECK_EQ(91, r.Call(1)); |
1260 CHECK_EQ(91, r.Call(-8734)); | 1260 CHECK_EQ(91, r.Call(-8734)); |
1261 } | 1261 } |
1262 | 1262 |
1263 TEST(Run_Wasm_IfBreak2) { | 1263 WASM_EXEC_TEST(IfBreak2) { |
1264 WasmRunner<int32_t> r(MachineType::Int32()); | 1264 WasmRunner<int32_t> r(MachineType::Int32()); |
1265 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))), | 1265 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))), |
1266 WASM_I8(81)); | 1266 WASM_I8(81)); |
1267 CHECK_EQ(81, r.Call(0)); | 1267 CHECK_EQ(81, r.Call(0)); |
1268 CHECK_EQ(81, r.Call(1)); | 1268 CHECK_EQ(81, r.Call(1)); |
1269 CHECK_EQ(81, r.Call(-8734)); | 1269 CHECK_EQ(81, r.Call(-8734)); |
1270 } | 1270 } |
1271 | 1271 |
1272 TEST(Run_Wasm_LoadMemI32) { | 1272 WASM_EXEC_TEST(LoadMemI32) { |
1273 TestingModule module; | 1273 TestingModule module; |
1274 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1274 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1275 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1275 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1276 module.RandomizeMemory(1111); | 1276 module.RandomizeMemory(1111); |
1277 | 1277 |
1278 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); | 1278 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); |
1279 | 1279 |
1280 memory[0] = 99999999; | 1280 memory[0] = 99999999; |
1281 CHECK_EQ(99999999, r.Call(0)); | 1281 CHECK_EQ(99999999, r.Call(0)); |
1282 | 1282 |
1283 memory[0] = 88888888; | 1283 memory[0] = 88888888; |
1284 CHECK_EQ(88888888, r.Call(0)); | 1284 CHECK_EQ(88888888, r.Call(0)); |
1285 | 1285 |
1286 memory[0] = 77777777; | 1286 memory[0] = 77777777; |
1287 CHECK_EQ(77777777, r.Call(0)); | 1287 CHECK_EQ(77777777, r.Call(0)); |
1288 } | 1288 } |
1289 | 1289 |
1290 TEST(Run_Wasm_LoadMemI32_oob) { | 1290 WASM_EXEC_TEST(LoadMemI32_oob) { |
1291 TestingModule module; | 1291 TestingModule module; |
1292 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1292 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1293 WasmRunner<int32_t> r(&module, MachineType::Uint32()); | 1293 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1294 module.RandomizeMemory(1111); | 1294 module.RandomizeMemory(1111); |
1295 | 1295 |
1296 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); | 1296 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); |
1297 | 1297 |
1298 memory[0] = 88888888; | 1298 memory[0] = 88888888; |
1299 CHECK_EQ(88888888, r.Call(0u)); | 1299 CHECK_EQ(88888888, r.Call(0u)); |
1300 for (uint32_t offset = 29; offset < 40; offset++) { | 1300 for (uint32_t offset = 29; offset < 40; offset++) { |
1301 CHECK_TRAP(r.Call(offset)); | 1301 CHECK_TRAP(r.Call(offset)); |
1302 } | 1302 } |
1303 | 1303 |
1304 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 1304 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
1305 CHECK_TRAP(r.Call(offset)); | 1305 CHECK_TRAP(r.Call(offset)); |
1306 } | 1306 } |
1307 } | 1307 } |
1308 | 1308 |
1309 TEST(Run_Wasm_LoadMem_offset_oob) { | 1309 WASM_EXEC_TEST(LoadMem_offset_oob) { |
1310 TestingModule module; | 1310 TestingModule module; |
1311 module.AddMemoryElems<int32_t>(8); | 1311 module.AddMemoryElems<int32_t>(8); |
1312 | 1312 |
1313 static const MachineType machineTypes[] = { | 1313 static const MachineType machineTypes[] = { |
1314 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 1314 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
1315 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 1315 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
1316 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), | 1316 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
1317 MachineType::Float64()}; | 1317 MachineType::Float64()}; |
1318 | 1318 |
1319 for (size_t m = 0; m < arraysize(machineTypes); m++) { | 1319 for (size_t m = 0; m < arraysize(machineTypes); m++) { |
1320 module.RandomizeMemory(1116 + static_cast<int>(m)); | 1320 module.RandomizeMemory(1116 + static_cast<int>(m)); |
1321 WasmRunner<int32_t> r(&module, MachineType::Uint32()); | 1321 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1322 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]); | 1322 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]); |
1323 | 1323 |
1324 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)), | 1324 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)), |
1325 WASM_ZERO); | 1325 WASM_ZERO); |
1326 | 1326 |
1327 CHECK_EQ(0, r.Call(boundary)); // in bounds. | 1327 CHECK_EQ(0, r.Call(boundary)); // in bounds. |
1328 | 1328 |
1329 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { | 1329 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { |
1330 CHECK_TRAP(r.Call(offset)); // out of bounds. | 1330 CHECK_TRAP(r.Call(offset)); // out of bounds. |
1331 } | 1331 } |
1332 } | 1332 } |
1333 } | 1333 } |
1334 | 1334 |
1335 TEST(Run_Wasm_LoadMemI32_offset) { | 1335 WASM_EXEC_TEST(LoadMemI32_offset) { |
1336 TestingModule module; | 1336 TestingModule module; |
1337 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1337 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
1338 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1338 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1339 module.RandomizeMemory(1111); | 1339 module.RandomizeMemory(1111); |
1340 | 1340 |
1341 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0))); | 1341 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0))); |
1342 | 1342 |
1343 memory[0] = 66666666; | 1343 memory[0] = 66666666; |
1344 memory[1] = 77777777; | 1344 memory[1] = 77777777; |
1345 memory[2] = 88888888; | 1345 memory[2] = 88888888; |
1346 memory[3] = 99999999; | 1346 memory[3] = 99999999; |
1347 CHECK_EQ(77777777, r.Call(0)); | 1347 CHECK_EQ(77777777, r.Call(0)); |
1348 CHECK_EQ(88888888, r.Call(4)); | 1348 CHECK_EQ(88888888, r.Call(4)); |
1349 CHECK_EQ(99999999, r.Call(8)); | 1349 CHECK_EQ(99999999, r.Call(8)); |
1350 | 1350 |
1351 memory[0] = 11111111; | 1351 memory[0] = 11111111; |
1352 memory[1] = 22222222; | 1352 memory[1] = 22222222; |
1353 memory[2] = 33333333; | 1353 memory[2] = 33333333; |
1354 memory[3] = 44444444; | 1354 memory[3] = 44444444; |
1355 CHECK_EQ(22222222, r.Call(0)); | 1355 CHECK_EQ(22222222, r.Call(0)); |
1356 CHECK_EQ(33333333, r.Call(4)); | 1356 CHECK_EQ(33333333, r.Call(4)); |
1357 CHECK_EQ(44444444, r.Call(8)); | 1357 CHECK_EQ(44444444, r.Call(8)); |
1358 } | 1358 } |
1359 | 1359 |
1360 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 | 1360 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 |
1361 | 1361 |
1362 TEST(Run_Wasm_LoadMemI32_const_oob_misaligned) { | 1362 WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { |
1363 const int kMemSize = 12; | 1363 const int kMemSize = 12; |
1364 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. | 1364 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. |
1365 for (int offset = 0; offset < kMemSize + 5; offset++) { | 1365 for (int offset = 0; offset < kMemSize + 5; offset++) { |
1366 for (int index = 0; index < kMemSize + 5; index++) { | 1366 for (int index = 0; index < kMemSize + 5; index++) { |
1367 TestingModule module; | 1367 TestingModule module; |
1368 module.AddMemoryElems<byte>(kMemSize); | 1368 module.AddMemoryElems<byte>(kMemSize); |
1369 | 1369 |
1370 WasmRunner<int32_t> r(&module); | 1370 WasmRunner<int32_t> r(&module); |
1371 module.RandomizeMemory(); | 1371 module.RandomizeMemory(); |
1372 | 1372 |
1373 BUILD(r, | 1373 BUILD(r, |
1374 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1374 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); |
1375 | 1375 |
1376 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { | 1376 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { |
1377 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); | 1377 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); |
1378 } else { | 1378 } else { |
1379 CHECK_TRAP(r.Call()); | 1379 CHECK_TRAP(r.Call()); |
1380 } | 1380 } |
1381 } | 1381 } |
1382 } | 1382 } |
1383 } | 1383 } |
1384 | 1384 |
1385 #endif | 1385 #endif |
1386 | 1386 |
1387 TEST(Run_Wasm_LoadMemI32_const_oob) { | 1387 WASM_EXEC_TEST(LoadMemI32_const_oob) { |
1388 const int kMemSize = 24; | 1388 const int kMemSize = 24; |
1389 for (int offset = 0; offset < kMemSize + 5; offset += 4) { | 1389 for (int offset = 0; offset < kMemSize + 5; offset += 4) { |
1390 for (int index = 0; index < kMemSize + 5; index += 4) { | 1390 for (int index = 0; index < kMemSize + 5; index += 4) { |
1391 TestingModule module; | 1391 TestingModule module; |
1392 module.AddMemoryElems<byte>(kMemSize); | 1392 module.AddMemoryElems<byte>(kMemSize); |
1393 | 1393 |
1394 WasmRunner<int32_t> r(&module); | 1394 WasmRunner<int32_t> r(&module); |
1395 module.RandomizeMemory(); | 1395 module.RandomizeMemory(); |
1396 | 1396 |
1397 BUILD(r, | 1397 BUILD(r, |
1398 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1398 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); |
1399 | 1399 |
1400 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { | 1400 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { |
1401 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); | 1401 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); |
1402 } else { | 1402 } else { |
1403 CHECK_TRAP(r.Call()); | 1403 CHECK_TRAP(r.Call()); |
1404 } | 1404 } |
1405 } | 1405 } |
1406 } | 1406 } |
1407 } | 1407 } |
1408 | 1408 |
1409 TEST(Run_Wasm_StoreMemI32_offset) { | 1409 WASM_EXEC_TEST(StoreMemI32_offset) { |
1410 TestingModule module; | 1410 TestingModule module; |
1411 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1411 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
1412 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1412 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1413 const int32_t kWritten = 0xaabbccdd; | 1413 const int32_t kWritten = 0xaabbccdd; |
1414 | 1414 |
1415 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), | 1415 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), |
1416 WASM_I32V_5(kWritten))); | 1416 WASM_I32V_5(kWritten))); |
1417 | 1417 |
1418 for (int i = 0; i < 2; i++) { | 1418 for (int i = 0; i < 2; i++) { |
1419 module.RandomizeMemory(1111); | 1419 module.RandomizeMemory(1111); |
1420 memory[0] = 66666666; | 1420 memory[0] = 66666666; |
1421 memory[1] = 77777777; | 1421 memory[1] = 77777777; |
1422 memory[2] = 88888888; | 1422 memory[2] = 88888888; |
1423 memory[3] = 99999999; | 1423 memory[3] = 99999999; |
1424 CHECK_EQ(kWritten, r.Call(i * 4)); | 1424 CHECK_EQ(kWritten, r.Call(i * 4)); |
1425 CHECK_EQ(66666666, memory[0]); | 1425 CHECK_EQ(66666666, memory[0]); |
1426 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]); | 1426 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]); |
1427 CHECK_EQ(i == 1 ? kWritten : 88888888, memory[2]); | 1427 CHECK_EQ(i == 1 ? kWritten : 88888888, memory[2]); |
1428 CHECK_EQ(i == 2 ? kWritten : 99999999, memory[3]); | 1428 CHECK_EQ(i == 2 ? kWritten : 99999999, memory[3]); |
1429 } | 1429 } |
1430 } | 1430 } |
1431 | 1431 |
1432 TEST(Run_Wasm_StoreMem_offset_oob) { | 1432 WASM_EXEC_TEST(StoreMem_offset_oob) { |
1433 TestingModule module; | 1433 TestingModule module; |
1434 byte* memory = module.AddMemoryElems<byte>(32); | 1434 byte* memory = module.AddMemoryElems<byte>(32); |
1435 | 1435 |
1436 #if WASM_64 | 1436 #if WASM_64 |
1437 static const MachineType machineTypes[] = { | 1437 static const MachineType machineTypes[] = { |
1438 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 1438 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
1439 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 1439 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
1440 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), | 1440 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
1441 MachineType::Float64()}; | 1441 MachineType::Float64()}; |
1442 #else | 1442 #else |
(...skipping 15 matching lines...) Expand all Loading... |
1458 uint32_t boundary = 24 - memsize; | 1458 uint32_t boundary = 24 - memsize; |
1459 CHECK_EQ(0, r.Call(boundary)); // in bounds. | 1459 CHECK_EQ(0, r.Call(boundary)); // in bounds. |
1460 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); | 1460 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); |
1461 | 1461 |
1462 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { | 1462 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { |
1463 CHECK_TRAP(r.Call(offset)); // out of bounds. | 1463 CHECK_TRAP(r.Call(offset)); // out of bounds. |
1464 } | 1464 } |
1465 } | 1465 } |
1466 } | 1466 } |
1467 | 1467 |
1468 TEST(Run_Wasm_LoadMemI32_P) { | 1468 WASM_EXEC_TEST(LoadMemI32_P) { |
1469 const int kNumElems = 8; | 1469 const int kNumElems = 8; |
1470 TestingModule module; | 1470 TestingModule module; |
1471 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems); | 1471 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems); |
1472 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1472 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1473 module.RandomizeMemory(2222); | 1473 module.RandomizeMemory(2222); |
1474 | 1474 |
1475 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); | 1475 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); |
1476 | 1476 |
1477 for (int i = 0; i < kNumElems; i++) { | 1477 for (int i = 0; i < kNumElems; i++) { |
1478 CHECK_EQ(memory[i], r.Call(i * 4)); | 1478 CHECK_EQ(memory[i], r.Call(i * 4)); |
1479 } | 1479 } |
1480 } | 1480 } |
1481 | 1481 |
1482 TEST(Run_Wasm_MemI32_Sum) { | 1482 WASM_EXEC_TEST(MemI32_Sum) { |
1483 const int kNumElems = 20; | 1483 const int kNumElems = 20; |
1484 TestingModule module; | 1484 TestingModule module; |
1485 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems); | 1485 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems); |
1486 WasmRunner<uint32_t> r(&module, MachineType::Int32()); | 1486 WasmRunner<uint32_t> r(&module, MachineType::Int32()); |
1487 const byte kSum = r.AllocateLocal(kAstI32); | 1487 const byte kSum = r.AllocateLocal(kAstI32); |
1488 | 1488 |
1489 BUILD(r, WASM_BLOCK( | 1489 BUILD(r, WASM_BLOCK( |
1490 2, WASM_WHILE( | 1490 2, WASM_WHILE( |
1491 WASM_GET_LOCAL(0), | 1491 WASM_GET_LOCAL(0), |
1492 WASM_BLOCK( | 1492 WASM_BLOCK( |
(...skipping 11 matching lines...) Expand all Loading... |
1504 module.RandomizeMemory(i * 33); | 1504 module.RandomizeMemory(i * 33); |
1505 uint32_t expected = 0; | 1505 uint32_t expected = 0; |
1506 for (size_t j = kNumElems - 1; j > 0; j--) { | 1506 for (size_t j = kNumElems - 1; j > 0; j--) { |
1507 expected += memory[j]; | 1507 expected += memory[j]; |
1508 } | 1508 } |
1509 uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1))); | 1509 uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1))); |
1510 CHECK_EQ(expected, result); | 1510 CHECK_EQ(expected, result); |
1511 } | 1511 } |
1512 } | 1512 } |
1513 | 1513 |
1514 TEST(Run_Wasm_CheckMachIntsZero) { | 1514 WASM_EXEC_TEST(CheckMachIntsZero) { |
1515 const int kNumElems = 55; | 1515 const int kNumElems = 55; |
1516 TestingModule module; | 1516 TestingModule module; |
1517 module.AddMemoryElems<uint32_t>(kNumElems); | 1517 module.AddMemoryElems<uint32_t>(kNumElems); |
1518 WasmRunner<uint32_t> r(&module, MachineType::Int32()); | 1518 WasmRunner<uint32_t> r(&module, MachineType::Int32()); |
1519 | 1519 |
1520 BUILD(r, kExprLoop, kExprGetLocal, 0, kExprIf, kExprGetLocal, 0, | 1520 BUILD(r, kExprLoop, kExprGetLocal, 0, kExprIf, kExprGetLocal, 0, |
1521 kExprI32LoadMem, 0, 0, kExprIf, kExprI8Const, 255, kExprReturn, ARITY_1, | 1521 kExprI32LoadMem, 0, 0, kExprIf, kExprI8Const, 255, kExprReturn, ARITY_1, |
1522 kExprEnd, kExprGetLocal, 0, kExprI8Const, 4, kExprI32Sub, kExprSetLocal, | 1522 kExprEnd, kExprGetLocal, 0, kExprI8Const, 4, kExprI32Sub, kExprSetLocal, |
1523 0, kExprBr, ARITY_1, DEPTH_0, kExprEnd, kExprEnd, kExprI8Const, 0); | 1523 0, kExprBr, ARITY_1, DEPTH_0, kExprEnd, kExprEnd, kExprI8Const, 0); |
1524 | 1524 |
1525 module.BlankMemory(); | 1525 module.BlankMemory(); |
1526 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); | 1526 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); |
1527 } | 1527 } |
1528 | 1528 |
1529 TEST(Run_Wasm_MemF32_Sum) { | 1529 WASM_EXEC_TEST(MemF32_Sum) { |
1530 const int kSize = 5; | 1530 const int kSize = 5; |
1531 TestingModule module; | 1531 TestingModule module; |
1532 module.AddMemoryElems<float>(kSize); | 1532 module.AddMemoryElems<float>(kSize); |
1533 float* buffer = module.raw_mem_start<float>(); | 1533 float* buffer = module.raw_mem_start<float>(); |
1534 buffer[0] = -99.25; | 1534 buffer[0] = -99.25; |
1535 buffer[1] = -888.25; | 1535 buffer[1] = -888.25; |
1536 buffer[2] = -77.25; | 1536 buffer[2] = -77.25; |
1537 buffer[3] = 66666.25; | 1537 buffer[3] = 66666.25; |
1538 buffer[4] = 5555.25; | 1538 buffer[4] = 5555.25; |
1539 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1539 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), | 1582 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), |
1583 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))), | 1583 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))), |
1584 WASM_SET_LOCAL( | 1584 WASM_SET_LOCAL( |
1585 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(sizeof(T)))))), | 1585 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(sizeof(T)))))), |
1586 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), | 1586 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), |
1587 WASM_GET_LOCAL(0))); | 1587 WASM_GET_LOCAL(0))); |
1588 r.Call(static_cast<int>(sizeof(T) * (size - 1))); | 1588 r.Call(static_cast<int>(sizeof(T) * (size - 1))); |
1589 return module.raw_mem_at<double>(0); | 1589 return module.raw_mem_at<double>(0); |
1590 } | 1590 } |
1591 | 1591 |
1592 TEST(Run_Wasm_MemF64_Mul) { | 1592 WASM_EXEC_TEST(MemF64_Mul) { |
1593 const size_t kSize = 6; | 1593 const size_t kSize = 6; |
1594 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; | 1594 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; |
1595 double result = GenerateAndRunFold<double>(kExprF64Mul, buffer, kSize, | 1595 double result = GenerateAndRunFold<double>(kExprF64Mul, buffer, kSize, |
1596 kAstF64, MachineType::Float64()); | 1596 kAstF64, MachineType::Float64()); |
1597 CHECK_EQ(32, result); | 1597 CHECK_EQ(32, result); |
1598 } | 1598 } |
1599 | 1599 |
1600 TEST(Build_Wasm_Infinite_Loop) { | 1600 TEST(Build_Wasm_Infinite_Loop) { |
1601 WasmRunner<int32_t> r(MachineType::Int32()); | 1601 WasmRunner<int32_t> r(MachineType::Int32()); |
1602 // Only build the graph and compile, don't run. | 1602 // Only build the graph and compile, don't run. |
1603 BUILD(r, WASM_INFINITE_LOOP); | 1603 BUILD(r, WASM_INFINITE_LOOP); |
1604 } | 1604 } |
1605 | 1605 |
1606 TEST(Build_Wasm_Infinite_Loop_effect) { | 1606 TEST(Build_Wasm_Infinite_Loop_effect) { |
1607 TestingModule module; | 1607 TestingModule module; |
1608 module.AddMemoryElems<int8_t>(16); | 1608 module.AddMemoryElems<int8_t>(16); |
1609 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1609 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1610 | 1610 |
1611 // Only build the graph and compile, don't run. | 1611 // Only build the graph and compile, don't run. |
1612 BUILD(r, WASM_LOOP(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); | 1612 BUILD(r, WASM_LOOP(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); |
1613 } | 1613 } |
1614 | 1614 |
1615 TEST(Run_Wasm_Unreachable0a) { | 1615 WASM_EXEC_TEST(Unreachable0a) { |
1616 WasmRunner<int32_t> r(MachineType::Int32()); | 1616 WasmRunner<int32_t> r(MachineType::Int32()); |
1617 BUILD(r, B2(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0)))); | 1617 BUILD(r, B2(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0)))); |
1618 CHECK_EQ(9, r.Call(0)); | 1618 CHECK_EQ(9, r.Call(0)); |
1619 CHECK_EQ(9, r.Call(1)); | 1619 CHECK_EQ(9, r.Call(1)); |
1620 } | 1620 } |
1621 | 1621 |
1622 TEST(Run_Wasm_Unreachable0b) { | 1622 WASM_EXEC_TEST(Unreachable0b) { |
1623 WasmRunner<int32_t> r(MachineType::Int32()); | 1623 WasmRunner<int32_t> r(MachineType::Int32()); |
1624 BUILD(r, B2(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); | 1624 BUILD(r, B2(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); |
1625 CHECK_EQ(7, r.Call(0)); | 1625 CHECK_EQ(7, r.Call(0)); |
1626 CHECK_EQ(7, r.Call(1)); | 1626 CHECK_EQ(7, r.Call(1)); |
1627 } | 1627 } |
1628 | 1628 |
1629 TEST(Build_Wasm_Unreachable1) { | 1629 TEST(Build_Wasm_Unreachable1) { |
1630 WasmRunner<int32_t> r(MachineType::Int32()); | 1630 WasmRunner<int32_t> r(MachineType::Int32()); |
1631 BUILD(r, WASM_UNREACHABLE); | 1631 BUILD(r, WASM_UNREACHABLE); |
1632 } | 1632 } |
(...skipping 12 matching lines...) Expand all Loading... |
1645 WasmRunner<int32_t> r(MachineType::Int32()); | 1645 WasmRunner<int32_t> r(MachineType::Int32()); |
1646 BUILD(r, WASM_UNREACHABLE, WASM_IF(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 1646 BUILD(r, WASM_UNREACHABLE, WASM_IF(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
1647 } | 1647 } |
1648 | 1648 |
1649 TEST(Build_Wasm_UnreachableIf2) { | 1649 TEST(Build_Wasm_UnreachableIf2) { |
1650 WasmRunner<int32_t> r(MachineType::Int32()); | 1650 WasmRunner<int32_t> r(MachineType::Int32()); |
1651 BUILD(r, WASM_UNREACHABLE, | 1651 BUILD(r, WASM_UNREACHABLE, |
1652 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)); | 1652 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)); |
1653 } | 1653 } |
1654 | 1654 |
1655 TEST(Run_Wasm_Unreachable_Load) { | 1655 WASM_EXEC_TEST(Unreachable_Load) { |
1656 WasmRunner<int32_t> r(MachineType::Int32()); | 1656 WasmRunner<int32_t> r(MachineType::Int32()); |
1657 BUILD(r, B2(WASM_BRV(0, WASM_GET_LOCAL(0)), | 1657 BUILD(r, B2(WASM_BRV(0, WASM_GET_LOCAL(0)), |
1658 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)))); | 1658 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)))); |
1659 CHECK_EQ(11, r.Call(11)); | 1659 CHECK_EQ(11, r.Call(11)); |
1660 CHECK_EQ(21, r.Call(21)); | 1660 CHECK_EQ(21, r.Call(21)); |
1661 } | 1661 } |
1662 | 1662 |
1663 TEST(Run_Wasm_Infinite_Loop_not_taken1) { | 1663 WASM_EXEC_TEST(Infinite_Loop_not_taken1) { |
1664 WasmRunner<int32_t> r(MachineType::Int32()); | 1664 WasmRunner<int32_t> r(MachineType::Int32()); |
1665 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45))); | 1665 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45))); |
1666 // Run the code, but don't go into the infinite loop. | 1666 // Run the code, but don't go into the infinite loop. |
1667 CHECK_EQ(45, r.Call(0)); | 1667 CHECK_EQ(45, r.Call(0)); |
1668 } | 1668 } |
1669 | 1669 |
1670 TEST(Run_Wasm_Infinite_Loop_not_taken2) { | 1670 WASM_EXEC_TEST(Infinite_Loop_not_taken2) { |
1671 WasmRunner<int32_t> r(MachineType::Int32()); | 1671 WasmRunner<int32_t> r(MachineType::Int32()); |
1672 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)), | 1672 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)), |
1673 WASM_INFINITE_LOOP))); | 1673 WASM_INFINITE_LOOP))); |
1674 // Run the code, but don't go into the infinite loop. | 1674 // Run the code, but don't go into the infinite loop. |
1675 CHECK_EQ(45, r.Call(1)); | 1675 CHECK_EQ(45, r.Call(1)); |
1676 } | 1676 } |
1677 | 1677 |
1678 TEST(Run_Wasm_Infinite_Loop_not_taken2_brif) { | 1678 WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) { |
1679 WasmRunner<int32_t> r(MachineType::Int32()); | 1679 WasmRunner<int32_t> r(MachineType::Int32()); |
1680 BUILD(r, | 1680 BUILD(r, |
1681 B2(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), WASM_INFINITE_LOOP)); | 1681 B2(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), WASM_INFINITE_LOOP)); |
1682 // Run the code, but don't go into the infinite loop. | 1682 // Run the code, but don't go into the infinite loop. |
1683 CHECK_EQ(45, r.Call(1)); | 1683 CHECK_EQ(45, r.Call(1)); |
1684 } | 1684 } |
1685 | 1685 |
1686 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { | 1686 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { |
1687 Isolate* isolate = CcTest::InitIsolateOnce(); | 1687 Isolate* isolate = CcTest::InitIsolateOnce(); |
1688 Zone zone(isolate->allocator()); | 1688 Zone zone(isolate->allocator()); |
(...skipping 22 matching lines...) Expand all Loading... |
1711 TEST(Build_Wasm_SimpleExprs) { | 1711 TEST(Build_Wasm_SimpleExprs) { |
1712 // Test that the decoder can build a graph for all supported simple expressions. | 1712 // Test that the decoder can build a graph for all supported simple expressions. |
1713 #define GRAPH_BUILD_TEST(name, opcode, sig) \ | 1713 #define GRAPH_BUILD_TEST(name, opcode, sig) \ |
1714 TestBuildGraphForSimpleExpression(kExpr##name); | 1714 TestBuildGraphForSimpleExpression(kExpr##name); |
1715 | 1715 |
1716 FOREACH_SIMPLE_OPCODE(GRAPH_BUILD_TEST); | 1716 FOREACH_SIMPLE_OPCODE(GRAPH_BUILD_TEST); |
1717 | 1717 |
1718 #undef GRAPH_BUILD_TEST | 1718 #undef GRAPH_BUILD_TEST |
1719 } | 1719 } |
1720 | 1720 |
1721 TEST(Run_Wasm_Int32LoadInt8_signext) { | 1721 WASM_EXEC_TEST(Int32LoadInt8_signext) { |
1722 TestingModule module; | 1722 TestingModule module; |
1723 const int kNumElems = 16; | 1723 const int kNumElems = 16; |
1724 int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems); | 1724 int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems); |
1725 module.RandomizeMemory(); | 1725 module.RandomizeMemory(); |
1726 memory[0] = -1; | 1726 memory[0] = -1; |
1727 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1727 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1728 BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))); | 1728 BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))); |
1729 | 1729 |
1730 for (size_t i = 0; i < kNumElems; i++) { | 1730 for (size_t i = 0; i < kNumElems; i++) { |
1731 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); | 1731 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); |
1732 } | 1732 } |
1733 } | 1733 } |
1734 | 1734 |
1735 TEST(Run_Wasm_Int32LoadInt8_zeroext) { | 1735 WASM_EXEC_TEST(Int32LoadInt8_zeroext) { |
1736 TestingModule module; | 1736 TestingModule module; |
1737 const int kNumElems = 16; | 1737 const int kNumElems = 16; |
1738 byte* memory = module.AddMemory(kNumElems); | 1738 byte* memory = module.AddMemory(kNumElems); |
1739 module.RandomizeMemory(77); | 1739 module.RandomizeMemory(77); |
1740 memory[0] = 255; | 1740 memory[0] = 255; |
1741 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1741 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1742 BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0))); | 1742 BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0))); |
1743 | 1743 |
1744 for (size_t i = 0; i < kNumElems; i++) { | 1744 for (size_t i = 0; i < kNumElems; i++) { |
1745 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); | 1745 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); |
1746 } | 1746 } |
1747 } | 1747 } |
1748 | 1748 |
1749 TEST(Run_Wasm_Int32LoadInt16_signext) { | 1749 WASM_EXEC_TEST(Int32LoadInt16_signext) { |
1750 TestingModule module; | 1750 TestingModule module; |
1751 const int kNumBytes = 16; | 1751 const int kNumBytes = 16; |
1752 byte* memory = module.AddMemory(kNumBytes); | 1752 byte* memory = module.AddMemory(kNumBytes); |
1753 module.RandomizeMemory(888); | 1753 module.RandomizeMemory(888); |
1754 memory[1] = 200; | 1754 memory[1] = 200; |
1755 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1755 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1756 BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0))); | 1756 BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0))); |
1757 | 1757 |
1758 for (size_t i = 0; i < kNumBytes; i += 2) { | 1758 for (size_t i = 0; i < kNumBytes; i += 2) { |
1759 int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8); | 1759 int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8); |
1760 CHECK_EQ(expected, r.Call(static_cast<int>(i))); | 1760 CHECK_EQ(expected, r.Call(static_cast<int>(i))); |
1761 } | 1761 } |
1762 } | 1762 } |
1763 | 1763 |
1764 TEST(Run_Wasm_Int32LoadInt16_zeroext) { | 1764 WASM_EXEC_TEST(Int32LoadInt16_zeroext) { |
1765 TestingModule module; | 1765 TestingModule module; |
1766 const int kNumBytes = 16; | 1766 const int kNumBytes = 16; |
1767 byte* memory = module.AddMemory(kNumBytes); | 1767 byte* memory = module.AddMemory(kNumBytes); |
1768 module.RandomizeMemory(9999); | 1768 module.RandomizeMemory(9999); |
1769 memory[1] = 204; | 1769 memory[1] = 204; |
1770 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1770 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1771 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); | 1771 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); |
1772 | 1772 |
1773 for (size_t i = 0; i < kNumBytes; i += 2) { | 1773 for (size_t i = 0; i < kNumBytes; i += 2) { |
1774 int32_t expected = memory[i] | (memory[i + 1] << 8); | 1774 int32_t expected = memory[i] | (memory[i + 1] << 8); |
1775 CHECK_EQ(expected, r.Call(static_cast<int>(i))); | 1775 CHECK_EQ(expected, r.Call(static_cast<int>(i))); |
1776 } | 1776 } |
1777 } | 1777 } |
1778 | 1778 |
1779 TEST(Run_WasmInt32Global) { | 1779 WASM_EXEC_TEST(Int32Global) { |
1780 TestingModule module; | 1780 TestingModule module; |
1781 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32()); | 1781 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32()); |
1782 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1782 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1783 // global = global + p0 | 1783 // global = global + p0 |
1784 BUILD(r, WASM_STORE_GLOBAL( | 1784 BUILD(r, WASM_STORE_GLOBAL( |
1785 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); | 1785 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); |
1786 | 1786 |
1787 *global = 116; | 1787 *global = 116; |
1788 for (int i = 9; i < 444444; i += 111111) { | 1788 for (int i = 9; i < 444444; i += 111111) { |
1789 int32_t expected = *global + i; | 1789 int32_t expected = *global + i; |
1790 r.Call(i); | 1790 r.Call(i); |
1791 CHECK_EQ(expected, *global); | 1791 CHECK_EQ(expected, *global); |
1792 } | 1792 } |
1793 } | 1793 } |
1794 | 1794 |
1795 TEST(Run_WasmInt32Globals_DontAlias) { | 1795 WASM_EXEC_TEST(Int32Globals_DontAlias) { |
1796 const int kNumGlobals = 3; | 1796 const int kNumGlobals = 3; |
1797 TestingModule module; | 1797 TestingModule module; |
1798 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), | 1798 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), |
1799 module.AddGlobal<int32_t>(MachineType::Int32()), | 1799 module.AddGlobal<int32_t>(MachineType::Int32()), |
1800 module.AddGlobal<int32_t>(MachineType::Int32())}; | 1800 module.AddGlobal<int32_t>(MachineType::Int32())}; |
1801 | 1801 |
1802 for (int g = 0; g < kNumGlobals; g++) { | 1802 for (int g = 0; g < kNumGlobals; g++) { |
1803 // global = global + p0 | 1803 // global = global + p0 |
1804 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1804 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1805 BUILD(r, WASM_STORE_GLOBAL( | 1805 BUILD(r, WASM_STORE_GLOBAL( |
1806 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); | 1806 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); |
1807 | 1807 |
1808 // Check that reading/writing global number {g} doesn't alter the others. | 1808 // Check that reading/writing global number {g} doesn't alter the others. |
1809 *globals[g] = 116 * g; | 1809 *globals[g] = 116 * g; |
1810 int32_t before[kNumGlobals]; | 1810 int32_t before[kNumGlobals]; |
1811 for (int i = 9; i < 444444; i += 111113) { | 1811 for (int i = 9; i < 444444; i += 111113) { |
1812 int32_t sum = *globals[g] + i; | 1812 int32_t sum = *globals[g] + i; |
1813 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j]; | 1813 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j]; |
1814 r.Call(i); | 1814 r.Call(i); |
1815 for (int j = 0; j < kNumGlobals; j++) { | 1815 for (int j = 0; j < kNumGlobals; j++) { |
1816 int32_t expected = j == g ? sum : before[j]; | 1816 int32_t expected = j == g ? sum : before[j]; |
1817 CHECK_EQ(expected, *globals[j]); | 1817 CHECK_EQ(expected, *globals[j]); |
1818 } | 1818 } |
1819 } | 1819 } |
1820 } | 1820 } |
1821 } | 1821 } |
1822 | 1822 |
1823 TEST(Run_WasmFloat32Global) { | 1823 WASM_EXEC_TEST(Float32Global) { |
1824 TestingModule module; | 1824 TestingModule module; |
1825 float* global = module.AddGlobal<float>(MachineType::Float32()); | 1825 float* global = module.AddGlobal<float>(MachineType::Float32()); |
1826 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1826 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1827 // global = global + p0 | 1827 // global = global + p0 |
1828 BUILD(r, B2(WASM_STORE_GLOBAL( | 1828 BUILD(r, B2(WASM_STORE_GLOBAL( |
1829 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0), | 1829 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0), |
1830 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 1830 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
1831 WASM_ZERO)); | 1831 WASM_ZERO)); |
1832 | 1832 |
1833 *global = 1.25; | 1833 *global = 1.25; |
1834 for (int i = 9; i < 4444; i += 1111) { | 1834 for (int i = 9; i < 4444; i += 1111) { |
1835 volatile float expected = *global + i; | 1835 volatile float expected = *global + i; |
1836 r.Call(i); | 1836 r.Call(i); |
1837 CHECK_EQ(expected, *global); | 1837 CHECK_EQ(expected, *global); |
1838 } | 1838 } |
1839 } | 1839 } |
1840 | 1840 |
1841 TEST(Run_WasmFloat64Global) { | 1841 WASM_EXEC_TEST(Float64Global) { |
1842 TestingModule module; | 1842 TestingModule module; |
1843 double* global = module.AddGlobal<double>(MachineType::Float64()); | 1843 double* global = module.AddGlobal<double>(MachineType::Float64()); |
1844 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1844 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1845 // global = global + p0 | 1845 // global = global + p0 |
1846 BUILD(r, B2(WASM_STORE_GLOBAL( | 1846 BUILD(r, B2(WASM_STORE_GLOBAL( |
1847 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0), | 1847 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0), |
1848 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 1848 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
1849 WASM_ZERO)); | 1849 WASM_ZERO)); |
1850 | 1850 |
1851 *global = 1.25; | 1851 *global = 1.25; |
1852 for (int i = 9; i < 4444; i += 1111) { | 1852 for (int i = 9; i < 4444; i += 1111) { |
1853 volatile double expected = *global + i; | 1853 volatile double expected = *global + i; |
1854 r.Call(i); | 1854 r.Call(i); |
1855 CHECK_EQ(expected, *global); | 1855 CHECK_EQ(expected, *global); |
1856 } | 1856 } |
1857 } | 1857 } |
1858 | 1858 |
1859 TEST(Run_WasmMixedGlobals) { | 1859 WASM_EXEC_TEST(MixedGlobals) { |
1860 TestingModule module; | 1860 TestingModule module; |
1861 int32_t* unused = module.AddGlobal<int32_t>(MachineType::Int32()); | 1861 int32_t* unused = module.AddGlobal<int32_t>(MachineType::Int32()); |
1862 byte* memory = module.AddMemory(32); | 1862 byte* memory = module.AddMemory(32); |
1863 | 1863 |
1864 int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8()); | 1864 int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8()); |
1865 uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8()); | 1865 uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8()); |
1866 int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16()); | 1866 int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16()); |
1867 uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16()); | 1867 uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16()); |
1868 int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32()); | 1868 int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32()); |
1869 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32()); | 1869 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 CHECK(static_cast<int16_t>(0xccaa) == *var_int16); | 1903 CHECK(static_cast<int16_t>(0xccaa) == *var_int16); |
1904 CHECK(static_cast<uint16_t>(0xccaa) == *var_uint16); | 1904 CHECK(static_cast<uint16_t>(0xccaa) == *var_uint16); |
1905 CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32); | 1905 CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32); |
1906 CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32); | 1906 CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32); |
1907 CHECK(bit_cast<float>(0xee55ccaa) == *var_float); | 1907 CHECK(bit_cast<float>(0xee55ccaa) == *var_float); |
1908 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double); | 1908 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double); |
1909 | 1909 |
1910 USE(unused); | 1910 USE(unused); |
1911 } | 1911 } |
1912 | 1912 |
1913 TEST(Run_WasmCallEmpty) { | 1913 WASM_EXEC_TEST(CallEmpty) { |
1914 const int32_t kExpected = -414444; | 1914 const int32_t kExpected = -414444; |
1915 // Build the target function. | 1915 // Build the target function. |
1916 TestSignatures sigs; | 1916 TestSignatures sigs; |
1917 TestingModule module; | 1917 TestingModule module; |
1918 WasmFunctionCompiler t(sigs.i_v(), &module); | 1918 WasmFunctionCompiler t(sigs.i_v(), &module); |
1919 BUILD(t, WASM_I32V_3(kExpected)); | 1919 BUILD(t, WASM_I32V_3(kExpected)); |
1920 uint32_t index = t.CompileAndAdd(); | 1920 uint32_t index = t.CompileAndAdd(); |
1921 | 1921 |
1922 // Build the calling function. | 1922 // Build the calling function. |
1923 WasmRunner<int32_t> r(&module); | 1923 WasmRunner<int32_t> r(&module); |
1924 BUILD(r, WASM_CALL_FUNCTION0(index)); | 1924 BUILD(r, WASM_CALL_FUNCTION0(index)); |
1925 | 1925 |
1926 int32_t result = r.Call(); | 1926 int32_t result = r.Call(); |
1927 CHECK_EQ(kExpected, result); | 1927 CHECK_EQ(kExpected, result); |
1928 } | 1928 } |
1929 | 1929 |
1930 TEST(Run_WasmCallF32StackParameter) { | 1930 WASM_EXEC_TEST(CallF32StackParameter) { |
1931 // Build the target function. | 1931 // Build the target function. |
1932 LocalType param_types[20]; | 1932 LocalType param_types[20]; |
1933 for (int i = 0; i < 20; i++) param_types[i] = kAstF32; | 1933 for (int i = 0; i < 20; i++) param_types[i] = kAstF32; |
1934 FunctionSig sig(1, 19, param_types); | 1934 FunctionSig sig(1, 19, param_types); |
1935 TestingModule module; | 1935 TestingModule module; |
1936 WasmFunctionCompiler t(&sig, &module); | 1936 WasmFunctionCompiler t(&sig, &module); |
1937 BUILD(t, WASM_GET_LOCAL(17)); | 1937 BUILD(t, WASM_GET_LOCAL(17)); |
1938 uint32_t index = t.CompileAndAdd(); | 1938 uint32_t index = t.CompileAndAdd(); |
1939 | 1939 |
1940 // Build the calling function. | 1940 // Build the calling function. |
1941 WasmRunner<float> r(&module); | 1941 WasmRunner<float> r(&module); |
1942 BUILD(r, WASM_CALL_FUNCTIONN( | 1942 BUILD(r, WASM_CALL_FUNCTIONN( |
1943 19, index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f), | 1943 19, index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f), |
1944 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), | 1944 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), |
1945 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), | 1945 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), |
1946 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), | 1946 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), |
1947 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), | 1947 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), |
1948 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); | 1948 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); |
1949 | 1949 |
1950 float result = r.Call(); | 1950 float result = r.Call(); |
1951 CHECK_EQ(256.5f, result); | 1951 CHECK_EQ(256.5f, result); |
1952 } | 1952 } |
1953 | 1953 |
1954 TEST(Run_WasmCallF64StackParameter) { | 1954 WASM_EXEC_TEST(CallF64StackParameter) { |
1955 // Build the target function. | 1955 // Build the target function. |
1956 LocalType param_types[20]; | 1956 LocalType param_types[20]; |
1957 for (int i = 0; i < 20; i++) param_types[i] = kAstF64; | 1957 for (int i = 0; i < 20; i++) param_types[i] = kAstF64; |
1958 FunctionSig sig(1, 19, param_types); | 1958 FunctionSig sig(1, 19, param_types); |
1959 TestingModule module; | 1959 TestingModule module; |
1960 WasmFunctionCompiler t(&sig, &module); | 1960 WasmFunctionCompiler t(&sig, &module); |
1961 BUILD(t, WASM_GET_LOCAL(17)); | 1961 BUILD(t, WASM_GET_LOCAL(17)); |
1962 uint32_t index = t.CompileAndAdd(); | 1962 uint32_t index = t.CompileAndAdd(); |
1963 | 1963 |
1964 // Build the calling function. | 1964 // Build the calling function. |
1965 WasmRunner<double> r(&module); | 1965 WasmRunner<double> r(&module); |
1966 BUILD(r, WASM_CALL_FUNCTIONN(19, index, WASM_F64(1.0), WASM_F64(2.0), | 1966 BUILD(r, WASM_CALL_FUNCTIONN(19, index, WASM_F64(1.0), WASM_F64(2.0), |
1967 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), | 1967 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), |
1968 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0), | 1968 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0), |
1969 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5), | 1969 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5), |
1970 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5), | 1970 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5), |
1971 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5), | 1971 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5), |
1972 WASM_F64(256.5), WASM_F64(512.5))); | 1972 WASM_F64(256.5), WASM_F64(512.5))); |
1973 | 1973 |
1974 float result = r.Call(); | 1974 float result = r.Call(); |
1975 CHECK_EQ(256.5, result); | 1975 CHECK_EQ(256.5, result); |
1976 } | 1976 } |
1977 | 1977 |
1978 TEST(Run_WasmCallVoid) { | 1978 WASM_EXEC_TEST(CallVoid) { |
1979 const byte kMemOffset = 8; | 1979 const byte kMemOffset = 8; |
1980 const int32_t kElemNum = kMemOffset / sizeof(int32_t); | 1980 const int32_t kElemNum = kMemOffset / sizeof(int32_t); |
1981 const int32_t kExpected = -414444; | 1981 const int32_t kExpected = -414444; |
1982 // Build the target function. | 1982 // Build the target function. |
1983 TestSignatures sigs; | 1983 TestSignatures sigs; |
1984 TestingModule module; | 1984 TestingModule module; |
1985 module.AddMemory(16); | 1985 module.AddMemory(16); |
1986 module.RandomizeMemory(); | 1986 module.RandomizeMemory(); |
1987 WasmFunctionCompiler t(sigs.v_v(), &module); | 1987 WasmFunctionCompiler t(sigs.v_v(), &module); |
1988 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), | 1988 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), |
1989 WASM_I32V_3(kExpected))); | 1989 WASM_I32V_3(kExpected))); |
1990 uint32_t index = t.CompileAndAdd(); | 1990 uint32_t index = t.CompileAndAdd(); |
1991 | 1991 |
1992 // Build the calling function. | 1992 // Build the calling function. |
1993 WasmRunner<int32_t> r(&module); | 1993 WasmRunner<int32_t> r(&module); |
1994 BUILD(r, WASM_CALL_FUNCTION0(index), | 1994 BUILD(r, WASM_CALL_FUNCTION0(index), |
1995 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); | 1995 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); |
1996 | 1996 |
1997 int32_t result = r.Call(); | 1997 int32_t result = r.Call(); |
1998 CHECK_EQ(kExpected, result); | 1998 CHECK_EQ(kExpected, result); |
1999 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); | 1999 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); |
2000 } | 2000 } |
2001 | 2001 |
2002 TEST(Run_WasmCall_Int32Add) { | 2002 WASM_EXEC_TEST(Call_Int32Add) { |
2003 // Build the target function. | 2003 // Build the target function. |
2004 TestSignatures sigs; | 2004 TestSignatures sigs; |
2005 TestingModule module; | 2005 TestingModule module; |
2006 WasmFunctionCompiler t(sigs.i_ii(), &module); | 2006 WasmFunctionCompiler t(sigs.i_ii(), &module); |
2007 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2007 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2008 uint32_t index = t.CompileAndAdd(); | 2008 uint32_t index = t.CompileAndAdd(); |
2009 | 2009 |
2010 // Build the caller function. | 2010 // Build the caller function. |
2011 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); | 2011 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); |
2012 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2012 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2013 | 2013 |
2014 FOR_INT32_INPUTS(i) { | 2014 FOR_INT32_INPUTS(i) { |
2015 FOR_INT32_INPUTS(j) { | 2015 FOR_INT32_INPUTS(j) { |
2016 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + | 2016 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + |
2017 static_cast<uint32_t>(*j)); | 2017 static_cast<uint32_t>(*j)); |
2018 CHECK_EQ(expected, r.Call(*i, *j)); | 2018 CHECK_EQ(expected, r.Call(*i, *j)); |
2019 } | 2019 } |
2020 } | 2020 } |
2021 } | 2021 } |
2022 | 2022 |
2023 TEST(Run_WasmCall_Float32Sub) { | 2023 WASM_EXEC_TEST(Call_Float32Sub) { |
2024 TestSignatures sigs; | 2024 TestSignatures sigs; |
2025 TestingModule module; | 2025 TestingModule module; |
2026 WasmFunctionCompiler t(sigs.f_ff(), &module); | 2026 WasmFunctionCompiler t(sigs.f_ff(), &module); |
2027 | 2027 |
2028 // Build the target function. | 2028 // Build the target function. |
2029 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2029 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2030 uint32_t index = t.CompileAndAdd(); | 2030 uint32_t index = t.CompileAndAdd(); |
2031 | 2031 |
2032 // Builder the caller function. | 2032 // Builder the caller function. |
2033 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32()); | 2033 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32()); |
2034 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2034 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2035 | 2035 |
2036 FOR_FLOAT32_INPUTS(i) { | 2036 FOR_FLOAT32_INPUTS(i) { |
2037 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); } | 2037 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); } |
2038 } | 2038 } |
2039 } | 2039 } |
2040 | 2040 |
2041 TEST(Run_WasmCall_Float64Sub) { | 2041 WASM_EXEC_TEST(Call_Float64Sub) { |
2042 TestingModule module; | 2042 TestingModule module; |
2043 double* memory = module.AddMemoryElems<double>(16); | 2043 double* memory = module.AddMemoryElems<double>(16); |
2044 WasmRunner<int32_t> r(&module); | 2044 WasmRunner<int32_t> r(&module); |
2045 | 2045 |
2046 BUILD(r, WASM_BLOCK( | 2046 BUILD(r, WASM_BLOCK( |
2047 2, WASM_STORE_MEM( | 2047 2, WASM_STORE_MEM( |
2048 MachineType::Float64(), WASM_ZERO, | 2048 MachineType::Float64(), WASM_ZERO, |
2049 WASM_F64_SUB( | 2049 WASM_F64_SUB( |
2050 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), | 2050 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), |
2051 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), | 2051 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2152 for (int i = 0; i < size; i++) { | 2152 for (int i = 0; i < size; i++) { |
2153 int base = (which + 1) * kElemSize; | 2153 int base = (which + 1) * kElemSize; |
2154 byte expected = module.raw_mem_at<byte>(base + i); | 2154 byte expected = module.raw_mem_at<byte>(base + i); |
2155 byte result = module.raw_mem_at<byte>(i); | 2155 byte result = module.raw_mem_at<byte>(i); |
2156 CHECK_EQ(expected, result); | 2156 CHECK_EQ(expected, result); |
2157 } | 2157 } |
2158 } | 2158 } |
2159 } | 2159 } |
2160 } | 2160 } |
2161 | 2161 |
2162 TEST(Run_WasmMixedCall_0) { Run_WasmMixedCall_N(0); } | 2162 WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(0); } |
2163 TEST(Run_WasmMixedCall_1) { Run_WasmMixedCall_N(1); } | 2163 WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(1); } |
2164 TEST(Run_WasmMixedCall_2) { Run_WasmMixedCall_N(2); } | 2164 WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(2); } |
2165 TEST(Run_WasmMixedCall_3) { Run_WasmMixedCall_N(3); } | 2165 WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(3); } |
2166 | 2166 |
2167 TEST(Run_Wasm_AddCall) { | 2167 WASM_EXEC_TEST(AddCall) { |
2168 TestSignatures sigs; | 2168 TestSignatures sigs; |
2169 TestingModule module; | 2169 TestingModule module; |
2170 WasmFunctionCompiler t1(sigs.i_ii(), &module); | 2170 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2171 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2171 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2172 t1.CompileAndAdd(); | 2172 t1.CompileAndAdd(); |
2173 | 2173 |
2174 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 2174 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2175 byte local = r.AllocateLocal(kAstI32); | 2175 byte local = r.AllocateLocal(kAstI32); |
2176 BUILD(r, B2(WASM_SET_LOCAL(local, WASM_I8(99)), | 2176 BUILD(r, B2(WASM_SET_LOCAL(local, WASM_I8(99)), |
2177 WASM_I32_ADD( | 2177 WASM_I32_ADD( |
2178 WASM_CALL_FUNCTION2(t1.function_index_, WASM_GET_LOCAL(0), | 2178 WASM_CALL_FUNCTION2(t1.function_index_, WASM_GET_LOCAL(0), |
2179 WASM_GET_LOCAL(0)), | 2179 WASM_GET_LOCAL(0)), |
2180 WASM_CALL_FUNCTION2(t1.function_index_, WASM_GET_LOCAL(1), | 2180 WASM_CALL_FUNCTION2(t1.function_index_, WASM_GET_LOCAL(1), |
2181 WASM_GET_LOCAL(local))))); | 2181 WASM_GET_LOCAL(local))))); |
2182 | 2182 |
2183 CHECK_EQ(198, r.Call(0)); | 2183 CHECK_EQ(198, r.Call(0)); |
2184 CHECK_EQ(200, r.Call(1)); | 2184 CHECK_EQ(200, r.Call(1)); |
2185 CHECK_EQ(100, r.Call(-49)); | 2185 CHECK_EQ(100, r.Call(-49)); |
2186 } | 2186 } |
2187 | 2187 |
2188 TEST(Run_Wasm_CountDown_expr) { | 2188 WASM_EXEC_TEST(CountDown_expr) { |
2189 WasmRunner<int32_t> r(MachineType::Int32()); | 2189 WasmRunner<int32_t> r(MachineType::Int32()); |
2190 BUILD(r, WASM_LOOP( | 2190 BUILD(r, WASM_LOOP( |
2191 3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), | 2191 3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), |
2192 WASM_BREAKV(1, WASM_GET_LOCAL(0))), | 2192 WASM_BREAKV(1, WASM_GET_LOCAL(0))), |
2193 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), | 2193 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), |
2194 WASM_CONTINUE(0))); | 2194 WASM_CONTINUE(0))); |
2195 CHECK_EQ(0, r.Call(1)); | 2195 CHECK_EQ(0, r.Call(1)); |
2196 CHECK_EQ(0, r.Call(10)); | 2196 CHECK_EQ(0, r.Call(10)); |
2197 CHECK_EQ(0, r.Call(100)); | 2197 CHECK_EQ(0, r.Call(100)); |
2198 } | 2198 } |
2199 | 2199 |
2200 TEST(Run_Wasm_ExprBlock2a) { | 2200 WASM_EXEC_TEST(ExprBlock2a) { |
2201 WasmRunner<int32_t> r(MachineType::Int32()); | 2201 WasmRunner<int32_t> r(MachineType::Int32()); |
2202 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(1))); | 2202 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(1))); |
2203 CHECK_EQ(1, r.Call(0)); | 2203 CHECK_EQ(1, r.Call(0)); |
2204 CHECK_EQ(1, r.Call(1)); | 2204 CHECK_EQ(1, r.Call(1)); |
2205 } | 2205 } |
2206 | 2206 |
2207 TEST(Run_Wasm_ExprBlock2b) { | 2207 WASM_EXEC_TEST(ExprBlock2b) { |
2208 WasmRunner<int32_t> r(MachineType::Int32()); | 2208 WasmRunner<int32_t> r(MachineType::Int32()); |
2209 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(2))); | 2209 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(2))); |
2210 CHECK_EQ(2, r.Call(0)); | 2210 CHECK_EQ(2, r.Call(0)); |
2211 CHECK_EQ(1, r.Call(1)); | 2211 CHECK_EQ(1, r.Call(1)); |
2212 } | 2212 } |
2213 | 2213 |
2214 TEST(Run_Wasm_ExprBlock2c) { | 2214 WASM_EXEC_TEST(ExprBlock2c) { |
2215 WasmRunner<int32_t> r(MachineType::Int32()); | 2215 WasmRunner<int32_t> r(MachineType::Int32()); |
2216 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(1))); | 2216 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(1))); |
2217 CHECK_EQ(1, r.Call(0)); | 2217 CHECK_EQ(1, r.Call(0)); |
2218 CHECK_EQ(1, r.Call(1)); | 2218 CHECK_EQ(1, r.Call(1)); |
2219 } | 2219 } |
2220 | 2220 |
2221 TEST(Run_Wasm_ExprBlock2d) { | 2221 WASM_EXEC_TEST(ExprBlock2d) { |
2222 WasmRunner<int32_t> r(MachineType::Int32()); | 2222 WasmRunner<int32_t> r(MachineType::Int32()); |
2223 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(2))); | 2223 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(2))); |
2224 CHECK_EQ(2, r.Call(0)); | 2224 CHECK_EQ(2, r.Call(0)); |
2225 CHECK_EQ(1, r.Call(1)); | 2225 CHECK_EQ(1, r.Call(1)); |
2226 } | 2226 } |
2227 | 2227 |
2228 TEST(Run_Wasm_ExprBlock_ManualSwitch) { | 2228 WASM_EXEC_TEST(ExprBlock_ManualSwitch) { |
2229 WasmRunner<int32_t> r(MachineType::Int32()); | 2229 WasmRunner<int32_t> r(MachineType::Int32()); |
2230 BUILD(r, WASM_BLOCK(6, WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)), | 2230 BUILD(r, WASM_BLOCK(6, WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)), |
2231 WASM_BRV(1, WASM_I8(11))), | 2231 WASM_BRV(1, WASM_I8(11))), |
2232 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)), | 2232 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)), |
2233 WASM_BRV(1, WASM_I8(12))), | 2233 WASM_BRV(1, WASM_I8(12))), |
2234 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)), | 2234 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)), |
2235 WASM_BRV(1, WASM_I8(13))), | 2235 WASM_BRV(1, WASM_I8(13))), |
2236 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)), | 2236 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)), |
2237 WASM_BRV(1, WASM_I8(14))), | 2237 WASM_BRV(1, WASM_I8(14))), |
2238 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)), | 2238 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)), |
2239 WASM_BRV(1, WASM_I8(15))), | 2239 WASM_BRV(1, WASM_I8(15))), |
2240 WASM_I8(99))); | 2240 WASM_I8(99))); |
2241 CHECK_EQ(99, r.Call(0)); | 2241 CHECK_EQ(99, r.Call(0)); |
2242 CHECK_EQ(11, r.Call(1)); | 2242 CHECK_EQ(11, r.Call(1)); |
2243 CHECK_EQ(12, r.Call(2)); | 2243 CHECK_EQ(12, r.Call(2)); |
2244 CHECK_EQ(13, r.Call(3)); | 2244 CHECK_EQ(13, r.Call(3)); |
2245 CHECK_EQ(14, r.Call(4)); | 2245 CHECK_EQ(14, r.Call(4)); |
2246 CHECK_EQ(15, r.Call(5)); | 2246 CHECK_EQ(15, r.Call(5)); |
2247 CHECK_EQ(99, r.Call(6)); | 2247 CHECK_EQ(99, r.Call(6)); |
2248 } | 2248 } |
2249 | 2249 |
2250 TEST(Run_Wasm_ExprBlock_ManualSwitch_brif) { | 2250 WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { |
2251 WasmRunner<int32_t> r(MachineType::Int32()); | 2251 WasmRunner<int32_t> r(MachineType::Int32()); |
2252 BUILD(r, | 2252 BUILD(r, |
2253 WASM_BLOCK(6, WASM_BRV_IF(0, WASM_I8(11), | 2253 WASM_BLOCK(6, WASM_BRV_IF(0, WASM_I8(11), |
2254 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))), | 2254 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))), |
2255 WASM_BRV_IF(0, WASM_I8(12), | 2255 WASM_BRV_IF(0, WASM_I8(12), |
2256 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))), | 2256 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))), |
2257 WASM_BRV_IF(0, WASM_I8(13), | 2257 WASM_BRV_IF(0, WASM_I8(13), |
2258 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))), | 2258 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))), |
2259 WASM_BRV_IF(0, WASM_I8(14), | 2259 WASM_BRV_IF(0, WASM_I8(14), |
2260 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))), | 2260 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))), |
2261 WASM_BRV_IF(0, WASM_I8(15), | 2261 WASM_BRV_IF(0, WASM_I8(15), |
2262 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))), | 2262 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))), |
2263 WASM_I8(99))); | 2263 WASM_I8(99))); |
2264 CHECK_EQ(99, r.Call(0)); | 2264 CHECK_EQ(99, r.Call(0)); |
2265 CHECK_EQ(11, r.Call(1)); | 2265 CHECK_EQ(11, r.Call(1)); |
2266 CHECK_EQ(12, r.Call(2)); | 2266 CHECK_EQ(12, r.Call(2)); |
2267 CHECK_EQ(13, r.Call(3)); | 2267 CHECK_EQ(13, r.Call(3)); |
2268 CHECK_EQ(14, r.Call(4)); | 2268 CHECK_EQ(14, r.Call(4)); |
2269 CHECK_EQ(15, r.Call(5)); | 2269 CHECK_EQ(15, r.Call(5)); |
2270 CHECK_EQ(99, r.Call(6)); | 2270 CHECK_EQ(99, r.Call(6)); |
2271 } | 2271 } |
2272 | 2272 |
2273 TEST(Run_Wasm_nested_ifs) { | 2273 WASM_EXEC_TEST(nested_ifs) { |
2274 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2274 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
2275 | 2275 |
2276 BUILD(r, WASM_IF_ELSE( | 2276 BUILD(r, WASM_IF_ELSE( |
2277 WASM_GET_LOCAL(0), | 2277 WASM_GET_LOCAL(0), |
2278 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), | 2278 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), |
2279 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); | 2279 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); |
2280 | 2280 |
2281 CHECK_EQ(11, r.Call(1, 1)); | 2281 CHECK_EQ(11, r.Call(1, 1)); |
2282 CHECK_EQ(12, r.Call(1, 0)); | 2282 CHECK_EQ(12, r.Call(1, 0)); |
2283 CHECK_EQ(13, r.Call(0, 1)); | 2283 CHECK_EQ(13, r.Call(0, 1)); |
2284 CHECK_EQ(14, r.Call(0, 0)); | 2284 CHECK_EQ(14, r.Call(0, 0)); |
2285 } | 2285 } |
2286 | 2286 |
2287 TEST(Run_Wasm_ExprBlock_if) { | 2287 WASM_EXEC_TEST(ExprBlock_if) { |
2288 WasmRunner<int32_t> r(MachineType::Int32()); | 2288 WasmRunner<int32_t> r(MachineType::Int32()); |
2289 | 2289 |
2290 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)), | 2290 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)), |
2291 WASM_BRV(1, WASM_I8(14))))); | 2291 WASM_BRV(1, WASM_I8(14))))); |
2292 | 2292 |
2293 CHECK_EQ(11, r.Call(1)); | 2293 CHECK_EQ(11, r.Call(1)); |
2294 CHECK_EQ(14, r.Call(0)); | 2294 CHECK_EQ(14, r.Call(0)); |
2295 } | 2295 } |
2296 | 2296 |
2297 TEST(Run_Wasm_ExprBlock_nested_ifs) { | 2297 WASM_EXEC_TEST(ExprBlock_nested_ifs) { |
2298 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2298 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
2299 | 2299 |
2300 BUILD(r, WASM_BLOCK( | 2300 BUILD(r, WASM_BLOCK( |
2301 1, WASM_IF_ELSE( | 2301 1, WASM_IF_ELSE( |
2302 WASM_GET_LOCAL(0), | 2302 WASM_GET_LOCAL(0), |
2303 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)), | 2303 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)), |
2304 WASM_BRV(1, WASM_I8(12))), | 2304 WASM_BRV(1, WASM_I8(12))), |
2305 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)), | 2305 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)), |
2306 WASM_BRV(1, WASM_I8(14)))))); | 2306 WASM_BRV(1, WASM_I8(14)))))); |
2307 | 2307 |
2308 CHECK_EQ(11, r.Call(1, 1)); | 2308 CHECK_EQ(11, r.Call(1, 1)); |
2309 CHECK_EQ(12, r.Call(1, 0)); | 2309 CHECK_EQ(12, r.Call(1, 0)); |
2310 CHECK_EQ(13, r.Call(0, 1)); | 2310 CHECK_EQ(13, r.Call(0, 1)); |
2311 CHECK_EQ(14, r.Call(0, 0)); | 2311 CHECK_EQ(14, r.Call(0, 0)); |
2312 } | 2312 } |
2313 | 2313 |
2314 TEST(Run_Wasm_ExprLoop_nested_ifs) { | 2314 WASM_EXEC_TEST(ExprLoop_nested_ifs) { |
2315 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2315 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
2316 | 2316 |
2317 BUILD(r, WASM_LOOP( | 2317 BUILD(r, WASM_LOOP( |
2318 1, WASM_IF_ELSE( | 2318 1, WASM_IF_ELSE( |
2319 WASM_GET_LOCAL(0), | 2319 WASM_GET_LOCAL(0), |
2320 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(11)), | 2320 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(11)), |
2321 WASM_BRV(3, WASM_I8(12))), | 2321 WASM_BRV(3, WASM_I8(12))), |
2322 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(13)), | 2322 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(13)), |
2323 WASM_BRV(3, WASM_I8(14)))))); | 2323 WASM_BRV(3, WASM_I8(14)))))); |
2324 | 2324 |
2325 CHECK_EQ(11, r.Call(1, 1)); | 2325 CHECK_EQ(11, r.Call(1, 1)); |
2326 CHECK_EQ(12, r.Call(1, 0)); | 2326 CHECK_EQ(12, r.Call(1, 0)); |
2327 CHECK_EQ(13, r.Call(0, 1)); | 2327 CHECK_EQ(13, r.Call(0, 1)); |
2328 CHECK_EQ(14, r.Call(0, 0)); | 2328 CHECK_EQ(14, r.Call(0, 0)); |
2329 } | 2329 } |
2330 | 2330 |
2331 TEST(Run_Wasm_SimpleCallIndirect) { | 2331 WASM_EXEC_TEST(SimpleCallIndirect) { |
2332 TestSignatures sigs; | 2332 TestSignatures sigs; |
2333 TestingModule module; | 2333 TestingModule module; |
2334 | 2334 |
2335 WasmFunctionCompiler t1(sigs.i_ii(), &module); | 2335 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2336 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2336 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2337 t1.CompileAndAdd(/*sig_index*/ 1); | 2337 t1.CompileAndAdd(/*sig_index*/ 1); |
2338 | 2338 |
2339 WasmFunctionCompiler t2(sigs.i_ii(), &module); | 2339 WasmFunctionCompiler t2(sigs.i_ii(), &module); |
2340 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2340 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2341 t2.CompileAndAdd(/*sig_index*/ 1); | 2341 t2.CompileAndAdd(/*sig_index*/ 1); |
(...skipping 10 matching lines...) Expand all Loading... |
2352 | 2352 |
2353 // Builder the caller function. | 2353 // Builder the caller function. |
2354 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 2354 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2355 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 2355 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); |
2356 | 2356 |
2357 CHECK_EQ(88, r.Call(0)); | 2357 CHECK_EQ(88, r.Call(0)); |
2358 CHECK_EQ(44, r.Call(1)); | 2358 CHECK_EQ(44, r.Call(1)); |
2359 CHECK_TRAP(r.Call(2)); | 2359 CHECK_TRAP(r.Call(2)); |
2360 } | 2360 } |
2361 | 2361 |
2362 TEST(Run_Wasm_MultipleCallIndirect) { | 2362 WASM_EXEC_TEST(MultipleCallIndirect) { |
2363 TestSignatures sigs; | 2363 TestSignatures sigs; |
2364 TestingModule module; | 2364 TestingModule module; |
2365 | 2365 |
2366 WasmFunctionCompiler t1(sigs.i_ii(), &module); | 2366 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2367 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2367 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2368 t1.CompileAndAdd(/*sig_index*/ 1); | 2368 t1.CompileAndAdd(/*sig_index*/ 1); |
2369 | 2369 |
2370 WasmFunctionCompiler t2(sigs.i_ii(), &module); | 2370 WasmFunctionCompiler t2(sigs.i_ii(), &module); |
2371 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2371 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2372 t2.CompileAndAdd(/*sig_index*/ 1); | 2372 t2.CompileAndAdd(/*sig_index*/ 1); |
(...skipping 21 matching lines...) Expand all Loading... |
2394 CHECK_EQ(19, r.Call(0, 1, 9)); | 2394 CHECK_EQ(19, r.Call(0, 1, 9)); |
2395 CHECK_EQ(1, r.Call(1, 0, 2)); | 2395 CHECK_EQ(1, r.Call(1, 0, 2)); |
2396 CHECK_EQ(1, r.Call(1, 0, 9)); | 2396 CHECK_EQ(1, r.Call(1, 0, 9)); |
2397 | 2397 |
2398 CHECK_TRAP(r.Call(0, 2, 1)); | 2398 CHECK_TRAP(r.Call(0, 2, 1)); |
2399 CHECK_TRAP(r.Call(1, 2, 0)); | 2399 CHECK_TRAP(r.Call(1, 2, 0)); |
2400 CHECK_TRAP(r.Call(2, 0, 1)); | 2400 CHECK_TRAP(r.Call(2, 0, 1)); |
2401 CHECK_TRAP(r.Call(2, 1, 0)); | 2401 CHECK_TRAP(r.Call(2, 1, 0)); |
2402 } | 2402 } |
2403 | 2403 |
2404 TEST(Run_Wasm_CallIndirect_NoTable) { | 2404 WASM_EXEC_TEST(CallIndirect_NoTable) { |
2405 TestSignatures sigs; | 2405 TestSignatures sigs; |
2406 TestingModule module; | 2406 TestingModule module; |
2407 | 2407 |
2408 // One function. | 2408 // One function. |
2409 WasmFunctionCompiler t1(sigs.i_ii(), &module); | 2409 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2410 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2410 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2411 t1.CompileAndAdd(/*sig_index*/ 1); | 2411 t1.CompileAndAdd(/*sig_index*/ 1); |
2412 | 2412 |
2413 // Signature table. | 2413 // Signature table. |
2414 module.AddSignature(sigs.f_ff()); | 2414 module.AddSignature(sigs.f_ff()); |
2415 module.AddSignature(sigs.i_ii()); | 2415 module.AddSignature(sigs.i_ii()); |
2416 | 2416 |
2417 // Builder the caller function. | 2417 // Builder the caller function. |
2418 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 2418 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2419 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 2419 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); |
2420 | 2420 |
2421 CHECK_TRAP(r.Call(0)); | 2421 CHECK_TRAP(r.Call(0)); |
2422 CHECK_TRAP(r.Call(1)); | 2422 CHECK_TRAP(r.Call(1)); |
2423 CHECK_TRAP(r.Call(2)); | 2423 CHECK_TRAP(r.Call(2)); |
2424 } | 2424 } |
2425 | 2425 |
2426 TEST(Run_Wasm_F32Floor) { | 2426 WASM_EXEC_TEST(F32Floor) { |
2427 WasmRunner<float> r(MachineType::Float32()); | 2427 WasmRunner<float> r(MachineType::Float32()); |
2428 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); | 2428 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); |
2429 | 2429 |
2430 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); } | 2430 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); } |
2431 } | 2431 } |
2432 | 2432 |
2433 TEST(Run_Wasm_F32Ceil) { | 2433 WASM_EXEC_TEST(F32Ceil) { |
2434 WasmRunner<float> r(MachineType::Float32()); | 2434 WasmRunner<float> r(MachineType::Float32()); |
2435 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); | 2435 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); |
2436 | 2436 |
2437 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(ceilf(*i), r.Call(*i)); } | 2437 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(ceilf(*i), r.Call(*i)); } |
2438 } | 2438 } |
2439 | 2439 |
2440 TEST(Run_Wasm_F32Trunc) { | 2440 WASM_EXEC_TEST(F32Trunc) { |
2441 WasmRunner<float> r(MachineType::Float32()); | 2441 WasmRunner<float> r(MachineType::Float32()); |
2442 BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0))); | 2442 BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0))); |
2443 | 2443 |
2444 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(truncf(*i), r.Call(*i)); } | 2444 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(truncf(*i), r.Call(*i)); } |
2445 } | 2445 } |
2446 | 2446 |
2447 TEST(Run_Wasm_F32NearestInt) { | 2447 WASM_EXEC_TEST(F32NearestInt) { |
2448 WasmRunner<float> r(MachineType::Float32()); | 2448 WasmRunner<float> r(MachineType::Float32()); |
2449 BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0))); | 2449 BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0))); |
2450 | 2450 |
2451 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(nearbyintf(*i), r.Call(*i)); } | 2451 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(nearbyintf(*i), r.Call(*i)); } |
2452 } | 2452 } |
2453 | 2453 |
2454 TEST(Run_Wasm_F64Floor) { | 2454 WASM_EXEC_TEST(F64Floor) { |
2455 WasmRunner<double> r(MachineType::Float64()); | 2455 WasmRunner<double> r(MachineType::Float64()); |
2456 BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0))); | 2456 BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0))); |
2457 | 2457 |
2458 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(floor(*i), r.Call(*i)); } | 2458 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(floor(*i), r.Call(*i)); } |
2459 } | 2459 } |
2460 | 2460 |
2461 TEST(Run_Wasm_F64Ceil) { | 2461 WASM_EXEC_TEST(F64Ceil) { |
2462 WasmRunner<double> r(MachineType::Float64()); | 2462 WasmRunner<double> r(MachineType::Float64()); |
2463 BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0))); | 2463 BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0))); |
2464 | 2464 |
2465 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ceil(*i), r.Call(*i)); } | 2465 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ceil(*i), r.Call(*i)); } |
2466 } | 2466 } |
2467 | 2467 |
2468 TEST(Run_Wasm_F64Trunc) { | 2468 WASM_EXEC_TEST(F64Trunc) { |
2469 WasmRunner<double> r(MachineType::Float64()); | 2469 WasmRunner<double> r(MachineType::Float64()); |
2470 BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0))); | 2470 BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0))); |
2471 | 2471 |
2472 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(trunc(*i), r.Call(*i)); } | 2472 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(trunc(*i), r.Call(*i)); } |
2473 } | 2473 } |
2474 | 2474 |
2475 TEST(Run_Wasm_F64NearestInt) { | 2475 WASM_EXEC_TEST(F64NearestInt) { |
2476 WasmRunner<double> r(MachineType::Float64()); | 2476 WasmRunner<double> r(MachineType::Float64()); |
2477 BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0))); | 2477 BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0))); |
2478 | 2478 |
2479 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(nearbyint(*i), r.Call(*i)); } | 2479 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(nearbyint(*i), r.Call(*i)); } |
2480 } | 2480 } |
2481 | 2481 |
2482 TEST(Run_Wasm_F32Min) { | 2482 WASM_EXEC_TEST(F32Min) { |
2483 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 2483 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); |
2484 BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2484 BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2485 | 2485 |
2486 FOR_FLOAT32_INPUTS(i) { | 2486 FOR_FLOAT32_INPUTS(i) { |
2487 FOR_FLOAT32_INPUTS(j) { | 2487 FOR_FLOAT32_INPUTS(j) { |
2488 float expected; | 2488 float expected; |
2489 if (*i < *j) { | 2489 if (*i < *j) { |
2490 expected = *i; | 2490 expected = *i; |
2491 } else if (*j < *i) { | 2491 } else if (*j < *i) { |
2492 expected = *j; | 2492 expected = *j; |
2493 } else if (*i != *i) { | 2493 } else if (*i != *i) { |
2494 // If *i or *j is NaN, then the result is NaN. | 2494 // If *i or *j is NaN, then the result is NaN. |
2495 expected = *i; | 2495 expected = *i; |
2496 } else { | 2496 } else { |
2497 expected = *j; | 2497 expected = *j; |
2498 } | 2498 } |
2499 | 2499 |
2500 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); | 2500 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); |
2501 } | 2501 } |
2502 } | 2502 } |
2503 } | 2503 } |
2504 | 2504 |
2505 TEST(Run_Wasm_F64Min) { | 2505 WASM_EXEC_TEST(F64Min) { |
2506 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 2506 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); |
2507 BUILD(r, WASM_F64_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2507 BUILD(r, WASM_F64_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2508 | 2508 |
2509 FOR_FLOAT64_INPUTS(i) { | 2509 FOR_FLOAT64_INPUTS(i) { |
2510 FOR_FLOAT64_INPUTS(j) { | 2510 FOR_FLOAT64_INPUTS(j) { |
2511 double expected; | 2511 double expected; |
2512 if (*i < *j) { | 2512 if (*i < *j) { |
2513 expected = *i; | 2513 expected = *i; |
2514 } else if (*j < *i) { | 2514 } else if (*j < *i) { |
2515 expected = *j; | 2515 expected = *j; |
2516 } else if (*i != *i) { | 2516 } else if (*i != *i) { |
2517 // If *i or *j is NaN, then the result is NaN. | 2517 // If *i or *j is NaN, then the result is NaN. |
2518 expected = *i; | 2518 expected = *i; |
2519 } else { | 2519 } else { |
2520 expected = *j; | 2520 expected = *j; |
2521 } | 2521 } |
2522 | 2522 |
2523 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); | 2523 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); |
2524 } | 2524 } |
2525 } | 2525 } |
2526 } | 2526 } |
2527 | 2527 |
2528 TEST(Run_Wasm_F32Max) { | 2528 WASM_EXEC_TEST(F32Max) { |
2529 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 2529 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); |
2530 BUILD(r, WASM_F32_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2530 BUILD(r, WASM_F32_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2531 | 2531 |
2532 FOR_FLOAT32_INPUTS(i) { | 2532 FOR_FLOAT32_INPUTS(i) { |
2533 FOR_FLOAT32_INPUTS(j) { | 2533 FOR_FLOAT32_INPUTS(j) { |
2534 float expected; | 2534 float expected; |
2535 if (*i > *j) { | 2535 if (*i > *j) { |
2536 expected = *i; | 2536 expected = *i; |
2537 } else if (*j > *i) { | 2537 } else if (*j > *i) { |
2538 expected = *j; | 2538 expected = *j; |
2539 } else if (*i != *i) { | 2539 } else if (*i != *i) { |
2540 // If *i or *j is NaN, then the result is NaN. | 2540 // If *i or *j is NaN, then the result is NaN. |
2541 expected = *i; | 2541 expected = *i; |
2542 } else { | 2542 } else { |
2543 expected = *j; | 2543 expected = *j; |
2544 } | 2544 } |
2545 | 2545 |
2546 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); | 2546 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); |
2547 } | 2547 } |
2548 } | 2548 } |
2549 } | 2549 } |
2550 | 2550 |
2551 TEST(Run_Wasm_F64Max) { | 2551 WASM_EXEC_TEST(F64Max) { |
2552 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 2552 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); |
2553 BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2553 BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2554 | 2554 |
2555 FOR_FLOAT64_INPUTS(i) { | 2555 FOR_FLOAT64_INPUTS(i) { |
2556 FOR_FLOAT64_INPUTS(j) { | 2556 FOR_FLOAT64_INPUTS(j) { |
2557 double expected; | 2557 double expected; |
2558 if (*i > *j) { | 2558 if (*i > *j) { |
2559 expected = *i; | 2559 expected = *i; |
2560 } else if (*j > *i) { | 2560 } else if (*j > *i) { |
2561 expected = *j; | 2561 expected = *j; |
2562 } else if (*i != *i) { | 2562 } else if (*i != *i) { |
2563 // If *i or *j is NaN, then the result is NaN. | 2563 // If *i or *j is NaN, then the result is NaN. |
2564 expected = *i; | 2564 expected = *i; |
2565 } else { | 2565 } else { |
2566 expected = *j; | 2566 expected = *j; |
2567 } | 2567 } |
2568 | 2568 |
2569 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); | 2569 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); |
2570 } | 2570 } |
2571 } | 2571 } |
2572 } | 2572 } |
2573 | 2573 |
2574 // TODO(ahaas): Fix on mips and reenable. | 2574 // TODO(ahaas): Fix on mips and reenable. |
2575 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 | 2575 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 |
2576 | 2576 |
2577 TEST(Run_Wasm_F32Min_Snan) { | 2577 WASM_EXEC_TEST(F32Min_Snan) { |
2578 // Test that the instruction does not return a signalling NaN. | 2578 // Test that the instruction does not return a signalling NaN. |
2579 { | 2579 { |
2580 WasmRunner<float> r; | 2580 WasmRunner<float> r; |
2581 BUILD(r, | 2581 BUILD(r, |
2582 WASM_F32_MIN(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67))); | 2582 WASM_F32_MIN(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67))); |
2583 CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call())); | 2583 CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call())); |
2584 } | 2584 } |
2585 { | 2585 { |
2586 WasmRunner<float> r; | 2586 WasmRunner<float> r; |
2587 BUILD(r, | 2587 BUILD(r, |
2588 WASM_F32_MIN(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2)))); | 2588 WASM_F32_MIN(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2)))); |
2589 CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call())); | 2589 CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call())); |
2590 } | 2590 } |
2591 } | 2591 } |
2592 | 2592 |
2593 TEST(Run_Wasm_F32Max_Snan) { | 2593 WASM_EXEC_TEST(F32Max_Snan) { |
2594 // Test that the instruction does not return a signalling NaN. | 2594 // Test that the instruction does not return a signalling NaN. |
2595 { | 2595 { |
2596 WasmRunner<float> r; | 2596 WasmRunner<float> r; |
2597 BUILD(r, | 2597 BUILD(r, |
2598 WASM_F32_MAX(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67))); | 2598 WASM_F32_MAX(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67))); |
2599 CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call())); | 2599 CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call())); |
2600 } | 2600 } |
2601 { | 2601 { |
2602 WasmRunner<float> r; | 2602 WasmRunner<float> r; |
2603 BUILD(r, | 2603 BUILD(r, |
2604 WASM_F32_MAX(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2)))); | 2604 WASM_F32_MAX(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2)))); |
2605 CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call())); | 2605 CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call())); |
2606 } | 2606 } |
2607 } | 2607 } |
2608 | 2608 |
2609 TEST(Run_Wasm_F64Min_Snan) { | 2609 WASM_EXEC_TEST(F64Min_Snan) { |
2610 // Test that the instruction does not return a signalling NaN. | 2610 // Test that the instruction does not return a signalling NaN. |
2611 { | 2611 { |
2612 WasmRunner<double> r; | 2612 WasmRunner<double> r; |
2613 BUILD(r, WASM_F64_MIN(WASM_F64(bit_cast<double>(0xfff000000000f1e2)), | 2613 BUILD(r, WASM_F64_MIN(WASM_F64(bit_cast<double>(0xfff000000000f1e2)), |
2614 WASM_F64(57.67))); | 2614 WASM_F64(57.67))); |
2615 CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 2615 CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
2616 } | 2616 } |
2617 { | 2617 { |
2618 WasmRunner<double> r; | 2618 WasmRunner<double> r; |
2619 BUILD(r, WASM_F64_MIN(WASM_F64(45.73), | 2619 BUILD(r, WASM_F64_MIN(WASM_F64(45.73), |
2620 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); | 2620 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); |
2621 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 2621 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
2622 } | 2622 } |
2623 } | 2623 } |
2624 | 2624 |
2625 TEST(Run_Wasm_F64Max_Snan) { | 2625 WASM_EXEC_TEST(F64Max_Snan) { |
2626 // Test that the instruction does not return a signalling NaN. | 2626 // Test that the instruction does not return a signalling NaN. |
2627 { | 2627 { |
2628 WasmRunner<double> r; | 2628 WasmRunner<double> r; |
2629 BUILD(r, WASM_F64_MAX(WASM_F64(bit_cast<double>(0xfff000000000f1e2)), | 2629 BUILD(r, WASM_F64_MAX(WASM_F64(bit_cast<double>(0xfff000000000f1e2)), |
2630 WASM_F64(57.67))); | 2630 WASM_F64(57.67))); |
2631 CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 2631 CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
2632 } | 2632 } |
2633 { | 2633 { |
2634 WasmRunner<double> r; | 2634 WasmRunner<double> r; |
2635 BUILD(r, WASM_F64_MAX(WASM_F64(45.73), | 2635 BUILD(r, WASM_F64_MAX(WASM_F64(45.73), |
2636 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); | 2636 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); |
2637 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 2637 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
2638 } | 2638 } |
2639 } | 2639 } |
2640 | 2640 |
2641 #endif | 2641 #endif |
2642 | 2642 |
2643 TEST(Run_Wasm_I32SConvertF32) { | 2643 WASM_EXEC_TEST(I32SConvertF32) { |
2644 WasmRunner<int32_t> r(MachineType::Float32()); | 2644 WasmRunner<int32_t> r(MachineType::Float32()); |
2645 BUILD(r, WASM_I32_SCONVERT_F32(WASM_GET_LOCAL(0))); | 2645 BUILD(r, WASM_I32_SCONVERT_F32(WASM_GET_LOCAL(0))); |
2646 | 2646 |
2647 FOR_FLOAT32_INPUTS(i) { | 2647 FOR_FLOAT32_INPUTS(i) { |
2648 if (*i < static_cast<float>(INT32_MAX) && | 2648 if (*i < static_cast<float>(INT32_MAX) && |
2649 *i >= static_cast<float>(INT32_MIN)) { | 2649 *i >= static_cast<float>(INT32_MIN)) { |
2650 CHECK_EQ(static_cast<int32_t>(*i), r.Call(*i)); | 2650 CHECK_EQ(static_cast<int32_t>(*i), r.Call(*i)); |
2651 } else { | 2651 } else { |
2652 CHECK_TRAP32(r.Call(*i)); | 2652 CHECK_TRAP32(r.Call(*i)); |
2653 } | 2653 } |
2654 } | 2654 } |
2655 } | 2655 } |
2656 | 2656 |
2657 TEST(Run_Wasm_I32SConvertF64) { | 2657 WASM_EXEC_TEST(I32SConvertF64) { |
2658 WasmRunner<int32_t> r(MachineType::Float64()); | 2658 WasmRunner<int32_t> r(MachineType::Float64()); |
2659 BUILD(r, WASM_I32_SCONVERT_F64(WASM_GET_LOCAL(0))); | 2659 BUILD(r, WASM_I32_SCONVERT_F64(WASM_GET_LOCAL(0))); |
2660 | 2660 |
2661 FOR_FLOAT64_INPUTS(i) { | 2661 FOR_FLOAT64_INPUTS(i) { |
2662 if (*i < (static_cast<double>(INT32_MAX) + 1.0) && | 2662 if (*i < (static_cast<double>(INT32_MAX) + 1.0) && |
2663 *i > (static_cast<double>(INT32_MIN) - 1.0)) { | 2663 *i > (static_cast<double>(INT32_MIN) - 1.0)) { |
2664 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); | 2664 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); |
2665 } else { | 2665 } else { |
2666 CHECK_TRAP32(r.Call(*i)); | 2666 CHECK_TRAP32(r.Call(*i)); |
2667 } | 2667 } |
2668 } | 2668 } |
2669 } | 2669 } |
2670 | 2670 |
2671 TEST(Run_Wasm_I32UConvertF32) { | 2671 WASM_EXEC_TEST(I32UConvertF32) { |
2672 WasmRunner<uint32_t> r(MachineType::Float32()); | 2672 WasmRunner<uint32_t> r(MachineType::Float32()); |
2673 BUILD(r, WASM_I32_UCONVERT_F32(WASM_GET_LOCAL(0))); | 2673 BUILD(r, WASM_I32_UCONVERT_F32(WASM_GET_LOCAL(0))); |
2674 | 2674 |
2675 FOR_FLOAT32_INPUTS(i) { | 2675 FOR_FLOAT32_INPUTS(i) { |
2676 if (*i < (static_cast<float>(UINT32_MAX) + 1.0) && *i > -1) { | 2676 if (*i < (static_cast<float>(UINT32_MAX) + 1.0) && *i > -1) { |
2677 CHECK_EQ(static_cast<uint32_t>(*i), r.Call(*i)); | 2677 CHECK_EQ(static_cast<uint32_t>(*i), r.Call(*i)); |
2678 } else { | 2678 } else { |
2679 CHECK_TRAP32(r.Call(*i)); | 2679 CHECK_TRAP32(r.Call(*i)); |
2680 } | 2680 } |
2681 } | 2681 } |
2682 } | 2682 } |
2683 | 2683 |
2684 TEST(Run_Wasm_I32UConvertF64) { | 2684 WASM_EXEC_TEST(I32UConvertF64) { |
2685 WasmRunner<uint32_t> r(MachineType::Float64()); | 2685 WasmRunner<uint32_t> r(MachineType::Float64()); |
2686 BUILD(r, WASM_I32_UCONVERT_F64(WASM_GET_LOCAL(0))); | 2686 BUILD(r, WASM_I32_UCONVERT_F64(WASM_GET_LOCAL(0))); |
2687 | 2687 |
2688 FOR_FLOAT64_INPUTS(i) { | 2688 FOR_FLOAT64_INPUTS(i) { |
2689 if (*i < (static_cast<float>(UINT32_MAX) + 1.0) && *i > -1) { | 2689 if (*i < (static_cast<float>(UINT32_MAX) + 1.0) && *i > -1) { |
2690 CHECK_EQ(static_cast<uint32_t>(*i), r.Call(*i)); | 2690 CHECK_EQ(static_cast<uint32_t>(*i), r.Call(*i)); |
2691 } else { | 2691 } else { |
2692 CHECK_TRAP32(r.Call(*i)); | 2692 CHECK_TRAP32(r.Call(*i)); |
2693 } | 2693 } |
2694 } | 2694 } |
2695 } | 2695 } |
2696 | 2696 |
2697 TEST(Run_Wasm_F64CopySign) { | 2697 WASM_EXEC_TEST(F64CopySign) { |
2698 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 2698 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); |
2699 BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2699 BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2700 | 2700 |
2701 FOR_FLOAT64_INPUTS(i) { | 2701 FOR_FLOAT64_INPUTS(i) { |
2702 FOR_FLOAT64_INPUTS(j) { CHECK_DOUBLE_EQ(copysign(*i, *j), r.Call(*i, *j)); } | 2702 FOR_FLOAT64_INPUTS(j) { CHECK_DOUBLE_EQ(copysign(*i, *j), r.Call(*i, *j)); } |
2703 } | 2703 } |
2704 } | 2704 } |
2705 | 2705 |
2706 TEST(Run_Wasm_F32CopySign) { | 2706 WASM_EXEC_TEST(F32CopySign) { |
2707 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 2707 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); |
2708 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2708 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2709 | 2709 |
2710 FOR_FLOAT32_INPUTS(i) { | 2710 FOR_FLOAT32_INPUTS(i) { |
2711 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysignf(*i, *j), r.Call(*i, *j)); } | 2711 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysignf(*i, *j), r.Call(*i, *j)); } |
2712 } | 2712 } |
2713 } | 2713 } |
2714 | 2714 |
2715 void CompileCallIndirectMany(LocalType param) { | 2715 void CompileCallIndirectMany(LocalType param) { |
2716 // Make sure we don't run out of registers when compiling indirect calls | 2716 // Make sure we don't run out of registers when compiling indirect calls |
(...skipping 27 matching lines...) Expand all Loading... |
2744 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); } | 2744 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); } |
2745 | 2745 |
2746 #if WASM_64 | 2746 #if WASM_64 |
2747 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 2747 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } |
2748 #endif | 2748 #endif |
2749 | 2749 |
2750 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } | 2750 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } |
2751 | 2751 |
2752 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } | 2752 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } |
2753 | 2753 |
2754 TEST(Run_WASM_Int32RemS_dead) { | 2754 WASM_EXEC_TEST(Int32RemS_dead) { |
2755 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2755 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
2756 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); | 2756 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); |
2757 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 2757 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
2758 CHECK_EQ(0, r.Call(133, 100)); | 2758 CHECK_EQ(0, r.Call(133, 100)); |
2759 CHECK_EQ(0, r.Call(kMin, -1)); | 2759 CHECK_EQ(0, r.Call(kMin, -1)); |
2760 CHECK_EQ(0, r.Call(0, 1)); | 2760 CHECK_EQ(0, r.Call(0, 1)); |
2761 CHECK_TRAP(r.Call(100, 0)); | 2761 CHECK_TRAP(r.Call(100, 0)); |
2762 CHECK_TRAP(r.Call(-1001, 0)); | 2762 CHECK_TRAP(r.Call(-1001, 0)); |
2763 CHECK_TRAP(r.Call(kMin, 0)); | 2763 CHECK_TRAP(r.Call(kMin, 0)); |
2764 } | 2764 } |
OLD | NEW |