Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: src/x64/lithium-codegen-x64.cc

Issue 12374046: Tweak register allocation for Math.round and do not use roundsd. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/lithium-ia32.cc ('k') | src/x64/lithium-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 3516 matching lines...) Expand 10 before | Expand all | Expand 10 after
3527 } 3527 }
3528 3528
3529 3529
3530 void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { 3530 void LCodeGen::DoMathRound(LUnaryMathOperation* instr) {
3531 const XMMRegister xmm_scratch = xmm0; 3531 const XMMRegister xmm_scratch = xmm0;
3532 Register output_reg = ToRegister(instr->result()); 3532 Register output_reg = ToRegister(instr->result());
3533 XMMRegister input_reg = ToDoubleRegister(instr->value()); 3533 XMMRegister input_reg = ToDoubleRegister(instr->value());
3534 static int64_t one_half = V8_INT64_C(0x3FE0000000000000); // 0.5 3534 static int64_t one_half = V8_INT64_C(0x3FE0000000000000); // 0.5
3535 static int64_t minus_one_half = V8_INT64_C(0xBFE0000000000000); // -0.5 3535 static int64_t minus_one_half = V8_INT64_C(0xBFE0000000000000); // -0.5
3536 3536
3537 bool minus_zero_check = 3537 Label done, round_to_zero, below_one_half, do_not_compensate, restore;
3538 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero);
3539
3540 __ movq(kScratchRegister, one_half, RelocInfo::NONE64); 3538 __ movq(kScratchRegister, one_half, RelocInfo::NONE64);
3541 __ movq(xmm_scratch, kScratchRegister); 3539 __ movq(xmm_scratch, kScratchRegister);
3540 __ ucomisd(xmm_scratch, input_reg);
3541 __ j(above, &below_one_half);
3542 3542
3543 if (CpuFeatures::IsSupported(SSE4_1) && !minus_zero_check) { 3543 // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x).
3544 CpuFeatures::Scope scope(SSE4_1); 3544 __ addsd(xmm_scratch, input_reg);
3545 __ addsd(xmm_scratch, input_reg); 3545 __ cvttsd2si(output_reg, xmm_scratch);
3546 __ roundsd(xmm_scratch, xmm_scratch, Assembler::kRoundDown); 3546 // Overflow is signalled with minint.
3547 __ cvttsd2si(output_reg, xmm_scratch); 3547 __ cmpl(output_reg, Immediate(0x80000000));
3548 // Overflow is signalled with minint. 3548 __ RecordComment("D2I conversion overflow");
3549 __ cmpl(output_reg, Immediate(0x80000000)); 3549 DeoptimizeIf(equal, instr->environment());
3550 __ RecordComment("D2I conversion overflow"); 3550 __ jmp(&done);
3551 DeoptimizeIf(equal, instr->environment());
3552 } else {
3553 Label done, round_to_zero, below_one_half, do_not_compensate;
3554 __ ucomisd(xmm_scratch, input_reg);
3555 __ j(above, &below_one_half);
3556 3551
3557 // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). 3552 __ bind(&below_one_half);
3558 __ addsd(xmm_scratch, input_reg); 3553 __ movq(kScratchRegister, minus_one_half, RelocInfo::NONE64);
3559 __ cvttsd2si(output_reg, xmm_scratch); 3554 __ movq(xmm_scratch, kScratchRegister);
3560 // Overflow is signalled with minint. 3555 __ ucomisd(xmm_scratch, input_reg);
3561 __ cmpl(output_reg, Immediate(0x80000000)); 3556 __ j(below_equal, &round_to_zero);
3562 __ RecordComment("D2I conversion overflow");
3563 DeoptimizeIf(equal, instr->environment());
3564 __ jmp(&done);
3565 3557
3566 __ bind(&below_one_half); 3558 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then
3567 __ movq(kScratchRegister, minus_one_half, RelocInfo::NONE64); 3559 // compare and compensate.
3568 __ movq(xmm_scratch, kScratchRegister); 3560 __ movq(kScratchRegister, input_reg); // Back up input_reg.
3569 __ ucomisd(xmm_scratch, input_reg); 3561 __ subsd(input_reg, xmm_scratch);
3570 __ j(below_equal, &round_to_zero); 3562 __ cvttsd2si(output_reg, input_reg);
3563 // Catch minint due to overflow, and to prevent overflow when compensating.
3564 __ cmpl(output_reg, Immediate(0x80000000));
3565 __ RecordComment("D2I conversion overflow");
3566 DeoptimizeIf(equal, instr->environment());
3571 3567
3572 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then 3568 __ cvtlsi2sd(xmm_scratch, output_reg);
3573 // compare and compensate. 3569 __ ucomisd(input_reg, xmm_scratch);
3574 __ subsd(input_reg, xmm_scratch); 3570 __ j(equal, &restore, Label::kNear);
3575 __ cvttsd2si(output_reg, input_reg); 3571 __ subl(output_reg, Immediate(1));
3576 // Catch minint due to overflow, and to prevent overflow when compensating. 3572 // No overflow because we already ruled out minint.
3577 __ cmpl(output_reg, Immediate(0x80000000)); 3573 __ bind(&restore);
3578 __ RecordComment("D2I conversion overflow"); 3574 __ movq(input_reg, kScratchRegister); // Restore input_reg.
3579 DeoptimizeIf(equal, instr->environment()); 3575 __ jmp(&done);
3580 3576
3581 __ cvtlsi2sd(xmm_scratch, output_reg); 3577 __ bind(&round_to_zero);
3582 __ ucomisd(input_reg, xmm_scratch); 3578 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if
3583 __ j(equal, &done, Label::kNear); 3579 // we can ignore the difference between a result of -0 and +0.
3584 __ subl(output_reg, Immediate(1)); 3580 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3585 // No overflow because we already ruled out minint. 3581 __ movq(output_reg, input_reg);
3586 __ jmp(&done); 3582 __ testq(output_reg, output_reg);
3587 3583 __ RecordComment("Minus zero");
3588 __ bind(&round_to_zero); 3584 DeoptimizeIf(negative, instr->environment());
3589 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if
3590 // we can ignore the difference between a result of -0 and +0.
3591 if (minus_zero_check) {
3592 __ movq(output_reg, input_reg);
3593 __ testq(output_reg, output_reg);
3594 __ RecordComment("Minus zero");
3595 DeoptimizeIf(negative, instr->environment());
3596 }
3597 __ Set(output_reg, 0);
3598 __ bind(&done);
3599 } 3585 }
3586 __ Set(output_reg, 0);
3587 __ bind(&done);
3600 } 3588 }
3601 3589
3602 3590
3603 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { 3591 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) {
3604 XMMRegister input_reg = ToDoubleRegister(instr->value()); 3592 XMMRegister input_reg = ToDoubleRegister(instr->value());
3605 ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); 3593 ASSERT(ToDoubleRegister(instr->result()).is(input_reg));
3606 __ sqrtsd(input_reg, input_reg); 3594 __ sqrtsd(input_reg, input_reg);
3607 } 3595 }
3608 3596
3609 3597
(...skipping 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after
5822 FixedArray::kHeaderSize - kPointerSize)); 5810 FixedArray::kHeaderSize - kPointerSize));
5823 __ bind(&done); 5811 __ bind(&done);
5824 } 5812 }
5825 5813
5826 5814
5827 #undef __ 5815 #undef __
5828 5816
5829 } } // namespace v8::internal 5817 } } // namespace v8::internal
5830 5818
5831 #endif // V8_TARGET_ARCH_X64 5819 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/ia32/lithium-ia32.cc ('k') | src/x64/lithium-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698