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 2703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2714 __ cmpl(output_reg, Immediate(0x80000000)); | 2714 __ cmpl(output_reg, Immediate(0x80000000)); |
2715 DeoptimizeIf(equal, instr->environment()); | 2715 DeoptimizeIf(equal, instr->environment()); |
2716 } | 2716 } |
2717 | 2717 |
2718 | 2718 |
2719 void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { | 2719 void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { |
2720 const XMMRegister xmm_scratch = xmm0; | 2720 const XMMRegister xmm_scratch = xmm0; |
2721 Register output_reg = ToRegister(instr->result()); | 2721 Register output_reg = ToRegister(instr->result()); |
2722 XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); | 2722 XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
2723 | 2723 |
2724 Label done; | |
2724 // xmm_scratch = 0.5 | 2725 // xmm_scratch = 0.5 |
2725 __ movq(kScratchRegister, V8_INT64_C(0x3FE0000000000000), RelocInfo::NONE); | 2726 __ movq(kScratchRegister, V8_INT64_C(0x3FE0000000000000), RelocInfo::NONE); |
2726 __ movq(xmm_scratch, kScratchRegister); | 2727 __ movq(xmm_scratch, kScratchRegister); |
2728 NearLabel below_half; | |
2729 __ ucomisd(xmm_scratch, input_reg); | |
2730 __ j(above, &below_half); // If input_reg is NaN, this doesn't jump. | |
2731 // input = input + 0.5 | |
2732 // This addition might give a result that isn't the correct for | |
2733 // rounding, due to loss of precission, but only for a number that's | |
William Hesse
2011/04/13 09:12:45
precision
Lasse Reichstein
2011/04/13 09:35:23
Fixed, thanks.
| |
2734 // so big that the conversion below will overflow anyway. | |
2735 __ addsd(input_reg, xmm_scratch); | |
2736 // Compute Math.floor(input). | |
2737 // Use truncating instruction (OK because input is positive). | |
2738 __ cvttsd2si(output_reg, input_reg); | |
2739 // Overflow is signalled with minint. | |
2740 __ cmpl(output_reg, Immediate(0x80000000)); | |
2741 DeoptimizeIf(equal, instr->environment()); | |
2742 __ jmp(&done); | |
2727 | 2743 |
2728 // input = input + 0.5 | 2744 __ bind(&below_half); |
2729 __ addsd(input_reg, xmm_scratch); | |
2730 | |
2731 // We need to return -0 for the input range [-0.5, 0[, otherwise | |
2732 // compute Math.floor(value + 0.5). | |
2733 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 2745 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
2734 __ ucomisd(input_reg, xmm_scratch); | 2746 // Bailout if negative (including -0). |
2735 DeoptimizeIf(below_equal, instr->environment()); | 2747 __ movq(output_reg, input_reg); |
2748 __ testq(output_reg, output_reg); | |
2749 DeoptimizeIf(negative, instr->environment()); | |
2736 } else { | 2750 } else { |
2737 // If we don't need to bailout on -0, we check only bailout | 2751 // Bailout if below -0.5, otherwise round to (positive) zero, even |
2738 // on negative inputs. | 2752 // if negative. |
2739 __ xorpd(xmm_scratch, xmm_scratch); // Zero the register. | 2753 // xmm_scrach = -0.5 |
2754 __ movq(kScratchRegister, V8_INT64_C(0xBFE0000000000000), RelocInfo::NONE); | |
2755 __ movq(xmm_scratch, kScratchRegister); | |
2740 __ ucomisd(input_reg, xmm_scratch); | 2756 __ ucomisd(input_reg, xmm_scratch); |
2741 DeoptimizeIf(below, instr->environment()); | 2757 DeoptimizeIf(below, instr->environment()); |
2742 } | 2758 } |
2759 __ xorl(output_reg, output_reg); | |
2743 | 2760 |
2744 // Compute Math.floor(value + 0.5). | 2761 __ bind(&done); |
2745 // Use truncating instruction (OK because input is positive). | |
2746 __ cvttsd2si(output_reg, input_reg); | |
2747 | |
2748 // Overflow is signalled with minint. | |
2749 __ cmpl(output_reg, Immediate(0x80000000)); | |
2750 DeoptimizeIf(equal, instr->environment()); | |
2751 } | 2762 } |
2752 | 2763 |
2753 | 2764 |
2754 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { | 2765 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { |
2755 XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); | 2766 XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
2756 ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); | 2767 ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
2757 __ sqrtsd(input_reg, input_reg); | 2768 __ sqrtsd(input_reg, input_reg); |
2758 } | 2769 } |
2759 | 2770 |
2760 | 2771 |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3995 RegisterEnvironmentForDeoptimization(environment); | 4006 RegisterEnvironmentForDeoptimization(environment); |
3996 ASSERT(osr_pc_offset_ == -1); | 4007 ASSERT(osr_pc_offset_ == -1); |
3997 osr_pc_offset_ = masm()->pc_offset(); | 4008 osr_pc_offset_ = masm()->pc_offset(); |
3998 } | 4009 } |
3999 | 4010 |
4000 #undef __ | 4011 #undef __ |
4001 | 4012 |
4002 } } // namespace v8::internal | 4013 } } // namespace v8::internal |
4003 | 4014 |
4004 #endif // V8_TARGET_ARCH_X64 | 4015 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |