| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3726 __ cvtsi2sd(xmm_scratch, output_reg); | 3726 __ cvtsi2sd(xmm_scratch, output_reg); |
| 3727 __ ucomisd(input_reg, xmm_scratch); | 3727 __ ucomisd(input_reg, xmm_scratch); |
| 3728 __ j(equal, &done, Label::kNear); | 3728 __ j(equal, &done, Label::kNear); |
| 3729 __ sub(output_reg, Immediate(1)); | 3729 __ sub(output_reg, Immediate(1)); |
| 3730 DeoptimizeIf(overflow, instr->environment()); | 3730 DeoptimizeIf(overflow, instr->environment()); |
| 3731 | 3731 |
| 3732 __ bind(&done); | 3732 __ bind(&done); |
| 3733 } | 3733 } |
| 3734 } | 3734 } |
| 3735 | 3735 |
| 3736 void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { | 3736 void LCodeGen::DoMathRound(LMathRound* instr) { |
| 3737 CpuFeatures::Scope scope(SSE2); | 3737 CpuFeatures::Scope scope(SSE2); |
| 3738 Register output_reg = ToRegister(instr->result()); | 3738 Register output_reg = ToRegister(instr->result()); |
| 3739 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 3739 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
| 3740 XMMRegister xmm_scratch = xmm0; | 3740 XMMRegister xmm_scratch = xmm0; |
| 3741 XMMRegister input_temp = ToDoubleRegister(instr->temp()); |
| 3741 ExternalReference one_half = ExternalReference::address_of_one_half(); | 3742 ExternalReference one_half = ExternalReference::address_of_one_half(); |
| 3742 ExternalReference minus_one_half = | 3743 ExternalReference minus_one_half = |
| 3743 ExternalReference::address_of_minus_one_half(); | 3744 ExternalReference::address_of_minus_one_half(); |
| 3744 bool minus_zero_check = | |
| 3745 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); | |
| 3746 | 3745 |
| 3746 Label done, round_to_zero, below_one_half, do_not_compensate; |
| 3747 __ movdbl(xmm_scratch, Operand::StaticVariable(one_half)); | 3747 __ movdbl(xmm_scratch, Operand::StaticVariable(one_half)); |
| 3748 __ ucomisd(xmm_scratch, input_reg); |
| 3749 __ j(above, &below_one_half); |
| 3748 | 3750 |
| 3749 if (CpuFeatures::IsSupported(SSE4_1) && !minus_zero_check) { | 3751 // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). |
| 3750 CpuFeatures::Scope scope(SSE4_1); | 3752 __ addsd(xmm_scratch, input_reg); |
| 3753 __ cvttsd2si(output_reg, Operand(xmm_scratch)); |
| 3754 // Overflow is signalled with minint. |
| 3755 __ cmp(output_reg, 0x80000000u); |
| 3756 __ RecordComment("D2I conversion overflow"); |
| 3757 DeoptimizeIf(equal, instr->environment()); |
| 3758 __ jmp(&done); |
| 3751 | 3759 |
| 3752 __ addsd(xmm_scratch, input_reg); | 3760 __ bind(&below_one_half); |
| 3753 __ roundsd(xmm_scratch, xmm_scratch, Assembler::kRoundDown); | 3761 __ movdbl(xmm_scratch, Operand::StaticVariable(minus_one_half)); |
| 3754 __ cvttsd2si(output_reg, Operand(xmm_scratch)); | 3762 __ ucomisd(xmm_scratch, input_reg); |
| 3755 // Overflow is signalled with minint. | 3763 __ j(below_equal, &round_to_zero); |
| 3756 __ cmp(output_reg, 0x80000000u); | |
| 3757 __ RecordComment("D2I conversion overflow"); | |
| 3758 DeoptimizeIf(equal, instr->environment()); | |
| 3759 } else { | |
| 3760 Label done, round_to_zero, below_one_half, do_not_compensate; | |
| 3761 __ ucomisd(xmm_scratch, input_reg); | |
| 3762 __ j(above, &below_one_half); | |
| 3763 | 3764 |
| 3764 // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). | 3765 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then |
| 3765 __ addsd(xmm_scratch, input_reg); | 3766 // compare and compensate. |
| 3766 __ cvttsd2si(output_reg, Operand(xmm_scratch)); | 3767 __ movsd(input_temp, input_reg); // Do not alter input_reg. |
| 3767 // Overflow is signalled with minint. | 3768 __ subsd(input_temp, xmm_scratch); |
| 3768 __ cmp(output_reg, 0x80000000u); | 3769 __ cvttsd2si(output_reg, Operand(input_temp)); |
| 3769 __ RecordComment("D2I conversion overflow"); | 3770 // Catch minint due to overflow, and to prevent overflow when compensating. |
| 3770 DeoptimizeIf(equal, instr->environment()); | 3771 __ cmp(output_reg, 0x80000000u); |
| 3771 __ jmp(&done); | 3772 __ RecordComment("D2I conversion overflow"); |
| 3773 DeoptimizeIf(equal, instr->environment()); |
| 3772 | 3774 |
| 3773 __ bind(&below_one_half); | 3775 __ cvtsi2sd(xmm_scratch, output_reg); |
| 3774 __ movdbl(xmm_scratch, Operand::StaticVariable(minus_one_half)); | 3776 __ ucomisd(xmm_scratch, input_temp); |
| 3775 __ ucomisd(xmm_scratch, input_reg); | 3777 __ j(equal, &done); |
| 3776 __ j(below_equal, &round_to_zero); | 3778 __ sub(output_reg, Immediate(1)); |
| 3779 // No overflow because we already ruled out minint. |
| 3780 __ jmp(&done); |
| 3777 | 3781 |
| 3778 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then | 3782 __ bind(&round_to_zero); |
| 3779 // compare and compensate. | 3783 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if |
| 3780 __ subsd(input_reg, xmm_scratch); | 3784 // we can ignore the difference between a result of -0 and +0. |
| 3781 __ cvttsd2si(output_reg, Operand(input_reg)); | 3785 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3782 // Catch minint due to overflow, and to prevent overflow when compensating. | 3786 // If the sign is positive, we return +0. |
| 3783 __ cmp(output_reg, 0x80000000u); | 3787 __ movmskpd(output_reg, input_reg); |
| 3784 __ RecordComment("D2I conversion overflow"); | 3788 __ test(output_reg, Immediate(1)); |
| 3785 DeoptimizeIf(equal, instr->environment()); | 3789 __ RecordComment("Minus zero"); |
| 3786 | 3790 DeoptimizeIf(not_zero, instr->environment()); |
| 3787 __ cvtsi2sd(xmm_scratch, output_reg); | |
| 3788 __ ucomisd(xmm_scratch, input_reg); | |
| 3789 __ j(equal, &done); | |
| 3790 __ sub(output_reg, Immediate(1)); | |
| 3791 // No overflow because we already ruled out minint. | |
| 3792 __ jmp(&done); | |
| 3793 | |
| 3794 __ bind(&round_to_zero); | |
| 3795 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if | |
| 3796 // we can ignore the difference between a result of -0 and +0. | |
| 3797 if (minus_zero_check) { | |
| 3798 // If the sign is positive, we return +0. | |
| 3799 __ movmskpd(output_reg, input_reg); | |
| 3800 __ test(output_reg, Immediate(1)); | |
| 3801 __ RecordComment("Minus zero"); | |
| 3802 DeoptimizeIf(not_zero, instr->environment()); | |
| 3803 } | |
| 3804 __ Set(output_reg, Immediate(0)); | |
| 3805 __ bind(&done); | |
| 3806 } | 3791 } |
| 3792 __ Set(output_reg, Immediate(0)); |
| 3793 __ bind(&done); |
| 3807 } | 3794 } |
| 3808 | 3795 |
| 3809 | 3796 |
| 3810 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { | 3797 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { |
| 3811 CpuFeatures::Scope scope(SSE2); | 3798 CpuFeatures::Scope scope(SSE2); |
| 3812 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 3799 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
| 3813 ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); | 3800 ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
| 3814 __ sqrtsd(input_reg, input_reg); | 3801 __ sqrtsd(input_reg, input_reg); |
| 3815 } | 3802 } |
| 3816 | 3803 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4028 | 4015 |
| 4029 | 4016 |
| 4030 void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) { | 4017 void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) { |
| 4031 switch (instr->op()) { | 4018 switch (instr->op()) { |
| 4032 case kMathAbs: | 4019 case kMathAbs: |
| 4033 DoMathAbs(instr); | 4020 DoMathAbs(instr); |
| 4034 break; | 4021 break; |
| 4035 case kMathFloor: | 4022 case kMathFloor: |
| 4036 DoMathFloor(instr); | 4023 DoMathFloor(instr); |
| 4037 break; | 4024 break; |
| 4038 case kMathRound: | |
| 4039 DoMathRound(instr); | |
| 4040 break; | |
| 4041 case kMathSqrt: | 4025 case kMathSqrt: |
| 4042 DoMathSqrt(instr); | 4026 DoMathSqrt(instr); |
| 4043 break; | 4027 break; |
| 4044 case kMathCos: | 4028 case kMathCos: |
| 4045 DoMathCos(instr); | 4029 DoMathCos(instr); |
| 4046 break; | 4030 break; |
| 4047 case kMathSin: | 4031 case kMathSin: |
| 4048 DoMathSin(instr); | 4032 DoMathSin(instr); |
| 4049 break; | 4033 break; |
| 4050 case kMathTan: | 4034 case kMathTan: |
| (...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6243 FixedArray::kHeaderSize - kPointerSize)); | 6227 FixedArray::kHeaderSize - kPointerSize)); |
| 6244 __ bind(&done); | 6228 __ bind(&done); |
| 6245 } | 6229 } |
| 6246 | 6230 |
| 6247 | 6231 |
| 6248 #undef __ | 6232 #undef __ |
| 6249 | 6233 |
| 6250 } } // namespace v8::internal | 6234 } } // namespace v8::internal |
| 6251 | 6235 |
| 6252 #endif // V8_TARGET_ARCH_IA32 | 6236 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |