OLD | NEW |
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 3502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3513 __ cvttsd2si(output_reg, input_reg); | 3513 __ cvttsd2si(output_reg, input_reg); |
3514 // Overflow is signalled with minint. | 3514 // Overflow is signalled with minint. |
3515 __ cmpl(output_reg, Immediate(0x80000000)); | 3515 __ cmpl(output_reg, Immediate(0x80000000)); |
3516 DeoptimizeIf(equal, instr->environment()); | 3516 DeoptimizeIf(equal, instr->environment()); |
3517 __ jmp(&done, Label::kNear); | 3517 __ jmp(&done, Label::kNear); |
3518 | 3518 |
3519 // Non-zero negative reaches here. | 3519 // Non-zero negative reaches here. |
3520 __ bind(&negative_sign); | 3520 __ bind(&negative_sign); |
3521 // Truncate, then compare and compensate. | 3521 // Truncate, then compare and compensate. |
3522 __ cvttsd2si(output_reg, input_reg); | 3522 __ cvttsd2si(output_reg, input_reg); |
3523 __ Cvtlsi2sd(xmm_scratch, output_reg); | 3523 __ cvtlsi2sd(xmm_scratch, output_reg); |
3524 __ ucomisd(input_reg, xmm_scratch); | 3524 __ ucomisd(input_reg, xmm_scratch); |
3525 __ j(equal, &done, Label::kNear); | 3525 __ j(equal, &done, Label::kNear); |
3526 __ subl(output_reg, Immediate(1)); | 3526 __ subl(output_reg, Immediate(1)); |
3527 DeoptimizeIf(overflow, instr->environment()); | 3527 DeoptimizeIf(overflow, instr->environment()); |
3528 | 3528 |
3529 __ bind(&done); | 3529 __ bind(&done); |
3530 } | 3530 } |
3531 } | 3531 } |
3532 | 3532 |
3533 | 3533 |
(...skipping 28 matching lines...) Expand all Loading... |
3562 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then | 3562 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then |
3563 // compare and compensate. | 3563 // compare and compensate. |
3564 __ movq(kScratchRegister, input_reg); // Back up input_reg. | 3564 __ movq(kScratchRegister, input_reg); // Back up input_reg. |
3565 __ subsd(input_reg, xmm_scratch); | 3565 __ subsd(input_reg, xmm_scratch); |
3566 __ cvttsd2si(output_reg, input_reg); | 3566 __ cvttsd2si(output_reg, input_reg); |
3567 // Catch minint due to overflow, and to prevent overflow when compensating. | 3567 // Catch minint due to overflow, and to prevent overflow when compensating. |
3568 __ cmpl(output_reg, Immediate(0x80000000)); | 3568 __ cmpl(output_reg, Immediate(0x80000000)); |
3569 __ RecordComment("D2I conversion overflow"); | 3569 __ RecordComment("D2I conversion overflow"); |
3570 DeoptimizeIf(equal, instr->environment()); | 3570 DeoptimizeIf(equal, instr->environment()); |
3571 | 3571 |
3572 __ Cvtlsi2sd(xmm_scratch, output_reg); | 3572 __ cvtlsi2sd(xmm_scratch, output_reg); |
3573 __ ucomisd(input_reg, xmm_scratch); | 3573 __ ucomisd(input_reg, xmm_scratch); |
3574 __ j(equal, &restore, Label::kNear); | 3574 __ j(equal, &restore, Label::kNear); |
3575 __ subl(output_reg, Immediate(1)); | 3575 __ subl(output_reg, Immediate(1)); |
3576 // No overflow because we already ruled out minint. | 3576 // No overflow because we already ruled out minint. |
3577 __ bind(&restore); | 3577 __ bind(&restore); |
3578 __ movq(input_reg, kScratchRegister); // Restore input_reg. | 3578 __ movq(input_reg, kScratchRegister); // Restore input_reg. |
3579 __ jmp(&done); | 3579 __ jmp(&done); |
3580 | 3580 |
3581 __ bind(&round_to_zero); | 3581 __ bind(&round_to_zero); |
3582 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if | 3582 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4442 __ StoreToSafepointRegisterSlot(result, rax); | 4442 __ StoreToSafepointRegisterSlot(result, rax); |
4443 } | 4443 } |
4444 | 4444 |
4445 | 4445 |
4446 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { | 4446 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
4447 LOperand* input = instr->value(); | 4447 LOperand* input = instr->value(); |
4448 ASSERT(input->IsRegister() || input->IsStackSlot()); | 4448 ASSERT(input->IsRegister() || input->IsStackSlot()); |
4449 LOperand* output = instr->result(); | 4449 LOperand* output = instr->result(); |
4450 ASSERT(output->IsDoubleRegister()); | 4450 ASSERT(output->IsDoubleRegister()); |
4451 if (input->IsRegister()) { | 4451 if (input->IsRegister()) { |
4452 __ Cvtlsi2sd(ToDoubleRegister(output), ToRegister(input)); | 4452 __ cvtlsi2sd(ToDoubleRegister(output), ToRegister(input)); |
4453 } else { | 4453 } else { |
4454 __ Cvtlsi2sd(ToDoubleRegister(output), ToOperand(input)); | 4454 __ cvtlsi2sd(ToDoubleRegister(output), ToOperand(input)); |
4455 } | 4455 } |
4456 } | 4456 } |
4457 | 4457 |
4458 | 4458 |
4459 void LCodeGen::DoInteger32ToSmi(LInteger32ToSmi* instr) { | 4459 void LCodeGen::DoInteger32ToSmi(LInteger32ToSmi* instr) { |
4460 LOperand* input = instr->value(); | 4460 LOperand* input = instr->value(); |
4461 ASSERT(input->IsRegister()); | 4461 ASSERT(input->IsRegister()); |
4462 LOperand* output = instr->result(); | 4462 LOperand* output = instr->result(); |
4463 __ Integer32ToSmi(ToRegister(output), ToRegister(input)); | 4463 __ Integer32ToSmi(ToRegister(output), ToRegister(input)); |
4464 if (!instr->hydrogen()->value()->HasRange() || | 4464 if (!instr->hydrogen()->value()->HasRange() || |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4616 __ SmiToInteger32(input, input); | 4616 __ SmiToInteger32(input, input); |
4617 } | 4617 } |
4618 | 4618 |
4619 | 4619 |
4620 void LCodeGen::EmitNumberUntagD(Register input_reg, | 4620 void LCodeGen::EmitNumberUntagD(Register input_reg, |
4621 XMMRegister result_reg, | 4621 XMMRegister result_reg, |
4622 bool can_convert_undefined_to_nan, | 4622 bool can_convert_undefined_to_nan, |
4623 bool deoptimize_on_minus_zero, | 4623 bool deoptimize_on_minus_zero, |
4624 LEnvironment* env, | 4624 LEnvironment* env, |
4625 NumberUntagDMode mode) { | 4625 NumberUntagDMode mode) { |
4626 Label convert, load_smi, done; | 4626 Label load_smi, done; |
4627 | 4627 |
4628 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { | 4628 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
4629 // Smi check. | 4629 // Smi check. |
4630 __ JumpIfSmi(input_reg, &load_smi, Label::kNear); | 4630 __ JumpIfSmi(input_reg, &load_smi, Label::kNear); |
4631 | 4631 |
4632 // Heap number map check. | 4632 // Heap number map check. |
4633 __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), | 4633 __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), |
4634 Heap::kHeapNumberMapRootIndex); | 4634 Heap::kHeapNumberMapRootIndex); |
| 4635 if (!can_convert_undefined_to_nan) { |
| 4636 DeoptimizeIf(not_equal, env); |
| 4637 } else { |
| 4638 Label heap_number, convert; |
| 4639 __ j(equal, &heap_number, Label::kNear); |
4635 | 4640 |
4636 // On x64 it is safe to load at heap number offset before evaluating the map | 4641 // Convert undefined (and hole) to NaN. Compute NaN as 0/0. |
4637 // check, since all heap objects are at least two words long. | 4642 __ CompareRoot(input_reg, Heap::kUndefinedValueRootIndex); |
| 4643 DeoptimizeIf(not_equal, env); |
| 4644 |
| 4645 __ bind(&convert); |
| 4646 __ xorps(result_reg, result_reg); |
| 4647 __ divsd(result_reg, result_reg); |
| 4648 __ jmp(&done, Label::kNear); |
| 4649 |
| 4650 __ bind(&heap_number); |
| 4651 } |
| 4652 // Heap number to XMM conversion. |
4638 __ movsd(result_reg, FieldOperand(input_reg, HeapNumber::kValueOffset)); | 4653 __ movsd(result_reg, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
4639 | |
4640 if (can_convert_undefined_to_nan) { | |
4641 __ j(not_equal, &convert); | |
4642 } else { | |
4643 DeoptimizeIf(not_equal, env); | |
4644 } | |
4645 | |
4646 if (deoptimize_on_minus_zero) { | 4654 if (deoptimize_on_minus_zero) { |
4647 XMMRegister xmm_scratch = xmm0; | 4655 XMMRegister xmm_scratch = xmm0; |
4648 __ xorps(xmm_scratch, xmm_scratch); | 4656 __ xorps(xmm_scratch, xmm_scratch); |
4649 __ ucomisd(xmm_scratch, result_reg); | 4657 __ ucomisd(xmm_scratch, result_reg); |
4650 __ j(not_equal, &done, Label::kNear); | 4658 __ j(not_equal, &done, Label::kNear); |
4651 __ movmskpd(kScratchRegister, result_reg); | 4659 __ movmskpd(kScratchRegister, result_reg); |
4652 __ testq(kScratchRegister, Immediate(1)); | 4660 __ testq(kScratchRegister, Immediate(1)); |
4653 DeoptimizeIf(not_zero, env); | 4661 DeoptimizeIf(not_zero, env); |
4654 } | 4662 } |
4655 __ jmp(&done, Label::kNear); | 4663 __ jmp(&done, Label::kNear); |
4656 | |
4657 if (can_convert_undefined_to_nan) { | |
4658 __ bind(&convert); | |
4659 | |
4660 // Convert undefined (and hole) to NaN. Compute NaN as 0/0. | |
4661 __ CompareRoot(input_reg, Heap::kUndefinedValueRootIndex); | |
4662 DeoptimizeIf(not_equal, env); | |
4663 | |
4664 __ xorps(result_reg, result_reg); | |
4665 __ divsd(result_reg, result_reg); | |
4666 __ jmp(&done, Label::kNear); | |
4667 } | |
4668 } else { | 4664 } else { |
4669 ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); | 4665 ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
4670 } | 4666 } |
4671 | 4667 |
4672 // Smi to XMM conversion | 4668 // Smi to XMM conversion |
4673 __ bind(&load_smi); | 4669 __ bind(&load_smi); |
4674 __ SmiToInteger32(kScratchRegister, input_reg); | 4670 __ SmiToInteger32(kScratchRegister, input_reg); |
4675 __ Cvtlsi2sd(result_reg, kScratchRegister); | 4671 __ cvtlsi2sd(result_reg, kScratchRegister); |
4676 __ bind(&done); | 4672 __ bind(&done); |
4677 } | 4673 } |
4678 | 4674 |
4679 | 4675 |
4680 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr, Label* done) { | 4676 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr, Label* done) { |
4681 Label heap_number; | 4677 Label heap_number; |
4682 Register input_reg = ToRegister(instr->value()); | 4678 Register input_reg = ToRegister(instr->value()); |
4683 | 4679 |
4684 | 4680 |
4685 if (instr->truncating()) { | 4681 if (instr->truncating()) { |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5497 FixedArray::kHeaderSize - kPointerSize)); | 5493 FixedArray::kHeaderSize - kPointerSize)); |
5498 __ bind(&done); | 5494 __ bind(&done); |
5499 } | 5495 } |
5500 | 5496 |
5501 | 5497 |
5502 #undef __ | 5498 #undef __ |
5503 | 5499 |
5504 } } // namespace v8::internal | 5500 } } // namespace v8::internal |
5505 | 5501 |
5506 #endif // V8_TARGET_ARCH_X64 | 5502 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |