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

Side by Side Diff: src/builtins/ia32/builtins-ia32.cc

Issue 2728463006: Migrate Math.Min/Max to CodeStubAssembler (Closed)
Patch Set: ChangeFloat64ToTagged Created 3 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
« no previous file with comments | « src/builtins/builtins-math.cc ('k') | src/builtins/mips/builtins-mips.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 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_IA32 5 #if V8_TARGET_ARCH_IA32
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/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 } 1712 }
1713 1713
1714 // Run the native code for the Array function called as a normal function. 1714 // Run the native code for the Array function called as a normal function.
1715 // tail call a stub 1715 // tail call a stub
1716 __ mov(ebx, masm->isolate()->factory()->undefined_value()); 1716 __ mov(ebx, masm->isolate()->factory()->undefined_value());
1717 ArrayConstructorStub stub(masm->isolate()); 1717 ArrayConstructorStub stub(masm->isolate());
1718 __ TailCallStub(&stub); 1718 __ TailCallStub(&stub);
1719 } 1719 }
1720 1720
1721 // static 1721 // static
1722 void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) {
1723 // ----------- S t a t e -------------
1724 // -- eax : number of arguments
1725 // -- edi : function
1726 // -- esi : context
1727 // -- esp[0] : return address
1728 // -- esp[(argc - n) * 8] : arg[n] (zero-based)
1729 // -- esp[(argc + 1) * 8] : receiver
1730 // -----------------------------------
1731 Condition const cc = (kind == MathMaxMinKind::kMin) ? below : above;
1732 Heap::RootListIndex const root_index =
1733 (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex
1734 : Heap::kMinusInfinityValueRootIndex;
1735 XMMRegister const reg = (kind == MathMaxMinKind::kMin) ? xmm1 : xmm0;
1736
1737 // Load the accumulator with the default return value (either -Infinity or
1738 // +Infinity), with the tagged value in edx and the double value in xmm0.
1739 __ LoadRoot(edx, root_index);
1740 __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
1741 __ Move(ecx, eax);
1742
1743 Label done_loop, loop;
1744 __ bind(&loop);
1745 {
1746 // Check if all parameters done.
1747 __ test(ecx, ecx);
1748 __ j(zero, &done_loop);
1749
1750 // Load the next parameter tagged value into ebx.
1751 __ mov(ebx, Operand(esp, ecx, times_pointer_size, 0));
1752
1753 // Load the double value of the parameter into xmm1, maybe converting the
1754 // parameter to a number first using the ToNumber builtin if necessary.
1755 Label convert, convert_smi, convert_number, done_convert;
1756 __ bind(&convert);
1757 __ JumpIfSmi(ebx, &convert_smi);
1758 __ JumpIfRoot(FieldOperand(ebx, HeapObject::kMapOffset),
1759 Heap::kHeapNumberMapRootIndex, &convert_number);
1760 {
1761 // Parameter is not a Number, use the ToNumber builtin to convert it.
1762 FrameScope scope(masm, StackFrame::MANUAL);
1763 __ SmiTag(eax);
1764 __ SmiTag(ecx);
1765 __ EnterBuiltinFrame(esi, edi, eax);
1766 __ Push(ecx);
1767 __ Push(edx);
1768 __ mov(eax, ebx);
1769 __ Call(masm->isolate()->builtins()->ToNumber(), RelocInfo::CODE_TARGET);
1770 __ mov(ebx, eax);
1771 __ Pop(edx);
1772 __ Pop(ecx);
1773 __ LeaveBuiltinFrame(esi, edi, eax);
1774 __ SmiUntag(ecx);
1775 __ SmiUntag(eax);
1776 {
1777 // Restore the double accumulator value (xmm0).
1778 Label restore_smi, done_restore;
1779 __ JumpIfSmi(edx, &restore_smi, Label::kNear);
1780 __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
1781 __ jmp(&done_restore, Label::kNear);
1782 __ bind(&restore_smi);
1783 __ SmiUntag(edx);
1784 __ Cvtsi2sd(xmm0, edx);
1785 __ SmiTag(edx);
1786 __ bind(&done_restore);
1787 }
1788 }
1789 __ jmp(&convert);
1790 __ bind(&convert_number);
1791 __ movsd(xmm1, FieldOperand(ebx, HeapNumber::kValueOffset));
1792 __ jmp(&done_convert, Label::kNear);
1793 __ bind(&convert_smi);
1794 __ SmiUntag(ebx);
1795 __ Cvtsi2sd(xmm1, ebx);
1796 __ SmiTag(ebx);
1797 __ bind(&done_convert);
1798
1799 // Perform the actual comparison with the accumulator value on the left hand
1800 // side (xmm0) and the next parameter value on the right hand side (xmm1).
1801 Label compare_equal, compare_nan, compare_swap, done_compare;
1802 __ ucomisd(xmm0, xmm1);
1803 __ j(parity_even, &compare_nan, Label::kNear);
1804 __ j(cc, &done_compare, Label::kNear);
1805 __ j(equal, &compare_equal, Label::kNear);
1806
1807 // Result is on the right hand side.
1808 __ bind(&compare_swap);
1809 __ movaps(xmm0, xmm1);
1810 __ mov(edx, ebx);
1811 __ jmp(&done_compare, Label::kNear);
1812
1813 // At least one side is NaN, which means that the result will be NaN too.
1814 __ bind(&compare_nan);
1815 __ LoadRoot(edx, Heap::kNanValueRootIndex);
1816 __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
1817 __ jmp(&done_compare, Label::kNear);
1818
1819 // Left and right hand side are equal, check for -0 vs. +0.
1820 __ bind(&compare_equal);
1821 __ Push(edi); // Preserve function in edi.
1822 __ movmskpd(edi, reg);
1823 __ test(edi, Immediate(1));
1824 __ Pop(edi);
1825 __ j(not_zero, &compare_swap);
1826
1827 __ bind(&done_compare);
1828 __ dec(ecx);
1829 __ jmp(&loop);
1830 }
1831
1832 __ bind(&done_loop);
1833 __ PopReturnAddressTo(ecx);
1834 __ lea(esp, Operand(esp, eax, times_pointer_size, kPointerSize));
1835 __ PushReturnAddressFrom(ecx);
1836 __ mov(eax, edx);
1837 __ Ret();
1838 }
1839
1840 // static
1841 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { 1722 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) {
1842 // ----------- S t a t e ------------- 1723 // ----------- S t a t e -------------
1843 // -- eax : number of arguments 1724 // -- eax : number of arguments
1844 // -- edi : constructor function 1725 // -- edi : constructor function
1845 // -- esi : context 1726 // -- esi : context
1846 // -- esp[0] : return address 1727 // -- esp[0] : return address
1847 // -- esp[(argc - n) * 4] : arg[n] (zero-based) 1728 // -- esp[(argc - n) * 4] : arg[n] (zero-based)
1848 // -- esp[(argc + 1) * 4] : receiver 1729 // -- esp[(argc + 1) * 4] : receiver
1849 // ----------------------------------- 1730 // -----------------------------------
1850 1731
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after
3402 3283
3403 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { 3284 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) {
3404 Generate_OnStackReplacementHelper(masm, true); 3285 Generate_OnStackReplacementHelper(masm, true);
3405 } 3286 }
3406 3287
3407 #undef __ 3288 #undef __
3408 } // namespace internal 3289 } // namespace internal
3409 } // namespace v8 3290 } // namespace v8
3410 3291
3411 #endif // V8_TARGET_ARCH_IA32 3292 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/builtins/builtins-math.cc ('k') | src/builtins/mips/builtins-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698