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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 safepoint.DefinePointerSlot(pointer->index()); | 607 safepoint.DefinePointerSlot(pointer->index()); |
608 } else if (pointer->IsRegister()) { | 608 } else if (pointer->IsRegister()) { |
609 safepoint.DefinePointerRegister(ToRegister(pointer)); | 609 safepoint.DefinePointerRegister(ToRegister(pointer)); |
610 } | 610 } |
611 } | 611 } |
612 // Register cp always contains a pointer to the context. | 612 // Register cp always contains a pointer to the context. |
613 safepoint.DefinePointerRegister(cp); | 613 safepoint.DefinePointerRegister(cp); |
614 } | 614 } |
615 | 615 |
616 | 616 |
| 617 void LCodeGen::RecordSafepointWithRegistersAndDoubles( |
| 618 LPointerMap* pointers, |
| 619 int arguments, |
| 620 int deoptimization_index) { |
| 621 const ZoneList<LOperand*>* operands = pointers->operands(); |
| 622 Safepoint safepoint = |
| 623 safepoints_.DefineSafepointWithRegistersAndDoubles( |
| 624 masm(), arguments, deoptimization_index); |
| 625 for (int i = 0; i < operands->length(); i++) { |
| 626 LOperand* pointer = operands->at(i); |
| 627 if (pointer->IsStackSlot()) { |
| 628 safepoint.DefinePointerSlot(pointer->index()); |
| 629 } else if (pointer->IsRegister()) { |
| 630 safepoint.DefinePointerRegister(ToRegister(pointer)); |
| 631 } |
| 632 } |
| 633 // Register cp always contains a pointer to the context. |
| 634 safepoint.DefinePointerRegister(cp); |
| 635 } |
| 636 |
| 637 |
617 void LCodeGen::RecordPosition(int position) { | 638 void LCodeGen::RecordPosition(int position) { |
618 if (!FLAG_debug_info || position == RelocInfo::kNoPosition) return; | 639 if (!FLAG_debug_info || position == RelocInfo::kNoPosition) return; |
619 masm()->positions_recorder()->RecordPosition(position); | 640 masm()->positions_recorder()->RecordPosition(position); |
620 } | 641 } |
621 | 642 |
622 | 643 |
623 void LCodeGen::DoLabel(LLabel* label) { | 644 void LCodeGen::DoLabel(LLabel* label) { |
624 if (label->is_loop_header()) { | 645 if (label->is_loop_header()) { |
625 Comment(";;; B%d - LOOP entry", label->block_id()); | 646 Comment(";;; B%d - LOOP entry", label->block_id()); |
626 } else { | 647 } else { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 // Nothing to do. | 846 // Nothing to do. |
826 } | 847 } |
827 | 848 |
828 | 849 |
829 void LCodeGen::DoModI(LModI* instr) { | 850 void LCodeGen::DoModI(LModI* instr) { |
830 Abort("DoModI unimplemented."); | 851 Abort("DoModI unimplemented."); |
831 } | 852 } |
832 | 853 |
833 | 854 |
834 void LCodeGen::DoDivI(LDivI* instr) { | 855 void LCodeGen::DoDivI(LDivI* instr) { |
835 Abort("DoDivI unimplemented."); | 856 class DeferredDivI: public LDeferredCode { |
| 857 public: |
| 858 DeferredDivI(LCodeGen* codegen, LDivI* instr) |
| 859 : LDeferredCode(codegen), instr_(instr) { } |
| 860 virtual void Generate() { codegen()->DoDeferredDivI(instr_); } |
| 861 private: |
| 862 LDivI* instr_; |
| 863 }; |
| 864 |
| 865 const Register left = ToRegister(instr->left()); |
| 866 const Register right = ToRegister(instr->right()); |
| 867 const Register scratch = scratch0(); |
| 868 const Register result = ToRegister(instr->result()); |
| 869 |
| 870 // Check for x / 0. |
| 871 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 872 __ tst(right, right); |
| 873 DeoptimizeIf(eq, instr->environment()); |
| 874 } |
| 875 |
| 876 // Check for (0 / -x) that will produce negative zero. |
| 877 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 878 Label left_not_zero; |
| 879 __ tst(left, Operand(left)); |
| 880 __ b(ne, &left_not_zero); |
| 881 __ tst(right, Operand(right)); |
| 882 DeoptimizeIf(mi, instr->environment()); |
| 883 __ bind(&left_not_zero); |
| 884 } |
| 885 |
| 886 // Check for (-kMinInt / -1). |
| 887 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 888 Label left_not_min_int; |
| 889 __ cmp(left, Operand(kMinInt)); |
| 890 __ b(ne, &left_not_min_int); |
| 891 __ cmp(right, Operand(-1)); |
| 892 DeoptimizeIf(eq, instr->environment()); |
| 893 __ bind(&left_not_min_int); |
| 894 } |
| 895 |
| 896 Label done, deoptimize; |
| 897 // Test for a few common cases first. |
| 898 __ cmp(right, Operand(1)); |
| 899 __ mov(result, left, LeaveCC, eq); |
| 900 __ b(eq, &done); |
| 901 |
| 902 __ cmp(right, Operand(2)); |
| 903 __ tst(left, Operand(1), eq); |
| 904 __ mov(result, Operand(left, ASR, 1), LeaveCC, eq); |
| 905 __ b(eq, &done); |
| 906 |
| 907 __ cmp(right, Operand(4)); |
| 908 __ tst(left, Operand(3), eq); |
| 909 __ mov(result, Operand(left, ASR, 2), LeaveCC, eq); |
| 910 __ b(eq, &done); |
| 911 |
| 912 // Call the generic stub. The numbers in r0 and r1 have |
| 913 // to be tagged to Smis. If that is not possible, deoptimize. |
| 914 DeferredDivI* deferred = new DeferredDivI(this, instr); |
| 915 |
| 916 __ TrySmiTag(left, &deoptimize, scratch); |
| 917 __ TrySmiTag(right, &deoptimize, scratch); |
| 918 |
| 919 __ b(al, deferred->entry()); |
| 920 __ bind(deferred->exit()); |
| 921 |
| 922 // If the result in r0 is a Smi, untag it, else deoptimize. |
| 923 __ BranchOnNotSmi(result, &deoptimize); |
| 924 __ SmiUntag(result); |
| 925 __ b(&done); |
| 926 |
| 927 __ bind(&deoptimize); |
| 928 DeoptimizeIf(al, instr->environment()); |
| 929 __ bind(&done); |
836 } | 930 } |
837 | 931 |
838 | 932 |
| 933 void LCodeGen::DoDeferredDivI(LDivI* instr) { |
| 934 Register left = ToRegister(instr->left()); |
| 935 Register right = ToRegister(instr->right()); |
| 936 |
| 937 __ PushSafepointRegistersAndDoubles(); |
| 938 GenericBinaryOpStub stub(Token::DIV, OVERWRITE_LEFT, left, right); |
| 939 __ CallStub(&stub); |
| 940 RecordSafepointWithRegisters(instr->pointer_map(), |
| 941 0, |
| 942 Safepoint::kNoDeoptimizationIndex); |
| 943 // Overwrite the stored value of r0 with the result of the stub. |
| 944 __ str(r0, MemOperand(sp, DwVfpRegister::kNumAllocatableRegisters * |
| 945 kDoubleSize)); |
| 946 __ PopSafepointRegistersAndDoubles(); |
| 947 } |
| 948 |
| 949 |
839 void LCodeGen::DoMulI(LMulI* instr) { | 950 void LCodeGen::DoMulI(LMulI* instr) { |
840 Register scratch = scratch0(); | 951 Register scratch = scratch0(); |
841 Register left = ToRegister(instr->left()); | 952 Register left = ToRegister(instr->left()); |
842 Register right = EmitLoadRegister(instr->right(), scratch); | 953 Register right = EmitLoadRegister(instr->right(), scratch); |
843 | 954 |
844 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero) && | 955 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero) && |
845 !instr->right()->IsConstantOperand()) { | 956 !instr->right()->IsConstantOperand()) { |
846 __ orr(ToRegister(instr->temp()), left, right); | 957 __ orr(ToRegister(instr->temp()), left, right); |
847 } | 958 } |
848 | 959 |
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2830 | 2941 |
2831 | 2942 |
2832 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { | 2943 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
2833 Abort("DoOsrEntry unimplemented."); | 2944 Abort("DoOsrEntry unimplemented."); |
2834 } | 2945 } |
2835 | 2946 |
2836 | 2947 |
2837 #undef __ | 2948 #undef __ |
2838 | 2949 |
2839 } } // namespace v8::internal | 2950 } } // namespace v8::internal |
OLD | NEW |