Line data Source code
1 : // Copyright 2014 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "test/cctest/compiler/codegen-tester.h"
6 :
7 : #include "src/base/overflowing-math.h"
8 : #include "src/objects-inl.h"
9 : #include "test/cctest/cctest.h"
10 : #include "test/cctest/compiler/value-helper.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 : namespace compiler {
15 :
16 26643 : TEST(CompareWrapper) {
17 : // Who tests the testers?
18 : // If CompareWrapper is broken, then test expectations will be broken.
19 : CompareWrapper wWord32Equal(IrOpcode::kWord32Equal);
20 : CompareWrapper wInt32LessThan(IrOpcode::kInt32LessThan);
21 : CompareWrapper wInt32LessThanOrEqual(IrOpcode::kInt32LessThanOrEqual);
22 : CompareWrapper wUint32LessThan(IrOpcode::kUint32LessThan);
23 : CompareWrapper wUint32LessThanOrEqual(IrOpcode::kUint32LessThanOrEqual);
24 :
25 468 : FOR_INT32_INPUTS(a) {
26 27144 : FOR_INT32_INPUTS(b) {
27 13456 : CHECK_EQ(a == b, wWord32Equal.Int32Compare(a, b));
28 13456 : CHECK_EQ(a < b, wInt32LessThan.Int32Compare(a, b));
29 13456 : CHECK_EQ(a <= b, wInt32LessThanOrEqual.Int32Compare(a, b));
30 : }
31 : }
32 :
33 468 : FOR_UINT32_INPUTS(a) {
34 27144 : FOR_UINT32_INPUTS(b) {
35 13456 : CHECK_EQ(a == b, wWord32Equal.Int32Compare(a, b));
36 13456 : CHECK_EQ(a < b, wUint32LessThan.Int32Compare(a, b));
37 13456 : CHECK_EQ(a <= b, wUint32LessThanOrEqual.Int32Compare(a, b));
38 : }
39 : }
40 :
41 4 : CHECK_EQ(true, wWord32Equal.Int32Compare(0, 0));
42 4 : CHECK_EQ(true, wWord32Equal.Int32Compare(257, 257));
43 4 : CHECK_EQ(true, wWord32Equal.Int32Compare(65539, 65539));
44 4 : CHECK_EQ(true, wWord32Equal.Int32Compare(-1, -1));
45 4 : CHECK_EQ(true, wWord32Equal.Int32Compare(0xFFFFFFFF, 0xFFFFFFFF));
46 :
47 4 : CHECK_EQ(false, wWord32Equal.Int32Compare(0, 1));
48 4 : CHECK_EQ(false, wWord32Equal.Int32Compare(257, 256));
49 4 : CHECK_EQ(false, wWord32Equal.Int32Compare(65539, 65537));
50 4 : CHECK_EQ(false, wWord32Equal.Int32Compare(-1, -2));
51 4 : CHECK_EQ(false, wWord32Equal.Int32Compare(0xFFFFFFFF, 0xFFFFFFFE));
52 :
53 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(0, 0));
54 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(357, 357));
55 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(75539, 75539));
56 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(-1, -1));
57 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(0xFFFFFFFF, 0xFFFFFFFF));
58 :
59 4 : CHECK_EQ(true, wInt32LessThan.Int32Compare(0, 1));
60 4 : CHECK_EQ(true, wInt32LessThan.Int32Compare(456, 457));
61 4 : CHECK_EQ(true, wInt32LessThan.Int32Compare(85537, 85539));
62 4 : CHECK_EQ(true, wInt32LessThan.Int32Compare(-2, -1));
63 4 : CHECK_EQ(true, wInt32LessThan.Int32Compare(0xFFFFFFFE, 0xFFFFFFFF));
64 :
65 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(1, 0));
66 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(457, 456));
67 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(85539, 85537));
68 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(-1, -2));
69 4 : CHECK_EQ(false, wInt32LessThan.Int32Compare(0xFFFFFFFF, 0xFFFFFFFE));
70 :
71 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(0, 0));
72 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(357, 357));
73 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(75539, 75539));
74 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(-1, -1));
75 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(0xFFFFFFFF, 0xFFFFFFFF));
76 :
77 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(0, 1));
78 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(456, 457));
79 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(85537, 85539));
80 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(-2, -1));
81 4 : CHECK_EQ(true, wInt32LessThanOrEqual.Int32Compare(0xFFFFFFFE, 0xFFFFFFFF));
82 :
83 4 : CHECK_EQ(false, wInt32LessThanOrEqual.Int32Compare(1, 0));
84 4 : CHECK_EQ(false, wInt32LessThanOrEqual.Int32Compare(457, 456));
85 4 : CHECK_EQ(false, wInt32LessThanOrEqual.Int32Compare(85539, 85537));
86 4 : CHECK_EQ(false, wInt32LessThanOrEqual.Int32Compare(-1, -2));
87 4 : CHECK_EQ(false, wInt32LessThanOrEqual.Int32Compare(0xFFFFFFFF, 0xFFFFFFFE));
88 :
89 : // Unsigned comparisons.
90 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(0, 0));
91 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(357, 357));
92 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(75539, 75539));
93 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(-1, -1));
94 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(0xFFFFFFFF, 0xFFFFFFFF));
95 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(0xFFFFFFFF, 0));
96 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(-2999, 0));
97 :
98 4 : CHECK_EQ(true, wUint32LessThan.Int32Compare(0, 1));
99 4 : CHECK_EQ(true, wUint32LessThan.Int32Compare(456, 457));
100 4 : CHECK_EQ(true, wUint32LessThan.Int32Compare(85537, 85539));
101 4 : CHECK_EQ(true, wUint32LessThan.Int32Compare(-11, -10));
102 4 : CHECK_EQ(true, wUint32LessThan.Int32Compare(0xFFFFFFFE, 0xFFFFFFFF));
103 4 : CHECK_EQ(true, wUint32LessThan.Int32Compare(0, 0xFFFFFFFF));
104 4 : CHECK_EQ(true, wUint32LessThan.Int32Compare(0, -2996));
105 :
106 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(1, 0));
107 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(457, 456));
108 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(85539, 85537));
109 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(-10, -21));
110 4 : CHECK_EQ(false, wUint32LessThan.Int32Compare(0xFFFFFFFF, 0xFFFFFFFE));
111 :
112 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(0, 0));
113 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(357, 357));
114 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(75539, 75539));
115 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(-1, -1));
116 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(0xFFFFFFFF, 0xFFFFFFFF));
117 :
118 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(0, 1));
119 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(456, 457));
120 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(85537, 85539));
121 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(-300, -299));
122 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(-300, -300));
123 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(0xFFFFFFFE, 0xFFFFFFFF));
124 4 : CHECK_EQ(true, wUint32LessThanOrEqual.Int32Compare(0, -2995));
125 :
126 4 : CHECK_EQ(false, wUint32LessThanOrEqual.Int32Compare(1, 0));
127 4 : CHECK_EQ(false, wUint32LessThanOrEqual.Int32Compare(457, 456));
128 4 : CHECK_EQ(false, wUint32LessThanOrEqual.Int32Compare(85539, 85537));
129 4 : CHECK_EQ(false, wUint32LessThanOrEqual.Int32Compare(-130, -170));
130 4 : CHECK_EQ(false, wUint32LessThanOrEqual.Int32Compare(0xFFFFFFFF, 0xFFFFFFFE));
131 4 : CHECK_EQ(false, wUint32LessThanOrEqual.Int32Compare(-2997, 0));
132 :
133 : CompareWrapper wFloat64Equal(IrOpcode::kFloat64Equal);
134 : CompareWrapper wFloat64LessThan(IrOpcode::kFloat64LessThan);
135 : CompareWrapper wFloat64LessThanOrEqual(IrOpcode::kFloat64LessThanOrEqual);
136 :
137 : // Check NaN handling.
138 : double nan = std::numeric_limits<double>::quiet_NaN();
139 : double inf = V8_INFINITY;
140 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(nan, 0.0));
141 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(nan, 1.0));
142 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(nan, inf));
143 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(nan, -inf));
144 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(nan, nan));
145 :
146 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(0.0, nan));
147 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(1.0, nan));
148 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(inf, nan));
149 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(-inf, nan));
150 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(nan, nan));
151 :
152 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(nan, 0.0));
153 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(nan, 1.0));
154 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(nan, inf));
155 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(nan, -inf));
156 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(nan, nan));
157 :
158 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(0.0, nan));
159 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(1.0, nan));
160 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(inf, nan));
161 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(-inf, nan));
162 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(nan, nan));
163 :
164 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(nan, 0.0));
165 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(nan, 1.0));
166 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(nan, inf));
167 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(nan, -inf));
168 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(nan, nan));
169 :
170 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(0.0, nan));
171 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(1.0, nan));
172 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(inf, nan));
173 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(-inf, nan));
174 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(nan, nan));
175 :
176 : // Check inf handling.
177 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(inf, 0.0));
178 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(inf, 1.0));
179 4 : CHECK_EQ(true, wFloat64Equal.Float64Compare(inf, inf));
180 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(inf, -inf));
181 :
182 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(0.0, inf));
183 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(1.0, inf));
184 4 : CHECK_EQ(true, wFloat64Equal.Float64Compare(inf, inf));
185 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(-inf, inf));
186 :
187 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(inf, 0.0));
188 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(inf, 1.0));
189 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(inf, inf));
190 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(inf, -inf));
191 :
192 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(0.0, inf));
193 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(1.0, inf));
194 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(inf, inf));
195 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(-inf, inf));
196 :
197 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(inf, 0.0));
198 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(inf, 1.0));
199 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(inf, inf));
200 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(inf, -inf));
201 :
202 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(0.0, inf));
203 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(1.0, inf));
204 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(inf, inf));
205 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(-inf, inf));
206 :
207 : // Check -inf handling.
208 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(-inf, 0.0));
209 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(-inf, 1.0));
210 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(-inf, inf));
211 4 : CHECK_EQ(true, wFloat64Equal.Float64Compare(-inf, -inf));
212 :
213 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(0.0, -inf));
214 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(1.0, -inf));
215 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(inf, -inf));
216 4 : CHECK_EQ(true, wFloat64Equal.Float64Compare(-inf, -inf));
217 :
218 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(-inf, 0.0));
219 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(-inf, 1.0));
220 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(-inf, inf));
221 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(-inf, -inf));
222 :
223 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(0.0, -inf));
224 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(1.0, -inf));
225 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(inf, -inf));
226 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(-inf, -inf));
227 :
228 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(-inf, 0.0));
229 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(-inf, 1.0));
230 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(-inf, inf));
231 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(-inf, -inf));
232 :
233 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(0.0, -inf));
234 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(1.0, -inf));
235 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(inf, -inf));
236 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(-inf, -inf));
237 :
238 : // Check basic values.
239 4 : CHECK_EQ(true, wFloat64Equal.Float64Compare(0, 0));
240 4 : CHECK_EQ(true, wFloat64Equal.Float64Compare(257.1, 257.1));
241 4 : CHECK_EQ(true, wFloat64Equal.Float64Compare(65539.1, 65539.1));
242 4 : CHECK_EQ(true, wFloat64Equal.Float64Compare(-1.1, -1.1));
243 :
244 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(0, 1));
245 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(257.2, 256.2));
246 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(65539.2, 65537.2));
247 4 : CHECK_EQ(false, wFloat64Equal.Float64Compare(-1.2, -2.2));
248 :
249 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(0, 0));
250 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(357.3, 357.3));
251 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(75539.3, 75539.3));
252 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(-1.3, -1.3));
253 :
254 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(0, 1));
255 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(456.4, 457.4));
256 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(85537.4, 85539.4));
257 4 : CHECK_EQ(true, wFloat64LessThan.Float64Compare(-2.4, -1.4));
258 :
259 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(1, 0));
260 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(457.5, 456.5));
261 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(85539.5, 85537.5));
262 4 : CHECK_EQ(false, wFloat64LessThan.Float64Compare(-1.5, -2.5));
263 :
264 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(0, 0));
265 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(357.6, 357.6));
266 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(75539.6, 75539.6));
267 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(-1.6, -1.6));
268 :
269 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(0, 1));
270 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(456.7, 457.7));
271 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(85537.7, 85539.7));
272 4 : CHECK_EQ(true, wFloat64LessThanOrEqual.Float64Compare(-2.7, -1.7));
273 :
274 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(1, 0));
275 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(457.8, 456.8));
276 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(85539.8, 85537.8));
277 4 : CHECK_EQ(false, wFloat64LessThanOrEqual.Float64Compare(-1.8, -2.8));
278 4 : }
279 :
280 :
281 120 : void Int32BinopInputShapeTester::TestAllInputShapes() {
282 : Vector<const int32_t> inputs = ValueHelper::int32_vector();
283 : int num_int_inputs = static_cast<int>(inputs.size());
284 : if (num_int_inputs > 16) num_int_inputs = 16; // limit to 16 inputs
285 :
286 4440 : for (int i = -2; i < num_int_inputs; i++) { // for all left shapes
287 18480 : for (int j = -2; j < num_int_inputs; j++) { // for all right shapes
288 10080 : if (i >= 0 && j >= 0) break; // No constant/constant combos
289 : RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
290 8160 : MachineType::Int32());
291 8160 : Node* p0 = m.Parameter(0);
292 8160 : Node* p1 = m.Parameter(1);
293 : Node* n0;
294 : Node* n1;
295 :
296 : // left = Parameter | Load | Constant
297 8160 : if (i == -2) {
298 : n0 = p0;
299 6000 : } else if (i == -1) {
300 2160 : n0 = m.LoadFromPointer(&input_a, MachineType::Int32());
301 : } else {
302 7680 : n0 = m.Int32Constant(inputs[i]);
303 : }
304 :
305 : // right = Parameter | Load | Constant
306 8160 : if (j == -2) {
307 : n1 = p1;
308 6000 : } else if (j == -1) {
309 2160 : n1 = m.LoadFromPointer(&input_b, MachineType::Int32());
310 : } else {
311 7680 : n1 = m.Int32Constant(inputs[j]);
312 : }
313 :
314 8160 : gen->gen(&m, n0, n1);
315 :
316 8160 : if (i >= 0) {
317 7680 : input_a = inputs[i];
318 3840 : RunRight(&m);
319 4320 : } else if (j >= 0) {
320 7680 : input_b = inputs[j];
321 3840 : RunLeft(&m);
322 : } else {
323 480 : Run(&m);
324 : }
325 : }
326 : }
327 120 : }
328 :
329 :
330 480 : void Int32BinopInputShapeTester::Run(RawMachineAssemblerTester<int32_t>* m) {
331 56160 : FOR_INT32_INPUTS(pl) {
332 3257280 : FOR_INT32_INPUTS(pr) {
333 1614720 : input_a = pl;
334 1614720 : input_b = pr;
335 1614720 : int32_t expect = gen->expected(input_a, input_b);
336 1614720 : CHECK_EQ(expect, m->Call(input_a, input_b));
337 : }
338 : }
339 480 : }
340 :
341 :
342 3840 : void Int32BinopInputShapeTester::RunLeft(
343 : RawMachineAssemblerTester<int32_t>* m) {
344 449280 : FOR_UINT32_INPUTS(i) {
345 222720 : input_a = i;
346 222720 : int32_t expect = gen->expected(input_a, input_b);
347 222720 : CHECK_EQ(expect, m->Call(input_a, input_b));
348 : }
349 3840 : }
350 :
351 :
352 3840 : void Int32BinopInputShapeTester::RunRight(
353 : RawMachineAssemblerTester<int32_t>* m) {
354 449280 : FOR_UINT32_INPUTS(i) {
355 222720 : input_b = i;
356 222720 : int32_t expect = gen->expected(input_a, input_b);
357 222720 : CHECK_EQ(expect, m->Call(input_a, input_b));
358 : }
359 3840 : }
360 :
361 :
362 26643 : TEST(ParametersEqual) {
363 : RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
364 4 : MachineType::Int32());
365 4 : Node* p1 = m.Parameter(1);
366 4 : CHECK(p1);
367 4 : Node* p0 = m.Parameter(0);
368 4 : CHECK(p0);
369 4 : CHECK_EQ(p0, m.Parameter(0));
370 4 : CHECK_EQ(p1, m.Parameter(1));
371 4 : }
372 :
373 :
374 0 : void RunSmiConstant(int32_t v) {
375 : // TODO(dcarney): on x64 Smis are generated with the SmiConstantRegister
376 : #if !V8_TARGET_ARCH_X64
377 : if (Smi::IsValid(v)) {
378 : RawMachineAssemblerTester<Object> m;
379 : m.Return(m.NumberConstant(v));
380 : CHECK_EQ(Smi::FromInt(v), m.Call());
381 : }
382 : #endif
383 0 : }
384 :
385 :
386 956 : void RunNumberConstant(double v) {
387 956 : RawMachineAssemblerTester<Object> m;
388 : #if V8_TARGET_ARCH_X64
389 : // TODO(dcarney): on x64 Smis are generated with the SmiConstantRegister
390 956 : Handle<Object> number = m.isolate()->factory()->NewNumber(v);
391 956 : if (number->IsSmi()) return;
392 : #endif
393 160 : m.Return(m.NumberConstant(v));
394 160 : Object result = m.Call();
395 160 : m.CheckNumber(v, result);
396 : }
397 :
398 :
399 26643 : TEST(RunEmpty) {
400 4 : RawMachineAssemblerTester<int32_t> m;
401 4 : m.Return(m.Int32Constant(0));
402 4 : CHECK_EQ(0, m.Call());
403 4 : }
404 :
405 :
406 26643 : TEST(RunInt32Constants) {
407 468 : FOR_INT32_INPUTS(i) {
408 232 : RawMachineAssemblerTester<int32_t> m;
409 232 : m.Return(m.Int32Constant(i));
410 232 : CHECK_EQ(i, m.Call());
411 : }
412 4 : }
413 :
414 :
415 26643 : TEST(RunSmiConstants) {
416 260 : for (int32_t i = 1; i < Smi::kMaxValue && i != 0;
417 : i = base::ShlWithWraparound(i, 1)) {
418 : RunSmiConstant(i);
419 : RunSmiConstant(base::MulWithWraparound(3, i));
420 : RunSmiConstant(base::MulWithWraparound(5, i));
421 : RunSmiConstant(base::NegateWithWraparound(i));
422 : RunSmiConstant(i | 1);
423 : RunSmiConstant(i | 3);
424 : }
425 : RunSmiConstant(Smi::kMaxValue);
426 : RunSmiConstant(Smi::kMaxValue - 1);
427 : RunSmiConstant(Smi::kMinValue);
428 : RunSmiConstant(Smi::kMinValue + 1);
429 :
430 : FOR_INT32_INPUTS(i) { RunSmiConstant(i); }
431 4 : }
432 :
433 26643 : TEST(RunNumberConstants) {
434 200 : FOR_FLOAT64_INPUTS(i) { RunNumberConstant(i); }
435 236 : FOR_INT32_INPUTS(i) { RunNumberConstant(i); }
436 :
437 260 : for (int32_t i = 1; i < Smi::kMaxValue && i != 0;
438 : i = base::ShlWithWraparound(i, 1)) {
439 128 : RunNumberConstant(i);
440 128 : RunNumberConstant(base::NegateWithWraparound(i));
441 128 : RunNumberConstant(i | 1);
442 128 : RunNumberConstant(i | 3);
443 : }
444 4 : RunNumberConstant(Smi::kMaxValue);
445 4 : RunNumberConstant(Smi::kMaxValue - 1);
446 4 : RunNumberConstant(Smi::kMinValue);
447 4 : RunNumberConstant(Smi::kMinValue + 1);
448 4 : }
449 :
450 26643 : TEST(RunEmptyString) {
451 4 : RawMachineAssemblerTester<Object> m;
452 4 : m.Return(m.StringConstant("empty"));
453 4 : m.CheckString("empty", m.Call());
454 4 : }
455 :
456 :
457 26643 : TEST(RunHeapConstant) {
458 4 : RawMachineAssemblerTester<Object> m;
459 4 : m.Return(m.StringConstant("empty"));
460 4 : m.CheckString("empty", m.Call());
461 4 : }
462 :
463 :
464 26643 : TEST(RunHeapNumberConstant) {
465 4 : RawMachineAssemblerTester<void*> m;
466 4 : Handle<HeapObject> number = m.isolate()->factory()->NewHeapNumber(100.5);
467 4 : m.Return(m.HeapConstant(number));
468 : HeapObject result =
469 4 : HeapObject::cast(Object(reinterpret_cast<Address>(m.Call())));
470 4 : CHECK_EQ(result, *number);
471 4 : }
472 :
473 :
474 26643 : TEST(RunParam1) {
475 4 : RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
476 4 : m.Return(m.Parameter(0));
477 :
478 468 : FOR_INT32_INPUTS(i) {
479 232 : int32_t result = m.Call(i);
480 232 : CHECK_EQ(i, result);
481 : }
482 4 : }
483 :
484 :
485 26643 : TEST(RunParam2_1) {
486 : RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
487 4 : MachineType::Int32());
488 4 : Node* p0 = m.Parameter(0);
489 4 : Node* p1 = m.Parameter(1);
490 4 : m.Return(p0);
491 : USE(p1);
492 :
493 468 : FOR_INT32_INPUTS(i) {
494 232 : int32_t result = m.Call(i, -9999);
495 232 : CHECK_EQ(i, result);
496 : }
497 4 : }
498 :
499 :
500 26643 : TEST(RunParam2_2) {
501 : RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
502 4 : MachineType::Int32());
503 4 : Node* p0 = m.Parameter(0);
504 4 : Node* p1 = m.Parameter(1);
505 4 : m.Return(p1);
506 : USE(p0);
507 :
508 468 : FOR_INT32_INPUTS(i) {
509 232 : int32_t result = m.Call(-7777, i);
510 232 : CHECK_EQ(i, result);
511 : }
512 4 : }
513 :
514 :
515 26643 : TEST(RunParam3) {
516 28 : for (int i = 0; i < 3; i++) {
517 : RawMachineAssemblerTester<int32_t> m(
518 12 : MachineType::Int32(), MachineType::Int32(), MachineType::Int32());
519 12 : Node* nodes[] = {m.Parameter(0), m.Parameter(1), m.Parameter(2)};
520 12 : m.Return(nodes[i]);
521 :
522 12 : int p[] = {-99, -77, -88};
523 1404 : FOR_INT32_INPUTS(j) {
524 696 : p[i] = j;
525 696 : int32_t result = m.Call(p[0], p[1], p[2]);
526 696 : CHECK_EQ(j, result);
527 : }
528 : }
529 4 : }
530 :
531 :
532 26643 : TEST(RunBinopTester) {
533 : {
534 4 : RawMachineAssemblerTester<int32_t> m;
535 : Int32BinopTester bt(&m);
536 4 : bt.AddReturn(bt.param0);
537 :
538 468 : FOR_INT32_INPUTS(i) { CHECK_EQ(i, bt.call(i, 777)); }
539 : }
540 :
541 : {
542 4 : RawMachineAssemblerTester<int32_t> m;
543 : Int32BinopTester bt(&m);
544 4 : bt.AddReturn(bt.param1);
545 :
546 468 : FOR_INT32_INPUTS(i) { CHECK_EQ(i, bt.call(666, i)); }
547 : }
548 :
549 : {
550 4 : RawMachineAssemblerTester<int32_t> m;
551 : Float64BinopTester bt(&m);
552 4 : bt.AddReturn(bt.param0);
553 :
554 396 : FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(i, bt.call(i, 9.0)); }
555 : }
556 :
557 : {
558 4 : RawMachineAssemblerTester<int32_t> m;
559 : Float64BinopTester bt(&m);
560 4 : bt.AddReturn(bt.param1);
561 :
562 396 : FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(i, bt.call(-11.25, i)); }
563 : }
564 4 : }
565 :
566 :
567 : #if V8_TARGET_ARCH_64_BIT
568 : // TODO(ahaas): run int64 tests on all platforms when supported.
569 :
570 : namespace {
571 :
572 : int64_t Add4(int64_t a, int64_t b, int64_t c, int64_t d) {
573 : // Operate on uint64_t values to avoid undefined behavior.
574 : return static_cast<int64_t>(
575 262440 : static_cast<uint64_t>(a) + static_cast<uint64_t>(b) +
576 262440 : static_cast<uint64_t>(c) + static_cast<uint64_t>(d));
577 : }
578 :
579 : int64_t Add3(int64_t a, int64_t b, int64_t c) { return Add4(a, b, c, 0); }
580 :
581 : } // namespace
582 :
583 26643 : TEST(RunBufferedRawMachineAssemblerTesterTester) {
584 : {
585 4 : BufferedRawMachineAssemblerTester<int64_t> m;
586 4 : m.Return(m.Int64Constant(0x12500000000));
587 4 : CHECK_EQ(0x12500000000, m.Call());
588 : }
589 : {
590 4 : BufferedRawMachineAssemblerTester<double> m(MachineType::Float64());
591 4 : m.Return(m.Parameter(0));
592 396 : FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(i, m.Call(i)); }
593 : }
594 : {
595 : BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Int64(),
596 4 : MachineType::Int64());
597 4 : m.Return(m.Int64Add(m.Parameter(0), m.Parameter(1)));
598 652 : FOR_INT64_INPUTS(i) {
599 52812 : FOR_INT64_INPUTS(j) {
600 52488 : CHECK_EQ(base::AddWithWraparound(i, j), m.Call(i, j));
601 26244 : CHECK_EQ(base::AddWithWraparound(j, i), m.Call(j, i));
602 : }
603 : }
604 : }
605 : {
606 : BufferedRawMachineAssemblerTester<int64_t> m(
607 4 : MachineType::Int64(), MachineType::Int64(), MachineType::Int64());
608 4 : m.Return(
609 4 : m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2)));
610 652 : FOR_INT64_INPUTS(i) {
611 52812 : FOR_INT64_INPUTS(j) {
612 52488 : CHECK_EQ(Add3(i, i, j), m.Call(i, i, j));
613 52488 : CHECK_EQ(Add3(i, j, i), m.Call(i, j, i));
614 26244 : CHECK_EQ(Add3(j, i, i), m.Call(j, i, i));
615 : }
616 : }
617 : }
618 : {
619 : BufferedRawMachineAssemblerTester<int64_t> m(
620 : MachineType::Int64(), MachineType::Int64(), MachineType::Int64(),
621 4 : MachineType::Int64());
622 4 : m.Return(m.Int64Add(
623 : m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2)),
624 4 : m.Parameter(3)));
625 652 : FOR_INT64_INPUTS(i) {
626 52812 : FOR_INT64_INPUTS(j) {
627 52488 : CHECK_EQ(Add4(i, i, i, j), m.Call(i, i, i, j));
628 52488 : CHECK_EQ(Add4(i, i, j, i), m.Call(i, i, j, i));
629 52488 : CHECK_EQ(Add4(i, j, i, i), m.Call(i, j, i, i));
630 26244 : CHECK_EQ(Add4(j, i, i, i), m.Call(j, i, i, i));
631 : }
632 : }
633 : }
634 : {
635 4 : BufferedRawMachineAssemblerTester<void> m;
636 : int64_t result;
637 4 : m.Store(MachineTypeForC<int64_t>().representation(),
638 : m.PointerConstant(&result), m.Int64Constant(0x12500000000),
639 4 : kNoWriteBarrier);
640 4 : m.Return(m.Int32Constant(0));
641 : m.Call();
642 4 : CHECK_EQ(0x12500000000, result);
643 : }
644 : {
645 4 : BufferedRawMachineAssemblerTester<void> m(MachineType::Float64());
646 : double result;
647 : m.Store(MachineTypeForC<double>().representation(),
648 4 : m.PointerConstant(&result), m.Parameter(0), kNoWriteBarrier);
649 4 : m.Return(m.Int32Constant(0));
650 396 : FOR_FLOAT64_INPUTS(i) {
651 : m.Call(i);
652 392 : CHECK_DOUBLE_EQ(i, result);
653 : }
654 : }
655 : {
656 : BufferedRawMachineAssemblerTester<void> m(MachineType::Int64(),
657 4 : MachineType::Int64());
658 : int64_t result;
659 4 : m.Store(MachineTypeForC<int64_t>().representation(),
660 : m.PointerConstant(&result),
661 4 : m.Int64Add(m.Parameter(0), m.Parameter(1)), kNoWriteBarrier);
662 4 : m.Return(m.Int32Constant(0));
663 652 : FOR_INT64_INPUTS(i) {
664 52812 : FOR_INT64_INPUTS(j) {
665 : m.Call(i, j);
666 52488 : CHECK_EQ(base::AddWithWraparound(i, j), result);
667 :
668 : m.Call(j, i);
669 26244 : CHECK_EQ(base::AddWithWraparound(j, i), result);
670 : }
671 : }
672 : }
673 : {
674 : BufferedRawMachineAssemblerTester<void> m(
675 4 : MachineType::Int64(), MachineType::Int64(), MachineType::Int64());
676 : int64_t result;
677 4 : m.Store(
678 : MachineTypeForC<int64_t>().representation(), m.PointerConstant(&result),
679 : m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2)),
680 4 : kNoWriteBarrier);
681 4 : m.Return(m.Int32Constant(0));
682 652 : FOR_INT64_INPUTS(i) {
683 52812 : FOR_INT64_INPUTS(j) {
684 : m.Call(i, i, j);
685 52488 : CHECK_EQ(Add3(i, i, j), result);
686 :
687 : m.Call(i, j, i);
688 52488 : CHECK_EQ(Add3(i, j, i), result);
689 :
690 : m.Call(j, i, i);
691 26244 : CHECK_EQ(Add3(j, i, i), result);
692 : }
693 : }
694 : }
695 : {
696 : BufferedRawMachineAssemblerTester<void> m(
697 : MachineType::Int64(), MachineType::Int64(), MachineType::Int64(),
698 4 : MachineType::Int64());
699 : int64_t result;
700 4 : m.Store(MachineTypeForC<int64_t>().representation(),
701 : m.PointerConstant(&result),
702 : m.Int64Add(m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)),
703 : m.Parameter(2)),
704 : m.Parameter(3)),
705 4 : kNoWriteBarrier);
706 4 : m.Return(m.Int32Constant(0));
707 652 : FOR_INT64_INPUTS(i) {
708 52812 : FOR_INT64_INPUTS(j) {
709 : m.Call(i, i, i, j);
710 52488 : CHECK_EQ(Add4(i, i, i, j), result);
711 :
712 : m.Call(i, i, j, i);
713 52488 : CHECK_EQ(Add4(i, i, j, i), result);
714 :
715 : m.Call(i, j, i, i);
716 52488 : CHECK_EQ(Add4(i, j, i, i), result);
717 :
718 : m.Call(j, i, i, i);
719 26244 : CHECK_EQ(Add4(j, i, i, i), result);
720 : }
721 : }
722 : }
723 4 : }
724 :
725 : #endif
726 : } // namespace compiler
727 : } // namespace internal
728 79917 : } // namespace v8
|