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

Side by Side Diff: runtime/vm/assembler_dbc_test.cc

Issue 2053213004: DBC: Adds BinarySmiOp instruction (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments, fix bugs Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_ARCH_DBC) 6 #if defined(TARGET_ARCH_DBC)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/stack_frame.h" 9 #include "vm/stack_frame.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 __ PushConstant(Smi::Handle(Smi::New(42))); 112 __ PushConstant(Smi::Handle(Smi::New(42)));
113 __ ReturnTOS(); 113 __ ReturnTOS();
114 } 114 }
115 115
116 116
117 ASSEMBLER_TEST_RUN(Simple, test) { 117 ASSEMBLER_TEST_RUN(Simple, test) {
118 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); 118 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
119 } 119 }
120 120
121 121
122 ASSEMBLER_TEST_GENERATE(Nop, assembler) {
123 __ PushConstant(Smi::Handle(Smi::New(42)));
124 __ Nop();
125 __ Nop();
126 __ Nop();
127 __ Nop();
128 __ Nop();
129 __ ReturnTOS();
130 }
131
132
133 ASSEMBLER_TEST_RUN(Nop, test) {
134 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
135 }
136
137
122 // Called from assembler_test.cc. 138 // Called from assembler_test.cc.
123 // FP[-kParamEndSlotFromFp - 1]: growable array 139 // FP[-kParamEndSlotFromFp - 1]: growable array
124 // FP[-kParamEndSlotFromFp - 2]: value 140 // FP[-kParamEndSlotFromFp - 2]: value
125 ASSEMBLER_TEST_GENERATE(StoreIntoObject, assembler) { 141 ASSEMBLER_TEST_GENERATE(StoreIntoObject, assembler) {
126 __ Frame(2); 142 __ Frame(2);
127 __ Move(0, -kParamEndSlotFromFp - 1); 143 __ Move(0, -kParamEndSlotFromFp - 1);
128 __ Move(1, -kParamEndSlotFromFp - 2); 144 __ Move(1, -kParamEndSlotFromFp - 2);
129 __ StoreField(0, GrowableObjectArray::data_offset() / kWordSize, 1); 145 __ StoreField(0, GrowableObjectArray::data_offset() / kWordSize, 1);
130 __ Return(0); 146 __ Return(0);
131 } 147 }
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 MakeDummyInstanceCall(assembler, Bool::True()); 493 MakeDummyInstanceCall(assembler, Bool::True());
478 __ ReturnTOS(); 494 __ ReturnTOS();
479 } 495 }
480 496
481 497
482 ASSEMBLER_TEST_RUN(GreaterThanTOSNonSmi, test) { 498 ASSEMBLER_TEST_RUN(GreaterThanTOSNonSmi, test) {
483 EXPECT(EXECUTE_TEST_CODE_BOOL(test->code())); 499 EXPECT(EXECUTE_TEST_CODE_BOOL(test->code()));
484 } 500 }
485 501
486 502
503 // - Add, Sub, Mul, Div, Mod, Shl, Shr rA, rB, rC
504 //
505 // Arithmetic operations on Smis. FP[rA] <- FP[rB] op FP[rC].
506 // If these instructions can trigger a deoptimization, the following
507 // instruction should be Deopt. If no deoptimization should be triggered,
508 // the immediately following instruction is skipped.
509 ASSEMBLER_TEST_GENERATE(AddNoOverflow, assembler) {
510 __ Frame(3);
511 __ LoadConstant(0, Smi::Handle(Smi::New(20)));
512 __ LoadConstant(1, Smi::Handle(Smi::New(22)));
513 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
514 __ Add(2, 0, 1);
515 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
516 __ Return(2);
517 }
518
519
520 ASSEMBLER_TEST_RUN(AddNoOverflow, test) {
521 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
522 }
523
524
525 ASSEMBLER_TEST_GENERATE(AddOverflow, assembler) {
526 __ Frame(3);
527 __ LoadConstant(0, Smi::Handle(Smi::New(Smi::kMaxValue)));
528 __ LoadConstant(1, Smi::Handle(Smi::New(1)));
529 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
530 __ Add(2, 0, 1);
531 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
532 __ Return(2);
533 }
534
535
536 ASSEMBLER_TEST_RUN(AddOverflow, test) {
537 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
538 }
539
540
541 ASSEMBLER_TEST_GENERATE(SubNoOverflow, assembler) {
542 __ Frame(3);
543 __ LoadConstant(0, Smi::Handle(Smi::New(64)));
544 __ LoadConstant(1, Smi::Handle(Smi::New(22)));
545 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
546 __ Sub(2, 0, 1);
547 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
548 __ Return(2);
549 }
550
551
552 ASSEMBLER_TEST_RUN(SubNoOverflow, test) {
553 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
554 }
555
556
557 ASSEMBLER_TEST_GENERATE(SubOverflow, assembler) {
558 __ Frame(3);
559 __ LoadConstant(0, Smi::Handle(Smi::New(Smi::kMinValue)));
560 __ LoadConstant(1, Smi::Handle(Smi::New(1)));
561 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
562 __ Sub(2, 0, 1);
563 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
564 __ Return(2);
565 }
566
567
568 ASSEMBLER_TEST_RUN(SubOverflow, test) {
569 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
570 }
571
572
573 ASSEMBLER_TEST_GENERATE(MulNoOverflow, assembler) {
574 __ Frame(3);
575 __ LoadConstant(0, Smi::Handle(Smi::New(-6)));
576 __ LoadConstant(1, Smi::Handle(Smi::New(-7)));
577 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
578 __ Mul(2, 0, 1);
579 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
580 __ Return(2);
581 }
582
583
584 ASSEMBLER_TEST_RUN(MulNoOverflow, test) {
585 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
586 }
587
588
589 ASSEMBLER_TEST_GENERATE(MulOverflow, assembler) {
590 __ Frame(3);
591 __ LoadConstant(0, Smi::Handle(Smi::New(Smi::kMaxValue)));
592 __ LoadConstant(1, Smi::Handle(Smi::New(-8)));
593 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
594 __ Mul(2, 0, 1);
595 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
596 __ Return(2);
597 }
598
599
600 ASSEMBLER_TEST_RUN(MulOverflow, test) {
601 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
602 }
603
604
605 ASSEMBLER_TEST_GENERATE(DivNoDeopt, assembler) {
606 __ Frame(3);
607 __ LoadConstant(0, Smi::Handle(Smi::New(27)));
608 __ LoadConstant(1, Smi::Handle(Smi::New(3)));
609 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
610 __ Div(2, 0, 1);
611 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
612 __ Return(2);
613 }
614
615
616 ASSEMBLER_TEST_RUN(DivNoDeopt, test) {
617 EXPECT_EQ(9, EXECUTE_TEST_CODE_INTPTR(test->code()));
618 }
619
620
621 ASSEMBLER_TEST_GENERATE(DivZero, assembler) {
622 __ Frame(3);
623 __ LoadConstant(0, Smi::Handle(Smi::New(3)));
624 __ LoadConstant(1, Smi::Handle(Smi::New(0)));
625 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
626 __ Div(2, 0, 1);
627 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
628 __ Return(2);
629 }
630
631
632 ASSEMBLER_TEST_RUN(DivZero, test) {
633 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
634 }
635
636
637 ASSEMBLER_TEST_GENERATE(DivCornerCase, assembler) {
638 __ Frame(3);
639 __ LoadConstant(0, Smi::Handle(Smi::New(Smi::kMinValue)));
640 __ LoadConstant(1, Smi::Handle(Smi::New(-1)));
641 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
642 __ Div(2, 0, 1);
643 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
644 __ Return(2);
645 }
646
647
648 ASSEMBLER_TEST_RUN(DivCornerCase, test) {
649 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
650 }
651
652
653 ASSEMBLER_TEST_GENERATE(ModPosPos, assembler) {
654 __ Frame(3);
655 __ LoadConstant(0, Smi::Handle(Smi::New(42)));
656 __ LoadConstant(1, Smi::Handle(Smi::New(4)));
657 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
658 __ Mod(2, 0, 1);
659 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
660 __ Return(2);
661 }
662
663
664 ASSEMBLER_TEST_RUN(ModPosPos, test) {
665 EXPECT_EQ(2, EXECUTE_TEST_CODE_INTPTR(test->code()));
666 }
667
668
669 ASSEMBLER_TEST_GENERATE(ModNegPos, assembler) {
670 __ Frame(3);
671 __ LoadConstant(0, Smi::Handle(Smi::New(-42)));
672 __ LoadConstant(1, Smi::Handle(Smi::New(4)));
673 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
674 __ Mod(2, 0, 1);
675 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
676 __ Return(2);
677 }
678
679
680 ASSEMBLER_TEST_RUN(ModNegPos, test) {
681 EXPECT_EQ(2, EXECUTE_TEST_CODE_INTPTR(test->code()));
682 }
683
684
685 ASSEMBLER_TEST_GENERATE(ModPosNeg, assembler) {
686 __ Frame(3);
687 __ LoadConstant(0, Smi::Handle(Smi::New(42)));
688 __ LoadConstant(1, Smi::Handle(Smi::New(-4)));
689 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
690 __ Mod(2, 0, 1);
691 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
692 __ Return(2);
693 }
694
695
696 ASSEMBLER_TEST_RUN(ModPosNeg, test) {
697 EXPECT_EQ(2, EXECUTE_TEST_CODE_INTPTR(test->code()));
698 }
699
700
701 ASSEMBLER_TEST_GENERATE(ModZero, assembler) {
702 __ Frame(3);
703 __ LoadConstant(0, Smi::Handle(Smi::New(3)));
704 __ LoadConstant(1, Smi::Handle(Smi::New(0)));
705 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
706 __ Mod(2, 0, 1);
707 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
708 __ Return(2);
709 }
710
711
712 ASSEMBLER_TEST_RUN(ModZero, test) {
713 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
714 }
715
716
717 ASSEMBLER_TEST_GENERATE(ShlNoDeopt, assembler) {
718 __ Frame(3);
719 __ LoadConstant(0, Smi::Handle(Smi::New(21)));
720 __ LoadConstant(1, Smi::Handle(Smi::New(1)));
721 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
722 __ Shl(2, 0, 1);
723 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
724 __ Return(2);
725 }
726
727
728 ASSEMBLER_TEST_RUN(ShlNoDeopt, test) {
729 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
730 }
731
732
733 ASSEMBLER_TEST_GENERATE(ShlOverflow, assembler) {
734 __ Frame(3);
735 __ LoadConstant(0, Smi::Handle(Smi::New(Smi::kMaxValue)));
736 __ LoadConstant(1, Smi::Handle(Smi::New(1)));
737 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
738 __ Shl(2, 0, 1);
739 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
740 __ Return(2);
741 }
742
743
744 ASSEMBLER_TEST_RUN(ShlOverflow, test) {
745 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
746 }
747
748
749 ASSEMBLER_TEST_GENERATE(ShlNegShift, assembler) {
750 __ Frame(3);
751 __ LoadConstant(0, Smi::Handle(Smi::New(21)));
752 __ LoadConstant(1, Smi::Handle(Smi::New(-1)));
753 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
754 __ Shl(2, 0, 1);
755 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
756 __ Return(2);
757 }
758
759
760 ASSEMBLER_TEST_RUN(ShlNegShift, test) {
761 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
762 }
763
764
765 ASSEMBLER_TEST_GENERATE(ShrNoDeopt, assembler) {
766 __ Frame(3);
767 __ LoadConstant(0, Smi::Handle(Smi::New(84)));
768 __ LoadConstant(1, Smi::Handle(Smi::New(1)));
769 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
770 __ Shr(2, 0, 1);
771 __ LoadConstant(2, Smi::Handle(Smi::New(-42)));
772 __ Return(2);
773 }
774
775
776 ASSEMBLER_TEST_RUN(ShrNoDeopt, test) {
777 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
778 }
779
780
781 ASSEMBLER_TEST_GENERATE(ShrNegShift, assembler) {
782 __ Frame(3);
783 __ LoadConstant(0, Smi::Handle(Smi::New(21)));
784 __ LoadConstant(1, Smi::Handle(Smi::New(-1)));
785 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
786 __ Shr(2, 0, 1);
787 __ LoadConstant(2, Smi::Handle(Smi::New(42)));
788 __ Return(2);
789 }
790
791
792 ASSEMBLER_TEST_RUN(ShrNegShift, test) {
793 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
794 }
795
796
797 // - BitOr, BitAnd, BitXor rA, rB, rC
798 //
799 // FP[rA] <- FP[rB] op FP[rC]
800 ASSEMBLER_TEST_GENERATE(BitOr, assembler) {
801 __ Frame(3);
802 __ LoadConstant(0, Smi::Handle(Smi::New(0x2)));
803 __ LoadConstant(1, Smi::Handle(Smi::New(0x28)));
804 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
805 __ BitOr(2, 0, 1);
806 __ Return(2);
807 }
808
809
810 ASSEMBLER_TEST_RUN(BitOr, test) {
811 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
812 }
813
814
815 ASSEMBLER_TEST_GENERATE(BitAnd, assembler) {
816 __ Frame(3);
817 __ LoadConstant(0, Smi::Handle(Smi::New(0x2b)));
818 __ LoadConstant(1, Smi::Handle(Smi::New(0x6a)));
819 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
820 __ BitAnd(2, 0, 1);
821 __ Return(2);
822 }
823
824
825 ASSEMBLER_TEST_RUN(BitAnd, test) {
826 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
827 }
828
829
830 ASSEMBLER_TEST_GENERATE(BitXor, assembler) {
831 __ Frame(3);
832 __ LoadConstant(0, Smi::Handle(Smi::New(0x37)));
833 __ LoadConstant(1, Smi::Handle(Smi::New(0x1d)));
834 __ LoadConstant(2, Smi::Handle(Smi::New(-1)));
835 __ BitXor(2, 0, 1);
836 __ Return(2);
837 }
838
839
840 ASSEMBLER_TEST_RUN(BitXor, test) {
841 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
842 }
843
844
487 // - IfNeStrictTOS; IfEqStrictTOS; IfNeStrictNumTOS; IfEqStrictNumTOS 845 // - IfNeStrictTOS; IfEqStrictTOS; IfNeStrictNumTOS; IfEqStrictNumTOS
488 // 846 //
489 // Skips the next instruction unless the given condition holds. 'Num' 847 // Skips the next instruction unless the given condition holds. 'Num'
490 // variants perform number check while non-Num variants just compare 848 // variants perform number check while non-Num variants just compare
491 // RawObject pointers. 849 // RawObject pointers.
492 // 850 //
493 // Used to implement conditional jump: 851 // Used to implement conditional jump:
494 // 852 //
495 // IfNeStrictTOS 853 // IfNeStrictTOS
496 // Jump T ;; jump if not equal 854 // Jump T ;; jump if not equal
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 } 1520 }
1163 1521
1164 1522
1165 ASSEMBLER_TEST_RUN(CheckSmiFail, test) { 1523 ASSEMBLER_TEST_RUN(CheckSmiFail, test) {
1166 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); 1524 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code()));
1167 } 1525 }
1168 1526
1169 } // namespace dart 1527 } // namespace dart
1170 1528
1171 #endif // defined(TARGET_ARCH_DBC) 1529 #endif // defined(TARGET_ARCH_DBC)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698