PPC: [runtime] Add %ToString and %_ToString and remove the TO_STRING builtin.
authormbrandy <mbrandy@us.ibm.com>
Fri, 28 Aug 2015 15:34:07 +0000 (08:34 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 28 Aug 2015 15:34:25 +0000 (15:34 +0000)
Port 09de997b3504368d40644afa7310b90faff5d09c

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=bmeurer@chromium.org, jyan@ca.ibm.com, dstence@us.ibm.com, joransiu@ca.ibm.com
BUG=v8:4307
LOG=n

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

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

src/full-codegen/ppc/full-codegen-ppc.cc
src/ppc/builtins-ppc.cc
src/ppc/code-stubs-ppc.cc
src/ppc/interface-descriptors-ppc.cc
src/ppc/macro-assembler-ppc.h

index c9b11ba4cb1debebae95c721d5251741c139538b..b6b32e96532ac2159e3aaf5c59b398d86915cf93 100644 (file)
@@ -3989,6 +3989,39 @@ void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
 }
 
 
+void FullCodeGenerator::EmitToString(CallRuntime* expr) {
+  ZoneList<Expression*>* args = expr->arguments();
+  DCHECK_EQ(1, args->length());
+
+  // Load the argument into r3 and convert it.
+  VisitForAccumulatorValue(args->at(0));
+
+  ToStringStub stub(isolate());
+  __ CallStub(&stub);
+  context()->Plug(r3);
+}
+
+
+void FullCodeGenerator::EmitToName(CallRuntime* expr) {
+  ZoneList<Expression*>* args = expr->arguments();
+  DCHECK_EQ(1, args->length());
+
+  // Load the argument into r3 and convert it.
+  VisitForAccumulatorValue(args->at(0));
+
+  Label convert, done_convert;
+  __ JumpIfSmi(r3, &convert);
+  STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
+  __ CompareObjectType(r3, r4, r4, LAST_NAME_TYPE);
+  __ ble(&done_convert);
+  __ bind(&convert);
+  ToStringStub stub(isolate());
+  __ CallStub(&stub);
+  __ bind(&done_convert);
+  context()->Plug(r3);
+}
+
+
 void FullCodeGenerator::EmitToObject(CallRuntime* expr) {
   ZoneList<Expression*>* args = expr->arguments();
   DCHECK_EQ(1, args->length());
index 96c497697bec06f10582d1677ac966c5d2dc10af..5a5d1b268534e49aea5b57fd8f536d8171a0bb2f 100644 (file)
@@ -232,8 +232,8 @@ void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
   __ IncrementCounter(counters->string_ctor_conversions(), 1, r6, r7);
   {
     FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
-    __ push(r3);
-    __ InvokeBuiltin(Context::TO_STRING_BUILTIN_INDEX, CALL_FUNCTION);
+    ToStringStub stub(masm->isolate());
+    __ CallStub(&stub);
   }
   __ pop(function);
   __ mr(argument, r3);
index 50e8b7f6fab357fefe7af797a961b23a20c0b712..2f76275f1ef5cf942954da7cbc6c73e15899283d 100644 (file)
@@ -3401,15 +3401,10 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
   __ blr();
   __ bind(&not_smi);
 
-  Label not_heap_number;
-  __ LoadP(r4, FieldMemOperand(r3, HeapObject::kMapOffset));
-  __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
-  // r3: object
-  // r4: instance type.
-  __ cmpi(r4, Operand(HEAP_NUMBER_TYPE));
-  __ bne(&not_heap_number);
-  __ blr();
-  __ bind(&not_heap_number);
+  __ CompareObjectType(r3, r4, r4, HEAP_NUMBER_TYPE);
+  // r3: receiver
+  // r4: receiver instance type
+  __ Ret(eq);
 
   Label not_string, slow_string;
   __ cmpli(r4, Operand(FIRST_NONSTRING_TYPE));
@@ -3437,6 +3432,36 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
 }
 
 
+void ToStringStub::Generate(MacroAssembler* masm) {
+  // The ToString stub takes one argument in r3.
+  Label is_number;
+  __ JumpIfSmi(r3, &is_number);
+
+  __ CompareObjectType(r3, r4, r4, FIRST_NONSTRING_TYPE);
+  // r3: receiver
+  // r4: receiver instance type
+  __ Ret(lt);
+
+  Label not_heap_number;
+  __ cmpi(r4, Operand(HEAP_NUMBER_TYPE));
+  __ bne(&not_heap_number);
+  __ bind(&is_number);
+  NumberToStringStub stub(isolate());
+  __ TailCallStub(&stub);
+  __ bind(&not_heap_number);
+
+  Label not_oddball;
+  __ cmpi(r4, Operand(ODDBALL_TYPE));
+  __ bne(&not_oddball);
+  __ LoadP(r3, FieldMemOperand(r3, Oddball::kToStringOffset));
+  __ Ret();
+  __ bind(&not_oddball);
+
+  __ push(r3);  // Push argument.
+  __ TailCallRuntime(Runtime::kToString, 1, 1);
+}
+
+
 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
                                                    Register left,
                                                    Register right,
index 48adcf3fab58af961e48f5469320e27219f704a6..70dcb0fffa2529818f2c92866970610bd5026c47 100644 (file)
@@ -98,6 +98,10 @@ void ToNumberDescriptor::InitializePlatformSpecific(
 }
 
 
+// static
+const Register ToStringDescriptor::ReceiverRegister() { return r3; }
+
+
 // static
 const Register ToObjectDescriptor::ReceiverRegister() { return r3; }
 
index 26357ab2c79894093d5fa23aa537e0128711a5fe..1ea3e5cb153f46f81db6acceb0312ec26836ba02 100644 (file)
@@ -887,21 +887,9 @@ class MacroAssembler : public Assembler {
 
   void BranchOnNoOverflow(Label* label) { bge(label, cr0); }
 
-  void RetOnOverflow(void) {
-    Label label;
+  void RetOnOverflow(void) { Ret(lt, cr0); }
 
-    blt(&label, cr0);
-    Ret();
-    bind(&label);
-  }
-
-  void RetOnNoOverflow(void) {
-    Label label;
-
-    bge(&label, cr0);
-    Ret();
-    bind(&label);
-  }
+  void RetOnNoOverflow(void) { Ret(ge, cr0); }
 
   // ---------------------------------------------------------------------------
   // Runtime calls