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

Side by Side Diff: src/x64/code-stubs-x64.cc

Issue 1676883002: [runtime] Optimize and unify rest parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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/bootstrapper.h" 7 #include "src/bootstrapper.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/codegen.h" 9 #include "src/codegen.h"
10 #include "src/ic/handler-compiler.h" 10 #include "src/ic/handler-compiler.h"
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 __ bind(&runtime); 831 __ bind(&runtime);
832 __ PopReturnAddressTo(rax); 832 __ PopReturnAddressTo(rax);
833 __ Push(rdi); // Push function. 833 __ Push(rdi); // Push function.
834 __ Push(rdx); // Push parameters pointer. 834 __ Push(rdx); // Push parameters pointer.
835 __ Push(rcx); // Push parameter count. 835 __ Push(rcx); // Push parameter count.
836 __ PushReturnAddressFrom(rax); 836 __ PushReturnAddressFrom(rax);
837 __ TailCallRuntime(Runtime::kNewSloppyArguments); 837 __ TailCallRuntime(Runtime::kNewSloppyArguments);
838 } 838 }
839 839
840 840
841 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
842 // rcx : number of parameters (tagged)
843 // rdx : parameters pointer
844 // rbx : rest parameter index (tagged)
845 // rsp[0] : return address
846
847 // Check if the calling frame is an arguments adaptor frame.
848 Label runtime;
849 __ movp(r8, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
850 __ movp(rax, Operand(r8, StandardFrameConstants::kContextOffset));
851 __ Cmp(rax, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
852 __ j(not_equal, &runtime);
853
854 // Patch the arguments.length and the parameters pointer.
855 StackArgumentsAccessor args(rsp, 4, ARGUMENTS_DONT_CONTAIN_RECEIVER);
856 __ movp(rcx, Operand(r8, ArgumentsAdaptorFrameConstants::kLengthOffset));
857 __ SmiToInteger64(rax, rcx);
858 __ leap(rdx, Operand(r8, rax, times_pointer_size,
859 StandardFrameConstants::kCallerSPOffset));
860
861 __ bind(&runtime);
862 __ PopReturnAddressTo(rax);
863 __ Push(rcx); // Push number of parameters.
864 __ Push(rdx); // Push parameters pointer.
865 __ Push(rbx); // Push rest parameter index.
866 __ PushReturnAddressFrom(rax);
867 __ TailCallRuntime(Runtime::kNewRestParam);
868 }
869
870
871 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) { 841 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
872 // Return address is on the stack. 842 // Return address is on the stack.
873 Label slow; 843 Label slow;
874 844
875 Register receiver = LoadDescriptor::ReceiverRegister(); 845 Register receiver = LoadDescriptor::ReceiverRegister();
876 Register key = LoadDescriptor::NameRegister(); 846 Register key = LoadDescriptor::NameRegister();
877 Register scratch = rax; 847 Register scratch = rax;
878 DCHECK(!scratch.is(receiver) && !scratch.is(key)); 848 DCHECK(!scratch.is(receiver) && !scratch.is(key));
879 849
880 // Check that the key is an array index, that is Uint32. 850 // Check that the key is an array index, that is Uint32.
(...skipping 4020 matching lines...) Expand 10 before | Expand all | Expand 10 after
4901 Label fast_elements_case; 4871 Label fast_elements_case;
4902 __ cmpl(rcx, Immediate(FAST_ELEMENTS)); 4872 __ cmpl(rcx, Immediate(FAST_ELEMENTS));
4903 __ j(equal, &fast_elements_case); 4873 __ j(equal, &fast_elements_case);
4904 GenerateCase(masm, FAST_HOLEY_ELEMENTS); 4874 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4905 4875
4906 __ bind(&fast_elements_case); 4876 __ bind(&fast_elements_case);
4907 GenerateCase(masm, FAST_ELEMENTS); 4877 GenerateCase(masm, FAST_ELEMENTS);
4908 } 4878 }
4909 4879
4910 4880
4881 void FastNewRestParameterStub::Generate(MacroAssembler* masm) {
4882 // ----------- S t a t e -------------
4883 // -- rdi : function
4884 // -- rsi : context
4885 // -- rbp : frame pointer
4886 // -- rsp[0] : return address
4887 // -----------------------------------
4888 __ AssertFunction(rdi);
4889
4890 // For Ignition we need to skip all possible handler/stub frames until
4891 // we reach the JavaScript frame for the function (similar to what the
4892 // runtime fallback implementation does). So make rdx point to that
4893 // JavaScript frame.
4894 {
4895 Label loop, loop_entry;
4896 __ movp(rdx, rbp);
4897 __ jmp(&loop_entry, Label::kNear);
4898 __ bind(&loop);
4899 __ movp(rdx, Operand(rdx, StandardFrameConstants::kCallerFPOffset));
4900 __ bind(&loop_entry);
4901 __ cmpp(rdi, Operand(rdx, StandardFrameConstants::kMarkerOffset));
4902 __ j(not_equal, &loop);
4903 }
4904
4905 // Check if we have rest parameters (only possible if we have an
4906 // arguments adaptor frame below the function frame).
4907 Label no_rest_parameters;
4908 __ movp(rbx, Operand(rdx, StandardFrameConstants::kCallerFPOffset));
4909 __ Cmp(Operand(rbx, StandardFrameConstants::kContextOffset),
4910 Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
4911 __ j(not_equal, &no_rest_parameters, Label::kNear);
4912
4913 // Check if the arguments adaptor frame contains more arguments than
4914 // specified by the function's internal formal parameter count.
4915 Label rest_parameters;
4916 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
4917 __ LoadSharedFunctionInfoSpecialField(
4918 rcx, rcx, SharedFunctionInfo::kFormalParameterCountOffset);
4919 __ SmiToInteger32(
4920 rax, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4921 __ subl(rax, rcx);
4922 __ j(greater, &rest_parameters);
4923
4924 // Return an empty rest parameter array.
4925 __ bind(&no_rest_parameters);
4926 {
4927 // ----------- S t a t e -------------
4928 // -- rsi : context
4929 // -- rsp[0] : return address
4930 // -----------------------------------
4931
4932 // Allocate an empty rest parameter array.
4933 Label allocate, done_allocate;
4934 __ Allocate(JSArray::kSize, rax, rdx, rcx, &allocate, TAG_OBJECT);
4935 __ bind(&done_allocate);
4936
4937 // Setup the rest parameter array in rax.
4938 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, rcx);
4939 __ movp(FieldOperand(rax, JSArray::kMapOffset), rcx);
4940 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex);
4941 __ movp(FieldOperand(rax, JSArray::kPropertiesOffset), rcx);
4942 __ movp(FieldOperand(rax, JSArray::kElementsOffset), rcx);
4943 __ movp(FieldOperand(rax, JSArray::kLengthOffset), Immediate(0));
4944 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4945 __ Ret();
4946
4947 // Fall back to %AllocateInNewSpace.
4948 __ bind(&allocate);
4949 {
4950 FrameScope scope(masm, StackFrame::INTERNAL);
4951 __ Push(Smi::FromInt(JSArray::kSize));
4952 __ CallRuntime(Runtime::kAllocateInNewSpace);
4953 }
4954 __ jmp(&done_allocate);
4955 }
4956
4957 __ bind(&rest_parameters);
4958 {
4959 // Compute the pointer to the first rest parameter (skippping the receiver).
4960 __ leap(rbx, Operand(rbx, rax, times_pointer_size,
4961 StandardFrameConstants::kCallerSPOffset -
4962 1 * kPointerSize));
4963
4964 // ----------- S t a t e -------------
4965 // -- rsi : context
4966 // -- rax : number of rest parameters
4967 // -- rbx : pointer to first rest parameters
4968 // -- rsp[0] : return address
4969 // -----------------------------------
4970
4971 // Allocate space for the rest parameter array plus the backing store.
4972 Label allocate, done_allocate;
4973 __ leal(rcx, Operand(rax, times_pointer_size,
4974 JSArray::kSize + FixedArray::kHeaderSize));
4975 __ Allocate(rcx, rdx, rdi, no_reg, &allocate, TAG_OBJECT);
4976 __ bind(&done_allocate);
4977
4978 // Compute the arguments.length in rdi.
4979 __ Integer32ToSmi(rdi, rax);
4980
4981 // Setup the elements array in rdx.
4982 __ LoadRoot(rcx, Heap::kFixedArrayMapRootIndex);
4983 __ movp(FieldOperand(rdx, FixedArray::kMapOffset), rcx);
4984 __ movp(FieldOperand(rdx, FixedArray::kLengthOffset), rdi);
4985 {
4986 Label loop, done_loop;
4987 __ Set(rcx, 0);
4988 __ bind(&loop);
4989 __ cmpl(rcx, rax);
4990 __ j(equal, &done_loop, Label::kNear);
4991 __ movp(kScratchRegister, Operand(rbx, 0 * kPointerSize));
4992 __ movp(
4993 FieldOperand(rdx, rcx, times_pointer_size, FixedArray::kHeaderSize),
4994 kScratchRegister);
4995 __ subp(rbx, Immediate(1 * kPointerSize));
4996 __ addl(rcx, Immediate(1));
4997 __ jmp(&loop);
4998 __ bind(&done_loop);
4999 }
5000
5001 // Setup the rest parameter array in rax.
5002 __ leap(rax,
5003 Operand(rdx, rax, times_pointer_size, FixedArray::kHeaderSize));
5004 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, rcx);
5005 __ movp(FieldOperand(rax, JSArray::kMapOffset), rcx);
5006 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex);
5007 __ movp(FieldOperand(rax, JSArray::kPropertiesOffset), rcx);
5008 __ movp(FieldOperand(rax, JSArray::kElementsOffset), rdx);
5009 __ movp(FieldOperand(rax, JSArray::kLengthOffset), rdi);
5010 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
5011 __ Ret();
5012
5013 // Fall back to %AllocateInNewSpace.
5014 __ bind(&allocate);
5015 {
5016 FrameScope scope(masm, StackFrame::INTERNAL);
5017 __ Integer32ToSmi(rax, rax);
5018 __ Integer32ToSmi(rcx, rcx);
5019 __ Push(rax);
5020 __ Push(rbx);
5021 __ Push(rcx);
5022 __ CallRuntime(Runtime::kAllocateInNewSpace);
5023 __ movp(rdx, rax);
5024 __ Pop(rbx);
5025 __ Pop(rax);
5026 __ SmiToInteger32(rax, rax);
5027 }
5028 __ jmp(&done_allocate);
5029 }
5030 }
5031
5032
4911 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) { 5033 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
4912 Register context_reg = rsi; 5034 Register context_reg = rsi;
4913 Register slot_reg = rbx; 5035 Register slot_reg = rbx;
4914 Register result_reg = rax; 5036 Register result_reg = rax;
4915 Label slow_case; 5037 Label slow_case;
4916 5038
4917 // Go up context chain to the script context. 5039 // Go up context chain to the script context.
4918 for (int i = 0; i < depth(); ++i) { 5040 for (int i = 0; i < depth(); ++i) {
4919 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX)); 5041 __ movp(rdi, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
4920 context_reg = rdi; 5042 context_reg = rdi;
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
5458 NULL); 5580 NULL);
5459 } 5581 }
5460 5582
5461 5583
5462 #undef __ 5584 #undef __
5463 5585
5464 } // namespace internal 5586 } // namespace internal
5465 } // namespace v8 5587 } // namespace v8
5466 5588
5467 #endif // V8_TARGET_ARCH_X64 5589 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698