| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
| 6 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/hydrogen-osr.h" | 10 #include "src/hydrogen-osr.h" |
| (...skipping 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3602 | 3602 |
| 3603 if (CpuFeatures::IsSupported(SSE4_1)) { | 3603 if (CpuFeatures::IsSupported(SSE4_1)) { |
| 3604 CpuFeatureScope scope(masm(), SSE4_1); | 3604 CpuFeatureScope scope(masm(), SSE4_1); |
| 3605 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 3605 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3606 // Deoptimize if minus zero. | 3606 // Deoptimize if minus zero. |
| 3607 __ Movq(output_reg, input_reg); | 3607 __ Movq(output_reg, input_reg); |
| 3608 __ subq(output_reg, Immediate(1)); | 3608 __ subq(output_reg, Immediate(1)); |
| 3609 DeoptimizeIf(overflow, instr, Deoptimizer::kMinusZero); | 3609 DeoptimizeIf(overflow, instr, Deoptimizer::kMinusZero); |
| 3610 } | 3610 } |
| 3611 __ roundsd(xmm_scratch, input_reg, kRoundDown); | 3611 __ roundsd(xmm_scratch, input_reg, kRoundDown); |
| 3612 __ cvttsd2si(output_reg, xmm_scratch); | 3612 __ Cvttsd2si(output_reg, xmm_scratch); |
| 3613 __ cmpl(output_reg, Immediate(0x1)); | 3613 __ cmpl(output_reg, Immediate(0x1)); |
| 3614 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); | 3614 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); |
| 3615 } else { | 3615 } else { |
| 3616 Label negative_sign, done; | 3616 Label negative_sign, done; |
| 3617 // Deoptimize on unordered. | 3617 // Deoptimize on unordered. |
| 3618 __ Xorpd(xmm_scratch, xmm_scratch); // Zero the register. | 3618 __ Xorpd(xmm_scratch, xmm_scratch); // Zero the register. |
| 3619 __ ucomisd(input_reg, xmm_scratch); | 3619 __ ucomisd(input_reg, xmm_scratch); |
| 3620 DeoptimizeIf(parity_even, instr, Deoptimizer::kNaN); | 3620 DeoptimizeIf(parity_even, instr, Deoptimizer::kNaN); |
| 3621 __ j(below, &negative_sign, Label::kNear); | 3621 __ j(below, &negative_sign, Label::kNear); |
| 3622 | 3622 |
| 3623 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 3623 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3624 // Check for negative zero. | 3624 // Check for negative zero. |
| 3625 Label positive_sign; | 3625 Label positive_sign; |
| 3626 __ j(above, &positive_sign, Label::kNear); | 3626 __ j(above, &positive_sign, Label::kNear); |
| 3627 __ movmskpd(output_reg, input_reg); | 3627 __ movmskpd(output_reg, input_reg); |
| 3628 __ testq(output_reg, Immediate(1)); | 3628 __ testq(output_reg, Immediate(1)); |
| 3629 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero); | 3629 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero); |
| 3630 __ Set(output_reg, 0); | 3630 __ Set(output_reg, 0); |
| 3631 __ jmp(&done); | 3631 __ jmp(&done); |
| 3632 __ bind(&positive_sign); | 3632 __ bind(&positive_sign); |
| 3633 } | 3633 } |
| 3634 | 3634 |
| 3635 // Use truncating instruction (OK because input is positive). | 3635 // Use truncating instruction (OK because input is positive). |
| 3636 __ cvttsd2si(output_reg, input_reg); | 3636 __ Cvttsd2si(output_reg, input_reg); |
| 3637 // Overflow is signalled with minint. | 3637 // Overflow is signalled with minint. |
| 3638 __ cmpl(output_reg, Immediate(0x1)); | 3638 __ cmpl(output_reg, Immediate(0x1)); |
| 3639 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); | 3639 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); |
| 3640 __ jmp(&done, Label::kNear); | 3640 __ jmp(&done, Label::kNear); |
| 3641 | 3641 |
| 3642 // Non-zero negative reaches here. | 3642 // Non-zero negative reaches here. |
| 3643 __ bind(&negative_sign); | 3643 __ bind(&negative_sign); |
| 3644 // Truncate, then compare and compensate. | 3644 // Truncate, then compare and compensate. |
| 3645 __ cvttsd2si(output_reg, input_reg); | 3645 __ Cvttsd2si(output_reg, input_reg); |
| 3646 __ Cvtlsi2sd(xmm_scratch, output_reg); | 3646 __ Cvtlsi2sd(xmm_scratch, output_reg); |
| 3647 __ ucomisd(input_reg, xmm_scratch); | 3647 __ ucomisd(input_reg, xmm_scratch); |
| 3648 __ j(equal, &done, Label::kNear); | 3648 __ j(equal, &done, Label::kNear); |
| 3649 __ subl(output_reg, Immediate(1)); | 3649 __ subl(output_reg, Immediate(1)); |
| 3650 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); | 3650 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); |
| 3651 | 3651 |
| 3652 __ bind(&done); | 3652 __ bind(&done); |
| 3653 } | 3653 } |
| 3654 } | 3654 } |
| 3655 | 3655 |
| 3656 | 3656 |
| 3657 void LCodeGen::DoMathRound(LMathRound* instr) { | 3657 void LCodeGen::DoMathRound(LMathRound* instr) { |
| 3658 const XMMRegister xmm_scratch = double_scratch0(); | 3658 const XMMRegister xmm_scratch = double_scratch0(); |
| 3659 Register output_reg = ToRegister(instr->result()); | 3659 Register output_reg = ToRegister(instr->result()); |
| 3660 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 3660 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
| 3661 XMMRegister input_temp = ToDoubleRegister(instr->temp()); | 3661 XMMRegister input_temp = ToDoubleRegister(instr->temp()); |
| 3662 static int64_t one_half = V8_INT64_C(0x3FE0000000000000); // 0.5 | 3662 static int64_t one_half = V8_INT64_C(0x3FE0000000000000); // 0.5 |
| 3663 static int64_t minus_one_half = V8_INT64_C(0xBFE0000000000000); // -0.5 | 3663 static int64_t minus_one_half = V8_INT64_C(0xBFE0000000000000); // -0.5 |
| 3664 | 3664 |
| 3665 Label done, round_to_zero, below_one_half; | 3665 Label done, round_to_zero, below_one_half; |
| 3666 Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; | 3666 Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; |
| 3667 __ movq(kScratchRegister, one_half); | 3667 __ movq(kScratchRegister, one_half); |
| 3668 __ Movq(xmm_scratch, kScratchRegister); | 3668 __ Movq(xmm_scratch, kScratchRegister); |
| 3669 __ ucomisd(xmm_scratch, input_reg); | 3669 __ ucomisd(xmm_scratch, input_reg); |
| 3670 __ j(above, &below_one_half, Label::kNear); | 3670 __ j(above, &below_one_half, Label::kNear); |
| 3671 | 3671 |
| 3672 // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). | 3672 // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). |
| 3673 __ addsd(xmm_scratch, input_reg); | 3673 __ addsd(xmm_scratch, input_reg); |
| 3674 __ cvttsd2si(output_reg, xmm_scratch); | 3674 __ Cvttsd2si(output_reg, xmm_scratch); |
| 3675 // Overflow is signalled with minint. | 3675 // Overflow is signalled with minint. |
| 3676 __ cmpl(output_reg, Immediate(0x1)); | 3676 __ cmpl(output_reg, Immediate(0x1)); |
| 3677 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); | 3677 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); |
| 3678 __ jmp(&done, dist); | 3678 __ jmp(&done, dist); |
| 3679 | 3679 |
| 3680 __ bind(&below_one_half); | 3680 __ bind(&below_one_half); |
| 3681 __ movq(kScratchRegister, minus_one_half); | 3681 __ movq(kScratchRegister, minus_one_half); |
| 3682 __ Movq(xmm_scratch, kScratchRegister); | 3682 __ Movq(xmm_scratch, kScratchRegister); |
| 3683 __ ucomisd(xmm_scratch, input_reg); | 3683 __ ucomisd(xmm_scratch, input_reg); |
| 3684 __ j(below_equal, &round_to_zero, Label::kNear); | 3684 __ j(below_equal, &round_to_zero, Label::kNear); |
| 3685 | 3685 |
| 3686 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then | 3686 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then |
| 3687 // compare and compensate. | 3687 // compare and compensate. |
| 3688 __ Movapd(input_temp, input_reg); // Do not alter input_reg. | 3688 __ Movapd(input_temp, input_reg); // Do not alter input_reg. |
| 3689 __ subsd(input_temp, xmm_scratch); | 3689 __ subsd(input_temp, xmm_scratch); |
| 3690 __ cvttsd2si(output_reg, input_temp); | 3690 __ Cvttsd2si(output_reg, input_temp); |
| 3691 // Catch minint due to overflow, and to prevent overflow when compensating. | 3691 // Catch minint due to overflow, and to prevent overflow when compensating. |
| 3692 __ cmpl(output_reg, Immediate(0x1)); | 3692 __ cmpl(output_reg, Immediate(0x1)); |
| 3693 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); | 3693 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); |
| 3694 | 3694 |
| 3695 __ Cvtlsi2sd(xmm_scratch, output_reg); | 3695 __ Cvtlsi2sd(xmm_scratch, output_reg); |
| 3696 __ ucomisd(xmm_scratch, input_temp); | 3696 __ ucomisd(xmm_scratch, input_temp); |
| 3697 __ j(equal, &done, dist); | 3697 __ j(equal, &done, dist); |
| 3698 __ subl(output_reg, Immediate(1)); | 3698 __ subl(output_reg, Immediate(1)); |
| 3699 // No overflow because we already ruled out minint. | 3699 // No overflow because we already ruled out minint. |
| 3700 __ jmp(&done, dist); | 3700 __ jmp(&done, dist); |
| (...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4987 DeoptimizeIf(not_equal, instr, | 4987 DeoptimizeIf(not_equal, instr, |
| 4988 Deoptimizer::kNotAHeapNumberUndefinedBoolean); | 4988 Deoptimizer::kNotAHeapNumberUndefinedBoolean); |
| 4989 __ Set(input_reg, 0); | 4989 __ Set(input_reg, 0); |
| 4990 } else { | 4990 } else { |
| 4991 XMMRegister scratch = ToDoubleRegister(instr->temp()); | 4991 XMMRegister scratch = ToDoubleRegister(instr->temp()); |
| 4992 DCHECK(!scratch.is(xmm0)); | 4992 DCHECK(!scratch.is(xmm0)); |
| 4993 __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), | 4993 __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 4994 Heap::kHeapNumberMapRootIndex); | 4994 Heap::kHeapNumberMapRootIndex); |
| 4995 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotAHeapNumber); | 4995 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotAHeapNumber); |
| 4996 __ Movsd(xmm0, FieldOperand(input_reg, HeapNumber::kValueOffset)); | 4996 __ Movsd(xmm0, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 4997 __ cvttsd2si(input_reg, xmm0); | 4997 __ Cvttsd2si(input_reg, xmm0); |
| 4998 __ Cvtlsi2sd(scratch, input_reg); | 4998 __ Cvtlsi2sd(scratch, input_reg); |
| 4999 __ ucomisd(xmm0, scratch); | 4999 __ ucomisd(xmm0, scratch); |
| 5000 DeoptimizeIf(not_equal, instr, Deoptimizer::kLostPrecision); | 5000 DeoptimizeIf(not_equal, instr, Deoptimizer::kLostPrecision); |
| 5001 DeoptimizeIf(parity_even, instr, Deoptimizer::kNaN); | 5001 DeoptimizeIf(parity_even, instr, Deoptimizer::kNaN); |
| 5002 if (instr->hydrogen()->GetMinusZeroMode() == FAIL_ON_MINUS_ZERO) { | 5002 if (instr->hydrogen()->GetMinusZeroMode() == FAIL_ON_MINUS_ZERO) { |
| 5003 __ testl(input_reg, input_reg); | 5003 __ testl(input_reg, input_reg); |
| 5004 __ j(not_zero, done); | 5004 __ j(not_zero, done); |
| 5005 __ movmskpd(input_reg, xmm0); | 5005 __ movmskpd(input_reg, xmm0); |
| 5006 __ andl(input_reg, Immediate(1)); | 5006 __ andl(input_reg, Immediate(1)); |
| 5007 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero); | 5007 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero); |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5905 RecordSafepoint(Safepoint::kNoLazyDeopt); | 5905 RecordSafepoint(Safepoint::kNoLazyDeopt); |
| 5906 } | 5906 } |
| 5907 | 5907 |
| 5908 | 5908 |
| 5909 #undef __ | 5909 #undef __ |
| 5910 | 5910 |
| 5911 } // namespace internal | 5911 } // namespace internal |
| 5912 } // namespace v8 | 5912 } // namespace v8 |
| 5913 | 5913 |
| 5914 #endif // V8_TARGET_ARCH_X64 | 5914 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |