OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 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 "test/unittests/compiler/instruction-selector-unittest.h" | 5 #include "test/unittests/compiler/instruction-selector-unittest.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace compiler { | 9 namespace compiler { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 // Immediates (random subset). | 13 // Immediates (random subset). |
14 static const int32_t kImmediates[] = { | 14 static const int32_t kImmediates[] = { |
15 kMinInt, -42, -1, 0, 1, 2, 3, 4, 5, | 15 kMinInt, -42, -1, 0, 1, 2, 3, 4, 5, |
16 6, 7, 8, 16, 42, 0xff, 0xffff, 0x0f0f0f0f, kMaxInt}; | 16 6, 7, 8, 16, 42, 0xff, 0xffff, 0x0f0f0f0f, kMaxInt}; |
17 | 17 |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 | 20 |
21 TEST_F(InstructionSelectorTest, Int32AddWithParameter) { | 21 TEST_F(InstructionSelectorTest, Int32AddWithParameter) { |
22 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); | 22 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
23 m.Return(m.Int32Add(m.Parameter(0), m.Parameter(1))); | 23 m.Return(m.Int32Add(m.Parameter(0), m.Parameter(1))); |
24 Stream s = m.Build(); | 24 Stream s = m.Build(); |
25 ASSERT_EQ(1U, s.size()); | 25 ASSERT_EQ(1U, s.size()); |
26 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); | 26 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); |
27 } | 27 } |
28 | 28 |
29 | 29 |
30 TEST_F(InstructionSelectorTest, Int32AddWithImmediate) { | 30 TEST_F(InstructionSelectorTest, Int32AddWithImmediate) { |
31 TRACED_FOREACH(int32_t, imm, kImmediates) { | 31 TRACED_FOREACH(int32_t, imm, kImmediates) { |
32 { | 32 { |
33 StreamBuilder m(this, kMachInt32, kMachInt32); | 33 StreamBuilder m(this, kMachInt32, kMachInt32); |
34 m.Return(m.Int32Add(m.Parameter(0), m.Int32Constant(imm))); | 34 m.Return(m.Int32Add(m.Parameter(0), m.Int32Constant(imm))); |
35 Stream s = m.Build(); | 35 Stream s = m.Build(); |
36 ASSERT_EQ(1U, s.size()); | 36 ASSERT_EQ(1U, s.size()); |
37 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); | 37 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); |
38 ASSERT_EQ(2U, s[0]->InputCount()); | 38 if (imm == 0) { |
39 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); | 39 ASSERT_EQ(1U, s[0]->InputCount()); |
| 40 } else { |
| 41 ASSERT_EQ(2U, s[0]->InputCount()); |
| 42 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 43 } |
40 } | 44 } |
41 { | 45 { |
42 StreamBuilder m(this, kMachInt32, kMachInt32); | 46 StreamBuilder m(this, kMachInt32, kMachInt32); |
43 m.Return(m.Int32Add(m.Int32Constant(imm), m.Parameter(0))); | 47 m.Return(m.Int32Add(m.Int32Constant(imm), m.Parameter(0))); |
44 Stream s = m.Build(); | 48 Stream s = m.Build(); |
45 ASSERT_EQ(1U, s.size()); | 49 ASSERT_EQ(1U, s.size()); |
46 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); | 50 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); |
47 ASSERT_EQ(2U, s[0]->InputCount()); | 51 if (imm == 0) { |
48 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); | 52 ASSERT_EQ(1U, s[0]->InputCount()); |
| 53 } else { |
| 54 ASSERT_EQ(2U, s[0]->InputCount()); |
| 55 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 56 } |
49 } | 57 } |
50 } | 58 } |
51 } | 59 } |
52 | 60 |
53 | 61 |
54 TEST_F(InstructionSelectorTest, Int32SubWithParameter) { | 62 TEST_F(InstructionSelectorTest, Int32SubWithParameter) { |
55 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); | 63 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
56 m.Return(m.Int32Sub(m.Parameter(0), m.Parameter(1))); | 64 m.Return(m.Int32Sub(m.Parameter(0), m.Parameter(1))); |
57 Stream s = m.Build(); | 65 Stream s = m.Build(); |
58 ASSERT_EQ(1U, s.size()); | 66 ASSERT_EQ(1U, s.size()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 113 |
106 | 114 |
107 TEST_F(InstructionSelectorTest, BetterLeftOperandTestAddBinop) { | 115 TEST_F(InstructionSelectorTest, BetterLeftOperandTestAddBinop) { |
108 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); | 116 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
109 Node* param1 = m.Parameter(0); | 117 Node* param1 = m.Parameter(0); |
110 Node* param2 = m.Parameter(1); | 118 Node* param2 = m.Parameter(1); |
111 Node* add = m.Int32Add(param1, param2); | 119 Node* add = m.Int32Add(param1, param2); |
112 m.Return(m.Int32Add(add, param1)); | 120 m.Return(m.Int32Add(add, param1)); |
113 Stream s = m.Build(); | 121 Stream s = m.Build(); |
114 ASSERT_EQ(2U, s.size()); | 122 ASSERT_EQ(2U, s.size()); |
115 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); | 123 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); |
116 ASSERT_EQ(2U, s[0]->InputCount()); | 124 ASSERT_EQ(2U, s[0]->InputCount()); |
117 ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated()); | 125 ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated()); |
118 EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(0))); | 126 EXPECT_EQ(s.ToVreg(param1), s.ToVreg(s[0]->InputAt(0))); |
| 127 EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(1))); |
| 128 ASSERT_EQ(2U, s[1]->InputCount()); |
| 129 EXPECT_EQ(s.ToVreg(param1), s.ToVreg(s[0]->InputAt(0))); |
119 } | 130 } |
120 | 131 |
121 | 132 |
122 TEST_F(InstructionSelectorTest, BetterLeftOperandTestMulBinop) { | 133 TEST_F(InstructionSelectorTest, BetterLeftOperandTestMulBinop) { |
123 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); | 134 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
124 Node* param1 = m.Parameter(0); | 135 Node* param1 = m.Parameter(0); |
125 Node* param2 = m.Parameter(1); | 136 Node* param2 = m.Parameter(1); |
126 Node* mul = m.Int32Mul(param1, param2); | 137 Node* mul = m.Int32Mul(param1, param2); |
127 m.Return(m.Int32Mul(mul, param1)); | 138 m.Return(m.Int32Mul(mul, param1)); |
128 Stream s = m.Build(); | 139 Stream s = m.Build(); |
129 ASSERT_EQ(2U, s.size()); | 140 ASSERT_EQ(2U, s.size()); |
130 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode()); | 141 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode()); |
131 ASSERT_EQ(2U, s[0]->InputCount()); | 142 ASSERT_EQ(2U, s[0]->InputCount()); |
132 ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated()); | 143 ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated()); |
133 EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(0))); | 144 EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(0))); |
| 145 EXPECT_EQ(s.ToVreg(param1), s.ToVreg(s[0]->InputAt(1))); |
134 } | 146 } |
135 | 147 |
136 | 148 |
137 // ----------------------------------------------------------------------------- | 149 // ----------------------------------------------------------------------------- |
138 // Conversions. | 150 // Conversions. |
139 | 151 |
140 | 152 |
141 TEST_F(InstructionSelectorTest, ChangeUint32ToFloat64WithParameter) { | 153 TEST_F(InstructionSelectorTest, ChangeUint32ToFloat64WithParameter) { |
142 StreamBuilder m(this, kMachFloat64, kMachUint32); | 154 StreamBuilder m(this, kMachFloat64, kMachUint32); |
143 m.Return(m.ChangeUint32ToFloat64(m.Parameter(0))); | 155 m.Return(m.ChangeUint32ToFloat64(m.Parameter(0))); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 309 |
298 // ----------------------------------------------------------------------------- | 310 // ----------------------------------------------------------------------------- |
299 // AddressingMode for loads and stores. | 311 // AddressingMode for loads and stores. |
300 | 312 |
301 | 313 |
302 class AddressingModeUnitTest : public InstructionSelectorTest { | 314 class AddressingModeUnitTest : public InstructionSelectorTest { |
303 public: | 315 public: |
304 AddressingModeUnitTest() : m(NULL) { Reset(); } | 316 AddressingModeUnitTest() : m(NULL) { Reset(); } |
305 ~AddressingModeUnitTest() { delete m; } | 317 ~AddressingModeUnitTest() { delete m; } |
306 | 318 |
307 void Run(Node* base, Node* index, AddressingMode mode) { | 319 void Run(Node* base, Node* load_index, Node* store_index, |
308 Node* load = m->Load(kMachInt32, base, index); | 320 AddressingMode mode) { |
309 m->Store(kMachInt32, base, index, load); | 321 Node* load = m->Load(kMachInt32, base, load_index); |
| 322 m->Store(kMachInt32, base, store_index, load); |
310 m->Return(m->Int32Constant(0)); | 323 m->Return(m->Int32Constant(0)); |
311 Stream s = m->Build(); | 324 Stream s = m->Build(); |
312 ASSERT_EQ(2U, s.size()); | 325 ASSERT_EQ(2U, s.size()); |
313 EXPECT_EQ(mode, s[0]->addressing_mode()); | 326 EXPECT_EQ(mode, s[0]->addressing_mode()); |
314 EXPECT_EQ(mode, s[1]->addressing_mode()); | 327 EXPECT_EQ(mode, s[1]->addressing_mode()); |
315 } | 328 } |
316 | 329 |
317 Node* zero; | 330 Node* zero; |
318 Node* null_ptr; | 331 Node* null_ptr; |
319 Node* non_zero; | 332 Node* non_zero; |
(...skipping 15 matching lines...) Expand all Loading... |
335 scales[1] = m->Int32Constant(2); | 348 scales[1] = m->Int32Constant(2); |
336 scales[2] = m->Int32Constant(4); | 349 scales[2] = m->Int32Constant(4); |
337 scales[3] = m->Int32Constant(8); | 350 scales[3] = m->Int32Constant(8); |
338 } | 351 } |
339 }; | 352 }; |
340 | 353 |
341 | 354 |
342 TEST_F(AddressingModeUnitTest, AddressingMode_MR) { | 355 TEST_F(AddressingModeUnitTest, AddressingMode_MR) { |
343 Node* base = base_reg; | 356 Node* base = base_reg; |
344 Node* index = zero; | 357 Node* index = zero; |
345 Run(base, index, kMode_MR); | 358 Run(base, index, index, kMode_MR); |
346 } | 359 } |
347 | 360 |
348 | 361 |
349 TEST_F(AddressingModeUnitTest, AddressingMode_MRI) { | 362 TEST_F(AddressingModeUnitTest, AddressingMode_MRI) { |
350 Node* base = base_reg; | 363 Node* base = base_reg; |
351 Node* index = non_zero; | 364 Node* index = non_zero; |
352 Run(base, index, kMode_MRI); | 365 Run(base, index, index, kMode_MRI); |
353 } | 366 } |
354 | 367 |
355 | 368 |
356 TEST_F(AddressingModeUnitTest, AddressingMode_MR1) { | 369 TEST_F(AddressingModeUnitTest, AddressingMode_MR1) { |
357 Node* base = base_reg; | 370 Node* base = base_reg; |
358 Node* index = index_reg; | 371 Node* index = index_reg; |
359 Run(base, index, kMode_MR1); | 372 Run(base, index, index, kMode_MR1); |
360 } | 373 } |
361 | 374 |
362 | 375 |
363 TEST_F(AddressingModeUnitTest, AddressingMode_MRN) { | 376 TEST_F(AddressingModeUnitTest, AddressingMode_MRN) { |
364 AddressingMode expected[] = {kMode_MR1, kMode_MR2, kMode_MR4, kMode_MR8}; | 377 AddressingMode expected[] = {kMode_MR1, kMode_MR2, kMode_MR4, kMode_MR8}; |
365 for (size_t i = 0; i < arraysize(scales); ++i) { | 378 for (size_t i = 0; i < arraysize(scales); ++i) { |
366 Reset(); | 379 Reset(); |
367 Node* base = base_reg; | 380 Node* base = base_reg; |
368 Node* index = m->Int32Mul(index_reg, scales[i]); | 381 Node* load_index = m->Int32Mul(index_reg, scales[i]); |
369 Run(base, index, expected[i]); | 382 Node* store_index = m->Int32Mul(index_reg, scales[i]); |
| 383 Run(base, load_index, store_index, expected[i]); |
370 } | 384 } |
371 } | 385 } |
372 | 386 |
373 | 387 |
374 TEST_F(AddressingModeUnitTest, AddressingMode_MR1I) { | 388 TEST_F(AddressingModeUnitTest, AddressingMode_MR1I) { |
375 Node* base = base_reg; | 389 Node* base = base_reg; |
376 Node* index = m->Int32Add(index_reg, non_zero); | 390 Node* load_index = m->Int32Add(index_reg, non_zero); |
377 Run(base, index, kMode_MR1I); | 391 Node* store_index = m->Int32Add(index_reg, non_zero); |
| 392 Run(base, load_index, store_index, kMode_MR1I); |
378 } | 393 } |
379 | 394 |
380 | 395 |
381 TEST_F(AddressingModeUnitTest, AddressingMode_MRNI) { | 396 TEST_F(AddressingModeUnitTest, AddressingMode_MRNI) { |
382 AddressingMode expected[] = {kMode_MR1I, kMode_MR2I, kMode_MR4I, kMode_MR8I}; | 397 AddressingMode expected[] = {kMode_MR1I, kMode_MR2I, kMode_MR4I, kMode_MR8I}; |
383 for (size_t i = 0; i < arraysize(scales); ++i) { | 398 for (size_t i = 0; i < arraysize(scales); ++i) { |
384 Reset(); | 399 Reset(); |
385 Node* base = base_reg; | 400 Node* base = base_reg; |
386 Node* index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero); | 401 Node* load_index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero); |
387 Run(base, index, expected[i]); | 402 Node* store_index = |
| 403 m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero); |
| 404 Run(base, load_index, store_index, expected[i]); |
388 } | 405 } |
389 } | 406 } |
390 | 407 |
391 | 408 |
392 TEST_F(AddressingModeUnitTest, AddressingMode_M1) { | 409 TEST_F(AddressingModeUnitTest, AddressingMode_M1ToMR) { |
393 Node* base = null_ptr; | 410 Node* base = null_ptr; |
394 Node* index = index_reg; | 411 Node* index = index_reg; |
395 Run(base, index, kMode_M1); | 412 // M1 maps to MR |
| 413 Run(base, index, index, kMode_MR); |
396 } | 414 } |
397 | 415 |
398 | 416 |
399 TEST_F(AddressingModeUnitTest, AddressingMode_MN) { | 417 TEST_F(AddressingModeUnitTest, AddressingMode_MN) { |
400 AddressingMode expected[] = {kMode_M1, kMode_M2, kMode_M4, kMode_M8}; | 418 AddressingMode expected[] = {kMode_MR, kMode_M2, kMode_M4, kMode_M8}; |
401 for (size_t i = 0; i < arraysize(scales); ++i) { | 419 for (size_t i = 0; i < arraysize(scales); ++i) { |
402 Reset(); | 420 Reset(); |
403 Node* base = null_ptr; | 421 Node* base = null_ptr; |
404 Node* index = m->Int32Mul(index_reg, scales[i]); | 422 Node* load_index = m->Int32Mul(index_reg, scales[i]); |
405 Run(base, index, expected[i]); | 423 Node* store_index = m->Int32Mul(index_reg, scales[i]); |
| 424 Run(base, load_index, store_index, expected[i]); |
406 } | 425 } |
407 } | 426 } |
408 | 427 |
409 | 428 |
410 TEST_F(AddressingModeUnitTest, AddressingMode_M1I) { | 429 TEST_F(AddressingModeUnitTest, AddressingMode_M1IToMRI) { |
411 Node* base = null_ptr; | 430 Node* base = null_ptr; |
412 Node* index = m->Int32Add(index_reg, non_zero); | 431 Node* load_index = m->Int32Add(index_reg, non_zero); |
413 Run(base, index, kMode_M1I); | 432 Node* store_index = m->Int32Add(index_reg, non_zero); |
| 433 // M1I maps to MRI |
| 434 Run(base, load_index, store_index, kMode_MRI); |
414 } | 435 } |
415 | 436 |
416 | 437 |
417 TEST_F(AddressingModeUnitTest, AddressingMode_MNI) { | 438 TEST_F(AddressingModeUnitTest, AddressingMode_MNI) { |
418 AddressingMode expected[] = {kMode_M1I, kMode_M2I, kMode_M4I, kMode_M8I}; | 439 AddressingMode expected[] = {kMode_MRI, kMode_M2I, kMode_M4I, kMode_M8I}; |
419 for (size_t i = 0; i < arraysize(scales); ++i) { | 440 for (size_t i = 0; i < arraysize(scales); ++i) { |
420 Reset(); | 441 Reset(); |
421 Node* base = null_ptr; | 442 Node* base = null_ptr; |
422 Node* index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero); | 443 Node* load_index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero); |
423 Run(base, index, expected[i]); | 444 Node* store_index = |
| 445 m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero); |
| 446 Run(base, load_index, store_index, expected[i]); |
424 } | 447 } |
425 } | 448 } |
426 | 449 |
427 | 450 |
428 TEST_F(AddressingModeUnitTest, AddressingMode_MI) { | 451 TEST_F(AddressingModeUnitTest, AddressingMode_MI) { |
429 Node* bases[] = {null_ptr, non_zero}; | 452 Node* bases[] = {null_ptr, non_zero}; |
430 Node* indices[] = {zero, non_zero}; | 453 Node* indices[] = {zero, non_zero}; |
431 for (size_t i = 0; i < arraysize(bases); ++i) { | 454 for (size_t i = 0; i < arraysize(bases); ++i) { |
432 for (size_t j = 0; j < arraysize(indices); ++j) { | 455 for (size_t j = 0; j < arraysize(indices); ++j) { |
433 Reset(); | 456 Reset(); |
434 Node* base = bases[i]; | 457 Node* base = bases[i]; |
435 Node* index = indices[j]; | 458 Node* index = indices[j]; |
436 Run(base, index, kMode_MI); | 459 Run(base, index, index, kMode_MI); |
437 } | 460 } |
438 } | 461 } |
439 } | 462 } |
440 | 463 |
441 | 464 |
442 // ----------------------------------------------------------------------------- | 465 // ----------------------------------------------------------------------------- |
443 // Multiplication. | 466 // Multiplication. |
444 | 467 |
445 | 468 |
446 namespace { | 469 namespace { |
447 | 470 |
448 struct MultParam { | 471 struct MultParam { |
449 int value; | 472 int value; |
450 bool lea_expected; | 473 bool lea_expected; |
451 AddressingMode addressing_mode; | 474 AddressingMode addressing_mode; |
452 }; | 475 }; |
453 | 476 |
454 | 477 |
455 std::ostream& operator<<(std::ostream& os, const MultParam& m) { | 478 std::ostream& operator<<(std::ostream& os, const MultParam& m) { |
456 return os << m.value << "." << m.lea_expected << "." << m.addressing_mode; | 479 return os << m.value << "." << m.lea_expected << "." << m.addressing_mode; |
457 } | 480 } |
458 | 481 |
459 | 482 |
460 const MultParam kMultParams[] = {{-1, false, kMode_None}, | 483 const MultParam kMultParams[] = {{-1, false, kMode_None}, |
461 {0, false, kMode_None}, | 484 {0, false, kMode_None}, |
462 {1, true, kMode_M1}, | 485 {1, true, kMode_MR}, |
463 {2, true, kMode_M2}, | 486 {2, true, kMode_M2}, |
464 {3, true, kMode_MR2}, | 487 {3, true, kMode_MR2}, |
465 {4, true, kMode_M4}, | 488 {4, true, kMode_M4}, |
466 {5, true, kMode_MR4}, | 489 {5, true, kMode_MR4}, |
467 {6, false, kMode_None}, | 490 {6, false, kMode_None}, |
468 {7, false, kMode_None}, | 491 {7, false, kMode_None}, |
469 {8, true, kMode_M8}, | 492 {8, true, kMode_M8}, |
470 {9, true, kMode_MR8}, | 493 {9, true, kMode_MR8}, |
471 {10, false, kMode_None}, | 494 {10, false, kMode_None}, |
472 {11, false, kMode_None}}; | 495 {11, false, kMode_None}}; |
(...skipping 13 matching lines...) Expand all Loading... |
486 return 3U; | 509 return 3U; |
487 case kMode_M1I: | 510 case kMode_M1I: |
488 case kMode_M2I: | 511 case kMode_M2I: |
489 case kMode_M4I: | 512 case kMode_M4I: |
490 case kMode_M8I: | 513 case kMode_M8I: |
491 return 2U; | 514 return 2U; |
492 case kMode_MR1: | 515 case kMode_MR1: |
493 case kMode_MR2: | 516 case kMode_MR2: |
494 case kMode_MR4: | 517 case kMode_MR4: |
495 case kMode_MR8: | 518 case kMode_MR8: |
| 519 case kMode_MRI: |
496 return 2U; | 520 return 2U; |
497 case kMode_M1: | 521 case kMode_M1: |
498 case kMode_M2: | 522 case kMode_M2: |
499 case kMode_M4: | 523 case kMode_M4: |
500 case kMode_M8: | 524 case kMode_M8: |
| 525 case kMode_MI: |
| 526 case kMode_MR: |
501 return 1U; | 527 return 1U; |
502 default: | 528 default: |
503 UNREACHABLE(); | 529 UNREACHABLE(); |
504 return 0U; | 530 return 0U; |
505 } | 531 } |
506 } | 532 } |
507 | 533 |
508 | 534 |
509 static AddressingMode AddressingModeForAddMult(const MultParam& m) { | 535 static AddressingMode AddressingModeForAddMult(int32_t imm, |
| 536 const MultParam& m) { |
| 537 if (imm == 0) return m.addressing_mode; |
510 switch (m.addressing_mode) { | 538 switch (m.addressing_mode) { |
511 case kMode_MR1: | 539 case kMode_MR1: |
512 return kMode_MR1I; | 540 return kMode_MR1I; |
513 case kMode_MR2: | 541 case kMode_MR2: |
514 return kMode_MR2I; | 542 return kMode_MR2I; |
515 case kMode_MR4: | 543 case kMode_MR4: |
516 return kMode_MR4I; | 544 return kMode_MR4I; |
517 case kMode_MR8: | 545 case kMode_MR8: |
518 return kMode_MR8I; | 546 return kMode_MR8I; |
519 case kMode_M1: | 547 case kMode_M1: |
520 return kMode_M1I; | 548 return kMode_M1I; |
521 case kMode_M2: | 549 case kMode_M2: |
522 return kMode_M2I; | 550 return kMode_M2I; |
523 case kMode_M4: | 551 case kMode_M4: |
524 return kMode_M4I; | 552 return kMode_M4I; |
525 case kMode_M8: | 553 case kMode_M8: |
526 return kMode_M8I; | 554 return kMode_M8I; |
| 555 case kMode_MR: |
| 556 return kMode_MRI; |
527 default: | 557 default: |
528 UNREACHABLE(); | 558 UNREACHABLE(); |
529 return kMode_None; | 559 return kMode_None; |
530 } | 560 } |
531 } | 561 } |
532 | 562 |
533 | 563 |
534 TEST_P(InstructionSelectorMultTest, Mult32) { | 564 TEST_P(InstructionSelectorMultTest, Mult32) { |
535 const MultParam m_param = GetParam(); | 565 const MultParam m_param = GetParam(); |
536 StreamBuilder m(this, kMachInt32, kMachInt32); | 566 StreamBuilder m(this, kMachInt32, kMachInt32); |
(...skipping 19 matching lines...) Expand all Loading... |
556 const MultParam m_param = GetParam(); | 586 const MultParam m_param = GetParam(); |
557 StreamBuilder m(this, kMachInt32, kMachInt32); | 587 StreamBuilder m(this, kMachInt32, kMachInt32); |
558 Node* param = m.Parameter(0); | 588 Node* param = m.Parameter(0); |
559 Node* mult = m.Int32Add(m.Int32Mul(param, m.Int32Constant(m_param.value)), | 589 Node* mult = m.Int32Add(m.Int32Mul(param, m.Int32Constant(m_param.value)), |
560 m.Int32Constant(imm)); | 590 m.Int32Constant(imm)); |
561 m.Return(mult); | 591 m.Return(mult); |
562 Stream s = m.Build(); | 592 Stream s = m.Build(); |
563 if (m_param.lea_expected) { | 593 if (m_param.lea_expected) { |
564 ASSERT_EQ(1U, s.size()); | 594 ASSERT_EQ(1U, s.size()); |
565 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); | 595 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); |
566 EXPECT_EQ(AddressingModeForAddMult(m_param), s[0]->addressing_mode()); | 596 EXPECT_EQ(AddressingModeForAddMult(imm, m_param), |
| 597 s[0]->addressing_mode()); |
567 unsigned input_count = InputCountForLea(s[0]->addressing_mode()); | 598 unsigned input_count = InputCountForLea(s[0]->addressing_mode()); |
568 ASSERT_EQ(input_count, s[0]->InputCount()); | 599 ASSERT_EQ(input_count, s[0]->InputCount()); |
569 ASSERT_EQ(InstructionOperand::IMMEDIATE, | 600 if (imm != 0) { |
570 s[0]->InputAt(input_count - 1)->kind()); | 601 ASSERT_EQ(InstructionOperand::IMMEDIATE, |
571 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(input_count - 1))); | 602 s[0]->InputAt(input_count - 1)->kind()); |
| 603 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(input_count - 1))); |
| 604 } |
572 } else { | 605 } else { |
573 ASSERT_EQ(2U, s.size()); | 606 ASSERT_EQ(2U, s.size()); |
574 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode()); | 607 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode()); |
575 EXPECT_EQ(kIA32Add, s[1]->arch_opcode()); | 608 EXPECT_EQ(kIA32Lea, s[1]->arch_opcode()); |
576 } | 609 } |
577 } | 610 } |
578 } | 611 } |
579 | 612 |
580 | 613 |
581 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMultTest, | 614 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMultTest, |
582 ::testing::ValuesIn(kMultParams)); | 615 ::testing::ValuesIn(kMultParams)); |
583 | 616 |
584 | 617 |
585 TEST_F(InstructionSelectorTest, Int32MulHigh) { | 618 TEST_F(InstructionSelectorTest, Int32MulHigh) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 EXPECT_EQ(kSSEFloat64Add, s[0]->arch_opcode()); | 662 EXPECT_EQ(kSSEFloat64Add, s[0]->arch_opcode()); |
630 EXPECT_EQ(kSSEFloat64Mul, s[1]->arch_opcode()); | 663 EXPECT_EQ(kSSEFloat64Mul, s[1]->arch_opcode()); |
631 EXPECT_EQ(kSSEFloat64Sub, s[2]->arch_opcode()); | 664 EXPECT_EQ(kSSEFloat64Sub, s[2]->arch_opcode()); |
632 EXPECT_EQ(kSSEFloat64Div, s[3]->arch_opcode()); | 665 EXPECT_EQ(kSSEFloat64Div, s[3]->arch_opcode()); |
633 } | 666 } |
634 } | 667 } |
635 | 668 |
636 } // namespace compiler | 669 } // namespace compiler |
637 } // namespace internal | 670 } // namespace internal |
638 } // namespace v8 | 671 } // namespace v8 |
OLD | NEW |