| 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 <list> | 5 #include <list> |
| 6 | 6 |
| 7 #include "src/compiler/instruction-selector-unittest.h" | 7 #include "src/compiler/instruction-selector-unittest.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // ----------------------------------------------------------------------------- | 472 // ----------------------------------------------------------------------------- |
| 473 // Memory access instructions. | 473 // Memory access instructions. |
| 474 | 474 |
| 475 | 475 |
| 476 namespace { | 476 namespace { |
| 477 | 477 |
| 478 struct MemoryAccess { | 478 struct MemoryAccess { |
| 479 MachineType type; | 479 MachineType type; |
| 480 ArchOpcode ldr_opcode; | 480 ArchOpcode ldr_opcode; |
| 481 ArchOpcode str_opcode; | 481 ArchOpcode str_opcode; |
| 482 const int32_t immediates[20]; |
| 482 }; | 483 }; |
| 483 | 484 |
| 484 | 485 |
| 485 std::ostream& operator<<(std::ostream& os, const MemoryAccess& memacc) { | 486 std::ostream& operator<<(std::ostream& os, const MemoryAccess& memacc) { |
| 486 OStringStream ost; | 487 OStringStream ost; |
| 487 ost << memacc.type; | 488 ost << memacc.type; |
| 488 return os << ost.c_str(); | 489 return os << ost.c_str(); |
| 489 } | 490 } |
| 490 | 491 |
| 491 } // namespace | 492 } // namespace |
| 492 | 493 |
| 493 | 494 |
| 494 static const MemoryAccess kMemoryAccesses[] = { | 495 static const MemoryAccess kMemoryAccesses[] = { |
| 495 {kMachInt8, kArm64Ldrsb, kArm64Strb}, | 496 {kMachInt8, kArm64Ldrsb, kArm64Strb, |
| 496 {kMachUint8, kArm64Ldrb, kArm64Strb}, | 497 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 257, 258, 1000, 1001, |
| 497 {kMachInt16, kArm64Ldrsh, kArm64Strh}, | 498 2121, 2442, 4093, 4094, 4095}}, |
| 498 {kMachUint16, kArm64Ldrh, kArm64Strh}, | 499 {kMachUint8, kArm64Ldrb, kArm64Strb, |
| 499 {kMachInt32, kArm64LdrW, kArm64StrW}, | 500 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 257, 258, 1000, 1001, |
| 500 {kMachUint32, kArm64LdrW, kArm64StrW}, | 501 2121, 2442, 4093, 4094, 4095}}, |
| 501 {kMachInt64, kArm64Ldr, kArm64Str}, | 502 {kMachInt16, kArm64Ldrsh, kArm64Strh, |
| 502 {kMachUint64, kArm64Ldr, kArm64Str}, | 503 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 258, 260, 4096, 4098, |
| 503 {kMachFloat32, kArm64LdrS, kArm64StrS}, | 504 4100, 4242, 6786, 8188, 8190}}, |
| 504 {kMachFloat64, kArm64LdrD, kArm64StrD}}; | 505 {kMachUint16, kArm64Ldrh, kArm64Strh, |
| 506 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 258, 260, 4096, 4098, |
| 507 4100, 4242, 6786, 8188, 8190}}, |
| 508 {kMachInt32, kArm64LdrW, kArm64StrW, |
| 509 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 260, 4096, 4100, 8192, |
| 510 8196, 3276, 3280, 16376, 16380}}, |
| 511 {kMachUint32, kArm64LdrW, kArm64StrW, |
| 512 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 260, 4096, 4100, 8192, |
| 513 8196, 3276, 3280, 16376, 16380}}, |
| 514 {kMachInt64, kArm64Ldr, kArm64Str, |
| 515 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 264, 4096, 4104, 8192, |
| 516 8200, 16384, 16392, 32752, 32760}}, |
| 517 {kMachUint64, kArm64Ldr, kArm64Str, |
| 518 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 264, 4096, 4104, 8192, |
| 519 8200, 16384, 16392, 32752, 32760}}, |
| 520 {kMachFloat32, kArm64LdrS, kArm64StrS, |
| 521 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 260, 4096, 4100, 8192, |
| 522 8196, 3276, 3280, 16376, 16380}}, |
| 523 {kMachFloat64, kArm64LdrD, kArm64StrD, |
| 524 {-256, -255, -3, -2, -1, 0, 1, 2, 3, 255, 256, 264, 4096, 4104, 8192, |
| 525 8200, 16384, 16392, 32752, 32760}}}; |
| 505 | 526 |
| 506 | 527 |
| 507 typedef InstructionSelectorTestWithParam<MemoryAccess> | 528 typedef InstructionSelectorTestWithParam<MemoryAccess> |
| 508 InstructionSelectorMemoryAccessTest; | 529 InstructionSelectorMemoryAccessTest; |
| 509 | 530 |
| 510 | 531 |
| 511 TEST_P(InstructionSelectorMemoryAccessTest, LoadWithParameters) { | 532 TEST_P(InstructionSelectorMemoryAccessTest, LoadWithParameters) { |
| 512 const MemoryAccess memacc = GetParam(); | 533 const MemoryAccess memacc = GetParam(); |
| 513 StreamBuilder m(this, memacc.type, kMachPtr, kMachInt32); | 534 StreamBuilder m(this, memacc.type, kMachPtr, kMachInt32); |
| 514 m.Return(m.Load(memacc.type, m.Parameter(0), m.Parameter(1))); | 535 m.Return(m.Load(memacc.type, m.Parameter(0), m.Parameter(1))); |
| 515 Stream s = m.Build(); | 536 Stream s = m.Build(); |
| 516 ASSERT_EQ(1U, s.size()); | 537 ASSERT_EQ(1U, s.size()); |
| 517 EXPECT_EQ(memacc.ldr_opcode, s[0]->arch_opcode()); | 538 EXPECT_EQ(memacc.ldr_opcode, s[0]->arch_opcode()); |
| 518 EXPECT_EQ(kMode_MRR, s[0]->addressing_mode()); | 539 EXPECT_EQ(kMode_MRR, s[0]->addressing_mode()); |
| 519 EXPECT_EQ(2U, s[0]->InputCount()); | 540 EXPECT_EQ(2U, s[0]->InputCount()); |
| 520 EXPECT_EQ(1U, s[0]->OutputCount()); | 541 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 521 } | 542 } |
| 522 | 543 |
| 523 | 544 |
| 545 TEST_P(InstructionSelectorMemoryAccessTest, LoadWithImmediateIndex) { |
| 546 const MemoryAccess memacc = GetParam(); |
| 547 TRACED_FOREACH(int32_t, index, memacc.immediates) { |
| 548 StreamBuilder m(this, memacc.type, kMachPtr); |
| 549 m.Return(m.Load(memacc.type, m.Parameter(0), m.Int32Constant(index))); |
| 550 Stream s = m.Build(); |
| 551 ASSERT_EQ(1U, s.size()); |
| 552 EXPECT_EQ(memacc.ldr_opcode, s[0]->arch_opcode()); |
| 553 EXPECT_EQ(kMode_MRI, s[0]->addressing_mode()); |
| 554 EXPECT_EQ(2U, s[0]->InputCount()); |
| 555 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 556 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); |
| 557 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 558 } |
| 559 } |
| 560 |
| 561 |
| 524 TEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) { | 562 TEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) { |
| 525 const MemoryAccess memacc = GetParam(); | 563 const MemoryAccess memacc = GetParam(); |
| 526 StreamBuilder m(this, kMachInt32, kMachPtr, kMachInt32, memacc.type); | 564 StreamBuilder m(this, kMachInt32, kMachPtr, kMachInt32, memacc.type); |
| 527 m.Store(memacc.type, m.Parameter(0), m.Parameter(1), m.Parameter(2)); | 565 m.Store(memacc.type, m.Parameter(0), m.Parameter(1), m.Parameter(2)); |
| 528 m.Return(m.Int32Constant(0)); | 566 m.Return(m.Int32Constant(0)); |
| 529 Stream s = m.Build(); | 567 Stream s = m.Build(); |
| 530 ASSERT_EQ(1U, s.size()); | 568 ASSERT_EQ(1U, s.size()); |
| 531 EXPECT_EQ(memacc.str_opcode, s[0]->arch_opcode()); | 569 EXPECT_EQ(memacc.str_opcode, s[0]->arch_opcode()); |
| 532 EXPECT_EQ(kMode_MRR, s[0]->addressing_mode()); | 570 EXPECT_EQ(kMode_MRR, s[0]->addressing_mode()); |
| 533 EXPECT_EQ(3U, s[0]->InputCount()); | 571 EXPECT_EQ(3U, s[0]->InputCount()); |
| 534 EXPECT_EQ(0U, s[0]->OutputCount()); | 572 EXPECT_EQ(0U, s[0]->OutputCount()); |
| 535 } | 573 } |
| 536 | 574 |
| 537 | 575 |
| 576 TEST_P(InstructionSelectorMemoryAccessTest, StoreWithImmediateIndex) { |
| 577 const MemoryAccess memacc = GetParam(); |
| 578 TRACED_FOREACH(int32_t, index, memacc.immediates) { |
| 579 StreamBuilder m(this, kMachInt32, kMachPtr, memacc.type); |
| 580 m.Store(memacc.type, m.Parameter(0), m.Int32Constant(index), |
| 581 m.Parameter(1)); |
| 582 m.Return(m.Int32Constant(0)); |
| 583 Stream s = m.Build(); |
| 584 ASSERT_EQ(1U, s.size()); |
| 585 EXPECT_EQ(memacc.str_opcode, s[0]->arch_opcode()); |
| 586 EXPECT_EQ(kMode_MRI, s[0]->addressing_mode()); |
| 587 ASSERT_EQ(3U, s[0]->InputCount()); |
| 588 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 589 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); |
| 590 EXPECT_EQ(0U, s[0]->OutputCount()); |
| 591 } |
| 592 } |
| 593 |
| 594 |
| 538 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, | 595 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
| 539 InstructionSelectorMemoryAccessTest, | 596 InstructionSelectorMemoryAccessTest, |
| 540 ::testing::ValuesIn(kMemoryAccesses)); | 597 ::testing::ValuesIn(kMemoryAccesses)); |
| 541 | 598 |
| 542 } // namespace compiler | 599 } // namespace compiler |
| 543 } // namespace internal | 600 } // namespace internal |
| 544 } // namespace v8 | 601 } // namespace v8 |
| OLD | NEW |