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 2648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2659 Register input = ToRegister(instr->InputAt(0)); | 2659 Register input = ToRegister(instr->InputAt(0)); |
2660 // Smi check. | 2660 // Smi check. |
2661 __ JumpIfNotSmi(input, deferred->entry()); | 2661 __ JumpIfNotSmi(input, deferred->entry()); |
2662 // If smi, handle it directly. | 2662 // If smi, handle it directly. |
2663 EmitIntegerMathAbs(instr); | 2663 EmitIntegerMathAbs(instr); |
2664 __ bind(deferred->exit()); | 2664 __ bind(deferred->exit()); |
2665 } | 2665 } |
2666 } | 2666 } |
2667 | 2667 |
2668 | 2668 |
| 2669 // Truncates a double using a specific rounding mode. |
| 2670 // Clears the z flag (ne condition) if an overflow occurs. |
| 2671 void LCodeGen::EmitVFPTruncate(VFPRoundingMode rounding_mode, |
| 2672 SwVfpRegister result, |
| 2673 DwVfpRegister double_input, |
| 2674 Register scratch1, |
| 2675 Register scratch2) { |
| 2676 Register prev_fpscr = scratch1; |
| 2677 Register scratch = scratch2; |
| 2678 |
| 2679 // Set custom FPCSR: |
| 2680 // - Set rounding mode. |
| 2681 // - Clear vfp cumulative exception flags. |
| 2682 // - Make sure Flush-to-zero mode control bit is unset. |
| 2683 __ vmrs(prev_fpscr); |
| 2684 __ bic(scratch, prev_fpscr, Operand(kVFPExceptionMask | |
| 2685 kVFPRoundingModeMask | |
| 2686 kVFPFlushToZeroMask)); |
| 2687 __ orr(scratch, scratch, Operand(rounding_mode)); |
| 2688 __ vmsr(scratch); |
| 2689 |
| 2690 // Convert the argument to an integer. |
| 2691 __ vcvt_s32_f64(result, |
| 2692 double_input, |
| 2693 kFPSCRRounding); |
| 2694 |
| 2695 // Retrieve FPSCR. |
| 2696 __ vmrs(scratch); |
| 2697 // Restore FPSCR. |
| 2698 __ vmsr(prev_fpscr); |
| 2699 // Check for vfp exceptions. |
| 2700 __ tst(scratch, Operand(kVFPExceptionMask)); |
| 2701 } |
| 2702 |
| 2703 |
2669 void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { | 2704 void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { |
2670 DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); | 2705 DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); |
2671 Register result = ToRegister(instr->result()); | 2706 Register result = ToRegister(instr->result()); |
2672 Register prev_fpscr = ToRegister(instr->TempAt(0)); | |
2673 SwVfpRegister single_scratch = double_scratch0().low(); | 2707 SwVfpRegister single_scratch = double_scratch0().low(); |
2674 Register scratch = scratch0(); | 2708 Register scratch1 = scratch0(); |
| 2709 Register scratch2 = ToRegister(instr->TempAt(0)); |
2675 | 2710 |
2676 // Set custom FPCSR: | 2711 EmitVFPTruncate(kRoundToMinusInf, |
2677 // - Set rounding mode to "Round towards Minus Infinity". | 2712 single_scratch, |
2678 // - Clear vfp cumulative exception flags. | |
2679 // - Make sure Flush-to-zero mode control bit is unset. | |
2680 __ vmrs(prev_fpscr); | |
2681 __ bic(scratch, prev_fpscr, | |
2682 Operand(kVFPExceptionMask | kVFPRoundingModeMask | kVFPFlushToZeroMask)); | |
2683 __ orr(scratch, scratch, Operand(kVFPRoundToMinusInfinityBits)); | |
2684 __ vmsr(scratch); | |
2685 | |
2686 // Convert the argument to an integer. | |
2687 __ vcvt_s32_f64(single_scratch, | |
2688 input, | 2713 input, |
2689 Assembler::FPSCRRounding, | 2714 scratch1, |
2690 al); | 2715 scratch2); |
2691 | |
2692 // Retrieve FPSCR and check for vfp exceptions. | |
2693 __ vmrs(scratch); | |
2694 // Restore FPSCR | |
2695 __ vmsr(prev_fpscr); | |
2696 __ tst(scratch, Operand(kVFPExceptionMask)); | |
2697 DeoptimizeIf(ne, instr->environment()); | 2716 DeoptimizeIf(ne, instr->environment()); |
2698 | 2717 |
2699 // Move the result back to general purpose register r0. | 2718 // Move the result back to general purpose register r0. |
2700 __ vmov(result, single_scratch); | 2719 __ vmov(result, single_scratch); |
2701 | 2720 |
2702 // Test for -0. | 2721 // Test for -0. |
2703 Label done; | 2722 Label done; |
2704 __ cmp(result, Operand(0)); | 2723 __ cmp(result, Operand(0)); |
2705 __ b(ne, &done); | 2724 __ b(ne, &done); |
2706 __ vmov(scratch, input.high()); | 2725 __ vmov(scratch1, input.high()); |
2707 __ tst(scratch, Operand(HeapNumber::kSignMask)); | 2726 __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
2708 DeoptimizeIf(ne, instr->environment()); | 2727 DeoptimizeIf(ne, instr->environment()); |
2709 __ bind(&done); | 2728 __ bind(&done); |
2710 } | 2729 } |
2711 | 2730 |
2712 | 2731 |
2713 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { | 2732 void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { |
2714 DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); | 2733 DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); |
2715 ASSERT(ToDoubleRegister(instr->result()).is(input)); | 2734 ASSERT(ToDoubleRegister(instr->result()).is(input)); |
2716 __ vsqrt(input, input); | 2735 __ vsqrt(input, input); |
2717 } | 2736 } |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3331 ASSERT(result->IsDoubleRegister()); | 3350 ASSERT(result->IsDoubleRegister()); |
3332 | 3351 |
3333 Register input_reg = ToRegister(input); | 3352 Register input_reg = ToRegister(input); |
3334 DoubleRegister result_reg = ToDoubleRegister(result); | 3353 DoubleRegister result_reg = ToDoubleRegister(result); |
3335 | 3354 |
3336 EmitNumberUntagD(input_reg, result_reg, instr->environment()); | 3355 EmitNumberUntagD(input_reg, result_reg, instr->environment()); |
3337 } | 3356 } |
3338 | 3357 |
3339 | 3358 |
3340 void LCodeGen::DoDoubleToI(LDoubleToI* instr) { | 3359 void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
3341 Abort("DoDoubleToI unimplemented."); | 3360 LOperand* input = instr->InputAt(0); |
| 3361 ASSERT(input->IsDoubleRegister()); |
| 3362 LOperand* result = instr->result(); |
| 3363 ASSERT(result->IsRegister()); |
| 3364 |
| 3365 DoubleRegister double_input = ToDoubleRegister(input); |
| 3366 Register result_reg = ToRegister(result); |
| 3367 SwVfpRegister single_scratch = double_scratch0().low(); |
| 3368 Register scratch1 = scratch0(); |
| 3369 Register scratch2 = ToRegister(instr->TempAt(0)); |
| 3370 |
| 3371 VFPRoundingMode rounding_mode = instr->truncating() ? kRoundToMinusInf |
| 3372 : kRoundToNearest; |
| 3373 |
| 3374 |
| 3375 EmitVFPTruncate(rounding_mode, |
| 3376 single_scratch, |
| 3377 double_input, |
| 3378 scratch1, |
| 3379 scratch2); |
| 3380 // Deoptimize if we had a vfp invalid exception. |
| 3381 DeoptimizeIf(ne, instr->environment()); |
| 3382 // Retrieve the result. |
| 3383 __ vmov(result_reg, single_scratch); |
| 3384 |
| 3385 if (instr->truncating() && |
| 3386 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3387 Label done; |
| 3388 __ cmp(result_reg, Operand(0)); |
| 3389 __ b(ne, &done); |
| 3390 // Check for -0. |
| 3391 __ vmov(scratch1, double_input.high()); |
| 3392 __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
| 3393 DeoptimizeIf(ne, instr->environment()); |
| 3394 |
| 3395 __ bind(&done); |
| 3396 } |
3342 } | 3397 } |
3343 | 3398 |
3344 | 3399 |
3345 void LCodeGen::DoCheckSmi(LCheckSmi* instr) { | 3400 void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
3346 LOperand* input = instr->InputAt(0); | 3401 LOperand* input = instr->InputAt(0); |
3347 ASSERT(input->IsRegister()); | 3402 ASSERT(input->IsRegister()); |
3348 __ tst(ToRegister(input), Operand(kSmiTagMask)); | 3403 __ tst(ToRegister(input), Operand(kSmiTagMask)); |
3349 DeoptimizeIf(instr->condition(), instr->environment()); | 3404 DeoptimizeIf(instr->condition(), instr->environment()); |
3350 } | 3405 } |
3351 | 3406 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3723 | 3778 |
3724 | 3779 |
3725 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { | 3780 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
3726 Abort("DoOsrEntry unimplemented."); | 3781 Abort("DoOsrEntry unimplemented."); |
3727 } | 3782 } |
3728 | 3783 |
3729 | 3784 |
3730 #undef __ | 3785 #undef __ |
3731 | 3786 |
3732 } } // namespace v8::internal | 3787 } } // namespace v8::internal |
OLD | NEW |