Commit efc641a7 authored by jacob.bramley's avatar jacob.bramley Committed by Commit bot

[arm64] Improve some new builtins.

- Simplify the variable-length pop sequence on entry. (It now uses
  smaller code with no branches.)
- Use conditional compare to merge branches where appropriate.
- Make use of Ldrsw + UntagSmiFieldMemOperand to load smis more
  efficiently.
- Only load 'undefined' and 'null' once per builtin.
- A few other small improvements.

BUG=

Review URL: https://codereview.chromium.org/1537903004

Cr-Commit-Position: refs/heads/master@{#32975}
parent 36afb789
...@@ -1400,54 +1400,73 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) { ...@@ -1400,54 +1400,73 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
void Builtins::Generate_FunctionApply(MacroAssembler* masm) { void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- r0 : argc // -- x0 : argc
// -- sp[0] : argArray // -- jssp[0] : argArray (if argc == 2)
// -- sp[8] : thisArg // -- jssp[8] : thisArg (if argc >= 1)
// -- sp[16] : receiver // -- jssp[16] : receiver
// ----------------------------------- // -----------------------------------
ASM_LOCATION("Builtins::Generate_FunctionApply"); ASM_LOCATION("Builtins::Generate_FunctionApply");
Register argc = x0;
Register arg_array = x0;
Register receiver = x1;
Register this_arg = x2;
Register undefined = x3;
Register null = x4;
__ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
__ LoadRoot(null, Heap::kNullValueRootIndex);
// 1. Load receiver into x1, argArray into x0 (if present), remove all // 1. Load receiver into x1, argArray into x0 (if present), remove all
// arguments from the stack (including the receiver), and push thisArg (if // arguments from the stack (including the receiver), and push thisArg (if
// present) instead. // present) instead.
{ {
Label done; // Claim (2 - argc) dummy arguments from the stack, to put the stack in a
__ LoadRoot(x2, Heap::kUndefinedValueRootIndex); // consistent state for a simple pop operation.
__ Mov(x3, x2); Register neg_argc = x10;
__ Peek(x1, Operand(x0, LSL, kPointerSizeLog2)); // receiver __ Negs(neg_argc, argc); // Negate; set the Z flag if argc == 0.
__ Subs(x4, x0, 1); __ Add(x11, neg_argc, 2);
__ B(lt, &done); __ Claim(x11);
__ Peek(x2, Operand(x4, LSL, kPointerSizeLog2)); // thisArg
__ Subs(x4, x4, 1); // ----------- S t a t e -------------
__ B(lt, &done); // -- x0 : argc
__ Peek(x3, Operand(x4, LSL, kPointerSizeLog2)); // argArray // -- jssp[0] : argArray (dummy value if argc <= 1)
__ Bind(&done); // -- jssp[8] : thisArg (dummy value if argc == 0)
__ Drop(x0); // -- jssp[16] : receiver
__ Poke(x2, 0); // -----------------------------------
__ Mov(x0, x3); __ Pop(arg_array, this_arg);
__ CmovX(this_arg, undefined, eq); // undefined if argc == 0.
__ Cmp(neg_argc, -1);
__ CmovX(arg_array, undefined, ge); // undefined if argc <= 1.
__ Peek(receiver, 0);
__ Poke(this_arg, 0);
} }
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- x0 : argArray // -- x0 : argArray
// -- x1 : receiver // -- x1 : receiver
// -- sp[0] : thisArg // -- x3 : undefined root value
// -- jssp[0] : thisArg
// ----------------------------------- // -----------------------------------
// 2. Make sure the receiver is actually callable. // 2. Make sure the receiver is actually callable.
Label receiver_not_callable; Label receiver_not_callable;
__ JumpIfSmi(x1, &receiver_not_callable); __ JumpIfSmi(receiver, &receiver_not_callable);
__ Ldr(x4, FieldMemOperand(x1, HeapObject::kMapOffset)); __ Ldr(x10, FieldMemOperand(receiver, HeapObject::kMapOffset));
__ Ldrb(x4, FieldMemOperand(x4, Map::kBitFieldOffset)); __ Ldrb(w10, FieldMemOperand(x10, Map::kBitFieldOffset));
__ TestAndBranchIfAllClear(x4, 1 << Map::kIsCallable, &receiver_not_callable); __ TestAndBranchIfAllClear(x10, 1 << Map::kIsCallable,
&receiver_not_callable);
// 3. Tail call with no arguments if argArray is null or undefined. // 3. Tail call with no arguments if argArray is null or undefined.
Label no_arguments; Label no_arguments;
__ JumpIfRoot(x0, Heap::kNullValueRootIndex, &no_arguments); __ Cmp(arg_array, null);
__ JumpIfRoot(x0, Heap::kUndefinedValueRootIndex, &no_arguments); __ Ccmp(arg_array, undefined, ZFlag, ne);
__ B(eq, &no_arguments);
// 4a. Apply the receiver to the given argArray (passing undefined for // 4a. Apply the receiver to the given argArray (passing undefined for
// new.target). // new.target in x3).
__ LoadRoot(x3, Heap::kUndefinedValueRootIndex); DCHECK(undefined.Is(x3));
__ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET); __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
// 4b. The argArray is either null or undefined, so we tail call without any // 4b. The argArray is either null or undefined, so we tail call without any
...@@ -1455,13 +1474,14 @@ void Builtins::Generate_FunctionApply(MacroAssembler* masm) { ...@@ -1455,13 +1474,14 @@ void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
__ Bind(&no_arguments); __ Bind(&no_arguments);
{ {
__ Mov(x0, 0); __ Mov(x0, 0);
DCHECK(receiver.Is(x1));
__ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
} }
// 4c. The receiver is not callable, throw an appropriate TypeError. // 4c. The receiver is not callable, throw an appropriate TypeError.
__ Bind(&receiver_not_callable); __ Bind(&receiver_not_callable);
{ {
__ Poke(x1, 0); __ Poke(receiver, 0);
__ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1, 1); __ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1, 1);
} }
} }
...@@ -1470,58 +1490,69 @@ void Builtins::Generate_FunctionApply(MacroAssembler* masm) { ...@@ -1470,58 +1490,69 @@ void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
void Builtins::Generate_ReflectApply(MacroAssembler* masm) { void Builtins::Generate_ReflectApply(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- x0 : argc // -- x0 : argc
// -- sp[0] : argumentsList // -- jssp[0] : argumentsList (if argc == 3)
// -- sp[8] : thisArgument // -- jssp[8] : thisArgument (if argc >= 2)
// -- sp[16] : target // -- jssp[16] : target (if argc >= 1)
// -- sp[24] : receiver // -- jssp[24] : receiver
// ----------------------------------- // -----------------------------------
ASM_LOCATION("Builtins::Generate_ReflectApply"); ASM_LOCATION("Builtins::Generate_ReflectApply");
Register argc = x0;
Register arguments_list = x0;
Register target = x1;
Register this_argument = x2;
Register undefined = x3;
__ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
// 1. Load target into x1 (if present), argumentsList into x0 (if present), // 1. Load target into x1 (if present), argumentsList into x0 (if present),
// remove all arguments from the stack (including the receiver), and push // remove all arguments from the stack (including the receiver), and push
// thisArgument (if present) instead. // thisArgument (if present) instead.
{ {
Label done; // Claim (3 - argc) dummy arguments from the stack, to put the stack in a
__ LoadRoot(x1, Heap::kUndefinedValueRootIndex); // consistent state for a simple pop operation.
__ Mov(x2, x1); Register neg_argc = x10;
__ Mov(x3, x1); __ Negs(neg_argc, argc); // Negate; set the Z flag if argc == 0.
__ Subs(x4, x0, 1); __ Add(x11, neg_argc, 3);
__ B(lt, &done); __ Claim(x11);
__ Peek(x1, Operand(x4, LSL, kPointerSizeLog2)); // target
__ Subs(x4, x4, 1); // ----------- S t a t e -------------
__ B(lt, &done); // -- x0 : argc
__ Peek(x2, Operand(x4, LSL, kPointerSizeLog2)); // thisArgument // -- jssp[0] : argumentsList (dummy value if argc <= 2)
__ Subs(x4, x4, 1); // -- jssp[8] : thisArgument (dummy value if argc <= 1)
__ B(lt, &done); // -- jssp[16] : target (dummy value if argc == 0)
__ Peek(x3, Operand(x4, LSL, kPointerSizeLog2)); // argumentsList // -- jssp[24] : receiver
__ Bind(&done); // -----------------------------------
__ Drop(x0); __ Pop(arguments_list, this_argument, target);
__ Poke(x2, 0); __ CmovX(target, undefined, eq); // undefined if argc == 0.
__ Mov(x0, x3); __ Cmp(neg_argc, -2);
__ CmovX(this_argument, undefined, gt); // undefined if argc <= 1.
__ CmovX(arguments_list, undefined, ge); // undefined if argc <= 2.
__ Poke(this_argument, 0); // Overwrite receiver.
} }
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- x0 : argumentsList // -- x0 : argumentsList
// -- x1 : target // -- x1 : target
// -- sp[0] : thisArgument // -- jssp[0] : thisArgument
// ----------------------------------- // -----------------------------------
// 2. Make sure the target is actually callable. // 2. Make sure the target is actually callable.
Label target_not_callable; Label target_not_callable;
__ JumpIfSmi(x1, &target_not_callable); __ JumpIfSmi(target, &target_not_callable);
__ Ldr(x4, FieldMemOperand(x1, HeapObject::kMapOffset)); __ Ldr(x10, FieldMemOperand(target, HeapObject::kMapOffset));
__ Ldrb(x4, FieldMemOperand(x4, Map::kBitFieldOffset)); __ Ldr(x10, FieldMemOperand(x10, Map::kBitFieldOffset));
__ TestAndBranchIfAllClear(x4, 1 << Map::kIsCallable, &target_not_callable); __ TestAndBranchIfAllClear(x10, 1 << Map::kIsCallable, &target_not_callable);
// 3a. Apply the target to the given argumentsList (passing undefined for // 3a. Apply the target to the given argumentsList (passing undefined for
// new.target). // new.target in x3).
__ LoadRoot(x3, Heap::kUndefinedValueRootIndex); DCHECK(undefined.Is(x3));
__ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET); __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
// 3b. The target is not callable, throw an appropriate TypeError. // 3b. The target is not callable, throw an appropriate TypeError.
__ Bind(&target_not_callable); __ Bind(&target_not_callable);
{ {
__ Poke(x1, 0); __ Poke(target, 0);
__ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1, 1); __ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1, 1);
} }
} }
...@@ -1530,58 +1561,69 @@ void Builtins::Generate_ReflectApply(MacroAssembler* masm) { ...@@ -1530,58 +1561,69 @@ void Builtins::Generate_ReflectApply(MacroAssembler* masm) {
void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) { void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- x0 : argc // -- x0 : argc
// -- sp[0] : new.target (optional) // -- jssp[0] : new.target (optional)
// -- sp[8] : argumentsList // -- jssp[8] : argumentsList
// -- sp[16] : target // -- jssp[16] : target
// -- sp[24] : receiver // -- jssp[24] : receiver
// ----------------------------------- // -----------------------------------
ASM_LOCATION("Builtins::Generate_ReflectConstruct"); ASM_LOCATION("Builtins::Generate_ReflectConstruct");
Register argc = x0;
Register arguments_list = x0;
Register target = x1;
Register new_target = x3;
Register undefined = x4;
__ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
// 1. Load target into x1 (if present), argumentsList into x0 (if present), // 1. Load target into x1 (if present), argumentsList into x0 (if present),
// new.target into x3 (if present, otherwise use target), remove all // new.target into x3 (if present, otherwise use target), remove all
// arguments from the stack (including the receiver), and push thisArgument // arguments from the stack (including the receiver), and push thisArgument
// (if present) instead. // (if present) instead.
{ {
Label done; // Claim (3 - argc) dummy arguments from the stack, to put the stack in a
__ LoadRoot(x1, Heap::kUndefinedValueRootIndex); // consistent state for a simple pop operation.
__ Mov(x2, x1); Register neg_argc = x10;
__ Poke(x2, Operand(x0, LSL, kPointerSizeLog2)); // receiver __ Negs(neg_argc, argc); // Negate; set the Z flag if argc == 0.
__ Subs(x4, x0, 1); __ Add(x11, neg_argc, 3);
__ B(lt, &done); __ Claim(x11);
__ Peek(x1, Operand(x4, LSL, kPointerSizeLog2)); // target
__ Mov(x3, x1); // new.target defaults to target // ----------- S t a t e -------------
__ Subs(x4, x4, 1); // -- x0 : argc
__ B(lt, &done); // -- jssp[0] : new.target (dummy value if argc <= 2)
__ Peek(x2, Operand(x4, LSL, kPointerSizeLog2)); // argumentsList // -- jssp[8] : argumentsList (dummy value if argc <= 1)
__ Subs(x4, x4, 1); // -- jssp[16] : target (dummy value if argc == 0)
__ B(lt, &done); // -- jssp[24] : receiver
__ Peek(x3, Operand(x4, LSL, kPointerSizeLog2)); // new.target // -----------------------------------
__ Bind(&done); __ Pop(new_target, arguments_list, target);
__ Drop(x0); __ CmovX(target, undefined, eq); // undefined if argc == 0.
__ Mov(x0, x2); __ Cmp(neg_argc, -2);
__ CmovX(arguments_list, undefined, gt); // undefined if argc <= 1.
__ CmovX(new_target, target, ge); // target if argc <= 2.
__ Poke(undefined, 0); // Overwrite receiver.
} }
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- x0 : argumentsList // -- x0 : argumentsList
// -- x3 : new.target
// -- x1 : target // -- x1 : target
// -- sp[0] : receiver (undefined) // -- x3 : new.target
// -- jssp[0] : receiver (undefined)
// ----------------------------------- // -----------------------------------
// 2. Make sure the target is actually a constructor. // 2. Make sure the target is actually a constructor.
Label target_not_constructor; Label target_not_constructor;
__ JumpIfSmi(x1, &target_not_constructor); __ JumpIfSmi(target, &target_not_constructor);
__ Ldr(x4, FieldMemOperand(x1, HeapObject::kMapOffset)); __ Ldr(x10, FieldMemOperand(target, HeapObject::kMapOffset));
__ Ldrb(x4, FieldMemOperand(x4, Map::kBitFieldOffset)); __ Ldrb(x10, FieldMemOperand(x10, Map::kBitFieldOffset));
__ TestAndBranchIfAllClear(x4, 1 << Map::kIsConstructor, __ TestAndBranchIfAllClear(x10, 1 << Map::kIsConstructor,
&target_not_constructor); &target_not_constructor);
// 3. Make sure the target is actually a constructor. // 3. Make sure the new.target is actually a constructor.
Label new_target_not_constructor; Label new_target_not_constructor;
__ JumpIfSmi(x3, &new_target_not_constructor); __ JumpIfSmi(new_target, &new_target_not_constructor);
__ Ldr(x4, FieldMemOperand(x3, HeapObject::kMapOffset)); __ Ldr(x10, FieldMemOperand(new_target, HeapObject::kMapOffset));
__ Ldrb(x4, FieldMemOperand(x4, Map::kBitFieldOffset)); __ Ldrb(x10, FieldMemOperand(x10, Map::kBitFieldOffset));
__ TestAndBranchIfAllClear(x4, 1 << Map::kIsConstructor, __ TestAndBranchIfAllClear(x10, 1 << Map::kIsConstructor,
&new_target_not_constructor); &new_target_not_constructor);
// 4a. Construct the target with the given new.target and argumentsList. // 4a. Construct the target with the given new.target and argumentsList.
...@@ -1590,14 +1632,14 @@ void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) { ...@@ -1590,14 +1632,14 @@ void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
// 4b. The target is not a constructor, throw an appropriate TypeError. // 4b. The target is not a constructor, throw an appropriate TypeError.
__ Bind(&target_not_constructor); __ Bind(&target_not_constructor);
{ {
__ Poke(x1, 0); __ Poke(target, 0);
__ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1, 1); __ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1, 1);
} }
// 4c. The new.target is not a constructor, throw an appropriate TypeError. // 4c. The new.target is not a constructor, throw an appropriate TypeError.
__ Bind(&new_target_not_constructor); __ Bind(&new_target_not_constructor);
{ {
__ Poke(x3, 0); __ Poke(new_target, 0);
__ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1, 1); __ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1, 1);
} }
} }
...@@ -1656,69 +1698,78 @@ void Builtins::Generate_Apply(MacroAssembler* masm) { ...@@ -1656,69 +1698,78 @@ void Builtins::Generate_Apply(MacroAssembler* masm) {
// -- x0 : argumentsList // -- x0 : argumentsList
// -- x1 : target // -- x1 : target
// -- x3 : new.target (checked to be constructor or undefined) // -- x3 : new.target (checked to be constructor or undefined)
// -- sp[0] : thisArgument // -- jssp[0] : thisArgument
// ----------------------------------- // -----------------------------------
Register arguments_list = x0;
Register target = x1;
Register new_target = x3;
Register args = x0;
Register len = x2;
// Create the list of arguments from the array-like argumentsList. // Create the list of arguments from the array-like argumentsList.
{ {
Label create_arguments, create_array, create_runtime, done_create; Label create_arguments, create_array, create_runtime, done_create;
__ JumpIfSmi(x0, &create_runtime); __ JumpIfSmi(arguments_list, &create_runtime);
// Load the map of argumentsList into x2. // Load native context.
__ Ldr(x2, FieldMemOperand(x0, HeapObject::kMapOffset)); Register native_context = x4;
__ Ldr(native_context, NativeContextMemOperand());
// Load native context into x4. // Load the map of argumentsList.
__ Ldr(x4, NativeContextMemOperand()); Register arguments_list_map = x2;
__ Ldr(arguments_list_map,
FieldMemOperand(arguments_list, HeapObject::kMapOffset));
// Check if argumentsList is an (unmodified) arguments object. // Check if argumentsList is an (unmodified) arguments object.
__ Ldr(x5, ContextMemOperand(x4, Context::SLOPPY_ARGUMENTS_MAP_INDEX)); __ Ldr(x10, ContextMemOperand(native_context,
__ Cmp(x5, x2); Context::SLOPPY_ARGUMENTS_MAP_INDEX));
__ B(eq, &create_arguments); __ Ldr(x11, ContextMemOperand(native_context,
__ Ldr(x5, ContextMemOperand(x4, Context::STRICT_ARGUMENTS_MAP_INDEX)); Context::STRICT_ARGUMENTS_MAP_INDEX));
__ Cmp(x5, x2); __ Cmp(arguments_list_map, x10);
__ Ccmp(arguments_list_map, x11, ZFlag, ne);
__ B(eq, &create_arguments); __ B(eq, &create_arguments);
// Check if argumentsList is a fast JSArray. // Check if argumentsList is a fast JSArray.
__ CompareInstanceType(x2, x4, JS_ARRAY_TYPE); __ CompareInstanceType(arguments_list_map, native_context, JS_ARRAY_TYPE);
__ B(eq, &create_array); __ B(eq, &create_array);
// Ask the runtime to create the list (actually a FixedArray). // Ask the runtime to create the list (actually a FixedArray).
__ Bind(&create_runtime); __ Bind(&create_runtime);
{ {
FrameScope scope(masm, StackFrame::INTERNAL); FrameScope scope(masm, StackFrame::INTERNAL);
__ Push(x1, x3, x0); __ Push(target, new_target, arguments_list);
__ CallRuntime(Runtime::kCreateListFromArrayLike, 1); __ CallRuntime(Runtime::kCreateListFromArrayLike, 1);
__ Pop(x3, x1); __ Pop(new_target, target);
__ Ldrsw(x2, UntagSmiFieldMemOperand(x0, FixedArray::kLengthOffset)); __ Ldrsw(len, UntagSmiFieldMemOperand(arguments_list,
FixedArray::kLengthOffset));
} }
__ B(&done_create); __ B(&done_create);
// Try to create the list from an arguments object. // Try to create the list from an arguments object.
__ Bind(&create_arguments); __ Bind(&create_arguments);
__ Ldr(x2, __ Ldrsw(len, UntagSmiFieldMemOperand(
FieldMemOperand(x0, JSObject::kHeaderSize + arguments_list,
JSObject::kHeaderSize +
Heap::kArgumentsLengthIndex * kPointerSize)); Heap::kArgumentsLengthIndex * kPointerSize));
__ Ldr(x4, FieldMemOperand(x0, JSObject::kElementsOffset)); __ Ldr(x10, FieldMemOperand(arguments_list, JSObject::kElementsOffset));
__ Ldr(x5, FieldMemOperand(x4, FixedArray::kLengthOffset)); __ Ldrsw(x11, UntagSmiFieldMemOperand(x10, FixedArray::kLengthOffset));
__ Cmp(x2, x4); __ CompareAndBranch(len, x11, ne, &create_runtime);
__ B(ne, &create_runtime); __ Mov(args, x10);
__ SmiUntag(x2);
__ Mov(x0, x4);
__ B(&done_create); __ B(&done_create);
// Try to create the list from a JSArray object. // Try to create the list from a JSArray object.
__ Bind(&create_array); __ Bind(&create_array);
__ Ldr(x2, FieldMemOperand(x2, Map::kBitField2Offset)); __ Ldr(x10, FieldMemOperand(arguments_list_map, Map::kBitField2Offset));
__ DecodeField<Map::ElementsKindBits>(x2); __ DecodeField<Map::ElementsKindBits>(x10);
STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
STATIC_ASSERT(FAST_ELEMENTS == 2); STATIC_ASSERT(FAST_ELEMENTS == 2);
__ Cmp(x2, FAST_ELEMENTS); // Branch for anything that's not FAST_{SMI_}ELEMENTS.
__ B(hi, &create_runtime); __ TestAndBranchIfAnySet(x10, ~FAST_ELEMENTS, &create_runtime);
__ Cmp(x2, FAST_HOLEY_SMI_ELEMENTS); __ Ldrsw(len,
__ B(eq, &create_runtime); UntagSmiFieldMemOperand(arguments_list, JSArray::kLengthOffset));
__ Ldrsw(x2, UntagSmiFieldMemOperand(x0, JSArray::kLengthOffset)); __ Ldr(args, FieldMemOperand(arguments_list, JSArray::kElementsOffset));
__ Ldr(x0, FieldMemOperand(x0, JSArray::kElementsOffset));
__ Bind(&done_create); __ Bind(&done_create);
} }
...@@ -1731,41 +1782,53 @@ void Builtins::Generate_Apply(MacroAssembler* masm) { ...@@ -1731,41 +1782,53 @@ void Builtins::Generate_Apply(MacroAssembler* masm) {
__ LoadRoot(x10, Heap::kRealStackLimitRootIndex); __ LoadRoot(x10, Heap::kRealStackLimitRootIndex);
// Make x10 the space we have left. The stack might already be overflowed // Make x10 the space we have left. The stack might already be overflowed
// here which will cause x10 to become negative. // here which will cause x10 to become negative.
__ Sub(x10, jssp, x10); __ Sub(x10, masm->StackPointer(), x10);
// Check if the arguments will overflow the stack. // Check if the arguments will overflow the stack.
__ Cmp(x10, Operand(x2, LSL, kPointerSizeLog2)); __ Cmp(x10, Operand(len, LSL, kPointerSizeLog2));
__ B(gt, &done); // Signed comparison. __ B(gt, &done); // Signed comparison.
__ TailCallRuntime(Runtime::kThrowStackOverflow, 1, 1); __ TailCallRuntime(Runtime::kThrowStackOverflow, 1, 1);
__ Bind(&done); __ Bind(&done);
} }
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- x1 : target
// -- x0 : args (a FixedArray built from argumentsList) // -- x0 : args (a FixedArray built from argumentsList)
// -- x1 : target
// -- x2 : len (number of elements to push from args) // -- x2 : len (number of elements to push from args)
// -- x3 : new.target (checked to be constructor or undefined) // -- x3 : new.target (checked to be constructor or undefined)
// -- sp[0] : thisArgument // -- jssp[0] : thisArgument
// ----------------------------------- // -----------------------------------
// Push arguments onto the stack (thisArgument is already on the stack). // Push arguments onto the stack (thisArgument is already on the stack).
{ {
__ Mov(x4, 0);
Label done, loop; Label done, loop;
Register src = x4;
__ Add(src, args, FixedArray::kHeaderSize - kHeapObjectTag);
__ Mov(x0, len); // The 'len' argument for Call() or Construct().
__ Cbz(len, &done);
__ Claim(len);
__ Bind(&loop); __ Bind(&loop);
__ Cmp(x4, x2); __ Subs(len, len, 1);
__ B(eq, &done); __ Ldr(x10, MemOperand(src, kPointerSize, PostIndex));
__ Add(x10, x0, Operand(x4, LSL, kPointerSizeLog2)); __ Poke(x10, Operand(len, LSL, kPointerSizeLog2));
__ Ldr(x10, FieldMemOperand(x10, FixedArray::kHeaderSize)); __ B(ne, &loop);
__ Push(x10);
__ Add(x4, x4, 1);
__ B(&loop);
__ Bind(&done); __ Bind(&done);
__ Mov(x0, x4);
} }
// ----------- S t a t e -------------
// -- x0 : argument count (len)
// -- x1 : target
// -- x3 : new.target (checked to be constructor or undefined)
// -- jssp[0] : args[len-1]
// -- jssp[8] : args[len-2]
// ... : ...
// -- jssp[8*(len-2)] : args[1]
// -- jssp[8*(len-1)] : args[0]
// -----------------------------------
// Dispatch to Call or Construct depending on whether new.target is undefined. // Dispatch to Call or Construct depending on whether new.target is undefined.
{ {
__ CompareRoot(x3, Heap::kUndefinedValueRootIndex); __ CompareRoot(new_target, Heap::kUndefinedValueRootIndex);
__ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET, eq); __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET, eq);
__ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment