| Index: src/ia32/builtins-ia32.cc
|
| diff --git a/src/ia32/builtins-ia32.cc b/src/ia32/builtins-ia32.cc
|
| index b12de805e2c958913cb3badf3f032a3b8d7abf62..4043ea207126a3494720ba845c1de860ac57b4f0 100644
|
| --- a/src/ia32/builtins-ia32.cc
|
| +++ b/src/ia32/builtins-ia32.cc
|
| @@ -1416,6 +1416,122 @@ void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
|
|
|
|
|
| // static
|
| +void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) {
|
| + // ----------- S t a t e -------------
|
| + // -- eax : number of arguments
|
| + // -- esp[0] : return address
|
| + // -- esp[(argc - n) * 8] : arg[n] (zero-based)
|
| + // -- esp[(argc + 1) * 8] : receiver
|
| + // -----------------------------------
|
| + Condition const cc = (kind == MathMaxMinKind::kMin) ? below : above;
|
| + Heap::RootListIndex const root_index =
|
| + (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex
|
| + : Heap::kMinusInfinityValueRootIndex;
|
| + XMMRegister const reg = (kind == MathMaxMinKind::kMin) ? xmm1 : xmm0;
|
| +
|
| + // Load the accumulator with the default return value (either -Infinity or
|
| + // +Infinity), with the tagged value in edx and the double value in xmm0.
|
| + __ LoadRoot(edx, root_index);
|
| + __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
|
| + __ Move(ecx, eax);
|
| +
|
| + Label done_loop, loop;
|
| + __ bind(&loop);
|
| + {
|
| + // Check if all parameters done.
|
| + __ test(ecx, ecx);
|
| + __ j(zero, &done_loop);
|
| +
|
| + // Load the next parameter tagged value into ebx.
|
| + __ mov(ebx, Operand(esp, ecx, times_pointer_size, 0));
|
| +
|
| + // Load the double value of the parameter into xmm1, maybe converting the
|
| + // parameter to a number first using the ToNumberStub if necessary.
|
| + Label convert, convert_smi, convert_number, done_convert;
|
| + __ bind(&convert);
|
| + __ JumpIfSmi(ebx, &convert_smi);
|
| + __ JumpIfRoot(FieldOperand(ebx, HeapObject::kMapOffset),
|
| + Heap::kHeapNumberMapRootIndex, &convert_number);
|
| + {
|
| + // Parameter is not a Number, use the ToNumberStub to convert it.
|
| + FrameScope scope(masm, StackFrame::INTERNAL);
|
| + __ SmiTag(eax);
|
| + __ SmiTag(ecx);
|
| + __ Push(eax);
|
| + __ Push(ecx);
|
| + __ Push(edx);
|
| + __ mov(eax, ebx);
|
| + ToNumberStub stub(masm->isolate());
|
| + __ CallStub(&stub);
|
| + __ mov(ebx, eax);
|
| + __ Pop(edx);
|
| + __ Pop(ecx);
|
| + __ Pop(eax);
|
| + {
|
| + // Restore the double accumulator value (xmm0).
|
| + Label restore_smi, done_restore;
|
| + __ JumpIfSmi(edx, &restore_smi, Label::kNear);
|
| + __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
|
| + __ jmp(&done_restore, Label::kNear);
|
| + __ bind(&restore_smi);
|
| + __ SmiUntag(edx);
|
| + __ Cvtsi2sd(xmm0, edx);
|
| + __ SmiTag(edx);
|
| + __ bind(&done_restore);
|
| + }
|
| + __ SmiUntag(ecx);
|
| + __ SmiUntag(eax);
|
| + }
|
| + __ jmp(&convert);
|
| + __ bind(&convert_number);
|
| + __ movsd(xmm1, FieldOperand(ebx, HeapNumber::kValueOffset));
|
| + __ jmp(&done_convert, Label::kNear);
|
| + __ bind(&convert_smi);
|
| + __ SmiUntag(ebx);
|
| + __ Cvtsi2sd(xmm1, ebx);
|
| + __ SmiTag(ebx);
|
| + __ bind(&done_convert);
|
| +
|
| + // Perform the actual comparison with the accumulator value on the left hand
|
| + // side (xmm0) and the next parameter value on the right hand side (xmm1).
|
| + Label compare_equal, compare_nan, compare_swap, done_compare;
|
| + __ ucomisd(xmm0, xmm1);
|
| + __ j(parity_even, &compare_nan, Label::kNear);
|
| + __ j(cc, &done_compare, Label::kNear);
|
| + __ j(equal, &compare_equal, Label::kNear);
|
| +
|
| + // Result is on the right hand side.
|
| + __ bind(&compare_swap);
|
| + __ movaps(xmm0, xmm1);
|
| + __ mov(edx, ebx);
|
| + __ jmp(&done_compare, Label::kNear);
|
| +
|
| + // At least one side is NaN, which means that the result will be NaN too.
|
| + __ bind(&compare_nan);
|
| + __ LoadRoot(edx, Heap::kNanValueRootIndex);
|
| + __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
|
| + __ jmp(&done_compare, Label::kNear);
|
| +
|
| + // Left and right hand side are equal, check for -0 vs. +0.
|
| + __ bind(&compare_equal);
|
| + __ movmskpd(edi, reg);
|
| + __ test(edi, Immediate(1));
|
| + __ j(not_zero, &compare_swap);
|
| +
|
| + __ bind(&done_compare);
|
| + __ dec(ecx);
|
| + __ jmp(&loop);
|
| + }
|
| +
|
| + __ bind(&done_loop);
|
| + __ PopReturnAddressTo(ecx);
|
| + __ lea(esp, Operand(esp, eax, times_pointer_size, kPointerSize));
|
| + __ PushReturnAddressFrom(ecx);
|
| + __ mov(eax, edx);
|
| + __ Ret();
|
| +}
|
| +
|
| +// static
|
| void Builtins::Generate_NumberConstructor(MacroAssembler* masm) {
|
| // ----------- S t a t e -------------
|
| // -- eax : number of arguments
|
|
|