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 |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 {11, false, kMode_None}}; | 467 {11, false, kMode_None}}; |
468 | 468 |
469 } // namespace | 469 } // namespace |
470 | 470 |
471 | 471 |
472 typedef InstructionSelectorTestWithParam<MultParam> InstructionSelectorMultTest; | 472 typedef InstructionSelectorTestWithParam<MultParam> InstructionSelectorMultTest; |
473 | 473 |
474 | 474 |
475 static unsigned InputCountForLea(AddressingMode mode) { | 475 static unsigned InputCountForLea(AddressingMode mode) { |
476 switch (mode) { | 476 switch (mode) { |
| 477 case kMode_MR1I: |
| 478 case kMode_MR2I: |
| 479 case kMode_MR4I: |
| 480 case kMode_MR8I: |
| 481 return 3U; |
| 482 case kMode_M1I: |
| 483 case kMode_M2I: |
| 484 case kMode_M4I: |
| 485 case kMode_M8I: |
| 486 return 2U; |
477 case kMode_MR1: | 487 case kMode_MR1: |
478 case kMode_MR2: | 488 case kMode_MR2: |
479 case kMode_MR4: | 489 case kMode_MR4: |
480 case kMode_MR8: | 490 case kMode_MR8: |
481 return 2U; | 491 return 2U; |
482 case kMode_M1: | 492 case kMode_M1: |
483 case kMode_M2: | 493 case kMode_M2: |
484 case kMode_M4: | 494 case kMode_M4: |
485 case kMode_M8: | 495 case kMode_M8: |
486 return 1U; | 496 return 1U; |
487 default: | 497 default: |
488 UNREACHABLE(); | 498 UNREACHABLE(); |
489 return 0U; | 499 return 0U; |
490 } | 500 } |
491 } | 501 } |
492 | 502 |
493 | 503 |
| 504 static AddressingMode AddressingModeForAddMult(const MultParam& m) { |
| 505 switch (m.addressing_mode) { |
| 506 case kMode_MR1: |
| 507 return kMode_MR1I; |
| 508 case kMode_MR2: |
| 509 return kMode_MR2I; |
| 510 case kMode_MR4: |
| 511 return kMode_MR4I; |
| 512 case kMode_MR8: |
| 513 return kMode_MR8I; |
| 514 case kMode_M1: |
| 515 return kMode_M1I; |
| 516 case kMode_M2: |
| 517 return kMode_M2I; |
| 518 case kMode_M4: |
| 519 return kMode_M4I; |
| 520 case kMode_M8: |
| 521 return kMode_M8I; |
| 522 default: |
| 523 UNREACHABLE(); |
| 524 return kMode_None; |
| 525 } |
| 526 } |
| 527 |
| 528 |
494 TEST_P(InstructionSelectorMultTest, Mult32) { | 529 TEST_P(InstructionSelectorMultTest, Mult32) { |
495 const MultParam m_param = GetParam(); | 530 const MultParam m_param = GetParam(); |
496 StreamBuilder m(this, kMachInt32, kMachInt32); | 531 StreamBuilder m(this, kMachInt32, kMachInt32); |
497 Node* param = m.Parameter(0); | 532 Node* param = m.Parameter(0); |
498 Node* mult = m.Int32Mul(param, m.Int32Constant(m_param.value)); | 533 Node* mult = m.Int32Mul(param, m.Int32Constant(m_param.value)); |
499 m.Return(mult); | 534 m.Return(mult); |
500 Stream s = m.Build(); | 535 Stream s = m.Build(); |
501 ASSERT_EQ(1U, s.size()); | 536 ASSERT_EQ(1U, s.size()); |
502 EXPECT_EQ(m_param.addressing_mode, s[0]->addressing_mode()); | 537 EXPECT_EQ(m_param.addressing_mode, s[0]->addressing_mode()); |
503 if (m_param.lea_expected) { | 538 if (m_param.lea_expected) { |
504 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); | 539 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); |
505 ASSERT_EQ(InputCountForLea(s[0]->addressing_mode()), s[0]->InputCount()); | 540 ASSERT_EQ(InputCountForLea(s[0]->addressing_mode()), s[0]->InputCount()); |
506 } else { | 541 } else { |
507 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode()); | 542 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode()); |
508 ASSERT_EQ(2U, s[0]->InputCount()); | 543 ASSERT_EQ(2U, s[0]->InputCount()); |
509 } | 544 } |
510 EXPECT_EQ(param->id(), s.ToVreg(s[0]->InputAt(0))); | 545 EXPECT_EQ(param->id(), s.ToVreg(s[0]->InputAt(0))); |
511 } | 546 } |
512 | 547 |
513 | 548 |
| 549 TEST_P(InstructionSelectorMultTest, MultAdd32) { |
| 550 TRACED_FOREACH(int32_t, imm, kImmediates) { |
| 551 const MultParam m_param = GetParam(); |
| 552 StreamBuilder m(this, kMachInt32, kMachInt32); |
| 553 Node* param = m.Parameter(0); |
| 554 Node* mult = m.Int32Add(m.Int32Mul(param, m.Int32Constant(m_param.value)), |
| 555 m.Int32Constant(imm)); |
| 556 m.Return(mult); |
| 557 Stream s = m.Build(); |
| 558 if (m_param.lea_expected) { |
| 559 ASSERT_EQ(1U, s.size()); |
| 560 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode()); |
| 561 EXPECT_EQ(AddressingModeForAddMult(m_param), s[0]->addressing_mode()); |
| 562 unsigned input_count = InputCountForLea(s[0]->addressing_mode()); |
| 563 ASSERT_EQ(input_count, s[0]->InputCount()); |
| 564 ASSERT_EQ(InstructionOperand::IMMEDIATE, |
| 565 s[0]->InputAt(input_count - 1)->kind()); |
| 566 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(input_count - 1))); |
| 567 } else { |
| 568 ASSERT_EQ(2U, s.size()); |
| 569 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode()); |
| 570 EXPECT_EQ(kIA32Add, s[1]->arch_opcode()); |
| 571 } |
| 572 } |
| 573 } |
| 574 |
| 575 |
514 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMultTest, | 576 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMultTest, |
515 ::testing::ValuesIn(kMultParams)); | 577 ::testing::ValuesIn(kMultParams)); |
516 | 578 |
517 } // namespace compiler | 579 } // namespace compiler |
518 } // namespace internal | 580 } // namespace internal |
519 } // namespace v8 | 581 } // namespace v8 |
OLD | NEW |