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/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 const int64_t kExpectedValue = (static_cast<int64_t>(*i) << 32) | cntr; | 113 const int64_t kExpectedValue = (static_cast<int64_t>(*i) << 32) | cntr; |
114 // return(kExpectedValue) | 114 // return(kExpectedValue) |
115 BUILD(r, WASM_I64V(kExpectedValue)); | 115 BUILD(r, WASM_I64V(kExpectedValue)); |
116 CHECK_EQ(kExpectedValue, r.Call()); | 116 CHECK_EQ(kExpectedValue, r.Call()); |
117 cntr++; | 117 cntr++; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 WASM_EXEC_TEST(Return_I64) { | 121 WASM_EXEC_TEST(Return_I64) { |
122 REQUIRE(I64Return); | 122 REQUIRE(I64Return); |
123 WasmRunner<int64_t, int64_t> r(execution_mode); | 123 WasmRunner<int64_t> r(execution_mode, MachineType::Int64()); |
124 | 124 |
125 BUILD(r, WASM_RETURN1(WASM_GET_LOCAL(0))); | 125 BUILD(r, WASM_RETURN1(WASM_GET_LOCAL(0))); |
126 | 126 |
127 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 127 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
128 } | 128 } |
129 | 129 |
130 WASM_EXEC_TEST(I64Add) { | 130 WASM_EXEC_TEST(I64Add) { |
131 REQUIRE(I64Add); | 131 REQUIRE(I64Add); |
132 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 132 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 133 MachineType::Int64()); |
133 BUILD(r, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 134 BUILD(r, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
134 FOR_INT64_INPUTS(i) { | 135 FOR_INT64_INPUTS(i) { |
135 FOR_INT64_INPUTS(j) { CHECK_EQ(*i + *j, r.Call(*i, *j)); } | 136 FOR_INT64_INPUTS(j) { CHECK_EQ(*i + *j, r.Call(*i, *j)); } |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 WASM_EXEC_TEST(I64Sub) { | 140 WASM_EXEC_TEST(I64Sub) { |
140 REQUIRE(I64Sub); | 141 REQUIRE(I64Sub); |
141 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 142 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 143 MachineType::Int64()); |
142 BUILD(r, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 144 BUILD(r, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
143 FOR_INT64_INPUTS(i) { | 145 FOR_INT64_INPUTS(i) { |
144 FOR_INT64_INPUTS(j) { CHECK_EQ(*i - *j, r.Call(*i, *j)); } | 146 FOR_INT64_INPUTS(j) { CHECK_EQ(*i - *j, r.Call(*i, *j)); } |
145 } | 147 } |
146 } | 148 } |
147 | 149 |
148 WASM_EXEC_TEST(I64AddUseOnlyLowWord) { | 150 WASM_EXEC_TEST(I64AddUseOnlyLowWord) { |
149 REQUIRE(I64Add); | 151 REQUIRE(I64Add); |
150 REQUIRE(I32ConvertI64); | 152 REQUIRE(I32ConvertI64); |
151 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 153 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 154 MachineType::Int64()); |
152 BUILD(r, WASM_I32_CONVERT_I64( | 155 BUILD(r, WASM_I32_CONVERT_I64( |
153 WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); | 156 WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); |
154 FOR_INT64_INPUTS(i) { | 157 FOR_INT64_INPUTS(i) { |
155 FOR_INT64_INPUTS(j) { | 158 FOR_INT64_INPUTS(j) { |
156 CHECK_EQ(static_cast<int32_t>(*i + *j), r.Call(*i, *j)); | 159 CHECK_EQ(static_cast<int32_t>(*i + *j), r.Call(*i, *j)); |
157 } | 160 } |
158 } | 161 } |
159 } | 162 } |
160 | 163 |
161 WASM_EXEC_TEST(I64SubUseOnlyLowWord) { | 164 WASM_EXEC_TEST(I64SubUseOnlyLowWord) { |
162 REQUIRE(I64Sub); | 165 REQUIRE(I64Sub); |
163 REQUIRE(I32ConvertI64); | 166 REQUIRE(I32ConvertI64); |
164 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 167 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 168 MachineType::Int64()); |
165 BUILD(r, WASM_I32_CONVERT_I64( | 169 BUILD(r, WASM_I32_CONVERT_I64( |
166 WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); | 170 WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); |
167 FOR_INT64_INPUTS(i) { | 171 FOR_INT64_INPUTS(i) { |
168 FOR_INT64_INPUTS(j) { | 172 FOR_INT64_INPUTS(j) { |
169 CHECK_EQ(static_cast<int32_t>(*i - *j), r.Call(*i, *j)); | 173 CHECK_EQ(static_cast<int32_t>(*i - *j), r.Call(*i, *j)); |
170 } | 174 } |
171 } | 175 } |
172 } | 176 } |
173 | 177 |
174 WASM_EXEC_TEST(I64MulUseOnlyLowWord) { | 178 WASM_EXEC_TEST(I64MulUseOnlyLowWord) { |
175 REQUIRE(I64Mul); | 179 REQUIRE(I64Mul); |
176 REQUIRE(I32ConvertI64); | 180 REQUIRE(I32ConvertI64); |
177 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 181 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 182 MachineType::Int64()); |
178 BUILD(r, WASM_I32_CONVERT_I64( | 183 BUILD(r, WASM_I32_CONVERT_I64( |
179 WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); | 184 WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); |
180 FOR_INT64_INPUTS(i) { | 185 FOR_INT64_INPUTS(i) { |
181 FOR_INT64_INPUTS(j) { | 186 FOR_INT64_INPUTS(j) { |
182 CHECK_EQ(static_cast<int32_t>(*i * *j), r.Call(*i, *j)); | 187 CHECK_EQ(static_cast<int32_t>(*i * *j), r.Call(*i, *j)); |
183 } | 188 } |
184 } | 189 } |
185 } | 190 } |
186 | 191 |
187 WASM_EXEC_TEST(I64ShlUseOnlyLowWord) { | 192 WASM_EXEC_TEST(I64ShlUseOnlyLowWord) { |
188 REQUIRE(I64Shl); | 193 REQUIRE(I64Shl); |
189 REQUIRE(I32ConvertI64); | 194 REQUIRE(I32ConvertI64); |
190 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 195 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 196 MachineType::Int64()); |
191 BUILD(r, WASM_I32_CONVERT_I64( | 197 BUILD(r, WASM_I32_CONVERT_I64( |
192 WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); | 198 WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); |
193 FOR_INT64_INPUTS(i) { | 199 FOR_INT64_INPUTS(i) { |
194 FOR_INT64_INPUTS(j) { | 200 FOR_INT64_INPUTS(j) { |
195 int32_t expected = static_cast<int32_t>((*i) << (*j & 0x3f)); | 201 int32_t expected = static_cast<int32_t>((*i) << (*j & 0x3f)); |
196 CHECK_EQ(expected, r.Call(*i, *j)); | 202 CHECK_EQ(expected, r.Call(*i, *j)); |
197 } | 203 } |
198 } | 204 } |
199 } | 205 } |
200 | 206 |
201 WASM_EXEC_TEST(I64ShrUseOnlyLowWord) { | 207 WASM_EXEC_TEST(I64ShrUseOnlyLowWord) { |
202 REQUIRE(I64ShrU); | 208 REQUIRE(I64ShrU); |
203 REQUIRE(I32ConvertI64); | 209 REQUIRE(I32ConvertI64); |
204 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 210 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 211 MachineType::Int64()); |
205 BUILD(r, WASM_I32_CONVERT_I64( | 212 BUILD(r, WASM_I32_CONVERT_I64( |
206 WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); | 213 WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); |
207 FOR_UINT64_INPUTS(i) { | 214 FOR_UINT64_INPUTS(i) { |
208 FOR_UINT64_INPUTS(j) { | 215 FOR_UINT64_INPUTS(j) { |
209 int32_t expected = static_cast<int32_t>((*i) >> (*j & 0x3f)); | 216 int32_t expected = static_cast<int32_t>((*i) >> (*j & 0x3f)); |
210 CHECK_EQ(expected, r.Call(*i, *j)); | 217 CHECK_EQ(expected, r.Call(*i, *j)); |
211 } | 218 } |
212 } | 219 } |
213 } | 220 } |
214 | 221 |
215 WASM_EXEC_TEST(I64SarUseOnlyLowWord) { | 222 WASM_EXEC_TEST(I64SarUseOnlyLowWord) { |
216 REQUIRE(I64ShrS); | 223 REQUIRE(I64ShrS); |
217 REQUIRE(I32ConvertI64); | 224 REQUIRE(I32ConvertI64); |
218 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 225 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 226 MachineType::Int64()); |
219 BUILD(r, WASM_I32_CONVERT_I64( | 227 BUILD(r, WASM_I32_CONVERT_I64( |
220 WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); | 228 WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); |
221 FOR_INT64_INPUTS(i) { | 229 FOR_INT64_INPUTS(i) { |
222 FOR_INT64_INPUTS(j) { | 230 FOR_INT64_INPUTS(j) { |
223 int32_t expected = static_cast<int32_t>((*i) >> (*j & 0x3f)); | 231 int32_t expected = static_cast<int32_t>((*i) >> (*j & 0x3f)); |
224 CHECK_EQ(expected, r.Call(*i, *j)); | 232 CHECK_EQ(expected, r.Call(*i, *j)); |
225 } | 233 } |
226 } | 234 } |
227 } | 235 } |
228 | 236 |
229 WASM_EXEC_TEST_WITH_TRAP(I64DivS) { | 237 WASM_EXEC_TEST_WITH_TRAP(I64DivS) { |
230 REQUIRE(I64DivS); | 238 REQUIRE(I64DivS); |
231 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 239 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 240 MachineType::Int64()); |
232 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 241 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
233 FOR_INT64_INPUTS(i) { | 242 FOR_INT64_INPUTS(i) { |
234 FOR_INT64_INPUTS(j) { | 243 FOR_INT64_INPUTS(j) { |
235 if (*j == 0) { | 244 if (*j == 0) { |
236 CHECK_TRAP64(r.Call(*i, *j)); | 245 CHECK_TRAP64(r.Call(*i, *j)); |
237 } else if (*j == -1 && *i == std::numeric_limits<int64_t>::min()) { | 246 } else if (*j == -1 && *i == std::numeric_limits<int64_t>::min()) { |
238 CHECK_TRAP64(r.Call(*i, *j)); | 247 CHECK_TRAP64(r.Call(*i, *j)); |
239 } else { | 248 } else { |
240 CHECK_EQ(*i / *j, r.Call(*i, *j)); | 249 CHECK_EQ(*i / *j, r.Call(*i, *j)); |
241 } | 250 } |
242 } | 251 } |
243 } | 252 } |
244 } | 253 } |
245 | 254 |
246 WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) { | 255 WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) { |
247 REQUIRE(I64DivS); | 256 REQUIRE(I64DivS); |
248 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 257 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 258 MachineType::Int64()); |
249 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 259 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
250 CHECK_EQ(0, r.Call(asi64(0), asi64(100))); | 260 CHECK_EQ(0, r.Call(asi64(0), asi64(100))); |
251 CHECK_TRAP64(r.Call(asi64(100), asi64(0))); | 261 CHECK_TRAP64(r.Call(asi64(100), asi64(0))); |
252 CHECK_TRAP64(r.Call(asi64(-1001), asi64(0))); | 262 CHECK_TRAP64(r.Call(asi64(-1001), asi64(0))); |
253 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(-1))); | 263 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(-1))); |
254 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0))); | 264 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0))); |
255 } | 265 } |
256 | 266 |
257 WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) { | 267 WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) { |
258 REQUIRE(I64DivS); | 268 REQUIRE(I64DivS); |
259 for (int8_t denom = -2; denom < 8; denom++) { | 269 for (int8_t denom = -2; denom < 8; denom++) { |
260 WasmRunner<int64_t, int64_t> r(execution_mode); | 270 WasmRunner<int64_t> r(execution_mode, MachineType::Int64()); |
261 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(denom))); | 271 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(denom))); |
262 for (int64_t val = -7; val < 8; val++) { | 272 for (int64_t val = -7; val < 8; val++) { |
263 if (denom == 0) { | 273 if (denom == 0) { |
264 CHECK_TRAP64(r.Call(val)); | 274 CHECK_TRAP64(r.Call(val)); |
265 } else { | 275 } else { |
266 CHECK_EQ(val / denom, r.Call(val)); | 276 CHECK_EQ(val / denom, r.Call(val)); |
267 } | 277 } |
268 } | 278 } |
269 } | 279 } |
270 } | 280 } |
271 | 281 |
272 WASM_EXEC_TEST_WITH_TRAP(I64DivU) { | 282 WASM_EXEC_TEST_WITH_TRAP(I64DivU) { |
273 REQUIRE(I64DivU); | 283 REQUIRE(I64DivU); |
274 WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); | 284 WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(), |
| 285 MachineType::Uint64()); |
275 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 286 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
276 FOR_UINT64_INPUTS(i) { | 287 FOR_UINT64_INPUTS(i) { |
277 FOR_UINT64_INPUTS(j) { | 288 FOR_UINT64_INPUTS(j) { |
278 if (*j == 0) { | 289 if (*j == 0) { |
279 CHECK_TRAP64(r.Call(*i, *j)); | 290 CHECK_TRAP64(r.Call(*i, *j)); |
280 } else { | 291 } else { |
281 CHECK_EQ(*i / *j, r.Call(*i, *j)); | 292 CHECK_EQ(*i / *j, r.Call(*i, *j)); |
282 } | 293 } |
283 } | 294 } |
284 } | 295 } |
285 } | 296 } |
286 | 297 |
287 WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) { | 298 WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) { |
288 REQUIRE(I64DivU); | 299 REQUIRE(I64DivU); |
289 WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); | 300 WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(), |
| 301 MachineType::Uint64()); |
290 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 302 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
291 CHECK_EQ(0, r.Call(asu64(0), asu64(100))); | 303 CHECK_EQ(0u, r.Call(asu64(0), asu64(100))); |
292 CHECK_TRAP64(r.Call(asu64(100), asu64(0))); | 304 CHECK_TRAP64(r.Call(asu64(100), asu64(0))); |
293 CHECK_TRAP64(r.Call(asu64(1001), asu64(0))); | 305 CHECK_TRAP64(r.Call(asu64(1001), asu64(0))); |
294 CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0))); | 306 CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0))); |
295 } | 307 } |
296 | 308 |
297 WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) { | 309 WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) { |
298 REQUIRE(I64DivU); | 310 REQUIRE(I64DivU); |
299 for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) { | 311 for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) { |
300 WasmRunner<uint64_t, uint64_t> r(execution_mode); | 312 WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64()); |
301 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom))); | 313 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom))); |
302 | 314 |
303 for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) { | 315 for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) { |
304 if (denom == 0) { | 316 if (denom == 0) { |
305 CHECK_TRAP64(r.Call(val)); | 317 CHECK_TRAP64(r.Call(val)); |
306 } else { | 318 } else { |
307 CHECK_EQ(val / denom, r.Call(val)); | 319 CHECK_EQ(val / denom, r.Call(val)); |
308 } | 320 } |
309 } | 321 } |
310 } | 322 } |
311 } | 323 } |
312 | 324 |
313 WASM_EXEC_TEST_WITH_TRAP(I64RemS) { | 325 WASM_EXEC_TEST_WITH_TRAP(I64RemS) { |
314 REQUIRE(I64RemS); | 326 REQUIRE(I64RemS); |
315 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 327 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 328 MachineType::Int64()); |
316 BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 329 BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
317 FOR_INT64_INPUTS(i) { | 330 FOR_INT64_INPUTS(i) { |
318 FOR_INT64_INPUTS(j) { | 331 FOR_INT64_INPUTS(j) { |
319 if (*j == 0) { | 332 if (*j == 0) { |
320 CHECK_TRAP64(r.Call(*i, *j)); | 333 CHECK_TRAP64(r.Call(*i, *j)); |
321 } else { | 334 } else { |
322 CHECK_EQ(*i % *j, r.Call(*i, *j)); | 335 CHECK_EQ(*i % *j, r.Call(*i, *j)); |
323 } | 336 } |
324 } | 337 } |
325 } | 338 } |
326 } | 339 } |
327 | 340 |
328 WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) { | 341 WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) { |
329 REQUIRE(I64RemS); | 342 REQUIRE(I64RemS); |
330 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 343 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 344 MachineType::Int64()); |
331 BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 345 BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
332 CHECK_EQ(33, r.Call(asi64(133), asi64(100))); | 346 CHECK_EQ(33, r.Call(asi64(133), asi64(100))); |
333 CHECK_EQ(0, r.Call(std::numeric_limits<int64_t>::min(), asi64(-1))); | 347 CHECK_EQ(0, r.Call(std::numeric_limits<int64_t>::min(), asi64(-1))); |
334 CHECK_TRAP64(r.Call(asi64(100), asi64(0))); | 348 CHECK_TRAP64(r.Call(asi64(100), asi64(0))); |
335 CHECK_TRAP64(r.Call(asi64(-1001), asi64(0))); | 349 CHECK_TRAP64(r.Call(asi64(-1001), asi64(0))); |
336 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0))); | 350 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0))); |
337 } | 351 } |
338 | 352 |
339 WASM_EXEC_TEST_WITH_TRAP(I64RemU) { | 353 WASM_EXEC_TEST_WITH_TRAP(I64RemU) { |
340 REQUIRE(I64RemU); | 354 REQUIRE(I64RemU); |
341 WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); | 355 WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(), |
| 356 MachineType::Uint64()); |
342 BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 357 BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
343 FOR_UINT64_INPUTS(i) { | 358 FOR_UINT64_INPUTS(i) { |
344 FOR_UINT64_INPUTS(j) { | 359 FOR_UINT64_INPUTS(j) { |
345 if (*j == 0) { | 360 if (*j == 0) { |
346 CHECK_TRAP64(r.Call(*i, *j)); | 361 CHECK_TRAP64(r.Call(*i, *j)); |
347 } else { | 362 } else { |
348 CHECK_EQ(*i % *j, r.Call(*i, *j)); | 363 CHECK_EQ(*i % *j, r.Call(*i, *j)); |
349 } | 364 } |
350 } | 365 } |
351 } | 366 } |
352 } | 367 } |
353 | 368 |
354 WASM_EXEC_TEST_WITH_TRAP(I64RemU_Trap) { | 369 WASM_EXEC_TEST_WITH_TRAP(I64RemU_Trap) { |
355 REQUIRE(I64RemU); | 370 REQUIRE(I64RemU); |
356 WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); | 371 WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(), |
| 372 MachineType::Uint64()); |
357 BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 373 BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
358 CHECK_EQ(17, r.Call(asu64(217), asu64(100))); | 374 CHECK_EQ(17u, r.Call(asu64(217), asu64(100))); |
359 CHECK_TRAP64(r.Call(asu64(100), asu64(0))); | 375 CHECK_TRAP64(r.Call(asu64(100), asu64(0))); |
360 CHECK_TRAP64(r.Call(asu64(1001), asu64(0))); | 376 CHECK_TRAP64(r.Call(asu64(1001), asu64(0))); |
361 CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0))); | 377 CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0))); |
362 } | 378 } |
363 | 379 |
364 WASM_EXEC_TEST(I64And) { | 380 WASM_EXEC_TEST(I64And) { |
365 REQUIRE(I64And); | 381 REQUIRE(I64And); |
366 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 382 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 383 MachineType::Int64()); |
367 BUILD(r, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 384 BUILD(r, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
368 FOR_INT64_INPUTS(i) { | 385 FOR_INT64_INPUTS(i) { |
369 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) & (*j), r.Call(*i, *j)); } | 386 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) & (*j), r.Call(*i, *j)); } |
370 } | 387 } |
371 } | 388 } |
372 | 389 |
373 WASM_EXEC_TEST(I64Ior) { | 390 WASM_EXEC_TEST(I64Ior) { |
374 REQUIRE(I64Ior); | 391 REQUIRE(I64Ior); |
375 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 392 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 393 MachineType::Int64()); |
376 BUILD(r, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 394 BUILD(r, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
377 FOR_INT64_INPUTS(i) { | 395 FOR_INT64_INPUTS(i) { |
378 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) | (*j), r.Call(*i, *j)); } | 396 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) | (*j), r.Call(*i, *j)); } |
379 } | 397 } |
380 } | 398 } |
381 | 399 |
382 WASM_EXEC_TEST(I64Xor) { | 400 WASM_EXEC_TEST(I64Xor) { |
383 REQUIRE(I64Xor); | 401 REQUIRE(I64Xor); |
384 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 402 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 403 MachineType::Int64()); |
385 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 404 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
386 FOR_INT64_INPUTS(i) { | 405 FOR_INT64_INPUTS(i) { |
387 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) ^ (*j), r.Call(*i, *j)); } | 406 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) ^ (*j), r.Call(*i, *j)); } |
388 } | 407 } |
389 } | 408 } |
390 | 409 |
391 WASM_EXEC_TEST(I64Shl) { | 410 WASM_EXEC_TEST(I64Shl) { |
392 REQUIRE(I64Shl); | 411 REQUIRE(I64Shl); |
393 { | 412 { |
394 WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); | 413 WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(), |
| 414 MachineType::Uint64()); |
395 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 415 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
396 | 416 |
397 FOR_UINT64_INPUTS(i) { | 417 FOR_UINT64_INPUTS(i) { |
398 FOR_UINT64_INPUTS(j) { | 418 FOR_UINT64_INPUTS(j) { |
399 uint64_t expected = (*i) << (*j & 0x3f); | 419 uint64_t expected = (*i) << (*j & 0x3f); |
400 CHECK_EQ(expected, r.Call(*i, *j)); | 420 CHECK_EQ(expected, r.Call(*i, *j)); |
401 } | 421 } |
402 } | 422 } |
403 } | 423 } |
404 { | 424 { |
405 WasmRunner<uint64_t, int64_t> r(execution_mode); | 425 WasmRunner<uint64_t> r(execution_mode, MachineType::Int64()); |
406 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(0))); | 426 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
407 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 0, r.Call(*i)); } | 427 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 0, r.Call(*i)); } |
408 } | 428 } |
409 { | 429 { |
410 WasmRunner<uint64_t, int64_t> r(execution_mode); | 430 WasmRunner<uint64_t> r(execution_mode, MachineType::Int64()); |
411 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(32))); | 431 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(32))); |
412 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 32, r.Call(*i)); } | 432 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 32, r.Call(*i)); } |
413 } | 433 } |
414 { | 434 { |
415 WasmRunner<uint64_t, int64_t> r(execution_mode); | 435 WasmRunner<uint64_t> r(execution_mode, MachineType::Int64()); |
416 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(20))); | 436 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(20))); |
417 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 20, r.Call(*i)); } | 437 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 20, r.Call(*i)); } |
418 } | 438 } |
419 { | 439 { |
420 WasmRunner<uint64_t, int64_t> r(execution_mode); | 440 WasmRunner<uint64_t> r(execution_mode, MachineType::Int64()); |
421 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(40))); | 441 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(40))); |
422 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 40, r.Call(*i)); } | 442 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 40, r.Call(*i)); } |
423 } | 443 } |
424 } | 444 } |
425 | 445 |
426 WASM_EXEC_TEST(I64ShrU) { | 446 WASM_EXEC_TEST(I64ShrU) { |
427 REQUIRE(I64ShrU); | 447 REQUIRE(I64ShrU); |
428 { | 448 { |
429 WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); | 449 WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(), |
| 450 MachineType::Uint64()); |
430 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 451 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
431 | 452 |
432 FOR_UINT64_INPUTS(i) { | 453 FOR_UINT64_INPUTS(i) { |
433 FOR_UINT64_INPUTS(j) { | 454 FOR_UINT64_INPUTS(j) { |
434 uint64_t expected = (*i) >> (*j & 0x3f); | 455 uint64_t expected = (*i) >> (*j & 0x3f); |
435 CHECK_EQ(expected, r.Call(*i, *j)); | 456 CHECK_EQ(expected, r.Call(*i, *j)); |
436 } | 457 } |
437 } | 458 } |
438 } | 459 } |
439 { | 460 { |
440 WasmRunner<uint64_t, int64_t> r(execution_mode); | 461 WasmRunner<uint64_t> r(execution_mode, MachineType::Int64()); |
441 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(0))); | 462 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
442 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); } | 463 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); } |
443 } | 464 } |
444 { | 465 { |
445 WasmRunner<uint64_t, int64_t> r(execution_mode); | 466 WasmRunner<uint64_t> r(execution_mode, MachineType::Int64()); |
446 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(32))); | 467 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(32))); |
447 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 32, r.Call(*i)); } | 468 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 32, r.Call(*i)); } |
448 } | 469 } |
449 { | 470 { |
450 WasmRunner<uint64_t, int64_t> r(execution_mode); | 471 WasmRunner<uint64_t> r(execution_mode, MachineType::Int64()); |
451 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); | 472 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); |
452 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 20, r.Call(*i)); } | 473 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 20, r.Call(*i)); } |
453 } | 474 } |
454 { | 475 { |
455 WasmRunner<uint64_t, int64_t> r(execution_mode); | 476 WasmRunner<uint64_t> r(execution_mode, MachineType::Int64()); |
456 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(40))); | 477 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(40))); |
457 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); } | 478 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); } |
458 } | 479 } |
459 } | 480 } |
460 | 481 |
461 WASM_EXEC_TEST(I64ShrS) { | 482 WASM_EXEC_TEST(I64ShrS) { |
462 REQUIRE(I64ShrS); | 483 REQUIRE(I64ShrS); |
463 { | 484 { |
464 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 485 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 486 MachineType::Int64()); |
465 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 487 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
466 | 488 |
467 FOR_INT64_INPUTS(i) { | 489 FOR_INT64_INPUTS(i) { |
468 FOR_INT64_INPUTS(j) { | 490 FOR_INT64_INPUTS(j) { |
469 int64_t expected = (*i) >> (*j & 0x3f); | 491 int64_t expected = (*i) >> (*j & 0x3f); |
470 CHECK_EQ(expected, r.Call(*i, *j)); | 492 CHECK_EQ(expected, r.Call(*i, *j)); |
471 } | 493 } |
472 } | 494 } |
473 } | 495 } |
474 { | 496 { |
475 WasmRunner<int64_t, int64_t> r(execution_mode); | 497 WasmRunner<int64_t> r(execution_mode, MachineType::Int64()); |
476 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(0))); | 498 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
477 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); } | 499 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); } |
478 } | 500 } |
479 { | 501 { |
480 WasmRunner<int64_t, int64_t> r(execution_mode); | 502 WasmRunner<int64_t> r(execution_mode, MachineType::Int64()); |
481 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(32))); | 503 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(32))); |
482 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 32, r.Call(*i)); } | 504 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 32, r.Call(*i)); } |
483 } | 505 } |
484 { | 506 { |
485 WasmRunner<int64_t, int64_t> r(execution_mode); | 507 WasmRunner<int64_t> r(execution_mode, MachineType::Int64()); |
486 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); | 508 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); |
487 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 20, r.Call(*i)); } | 509 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 20, r.Call(*i)); } |
488 } | 510 } |
489 { | 511 { |
490 WasmRunner<int64_t, int64_t> r(execution_mode); | 512 WasmRunner<int64_t> r(execution_mode, MachineType::Int64()); |
491 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(40))); | 513 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(40))); |
492 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); } | 514 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); } |
493 } | 515 } |
494 } | 516 } |
495 | 517 |
496 WASM_EXEC_TEST(I64Eq) { | 518 WASM_EXEC_TEST(I64Eq) { |
497 REQUIRE(I64Eq); | 519 REQUIRE(I64Eq); |
498 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 520 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 521 MachineType::Int64()); |
499 BUILD(r, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 522 BUILD(r, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
500 FOR_INT64_INPUTS(i) { | 523 FOR_INT64_INPUTS(i) { |
501 FOR_INT64_INPUTS(j) { CHECK_EQ(*i == *j ? 1 : 0, r.Call(*i, *j)); } | 524 FOR_INT64_INPUTS(j) { CHECK_EQ(*i == *j ? 1 : 0, r.Call(*i, *j)); } |
502 } | 525 } |
503 } | 526 } |
504 | 527 |
505 WASM_EXEC_TEST(I64Ne) { | 528 WASM_EXEC_TEST(I64Ne) { |
506 REQUIRE(I64Ne); | 529 REQUIRE(I64Ne); |
507 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 530 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 531 MachineType::Int64()); |
508 BUILD(r, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 532 BUILD(r, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
509 FOR_INT64_INPUTS(i) { | 533 FOR_INT64_INPUTS(i) { |
510 FOR_INT64_INPUTS(j) { CHECK_EQ(*i != *j ? 1 : 0, r.Call(*i, *j)); } | 534 FOR_INT64_INPUTS(j) { CHECK_EQ(*i != *j ? 1 : 0, r.Call(*i, *j)); } |
511 } | 535 } |
512 } | 536 } |
513 | 537 |
514 WASM_EXEC_TEST(I64LtS) { | 538 WASM_EXEC_TEST(I64LtS) { |
515 REQUIRE(I64LtS); | 539 REQUIRE(I64LtS); |
516 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 540 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 541 MachineType::Int64()); |
517 BUILD(r, WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 542 BUILD(r, WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
518 FOR_INT64_INPUTS(i) { | 543 FOR_INT64_INPUTS(i) { |
519 FOR_INT64_INPUTS(j) { CHECK_EQ(*i < *j ? 1 : 0, r.Call(*i, *j)); } | 544 FOR_INT64_INPUTS(j) { CHECK_EQ(*i < *j ? 1 : 0, r.Call(*i, *j)); } |
520 } | 545 } |
521 } | 546 } |
522 | 547 |
523 WASM_EXEC_TEST(I64LeS) { | 548 WASM_EXEC_TEST(I64LeS) { |
524 REQUIRE(I64LeS); | 549 REQUIRE(I64LeS); |
525 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 550 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 551 MachineType::Int64()); |
526 BUILD(r, WASM_I64_LES(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 552 BUILD(r, WASM_I64_LES(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
527 FOR_INT64_INPUTS(i) { | 553 FOR_INT64_INPUTS(i) { |
528 FOR_INT64_INPUTS(j) { CHECK_EQ(*i <= *j ? 1 : 0, r.Call(*i, *j)); } | 554 FOR_INT64_INPUTS(j) { CHECK_EQ(*i <= *j ? 1 : 0, r.Call(*i, *j)); } |
529 } | 555 } |
530 } | 556 } |
531 | 557 |
532 WASM_EXEC_TEST(I64LtU) { | 558 WASM_EXEC_TEST(I64LtU) { |
533 REQUIRE(I64LtU); | 559 REQUIRE(I64LtU); |
534 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 560 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 561 MachineType::Int64()); |
535 BUILD(r, WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 562 BUILD(r, WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
536 FOR_UINT64_INPUTS(i) { | 563 FOR_UINT64_INPUTS(i) { |
537 FOR_UINT64_INPUTS(j) { CHECK_EQ(*i < *j ? 1 : 0, r.Call(*i, *j)); } | 564 FOR_UINT64_INPUTS(j) { CHECK_EQ(*i < *j ? 1 : 0, r.Call(*i, *j)); } |
538 } | 565 } |
539 } | 566 } |
540 | 567 |
541 WASM_EXEC_TEST(I64LeU) { | 568 WASM_EXEC_TEST(I64LeU) { |
542 REQUIRE(I64LeU); | 569 REQUIRE(I64LeU); |
543 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 570 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 571 MachineType::Int64()); |
544 BUILD(r, WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 572 BUILD(r, WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
545 FOR_UINT64_INPUTS(i) { | 573 FOR_UINT64_INPUTS(i) { |
546 FOR_UINT64_INPUTS(j) { CHECK_EQ(*i <= *j ? 1 : 0, r.Call(*i, *j)); } | 574 FOR_UINT64_INPUTS(j) { CHECK_EQ(*i <= *j ? 1 : 0, r.Call(*i, *j)); } |
547 } | 575 } |
548 } | 576 } |
549 | 577 |
550 WASM_EXEC_TEST(I64GtS) { | 578 WASM_EXEC_TEST(I64GtS) { |
551 REQUIRE(I64GtS); | 579 REQUIRE(I64GtS); |
552 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 580 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 581 MachineType::Int64()); |
553 BUILD(r, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 582 BUILD(r, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
554 FOR_INT64_INPUTS(i) { | 583 FOR_INT64_INPUTS(i) { |
555 FOR_INT64_INPUTS(j) { CHECK_EQ(*i > *j ? 1 : 0, r.Call(*i, *j)); } | 584 FOR_INT64_INPUTS(j) { CHECK_EQ(*i > *j ? 1 : 0, r.Call(*i, *j)); } |
556 } | 585 } |
557 } | 586 } |
558 | 587 |
559 WASM_EXEC_TEST(I64GeS) { | 588 WASM_EXEC_TEST(I64GeS) { |
560 REQUIRE(I64GeS); | 589 REQUIRE(I64GeS); |
561 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 590 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 591 MachineType::Int64()); |
562 BUILD(r, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 592 BUILD(r, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
563 FOR_INT64_INPUTS(i) { | 593 FOR_INT64_INPUTS(i) { |
564 FOR_INT64_INPUTS(j) { CHECK_EQ(*i >= *j ? 1 : 0, r.Call(*i, *j)); } | 594 FOR_INT64_INPUTS(j) { CHECK_EQ(*i >= *j ? 1 : 0, r.Call(*i, *j)); } |
565 } | 595 } |
566 } | 596 } |
567 | 597 |
568 WASM_EXEC_TEST(I64GtU) { | 598 WASM_EXEC_TEST(I64GtU) { |
569 REQUIRE(I64GtU); | 599 REQUIRE(I64GtU); |
570 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 600 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 601 MachineType::Int64()); |
571 BUILD(r, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 602 BUILD(r, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
572 FOR_UINT64_INPUTS(i) { | 603 FOR_UINT64_INPUTS(i) { |
573 FOR_UINT64_INPUTS(j) { CHECK_EQ(*i > *j ? 1 : 0, r.Call(*i, *j)); } | 604 FOR_UINT64_INPUTS(j) { CHECK_EQ(*i > *j ? 1 : 0, r.Call(*i, *j)); } |
574 } | 605 } |
575 } | 606 } |
576 | 607 |
577 WASM_EXEC_TEST(I64GeU) { | 608 WASM_EXEC_TEST(I64GeU) { |
578 REQUIRE(I64GeU); | 609 REQUIRE(I64GeU); |
579 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 610 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 611 MachineType::Int64()); |
580 BUILD(r, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 612 BUILD(r, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
581 FOR_UINT64_INPUTS(i) { | 613 FOR_UINT64_INPUTS(i) { |
582 FOR_UINT64_INPUTS(j) { CHECK_EQ(*i >= *j ? 1 : 0, r.Call(*i, *j)); } | 614 FOR_UINT64_INPUTS(j) { CHECK_EQ(*i >= *j ? 1 : 0, r.Call(*i, *j)); } |
583 } | 615 } |
584 } | 616 } |
585 | 617 |
586 WASM_EXEC_TEST(I32ConvertI64) { | 618 WASM_EXEC_TEST(I32ConvertI64) { |
587 REQUIRE(I32ConvertI64); | 619 REQUIRE(I32ConvertI64); |
588 FOR_INT64_INPUTS(i) { | 620 FOR_INT64_INPUTS(i) { |
589 WasmRunner<int32_t> r(execution_mode); | 621 WasmRunner<int32_t> r(execution_mode); |
590 BUILD(r, WASM_I32_CONVERT_I64(WASM_I64V(*i))); | 622 BUILD(r, WASM_I32_CONVERT_I64(WASM_I64V(*i))); |
591 CHECK_EQ(static_cast<int32_t>(*i), r.Call()); | 623 CHECK_EQ(static_cast<int32_t>(*i), r.Call()); |
592 } | 624 } |
593 } | 625 } |
594 | 626 |
595 WASM_EXEC_TEST(I64SConvertI32) { | 627 WASM_EXEC_TEST(I64SConvertI32) { |
596 REQUIRE(I64SConvertI32); | 628 REQUIRE(I64SConvertI32); |
597 WasmRunner<int64_t, int32_t> r(execution_mode); | 629 WasmRunner<int64_t> r(execution_mode, MachineType::Int32()); |
598 BUILD(r, WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0))); | 630 BUILD(r, WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0))); |
599 FOR_INT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); } | 631 FOR_INT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); } |
600 } | 632 } |
601 | 633 |
602 WASM_EXEC_TEST(I64UConvertI32) { | 634 WASM_EXEC_TEST(I64UConvertI32) { |
603 REQUIRE(I64UConvertI32); | 635 REQUIRE(I64UConvertI32); |
604 WasmRunner<int64_t, uint32_t> r(execution_mode); | 636 WasmRunner<int64_t> r(execution_mode, MachineType::Uint32()); |
605 BUILD(r, WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(0))); | 637 BUILD(r, WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(0))); |
606 FOR_UINT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); } | 638 FOR_UINT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); } |
607 } | 639 } |
608 | 640 |
609 WASM_EXEC_TEST(I64Popcnt) { | 641 WASM_EXEC_TEST(I64Popcnt) { |
610 struct { | 642 struct { |
611 int64_t expected; | 643 int64_t expected; |
612 uint64_t input; | 644 uint64_t input; |
613 } values[] = {{64, 0xffffffffffffffff}, | 645 } values[] = {{64, 0xffffffffffffffff}, |
614 {0, 0x0000000000000000}, | 646 {0, 0x0000000000000000}, |
615 {2, 0x0000080000008000}, | 647 {2, 0x0000080000008000}, |
616 {26, 0x1123456782345678}, | 648 {26, 0x1123456782345678}, |
617 {38, 0xffedcba09edcba09}}; | 649 {38, 0xffedcba09edcba09}}; |
618 | 650 |
619 WasmRunner<int64_t, uint64_t> r(execution_mode); | 651 WasmRunner<int64_t> r(execution_mode, MachineType::Uint64()); |
620 BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0))); | 652 BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0))); |
621 for (size_t i = 0; i < arraysize(values); i++) { | 653 for (size_t i = 0; i < arraysize(values); i++) { |
622 CHECK_EQ(values[i].expected, r.Call(values[i].input)); | 654 CHECK_EQ(values[i].expected, r.Call(values[i].input)); |
623 } | 655 } |
624 } | 656 } |
625 | 657 |
626 WASM_EXEC_TEST(F32SConvertI64) { | 658 WASM_EXEC_TEST(F32SConvertI64) { |
627 REQUIRE(F32SConvertI64); | 659 REQUIRE(F32SConvertI64); |
628 WasmRunner<float, int64_t> r(execution_mode); | 660 WasmRunner<float> r(execution_mode, MachineType::Int64()); |
629 BUILD(r, WASM_F32_SCONVERT_I64(WASM_GET_LOCAL(0))); | 661 BUILD(r, WASM_F32_SCONVERT_I64(WASM_GET_LOCAL(0))); |
630 FOR_INT64_INPUTS(i) { CHECK_FLOAT_EQ(static_cast<float>(*i), r.Call(*i)); } | 662 FOR_INT64_INPUTS(i) { CHECK_FLOAT_EQ(static_cast<float>(*i), r.Call(*i)); } |
631 } | 663 } |
632 | 664 |
633 WASM_EXEC_TEST(F32UConvertI64) { | 665 WASM_EXEC_TEST(F32UConvertI64) { |
634 REQUIRE(F32UConvertI64); | 666 REQUIRE(F32UConvertI64); |
635 struct { | 667 struct { |
636 uint64_t input; | 668 uint64_t input; |
637 uint32_t expected; | 669 uint32_t expected; |
638 } values[] = {{0x0, 0x0}, | 670 } values[] = {{0x0, 0x0}, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 {0x3fffffffffff, 0x56800000}, | 736 {0x3fffffffffff, 0x56800000}, |
705 {0x1fffffffffff, 0x56000000}, | 737 {0x1fffffffffff, 0x56000000}, |
706 {0xfffffffffff, 0x55800000}, | 738 {0xfffffffffff, 0x55800000}, |
707 {0x7ffffffffff, 0x55000000}, | 739 {0x7ffffffffff, 0x55000000}, |
708 {0x3ffffffffff, 0x54800000}, | 740 {0x3ffffffffff, 0x54800000}, |
709 {0x1ffffffffff, 0x54000000}, | 741 {0x1ffffffffff, 0x54000000}, |
710 {0x8000008000000000, 0x5f000000}, | 742 {0x8000008000000000, 0x5f000000}, |
711 {0x8000008000000001, 0x5f000001}, | 743 {0x8000008000000001, 0x5f000001}, |
712 {0x8000000000000400, 0x5f000000}, | 744 {0x8000000000000400, 0x5f000000}, |
713 {0x8000000000000401, 0x5f000000}}; | 745 {0x8000000000000401, 0x5f000000}}; |
714 WasmRunner<float, uint64_t> r(execution_mode); | 746 WasmRunner<float> r(execution_mode, MachineType::Uint64()); |
715 BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0))); | 747 BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0))); |
716 for (size_t i = 0; i < arraysize(values); i++) { | 748 for (size_t i = 0; i < arraysize(values); i++) { |
717 CHECK_EQ(bit_cast<float>(values[i].expected), r.Call(values[i].input)); | 749 CHECK_EQ(bit_cast<float>(values[i].expected), r.Call(values[i].input)); |
718 } | 750 } |
719 } | 751 } |
720 | 752 |
721 WASM_EXEC_TEST(F64SConvertI64) { | 753 WASM_EXEC_TEST(F64SConvertI64) { |
722 REQUIRE(F64SConvertI64); | 754 REQUIRE(F64SConvertI64); |
723 WasmRunner<double, int64_t> r(execution_mode); | 755 WasmRunner<double> r(execution_mode, MachineType::Int64()); |
724 BUILD(r, WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0))); | 756 BUILD(r, WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0))); |
725 FOR_INT64_INPUTS(i) { CHECK_DOUBLE_EQ(static_cast<double>(*i), r.Call(*i)); } | 757 FOR_INT64_INPUTS(i) { CHECK_DOUBLE_EQ(static_cast<double>(*i), r.Call(*i)); } |
726 } | 758 } |
727 | 759 |
728 WASM_EXEC_TEST(F64UConvertI64) { | 760 WASM_EXEC_TEST(F64UConvertI64) { |
729 REQUIRE(F64UConvertI64); | 761 REQUIRE(F64UConvertI64); |
730 struct { | 762 struct { |
731 uint64_t input; | 763 uint64_t input; |
732 uint64_t expected; | 764 uint64_t expected; |
733 } values[] = {{0x0, 0x0}, | 765 } values[] = {{0x0, 0x0}, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 {0x3fffffffffff, 0x42cfffffffffff80}, | 830 {0x3fffffffffff, 0x42cfffffffffff80}, |
799 {0x1fffffffffff, 0x42bfffffffffff00}, | 831 {0x1fffffffffff, 0x42bfffffffffff00}, |
800 {0xfffffffffff, 0x42affffffffffe00}, | 832 {0xfffffffffff, 0x42affffffffffe00}, |
801 {0x7ffffffffff, 0x429ffffffffffc00}, | 833 {0x7ffffffffff, 0x429ffffffffffc00}, |
802 {0x3ffffffffff, 0x428ffffffffff800}, | 834 {0x3ffffffffff, 0x428ffffffffff800}, |
803 {0x1ffffffffff, 0x427ffffffffff000}, | 835 {0x1ffffffffff, 0x427ffffffffff000}, |
804 {0x8000008000000000, 0x43e0000010000000}, | 836 {0x8000008000000000, 0x43e0000010000000}, |
805 {0x8000008000000001, 0x43e0000010000000}, | 837 {0x8000008000000001, 0x43e0000010000000}, |
806 {0x8000000000000400, 0x43e0000000000000}, | 838 {0x8000000000000400, 0x43e0000000000000}, |
807 {0x8000000000000401, 0x43e0000000000001}}; | 839 {0x8000000000000401, 0x43e0000000000001}}; |
808 WasmRunner<double, uint64_t> r(execution_mode); | 840 WasmRunner<double> r(execution_mode, MachineType::Uint64()); |
809 BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0))); | 841 BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0))); |
810 for (size_t i = 0; i < arraysize(values); i++) { | 842 for (size_t i = 0; i < arraysize(values); i++) { |
811 CHECK_EQ(bit_cast<double>(values[i].expected), r.Call(values[i].input)); | 843 CHECK_EQ(bit_cast<double>(values[i].expected), r.Call(values[i].input)); |
812 } | 844 } |
813 } | 845 } |
814 | 846 |
815 WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) { | 847 WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) { |
816 WasmRunner<int64_t, float> r(execution_mode); | 848 WasmRunner<int64_t> r(execution_mode, MachineType::Float32()); |
817 BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0))); | 849 BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0))); |
818 | 850 |
819 FOR_FLOAT32_INPUTS(i) { | 851 FOR_FLOAT32_INPUTS(i) { |
820 if (*i < static_cast<float>(std::numeric_limits<int64_t>::max()) && | 852 if (*i < static_cast<float>(std::numeric_limits<int64_t>::max()) && |
821 *i >= static_cast<float>(std::numeric_limits<int64_t>::min())) { | 853 *i >= static_cast<float>(std::numeric_limits<int64_t>::min())) { |
822 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); | 854 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); |
823 } else { | 855 } else { |
824 CHECK_TRAP64(r.Call(*i)); | 856 CHECK_TRAP64(r.Call(*i)); |
825 } | 857 } |
826 } | 858 } |
827 } | 859 } |
828 | 860 |
829 WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) { | 861 WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) { |
830 WasmRunner<int64_t, double> r(execution_mode); | 862 WasmRunner<int64_t> r(execution_mode, MachineType::Float64()); |
831 BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0))); | 863 BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0))); |
832 | 864 |
833 FOR_FLOAT64_INPUTS(i) { | 865 FOR_FLOAT64_INPUTS(i) { |
834 if (*i < static_cast<double>(std::numeric_limits<int64_t>::max()) && | 866 if (*i < static_cast<double>(std::numeric_limits<int64_t>::max()) && |
835 *i >= static_cast<double>(std::numeric_limits<int64_t>::min())) { | 867 *i >= static_cast<double>(std::numeric_limits<int64_t>::min())) { |
836 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); | 868 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); |
837 } else { | 869 } else { |
838 CHECK_TRAP64(r.Call(*i)); | 870 CHECK_TRAP64(r.Call(*i)); |
839 } | 871 } |
840 } | 872 } |
841 } | 873 } |
842 | 874 |
843 WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) { | 875 WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) { |
844 WasmRunner<uint64_t, float> r(execution_mode); | 876 WasmRunner<uint64_t> r(execution_mode, MachineType::Float32()); |
845 BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0))); | 877 BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0))); |
846 | 878 |
847 FOR_FLOAT32_INPUTS(i) { | 879 FOR_FLOAT32_INPUTS(i) { |
848 if (*i < static_cast<float>(std::numeric_limits<uint64_t>::max()) && | 880 if (*i < static_cast<float>(std::numeric_limits<uint64_t>::max()) && |
849 *i > -1) { | 881 *i > -1) { |
850 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); | 882 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); |
851 } else { | 883 } else { |
852 CHECK_TRAP64(r.Call(*i)); | 884 CHECK_TRAP64(r.Call(*i)); |
853 } | 885 } |
854 } | 886 } |
855 } | 887 } |
856 | 888 |
857 WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64a) { | 889 WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64a) { |
858 WasmRunner<uint64_t, double> r(execution_mode); | 890 WasmRunner<uint64_t> r(execution_mode, MachineType::Float64()); |
859 BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0))); | 891 BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0))); |
860 | 892 |
861 FOR_FLOAT64_INPUTS(i) { | 893 FOR_FLOAT64_INPUTS(i) { |
862 if (*i < static_cast<float>(std::numeric_limits<uint64_t>::max()) && | 894 if (*i < static_cast<float>(std::numeric_limits<uint64_t>::max()) && |
863 *i > -1) { | 895 *i > -1) { |
864 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); | 896 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); |
865 } else { | 897 } else { |
866 CHECK_TRAP64(r.Call(*i)); | 898 CHECK_TRAP64(r.Call(*i)); |
867 } | 899 } |
868 } | 900 } |
869 } | 901 } |
870 | 902 |
871 WASM_EXEC_TEST(CallI64Parameter) { | 903 WASM_EXEC_TEST(CallI64Parameter) { |
| 904 // Build the target function. |
872 LocalType param_types[20]; | 905 LocalType param_types[20]; |
873 for (int i = 0; i < 20; i++) param_types[i] = kAstI64; | 906 for (int i = 0; i < 20; i++) param_types[i] = kAstI64; |
874 param_types[3] = kAstI32; | 907 param_types[3] = kAstI32; |
875 param_types[4] = kAstI32; | 908 param_types[4] = kAstI32; |
876 FunctionSig sig(1, 19, param_types); | 909 FunctionSig sig(1, 19, param_types); |
877 for (int i = 0; i < 19; i++) { | 910 for (int i = 0; i < 19; i++) { |
878 if (i == 2 || i == 3) continue; | 911 TestingModule module(execution_mode); |
879 WasmRunner<int32_t> r(execution_mode); | 912 WasmFunctionCompiler t(&sig, &module); |
880 // Build the target function. | 913 if (i == 2 || i == 3) { |
881 WasmFunctionCompiler& t = r.NewFunction(&sig); | 914 continue; |
882 BUILD(t, WASM_GET_LOCAL(i)); | 915 } else { |
| 916 BUILD(t, WASM_GET_LOCAL(i)); |
| 917 } |
| 918 uint32_t index = t.CompileAndAdd(); |
883 | 919 |
884 // Build the calling function. | 920 // Build the calling function. |
| 921 WasmRunner<int32_t> r(&module); |
885 BUILD( | 922 BUILD( |
886 r, | 923 r, |
887 WASM_I32_CONVERT_I64(WASM_CALL_FUNCTION( | 924 WASM_I32_CONVERT_I64(WASM_CALL_FUNCTION( |
888 t.function_index(), WASM_I64V_9(0xbcd12340000000b), | 925 index, WASM_I64V_9(0xbcd12340000000b), |
889 WASM_I64V_9(0xbcd12340000000c), WASM_I32V_1(0xd), | 926 WASM_I64V_9(0xbcd12340000000c), WASM_I32V_1(0xd), |
890 WASM_I32_CONVERT_I64(WASM_I64V_9(0xbcd12340000000e)), | 927 WASM_I32_CONVERT_I64(WASM_I64V_9(0xbcd12340000000e)), |
891 WASM_I64V_9(0xbcd12340000000f), WASM_I64V_10(0xbcd1234000000010), | 928 WASM_I64V_9(0xbcd12340000000f), WASM_I64V_10(0xbcd1234000000010), |
892 WASM_I64V_10(0xbcd1234000000011), WASM_I64V_10(0xbcd1234000000012), | 929 WASM_I64V_10(0xbcd1234000000011), WASM_I64V_10(0xbcd1234000000012), |
893 WASM_I64V_10(0xbcd1234000000013), WASM_I64V_10(0xbcd1234000000014), | 930 WASM_I64V_10(0xbcd1234000000013), WASM_I64V_10(0xbcd1234000000014), |
894 WASM_I64V_10(0xbcd1234000000015), WASM_I64V_10(0xbcd1234000000016), | 931 WASM_I64V_10(0xbcd1234000000015), WASM_I64V_10(0xbcd1234000000016), |
895 WASM_I64V_10(0xbcd1234000000017), WASM_I64V_10(0xbcd1234000000018), | 932 WASM_I64V_10(0xbcd1234000000017), WASM_I64V_10(0xbcd1234000000018), |
896 WASM_I64V_10(0xbcd1234000000019), WASM_I64V_10(0xbcd123400000001a), | 933 WASM_I64V_10(0xbcd1234000000019), WASM_I64V_10(0xbcd123400000001a), |
897 WASM_I64V_10(0xbcd123400000001b), WASM_I64V_10(0xbcd123400000001c), | 934 WASM_I64V_10(0xbcd123400000001b), WASM_I64V_10(0xbcd123400000001c), |
898 WASM_I64V_10(0xbcd123400000001d)))); | 935 WASM_I64V_10(0xbcd123400000001d)))); |
899 | 936 |
900 CHECK_EQ(i + 0xb, r.Call()); | 937 CHECK_EQ(i + 0xb, r.Call()); |
901 } | 938 } |
902 } | 939 } |
903 | 940 |
904 void TestI64Binop(WasmExecutionMode execution_mode, WasmOpcode opcode, | 941 void TestI64Binop(WasmExecutionMode execution_mode, WasmOpcode opcode, |
905 int64_t expected, int64_t a, int64_t b) { | 942 int64_t expected, int64_t a, int64_t b) { |
906 { | 943 { |
907 WasmRunner<int64_t> r(execution_mode); | 944 WasmRunner<int64_t> r(execution_mode); |
908 // return K op K | 945 // return K op K |
909 BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b))); | 946 BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b))); |
910 CHECK_EQ(expected, r.Call()); | 947 CHECK_EQ(expected, r.Call()); |
911 } | 948 } |
912 { | 949 { |
913 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 950 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 951 MachineType::Int64()); |
914 // return a op b | 952 // return a op b |
915 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 953 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
916 CHECK_EQ(expected, r.Call(a, b)); | 954 CHECK_EQ(expected, r.Call(a, b)); |
917 } | 955 } |
918 } | 956 } |
919 | 957 |
920 void TestI64Cmp(WasmExecutionMode execution_mode, WasmOpcode opcode, | 958 void TestI64Cmp(WasmExecutionMode execution_mode, WasmOpcode opcode, |
921 int64_t expected, int64_t a, int64_t b) { | 959 int64_t expected, int64_t a, int64_t b) { |
922 { | 960 { |
923 WasmRunner<int32_t> r(execution_mode); | 961 WasmRunner<int32_t> r(execution_mode); |
924 // return K op K | 962 // return K op K |
925 BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b))); | 963 BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b))); |
926 CHECK_EQ(expected, r.Call()); | 964 CHECK_EQ(expected, r.Call()); |
927 } | 965 } |
928 { | 966 { |
929 WasmRunner<int32_t, int64_t, int64_t> r(execution_mode); | 967 WasmRunner<int32_t> r(execution_mode, MachineType::Int64(), |
| 968 MachineType::Int64()); |
930 // return a op b | 969 // return a op b |
931 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 970 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
932 CHECK_EQ(expected, r.Call(a, b)); | 971 CHECK_EQ(expected, r.Call(a, b)); |
933 } | 972 } |
934 } | 973 } |
935 | 974 |
936 #define TEST_I64_BINOP(name, expected, a, b) \ | 975 #define TEST_I64_BINOP(name, expected, a, b) \ |
937 do { \ | 976 do { \ |
938 if (WASM_64 || kSupported_##name) \ | 977 if (WASM_64 || kSupported_##name) \ |
939 TestI64Binop(execution_mode, kExpr##name, expected, a, b); \ | 978 TestI64Binop(execution_mode, kExpr##name, expected, a, b); \ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 {48, 0x0000000000008040}, {49, 0x0000000000004005}, | 1061 {48, 0x0000000000008040}, {49, 0x0000000000004005}, |
1023 {50, 0x0000000000002050}, {51, 0x0000000000001700}, | 1062 {50, 0x0000000000002050}, {51, 0x0000000000001700}, |
1024 {52, 0x0000000000000870}, {53, 0x0000000000000405}, | 1063 {52, 0x0000000000000870}, {53, 0x0000000000000405}, |
1025 {54, 0x0000000000000203}, {55, 0x0000000000000101}, | 1064 {54, 0x0000000000000203}, {55, 0x0000000000000101}, |
1026 {56, 0x0000000000000089}, {57, 0x0000000000000041}, | 1065 {56, 0x0000000000000089}, {57, 0x0000000000000041}, |
1027 {58, 0x0000000000000022}, {59, 0x0000000000000013}, | 1066 {58, 0x0000000000000022}, {59, 0x0000000000000013}, |
1028 {60, 0x0000000000000008}, {61, 0x0000000000000004}, | 1067 {60, 0x0000000000000008}, {61, 0x0000000000000004}, |
1029 {62, 0x0000000000000002}, {63, 0x0000000000000001}, | 1068 {62, 0x0000000000000002}, {63, 0x0000000000000001}, |
1030 {64, 0x0000000000000000}}; | 1069 {64, 0x0000000000000000}}; |
1031 | 1070 |
1032 WasmRunner<int64_t, uint64_t> r(execution_mode); | 1071 WasmRunner<int64_t> r(execution_mode, MachineType::Uint64()); |
1033 BUILD(r, WASM_I64_CLZ(WASM_GET_LOCAL(0))); | 1072 BUILD(r, WASM_I64_CLZ(WASM_GET_LOCAL(0))); |
1034 for (size_t i = 0; i < arraysize(values); i++) { | 1073 for (size_t i = 0; i < arraysize(values); i++) { |
1035 CHECK_EQ(values[i].expected, r.Call(values[i].input)); | 1074 CHECK_EQ(values[i].expected, r.Call(values[i].input)); |
1036 } | 1075 } |
1037 } | 1076 } |
1038 | 1077 |
1039 WASM_EXEC_TEST(I64Ctz) { | 1078 WASM_EXEC_TEST(I64Ctz) { |
1040 REQUIRE(I64Ctz); | 1079 REQUIRE(I64Ctz); |
1041 struct { | 1080 struct { |
1042 int64_t expected; | 1081 int64_t expected; |
(...skipping 25 matching lines...) Expand all Loading... |
1068 {16, 0x00000000b8f10000}, {15, 0x000000003b9f8000}, | 1107 {16, 0x00000000b8f10000}, {15, 0x000000003b9f8000}, |
1069 {14, 0x00000000db4c4000}, {13, 0x00000000e9a32000}, | 1108 {14, 0x00000000db4c4000}, {13, 0x00000000e9a32000}, |
1070 {12, 0x00000000fca61000}, {11, 0x000000006c8a7800}, | 1109 {12, 0x00000000fca61000}, {11, 0x000000006c8a7800}, |
1071 {10, 0x000000008ce5a400}, {9, 0x00000000cb7d0200}, | 1110 {10, 0x000000008ce5a400}, {9, 0x00000000cb7d0200}, |
1072 {8, 0x00000000cb4dc100}, {7, 0x00000000dfbec580}, | 1111 {8, 0x00000000cb4dc100}, {7, 0x00000000dfbec580}, |
1073 {6, 0x0000000027a9db40}, {5, 0x00000000de3bcb20}, | 1112 {6, 0x0000000027a9db40}, {5, 0x00000000de3bcb20}, |
1074 {4, 0x00000000d7e8a610}, {3, 0x000000009afdbc88}, | 1113 {4, 0x00000000d7e8a610}, {3, 0x000000009afdbc88}, |
1075 {2, 0x000000009afdbc84}, {1, 0x000000009afdbc82}, | 1114 {2, 0x000000009afdbc84}, {1, 0x000000009afdbc82}, |
1076 {0, 0x000000009afdbc81}}; | 1115 {0, 0x000000009afdbc81}}; |
1077 | 1116 |
1078 WasmRunner<int64_t, uint64_t> r(execution_mode); | 1117 WasmRunner<int64_t> r(execution_mode, MachineType::Uint64()); |
1079 BUILD(r, WASM_I64_CTZ(WASM_GET_LOCAL(0))); | 1118 BUILD(r, WASM_I64_CTZ(WASM_GET_LOCAL(0))); |
1080 for (size_t i = 0; i < arraysize(values); i++) { | 1119 for (size_t i = 0; i < arraysize(values); i++) { |
1081 CHECK_EQ(values[i].expected, r.Call(values[i].input)); | 1120 CHECK_EQ(values[i].expected, r.Call(values[i].input)); |
1082 } | 1121 } |
1083 } | 1122 } |
1084 | 1123 |
1085 WASM_EXEC_TEST(I64Popcnt2) { | 1124 WASM_EXEC_TEST(I64Popcnt2) { |
1086 REQUIRE(I64Popcnt); | 1125 REQUIRE(I64Popcnt); |
1087 struct { | 1126 struct { |
1088 int64_t expected; | 1127 int64_t expected; |
1089 uint64_t input; | 1128 uint64_t input; |
1090 } values[] = {{64, 0xffffffffffffffff}, | 1129 } values[] = {{64, 0xffffffffffffffff}, |
1091 {0, 0x0000000000000000}, | 1130 {0, 0x0000000000000000}, |
1092 {2, 0x0000080000008000}, | 1131 {2, 0x0000080000008000}, |
1093 {26, 0x1123456782345678}, | 1132 {26, 0x1123456782345678}, |
1094 {38, 0xffedcba09edcba09}}; | 1133 {38, 0xffedcba09edcba09}}; |
1095 | 1134 |
1096 WasmRunner<int64_t, uint64_t> r(execution_mode); | 1135 WasmRunner<int64_t> r(execution_mode, MachineType::Uint64()); |
1097 BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0))); | 1136 BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0))); |
1098 for (size_t i = 0; i < arraysize(values); i++) { | 1137 for (size_t i = 0; i < arraysize(values); i++) { |
1099 CHECK_EQ(values[i].expected, r.Call(values[i].input)); | 1138 CHECK_EQ(values[i].expected, r.Call(values[i].input)); |
1100 } | 1139 } |
1101 } | 1140 } |
1102 | 1141 |
1103 // Test the WasmRunner with an Int64 return value and different numbers of | 1142 // Test the WasmRunner with an Int64 return value and different numbers of |
1104 // Int64 parameters. | 1143 // Int64 parameters. |
1105 WASM_EXEC_TEST(I64WasmRunner) { | 1144 WASM_EXEC_TEST(I64WasmRunner) { |
1106 REQUIRE(I64Param); | 1145 REQUIRE(I64Param); |
1107 REQUIRE(I64Xor); | 1146 REQUIRE(I64Xor); |
1108 {FOR_INT64_INPUTS(i){WasmRunner<int64_t> r(execution_mode); | 1147 {FOR_INT64_INPUTS(i){WasmRunner<int64_t> r(execution_mode); |
1109 BUILD(r, WASM_I64V(*i)); | 1148 BUILD(r, WASM_I64V(*i)); |
1110 CHECK_EQ(*i, r.Call()); | 1149 CHECK_EQ(*i, r.Call()); |
1111 } | 1150 } |
1112 } | 1151 } |
1113 { | 1152 { |
1114 WasmRunner<int64_t, int64_t> r(execution_mode); | 1153 WasmRunner<int64_t> r(execution_mode, MachineType::Int64()); |
1115 BUILD(r, WASM_GET_LOCAL(0)); | 1154 BUILD(r, WASM_GET_LOCAL(0)); |
1116 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1155 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1117 } | 1156 } |
1118 { | 1157 { |
1119 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 1158 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 1159 MachineType::Int64()); |
1120 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 1160 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
1121 FOR_INT64_INPUTS(i) { | 1161 FOR_INT64_INPUTS(i) { |
1122 FOR_INT64_INPUTS(j) { CHECK_EQ(*i ^ *j, r.Call(*i, *j)); } | 1162 FOR_INT64_INPUTS(j) { CHECK_EQ(*i ^ *j, r.Call(*i, *j)); } |
1123 } | 1163 } |
1124 } | 1164 } |
1125 { | 1165 { |
1126 WasmRunner<int64_t, int64_t, int64_t, int64_t> r(execution_mode); | 1166 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 1167 MachineType::Int64(), MachineType::Int64()); |
1127 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), | 1168 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), |
1128 WASM_I64_XOR(WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)))); | 1169 WASM_I64_XOR(WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)))); |
1129 FOR_INT64_INPUTS(i) { | 1170 FOR_INT64_INPUTS(i) { |
1130 FOR_INT64_INPUTS(j) { | 1171 FOR_INT64_INPUTS(j) { |
1131 CHECK_EQ(*i ^ *j ^ *j, r.Call(*i, *j, *j)); | 1172 CHECK_EQ(*i ^ *j ^ *j, r.Call(*i, *j, *j)); |
1132 CHECK_EQ(*j ^ *i ^ *j, r.Call(*j, *i, *j)); | 1173 CHECK_EQ(*j ^ *i ^ *j, r.Call(*j, *i, *j)); |
1133 CHECK_EQ(*j ^ *j ^ *i, r.Call(*j, *j, *i)); | 1174 CHECK_EQ(*j ^ *j ^ *i, r.Call(*j, *j, *i)); |
1134 } | 1175 } |
1135 } | 1176 } |
1136 } | 1177 } |
1137 { | 1178 { |
1138 WasmRunner<int64_t, int64_t, int64_t, int64_t, int64_t> r(execution_mode); | 1179 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 1180 MachineType::Int64(), MachineType::Int64(), |
| 1181 MachineType::Int64()); |
1139 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), | 1182 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), |
1140 WASM_I64_XOR(WASM_GET_LOCAL(1), | 1183 WASM_I64_XOR(WASM_GET_LOCAL(1), |
1141 WASM_I64_XOR(WASM_GET_LOCAL(2), | 1184 WASM_I64_XOR(WASM_GET_LOCAL(2), |
1142 WASM_GET_LOCAL(3))))); | 1185 WASM_GET_LOCAL(3))))); |
1143 FOR_INT64_INPUTS(i) { | 1186 FOR_INT64_INPUTS(i) { |
1144 FOR_INT64_INPUTS(j) { | 1187 FOR_INT64_INPUTS(j) { |
1145 CHECK_EQ(*i ^ *j ^ *j ^ *j, r.Call(*i, *j, *j, *j)); | 1188 CHECK_EQ(*i ^ *j ^ *j ^ *j, r.Call(*i, *j, *j, *j)); |
1146 CHECK_EQ(*j ^ *i ^ *j ^ *j, r.Call(*j, *i, *j, *j)); | 1189 CHECK_EQ(*j ^ *i ^ *j ^ *j, r.Call(*j, *i, *j, *j)); |
1147 CHECK_EQ(*j ^ *j ^ *i ^ *j, r.Call(*j, *j, *i, *j)); | 1190 CHECK_EQ(*j ^ *j ^ *i ^ *j, r.Call(*j, *j, *i, *j)); |
1148 CHECK_EQ(*j ^ *j ^ *j ^ *i, r.Call(*j, *j, *j, *i)); | 1191 CHECK_EQ(*j ^ *j ^ *j ^ *i, r.Call(*j, *j, *j, *i)); |
1149 } | 1192 } |
1150 } | 1193 } |
1151 } | 1194 } |
1152 } | 1195 } |
1153 | 1196 |
1154 WASM_EXEC_TEST(Call_Int64Sub) { | 1197 WASM_EXEC_TEST(Call_Int64Sub) { |
1155 REQUIRE(I64Sub); | 1198 REQUIRE(I64Sub); |
1156 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | |
1157 // Build the target function. | 1199 // Build the target function. |
1158 TestSignatures sigs; | 1200 TestSignatures sigs; |
1159 WasmFunctionCompiler& t = r.NewFunction(sigs.l_ll()); | 1201 TestingModule module(execution_mode); |
| 1202 WasmFunctionCompiler t(sigs.l_ll(), &module); |
1160 BUILD(t, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 1203 BUILD(t, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 1204 uint32_t index = t.CompileAndAdd(); |
1161 | 1205 |
1162 // Build the caller function. | 1206 // Build the caller function. |
1163 BUILD(r, WASM_CALL_FUNCTION(t.function_index(), WASM_GET_LOCAL(0), | 1207 WasmRunner<int64_t> r(&module, MachineType::Int64(), MachineType::Int64()); |
1164 WASM_GET_LOCAL(1))); | 1208 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
1165 | 1209 |
1166 FOR_INT32_INPUTS(i) { | 1210 FOR_INT32_INPUTS(i) { |
1167 FOR_INT32_INPUTS(j) { | 1211 FOR_INT32_INPUTS(j) { |
1168 int64_t a = static_cast<int64_t>(*i) << 32 | | 1212 int64_t a = static_cast<int64_t>(*i) << 32 | |
1169 (static_cast<int64_t>(*j) | 0xFFFFFFFF); | 1213 (static_cast<int64_t>(*j) | 0xFFFFFFFF); |
1170 int64_t b = static_cast<int64_t>(*j) << 32 | | 1214 int64_t b = static_cast<int64_t>(*j) << 32 | |
1171 (static_cast<int64_t>(*i) | 0xFFFFFFFF); | 1215 (static_cast<int64_t>(*i) | 0xFFFFFFFF); |
1172 | 1216 |
1173 int64_t expected = static_cast<int64_t>(static_cast<uint64_t>(a) - | 1217 int64_t expected = static_cast<int64_t>(static_cast<uint64_t>(a) - |
1174 static_cast<uint64_t>(b)); | 1218 static_cast<uint64_t>(b)); |
1175 CHECK_EQ(expected, r.Call(a, b)); | 1219 CHECK_EQ(expected, r.Call(a, b)); |
1176 } | 1220 } |
1177 } | 1221 } |
1178 } | 1222 } |
1179 | 1223 |
1180 WASM_EXEC_TEST(LoadStoreI64_sx) { | 1224 WASM_EXEC_TEST(LoadStoreI64_sx) { |
1181 REQUIRE(I64LoadStore); | 1225 REQUIRE(I64LoadStore); |
1182 REQUIRE(DepthFirst); | 1226 REQUIRE(DepthFirst); |
1183 byte loads[] = {kExprI64LoadMem8S, kExprI64LoadMem16S, kExprI64LoadMem32S, | 1227 byte loads[] = {kExprI64LoadMem8S, kExprI64LoadMem16S, kExprI64LoadMem32S, |
1184 kExprI64LoadMem}; | 1228 kExprI64LoadMem}; |
1185 | 1229 |
1186 for (size_t m = 0; m < arraysize(loads); m++) { | 1230 for (size_t m = 0; m < arraysize(loads); m++) { |
1187 WasmRunner<int64_t> r(execution_mode); | 1231 TestingModule module(execution_mode); |
1188 byte* memory = r.module().AddMemoryElems<byte>(16); | 1232 byte* memory = module.AddMemoryElems<byte>(16); |
| 1233 WasmRunner<int64_t> r(&module); |
1189 | 1234 |
1190 byte code[] = { | 1235 byte code[] = { |
1191 kExprI8Const, 8, // -- | 1236 kExprI8Const, 8, // -- |
1192 kExprI8Const, 0, // -- | 1237 kExprI8Const, 0, // -- |
1193 loads[m], // -- | 1238 loads[m], // -- |
1194 ZERO_ALIGNMENT, // -- | 1239 ZERO_ALIGNMENT, // -- |
1195 ZERO_OFFSET, // -- | 1240 ZERO_OFFSET, // -- |
1196 kExprI64StoreMem, // -- | 1241 kExprI64StoreMem, // -- |
1197 ZERO_ALIGNMENT, // -- | 1242 ZERO_ALIGNMENT, // -- |
1198 ZERO_OFFSET, // -- | 1243 ZERO_OFFSET, // -- |
1199 kExprI8Const, 0, // -- | 1244 kExprI8Const, 0, // -- |
1200 loads[m], // -- | 1245 loads[m], // -- |
1201 ZERO_ALIGNMENT, // -- | 1246 ZERO_ALIGNMENT, // -- |
1202 ZERO_OFFSET, // -- | 1247 ZERO_OFFSET, // -- |
1203 }; | 1248 }; |
1204 | 1249 |
1205 r.Build(code, code + arraysize(code)); | 1250 r.Build(code, code + arraysize(code)); |
1206 | 1251 |
1207 // Try a bunch of different negative values. | 1252 // Try a bunch of different negative values. |
1208 for (int i = -1; i >= -128; i -= 11) { | 1253 for (int i = -1; i >= -128; i -= 11) { |
1209 int size = 1 << m; | 1254 int size = 1 << m; |
1210 r.module().BlankMemory(); | 1255 module.BlankMemory(); |
1211 memory[size - 1] = static_cast<byte>(i); // set the high order byte. | 1256 memory[size - 1] = static_cast<byte>(i); // set the high order byte. |
1212 | 1257 |
1213 int64_t expected = static_cast<int64_t>(i) << ((size - 1) * 8); | 1258 int64_t expected = static_cast<int64_t>(i) << ((size - 1) * 8); |
1214 | 1259 |
1215 CHECK_EQ(expected, r.Call()); | 1260 CHECK_EQ(expected, r.Call()); |
1216 CHECK_EQ(static_cast<byte>(i), memory[8 + size - 1]); | 1261 CHECK_EQ(static_cast<byte>(i), memory[8 + size - 1]); |
1217 for (int j = size; j < 8; j++) { | 1262 for (int j = size; j < 8; j++) { |
1218 CHECK_EQ(255, memory[8 + j]); | 1263 CHECK_EQ(255, memory[8 + j]); |
1219 } | 1264 } |
1220 } | 1265 } |
1221 } | 1266 } |
1222 } | 1267 } |
1223 | 1268 |
1224 WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) { | 1269 WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) { |
1225 REQUIRE(I64SConvertF32); | 1270 REQUIRE(I64SConvertF32); |
1226 WasmRunner<int64_t, float> r(execution_mode); | 1271 WasmRunner<int64_t> r(execution_mode, MachineType::Float32()); |
1227 BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0))); | 1272 BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0))); |
1228 | 1273 |
1229 FOR_FLOAT32_INPUTS(i) { | 1274 FOR_FLOAT32_INPUTS(i) { |
1230 if (*i < static_cast<float>(INT64_MAX) && | 1275 if (*i < static_cast<float>(INT64_MAX) && |
1231 *i >= static_cast<float>(INT64_MIN)) { | 1276 *i >= static_cast<float>(INT64_MIN)) { |
1232 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); | 1277 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); |
1233 } else { | 1278 } else { |
1234 CHECK_TRAP64(r.Call(*i)); | 1279 CHECK_TRAP64(r.Call(*i)); |
1235 } | 1280 } |
1236 } | 1281 } |
1237 } | 1282 } |
1238 | 1283 |
1239 WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) { | 1284 WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) { |
1240 REQUIRE(I64SConvertF64); | 1285 REQUIRE(I64SConvertF64); |
1241 WasmRunner<int64_t, double> r(execution_mode); | 1286 WasmRunner<int64_t> r(execution_mode, MachineType::Float64()); |
1242 BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0))); | 1287 BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0))); |
1243 | 1288 |
1244 FOR_FLOAT64_INPUTS(i) { | 1289 FOR_FLOAT64_INPUTS(i) { |
1245 if (*i < static_cast<double>(INT64_MAX) && | 1290 if (*i < static_cast<double>(INT64_MAX) && |
1246 *i >= static_cast<double>(INT64_MIN)) { | 1291 *i >= static_cast<double>(INT64_MIN)) { |
1247 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); | 1292 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); |
1248 } else { | 1293 } else { |
1249 CHECK_TRAP64(r.Call(*i)); | 1294 CHECK_TRAP64(r.Call(*i)); |
1250 } | 1295 } |
1251 } | 1296 } |
1252 } | 1297 } |
1253 | 1298 |
1254 WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) { | 1299 WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) { |
1255 REQUIRE(I64UConvertF32); | 1300 REQUIRE(I64UConvertF32); |
1256 WasmRunner<uint64_t, float> r(execution_mode); | 1301 WasmRunner<uint64_t> r(execution_mode, MachineType::Float32()); |
1257 BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0))); | 1302 BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0))); |
1258 | 1303 |
1259 FOR_FLOAT32_INPUTS(i) { | 1304 FOR_FLOAT32_INPUTS(i) { |
1260 if (*i < static_cast<float>(UINT64_MAX) && *i > -1) { | 1305 if (*i < static_cast<float>(UINT64_MAX) && *i > -1) { |
1261 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); | 1306 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); |
1262 } else { | 1307 } else { |
1263 CHECK_TRAP64(r.Call(*i)); | 1308 CHECK_TRAP64(r.Call(*i)); |
1264 } | 1309 } |
1265 } | 1310 } |
1266 } | 1311 } |
1267 | 1312 |
1268 WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64b) { | 1313 WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64b) { |
1269 REQUIRE(I64UConvertF64); | 1314 REQUIRE(I64UConvertF64); |
1270 WasmRunner<uint64_t, double> r(execution_mode); | 1315 WasmRunner<uint64_t> r(execution_mode, MachineType::Float64()); |
1271 BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0))); | 1316 BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0))); |
1272 | 1317 |
1273 FOR_FLOAT64_INPUTS(i) { | 1318 FOR_FLOAT64_INPUTS(i) { |
1274 if (*i < static_cast<float>(UINT64_MAX) && *i > -1) { | 1319 if (*i < static_cast<float>(UINT64_MAX) && *i > -1) { |
1275 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); | 1320 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); |
1276 } else { | 1321 } else { |
1277 CHECK_TRAP64(r.Call(*i)); | 1322 CHECK_TRAP64(r.Call(*i)); |
1278 } | 1323 } |
1279 } | 1324 } |
1280 } | 1325 } |
1281 | 1326 |
1282 WASM_EXEC_TEST(I64ReinterpretF64) { | 1327 WASM_EXEC_TEST(I64ReinterpretF64) { |
1283 REQUIRE(I64ReinterpretF64); | 1328 REQUIRE(I64ReinterpretF64); |
1284 WasmRunner<int64_t> r(execution_mode); | 1329 TestingModule module(execution_mode); |
1285 int64_t* memory = r.module().AddMemoryElems<int64_t>(8); | 1330 int64_t* memory = module.AddMemoryElems<int64_t>(8); |
| 1331 WasmRunner<int64_t> r(&module); |
1286 | 1332 |
1287 BUILD(r, WASM_I64_REINTERPRET_F64( | 1333 BUILD(r, WASM_I64_REINTERPRET_F64( |
1288 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO))); | 1334 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO))); |
1289 | 1335 |
1290 FOR_INT32_INPUTS(i) { | 1336 FOR_INT32_INPUTS(i) { |
1291 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; | 1337 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; |
1292 r.module().WriteMemory(&memory[0], expected); | 1338 module.WriteMemory(&memory[0], expected); |
1293 CHECK_EQ(expected, r.Call()); | 1339 CHECK_EQ(expected, r.Call()); |
1294 } | 1340 } |
1295 } | 1341 } |
1296 | 1342 |
1297 WASM_EXEC_TEST(F64ReinterpretI64) { | 1343 WASM_EXEC_TEST(F64ReinterpretI64) { |
1298 REQUIRE(F64ReinterpretI64); | 1344 REQUIRE(F64ReinterpretI64); |
1299 WasmRunner<int64_t, int64_t> r(execution_mode); | 1345 TestingModule module(execution_mode); |
1300 int64_t* memory = r.module().AddMemoryElems<int64_t>(8); | 1346 int64_t* memory = module.AddMemoryElems<int64_t>(8); |
| 1347 WasmRunner<int64_t> r(&module, MachineType::Int64()); |
1301 | 1348 |
1302 BUILD(r, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO, | 1349 BUILD(r, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO, |
1303 WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))), | 1350 WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))), |
1304 WASM_GET_LOCAL(0)); | 1351 WASM_GET_LOCAL(0)); |
1305 | 1352 |
1306 FOR_INT32_INPUTS(i) { | 1353 FOR_INT32_INPUTS(i) { |
1307 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; | 1354 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; |
1308 CHECK_EQ(expected, r.Call(expected)); | 1355 CHECK_EQ(expected, r.Call(expected)); |
1309 CHECK_EQ(expected, r.module().ReadMemory<int64_t>(&memory[0])); | 1356 CHECK_EQ(expected, module.ReadMemory<int64_t>(&memory[0])); |
1310 } | 1357 } |
1311 } | 1358 } |
1312 | 1359 |
1313 WASM_EXEC_TEST(LoadMemI64) { | 1360 WASM_EXEC_TEST(LoadMemI64) { |
1314 REQUIRE(I64LoadStore); | 1361 REQUIRE(I64LoadStore); |
1315 WasmRunner<int64_t> r(execution_mode); | 1362 TestingModule module(execution_mode); |
1316 int64_t* memory = r.module().AddMemoryElems<int64_t>(8); | 1363 int64_t* memory = module.AddMemoryElems<int64_t>(8); |
1317 r.module().RandomizeMemory(1111); | 1364 module.RandomizeMemory(1111); |
| 1365 WasmRunner<int64_t> r(&module); |
1318 | 1366 |
1319 BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0))); | 1367 BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0))); |
1320 | 1368 |
1321 r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL); | 1369 module.WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL); |
1322 CHECK_EQ(0x1abbccdd00112233LL, r.Call()); | 1370 CHECK_EQ(0x1abbccdd00112233LL, r.Call()); |
1323 | 1371 |
1324 r.module().WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL); | 1372 module.WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL); |
1325 CHECK_EQ(0x33aabbccdd001122LL, r.Call()); | 1373 CHECK_EQ(0x33aabbccdd001122LL, r.Call()); |
1326 | 1374 |
1327 r.module().WriteMemory<int64_t>(&memory[0], 77777777); | 1375 module.WriteMemory<int64_t>(&memory[0], 77777777); |
1328 CHECK_EQ(77777777, r.Call()); | 1376 CHECK_EQ(77777777, r.Call()); |
1329 } | 1377 } |
1330 | 1378 |
1331 WASM_EXEC_TEST(LoadMemI64_alignment) { | 1379 WASM_EXEC_TEST(LoadMemI64_alignment) { |
1332 REQUIRE(I64LoadStore); | 1380 REQUIRE(I64LoadStore); |
| 1381 TestingModule module(execution_mode); |
| 1382 int64_t* memory = module.AddMemoryElems<int64_t>(8); |
1333 for (byte alignment = 0; alignment <= 3; alignment++) { | 1383 for (byte alignment = 0; alignment <= 3; alignment++) { |
1334 WasmRunner<int64_t> r(execution_mode); | 1384 module.RandomizeMemory(1111); |
1335 int64_t* memory = r.module().AddMemoryElems<int64_t>(8); | 1385 WasmRunner<int64_t> r(&module); |
1336 r.module().RandomizeMemory(1111); | |
1337 | 1386 |
1338 BUILD(r, | 1387 BUILD(r, |
1339 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment)); | 1388 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment)); |
1340 | 1389 |
1341 r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL); | 1390 module.WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL); |
1342 CHECK_EQ(0x1abbccdd00112233LL, r.Call()); | 1391 CHECK_EQ(0x1abbccdd00112233LL, r.Call()); |
1343 | 1392 |
1344 r.module().WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL); | 1393 module.WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL); |
1345 CHECK_EQ(0x33aabbccdd001122LL, r.Call()); | 1394 CHECK_EQ(0x33aabbccdd001122LL, r.Call()); |
1346 | 1395 |
1347 r.module().WriteMemory<int64_t>(&memory[0], 77777777); | 1396 module.WriteMemory<int64_t>(&memory[0], 77777777); |
1348 CHECK_EQ(77777777, r.Call()); | 1397 CHECK_EQ(77777777, r.Call()); |
1349 } | 1398 } |
1350 } | 1399 } |
1351 | 1400 |
1352 WASM_EXEC_TEST(MemI64_Sum) { | 1401 WASM_EXEC_TEST(MemI64_Sum) { |
1353 REQUIRE(I64LoadStore); | 1402 REQUIRE(I64LoadStore); |
1354 REQUIRE(I64Add); | 1403 REQUIRE(I64Add); |
1355 REQUIRE(I64Sub); | 1404 REQUIRE(I64Sub); |
1356 REQUIRE(I64Phi); | 1405 REQUIRE(I64Phi); |
1357 const int kNumElems = 20; | 1406 const int kNumElems = 20; |
1358 WasmRunner<uint64_t, int32_t> r(execution_mode); | 1407 TestingModule module(execution_mode); |
1359 uint64_t* memory = r.module().AddMemoryElems<uint64_t>(kNumElems); | 1408 uint64_t* memory = module.AddMemoryElems<uint64_t>(kNumElems); |
| 1409 WasmRunner<uint64_t> r(&module, MachineType::Int32()); |
1360 const byte kSum = r.AllocateLocal(kAstI64); | 1410 const byte kSum = r.AllocateLocal(kAstI64); |
1361 | 1411 |
1362 BUILD( | 1412 BUILD( |
1363 r, | 1413 r, |
1364 WASM_WHILE( | 1414 WASM_WHILE( |
1365 WASM_GET_LOCAL(0), | 1415 WASM_GET_LOCAL(0), |
1366 WASM_BLOCK( | 1416 WASM_BLOCK( |
1367 WASM_SET_LOCAL(kSum, | 1417 WASM_SET_LOCAL(kSum, |
1368 WASM_I64_ADD(WASM_GET_LOCAL(kSum), | 1418 WASM_I64_ADD(WASM_GET_LOCAL(kSum), |
1369 WASM_LOAD_MEM(MachineType::Int64(), | 1419 WASM_LOAD_MEM(MachineType::Int64(), |
1370 WASM_GET_LOCAL(0)))), | 1420 WASM_GET_LOCAL(0)))), |
1371 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(8))))), | 1421 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(8))))), |
1372 WASM_GET_LOCAL(1)); | 1422 WASM_GET_LOCAL(1)); |
1373 | 1423 |
1374 // Run 4 trials. | 1424 // Run 4 trials. |
1375 for (int i = 0; i < 3; i++) { | 1425 for (int i = 0; i < 3; i++) { |
1376 r.module().RandomizeMemory(i * 33); | 1426 module.RandomizeMemory(i * 33); |
1377 uint64_t expected = 0; | 1427 uint64_t expected = 0; |
1378 for (size_t j = kNumElems - 1; j > 0; j--) { | 1428 for (size_t j = kNumElems - 1; j > 0; j--) { |
1379 expected += r.module().ReadMemory(&memory[j]); | 1429 expected += module.ReadMemory(&memory[j]); |
1380 } | 1430 } |
1381 uint64_t result = r.Call(8 * (kNumElems - 1)); | 1431 uint64_t result = r.Call(8 * (kNumElems - 1)); |
1382 CHECK_EQ(expected, result); | 1432 CHECK_EQ(expected, result); |
1383 } | 1433 } |
1384 } | 1434 } |
1385 | 1435 |
1386 WASM_EXEC_TEST(StoreMemI64_alignment) { | 1436 WASM_EXEC_TEST(StoreMemI64_alignment) { |
| 1437 TestingModule module(execution_mode); |
| 1438 int64_t* memory = module.AddMemoryElems<int64_t>(4); |
1387 const int64_t kWritten = 0x12345678abcd0011ll; | 1439 const int64_t kWritten = 0x12345678abcd0011ll; |
1388 | 1440 |
1389 for (byte i = 0; i <= 3; i++) { | 1441 for (byte i = 0; i <= 3; i++) { |
1390 WasmRunner<int64_t, int64_t> r(execution_mode); | 1442 WasmRunner<int64_t> r(&module, MachineType::Int64()); |
1391 int64_t* memory = r.module().AddMemoryElems<int64_t>(4); | |
1392 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, i, | 1443 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, i, |
1393 WASM_GET_LOCAL(0)), | 1444 WASM_GET_LOCAL(0)), |
1394 WASM_GET_LOCAL(0)); | 1445 WASM_GET_LOCAL(0)); |
1395 r.module().RandomizeMemory(1111); | 1446 module.RandomizeMemory(1111); |
1396 r.module().WriteMemory<int64_t>(&memory[0], 0); | 1447 module.WriteMemory<int64_t>(&memory[0], 0); |
1397 | 1448 |
1398 CHECK_EQ(kWritten, r.Call(kWritten)); | 1449 CHECK_EQ(kWritten, r.Call(kWritten)); |
1399 CHECK_EQ(kWritten, r.module().ReadMemory(&memory[0])); | 1450 CHECK_EQ(kWritten, module.ReadMemory(&memory[0])); |
1400 } | 1451 } |
1401 } | 1452 } |
1402 | 1453 |
1403 WASM_EXEC_TEST(I64Global) { | 1454 WASM_EXEC_TEST(I64Global) { |
1404 REQUIRE(I64LoadStore); | 1455 REQUIRE(I64LoadStore); |
1405 REQUIRE(I64SConvertI32); | 1456 REQUIRE(I64SConvertI32); |
1406 REQUIRE(I64And); | 1457 REQUIRE(I64And); |
1407 REQUIRE(DepthFirst); | 1458 REQUIRE(DepthFirst); |
1408 WasmRunner<int32_t, int32_t> r(execution_mode); | 1459 TestingModule module(execution_mode); |
1409 int64_t* global = r.module().AddGlobal<int64_t>(); | 1460 int64_t* global = module.AddGlobal<int64_t>(kAstI64); |
| 1461 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1410 // global = global + p0 | 1462 // global = global + p0 |
1411 BUILD(r, WASM_SET_GLOBAL( | 1463 BUILD(r, WASM_SET_GLOBAL( |
1412 0, WASM_I64_AND(WASM_GET_GLOBAL(0), | 1464 0, WASM_I64_AND(WASM_GET_GLOBAL(0), |
1413 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 1465 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
1414 WASM_ZERO); | 1466 WASM_ZERO); |
1415 | 1467 |
1416 r.module().WriteMemory<int64_t>(global, 0xFFFFFFFFFFFFFFFFLL); | 1468 module.WriteMemory<int64_t>(global, 0xFFFFFFFFFFFFFFFFLL); |
1417 for (int i = 9; i < 444444; i += 111111) { | 1469 for (int i = 9; i < 444444; i += 111111) { |
1418 int64_t expected = *global & i; | 1470 int64_t expected = *global & i; |
1419 r.Call(i); | 1471 r.Call(i); |
1420 CHECK_EQ(expected, *global); | 1472 CHECK_EQ(expected, *global); |
1421 } | 1473 } |
1422 } | 1474 } |
1423 | 1475 |
1424 WASM_EXEC_TEST(I64Eqz) { | 1476 WASM_EXEC_TEST(I64Eqz) { |
1425 REQUIRE(I64Eq); | 1477 REQUIRE(I64Eq); |
1426 | 1478 |
1427 WasmRunner<int32_t, int64_t> r(execution_mode); | 1479 WasmRunner<int32_t> r(execution_mode, MachineType::Int64()); |
1428 BUILD(r, WASM_I64_EQZ(WASM_GET_LOCAL(0))); | 1480 BUILD(r, WASM_I64_EQZ(WASM_GET_LOCAL(0))); |
1429 | 1481 |
1430 FOR_INT64_INPUTS(i) { | 1482 FOR_INT64_INPUTS(i) { |
1431 int32_t result = *i == 0 ? 1 : 0; | 1483 int32_t result = *i == 0 ? 1 : 0; |
1432 CHECK_EQ(result, r.Call(*i)); | 1484 CHECK_EQ(result, r.Call(*i)); |
1433 } | 1485 } |
1434 } | 1486 } |
1435 | 1487 |
1436 WASM_EXEC_TEST(I64Ror) { | 1488 WASM_EXEC_TEST(I64Ror) { |
1437 REQUIRE(I64Ror); | 1489 REQUIRE(I64Ror); |
1438 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 1490 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 1491 MachineType::Int64()); |
1439 BUILD(r, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 1492 BUILD(r, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
1440 | 1493 |
1441 FOR_UINT64_INPUTS(i) { | 1494 FOR_UINT64_INPUTS(i) { |
1442 FOR_UINT64_INPUTS(j) { | 1495 FOR_UINT64_INPUTS(j) { |
1443 int64_t expected = bits::RotateRight64(*i, *j & 0x3f); | 1496 int64_t expected = bits::RotateRight64(*i, *j & 0x3f); |
1444 CHECK_EQ(expected, r.Call(*i, *j)); | 1497 CHECK_EQ(expected, r.Call(*i, *j)); |
1445 } | 1498 } |
1446 } | 1499 } |
1447 } | 1500 } |
1448 | 1501 |
1449 WASM_EXEC_TEST(I64Rol) { | 1502 WASM_EXEC_TEST(I64Rol) { |
1450 REQUIRE(I64Rol); | 1503 REQUIRE(I64Rol); |
1451 WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); | 1504 WasmRunner<int64_t> r(execution_mode, MachineType::Int64(), |
| 1505 MachineType::Int64()); |
1452 BUILD(r, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 1506 BUILD(r, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
1453 | 1507 |
1454 FOR_UINT64_INPUTS(i) { | 1508 FOR_UINT64_INPUTS(i) { |
1455 FOR_UINT64_INPUTS(j) { | 1509 FOR_UINT64_INPUTS(j) { |
1456 int64_t expected = bits::RotateLeft64(*i, *j & 0x3f); | 1510 int64_t expected = bits::RotateLeft64(*i, *j & 0x3f); |
1457 CHECK_EQ(expected, r.Call(*i, *j)); | 1511 CHECK_EQ(expected, r.Call(*i, *j)); |
1458 } | 1512 } |
1459 } | 1513 } |
1460 } | 1514 } |
1461 | 1515 |
1462 WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob_i64) { | 1516 WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob_i64) { |
| 1517 TestingModule module(execution_mode); |
| 1518 byte* memory = module.AddMemoryElems<byte>(32); |
| 1519 |
1463 static const MachineType machineTypes[] = { | 1520 static const MachineType machineTypes[] = { |
1464 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 1521 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
1465 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 1522 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
1466 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), | 1523 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
1467 MachineType::Float64()}; | 1524 MachineType::Float64()}; |
1468 | 1525 |
1469 for (size_t m = 0; m < arraysize(machineTypes); m++) { | 1526 for (size_t m = 0; m < arraysize(machineTypes); m++) { |
1470 WasmRunner<int32_t, uint32_t> r(execution_mode); | 1527 module.RandomizeMemory(1119 + static_cast<int>(m)); |
1471 byte* memory = r.module().AddMemoryElems<byte>(32); | 1528 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1472 r.module().RandomizeMemory(1119 + static_cast<int>(m)); | |
1473 | 1529 |
1474 BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0), | 1530 BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0), |
1475 WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)), | 1531 WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)), |
1476 WASM_ZERO); | 1532 WASM_ZERO); |
1477 | 1533 |
1478 byte memsize = WasmOpcodes::MemSize(machineTypes[m]); | 1534 byte memsize = WasmOpcodes::MemSize(machineTypes[m]); |
1479 uint32_t boundary = 24 - memsize; | 1535 uint32_t boundary = 24 - memsize; |
1480 CHECK_EQ(0, r.Call(boundary)); // in bounds. | 1536 CHECK_EQ(0, r.Call(boundary)); // in bounds. |
1481 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); | 1537 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); |
1482 | 1538 |
1483 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { | 1539 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { |
1484 CHECK_TRAP(r.Call(offset)); // out of bounds. | 1540 CHECK_TRAP(r.Call(offset)); // out of bounds. |
1485 } | 1541 } |
1486 } | 1542 } |
1487 } | 1543 } |
1488 | 1544 |
1489 #define ADD_CODE(vec, ...) \ | 1545 #define ADD_CODE(vec, ...) \ |
1490 do { \ | 1546 do { \ |
1491 byte __buf[] = {__VA_ARGS__}; \ | 1547 byte __buf[] = {__VA_ARGS__}; \ |
1492 for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \ | 1548 for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \ |
1493 } while (false) | 1549 } while (false) |
1494 | 1550 |
1495 static void CompileCallIndirectMany(LocalType param) { | 1551 static void CompileCallIndirectMany(LocalType param) { |
1496 // Make sure we don't run out of registers when compiling indirect calls | 1552 // Make sure we don't run out of registers when compiling indirect calls |
1497 // with many many parameters. | 1553 // with many many parameters. |
1498 TestSignatures sigs; | 1554 TestSignatures sigs; |
1499 for (byte num_params = 0; num_params < 40; num_params++) { | 1555 for (byte num_params = 0; num_params < 40; num_params++) { |
1500 WasmRunner<void> r(kExecuteCompiled); | 1556 v8::internal::AccountingAllocator allocator; |
1501 FunctionSig* sig = sigs.many(r.zone(), kAstStmt, param, num_params); | 1557 Zone zone(&allocator, ZONE_NAME); |
| 1558 HandleScope scope(CcTest::InitIsolateOnce()); |
| 1559 TestingModule module(kExecuteCompiled); |
| 1560 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params); |
1502 | 1561 |
1503 r.module().AddSignature(sig); | 1562 module.AddSignature(sig); |
1504 r.module().AddSignature(sig); | 1563 module.AddSignature(sig); |
1505 r.module().AddIndirectFunctionTable(nullptr, 0); | 1564 module.AddIndirectFunctionTable(nullptr, 0); |
1506 | 1565 |
1507 WasmFunctionCompiler& t = r.NewFunction(sig); | 1566 WasmFunctionCompiler t(sig, &module); |
1508 | 1567 |
1509 std::vector<byte> code; | 1568 std::vector<byte> code; |
1510 for (byte p = 0; p < num_params; p++) { | 1569 for (byte p = 0; p < num_params; p++) { |
1511 ADD_CODE(code, kExprGetLocal, p); | 1570 ADD_CODE(code, kExprGetLocal, p); |
1512 } | 1571 } |
1513 ADD_CODE(code, kExprI8Const, 0); | 1572 ADD_CODE(code, kExprI8Const, 0); |
1514 ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); | 1573 ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); |
1515 | 1574 |
1516 t.Build(&code[0], &code[0] + code.size()); | 1575 t.Build(&code[0], &code[0] + code.size()); |
| 1576 t.Compile(); |
1517 } | 1577 } |
1518 } | 1578 } |
1519 | 1579 |
1520 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 1580 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } |
1521 | 1581 |
1522 static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { | 1582 static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { |
1523 const int kExpected = 6333; | 1583 const int kExpected = 6333; |
1524 const int kElemSize = 8; | 1584 const int kElemSize = 8; |
1525 TestSignatures sigs; | 1585 TestSignatures sigs; |
1526 | 1586 |
1527 static MachineType mixed[] = { | 1587 static MachineType mixed[] = { |
1528 MachineType::Int32(), MachineType::Float32(), MachineType::Int64(), | 1588 MachineType::Int32(), MachineType::Float32(), MachineType::Int64(), |
1529 MachineType::Float64(), MachineType::Float32(), MachineType::Int64(), | 1589 MachineType::Float64(), MachineType::Float32(), MachineType::Int64(), |
1530 MachineType::Int32(), MachineType::Float64(), MachineType::Float32(), | 1590 MachineType::Int32(), MachineType::Float64(), MachineType::Float32(), |
1531 MachineType::Float64(), MachineType::Int32(), MachineType::Int64(), | 1591 MachineType::Float64(), MachineType::Int32(), MachineType::Int64(), |
1532 MachineType::Int32(), MachineType::Int32()}; | 1592 MachineType::Int32(), MachineType::Int32()}; |
1533 | 1593 |
1534 int num_params = static_cast<int>(arraysize(mixed)) - start; | 1594 int num_params = static_cast<int>(arraysize(mixed)) - start; |
1535 for (int which = 0; which < num_params; which++) { | 1595 for (int which = 0; which < num_params; which++) { |
1536 v8::internal::AccountingAllocator allocator; | 1596 v8::internal::AccountingAllocator allocator; |
1537 Zone zone(&allocator, ZONE_NAME); | 1597 Zone zone(&allocator, ZONE_NAME); |
1538 WasmRunner<int32_t> r(execution_mode); | 1598 TestingModule module(execution_mode); |
1539 r.module().AddMemory(1024); | 1599 module.AddMemory(1024); |
1540 MachineType* memtypes = &mixed[start]; | 1600 MachineType* memtypes = &mixed[start]; |
1541 MachineType result = memtypes[which]; | 1601 MachineType result = memtypes[which]; |
1542 | 1602 |
1543 // ========================================================================= | 1603 // ========================================================================= |
1544 // Build the selector function. | 1604 // Build the selector function. |
1545 // ========================================================================= | 1605 // ========================================================================= |
| 1606 uint32_t index; |
1546 FunctionSig::Builder b(&zone, 1, num_params); | 1607 FunctionSig::Builder b(&zone, 1, num_params); |
1547 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); | 1608 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); |
1548 for (int i = 0; i < num_params; i++) { | 1609 for (int i = 0; i < num_params; i++) { |
1549 b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i])); | 1610 b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i])); |
1550 } | 1611 } |
1551 WasmFunctionCompiler& t = r.NewFunction(b.Build()); | 1612 WasmFunctionCompiler t(b.Build(), &module); |
1552 BUILD(t, WASM_GET_LOCAL(which)); | 1613 BUILD(t, WASM_GET_LOCAL(which)); |
| 1614 index = t.CompileAndAdd(); |
1553 | 1615 |
1554 // ========================================================================= | 1616 // ========================================================================= |
1555 // Build the calling function. | 1617 // Build the calling function. |
1556 // ========================================================================= | 1618 // ========================================================================= |
| 1619 WasmRunner<int32_t> r(&module); |
1557 std::vector<byte> code; | 1620 std::vector<byte> code; |
1558 | 1621 |
1559 // Load the offset for the store. | 1622 // Load the offset for the store. |
1560 ADD_CODE(code, WASM_ZERO); | 1623 ADD_CODE(code, WASM_ZERO); |
1561 | 1624 |
1562 // Load the arguments. | 1625 // Load the arguments. |
1563 for (int i = 0; i < num_params; i++) { | 1626 for (int i = 0; i < num_params; i++) { |
1564 int offset = (i + 1) * kElemSize; | 1627 int offset = (i + 1) * kElemSize; |
1565 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); | 1628 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); |
1566 } | 1629 } |
1567 | 1630 |
1568 // Call the selector function. | 1631 // Call the selector function. |
1569 ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index())); | 1632 ADD_CODE(code, kExprCallFunction, static_cast<byte>(index)); |
1570 | 1633 |
1571 // Store the result in memory. | 1634 // Store the result in memory. |
1572 ADD_CODE(code, | 1635 ADD_CODE(code, |
1573 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), | 1636 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), |
1574 ZERO_ALIGNMENT, ZERO_OFFSET); | 1637 ZERO_ALIGNMENT, ZERO_OFFSET); |
1575 | 1638 |
1576 // Return the expected value. | 1639 // Return the expected value. |
1577 ADD_CODE(code, WASM_I32V_2(kExpected)); | 1640 ADD_CODE(code, WASM_I32V_2(kExpected)); |
1578 | 1641 |
1579 r.Build(&code[0], &code[0] + code.size()); | 1642 r.Build(&code[0], &code[0] + code.size()); |
1580 | 1643 |
1581 // Run the code. | 1644 // Run the code. |
1582 for (int t = 0; t < 10; t++) { | 1645 for (int t = 0; t < 10; t++) { |
1583 r.module().RandomizeMemory(); | 1646 module.RandomizeMemory(); |
1584 CHECK_EQ(kExpected, r.Call()); | 1647 CHECK_EQ(kExpected, r.Call()); |
1585 | 1648 |
1586 int size = WasmOpcodes::MemSize(result); | 1649 int size = WasmOpcodes::MemSize(result); |
1587 for (int i = 0; i < size; i++) { | 1650 for (int i = 0; i < size; i++) { |
1588 int base = (which + 1) * kElemSize; | 1651 int base = (which + 1) * kElemSize; |
1589 byte expected = r.module().raw_mem_at<byte>(base + i); | 1652 byte expected = module.raw_mem_at<byte>(base + i); |
1590 byte result = r.module().raw_mem_at<byte>(i); | 1653 byte result = module.raw_mem_at<byte>(i); |
1591 CHECK_EQ(expected, result); | 1654 CHECK_EQ(expected, result); |
1592 } | 1655 } |
1593 } | 1656 } |
1594 } | 1657 } |
1595 } | 1658 } |
1596 | 1659 |
1597 WASM_EXEC_TEST(MixedCall_i64_0) { Run_WasmMixedCall_N(execution_mode, 0); } | 1660 WASM_EXEC_TEST(MixedCall_i64_0) { Run_WasmMixedCall_N(execution_mode, 0); } |
1598 WASM_EXEC_TEST(MixedCall_i64_1) { Run_WasmMixedCall_N(execution_mode, 1); } | 1661 WASM_EXEC_TEST(MixedCall_i64_1) { Run_WasmMixedCall_N(execution_mode, 1); } |
1599 WASM_EXEC_TEST(MixedCall_i64_2) { Run_WasmMixedCall_N(execution_mode, 2); } | 1662 WASM_EXEC_TEST(MixedCall_i64_2) { Run_WasmMixedCall_N(execution_mode, 2); } |
1600 WASM_EXEC_TEST(MixedCall_i64_3) { Run_WasmMixedCall_N(execution_mode, 3); } | 1663 WASM_EXEC_TEST(MixedCall_i64_3) { Run_WasmMixedCall_N(execution_mode, 3); } |
OLD | NEW |