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

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

Issue 1804513002: [wasm] Int64Lowering of I64Div and I64Rem. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months 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
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/wasm/wasm-macro-gen.h" 9 #include "src/wasm/wasm-macro-gen.h"
10 10
11 #include "test/cctest/cctest.h" 11 #include "test/cctest/cctest.h"
12 #include "test/cctest/compiler/value-helper.h" 12 #include "test/cctest/compiler/value-helper.h"
13 #include "test/cctest/wasm/wasm-run-utils.h" 13 #include "test/cctest/wasm/wasm-run-utils.h"
14 14
15 // using namespace v8::base; 15 #define CHECK_TRAP32(x) \
16 // using namespace v8::internal; 16 CHECK_EQ(0xdeadbeef, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF)
17 // using namespace v8::internal::compiler; 17 #define CHECK_TRAP64(x) \
18 // using namespace v8::internal::wasm; 18 CHECK_EQ(0xdeadbeefdeadbeef, (bit_cast<uint64_t>(x)) & 0xFFFFFFFFFFFFFFFF)
19 #define CHECK_TRAP(x) CHECK_TRAP32(x)
20
21 #define asi64(x) static_cast<int64_t>(x)
22
23 #define asu64(x) static_cast<uint64_t>(x)
19 24
20 // todo(ahaas): I added a list of missing instructions here to make merging 25 // todo(ahaas): I added a list of missing instructions here to make merging
21 // easier when I do them one by one. 26 // easier when I do them one by one.
22 // kExprI64Add: 27 // kExprI64Add:
23 // kExprI64Sub: 28 // kExprI64Sub:
24 // kExprI64Mul: 29 // kExprI64Mul:
25 // kExprI64DivS: 30 // kExprI64DivS:
31
32 TEST(Run_WasmI64DivS) {
33 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
34 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
35 FOR_INT64_INPUTS(i) {
36 FOR_INT64_INPUTS(j) {
37 if (*j == 0) {
38 CHECK_TRAP64(r.Call(*i, *j));
39 } else if (*j == -1 && *i == std::numeric_limits<int64_t>::min()) {
40 CHECK_TRAP64(r.Call(*i, *j));
41 } else {
42 CHECK_EQ(*i / *j, r.Call(*i, *j));
43 }
44 }
45 }
46 }
47
48 TEST(Run_WasmI64DivS_Trap) {
49 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
50 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
51 CHECK_EQ(0, r.Call(asi64(0), asi64(100)));
52 CHECK_TRAP64(r.Call(asi64(100), asi64(0)));
53 CHECK_TRAP64(r.Call(asi64(-1001), asi64(0)));
54 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(-1)));
55 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0)));
56 }
57
58 TEST(Run_WasmI64DivS_Byzero_Const) {
59 for (int8_t denom = -2; denom < 8; denom++) {
60 WasmRunner<int64_t> r(MachineType::Int64());
61 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
62 for (int64_t val = -7; val < 8; val++) {
63 if (denom == 0) {
64 CHECK_TRAP64(r.Call(val));
65 } else {
66 CHECK_EQ(val / denom, r.Call(val));
67 }
68 }
69 }
70 }
26 // kExprI64DivU: 71 // kExprI64DivU:
72
73 TEST(Run_WasmI64DivU) {
74 WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
75 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
76 FOR_UINT64_INPUTS(i) {
77 FOR_UINT64_INPUTS(j) {
78 if (*j == 0) {
79 CHECK_TRAP64(r.Call(*i, *j));
80 } else {
81 CHECK_EQ(*i / *j, r.Call(*i, *j));
82 }
83 }
84 }
85 }
86
87 TEST(Run_WasmI64DivU_Trap) {
88 WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
89 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
90 CHECK_EQ(0, r.Call(asu64(0), asu64(100)));
91 CHECK_TRAP64(r.Call(asu64(100), asu64(0)));
92 CHECK_TRAP64(r.Call(asu64(1001), asu64(0)));
93 CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
94 }
95
96 TEST(Run_WasmI64DivU_Byzero_Const) {
97 for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) {
98 WasmRunner<uint64_t> r(MachineType::Uint64());
99 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
100
101 for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) {
102 if (denom == 0) {
103 CHECK_TRAP64(r.Call(val));
104 } else {
105 CHECK_EQ(val / denom, r.Call(val));
106 }
107 }
108 }
109 }
27 // kExprI64RemS: 110 // kExprI64RemS:
111 TEST(Run_WasmI64RemS) {
112 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
113 BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
114 FOR_INT64_INPUTS(i) {
115 FOR_INT64_INPUTS(j) {
116 if (*j == 0) {
117 CHECK_TRAP64(r.Call(*i, *j));
118 } else {
119 CHECK_EQ(*i % *j, r.Call(*i, *j));
120 }
121 }
122 }
123 }
124
125 TEST(Run_WasmI64RemS_Trap) {
126 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
127 BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
128 CHECK_EQ(33, r.Call(asi64(133), asi64(100)));
129 CHECK_EQ(0, r.Call(std::numeric_limits<int64_t>::min(), asi64(-1)));
130 CHECK_TRAP64(r.Call(asi64(100), asi64(0)));
131 CHECK_TRAP64(r.Call(asi64(-1001), asi64(0)));
132 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0)));
133 }
134
28 // kExprI64RemU: 135 // kExprI64RemU:
136 TEST(Run_WasmI64RemU) {
137 WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
138 BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
139 FOR_UINT64_INPUTS(i) {
140 FOR_UINT64_INPUTS(j) {
141 if (*j == 0) {
142 CHECK_TRAP64(r.Call(*i, *j));
143 } else {
144 CHECK_EQ(*i % *j, r.Call(*i, *j));
145 }
146 }
147 }
148 }
149
150 TEST(Run_Wasm_I64RemU_Trap) {
151 WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
152 BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
153 CHECK_EQ(17, r.Call(asu64(217), asu64(100)));
154 CHECK_TRAP64(r.Call(asu64(100), asu64(0)));
155 CHECK_TRAP64(r.Call(asu64(1001), asu64(0)));
156 CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
157 }
158
29 // kExprI64And: 159 // kExprI64And:
30 TEST(Run_WasmI64And) { 160 TEST(Run_WasmI64And) {
31 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); 161 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
32 BUILD(r, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 162 BUILD(r, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
33 FOR_INT64_INPUTS(i) { 163 FOR_INT64_INPUTS(i) {
34 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) & (*j), r.Call(*i, *j)); } 164 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) & (*j), r.Call(*i, *j)); }
35 } 165 }
36 } 166 }
37 // kExprI64Ior: 167 // kExprI64Ior:
38 TEST(Run_WasmI64Ior) { 168 TEST(Run_WasmI64Ior) {
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 WASM_I64V_10(0xbcd1234000000013), WASM_I64V_10(0xbcd1234000000014), 661 WASM_I64V_10(0xbcd1234000000013), WASM_I64V_10(0xbcd1234000000014),
532 WASM_I64V_10(0xbcd1234000000015), WASM_I64V_10(0xbcd1234000000016), 662 WASM_I64V_10(0xbcd1234000000015), WASM_I64V_10(0xbcd1234000000016),
533 WASM_I64V_10(0xbcd1234000000017), WASM_I64V_10(0xbcd1234000000018), 663 WASM_I64V_10(0xbcd1234000000017), WASM_I64V_10(0xbcd1234000000018),
534 WASM_I64V_10(0xbcd1234000000019), WASM_I64V_10(0xbcd123400000001a), 664 WASM_I64V_10(0xbcd1234000000019), WASM_I64V_10(0xbcd123400000001a),
535 WASM_I64V_10(0xbcd123400000001b), WASM_I64V_10(0xbcd123400000001c), 665 WASM_I64V_10(0xbcd123400000001b), WASM_I64V_10(0xbcd123400000001c),
536 WASM_I64V_10(0xbcd123400000001d)))); 666 WASM_I64V_10(0xbcd123400000001d))));
537 667
538 CHECK_EQ(i + 0xb, r.Call()); 668 CHECK_EQ(i + 0xb, r.Call());
539 } 669 }
540 } 670 }
OLDNEW
« src/compiler/wasm-compiler.cc ('K') | « test/cctest/wasm/test-run-wasm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698