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 3704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3715 __ j(equal, &done, Label::kNear); | 3715 __ j(equal, &done, Label::kNear); |
3716 __ sub(output_reg, Immediate(1)); | 3716 __ sub(output_reg, Immediate(1)); |
3717 DeoptimizeIf(overflow, instr->environment()); | 3717 DeoptimizeIf(overflow, instr->environment()); |
3718 | 3718 |
3719 __ bind(&done); | 3719 __ bind(&done); |
3720 } | 3720 } |
3721 } | 3721 } |
3722 | 3722 |
3723 void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { | 3723 void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { |
3724 CpuFeatures::Scope scope(SSE2); | 3724 CpuFeatures::Scope scope(SSE2); |
3725 XMMRegister xmm_scratch = xmm0; | |
3726 Register output_reg = ToRegister(instr->result()); | 3725 Register output_reg = ToRegister(instr->result()); |
3727 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 3726 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
| 3727 XMMRegister xmm_scratch = xmm0; |
| 3728 ExternalReference one_half = ExternalReference::address_of_one_half(); |
| 3729 ExternalReference minus_one_half = |
| 3730 ExternalReference::address_of_minus_one_half(); |
| 3731 bool minus_zero_check = |
| 3732 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
3728 | 3733 |
3729 Label below_half, done; | |
3730 // xmm_scratch = 0.5 | |
3731 ExternalReference one_half = ExternalReference::address_of_one_half(); | |
3732 __ movdbl(xmm_scratch, Operand::StaticVariable(one_half)); | 3734 __ movdbl(xmm_scratch, Operand::StaticVariable(one_half)); |
3733 __ ucomisd(xmm_scratch, input_reg); | |
3734 __ j(above, &below_half); | |
3735 // xmm_scratch = input + 0.5 | |
3736 __ addsd(xmm_scratch, input_reg); | |
3737 | 3735 |
3738 // Compute Math.floor(value + 0.5). | 3736 if (CpuFeatures::IsSupported(SSE4_1) && !minus_zero_check) { |
3739 // Use truncating instruction (OK because input is positive). | 3737 CpuFeatures::Scope scope(SSE4_1); |
3740 __ cvttsd2si(output_reg, Operand(xmm_scratch)); | |
3741 | 3738 |
3742 // Overflow is signalled with minint. | 3739 __ addsd(xmm_scratch, input_reg); |
3743 __ cmp(output_reg, 0x80000000u); | 3740 __ roundsd(xmm_scratch, input_reg, Assembler::kRoundDown); |
3744 DeoptimizeIf(equal, instr->environment()); | 3741 __ cvttsd2si(output_reg, Operand(xmm_scratch)); |
3745 __ jmp(&done); | 3742 // Overflow is signalled with minint. |
| 3743 __ cmp(output_reg, 0x80000000u); |
| 3744 __ RecordComment("D2I conversion overflow"); |
| 3745 DeoptimizeIf(equal, instr->environment()); |
| 3746 } else { |
| 3747 Label done, round_to_zero, below_one_half, do_not_compensate; |
| 3748 __ ucomisd(xmm_scratch, input_reg); |
| 3749 __ j(above, &below_one_half); |
3746 | 3750 |
3747 __ bind(&below_half); | 3751 // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). |
| 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); |
3748 | 3759 |
3749 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if | 3760 __ bind(&below_one_half); |
3750 // we can ignore the difference between a result of -0 and +0. | 3761 __ movdbl(xmm_scratch, Operand::StaticVariable(minus_one_half)); |
3751 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 3762 __ ucomisd(xmm_scratch, input_reg); |
3752 // If the sign is positive, we return +0. | 3763 __ j(below_equal, &round_to_zero); |
3753 __ movmskpd(output_reg, input_reg); | 3764 |
3754 __ test(output_reg, Immediate(1)); | 3765 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then |
3755 DeoptimizeIf(not_zero, instr->environment()); | 3766 // compare and compensate. |
3756 } else { | 3767 __ subsd(input_reg, xmm_scratch); |
3757 // If the input is >= -0.5, we return +0. | 3768 __ cvttsd2si(output_reg, Operand(input_reg)); |
3758 __ mov(output_reg, Immediate(0xBF000000)); | 3769 // Catch minint due to overflow, and to prevent overflow when compensating. |
3759 __ movd(xmm_scratch, Operand(output_reg)); | 3770 __ cmp(output_reg, 0x80000000u); |
3760 __ cvtss2sd(xmm_scratch, xmm_scratch); | 3771 __ RecordComment("D2I conversion overflow"); |
3761 __ ucomisd(input_reg, xmm_scratch); | 3772 DeoptimizeIf(equal, instr->environment()); |
3762 DeoptimizeIf(below, instr->environment()); | 3773 |
| 3774 __ cvtsi2sd(xmm_scratch, output_reg); |
| 3775 __ ucomisd(xmm_scratch, input_reg); |
| 3776 __ j(equal, &done); |
| 3777 __ sub(output_reg, Immediate(1)); |
| 3778 // No overflow because we already ruled out minint. |
| 3779 __ jmp(&done); |
| 3780 |
| 3781 __ bind(&round_to_zero); |
| 3782 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if |
| 3783 // we can ignore the difference between a result of -0 and +0. |
| 3784 if (minus_zero_check) { |
| 3785 // If the sign is positive, we return +0. |
| 3786 __ movmskpd(output_reg, input_reg); |
| 3787 __ test(output_reg, Immediate(1)); |
| 3788 __ RecordComment("Minus zero"); |
| 3789 DeoptimizeIf(not_zero, instr->environment()); |
| 3790 } |
| 3791 __ Set(output_reg, Immediate(0)); |
| 3792 __ bind(&done); |
3763 } | 3793 } |
3764 __ Set(output_reg, Immediate(0)); | |
3765 __ bind(&done); | |
3766 } | 3794 } |
3767 | 3795 |
3768 | 3796 |
3769 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { | 3797 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { |
3770 CpuFeatures::Scope scope(SSE2); | 3798 CpuFeatures::Scope scope(SSE2); |
3771 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 3799 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
3772 ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); | 3800 ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
3773 __ sqrtsd(input_reg, input_reg); | 3801 __ sqrtsd(input_reg, input_reg); |
3774 } | 3802 } |
3775 | 3803 |
(...skipping 2426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6202 FixedArray::kHeaderSize - kPointerSize)); | 6230 FixedArray::kHeaderSize - kPointerSize)); |
6203 __ bind(&done); | 6231 __ bind(&done); |
6204 } | 6232 } |
6205 | 6233 |
6206 | 6234 |
6207 #undef __ | 6235 #undef __ |
6208 | 6236 |
6209 } } // namespace v8::internal | 6237 } } // namespace v8::internal |
6210 | 6238 |
6211 #endif // V8_TARGET_ARCH_IA32 | 6239 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |