From c4f77b3e40842622c01118b83d6545db96862633 Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Tue, 23 Jul 2013 06:02:54 +0000 Subject: [PATCH] Turn ToNumberStub into a hydrogen code stub. R=danno@chromium.org, hpayer@chromium.org Review URL: https://codereview.chromium.org/19793005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15814 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/code-stubs-arm.cc | 37 ++++++++++-------------------------- src/code-stubs-hydrogen.cc | 31 ++++++++++++++++++++++++++++++ src/code-stubs.h | 10 +++++++--- src/ia32/code-stubs-ia32.cc | 31 ++++++++++-------------------- src/mips/code-stubs-mips.cc | 38 ++++++++++--------------------------- src/x64/code-stubs-x64.cc | 30 ++++++++++------------------- 6 files changed, 78 insertions(+), 99 deletions(-) diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index 7773667b7..f45c75b67 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -38,6 +38,16 @@ namespace v8 { namespace internal { +void ToNumberStub::InitializeInterfaceDescriptor( + Isolate* isolate, + CodeStubInterfaceDescriptor* descriptor) { + static Register registers[] = { r0 }; + descriptor->register_param_count_ = 1; + descriptor->register_params_ = registers; + descriptor->deoptimization_handler_ = NULL; +} + + void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( Isolate* isolate, CodeStubInterfaceDescriptor* descriptor) { @@ -286,17 +296,6 @@ static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register rhs); -// Check if the operand is a heap number. -static void EmitCheckForHeapNumber(MacroAssembler* masm, Register operand, - Register scratch1, Register scratch2, - Label* not_a_heap_number) { - __ ldr(scratch1, FieldMemOperand(operand, HeapObject::kMapOffset)); - __ LoadRoot(scratch2, Heap::kHeapNumberMapRootIndex); - __ cmp(scratch1, scratch2); - __ b(ne, not_a_heap_number); -} - - void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { // Update the static counter each time a new code stub is generated. Isolate* isolate = masm->isolate(); @@ -321,22 +320,6 @@ void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { } -void ToNumberStub::Generate(MacroAssembler* masm) { - // The ToNumber stub takes one argument in eax. - Label check_heap_number, call_builtin; - __ JumpIfNotSmi(r0, &check_heap_number); - __ Ret(); - - __ bind(&check_heap_number); - EmitCheckForHeapNumber(masm, r0, r1, ip, &call_builtin); - __ Ret(); - - __ bind(&call_builtin); - __ push(r0); - __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); -} - - void FastNewClosureStub::Generate(MacroAssembler* masm) { // Create a new closure from the given function info in new // space. Set the context to the current context in cp. diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc index 21b034100..388fd625b 100644 --- a/src/code-stubs-hydrogen.cc +++ b/src/code-stubs-hydrogen.cc @@ -306,6 +306,37 @@ static Handle DoGenerateCode(Stub* stub) { } +template <> +HValue* CodeStubGraphBuilder::BuildCodeStub() { + HValue* value = GetParameter(0); + + // Check if the parameter is already a SMI or heap number. + IfBuilder if_number(this); + if_number.If(value); + if_number.OrIf(value, isolate()->factory()->heap_number_map()); + if_number.Then(); + + // Return the number. + Push(value); + + if_number.Else(); + + // Convert the parameter to number using the builtin. + HValue* function = AddLoadJSBuiltin(Builtins::TO_NUMBER, context()); + Add(value); + Push(Add(context(), function, 1)); + + if_number.End(); + + return Pop(); +} + + +Handle ToNumberStub::GenerateCode() { + return DoGenerateCode(this); +} + + template <> HValue* CodeStubGraphBuilder::BuildCodeStub() { Zone* zone = this->zone(); diff --git a/src/code-stubs.h b/src/code-stubs.h index 33593544d..bc581d837 100644 --- a/src/code-stubs.h +++ b/src/code-stubs.h @@ -474,15 +474,19 @@ class InterruptStub : public PlatformCodeStub { }; -class ToNumberStub: public PlatformCodeStub { +class ToNumberStub: public HydrogenCodeStub { public: ToNumberStub() { } - void Generate(MacroAssembler* masm); + virtual Handle GenerateCode(); + + virtual void InitializeInterfaceDescriptor( + Isolate* isolate, + CodeStubInterfaceDescriptor* descriptor); private: Major MajorKey() { return ToNumber; } - int MinorKey() { return 0; } + int NotMissMinorKey() { return 0; } }; diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index 548cbaace..5789f4921 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -43,6 +43,16 @@ namespace v8 { namespace internal { +void ToNumberStub::InitializeInterfaceDescriptor( + Isolate* isolate, + CodeStubInterfaceDescriptor* descriptor) { + static Register registers[] = { eax }; + descriptor->register_param_count_ = 1; + descriptor->register_params_ = registers; + descriptor->deoptimization_handler_ = NULL; +} + + void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( Isolate* isolate, CodeStubInterfaceDescriptor* descriptor) { @@ -300,27 +310,6 @@ void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { } -void ToNumberStub::Generate(MacroAssembler* masm) { - // The ToNumber stub takes one argument in eax. - Label check_heap_number, call_builtin; - __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); - __ ret(0); - - __ bind(&check_heap_number); - __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); - Factory* factory = masm->isolate()->factory(); - __ cmp(ebx, Immediate(factory->heap_number_map())); - __ j(not_equal, &call_builtin, Label::kNear); - __ ret(0); - - __ bind(&call_builtin); - __ pop(ecx); // Pop return address. - __ push(eax); - __ push(ecx); // Push return address. - __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); -} - - void FastNewClosureStub::Generate(MacroAssembler* masm) { // Create a new closure from the given function info in new // space. Set the context to the current context in esi. diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index f984b3a7b..0e1b224ea 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -39,6 +39,16 @@ namespace v8 { namespace internal { +void ToNumberStub::InitializeInterfaceDescriptor( + Isolate* isolate, + CodeStubInterfaceDescriptor* descriptor) { + static Register registers[] = { a0 }; + descriptor->register_param_count_ = 1; + descriptor->register_params_ = registers; + descriptor->deoptimization_handler_ = NULL; +} + + void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( Isolate* isolate, CodeStubInterfaceDescriptor* descriptor) { @@ -287,16 +297,6 @@ static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register rhs); -// Check if the operand is a heap number. -static void EmitCheckForHeapNumber(MacroAssembler* masm, Register operand, - Register scratch1, Register scratch2, - Label* not_a_heap_number) { - __ lw(scratch1, FieldMemOperand(operand, HeapObject::kMapOffset)); - __ LoadRoot(scratch2, Heap::kHeapNumberMapRootIndex); - __ Branch(not_a_heap_number, ne, scratch1, Operand(scratch2)); -} - - void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { // Update the static counter each time a new code stub is generated. Isolate* isolate = masm->isolate(); @@ -321,24 +321,6 @@ void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { } -void ToNumberStub::Generate(MacroAssembler* masm) { - // The ToNumber stub takes one argument in a0. - Label check_heap_number, call_builtin; - __ JumpIfNotSmi(a0, &check_heap_number); - __ Ret(USE_DELAY_SLOT); - __ mov(v0, a0); - - __ bind(&check_heap_number); - EmitCheckForHeapNumber(masm, a0, a1, t0, &call_builtin); - __ Ret(USE_DELAY_SLOT); - __ mov(v0, a0); - - __ bind(&call_builtin); - __ push(a0); - __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); -} - - void FastNewClosureStub::Generate(MacroAssembler* masm) { // Create a new closure from the given function info in new // space. Set the context to the current context in cp. diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index e090437d5..551a71690 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -39,6 +39,16 @@ namespace v8 { namespace internal { +void ToNumberStub::InitializeInterfaceDescriptor( + Isolate* isolate, + CodeStubInterfaceDescriptor* descriptor) { + static Register registers[] = { rax }; + descriptor->register_param_count_ = 1; + descriptor->register_params_ = registers; + descriptor->deoptimization_handler_ = NULL; +} + + void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( Isolate* isolate, CodeStubInterfaceDescriptor* descriptor) { @@ -296,26 +306,6 @@ void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { } -void ToNumberStub::Generate(MacroAssembler* masm) { - // The ToNumber stub takes one argument in rax. - Label check_heap_number, call_builtin; - __ JumpIfNotSmi(rax, &check_heap_number, Label::kNear); - __ Ret(); - - __ bind(&check_heap_number); - __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), - Heap::kHeapNumberMapRootIndex); - __ j(not_equal, &call_builtin, Label::kNear); - __ Ret(); - - __ bind(&call_builtin); - __ pop(rcx); // Pop return address. - __ push(rax); - __ push(rcx); // Push return address. - __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); -} - - void FastNewClosureStub::Generate(MacroAssembler* masm) { // Create a new closure from the given function info in new // space. Set the context to the current context in rsi. -- 2.34.1