OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/counters.h" | 9 #include "src/counters.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 | 1677 |
1678 __ movp(rdx, rdi); | 1678 __ movp(rdx, rdi); |
1679 // Run the native code for the Array function called as a normal function. | 1679 // Run the native code for the Array function called as a normal function. |
1680 // tail call a stub | 1680 // tail call a stub |
1681 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); | 1681 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); |
1682 ArrayConstructorStub stub(masm->isolate()); | 1682 ArrayConstructorStub stub(masm->isolate()); |
1683 __ TailCallStub(&stub); | 1683 __ TailCallStub(&stub); |
1684 } | 1684 } |
1685 | 1685 |
1686 // static | 1686 // static |
1687 void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) { | |
1688 // ----------- S t a t e ------------- | |
1689 // -- rax : number of arguments | |
1690 // -- rdi : function | |
1691 // -- rsi : context | |
1692 // -- rsp[0] : return address | |
1693 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) | |
1694 // -- rsp[(argc + 1) * 8] : receiver | |
1695 // ----------------------------------- | |
1696 Condition const cc = (kind == MathMaxMinKind::kMin) ? below : above; | |
1697 Heap::RootListIndex const root_index = | |
1698 (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex | |
1699 : Heap::kMinusInfinityValueRootIndex; | |
1700 XMMRegister const reg = (kind == MathMaxMinKind::kMin) ? xmm1 : xmm0; | |
1701 | |
1702 // Load the accumulator with the default return value (either -Infinity or | |
1703 // +Infinity), with the tagged value in rdx and the double value in xmm0. | |
1704 __ LoadRoot(rdx, root_index); | |
1705 __ Movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); | |
1706 __ Move(rcx, rax); | |
1707 | |
1708 Label done_loop, loop; | |
1709 __ bind(&loop); | |
1710 { | |
1711 // Check if all parameters done. | |
1712 __ testp(rcx, rcx); | |
1713 __ j(zero, &done_loop); | |
1714 | |
1715 // Load the next parameter tagged value into rbx. | |
1716 __ movp(rbx, Operand(rsp, rcx, times_pointer_size, 0)); | |
1717 | |
1718 // Load the double value of the parameter into xmm1, maybe converting the | |
1719 // parameter to a number first using the ToNumber builtin if necessary. | |
1720 Label convert, convert_smi, convert_number, done_convert; | |
1721 __ bind(&convert); | |
1722 __ JumpIfSmi(rbx, &convert_smi); | |
1723 __ JumpIfRoot(FieldOperand(rbx, HeapObject::kMapOffset), | |
1724 Heap::kHeapNumberMapRootIndex, &convert_number); | |
1725 { | |
1726 // Parameter is not a Number, use the ToNumber builtin to convert it. | |
1727 FrameScope scope(masm, StackFrame::MANUAL); | |
1728 __ Integer32ToSmi(rax, rax); | |
1729 __ Integer32ToSmi(rcx, rcx); | |
1730 __ EnterBuiltinFrame(rsi, rdi, rax); | |
1731 __ Push(rcx); | |
1732 __ Push(rdx); | |
1733 __ movp(rax, rbx); | |
1734 __ Call(masm->isolate()->builtins()->ToNumber(), RelocInfo::CODE_TARGET); | |
1735 __ movp(rbx, rax); | |
1736 __ Pop(rdx); | |
1737 __ Pop(rcx); | |
1738 __ LeaveBuiltinFrame(rsi, rdi, rax); | |
1739 __ SmiToInteger32(rcx, rcx); | |
1740 __ SmiToInteger32(rax, rax); | |
1741 { | |
1742 // Restore the double accumulator value (xmm0). | |
1743 Label restore_smi, done_restore; | |
1744 __ JumpIfSmi(rdx, &restore_smi, Label::kNear); | |
1745 __ Movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); | |
1746 __ jmp(&done_restore, Label::kNear); | |
1747 __ bind(&restore_smi); | |
1748 __ SmiToDouble(xmm0, rdx); | |
1749 __ bind(&done_restore); | |
1750 } | |
1751 } | |
1752 __ jmp(&convert); | |
1753 __ bind(&convert_number); | |
1754 __ Movsd(xmm1, FieldOperand(rbx, HeapNumber::kValueOffset)); | |
1755 __ jmp(&done_convert, Label::kNear); | |
1756 __ bind(&convert_smi); | |
1757 __ SmiToDouble(xmm1, rbx); | |
1758 __ bind(&done_convert); | |
1759 | |
1760 // Perform the actual comparison with the accumulator value on the left hand | |
1761 // side (xmm0) and the next parameter value on the right hand side (xmm1). | |
1762 Label compare_equal, compare_nan, compare_swap, done_compare; | |
1763 __ Ucomisd(xmm0, xmm1); | |
1764 __ j(parity_even, &compare_nan, Label::kNear); | |
1765 __ j(cc, &done_compare, Label::kNear); | |
1766 __ j(equal, &compare_equal, Label::kNear); | |
1767 | |
1768 // Result is on the right hand side. | |
1769 __ bind(&compare_swap); | |
1770 __ Movaps(xmm0, xmm1); | |
1771 __ Move(rdx, rbx); | |
1772 __ jmp(&done_compare, Label::kNear); | |
1773 | |
1774 // At least one side is NaN, which means that the result will be NaN too. | |
1775 __ bind(&compare_nan); | |
1776 __ LoadRoot(rdx, Heap::kNanValueRootIndex); | |
1777 __ Movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); | |
1778 __ jmp(&done_compare, Label::kNear); | |
1779 | |
1780 // Left and right hand side are equal, check for -0 vs. +0. | |
1781 __ bind(&compare_equal); | |
1782 __ Movmskpd(kScratchRegister, reg); | |
1783 __ testl(kScratchRegister, Immediate(1)); | |
1784 __ j(not_zero, &compare_swap); | |
1785 | |
1786 __ bind(&done_compare); | |
1787 __ decp(rcx); | |
1788 __ jmp(&loop); | |
1789 } | |
1790 | |
1791 __ bind(&done_loop); | |
1792 __ PopReturnAddressTo(rcx); | |
1793 __ leap(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize)); | |
1794 __ PushReturnAddressFrom(rcx); | |
1795 __ movp(rax, rdx); | |
1796 __ Ret(); | |
1797 } | |
1798 | |
1799 // static | |
1800 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { | 1687 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { |
1801 // ----------- S t a t e ------------- | 1688 // ----------- S t a t e ------------- |
1802 // -- rax : number of arguments | 1689 // -- rax : number of arguments |
1803 // -- rdi : constructor function | 1690 // -- rdi : constructor function |
1804 // -- rsi : context | 1691 // -- rsi : context |
1805 // -- rsp[0] : return address | 1692 // -- rsp[0] : return address |
1806 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) | 1693 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) |
1807 // -- rsp[(argc + 1) * 8] : receiver | 1694 // -- rsp[(argc + 1) * 8] : receiver |
1808 // ----------------------------------- | 1695 // ----------------------------------- |
1809 | 1696 |
(...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3297 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { | 3184 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { |
3298 Generate_OnStackReplacementHelper(masm, true); | 3185 Generate_OnStackReplacementHelper(masm, true); |
3299 } | 3186 } |
3300 | 3187 |
3301 #undef __ | 3188 #undef __ |
3302 | 3189 |
3303 } // namespace internal | 3190 } // namespace internal |
3304 } // namespace v8 | 3191 } // namespace v8 |
3305 | 3192 |
3306 #endif // V8_TARGET_ARCH_X64 | 3193 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |