Revision: 25187
Author:   [email protected]
Date:     Thu Nov  6 12:01:41 2014 UTC
Log:      Turn ToNumberStub into a PlatformCodeStub again.

The HydrogenCodeStub is too expensive and there's no easy way to reduce
this cost, so turning it into a PlatformCodeStub solves that problem
until we can use TurboFan for code stubs.

TEST=mjsunit
[email protected]

Review URL: https://codereview.chromium.org/683913008
https://code.google.com/p/v8/source/detail?r=25187

Modified:
 /branches/bleeding_edge/src/arm/code-stubs-arm.cc
 /branches/bleeding_edge/src/arm64/code-stubs-arm64.cc
 /branches/bleeding_edge/src/code-stubs-hydrogen.cc
 /branches/bleeding_edge/src/code-stubs.cc
 /branches/bleeding_edge/src/code-stubs.h
 /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc
 /branches/bleeding_edge/src/x64/code-stubs-x64.cc

=======================================
--- /branches/bleeding_edge/src/arm/code-stubs-arm.cc Mon Oct 20 11:42:56 2014 UTC +++ /branches/bleeding_edge/src/arm/code-stubs-arm.cc Thu Nov 6 12:01:41 2014 UTC
@@ -3185,6 +3185,24 @@
   __ Ret();
   generator.SkipSlow(masm, &runtime);
 }
+
+
+void ToNumberStub::Generate(MacroAssembler* masm) {
+  // The ToNumber stub takes one argument in r0.
+  Label check_heap_number, call_builtin;
+  __ JumpIfNotSmi(r0, &check_heap_number);
+  __ Ret();
+
+  __ bind(&check_heap_number);
+  __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
+  __ CompareRoot(r1, Heap::kHeapNumberMapRootIndex);
+  __ b(ne, &call_builtin);
+  __ Ret();
+
+  __ bind(&call_builtin);
+  __ push(r0);
+  __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
+}


 void StringHelper::GenerateFlatOneByteStringEquals(
=======================================
--- /branches/bleeding_edge/src/arm64/code-stubs-arm64.cc Mon Oct 20 11:42:56 2014 UTC +++ /branches/bleeding_edge/src/arm64/code-stubs-arm64.cc Thu Nov 6 12:01:41 2014 UTC
@@ -3831,6 +3831,22 @@
   __ Ret();
   generator.SkipSlow(masm, &runtime);
 }
+
+
+void ToNumberStub::Generate(MacroAssembler* masm) {
+  // The ToNumber stub takes one argument in x0.
+  Label check_heap_number, call_builtin;
+  __ JumpIfNotSmi(x0, &check_heap_number);
+  __ Ret();
+
+  __ bind(&check_heap_number);
+  __ JumpIfNotHeapNumber(x0, &call_builtin);
+  __ Ret();
+
+  __ bind(&call_builtin);
+  __ push(x0);
+  __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
+}


 void StringHelper::GenerateFlatOneByteStringEquals(
=======================================
--- /branches/bleeding_edge/src/code-stubs-hydrogen.cc Wed Nov 5 11:37:02 2014 UTC +++ /branches/bleeding_edge/src/code-stubs-hydrogen.cc Thu Nov 6 12:01:41 2014 UTC
@@ -281,37 +281,6 @@
   }
   return code;
 }
-
-
-template <>
-HValue* CodeStubGraphBuilder<ToNumberStub>::BuildCodeStub() {
-  HValue* value = GetParameter(0);
-
-  // Check if the parameter is already a SMI or heap number.
-  IfBuilder if_number(this);
-  if_number.If<HIsSmiAndBranch>(value);
- if_number.OrIf<HCompareMap>(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);
-  Add<HPushArguments>(value);
-  Push(Add<HInvokeFunction>(function, 1));
-
-  if_number.End();
-
-  return Pop();
-}
-
-
-Handle<Code> ToNumberStub::GenerateCode() {
-  return DoGenerateCode(this);
-}


 template <>
=======================================
--- /branches/bleeding_edge/src/code-stubs.cc   Tue Nov  4 12:58:17 2014 UTC
+++ /branches/bleeding_edge/src/code-stubs.cc   Thu Nov  6 12:01:41 2014 UTC
@@ -652,9 +652,6 @@


 void FastNewContextStub::InitializeDescriptor(CodeStubDescriptor* d) {}
-
-
-void ToNumberStub::InitializeDescriptor(CodeStubDescriptor* d) {}


void NumberToStringStub::InitializeDescriptor(CodeStubDescriptor* descriptor) {
=======================================
--- /branches/bleeding_edge/src/code-stubs.h    Tue Nov  4 12:58:17 2014 UTC
+++ /branches/bleeding_edge/src/code-stubs.h    Thu Nov  6 12:01:41 2014 UTC
@@ -50,6 +50,7 @@
   V(StringCompare)                          \
   V(StubFailureTrampoline)                  \
   V(SubString)                              \
+  V(ToNumber)                               \
   /* HydrogenCodeStubs */                   \
   V(AllocateHeapNumber)                     \
   V(ArrayNArgumentsConstructor)             \
@@ -77,7 +78,6 @@
   V(StoreFastElement)                       \
   V(StringAdd)                              \
   V(ToBoolean)                              \
-  V(ToNumber)                               \
   V(TransitionElementsKind)                 \
   V(VectorKeyedLoad)                        \
   V(VectorLoad)                             \
@@ -545,15 +545,6 @@
 };


-class ToNumberStub: public HydrogenCodeStub {
- public:
-  explicit ToNumberStub(Isolate* isolate) : HydrogenCodeStub(isolate) { }
-
-  DEFINE_CALL_INTERFACE_DESCRIPTOR(ToNumber);
-  DEFINE_HYDROGEN_CODE_STUB(ToNumber, HydrogenCodeStub);
-};
-
-
 class NumberToStringStub FINAL : public HydrogenCodeStub {
  public:
explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
@@ -2537,6 +2528,15 @@
 };


+class ToNumberStub FINAL : public PlatformCodeStub {
+ public:
+  explicit ToNumberStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
+
+  DEFINE_CALL_INTERFACE_DESCRIPTOR(ToNumber);
+  DEFINE_PLATFORM_CODE_STUB(ToNumber, PlatformCodeStub);
+};
+
+
 class StringCompareStub : public PlatformCodeStub {
  public:
explicit StringCompareStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
=======================================
--- /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Mon Oct 20 11:42:56 2014 UTC +++ /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Thu Nov 6 12:01:41 2014 UTC
@@ -3171,6 +3171,25 @@
   __ ret(3 * kPointerSize);
   generator.SkipSlow(masm, &runtime);
 }
+
+
+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();
+
+  __ bind(&check_heap_number);
+  __ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
+  __ j(not_equal, &call_builtin, Label::kNear);
+  __ Ret();
+
+  __ bind(&call_builtin);
+  __ pop(ecx);  // Pop return address.
+  __ push(eax);
+  __ push(ecx);  // Push return address.
+  __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
+}


 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
=======================================
--- /branches/bleeding_edge/src/x64/code-stubs-x64.cc Mon Oct 20 11:42:56 2014 UTC +++ /branches/bleeding_edge/src/x64/code-stubs-x64.cc Thu Nov 6 12:01:41 2014 UTC
@@ -3120,6 +3120,26 @@
   __ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
   generator.SkipSlow(masm, &runtime);
 }
+
+
+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);
+  __ popq(rcx);  // Pop return address.
+  __ pushq(rax);
+  __ pushq(rcx);  // Push return address.
+  __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
+}


 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to