Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/interpreter.h" | 5 #include "src/interpreter/interpreter.h" |
| 6 | 6 |
| 7 #include <fstream> | 7 #include <fstream> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 Node* rhs = __ GetAccumulator(); | 769 Node* rhs = __ GetAccumulator(); |
| 770 Node* context = __ GetContext(); | 770 Node* context = __ GetContext(); |
| 771 Node* slot_index = __ BytecodeOperandIdx(1); | 771 Node* slot_index = __ BytecodeOperandIdx(1); |
| 772 Node* type_feedback_vector = __ LoadTypeFeedbackVector(); | 772 Node* type_feedback_vector = __ LoadTypeFeedbackVector(); |
| 773 Node* result = Generator::Generate(assembler, lhs, rhs, context, | 773 Node* result = Generator::Generate(assembler, lhs, rhs, context, |
| 774 type_feedback_vector, slot_index); | 774 type_feedback_vector, slot_index); |
| 775 __ SetAccumulator(result); | 775 __ SetAccumulator(result); |
| 776 __ Dispatch(); | 776 __ Dispatch(); |
| 777 } | 777 } |
| 778 | 778 |
| 779 template <class Generator> | |
| 780 void Interpreter::DoBitwiseBinaryOpAndCollectFeedback( | |
| 781 InterpreterAssembler* assembler) { | |
| 782 Node* reg_index = __ BytecodeOperandReg(0); | |
| 783 Node* lhs = __ LoadRegister(reg_index); | |
| 784 Node* rhs = __ GetAccumulator(); | |
| 785 Node* context = __ GetContext(); | |
| 786 Node* slot_index = __ BytecodeOperandIdx(1); | |
| 787 Node* type_feedback_vector = __ LoadTypeFeedbackVector(); | |
| 788 | |
| 789 typedef InterpreterAssembler::Label Label; | |
| 790 typedef InterpreterAssembler::Variable Variable; | |
| 791 | |
| 792 Variable var_type_feedback(assembler, MachineRepresentation::kWord32); | |
| 793 Label lhs_is_smi(assembler), lhs_is_not_smi(assembler), | |
| 794 collect_rhs_type(assembler); | |
| 795 | |
| 796 __ BranchIf(__ WordIsSmi(lhs), &lhs_is_smi, &lhs_is_not_smi); | |
| 797 __ Bind(&lhs_is_smi); | |
| 798 { | |
| 799 var_type_feedback.Bind( | |
| 800 __ Int32Constant(BinaryOperationFeedback::kSignedSmall)); | |
| 801 __ Goto(&collect_rhs_type); | |
| 802 } | |
| 803 | |
| 804 __ Bind(&lhs_is_not_smi); | |
| 805 { | |
| 806 Node* lhs_map = __ LoadMap(lhs); | |
| 807 Node* type = __ Select(__ WordEqual(lhs_map, __ HeapNumberMapConstant()), | |
| 808 __ Int32Constant(BinaryOperationFeedback::kNumber), | |
|
Benedikt Meurer
2016/08/11 09:32:21
We should probably recognize kSigned32 here as wel
epertoso
2016/08/11 12:18:57
We don't have kSigned32 in BinaryOperationFeedback
| |
| 809 __ Int32Constant(BinaryOperationFeedback::kAny)); | |
| 810 var_type_feedback.Bind(type); | |
| 811 __ Goto(&collect_rhs_type); | |
| 812 } | |
| 813 | |
| 814 __ Bind(&collect_rhs_type); | |
| 815 Label rhs_is_smi(assembler), rhs_is_not_smi(assembler), | |
| 816 do_binary_op(assembler); | |
| 817 __ BranchIf(__ WordIsSmi(rhs), &rhs_is_smi, &rhs_is_not_smi); | |
| 818 __ Bind(&rhs_is_smi); | |
| 819 { | |
| 820 var_type_feedback.Bind( | |
| 821 __ Word32Or(var_type_feedback.value(), | |
| 822 __ Int32Constant(BinaryOperationFeedback::kSignedSmall))); | |
| 823 __ Goto(&do_binary_op); | |
| 824 } | |
| 825 | |
| 826 __ Bind(&rhs_is_not_smi); | |
| 827 { | |
| 828 Node* rhs_map = __ LoadMap(rhs); | |
| 829 Node* type = __ Select(__ WordEqual(rhs_map, __ HeapNumberMapConstant()), | |
| 830 __ Int32Constant(BinaryOperationFeedback::kNumber), | |
|
Benedikt Meurer
2016/08/11 09:32:21
See comment above.
epertoso
2016/08/11 12:18:57
See answer above.
| |
| 831 __ Int32Constant(BinaryOperationFeedback::kAny)); | |
| 832 var_type_feedback.Bind(__ Word32Or(var_type_feedback.value(), type)); | |
| 833 __ Goto(&do_binary_op); | |
| 834 } | |
| 835 | |
| 836 __ Bind(&do_binary_op); | |
| 837 Node* result = Generator::Generate(assembler, lhs, rhs, context); | |
| 838 | |
| 839 // Bitwise binary ops return 32-bit values. | |
| 840 Node* result_type = | |
| 841 __ Select(__ WordIsSmi(result), | |
| 842 __ Int32Constant(BinaryOperationFeedback::kSignedSmall), | |
| 843 __ Int32Constant(BinaryOperationFeedback::kNumber)); | |
|
Benedikt Meurer
2016/08/11 09:32:21
s/kNumber/kSigned32
epertoso
2016/08/11 12:18:57
There's no kSigned32 constant.
| |
| 844 | |
| 845 if (FLAG_debug_code) { | |
| 846 Label ok(assembler); | |
| 847 __ GotoIf(__ WordIsSmi(result), &ok); | |
| 848 Node* result_map = __ LoadMap(result); | |
| 849 __ AbortIfWordNotEqual(result_map, __ HeapNumberMapConstant(), | |
| 850 kExpectedHeapNumber); | |
| 851 __ Bind(&ok); | |
| 852 } | |
| 853 __ UpdateFeedback(__ Word32Or(result_type, var_type_feedback.value()), | |
| 854 type_feedback_vector, slot_index); | |
| 855 | |
| 856 __ SetAccumulator(result); | |
| 857 __ Dispatch(); | |
| 858 } | |
| 859 | |
| 779 // Add <src> | 860 // Add <src> |
| 780 // | 861 // |
| 781 // Add register <src> to accumulator. | 862 // Add register <src> to accumulator. |
| 782 void Interpreter::DoAdd(InterpreterAssembler* assembler) { | 863 void Interpreter::DoAdd(InterpreterAssembler* assembler) { |
| 783 DoBinaryOpWithFeedback<AddWithFeedbackStub>(assembler); | 864 DoBinaryOpWithFeedback<AddWithFeedbackStub>(assembler); |
| 784 } | 865 } |
| 785 | 866 |
| 786 // Sub <src> | 867 // Sub <src> |
| 787 // | 868 // |
| 788 // Subtract register <src> from accumulator. | 869 // Subtract register <src> from accumulator. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 808 // | 889 // |
| 809 // Modulo register <src> by accumulator. | 890 // Modulo register <src> by accumulator. |
| 810 void Interpreter::DoMod(InterpreterAssembler* assembler) { | 891 void Interpreter::DoMod(InterpreterAssembler* assembler) { |
| 811 DoBinaryOpWithFeedback<ModulusWithFeedbackStub>(assembler); | 892 DoBinaryOpWithFeedback<ModulusWithFeedbackStub>(assembler); |
| 812 } | 893 } |
| 813 | 894 |
| 814 // BitwiseOr <src> | 895 // BitwiseOr <src> |
| 815 // | 896 // |
| 816 // BitwiseOr register <src> to accumulator. | 897 // BitwiseOr register <src> to accumulator. |
| 817 void Interpreter::DoBitwiseOr(InterpreterAssembler* assembler) { | 898 void Interpreter::DoBitwiseOr(InterpreterAssembler* assembler) { |
| 818 DoBinaryOp<BitwiseOrStub>(assembler); | 899 DoBitwiseBinaryOpAndCollectFeedback<BitwiseOrStub>(assembler); |
| 819 } | 900 } |
| 820 | 901 |
| 821 // BitwiseXor <src> | 902 // BitwiseXor <src> |
| 822 // | 903 // |
| 823 // BitwiseXor register <src> to accumulator. | 904 // BitwiseXor register <src> to accumulator. |
| 824 void Interpreter::DoBitwiseXor(InterpreterAssembler* assembler) { | 905 void Interpreter::DoBitwiseXor(InterpreterAssembler* assembler) { |
| 825 DoBinaryOp<BitwiseXorStub>(assembler); | 906 DoBitwiseBinaryOpAndCollectFeedback<BitwiseXorStub>(assembler); |
| 826 } | 907 } |
| 827 | 908 |
| 828 // BitwiseAnd <src> | 909 // BitwiseAnd <src> |
| 829 // | 910 // |
| 830 // BitwiseAnd register <src> to accumulator. | 911 // BitwiseAnd register <src> to accumulator. |
| 831 void Interpreter::DoBitwiseAnd(InterpreterAssembler* assembler) { | 912 void Interpreter::DoBitwiseAnd(InterpreterAssembler* assembler) { |
| 832 DoBinaryOp<BitwiseAndStub>(assembler); | 913 DoBitwiseBinaryOpAndCollectFeedback<BitwiseAndStub>(assembler); |
| 833 } | 914 } |
| 834 | 915 |
| 835 // ShiftLeft <src> | 916 // ShiftLeft <src> |
| 836 // | 917 // |
| 837 // Left shifts register <src> by the count specified in the accumulator. | 918 // Left shifts register <src> by the count specified in the accumulator. |
| 838 // Register <src> is converted to an int32 and the accumulator to uint32 | 919 // Register <src> is converted to an int32 and the accumulator to uint32 |
| 839 // before the operation. 5 lsb bits from the accumulator are used as count | 920 // before the operation. 5 lsb bits from the accumulator are used as count |
| 840 // i.e. <src> << (accumulator & 0x1F). | 921 // i.e. <src> << (accumulator & 0x1F). |
| 841 void Interpreter::DoShiftLeft(InterpreterAssembler* assembler) { | 922 void Interpreter::DoShiftLeft(InterpreterAssembler* assembler) { |
| 842 DoBinaryOp<ShiftLeftStub>(assembler); | 923 DoBitwiseBinaryOpAndCollectFeedback<ShiftLeftStub>(assembler); |
| 843 } | 924 } |
| 844 | 925 |
| 845 // ShiftRight <src> | 926 // ShiftRight <src> |
| 846 // | 927 // |
| 847 // Right shifts register <src> by the count specified in the accumulator. | 928 // Right shifts register <src> by the count specified in the accumulator. |
| 848 // Result is sign extended. Register <src> is converted to an int32 and the | 929 // Result is sign extended. Register <src> is converted to an int32 and the |
| 849 // accumulator to uint32 before the operation. 5 lsb bits from the accumulator | 930 // accumulator to uint32 before the operation. 5 lsb bits from the accumulator |
| 850 // are used as count i.e. <src> >> (accumulator & 0x1F). | 931 // are used as count i.e. <src> >> (accumulator & 0x1F). |
| 851 void Interpreter::DoShiftRight(InterpreterAssembler* assembler) { | 932 void Interpreter::DoShiftRight(InterpreterAssembler* assembler) { |
| 852 DoBinaryOp<ShiftRightStub>(assembler); | 933 DoBitwiseBinaryOpAndCollectFeedback<ShiftRightStub>(assembler); |
| 853 } | 934 } |
| 854 | 935 |
| 855 // ShiftRightLogical <src> | 936 // ShiftRightLogical <src> |
| 856 // | 937 // |
| 857 // Right Shifts register <src> by the count specified in the accumulator. | 938 // Right Shifts register <src> by the count specified in the accumulator. |
| 858 // Result is zero-filled. The accumulator and register <src> are converted to | 939 // Result is zero-filled. The accumulator and register <src> are converted to |
| 859 // uint32 before the operation 5 lsb bits from the accumulator are used as | 940 // uint32 before the operation 5 lsb bits from the accumulator are used as |
| 860 // count i.e. <src> << (accumulator & 0x1F). | 941 // count i.e. <src> << (accumulator & 0x1F). |
| 861 void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) { | 942 void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) { |
| 862 DoBinaryOp<ShiftRightLogicalStub>(assembler); | 943 DoBitwiseBinaryOpAndCollectFeedback<ShiftRightLogicalStub>(assembler); |
| 863 } | 944 } |
| 864 | 945 |
| 865 // AddSmi <imm> <reg> | 946 // AddSmi <imm> <reg> |
| 866 // | 947 // |
| 867 // Adds an immediate value <imm> to register <reg>. For this | 948 // Adds an immediate value <imm> to register <reg>. For this |
| 868 // operation <reg> is the lhs operand and <imm> is the <rhs> operand. | 949 // operation <reg> is the lhs operand and <imm> is the <rhs> operand. |
| 869 void Interpreter::DoAddSmi(InterpreterAssembler* assembler) { | 950 void Interpreter::DoAddSmi(InterpreterAssembler* assembler) { |
| 870 Variable var_result(assembler, MachineRepresentation::kTagged); | 951 Variable var_result(assembler, MachineRepresentation::kTagged); |
| 871 Label fastpath(assembler), slowpath(assembler, Label::kDeferred), | 952 Label fastpath(assembler), slowpath(assembler, Label::kDeferred), |
| 872 end(assembler); | 953 end(assembler); |
| (...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2163 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 2244 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
| 2164 __ SmiTag(new_state)); | 2245 __ SmiTag(new_state)); |
| 2165 __ SetAccumulator(old_state); | 2246 __ SetAccumulator(old_state); |
| 2166 | 2247 |
| 2167 __ Dispatch(); | 2248 __ Dispatch(); |
| 2168 } | 2249 } |
| 2169 | 2250 |
| 2170 } // namespace interpreter | 2251 } // namespace interpreter |
| 2171 } // namespace internal | 2252 } // namespace internal |
| 2172 } // namespace v8 | 2253 } // namespace v8 |
| OLD | NEW |