Chromium Code Reviews| Index: src/arm/code-stubs-arm.cc |
| diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc |
| index 52b1d288fe8dfaf0ca187b512edf9ac584393f4f..a6dcda84d506f7c0e446684e06847488c674fbf5 100644 |
| --- a/src/arm/code-stubs-arm.cc |
| +++ b/src/arm/code-stubs-arm.cc |
| @@ -3938,21 +3938,240 @@ void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| } |
| -void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| - UNIMPLEMENTED(); |
| +void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
| + // sp[0] : number of parameters |
| + // sp[4] : receiver displacement |
| + // sp[8] : function |
| + |
| + // Check if the calling frame is an arguments adaptor frame. |
| + Label runtime; |
| + __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| + __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset)); |
| + __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| + __ b(ne, &runtime); |
| + |
| + // Patch the arguments.length and the parameters pointer in the current frame. |
| + __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| + __ str(r2, MemOperand(sp, 0 * kPointerSize)); |
| + __ add(r3, r3, Operand(r2, LSL, 1)); |
| + __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| + __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| + |
| + __ bind(&runtime); |
| + __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| } |
| void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| - UNIMPLEMENTED(); |
| + // Stack layout: |
| + // sp[0] : number of parameters (tagged) |
| + // sp[4] : address of receiver argument |
| + // sp[8] : function |
| + // Registers used over whole function: |
| + // r6 : allocated object (tagged) |
| + // r9 : mapped parameter count (tagged) |
| + |
| + // r1 = parameter count (untagged) |
|
Kevin Millikin (Chromium)
2011/06/07 13:54:10
(untagged) ==> (tagged)
Karl Klose
2011/06/10 11:32:22
Done.
|
| + __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| + |
| + // Check if the calling frame is an arguments adaptor frame. |
| + Label runtime; |
| + Label adaptor_frame, try_allocate; |
| + __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| + __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset)); |
| + __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| + __ b(eq, &adaptor_frame); |
| + |
| + // No adaptor, parameter count = argument count. |
| + __ mov(r2, r1); |
| + __ b(&try_allocate); |
| + |
| + // We have an adaptor frame. Patch the parameters pointer. |
| + __ bind(&adaptor_frame); |
| + __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| + __ add(r3, r3, Operand(r2, LSL, 1)); |
| + __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| + __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| + |
| + // r1 = parameter count (tagged) |
| + // r2 = argument count (tagged) |
| + // Compute the mapped parameter count = min(r1, r2) in r1. |
| + __ cmp(r1, Operand(r2)); |
| + __ mov(r1, Operand(r2), LeaveCC, gt); |
| + |
| + __ bind(&try_allocate); |
| + // Save mapped parameter count. |
| + __ mov(r9, r1); |
| + |
| + // Compute the sizes of backing store, parameter map, and arguments object. |
| + // 1. Parameter map, has 2 extra words containing context and backing store. |
| + const int kParameterMapHeaderSize = |
| + FixedArray::kHeaderSize + 2 * kPointerSize; |
| + // If there are no mapped parameters, we do not need the parameter_map. |
| + __ cmp(r1, Operand(0)); |
|
Kevin Millikin (Chromium)
2011/06/07 13:54:10
Since r1 is tagged, can we use Smi::FromInt(0)?
Karl Klose
2011/06/10 11:32:22
Done.
|
| + __ mov(r1, Operand(r1, LSL, 1), LeaveCC, ne); |
| + __ add(r1, r1, Operand(kParameterMapHeaderSize), LeaveCC, ne); |
| + |
| + // 2. Backing store. |
| + __ add(r1, r1, Operand(r2, LSL, 1)); |
| + __ add(r1, r1, Operand(FixedArray::kHeaderSize)); |
| + |
| + // 3. Arguments object. |
| + __ add(r1, r1, Operand(Heap::kArgumentsObjectSize)); |
| + |
| + // Do the allocation of all three objects in one go. |
| + __ AllocateInNewSpace(r1, r0, r3, r4, &runtime, TAG_OBJECT); |
| + |
| + // r0 = address of new object(s) (tagged) |
| + // r2 = argument count (tagged) |
| + // Get the arguments boilerplate from the current (global) context into r4. |
| + const int kNormalOffset = |
| + Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX); |
| + const int kAliasedOffset = |
| + Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX); |
| + |
| + __ ldr(r4, MemOperand(r8, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| + __ ldr(r4, FieldMemOperand(r4, GlobalObject::kGlobalContextOffset)); |
| + __ mov(r1, r9); |
| + __ SmiUntag(r1); |
|
Kevin Millikin (Chromium)
2011/06/07 13:54:10
Hmm, if I correctly follow this, the untagged r1 i
Karl Klose
2011/06/10 11:32:22
Done.
|
| + __ cmp(r1, Operand(0)); |
| + __ ldr(r4, MemOperand(r4, kNormalOffset), eq); |
| + __ ldr(r4, MemOperand(r4, kAliasedOffset), ne); |
| + |
| + // r0 = address of new object (tagged) |
| + // r1 = mapped parameter count (untagged) |
| + // r2 = argument count (untagged) |
|
Kevin Millikin (Chromium)
2011/06/07 13:54:10
(untagged) ==> (tagged)
Karl Klose
2011/06/10 11:32:22
Done.
|
| + // r4 = address of boilerplate object (tagged) |
| + // Copy the JS object part. |
| + for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| + __ ldr(r3, FieldMemOperand(r4, i)); |
| + __ str(r3, FieldMemOperand(r0, i)); |
| + } |
| + |
| + // Setup the callee in-object property. |
| + STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| + __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| + const int kCalleeOffset = JSObject::kHeaderSize + |
| + Heap::kArgumentsCalleeIndex * kPointerSize; |
| + __ str(r3, FieldMemOperand(r0, kCalleeOffset)); |
| + |
| + // Use the length (smi tagged) and set that as an in-object property too. |
| + STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| + const int kLengthOffset = JSObject::kHeaderSize + |
| + Heap::kArgumentsLengthIndex * kPointerSize; |
| + __ str(r2, FieldMemOperand(r0, kLengthOffset)); |
| + |
| + // Setup the elements pointer in the allocated arguments object. |
| + // If we allocated a parameter map, r4 will point there, otherwise |
| + // it will point to the backing store. |
| + __ add(r4, r0, Operand(Heap::kArgumentsObjectSize)); |
| + __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| + |
| + // r0 = address of new object (tagged) |
| + // r1 = mapped parameter count (untagged) |
| + // r2 = argument count (tagged) |
| + // r4 = address of parameter map or backing store (tagged) |
| + __ mov(r6, r0); |
|
Kevin Millikin (Chromium)
2011/06/07 13:54:10
This mov might be unnecessary. Can r6 be used ins
|
| + |
| + // Initialize parameter map. If there are no mapped arguments, we're done. |
| + Label skip_parameter_map; |
| + __ cmp(r1, Operand(0)); |
| + __ b(eq, &skip_parameter_map); |
| + |
| + __ LoadRoot(r0, Heap::kNonStrictArgumentsElementsMapRootIndex); |
| + __ str(r0, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| + __ add(r0, r1, Operand(2)); |
| + __ SmiTag(r0); |
| + __ str(r0, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
| + __ str(r8, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| + __ add(r0, r4, Operand(r1, LSL, 2)); |
| + __ add(r0, r0, Operand(kParameterMapHeaderSize)); |
| + __ str(r0, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| + |
| + // Copy the parameter slots and the holes in the arguments. |
| + // We need to fill in mapped_parameter_count slots. They index the context, |
| + // where parameters are stored in reverse order, at |
| + // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| + // The mapped parameter thus need to get indices |
| + // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| + // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| + // We loop from right to left. |
| + Label parameters_loop, parameters_test; |
| + __ mov(r0, r9); |
| + __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| + __ add(r1, r1, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| + __ sub(r1, r1, Operand(r0)); |
| + __ LoadRoot(r7, Heap::kTheHoleValueRootIndex); |
| + __ mov(r3, r4); |
|
Kevin Millikin (Chromium)
2011/06/07 13:54:10
Can we avoid this mov by using r3 instead of r4 be
Karl Klose
2011/06/10 11:32:22
Done. The tricky part is that this code can be jum
|
| + __ mov(r5, r0); |
| + __ SmiUntag(r5); |
|
Kevin Millikin (Chromium)
2011/06/07 13:54:10
Is this untagged and retagged at its use? Maybe m
Karl Klose
2011/06/10 11:32:22
You are right, this is unnecessary.
|
| + __ add(r4, r4, Operand(r5, LSL, 2)); |
| + __ add(r4, r4, Operand(kParameterMapHeaderSize)); |
| + |
| + // r0 = loop variable (tagged) |
| + // r1 = mapping index (tagged) |
| + // r3 = address of parameter map (tagged) |
| + // r4 = address of backing store (tagged) |
| + // r5 = temporary scratch (a.o., for address calculation) |
| + // r7 = the hole value |
| + __ jmp(¶meters_test); |
| + |
| + __ bind(¶meters_loop); |
| + __ sub(r0, r0, Operand(Smi::FromInt(1))); |
| + __ mov(r5, Operand(r0, LSL, 1)); |
|
Kevin Millikin (Chromium)
2011/06/07 13:54:10
The computation of this value in r5 is duplicated
Karl Klose
2011/06/10 11:32:22
Done. It makes the code slightly harder to underst
|
| + __ add(r5, r5, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| + __ str(r1, MemOperand(r3, r5)); |
| + __ mov(r5, Operand(r0, LSL, 1)); |
| + __ add(r5, r5, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| + __ str(r7, MemOperand(r4, r5)); |
| + __ add(r1, r1, Operand(Smi::FromInt(1))); |
| + __ bind(¶meters_test); |
| + __ cmp(r0, Operand(0)); |
| + __ b(ne, ¶meters_loop); |
| + |
| + __ bind(&skip_parameter_map); |
| + // r2 = argument count (tagged) |
| + // r4 = address of backing store (tagged) |
| + // r5 = scratch |
| + // Copy arguments header and remaining slots (if there are any). |
| + __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex); |
| + __ str(r5, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| + __ str(r2, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
| + |
| + Label arguments_loop, arguments_test; |
| + __ mov(r1, r9); |
| + __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); |
| + __ sub(r3, r3, Operand(r1, LSL, 1)); |
| + __ jmp(&arguments_test); |
| + |
| + __ bind(&arguments_loop); |
| + __ sub(r3, r3, Operand(kPointerSize)); |
| + __ ldr(r0, MemOperand(r3, 0)); |
| + __ add(r5, r4, Operand(r1, LSL, 1)); |
| + __ str(r0, FieldMemOperand(r5, FixedArray::kHeaderSize)); |
| + __ add(r1, r1, Operand(Smi::FromInt(1))); |
| + |
| + __ bind(&arguments_test); |
| + __ cmp(r1, Operand(r2)); |
| + __ b(lt, &arguments_loop); |
| + |
| + // Return and remove the on-stack parameters. |
| + __ add(sp, sp, Operand(3 * kPointerSize)); |
| + __ mov(r0, r6); |
| + __ Ret(); |
| + |
| + // Do the runtime call to allocate the arguments object. |
| + // r2 = argument count (taggged) |
| + __ bind(&runtime); |
| + __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count. |
| + __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| } |
| -void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
| +void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| // sp[0] : number of parameters |
| // sp[4] : receiver displacement |
| // sp[8] : function |
| - |
| // Check if the calling frame is an arguments adaptor frame. |
| Label adaptor_frame, try_allocate, runtime; |
| __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| @@ -3976,90 +4195,76 @@ void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
| // of the arguments object and the elements array in words. |
| Label add_arguments_object; |
| __ bind(&try_allocate); |
| - if (type_ == NEW_NON_STRICT_SLOW || type_ == NEW_NON_STRICT_FAST) { |
| - __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| - } else { |
| - __ cmp(r1, Operand(0, RelocInfo::NONE)); |
| - __ b(eq, &add_arguments_object); |
| - __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
| - __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize)); |
| - __ bind(&add_arguments_object); |
| - __ add(r1, r1, Operand(Heap::kArgumentsObjectSizeStrict / kPointerSize)); |
| - |
| - // Do the allocation of both objects in one go. |
| - __ AllocateInNewSpace( |
| - r1, |
| - r0, |
| - r2, |
| - r3, |
| - &runtime, |
| - static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
| - |
| - // Get the arguments boilerplate from the current (global) context. |
| - __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| - __ ldr(r4, FieldMemOperand(r4, GlobalObject::kGlobalContextOffset)); |
| - __ ldr(r4, MemOperand(r4, Context::SlotOffset( |
| - Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX))); |
| - |
| - // Copy the JS object part. |
| - __ CopyFields(r0, r4, r3.bit(), JSObject::kHeaderSize / kPointerSize); |
| - |
| - if (type_ == NEW_NON_STRICT_SLOW || type_ == NEW_NON_STRICT_FAST) { |
| - // Setup the callee in-object property. |
| - STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| - __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| - const int kCalleeOffset = JSObject::kHeaderSize + |
| - Heap::kArgumentsCalleeIndex * kPointerSize; |
| - __ str(r3, FieldMemOperand(r0, kCalleeOffset)); |
| - } |
| - |
| - // Get the length (smi tagged) and set that as an in-object property too. |
| - STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| - __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| - __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize + |
| - Heap::kArgumentsLengthIndex * kPointerSize)); |
| + __ cmp(r1, Operand(0, RelocInfo::NONE)); |
| + __ b(eq, &add_arguments_object); |
| + __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
| + __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize)); |
| + __ bind(&add_arguments_object); |
| + __ add(r1, r1, Operand(Heap::kArgumentsObjectSizeStrict / kPointerSize)); |
| + |
| + // Do the allocation of both objects in one go. |
| + __ AllocateInNewSpace(r1, |
| + r0, |
| + r2, |
| + r3, |
| + &runtime, |
| + static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
| + |
| + // Get the arguments boilerplate from the current (global) context. |
| + __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| + __ ldr(r4, FieldMemOperand(r4, GlobalObject::kGlobalContextOffset)); |
| + __ ldr(r4, MemOperand(r4, Context::SlotOffset( |
| + Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX))); |
| + |
| + // Copy the JS object part. |
| + __ CopyFields(r0, r4, r3.bit(), JSObject::kHeaderSize / kPointerSize); |
| + |
| + // Get the length (smi tagged) and set that as an in-object property too. |
| + STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| + __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| + __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize + |
| + Heap::kArgumentsLengthIndex * kPointerSize)); |
| + |
| + // If there are no actual arguments, we're done. |
| + Label done; |
| + __ cmp(r1, Operand(0, RelocInfo::NONE)); |
| + __ b(eq, &done); |
| - // If there are no actual arguments, we're done. |
| - Label done; |
| - __ cmp(r1, Operand(0, RelocInfo::NONE)); |
| - __ b(eq, &done); |
| + // Get the parameters pointer from the stack. |
| + __ ldr(r2, MemOperand(sp, 1 * kPointerSize)); |
| - // Get the parameters pointer from the stack. |
| - __ ldr(r2, MemOperand(sp, 1 * kPointerSize)); |
| + // Setup the elements pointer in the allocated arguments object and |
| + // initialize the header in the elements fixed array. |
| + __ add(r4, r0, Operand(Heap::kArgumentsObjectSizeStrict)); |
| + __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| + __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex); |
| + __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| + __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
| + // Untag the length for the loop. |
| + __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
| - // Setup the elements pointer in the allocated arguments object and |
| - // initialize the header in the elements fixed array. |
| - __ add(r4, r0, Operand(Heap::kArgumentsObjectSizeStrict)); |
| - __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| - __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex); |
| - __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| - __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
| - // Untag the length for the loop. |
| - __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
| + // Copy the fixed array slots. |
| + Label loop; |
| + // Setup r4 to point to the first array slot. |
| + __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| + __ bind(&loop); |
| + // Pre-decrement r2 with kPointerSize on each iteration. |
| + // Pre-decrement in order to skip receiver. |
| + __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex)); |
| + // Post-increment r4 with kPointerSize on each iteration. |
| + __ str(r3, MemOperand(r4, kPointerSize, PostIndex)); |
| + __ sub(r1, r1, Operand(1)); |
| + __ cmp(r1, Operand(0, RelocInfo::NONE)); |
| + __ b(ne, &loop); |
| - // Copy the fixed array slots. |
| - Label loop; |
| - // Setup r4 to point to the first array slot. |
| - __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| - __ bind(&loop); |
| - // Pre-decrement r2 with kPointerSize on each iteration. |
| - // Pre-decrement in order to skip receiver. |
| - __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex)); |
| - // Post-increment r4 with kPointerSize on each iteration. |
| - __ str(r3, MemOperand(r4, kPointerSize, PostIndex)); |
| - __ sub(r1, r1, Operand(1)); |
| - __ cmp(r1, Operand(0, RelocInfo::NONE)); |
| - __ b(ne, &loop); |
| - |
| - // Return and remove the on-stack parameters. |
| - __ bind(&done); |
| - __ add(sp, sp, Operand(3 * kPointerSize)); |
| - __ Ret(); |
| + // Return and remove the on-stack parameters. |
| + __ bind(&done); |
| + __ add(sp, sp, Operand(3 * kPointerSize)); |
| + __ Ret(); |
| - // Do the runtime call to allocate the arguments object. |
| - __ bind(&runtime); |
| - __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
| - } |
| + // Do the runtime call to allocate the arguments object. |
| + __ bind(&runtime); |
| + __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
| } |