| 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 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 } | 774 } |
| 775 } | 775 } |
| 776 | 776 |
| 777 | 777 |
| 778 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { | 778 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 779 // Nothing to do. | 779 // Nothing to do. |
| 780 } | 780 } |
| 781 | 781 |
| 782 | 782 |
| 783 void LCodeGen::DoModI(LModI* instr) { | 783 void LCodeGen::DoModI(LModI* instr) { |
| 784 LOperand* right = instr->InputAt(1); | 784 if (instr->hydrogen()->HasPowerOf2Divisor()) { |
| 785 ASSERT(ToRegister(instr->result()).is(edx)); | 785 Register dividend = ToRegister(instr->InputAt(0)); |
| 786 ASSERT(ToRegister(instr->InputAt(0)).is(eax)); | |
| 787 ASSERT(!ToRegister(instr->InputAt(1)).is(eax)); | |
| 788 ASSERT(!ToRegister(instr->InputAt(1)).is(edx)); | |
| 789 | 786 |
| 790 Register right_reg = ToRegister(right); | 787 int32_t divisor = |
| 788 HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
| 791 | 789 |
| 792 // Check for x % 0. | 790 if (divisor < 0) divisor = -divisor; |
| 793 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | |
| 794 __ test(right_reg, ToOperand(right)); | |
| 795 DeoptimizeIf(zero, instr->environment()); | |
| 796 } | |
| 797 | 791 |
| 798 // Sign extend to edx. | 792 NearLabel positive_dividend, done; |
| 799 __ cdq(); | 793 __ test(dividend, Operand(dividend)); |
| 800 | 794 __ j(not_sign, &positive_dividend); |
| 801 // Check for (0 % -x) that will produce negative zero. | 795 __ neg(dividend); |
| 802 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 796 __ and_(dividend, divisor - 1); |
| 803 NearLabel positive_left; | 797 __ neg(dividend); |
| 804 NearLabel done; | 798 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 805 __ test(eax, Operand(eax)); | 799 __ j(not_zero, &done); |
| 806 __ j(not_sign, &positive_left); | 800 DeoptimizeIf(no_condition, instr->environment()); |
| 807 __ idiv(right_reg); | 801 } |
| 808 | 802 __ bind(&positive_dividend); |
| 809 // Test the remainder for 0, because then the result would be -0. | 803 __ and_(dividend, divisor - 1); |
| 810 __ test(edx, Operand(edx)); | |
| 811 __ j(not_zero, &done); | |
| 812 | |
| 813 DeoptimizeIf(no_condition, instr->environment()); | |
| 814 __ bind(&positive_left); | |
| 815 __ idiv(right_reg); | |
| 816 __ bind(&done); | 804 __ bind(&done); |
| 817 } else { | 805 } else { |
| 818 __ idiv(right_reg); | 806 LOperand* right = instr->InputAt(1); |
| 807 ASSERT(ToRegister(instr->InputAt(0)).is(eax)); |
| 808 ASSERT(ToRegister(instr->result()).is(edx)); |
| 809 |
| 810 Register right_reg = ToRegister(right); |
| 811 ASSERT(!right_reg.is(eax)); |
| 812 ASSERT(!right_reg.is(edx)); |
| 813 |
| 814 // Check for x % 0. |
| 815 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 816 __ test(right_reg, ToOperand(right)); |
| 817 DeoptimizeIf(zero, instr->environment()); |
| 818 } |
| 819 |
| 820 // Sign extend to edx. |
| 821 __ cdq(); |
| 822 |
| 823 // Check for (0 % -x) that will produce negative zero. |
| 824 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 825 NearLabel positive_left; |
| 826 NearLabel done; |
| 827 __ test(eax, Operand(eax)); |
| 828 __ j(not_sign, &positive_left); |
| 829 __ idiv(right_reg); |
| 830 |
| 831 // Test the remainder for 0, because then the result would be -0. |
| 832 __ test(edx, Operand(edx)); |
| 833 __ j(not_zero, &done); |
| 834 |
| 835 DeoptimizeIf(no_condition, instr->environment()); |
| 836 __ bind(&positive_left); |
| 837 __ idiv(right_reg); |
| 838 __ bind(&done); |
| 839 } else { |
| 840 __ idiv(right_reg); |
| 841 } |
| 819 } | 842 } |
| 820 } | 843 } |
| 821 | 844 |
| 822 | 845 |
| 823 void LCodeGen::DoDivI(LDivI* instr) { | 846 void LCodeGen::DoDivI(LDivI* instr) { |
| 824 LOperand* right = instr->InputAt(1); | 847 LOperand* right = instr->InputAt(1); |
| 825 ASSERT(ToRegister(instr->result()).is(eax)); | 848 ASSERT(ToRegister(instr->result()).is(eax)); |
| 826 ASSERT(ToRegister(instr->InputAt(0)).is(eax)); | 849 ASSERT(ToRegister(instr->InputAt(0)).is(eax)); |
| 827 ASSERT(!ToRegister(instr->InputAt(1)).is(eax)); | 850 ASSERT(!ToRegister(instr->InputAt(1)).is(eax)); |
| 828 ASSERT(!ToRegister(instr->InputAt(1)).is(edx)); | 851 ASSERT(!ToRegister(instr->InputAt(1)).is(edx)); |
| (...skipping 2171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3000 instr->pointer_map(), 2, Safepoint::kNoDeoptimizationIndex); | 3023 instr->pointer_map(), 2, Safepoint::kNoDeoptimizationIndex); |
| 3001 if (FLAG_debug_code) { | 3024 if (FLAG_debug_code) { |
| 3002 __ AbortIfNotSmi(eax); | 3025 __ AbortIfNotSmi(eax); |
| 3003 } | 3026 } |
| 3004 __ SmiUntag(eax); | 3027 __ SmiUntag(eax); |
| 3005 __ StoreToSafepointRegisterSlot(result, eax); | 3028 __ StoreToSafepointRegisterSlot(result, eax); |
| 3006 __ PopSafepointRegisters(); | 3029 __ PopSafepointRegisters(); |
| 3007 } | 3030 } |
| 3008 | 3031 |
| 3009 | 3032 |
| 3033 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
| 3034 class DeferredStringCharFromCode: public LDeferredCode { |
| 3035 public: |
| 3036 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 3037 : LDeferredCode(codegen), instr_(instr) { } |
| 3038 virtual void Generate() { codegen()->DoDeferredStringCharFromCode(instr_); } |
| 3039 private: |
| 3040 LStringCharFromCode* instr_; |
| 3041 }; |
| 3042 |
| 3043 DeferredStringCharFromCode* deferred = |
| 3044 new DeferredStringCharFromCode(this, instr); |
| 3045 |
| 3046 ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 3047 Register char_code = ToRegister(instr->char_code()); |
| 3048 Register result = ToRegister(instr->result()); |
| 3049 ASSERT(!char_code.is(result)); |
| 3050 |
| 3051 __ cmp(char_code, String::kMaxAsciiCharCode); |
| 3052 __ j(above, deferred->entry()); |
| 3053 __ Set(result, Immediate(Factory::single_character_string_cache())); |
| 3054 __ mov(result, FieldOperand(result, |
| 3055 char_code, times_pointer_size, |
| 3056 FixedArray::kHeaderSize)); |
| 3057 __ cmp(result, Factory::undefined_value()); |
| 3058 __ j(equal, deferred->entry()); |
| 3059 __ bind(deferred->exit()); |
| 3060 } |
| 3061 |
| 3062 |
| 3063 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 3064 Register char_code = ToRegister(instr->char_code()); |
| 3065 Register result = ToRegister(instr->result()); |
| 3066 |
| 3067 // TODO(3095996): Get rid of this. For now, we need to make the |
| 3068 // result register contain a valid pointer because it is already |
| 3069 // contained in the register pointer map. |
| 3070 __ Set(result, Immediate(0)); |
| 3071 |
| 3072 __ PushSafepointRegisters(); |
| 3073 __ SmiTag(char_code); |
| 3074 __ push(char_code); |
| 3075 __ CallRuntimeSaveDoubles(Runtime::kCharFromCode); |
| 3076 RecordSafepointWithRegisters( |
| 3077 instr->pointer_map(), 1, Safepoint::kNoDeoptimizationIndex); |
| 3078 __ StoreToSafepointRegisterSlot(result, eax); |
| 3079 __ PopSafepointRegisters(); |
| 3080 } |
| 3081 |
| 3082 |
| 3010 void LCodeGen::DoStringLength(LStringLength* instr) { | 3083 void LCodeGen::DoStringLength(LStringLength* instr) { |
| 3011 Register string = ToRegister(instr->string()); | 3084 Register string = ToRegister(instr->string()); |
| 3012 Register result = ToRegister(instr->result()); | 3085 Register result = ToRegister(instr->result()); |
| 3013 __ mov(result, FieldOperand(string, String::kLengthOffset)); | 3086 __ mov(result, FieldOperand(string, String::kLengthOffset)); |
| 3014 } | 3087 } |
| 3015 | 3088 |
| 3016 | 3089 |
| 3017 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { | 3090 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
| 3018 LOperand* input = instr->InputAt(0); | 3091 LOperand* input = instr->InputAt(0); |
| 3019 ASSERT(input->IsRegister() || input->IsStackSlot()); | 3092 ASSERT(input->IsRegister() || input->IsStackSlot()); |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3870 ASSERT(osr_pc_offset_ == -1); | 3943 ASSERT(osr_pc_offset_ == -1); |
| 3871 osr_pc_offset_ = masm()->pc_offset(); | 3944 osr_pc_offset_ = masm()->pc_offset(); |
| 3872 } | 3945 } |
| 3873 | 3946 |
| 3874 | 3947 |
| 3875 #undef __ | 3948 #undef __ |
| 3876 | 3949 |
| 3877 } } // namespace v8::internal | 3950 } } // namespace v8::internal |
| 3878 | 3951 |
| 3879 #endif // V8_TARGET_ARCH_IA32 | 3952 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |