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/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 int32_t result = r.Call(); | 53 int32_t result = r.Call(); |
54 CHECK_EQ(value, result); | 54 CHECK_EQ(value, result); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 TEST(Run_WasmInt32Const) { | 59 TEST(Run_WasmInt32Const) { |
60 WasmRunner<int32_t> r; | 60 WasmRunner<int32_t> r; |
61 const int32_t kExpectedValue = 0x11223344; | 61 const int32_t kExpectedValue = 0x11223344; |
62 // return(kExpectedValue) | 62 // return(kExpectedValue) |
63 BUILD(r, WASM_I32(kExpectedValue)); | 63 BUILD(r, WASM_I32V_5(kExpectedValue)); |
64 CHECK_EQ(kExpectedValue, r.Call()); | 64 CHECK_EQ(kExpectedValue, r.Call()); |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 TEST(Run_WasmInt32Const_many) { | 68 TEST(Run_WasmInt32Const_many) { |
69 FOR_INT32_INPUTS(i) { | 69 FOR_INT32_INPUTS(i) { |
70 WasmRunner<int32_t> r; | 70 WasmRunner<int32_t> r; |
71 const int32_t kExpectedValue = *i; | 71 const int32_t kExpectedValue = *i; |
72 // return(kExpectedValue) | 72 // return(kExpectedValue) |
73 BUILD(r, WASM_I32(kExpectedValue)); | 73 BUILD(r, WASM_I32V(kExpectedValue)); |
74 CHECK_EQ(kExpectedValue, r.Call()); | 74 CHECK_EQ(kExpectedValue, r.Call()); |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 TEST(Run_WasmMemorySize) { | 79 TEST(Run_WasmMemorySize) { |
80 TestingModule module; | 80 TestingModule module; |
81 WasmRunner<int32_t> r(&module); | 81 WasmRunner<int32_t> r(&module); |
82 module.AddMemory(1024); | 82 module.AddMemory(1024); |
83 BUILD(r, kExprMemorySize); | 83 BUILD(r, kExprMemorySize); |
84 CHECK_EQ(1024, r.Call()); | 84 CHECK_EQ(1024, r.Call()); |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 #if WASM_64 | 88 #if WASM_64 |
89 TEST(Run_WasmInt64Const) { | 89 TEST(Run_WasmInt64Const) { |
90 WasmRunner<int64_t> r; | 90 WasmRunner<int64_t> r; |
91 const int64_t kExpectedValue = 0x1122334455667788LL; | 91 const int64_t kExpectedValue = 0x1122334455667788LL; |
92 // return(kExpectedValue) | 92 // return(kExpectedValue) |
93 BUILD(r, WASM_I64(kExpectedValue)); | 93 BUILD(r, WASM_I64V_9(kExpectedValue)); |
94 CHECK_EQ(kExpectedValue, r.Call()); | 94 CHECK_EQ(kExpectedValue, r.Call()); |
95 } | 95 } |
96 | 96 |
97 | 97 |
98 TEST(Run_WasmInt64Const_many) { | 98 TEST(Run_WasmInt64Const_many) { |
99 int cntr = 0; | 99 int cntr = 0; |
100 FOR_INT32_INPUTS(i) { | 100 FOR_INT32_INPUTS(i) { |
101 WasmRunner<int64_t> r; | 101 WasmRunner<int64_t> r; |
102 const int64_t kExpectedValue = (static_cast<int64_t>(*i) << 32) | cntr; | 102 const int64_t kExpectedValue = (static_cast<int64_t>(*i) << 32) | cntr; |
103 // return(kExpectedValue) | 103 // return(kExpectedValue) |
104 BUILD(r, WASM_I64(kExpectedValue)); | 104 BUILD(r, WASM_I64V(kExpectedValue)); |
105 CHECK_EQ(kExpectedValue, r.Call()); | 105 CHECK_EQ(kExpectedValue, r.Call()); |
106 cntr++; | 106 cntr++; |
107 } | 107 } |
108 } | 108 } |
109 #endif | 109 #endif |
110 | 110 |
111 | 111 |
112 TEST(Run_WasmInt32Param0) { | 112 TEST(Run_WasmInt32Param0) { |
113 WasmRunner<int32_t> r(MachineType::Int32()); | 113 WasmRunner<int32_t> r(MachineType::Int32()); |
114 // return(local[0]) | 114 // return(local[0]) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // return int(13.5d + 43.5d) | 185 // return int(13.5d + 43.5d) |
186 BUILD(r, WASM_I32_SCONVERT_F64(WASM_F64_ADD(WASM_F64(13.5), WASM_F64(43.5)))); | 186 BUILD(r, WASM_I32_SCONVERT_F64(WASM_F64_ADD(WASM_F64(13.5), WASM_F64(43.5)))); |
187 CHECK_EQ(57, r.Call()); | 187 CHECK_EQ(57, r.Call()); |
188 } | 188 } |
189 | 189 |
190 | 190 |
191 void TestInt32Binop(WasmOpcode opcode, int32_t expected, int32_t a, int32_t b) { | 191 void TestInt32Binop(WasmOpcode opcode, int32_t expected, int32_t a, int32_t b) { |
192 { | 192 { |
193 WasmRunner<int32_t> r; | 193 WasmRunner<int32_t> r; |
194 // K op K | 194 // K op K |
195 BUILD(r, WASM_BINOP(opcode, WASM_I32(a), WASM_I32(b))); | 195 BUILD(r, WASM_BINOP(opcode, WASM_I32V(a), WASM_I32V(b))); |
196 CHECK_EQ(expected, r.Call()); | 196 CHECK_EQ(expected, r.Call()); |
197 } | 197 } |
198 { | 198 { |
199 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 199 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
200 // a op b | 200 // a op b |
201 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 201 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
202 CHECK_EQ(expected, r.Call(a, b)); | 202 CHECK_EQ(expected, r.Call(a, b)); |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
(...skipping 27 matching lines...) Expand all Loading... |
233 TestInt32Binop(kExprI32GeS, 0, -3, -2); | 233 TestInt32Binop(kExprI32GeS, 0, -3, -2); |
234 TestInt32Binop(kExprI32GtU, 1, -6, 0); | 234 TestInt32Binop(kExprI32GtU, 1, -6, 0); |
235 TestInt32Binop(kExprI32GeU, 1, 0xF0000000, 98978); | 235 TestInt32Binop(kExprI32GeU, 1, 0xF0000000, 98978); |
236 } | 236 } |
237 | 237 |
238 | 238 |
239 void TestInt32Unop(WasmOpcode opcode, int32_t expected, int32_t a) { | 239 void TestInt32Unop(WasmOpcode opcode, int32_t expected, int32_t a) { |
240 { | 240 { |
241 WasmRunner<int32_t> r; | 241 WasmRunner<int32_t> r; |
242 // return op K | 242 // return op K |
243 BUILD(r, WASM_UNOP(opcode, WASM_I32(a))); | 243 BUILD(r, WASM_UNOP(opcode, WASM_I32V(a))); |
244 CHECK_EQ(expected, r.Call()); | 244 CHECK_EQ(expected, r.Call()); |
245 } | 245 } |
246 { | 246 { |
247 WasmRunner<int32_t> r(MachineType::Int32()); | 247 WasmRunner<int32_t> r(MachineType::Int32()); |
248 // return op a | 248 // return op a |
249 BUILD(r, WASM_UNOP(opcode, WASM_GET_LOCAL(0))); | 249 BUILD(r, WASM_UNOP(opcode, WASM_GET_LOCAL(0))); |
250 CHECK_EQ(expected, r.Call(a)); | 250 CHECK_EQ(expected, r.Call(a)); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 TestInt32Unop(kExprI32Popcnt, 19, 0xfedcba09); | 334 TestInt32Unop(kExprI32Popcnt, 19, 0xfedcba09); |
335 } | 335 } |
336 | 336 |
337 | 337 |
338 #if WASM_64 | 338 #if WASM_64 |
339 void TestInt64Binop(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) { | 339 void TestInt64Binop(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) { |
340 if (!WasmOpcodes::IsSupported(opcode)) return; | 340 if (!WasmOpcodes::IsSupported(opcode)) return; |
341 { | 341 { |
342 WasmRunner<int64_t> r; | 342 WasmRunner<int64_t> r; |
343 // return K op K | 343 // return K op K |
344 BUILD(r, WASM_BINOP(opcode, WASM_I64(a), WASM_I64(b))); | 344 BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b))); |
345 CHECK_EQ(expected, r.Call()); | 345 CHECK_EQ(expected, r.Call()); |
346 } | 346 } |
347 { | 347 { |
348 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | 348 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); |
349 // return a op b | 349 // return a op b |
350 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 350 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
351 CHECK_EQ(expected, r.Call(a, b)); | 351 CHECK_EQ(expected, r.Call(a, b)); |
352 } | 352 } |
353 } | 353 } |
354 | 354 |
355 | 355 |
356 void TestInt64Cmp(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) { | 356 void TestInt64Cmp(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) { |
357 if (!WasmOpcodes::IsSupported(opcode)) return; | 357 if (!WasmOpcodes::IsSupported(opcode)) return; |
358 { | 358 { |
359 WasmRunner<int32_t> r; | 359 WasmRunner<int32_t> r; |
360 // return K op K | 360 // return K op K |
361 BUILD(r, WASM_BINOP(opcode, WASM_I64(a), WASM_I64(b))); | 361 BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b))); |
362 CHECK_EQ(expected, r.Call()); | 362 CHECK_EQ(expected, r.Call()); |
363 } | 363 } |
364 { | 364 { |
365 WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64()); | 365 WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64()); |
366 // return a op b | 366 // return a op b |
367 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 367 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
368 CHECK_EQ(expected, r.Call(a, b)); | 368 CHECK_EQ(expected, r.Call(a, b)); |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 CHECK_EQ(val / denom, r.Call(val)); | 567 CHECK_EQ(val / denom, r.Call(val)); |
568 } | 568 } |
569 } | 569 } |
570 } | 570 } |
571 } | 571 } |
572 | 572 |
573 | 573 |
574 TEST(Run_WASM_Int32DivU_byzero_const) { | 574 TEST(Run_WASM_Int32DivU_byzero_const) { |
575 for (uint32_t denom = 0xfffffffe; denom < 8; denom++) { | 575 for (uint32_t denom = 0xfffffffe; denom < 8; denom++) { |
576 WasmRunner<uint32_t> r(MachineType::Uint32()); | 576 WasmRunner<uint32_t> r(MachineType::Uint32()); |
577 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32(denom))); | 577 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); |
578 | 578 |
579 for (uint32_t val = 0xfffffff0; val < 8; val++) { | 579 for (uint32_t val = 0xfffffff0; val < 8; val++) { |
580 if (denom == 0) { | 580 if (denom == 0) { |
581 CHECK_TRAP(r.Call(val)); | 581 CHECK_TRAP(r.Call(val)); |
582 } else { | 582 } else { |
583 CHECK_EQ(val / denom, r.Call(val)); | 583 CHECK_EQ(val / denom, r.Call(val)); |
584 } | 584 } |
585 } | 585 } |
586 } | 586 } |
587 } | 587 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 CHECK_TRAP64(r.Call(as64(-1001), as64(0))); | 650 CHECK_TRAP64(r.Call(as64(-1001), as64(0))); |
651 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), as64(0))); | 651 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), as64(0))); |
652 CHECK_EQ(std::numeric_limits<int64_t>::min(), | 652 CHECK_EQ(std::numeric_limits<int64_t>::min(), |
653 r.Call(std::numeric_limits<int64_t>::min(), as64(-1))); | 653 r.Call(std::numeric_limits<int64_t>::min(), as64(-1))); |
654 } | 654 } |
655 | 655 |
656 | 656 |
657 TEST(Run_WASM_Int64DivS_byzero_const) { | 657 TEST(Run_WASM_Int64DivS_byzero_const) { |
658 for (int8_t denom = -2; denom < 8; denom++) { | 658 for (int8_t denom = -2; denom < 8; denom++) { |
659 WasmRunner<int64_t> r(MachineType::Int64()); | 659 WasmRunner<int64_t> r(MachineType::Int64()); |
660 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64(denom))); | 660 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(denom))); |
661 for (int64_t val = -7; val < 8; val++) { | 661 for (int64_t val = -7; val < 8; val++) { |
662 if (denom == 0) { | 662 if (denom == 0) { |
663 CHECK_TRAP64(r.Call(val)); | 663 CHECK_TRAP64(r.Call(val)); |
664 } else { | 664 } else { |
665 CHECK_EQ(val / denom, r.Call(val)); | 665 CHECK_EQ(val / denom, r.Call(val)); |
666 } | 666 } |
667 } | 667 } |
668 } | 668 } |
669 } | 669 } |
670 | 670 |
671 | 671 |
672 TEST(Run_WASM_Int64DivU_byzero_const) { | 672 TEST(Run_WASM_Int64DivU_byzero_const) { |
673 for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) { | 673 for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) { |
674 WasmRunner<uint64_t> r(MachineType::Uint64()); | 674 WasmRunner<uint64_t> r(MachineType::Uint64()); |
675 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64(denom))); | 675 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom))); |
676 | 676 |
677 for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) { | 677 for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) { |
678 if (denom == 0) { | 678 if (denom == 0) { |
679 CHECK_TRAP64(r.Call(val)); | 679 CHECK_TRAP64(r.Call(val)); |
680 } else { | 680 } else { |
681 CHECK_EQ(val / denom, r.Call(val)); | 681 CHECK_EQ(val / denom, r.Call(val)); |
682 } | 682 } |
683 } | 683 } |
684 } | 684 } |
685 } | 685 } |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 TestSignatures sigs; | 1261 TestSignatures sigs; |
1262 TestingModule module; | 1262 TestingModule module; |
1263 WasmFunctionCompiler t(sigs.v_v(), &module); | 1263 WasmFunctionCompiler t(sigs.v_v(), &module); |
1264 BUILD(t, kExprNop); | 1264 BUILD(t, kExprNop); |
1265 uint32_t index = t.CompileAndAdd(); | 1265 uint32_t index = t.CompileAndAdd(); |
1266 | 1266 |
1267 const int32_t kExpected = -414444; | 1267 const int32_t kExpected = -414444; |
1268 // Build the calling function. | 1268 // Build the calling function. |
1269 WasmRunner<int32_t> r; | 1269 WasmRunner<int32_t> r; |
1270 r.env()->module = &module; | 1270 r.env()->module = &module; |
1271 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); | 1271 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); |
1272 | 1272 |
1273 int32_t result = r.Call(); | 1273 int32_t result = r.Call(); |
1274 CHECK_EQ(kExpected, result); | 1274 CHECK_EQ(kExpected, result); |
1275 } | 1275 } |
1276 | 1276 |
1277 | 1277 |
1278 TEST(Run_Wasm_VoidReturn2) { | 1278 TEST(Run_Wasm_VoidReturn2) { |
1279 // We use a wrapper function because WasmRunner<void> does not exist. | 1279 // We use a wrapper function because WasmRunner<void> does not exist. |
1280 // Build the test function. | 1280 // Build the test function. |
1281 TestSignatures sigs; | 1281 TestSignatures sigs; |
1282 TestingModule module; | 1282 TestingModule module; |
1283 WasmFunctionCompiler t(sigs.v_v(), &module); | 1283 WasmFunctionCompiler t(sigs.v_v(), &module); |
1284 BUILD(t, WASM_RETURN0); | 1284 BUILD(t, WASM_RETURN0); |
1285 uint32_t index = t.CompileAndAdd(); | 1285 uint32_t index = t.CompileAndAdd(); |
1286 | 1286 |
1287 const int32_t kExpected = -414444; | 1287 const int32_t kExpected = -414444; |
1288 // Build the calling function. | 1288 // Build the calling function. |
1289 WasmRunner<int32_t> r; | 1289 WasmRunner<int32_t> r; |
1290 r.env()->module = &module; | 1290 r.env()->module = &module; |
1291 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); | 1291 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); |
1292 | 1292 |
1293 int32_t result = r.Call(); | 1293 int32_t result = r.Call(); |
1294 CHECK_EQ(kExpected, result); | 1294 CHECK_EQ(kExpected, result); |
1295 } | 1295 } |
1296 | 1296 |
1297 | 1297 |
1298 TEST(Run_Wasm_Block_If_P) { | 1298 TEST(Run_Wasm_Block_If_P) { |
1299 WasmRunner<int32_t> r(MachineType::Int32()); | 1299 WasmRunner<int32_t> r(MachineType::Int32()); |
1300 // { if (p0) return 51; return 52; } | 1300 // { if (p0) return 51; return 52; } |
1301 BUILD(r, WASM_BLOCK(2, // -- | 1301 BUILD(r, WASM_BLOCK(2, // -- |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 } | 1642 } |
1643 | 1643 |
1644 | 1644 |
1645 TEST(Run_Wasm_StoreMemI32_offset) { | 1645 TEST(Run_Wasm_StoreMemI32_offset) { |
1646 TestingModule module; | 1646 TestingModule module; |
1647 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1647 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
1648 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1648 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1649 const int32_t kWritten = 0xaabbccdd; | 1649 const int32_t kWritten = 0xaabbccdd; |
1650 | 1650 |
1651 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), | 1651 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), |
1652 WASM_I32(kWritten))); | 1652 WASM_I32V_5(kWritten))); |
1653 | 1653 |
1654 for (int i = 0; i < 2; i++) { | 1654 for (int i = 0; i < 2; i++) { |
1655 module.RandomizeMemory(1111); | 1655 module.RandomizeMemory(1111); |
1656 memory[0] = 66666666; | 1656 memory[0] = 66666666; |
1657 memory[1] = 77777777; | 1657 memory[1] = 77777777; |
1658 memory[2] = 88888888; | 1658 memory[2] = 88888888; |
1659 memory[3] = 99999999; | 1659 memory[3] = 99999999; |
1660 CHECK_EQ(kWritten, r.Call(i * 4)); | 1660 CHECK_EQ(kWritten, r.Call(i * 4)); |
1661 CHECK_EQ(66666666, memory[0]); | 1661 CHECK_EQ(66666666, memory[0]); |
1662 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]); | 1662 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]); |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 } | 2297 } |
2298 | 2298 |
2299 | 2299 |
2300 #if WASM_64 | 2300 #if WASM_64 |
2301 // Test the WasmRunner with an Int64 return value and different numbers of | 2301 // Test the WasmRunner with an Int64 return value and different numbers of |
2302 // Int64 parameters. | 2302 // Int64 parameters. |
2303 TEST(Run_TestI64WasmRunner) { | 2303 TEST(Run_TestI64WasmRunner) { |
2304 { | 2304 { |
2305 FOR_INT64_INPUTS(i) { | 2305 FOR_INT64_INPUTS(i) { |
2306 WasmRunner<int64_t> r; | 2306 WasmRunner<int64_t> r; |
2307 BUILD(r, WASM_I64(*i)); | 2307 BUILD(r, WASM_I64V(*i)); |
2308 CHECK_EQ(*i, r.Call()); | 2308 CHECK_EQ(*i, r.Call()); |
2309 } | 2309 } |
2310 } | 2310 } |
2311 { | 2311 { |
2312 WasmRunner<int64_t> r(MachineType::Int64()); | 2312 WasmRunner<int64_t> r(MachineType::Int64()); |
2313 BUILD(r, WASM_GET_LOCAL(0)); | 2313 BUILD(r, WASM_GET_LOCAL(0)); |
2314 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 2314 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
2315 } | 2315 } |
2316 { | 2316 { |
2317 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | 2317 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2352 } | 2352 } |
2353 #endif | 2353 #endif |
2354 | 2354 |
2355 | 2355 |
2356 TEST(Run_WasmCallEmpty) { | 2356 TEST(Run_WasmCallEmpty) { |
2357 const int32_t kExpected = -414444; | 2357 const int32_t kExpected = -414444; |
2358 // Build the target function. | 2358 // Build the target function. |
2359 TestSignatures sigs; | 2359 TestSignatures sigs; |
2360 TestingModule module; | 2360 TestingModule module; |
2361 WasmFunctionCompiler t(sigs.i_v(), &module); | 2361 WasmFunctionCompiler t(sigs.i_v(), &module); |
2362 BUILD(t, WASM_I32(kExpected)); | 2362 BUILD(t, WASM_I32V_3(kExpected)); |
2363 uint32_t index = t.CompileAndAdd(); | 2363 uint32_t index = t.CompileAndAdd(); |
2364 | 2364 |
2365 // Build the calling function. | 2365 // Build the calling function. |
2366 WasmRunner<int32_t> r(&module); | 2366 WasmRunner<int32_t> r(&module); |
2367 BUILD(r, WASM_CALL_FUNCTION0(index)); | 2367 BUILD(r, WASM_CALL_FUNCTION0(index)); |
2368 | 2368 |
2369 int32_t result = r.Call(); | 2369 int32_t result = r.Call(); |
2370 CHECK_EQ(kExpected, result); | 2370 CHECK_EQ(kExpected, result); |
2371 } | 2371 } |
2372 | 2372 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2424 const byte kMemOffset = 8; | 2424 const byte kMemOffset = 8; |
2425 const int32_t kElemNum = kMemOffset / sizeof(int32_t); | 2425 const int32_t kElemNum = kMemOffset / sizeof(int32_t); |
2426 const int32_t kExpected = -414444; | 2426 const int32_t kExpected = -414444; |
2427 // Build the target function. | 2427 // Build the target function. |
2428 TestSignatures sigs; | 2428 TestSignatures sigs; |
2429 TestingModule module; | 2429 TestingModule module; |
2430 module.AddMemory(16); | 2430 module.AddMemory(16); |
2431 module.RandomizeMemory(); | 2431 module.RandomizeMemory(); |
2432 WasmFunctionCompiler t(sigs.v_v(), &module); | 2432 WasmFunctionCompiler t(sigs.v_v(), &module); |
2433 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), | 2433 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), |
2434 WASM_I32(kExpected))); | 2434 WASM_I32V_3(kExpected))); |
2435 uint32_t index = t.CompileAndAdd(); | 2435 uint32_t index = t.CompileAndAdd(); |
2436 | 2436 |
2437 // Build the calling function. | 2437 // Build the calling function. |
2438 WasmRunner<int32_t> r(&module); | 2438 WasmRunner<int32_t> r(&module); |
2439 BUILD(r, WASM_CALL_FUNCTION0(index), | 2439 BUILD(r, WASM_CALL_FUNCTION0(index), |
2440 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); | 2440 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); |
2441 | 2441 |
2442 int32_t result = r.Call(); | 2442 int32_t result = r.Call(); |
2443 CHECK_EQ(kExpected, result); | 2443 CHECK_EQ(kExpected, result); |
2444 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); | 2444 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2604 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), | 2604 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), |
2605 WasmOpcodes::LoadStoreAccessOf(false)); | 2605 WasmOpcodes::LoadStoreAccessOf(false)); |
2606 ADD_CODE(code, WASM_ZERO); | 2606 ADD_CODE(code, WASM_ZERO); |
2607 ADD_CODE(code, kExprCallFunction, static_cast<byte>(index)); | 2607 ADD_CODE(code, kExprCallFunction, static_cast<byte>(index)); |
2608 | 2608 |
2609 for (int i = 0; i < num_params; i++) { | 2609 for (int i = 0; i < num_params; i++) { |
2610 int offset = (i + 1) * kElemSize; | 2610 int offset = (i + 1) * kElemSize; |
2611 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); | 2611 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); |
2612 } | 2612 } |
2613 | 2613 |
2614 ADD_CODE(code, WASM_I32(kExpected)); | 2614 ADD_CODE(code, WASM_I32V_2(kExpected)); |
2615 size_t end = code.size(); | 2615 size_t end = code.size(); |
2616 code.push_back(0); | 2616 code.push_back(0); |
2617 r.Build(&code[0], &code[end]); | 2617 r.Build(&code[0], &code[end]); |
2618 | 2618 |
2619 // Run the code. | 2619 // Run the code. |
2620 for (int t = 0; t < 10; t++) { | 2620 for (int t = 0; t < 10; t++) { |
2621 module.RandomizeMemory(); | 2621 module.RandomizeMemory(); |
2622 CHECK_EQ(kExpected, r.Call()); | 2622 CHECK_EQ(kExpected, r.Call()); |
2623 | 2623 |
2624 int size = WasmOpcodes::MemSize(result); | 2624 int size = WasmOpcodes::MemSize(result); |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3169 WasmRunner<double> r; | 3169 WasmRunner<double> r; |
3170 BUILD(r, WASM_F64_MAX(WASM_F64(45.73), | 3170 BUILD(r, WASM_F64_MAX(WASM_F64(45.73), |
3171 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); | 3171 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); |
3172 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 3172 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
3173 } | 3173 } |
3174 } | 3174 } |
3175 | 3175 |
3176 #endif | 3176 #endif |
3177 | 3177 |
3178 #if WASM_64 | 3178 #if WASM_64 |
| 3179 TEST(Run_Wasm_F32SConvertI64) { |
| 3180 WasmRunner<float> r(MachineType::Int64()); |
| 3181 BUILD(r, WASM_F32_SCONVERT_I64(WASM_GET_LOCAL(0))); |
| 3182 FOR_INT64_INPUTS(i) { CHECK_EQ(static_cast<float>(*i), r.Call(*i)); } |
| 3183 } |
| 3184 |
| 3185 |
| 3186 #if !defined(_WIN64) |
| 3187 // TODO(ahaas): Fix this failure. |
| 3188 TEST(Run_Wasm_F32UConvertI64) { |
| 3189 WasmRunner<float> r(MachineType::Uint64()); |
| 3190 BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0))); |
| 3191 FOR_UINT64_INPUTS(i) { CHECK_EQ(static_cast<float>(*i), r.Call(*i)); } |
| 3192 } |
| 3193 #endif |
| 3194 |
| 3195 |
| 3196 TEST(Run_Wasm_F64SConvertI64) { |
| 3197 WasmRunner<double> r(MachineType::Int64()); |
| 3198 BUILD(r, WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0))); |
| 3199 FOR_INT64_INPUTS(i) { CHECK_EQ(static_cast<double>(*i), r.Call(*i)); } |
| 3200 } |
| 3201 |
| 3202 |
| 3203 #if !defined(_WIN64) |
| 3204 // TODO(ahaas): Fix this failure. |
| 3205 TEST(Run_Wasm_F64UConvertI64) { |
| 3206 WasmRunner<double> r(MachineType::Uint64()); |
| 3207 BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0))); |
| 3208 FOR_UINT64_INPUTS(i) { CHECK_EQ(static_cast<double>(*i), r.Call(*i)); } |
| 3209 } |
| 3210 #endif |
| 3211 |
| 3212 |
3179 TEST(Run_Wasm_I64SConvertF32) { | 3213 TEST(Run_Wasm_I64SConvertF32) { |
3180 WasmRunner<int64_t> r(MachineType::Float32()); | 3214 WasmRunner<int64_t> r(MachineType::Float32()); |
3181 BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0))); | 3215 BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0))); |
3182 | 3216 |
3183 FOR_FLOAT32_INPUTS(i) { | 3217 FOR_FLOAT32_INPUTS(i) { |
3184 if (*i < static_cast<float>(INT64_MAX) && | 3218 if (*i < static_cast<float>(INT64_MAX) && |
3185 *i >= static_cast<float>(INT64_MIN)) { | 3219 *i >= static_cast<float>(INT64_MIN)) { |
3186 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); | 3220 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); |
3187 } else { | 3221 } else { |
3188 CHECK_TRAP64(r.Call(*i)); | 3222 CHECK_TRAP64(r.Call(*i)); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3356 | 3390 |
3357 #if WASM_64 | 3391 #if WASM_64 |
3358 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 3392 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } |
3359 #endif | 3393 #endif |
3360 | 3394 |
3361 | 3395 |
3362 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } | 3396 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } |
3363 | 3397 |
3364 | 3398 |
3365 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } | 3399 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } |
OLD | NEW |