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

Side by Side Diff: test/cctest/wasm/test-run-wasm-64.cc

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

Powered by Google App Engine
This is Rietveld 408576698