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

Unified Diff: src/mips/builtins-mips.cc

Issue 1573243009: [builtins] Migrate Number constructor similar to String constructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: src/mips/builtins-mips.cc
diff --git a/src/mips/builtins-mips.cc b/src/mips/builtins-mips.cc
index e65b7d1cfa24b449d3b6ee35706e07cd0173aa96..d59ba36489e511f001c0fef56a447e7773eb7d0b 100644
--- a/src/mips/builtins-mips.cc
+++ b/src/mips/builtins-mips.cc
@@ -142,6 +142,108 @@ void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
// static
+void Builtins::Generate_NumberConstructor(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- a0 : number of arguments
+ // -- a1 : constructor function
+ // -- ra : return address
+ // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
+ // -- sp[argc * 4] : receiver
+ // -----------------------------------
+
+ // 1. Load the first argument into a0 and get rid of the rest (including the
+ // receiver).
+ Label no_arguments;
+ {
+ __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
+ __ Subu(a0, a0, Operand(1));
+ __ sll(a0, a0, kPointerSizeLog2);
+ __ Addu(sp, a0, sp);
+ __ lw(a0, MemOperand(sp));
+ __ Drop(2);
+ }
+
+ // 2a. Convert first argument to number.
+ ToNumberStub stub(masm->isolate());
+ __ TailCallStub(&stub);
+
+ // 2b. No arguments, return +0.
+ __ bind(&no_arguments);
+ __ Move(v0, Smi::FromInt(0));
+ __ DropAndRet(1);
+}
+
+
+// static
+void Builtins::Generate_NumberConstructor_ConstructStub(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- a0 : number of arguments
+ // -- a1 : constructor function
+ // -- a3 : new target
+ // -- ra : return address
+ // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
+ // -- sp[argc * 4] : receiver
+ // -----------------------------------
+
+ // 1. Make sure we operate in the context of the called function.
+ __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
+
+ // 2. Load the first argument into a0 and get rid of the rest (including the
+ // receiver).
+ {
+ Label no_arguments, done;
+ __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
+ __ Subu(a0, a0, Operand(1));
+ __ sll(a0, a0, kPointerSizeLog2);
+ __ Addu(sp, a0, sp);
+ __ lw(a0, MemOperand(sp));
+ __ Drop(2);
+ __ jmp(&done);
+ __ bind(&no_arguments);
+ __ Move(a0, Smi::FromInt(0));
+ __ Drop(1);
+ __ bind(&done);
+ }
+
+ // 3. Make sure a0 is a number.
+ {
+ Label done_convert;
+ __ JumpIfSmi(a0, &done_convert);
+ __ GetObjectType(a0, a2, a2);
+ __ Branch(&done_convert, eq, a2, Operand(HEAP_NUMBER_TYPE));
+ {
+ FrameScope scope(masm, StackFrame::INTERNAL);
+ __ Push(a1, a3);
+ ToNumberStub stub(masm->isolate());
+ __ CallStub(&stub);
+ __ Move(a0, v0);
+ __ Pop(a1, a3);
+ }
+ __ bind(&done_convert);
+ }
+
+ // 4. Check if new target and constructor differ.
+ Label new_object;
+ __ Branch(&new_object, ne, a1, Operand(a3));
+
+ // 5. Allocate a JSValue wrapper for the number.
+ __ AllocateJSValue(v0, a1, a0, a2, t0, &new_object);
+ __ Ret();
+
+ // 6. Fallback to the runtime to create new object.
+ __ bind(&new_object);
+ {
+ FrameScope scope(masm, StackFrame::INTERNAL);
+ __ Push(a0, a1, a3); // first argument, constructor, new target
+ __ CallRuntime(Runtime::kNewObject);
+ __ Pop(a0);
+ }
+ __ Ret(USE_DELAY_SLOT);
+ __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot
+}
+
+
+// static
void Builtins::Generate_StringConstructor(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- a0 : number of arguments
@@ -211,7 +313,10 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
// -- sp[argc * 4] : receiver
// -----------------------------------
- // 1. Load the first argument into a0 and get rid of the rest (including the
+ // 1. Make sure we operate in the context of the called function.
+ __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
+
+ // 2. Load the first argument into a0 and get rid of the rest (including the
// receiver).
{
Label no_arguments, done;
@@ -228,7 +333,7 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
__ bind(&done);
}
- // 2. Make sure a0 is a string.
+ // 3. Make sure a0 is a string.
{
Label convert, done_convert;
__ JumpIfSmi(a0, &convert);
@@ -247,32 +352,15 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
__ bind(&done_convert);
}
- // 3. Check if new target and constructor differ.
+ // 4. Check if new target and constructor differ.
Label new_object;
__ Branch(&new_object, ne, a1, Operand(a3));
- // 4. Allocate a JSValue wrapper for the string.
- {
- // ----------- S t a t e -------------
- // -- a0 : the first argument
- // -- a1 : constructor function
- // -- a3 : new target
- // -- ra : return address
- // -----------------------------------
- __ Allocate(JSValue::kSize, v0, a2, t0, &new_object, TAG_OBJECT);
-
- // Initialize the JSValue in eax.
- __ LoadGlobalFunctionInitialMap(a1, a2, a3);
- __ sw(a2, FieldMemOperand(v0, HeapObject::kMapOffset));
- __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
- __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
- __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
- __ Ret(USE_DELAY_SLOT);
- __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset));
- STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize);
- }
+ // 5. Allocate a JSValue wrapper for the string.
+ __ AllocateJSValue(v0, a1, a0, a2, t0, &new_object);
+ __ Ret();
- // 5. Fallback to the runtime to create new object.
+ // 6. Fallback to the runtime to create new object.
__ bind(&new_object);
{
FrameScope scope(masm, StackFrame::INTERNAL);
@@ -281,7 +369,7 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
__ Pop(a0);
}
__ Ret(USE_DELAY_SLOT);
- __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset));
+ __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot
}
« no previous file with comments | « src/js/v8natives.js ('k') | src/mips/macro-assembler-mips.h » ('j') | src/x64/builtins-x64.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698