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

Side by Side Diff: src/arm/builtins-arm.cc

Issue 1344893002: [builtins] Unify the String constructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/arm64/builtins-arm64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if V8_TARGET_ARCH_ARM 5 #if V8_TARGET_ARCH_ARM
6 6
7 #include "src/codegen.h" 7 #include "src/codegen.h"
8 #include "src/debug/debug.h" 8 #include "src/debug/debug.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 __ mov(r3, r1); 130 __ mov(r3, r1);
131 // Run the native code for the Array function called as a normal function. 131 // Run the native code for the Array function called as a normal function.
132 // tail call a stub 132 // tail call a stub
133 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); 133 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
134 ArrayConstructorStub stub(masm->isolate()); 134 ArrayConstructorStub stub(masm->isolate());
135 __ TailCallStub(&stub); 135 __ TailCallStub(&stub);
136 } 136 }
137 137
138 138
139 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { 139 // static
140 void Builtins::Generate_StringConstructor(MacroAssembler* masm) {
140 // ----------- S t a t e ------------- 141 // ----------- S t a t e -------------
141 // -- r0 : number of arguments 142 // -- r0 : number of arguments
142 // -- r1 : constructor function 143 // -- r1 : constructor function
144 // -- lr : return address
145 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
146 // -- sp[argc * 4] : receiver
147 // -----------------------------------
148
149 // 1. Load the first argument into r0 and get rid of the rest (including the
150 // receiver).
151 Label no_arguments;
152 {
153 __ sub(r0, r0, Operand(1), SetCC);
154 __ b(lo, &no_arguments);
155 __ ldr(r0, MemOperand(sp, r0, LSL, kPointerSizeLog2, PreIndex));
156 __ Drop(2);
157 }
158
159 // 2a. At least one argument, return r0 if it's a string, otherwise
160 // dispatch to appropriate conversion.
161 Label to_string, symbol_descriptive_string;
162 {
163 __ JumpIfSmi(r0, &to_string);
164 STATIC_ASSERT(FIRST_NONSTRING_TYPE == SYMBOL_TYPE);
165 __ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE);
166 __ b(hi, &to_string);
167 __ b(eq, &symbol_descriptive_string);
168 __ Ret();
169 }
170
171 // 2b. No arguments, return the empty string (and pop the receiver).
172 __ bind(&no_arguments);
173 {
174 __ LoadRoot(r0, Heap::kempty_stringRootIndex);
175 __ Ret(1);
176 }
177
178 // 3a. Convert r0 to a string.
179 __ bind(&to_string);
180 {
181 ToStringStub stub(masm->isolate());
182 __ TailCallStub(&stub);
183 }
184
185 // 3b. Convert symbol in r0 to a string.
186 __ bind(&symbol_descriptive_string);
187 {
188 __ Push(r0);
189 __ TailCallRuntime(Runtime::kSymbolDescriptiveString, 1, 1);
190 }
191 }
192
193
194 // static
195 void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
196 // ----------- S t a t e -------------
197 // -- r0 : number of arguments
198 // -- r1 : constructor function
143 // -- lr : return address 199 // -- lr : return address
144 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) 200 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
145 // -- sp[argc * 4] : receiver 201 // -- sp[argc * 4] : receiver
146 // ----------------------------------- 202 // -----------------------------------
147 203
148 // 1. Load the first argument into r2 and get rid of the rest (including the 204 // 1. Load the first argument into r0 and get rid of the rest (including the
149 // receiver). 205 // receiver).
150 { 206 {
151 Label no_arguments, done; 207 Label no_arguments, done;
152 __ cmp(r0, Operand(0)); 208 __ sub(r0, r0, Operand(1), SetCC);
153 __ b(eq, &no_arguments); 209 __ b(lo, &no_arguments);
154 __ sub(r0, r0, Operand(1)); 210 __ ldr(r0, MemOperand(sp, r0, LSL, kPointerSizeLog2, PreIndex));
155 __ ldr(r2, MemOperand(sp, r0, LSL, kPointerSizeLog2, PreIndex));
156 __ Drop(2); 211 __ Drop(2);
157 __ b(&done); 212 __ b(&done);
158 __ bind(&no_arguments); 213 __ bind(&no_arguments);
159 __ LoadRoot(r2, Heap::kempty_stringRootIndex); 214 __ LoadRoot(r0, Heap::kempty_stringRootIndex);
160 __ Drop(1); 215 __ Drop(1);
161 __ bind(&done); 216 __ bind(&done);
162 } 217 }
163 218
164 // 2. Make sure r2 is a string. 219 // 2. Make sure r0 is a string.
165 { 220 {
166 Label convert, done_convert; 221 Label convert, done_convert;
167 __ JumpIfSmi(r2, &convert); 222 __ JumpIfSmi(r0, &convert);
168 __ CompareObjectType(r2, r3, r3, FIRST_NONSTRING_TYPE); 223 __ CompareObjectType(r0, r2, r2, FIRST_NONSTRING_TYPE);
169 __ b(lo, &done_convert); 224 __ b(lo, &done_convert);
170 __ bind(&convert); 225 __ bind(&convert);
171 { 226 {
172 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); 227 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
173 ToStringStub stub(masm->isolate()); 228 ToStringStub stub(masm->isolate());
174 __ Push(r1); 229 __ Push(r1);
175 __ Move(r0, r2);
176 __ CallStub(&stub); 230 __ CallStub(&stub);
177 __ Move(r2, r0);
178 __ Pop(r1); 231 __ Pop(r1);
179 } 232 }
180 __ bind(&done_convert); 233 __ bind(&done_convert);
181 } 234 }
182 235
183 // 3. Allocate a JSValue wrapper for the string. 236 // 3. Allocate a JSValue wrapper for the string.
184 { 237 {
185 // ----------- S t a t e ------------- 238 // ----------- S t a t e -------------
239 // -- r0 : the first argument
186 // -- r1 : constructor function 240 // -- r1 : constructor function
187 // -- r2 : the first argument
188 // -- lr : return address 241 // -- lr : return address
189 // ----------------------------------- 242 // -----------------------------------
190 243
191 Label allocate, done_allocate; 244 Label allocate, done_allocate;
245 __ Move(r2, r0);
192 __ Allocate(JSValue::kSize, r0, r3, r4, &allocate, TAG_OBJECT); 246 __ Allocate(JSValue::kSize, r0, r3, r4, &allocate, TAG_OBJECT);
193 __ bind(&done_allocate); 247 __ bind(&done_allocate);
194 248
195 // Initialize the JSValue in eax. 249 // Initialize the JSValue in r0.
196 __ LoadGlobalFunctionInitialMap(r1, r3, r4); 250 __ LoadGlobalFunctionInitialMap(r1, r3, r4);
197 __ str(r3, FieldMemOperand(r0, HeapObject::kMapOffset)); 251 __ str(r3, FieldMemOperand(r0, HeapObject::kMapOffset));
198 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex); 252 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
199 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset)); 253 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
200 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); 254 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
201 __ str(r2, FieldMemOperand(r0, JSValue::kValueOffset)); 255 __ str(r2, FieldMemOperand(r0, JSValue::kValueOffset));
202 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize); 256 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize);
203 __ Ret(); 257 __ Ret();
204 258
205 // Fallback to the runtime to allocate in new space. 259 // Fallback to the runtime to allocate in new space.
(...skipping 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 } 1836 }
1783 } 1837 }
1784 1838
1785 1839
1786 #undef __ 1840 #undef __
1787 1841
1788 } // namespace internal 1842 } // namespace internal
1789 } // namespace v8 1843 } // namespace v8
1790 1844
1791 #endif // V8_TARGET_ARCH_ARM 1845 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | src/arm64/builtins-arm64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698