OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 } | 841 } |
842 } | 842 } |
843 | 843 |
844 | 844 |
845 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { | 845 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
846 // Nothing to do. | 846 // Nothing to do. |
847 } | 847 } |
848 | 848 |
849 | 849 |
850 void LCodeGen::DoModI(LModI* instr) { | 850 void LCodeGen::DoModI(LModI* instr) { |
851 Abort("DoModI unimplemented."); | 851 class DeferredModI: public LDeferredCode { |
| 852 public: |
| 853 DeferredModI(LCodeGen* codegen, LModI* instr) |
| 854 : LDeferredCode(codegen), instr_(instr) { } |
| 855 virtual void Generate() { |
| 856 codegen()->DoDeferredGenericBinaryStub(instr_, Token::MOD); |
| 857 } |
| 858 private: |
| 859 LModI* instr_; |
| 860 }; |
| 861 // These registers hold untagged 32 bit values. |
| 862 Register left = ToRegister(instr->left()); |
| 863 Register right = ToRegister(instr->right()); |
| 864 Register result = ToRegister(instr->result()); |
| 865 Register scratch = scratch0(); |
| 866 |
| 867 Label deoptimize, done; |
| 868 // Check for x % 0. |
| 869 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 870 __ tst(right, Operand(right)); |
| 871 __ b(eq, &deoptimize); |
| 872 } |
| 873 |
| 874 // Check for (0 % -x) that will produce negative zero. |
| 875 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 876 Label ok; |
| 877 __ tst(left, Operand(left)); |
| 878 __ b(ne, &ok); |
| 879 __ tst(right, Operand(right)); |
| 880 __ b(pl, &ok); |
| 881 __ b(al, &deoptimize); |
| 882 __ bind(&ok); |
| 883 } |
| 884 |
| 885 // Call the generic stub. The numbers in r0 and r1 have |
| 886 // to be tagged to Smis. If that is not possible, deoptimize. |
| 887 DeferredModI* deferred = new DeferredModI(this, instr); |
| 888 __ TrySmiTag(left, &deoptimize, scratch); |
| 889 __ TrySmiTag(right, &deoptimize, scratch); |
| 890 |
| 891 __ b(al, deferred->entry()); |
| 892 __ bind(deferred->exit()); |
| 893 |
| 894 // If the result in r0 is a Smi, untag it, else deoptimize. |
| 895 __ BranchOnNotSmi(result, &deoptimize); |
| 896 __ mov(result, Operand(result, ASR, 1)); |
| 897 |
| 898 __ b(al, &done); |
| 899 __ bind(&deoptimize); |
| 900 DeoptimizeIf(al, instr->environment()); |
| 901 __ bind(&done); |
852 } | 902 } |
853 | 903 |
854 | 904 |
855 void LCodeGen::DoDivI(LDivI* instr) { | 905 void LCodeGen::DoDivI(LDivI* instr) { |
856 class DeferredDivI: public LDeferredCode { | 906 class DeferredDivI: public LDeferredCode { |
857 public: | 907 public: |
858 DeferredDivI(LCodeGen* codegen, LDivI* instr) | 908 DeferredDivI(LCodeGen* codegen, LDivI* instr) |
859 : LDeferredCode(codegen), instr_(instr) { } | 909 : LDeferredCode(codegen), instr_(instr) { } |
860 virtual void Generate() { codegen()->DoDeferredDivI(instr_); } | 910 virtual void Generate() { |
| 911 codegen()->DoDeferredGenericBinaryStub(instr_, Token::DIV); |
| 912 } |
861 private: | 913 private: |
862 LDivI* instr_; | 914 LDivI* instr_; |
863 }; | 915 }; |
864 | 916 |
865 const Register left = ToRegister(instr->left()); | 917 const Register left = ToRegister(instr->left()); |
866 const Register right = ToRegister(instr->right()); | 918 const Register right = ToRegister(instr->right()); |
867 const Register scratch = scratch0(); | 919 const Register scratch = scratch0(); |
868 const Register result = ToRegister(instr->result()); | 920 const Register result = ToRegister(instr->result()); |
869 | 921 |
870 // Check for x / 0. | 922 // Check for x / 0. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 __ BranchOnNotSmi(result, &deoptimize); | 975 __ BranchOnNotSmi(result, &deoptimize); |
924 __ SmiUntag(result); | 976 __ SmiUntag(result); |
925 __ b(&done); | 977 __ b(&done); |
926 | 978 |
927 __ bind(&deoptimize); | 979 __ bind(&deoptimize); |
928 DeoptimizeIf(al, instr->environment()); | 980 DeoptimizeIf(al, instr->environment()); |
929 __ bind(&done); | 981 __ bind(&done); |
930 } | 982 } |
931 | 983 |
932 | 984 |
933 void LCodeGen::DoDeferredDivI(LDivI* instr) { | 985 void LCodeGen::DoDeferredGenericBinaryStub(LBinaryOperation* instr, |
| 986 Token::Value op) { |
934 Register left = ToRegister(instr->left()); | 987 Register left = ToRegister(instr->left()); |
935 Register right = ToRegister(instr->right()); | 988 Register right = ToRegister(instr->right()); |
936 | 989 |
937 __ PushSafepointRegistersAndDoubles(); | 990 __ PushSafepointRegistersAndDoubles(); |
938 GenericBinaryOpStub stub(Token::DIV, OVERWRITE_LEFT, left, right); | 991 GenericBinaryOpStub stub(op, OVERWRITE_LEFT, left, right); |
939 __ CallStub(&stub); | 992 __ CallStub(&stub); |
940 RecordSafepointWithRegisters(instr->pointer_map(), | 993 RecordSafepointWithRegisters(instr->pointer_map(), |
941 0, | 994 0, |
942 Safepoint::kNoDeoptimizationIndex); | 995 Safepoint::kNoDeoptimizationIndex); |
943 // Overwrite the stored value of r0 with the result of the stub. | 996 // Overwrite the stored value of r0 with the result of the stub. |
944 __ str(r0, MemOperand(sp, DwVfpRegister::kNumAllocatableRegisters * | 997 __ str(r0, MemOperand(sp, DwVfpRegister::kNumAllocatableRegisters * |
945 kDoubleSize)); | 998 kDoubleSize)); |
946 __ PopSafepointRegistersAndDoubles(); | 999 __ PopSafepointRegistersAndDoubles(); |
947 } | 1000 } |
948 | 1001 |
(...skipping 2024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2973 | 3026 |
2974 | 3027 |
2975 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { | 3028 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
2976 Abort("DoOsrEntry unimplemented."); | 3029 Abort("DoOsrEntry unimplemented."); |
2977 } | 3030 } |
2978 | 3031 |
2979 | 3032 |
2980 #undef __ | 3033 #undef __ |
2981 | 3034 |
2982 } } // namespace v8::internal | 3035 } } // namespace v8::internal |
OLD | NEW |