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 "src/compiler/code-generator.h" | 5 #include "src/compiler/code-generator.h" |
6 #include "src/compiler/code-generator-impl.h" | 6 #include "src/compiler/code-generator-impl.h" |
7 #include "src/compiler/gap-resolver.h" | 7 #include "src/compiler/gap-resolver.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/mips/macro-assembler-mips.h" | 9 #include "src/mips/macro-assembler-mips.h" |
10 #include "src/scopes.h" | 10 #include "src/scopes.h" |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 break; | 848 break; |
849 } | 849 } |
850 } | 850 } |
851 | 851 |
852 | 852 |
853 #define UNSUPPORTED_COND(opcode, condition) \ | 853 #define UNSUPPORTED_COND(opcode, condition) \ |
854 OFStream out(stdout); \ | 854 OFStream out(stdout); \ |
855 out << "Unsupported " << #opcode << " condition: \"" << condition << "\""; \ | 855 out << "Unsupported " << #opcode << " condition: \"" << condition << "\""; \ |
856 UNIMPLEMENTED(); | 856 UNIMPLEMENTED(); |
857 | 857 |
| 858 static bool convertCondition(FlagsCondition condition, Condition& cc, |
| 859 bool& acceptNaN) { |
| 860 acceptNaN = false; |
| 861 switch (condition) { |
| 862 case kEqual: |
| 863 cc = eq; |
| 864 return true; |
| 865 case kNotEqual: |
| 866 cc = ne; |
| 867 acceptNaN = true; |
| 868 return true; |
| 869 case kUnsignedLessThan: |
| 870 cc = lt; |
| 871 return true; |
| 872 case kUnsignedGreaterThanOrEqual: |
| 873 cc = ge; |
| 874 acceptNaN = true; |
| 875 return true; |
| 876 case kUnsignedLessThanOrEqual: |
| 877 cc = le; |
| 878 return true; |
| 879 case kUnsignedGreaterThan: |
| 880 cc = gt; |
| 881 acceptNaN = true; |
| 882 return true; |
| 883 default: |
| 884 break; |
| 885 } |
| 886 return false; |
| 887 } |
| 888 |
| 889 |
858 // Assembles branches after an instruction. | 890 // Assembles branches after an instruction. |
859 void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { | 891 void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { |
860 MipsOperandConverter i(this, instr); | 892 MipsOperandConverter i(this, instr); |
861 Label* tlabel = branch->true_label; | 893 Label* tlabel = branch->true_label; |
862 Label* flabel = branch->false_label; | 894 Label* flabel = branch->false_label; |
863 Condition cc = kNoCondition; | 895 Condition cc = kNoCondition; |
864 | 896 |
865 // MIPS does not have condition code flags, so compare and branch are | 897 // MIPS does not have condition code flags, so compare and branch are |
866 // implemented differently than on the other arch's. The compare operations | 898 // implemented differently than on the other arch's. The compare operations |
867 // emit mips psuedo-instructions, which are handled here by branch | 899 // emit mips psuedo-instructions, which are handled here by branch |
(...skipping 13 matching lines...) Expand all Loading... |
881 __ sra(at, i.OutputRegister(), 31); | 913 __ sra(at, i.OutputRegister(), 31); |
882 __ Branch(tlabel, cc, at, Operand(kScratchReg)); | 914 __ Branch(tlabel, cc, at, Operand(kScratchReg)); |
883 } else if (instr->arch_opcode() == kMips64Cmp) { | 915 } else if (instr->arch_opcode() == kMips64Cmp) { |
884 cc = FlagsConditionToConditionCmp(branch->condition); | 916 cc = FlagsConditionToConditionCmp(branch->condition); |
885 __ Branch(tlabel, cc, i.InputRegister(0), i.InputOperand(1)); | 917 __ Branch(tlabel, cc, i.InputRegister(0), i.InputOperand(1)); |
886 | 918 |
887 if (!branch->fallthru) __ Branch(flabel); // no fallthru to flabel. | 919 if (!branch->fallthru) __ Branch(flabel); // no fallthru to flabel. |
888 } else if (instr->arch_opcode() == kMips64CmpS) { | 920 } else if (instr->arch_opcode() == kMips64CmpS) { |
889 // TODO(dusmil) optimize unordered checks to use fewer instructions | 921 // TODO(dusmil) optimize unordered checks to use fewer instructions |
890 // even if we have to unfold BranchF macro. | 922 // even if we have to unfold BranchF macro. |
891 Label* nan = flabel; | 923 bool acceptNaN = false; |
892 switch (branch->condition) { | 924 if (!convertCondition(branch->condition, cc, acceptNaN)) { |
893 case kEqual: | 925 UNSUPPORTED_COND(kMips64CmpS, branch->condition); |
894 cc = eq; | |
895 break; | |
896 case kNotEqual: | |
897 cc = ne; | |
898 nan = tlabel; | |
899 break; | |
900 case kUnsignedLessThan: | |
901 cc = lt; | |
902 break; | |
903 case kUnsignedGreaterThanOrEqual: | |
904 cc = ge; | |
905 nan = tlabel; | |
906 break; | |
907 case kUnsignedLessThanOrEqual: | |
908 cc = le; | |
909 break; | |
910 case kUnsignedGreaterThan: | |
911 cc = gt; | |
912 nan = tlabel; | |
913 break; | |
914 default: | |
915 UNSUPPORTED_COND(kMips64CmpS, branch->condition); | |
916 break; | |
917 } | 926 } |
918 __ BranchFS(tlabel, nan, cc, i.InputDoubleRegister(0), | 927 Label* nan = acceptNaN ? tlabel : flabel; |
919 i.InputDoubleRegister(1)); | 928 __ BranchFS(tlabel, nan, cc, i.InputSingleRegister(0), |
| 929 i.InputSingleRegister(1)); |
920 | 930 |
921 if (!branch->fallthru) __ Branch(flabel); // no fallthru to flabel. | 931 if (!branch->fallthru) __ Branch(flabel); // no fallthru to flabel. |
922 | 932 |
923 } else if (instr->arch_opcode() == kMips64CmpD) { | 933 } else if (instr->arch_opcode() == kMips64CmpD) { |
924 // TODO(dusmil) optimize unordered checks to use less instructions | 934 // TODO(dusmil) optimize unordered checks to use less instructions |
925 // even if we have to unfold BranchF macro. | 935 // even if we have to unfold BranchF macro. |
926 Label* nan = flabel; | 936 bool acceptNaN = false; |
927 switch (branch->condition) { | 937 if (!convertCondition(branch->condition, cc, acceptNaN)) { |
928 case kEqual: | 938 UNSUPPORTED_COND(kMips64CmpD, branch->condition); |
929 cc = eq; | |
930 break; | |
931 case kNotEqual: | |
932 cc = ne; | |
933 nan = tlabel; | |
934 break; | |
935 case kUnsignedLessThan: | |
936 cc = lt; | |
937 break; | |
938 case kUnsignedGreaterThanOrEqual: | |
939 cc = ge; | |
940 nan = tlabel; | |
941 break; | |
942 case kUnsignedLessThanOrEqual: | |
943 cc = le; | |
944 break; | |
945 case kUnsignedGreaterThan: | |
946 cc = gt; | |
947 nan = tlabel; | |
948 break; | |
949 default: | |
950 UNSUPPORTED_COND(kMips64CmpD, branch->condition); | |
951 break; | |
952 } | 939 } |
| 940 Label* nan = acceptNaN ? tlabel : flabel; |
953 __ BranchF(tlabel, nan, cc, i.InputDoubleRegister(0), | 941 __ BranchF(tlabel, nan, cc, i.InputDoubleRegister(0), |
954 i.InputDoubleRegister(1)); | 942 i.InputDoubleRegister(1)); |
955 | 943 |
956 if (!branch->fallthru) __ Branch(flabel); // no fallthru to flabel. | 944 if (!branch->fallthru) __ Branch(flabel); // no fallthru to flabel. |
957 } else { | 945 } else { |
958 PrintF("AssembleArchBranch Unimplemented arch_opcode: %d\n", | 946 PrintF("AssembleArchBranch Unimplemented arch_opcode: %d\n", |
959 instr->arch_opcode()); | 947 instr->arch_opcode()); |
960 UNIMPLEMENTED(); | 948 UNIMPLEMENTED(); |
961 } | 949 } |
962 } | 950 } |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 } | 1350 } |
1363 } | 1351 } |
1364 MarkLazyDeoptSite(); | 1352 MarkLazyDeoptSite(); |
1365 } | 1353 } |
1366 | 1354 |
1367 #undef __ | 1355 #undef __ |
1368 | 1356 |
1369 } // namespace compiler | 1357 } // namespace compiler |
1370 } // namespace internal | 1358 } // namespace internal |
1371 } // namespace v8 | 1359 } // namespace v8 |
OLD | NEW |