X87: [runtime] Add %ToString and %_ToString and remove the TO_STRING builtin.
authorchunyang.dai <chunyang.dai@intel.com>
Mon, 31 Aug 2015 09:23:16 +0000 (02:23 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 31 Aug 2015 09:23:36 +0000 (09:23 +0000)
port 09de997b3504368d40644afa7310b90faff5d09c (r30442).

original commit message:

    This adds a new ToString runtime function and a fast-path ToStringStub
    (which is just a simple dispatcher for existing functionality), and also
    implements %_ToName using the ToStringStub.

R=weiliang.lin@intel.com
BUG=

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

Cr-Commit-Position: refs/heads/master@{#30460}

src/full-codegen/x87/full-codegen-x87.cc
src/x87/builtins-x87.cc
src/x87/code-stubs-x87.cc
src/x87/interface-descriptors-x87.cc

index b36fe8f4fc61b49aad4e13225b734cb244882a57..c1451a58fad56444cd1b71072ff9456664cab5c1 100644 (file)
@@ -3833,6 +3833,40 @@ void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
 }
 
 
+void FullCodeGenerator::EmitToString(CallRuntime* expr) {
+  ZoneList<Expression*>* args = expr->arguments();
+  DCHECK_EQ(1, args->length());
+
+  // Load the argument into eax and convert it.
+  VisitForAccumulatorValue(args->at(0));
+
+  ToStringStub stub(isolate());
+  __ CallStub(&stub);
+  context()->Plug(eax);
+}
+
+
+void FullCodeGenerator::EmitToName(CallRuntime* expr) {
+  ZoneList<Expression*>* args = expr->arguments();
+  DCHECK_EQ(1, args->length());
+
+  // Load the argument into eax and convert it.
+  VisitForAccumulatorValue(args->at(0));
+
+  // Convert the object to a name.
+  Label convert, done_convert;
+  __ JumpIfSmi(eax, &convert, Label::kNear);
+  STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
+  __ CmpObjectType(eax, LAST_NAME_TYPE, ecx);
+  __ j(below_equal, &done_convert, Label::kNear);
+  __ bind(&convert);
+  ToStringStub stub(isolate());
+  __ CallStub(&stub);
+  __ bind(&done_convert);
+  context()->Plug(eax);
+}
+
+
 void FullCodeGenerator::EmitToObject(CallRuntime* expr) {
   ZoneList<Expression*>* args = expr->arguments();
   DCHECK_EQ(1, args->length());
index cd7568c75c5645c6be44ebb6c98c52be38d57aa0..77f79387be507ecd8b9607cd9274876dcc5dc84a 100644 (file)
@@ -1527,8 +1527,8 @@ void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
   {
     FrameScope scope(masm, StackFrame::INTERNAL);
     __ push(edi);  // Preserve the function.
-    __ push(eax);
-    __ InvokeBuiltin(Context::TO_STRING_BUILTIN_INDEX, CALL_FUNCTION);
+    ToStringStub stub(masm->isolate());
+    __ CallStub(&stub);
     __ pop(edi);
   }
   __ mov(ebx, eax);
index ff05f4d763af4032802c1d7977e29d4841152534..ea6250fae188eef717390507cf71d735bbf8dbf6 100644 (file)
@@ -2985,6 +2985,41 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
 }
 
 
+void ToStringStub::Generate(MacroAssembler* masm) {
+  // The ToString stub takes one argument in eax.
+  Label is_number;
+  __ JumpIfSmi(eax, &is_number, Label::kNear);
+
+  Label not_string;
+  __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
+  // eax: receiver
+  // edi: receiver map
+  __ j(above_equal, &not_string, Label::kNear);
+  __ Ret();
+  __ bind(&not_string);
+
+  Label not_heap_number;
+  __ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
+  __ j(not_equal, &not_heap_number, Label::kNear);
+  __ bind(&is_number);
+  NumberToStringStub stub(isolate());
+  __ TailCallStub(&stub);
+  __ bind(&not_heap_number);
+
+  Label not_oddball;
+  __ CmpInstanceType(edi, ODDBALL_TYPE);
+  __ j(not_equal, &not_oddball, Label::kNear);
+  __ mov(eax, FieldOperand(eax, Oddball::kToStringOffset));
+  __ Ret();
+  __ bind(&not_oddball);
+
+  __ pop(ecx);   // Pop return address.
+  __ push(eax);  // Push argument.
+  __ push(ecx);  // Push return address.
+  __ TailCallRuntime(Runtime::kToString, 1, 1);
+}
+
+
 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
                                                    Register left,
                                                    Register right,
index d68802a19879c1f98ede637bd0a476b80cd0ec50..3ffccd3b712c5f9a11198cb7f1d702cc87e71cf1 100644 (file)
@@ -106,6 +106,10 @@ void ToNumberDescriptor::InitializePlatformSpecific(
 }
 
 
+// static
+const Register ToStringDescriptor::ReceiverRegister() { return eax; }
+
+
 // static
 const Register ToObjectDescriptor::ReceiverRegister() { return eax; }