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

Side by Side Diff: test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc

Issue 1064813003: ARM64: Support sign extend for add and subtract (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « src/compiler/arm64/instruction-selector-arm64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 EXPECT_EQ(dpi.mi.arch_opcode, s[0]->arch_opcode()); 465 EXPECT_EQ(dpi.mi.arch_opcode, s[0]->arch_opcode());
466 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 466 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
467 EXPECT_EQ(3U, s[0]->InputCount()); 467 EXPECT_EQ(3U, s[0]->InputCount());
468 EXPECT_EQ(imm, s.ToInt64(s[0]->InputAt(2))); 468 EXPECT_EQ(imm, s.ToInt64(s[0]->InputAt(2)));
469 EXPECT_EQ(1U, s[0]->OutputCount()); 469 EXPECT_EQ(1U, s[0]->OutputCount());
470 } 470 }
471 } 471 }
472 } 472 }
473 473
474 474
475 TEST_P(InstructionSelectorAddSubTest, ExtendByte) { 475 TEST_P(InstructionSelectorAddSubTest, UnsignedExtendByte) {
476 const AddSub dpi = GetParam(); 476 const AddSub dpi = GetParam();
477 const MachineType type = dpi.mi.machine_type; 477 const MachineType type = dpi.mi.machine_type;
478 StreamBuilder m(this, type, type, type); 478 StreamBuilder m(this, type, type, type);
479 m.Return((m.*dpi.mi.constructor)( 479 m.Return((m.*dpi.mi.constructor)(
480 m.Parameter(0), m.Word32And(m.Parameter(1), m.Int32Constant(0xff)))); 480 m.Parameter(0), m.Word32And(m.Parameter(1), m.Int32Constant(0xff))));
481 Stream s = m.Build(); 481 Stream s = m.Build();
482 ASSERT_EQ(1U, s.size()); 482 ASSERT_EQ(1U, s.size());
483 EXPECT_EQ(dpi.mi.arch_opcode, s[0]->arch_opcode()); 483 EXPECT_EQ(dpi.mi.arch_opcode, s[0]->arch_opcode());
484 EXPECT_EQ(kMode_Operand2_R_UXTB, s[0]->addressing_mode()); 484 EXPECT_EQ(kMode_Operand2_R_UXTB, s[0]->addressing_mode());
485 ASSERT_EQ(2U, s[0]->InputCount()); 485 ASSERT_EQ(2U, s[0]->InputCount());
486 ASSERT_EQ(1U, s[0]->OutputCount()); 486 ASSERT_EQ(1U, s[0]->OutputCount());
487 } 487 }
488 488
489 489
490 TEST_P(InstructionSelectorAddSubTest, ExtendHalfword) { 490 TEST_P(InstructionSelectorAddSubTest, UnsignedExtendHalfword) {
491 const AddSub dpi = GetParam(); 491 const AddSub dpi = GetParam();
492 const MachineType type = dpi.mi.machine_type; 492 const MachineType type = dpi.mi.machine_type;
493 StreamBuilder m(this, type, type, type); 493 StreamBuilder m(this, type, type, type);
494 m.Return((m.*dpi.mi.constructor)( 494 m.Return((m.*dpi.mi.constructor)(
495 m.Parameter(0), m.Word32And(m.Parameter(1), m.Int32Constant(0xffff)))); 495 m.Parameter(0), m.Word32And(m.Parameter(1), m.Int32Constant(0xffff))));
496 Stream s = m.Build(); 496 Stream s = m.Build();
497 ASSERT_EQ(1U, s.size()); 497 ASSERT_EQ(1U, s.size());
498 EXPECT_EQ(dpi.mi.arch_opcode, s[0]->arch_opcode()); 498 EXPECT_EQ(dpi.mi.arch_opcode, s[0]->arch_opcode());
499 EXPECT_EQ(kMode_Operand2_R_UXTH, s[0]->addressing_mode()); 499 EXPECT_EQ(kMode_Operand2_R_UXTH, s[0]->addressing_mode());
500 ASSERT_EQ(2U, s[0]->InputCount()); 500 ASSERT_EQ(2U, s[0]->InputCount());
501 ASSERT_EQ(1U, s[0]->OutputCount()); 501 ASSERT_EQ(1U, s[0]->OutputCount());
502 } 502 }
503 503
504 504
505 TEST_P(InstructionSelectorAddSubTest, SignedExtendByte) {
506 const AddSub dpi = GetParam();
507 const MachineType type = dpi.mi.machine_type;
508 StreamBuilder m(this, type, type, type);
509 m.Return((m.*dpi.mi.constructor)(
510 m.Parameter(0),
511 m.Word32Sar(m.Word32Shl(m.Parameter(1), m.Int32Constant(24)),
512 m.Int32Constant(24))));
513 Stream s = m.Build();
514 ASSERT_EQ(1U, s.size());
515 EXPECT_EQ(dpi.mi.arch_opcode, s[0]->arch_opcode());
516 EXPECT_EQ(kMode_Operand2_R_SXTB, s[0]->addressing_mode());
517 ASSERT_EQ(2U, s[0]->InputCount());
518 ASSERT_EQ(1U, s[0]->OutputCount());
519 }
520
521
522 TEST_P(InstructionSelectorAddSubTest, SignedExtendHalfword) {
523 const AddSub dpi = GetParam();
524 const MachineType type = dpi.mi.machine_type;
525 StreamBuilder m(this, type, type, type);
526 m.Return((m.*dpi.mi.constructor)(
527 m.Parameter(0),
528 m.Word32Sar(m.Word32Shl(m.Parameter(1), m.Int32Constant(16)),
529 m.Int32Constant(16))));
530 Stream s = m.Build();
531 ASSERT_EQ(1U, s.size());
532 EXPECT_EQ(dpi.mi.arch_opcode, s[0]->arch_opcode());
533 EXPECT_EQ(kMode_Operand2_R_SXTH, s[0]->addressing_mode());
534 ASSERT_EQ(2U, s[0]->InputCount());
535 ASSERT_EQ(1U, s[0]->OutputCount());
536 }
537
538
505 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorAddSubTest, 539 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorAddSubTest,
506 ::testing::ValuesIn(kAddSubInstructions)); 540 ::testing::ValuesIn(kAddSubInstructions));
507 541
508 542
509 TEST_F(InstructionSelectorTest, AddImmediateOnLeft) { 543 TEST_F(InstructionSelectorTest, AddImmediateOnLeft) {
510 { 544 {
511 // 32-bit add. 545 // 32-bit add.
512 TRACED_FOREACH(int32_t, imm, kAddSubImmediates) { 546 TRACED_FOREACH(int32_t, imm, kAddSubImmediates) {
513 StreamBuilder m(this, kMachInt32, kMachInt32); 547 StreamBuilder m(this, kMachInt32, kMachInt32);
514 m.Return(m.Int32Add(m.Int32Constant(imm), m.Parameter(0))); 548 m.Return(m.Int32Add(m.Int32Constant(imm), m.Parameter(0)));
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); 673 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
640 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 674 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
641 EXPECT_EQ(3U, s[0]->InputCount()); 675 EXPECT_EQ(3U, s[0]->InputCount());
642 EXPECT_EQ(imm, s.ToInt64(s[0]->InputAt(2))); 676 EXPECT_EQ(imm, s.ToInt64(s[0]->InputAt(2)));
643 EXPECT_EQ(1U, s[0]->OutputCount()); 677 EXPECT_EQ(1U, s[0]->OutputCount());
644 } 678 }
645 } 679 }
646 } 680 }
647 681
648 682
649 TEST_F(InstructionSelectorTest, AddExtendByteOnLeft) { 683 TEST_F(InstructionSelectorTest, AddUnsignedExtendByteOnLeft) {
650 { 684 {
651 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); 685 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
652 m.Return(m.Int32Add(m.Word32And(m.Parameter(0), m.Int32Constant(0xff)), 686 m.Return(m.Int32Add(m.Word32And(m.Parameter(0), m.Int32Constant(0xff)),
653 m.Parameter(1))); 687 m.Parameter(1)));
654 Stream s = m.Build(); 688 Stream s = m.Build();
655 ASSERT_EQ(1U, s.size()); 689 ASSERT_EQ(1U, s.size());
656 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); 690 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
657 EXPECT_EQ(kMode_Operand2_R_UXTB, s[0]->addressing_mode()); 691 EXPECT_EQ(kMode_Operand2_R_UXTB, s[0]->addressing_mode());
658 ASSERT_EQ(2U, s[0]->InputCount()); 692 ASSERT_EQ(2U, s[0]->InputCount());
659 ASSERT_EQ(1U, s[0]->OutputCount()); 693 ASSERT_EQ(1U, s[0]->OutputCount());
660 } 694 }
661 { 695 {
662 StreamBuilder m(this, kMachInt64, kMachInt32, kMachInt64); 696 StreamBuilder m(this, kMachInt64, kMachInt32, kMachInt64);
663 m.Return(m.Int64Add(m.Word32And(m.Parameter(0), m.Int32Constant(0xff)), 697 m.Return(m.Int64Add(m.Word32And(m.Parameter(0), m.Int32Constant(0xff)),
664 m.Parameter(1))); 698 m.Parameter(1)));
665 Stream s = m.Build(); 699 Stream s = m.Build();
666 ASSERT_EQ(1U, s.size()); 700 ASSERT_EQ(1U, s.size());
667 EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); 701 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
668 EXPECT_EQ(kMode_Operand2_R_UXTB, s[0]->addressing_mode()); 702 EXPECT_EQ(kMode_Operand2_R_UXTB, s[0]->addressing_mode());
669 ASSERT_EQ(2U, s[0]->InputCount()); 703 ASSERT_EQ(2U, s[0]->InputCount());
670 ASSERT_EQ(1U, s[0]->OutputCount()); 704 ASSERT_EQ(1U, s[0]->OutputCount());
671 } 705 }
672 } 706 }
673 707
674 708
675 TEST_F(InstructionSelectorTest, AddExtendHalfwordOnLeft) { 709 TEST_F(InstructionSelectorTest, AddUnsignedExtendHalfwordOnLeft) {
676 { 710 {
677 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); 711 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
678 m.Return(m.Int32Add(m.Word32And(m.Parameter(0), m.Int32Constant(0xffff)), 712 m.Return(m.Int32Add(m.Word32And(m.Parameter(0), m.Int32Constant(0xffff)),
679 m.Parameter(1))); 713 m.Parameter(1)));
680 Stream s = m.Build(); 714 Stream s = m.Build();
681 ASSERT_EQ(1U, s.size()); 715 ASSERT_EQ(1U, s.size());
682 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); 716 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
683 EXPECT_EQ(kMode_Operand2_R_UXTH, s[0]->addressing_mode()); 717 EXPECT_EQ(kMode_Operand2_R_UXTH, s[0]->addressing_mode());
684 ASSERT_EQ(2U, s[0]->InputCount()); 718 ASSERT_EQ(2U, s[0]->InputCount());
685 ASSERT_EQ(1U, s[0]->OutputCount()); 719 ASSERT_EQ(1U, s[0]->OutputCount());
686 } 720 }
687 { 721 {
688 StreamBuilder m(this, kMachInt64, kMachInt32, kMachInt64); 722 StreamBuilder m(this, kMachInt64, kMachInt32, kMachInt64);
689 m.Return(m.Int64Add(m.Word32And(m.Parameter(0), m.Int32Constant(0xffff)), 723 m.Return(m.Int64Add(m.Word32And(m.Parameter(0), m.Int32Constant(0xffff)),
690 m.Parameter(1))); 724 m.Parameter(1)));
691 Stream s = m.Build(); 725 Stream s = m.Build();
692 ASSERT_EQ(1U, s.size()); 726 ASSERT_EQ(1U, s.size());
693 EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); 727 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
694 EXPECT_EQ(kMode_Operand2_R_UXTH, s[0]->addressing_mode()); 728 EXPECT_EQ(kMode_Operand2_R_UXTH, s[0]->addressing_mode());
695 ASSERT_EQ(2U, s[0]->InputCount()); 729 ASSERT_EQ(2U, s[0]->InputCount());
696 ASSERT_EQ(1U, s[0]->OutputCount()); 730 ASSERT_EQ(1U, s[0]->OutputCount());
697 } 731 }
698 } 732 }
699 733
700 734
735 TEST_F(InstructionSelectorTest, AddSignedExtendByteOnLeft) {
736 {
737 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
738 m.Return(
739 m.Int32Add(m.Word32Sar(m.Word32Shl(m.Parameter(0), m.Int32Constant(24)),
740 m.Int32Constant(24)),
741 m.Parameter(1)));
742 Stream s = m.Build();
743 ASSERT_EQ(1U, s.size());
744 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
745 EXPECT_EQ(kMode_Operand2_R_SXTB, s[0]->addressing_mode());
746 ASSERT_EQ(2U, s[0]->InputCount());
747 ASSERT_EQ(1U, s[0]->OutputCount());
748 }
749 {
750 StreamBuilder m(this, kMachInt64, kMachInt32, kMachInt64);
751 m.Return(
752 m.Int64Add(m.Word32Sar(m.Word32Shl(m.Parameter(0), m.Int32Constant(24)),
753 m.Int32Constant(24)),
754 m.Parameter(1)));
755 Stream s = m.Build();
756 ASSERT_EQ(1U, s.size());
757 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
758 EXPECT_EQ(kMode_Operand2_R_SXTB, s[0]->addressing_mode());
759 ASSERT_EQ(2U, s[0]->InputCount());
760 ASSERT_EQ(1U, s[0]->OutputCount());
761 }
762 }
763
764
765 TEST_F(InstructionSelectorTest, AddSignedExtendHalfwordOnLeft) {
766 {
767 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
768 m.Return(
769 m.Int32Add(m.Word32Sar(m.Word32Shl(m.Parameter(0), m.Int32Constant(16)),
770 m.Int32Constant(16)),
771 m.Parameter(1)));
772 Stream s = m.Build();
773 ASSERT_EQ(1U, s.size());
774 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
775 EXPECT_EQ(kMode_Operand2_R_SXTH, s[0]->addressing_mode());
776 ASSERT_EQ(2U, s[0]->InputCount());
777 ASSERT_EQ(1U, s[0]->OutputCount());
778 }
779 {
780 StreamBuilder m(this, kMachInt64, kMachInt32, kMachInt64);
781 m.Return(
782 m.Int64Add(m.Word32Sar(m.Word32Shl(m.Parameter(0), m.Int32Constant(16)),
783 m.Int32Constant(16)),
784 m.Parameter(1)));
785 Stream s = m.Build();
786 ASSERT_EQ(1U, s.size());
787 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
788 EXPECT_EQ(kMode_Operand2_R_SXTH, s[0]->addressing_mode());
789 ASSERT_EQ(2U, s[0]->InputCount());
790 ASSERT_EQ(1U, s[0]->OutputCount());
791 }
792 }
793
794
701 // ----------------------------------------------------------------------------- 795 // -----------------------------------------------------------------------------
702 // Data processing controlled branches. 796 // Data processing controlled branches.
703 797
704 798
705 typedef InstructionSelectorTestWithParam<MachInst2> 799 typedef InstructionSelectorTestWithParam<MachInst2>
706 InstructionSelectorDPFlagSetTest; 800 InstructionSelectorDPFlagSetTest;
707 801
708 802
709 TEST_P(InstructionSelectorDPFlagSetTest, BranchWithParameters) { 803 TEST_P(InstructionSelectorDPFlagSetTest, BranchWithParameters) {
710 const MachInst2 dpi = GetParam(); 804 const MachInst2 dpi = GetParam();
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 EXPECT_EQ(kArm64Float64Neg, s[0]->arch_opcode()); 2422 EXPECT_EQ(kArm64Float64Neg, s[0]->arch_opcode());
2329 ASSERT_EQ(1U, s[0]->InputCount()); 2423 ASSERT_EQ(1U, s[0]->InputCount());
2330 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); 2424 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
2331 ASSERT_EQ(1U, s[0]->OutputCount()); 2425 ASSERT_EQ(1U, s[0]->OutputCount());
2332 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); 2426 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
2333 } 2427 }
2334 2428
2335 } // namespace compiler 2429 } // namespace compiler
2336 } // namespace internal 2430 } // namespace internal
2337 } // namespace v8 2431 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/arm64/instruction-selector-arm64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698