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

Side by Side Diff: src/arm64/builtins-arm64.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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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_ARM64 5 #if V8_TARGET_ARCH_ARM64
6 6
7 #include "src/arm64/frames-arm64.h" 7 #include "src/arm64/frames-arm64.h"
8 #include "src/codegen.h" 8 #include "src/codegen.h"
9 #include "src/debug/debug.h" 9 #include "src/debug/debug.h"
10 #include "src/deoptimizer.h" 10 #include "src/deoptimizer.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 // Run the native code for the Array function called as a normal function. 132 // Run the native code for the Array function called as a normal function.
133 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex); 133 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
134 __ Mov(x3, x1); 134 __ Mov(x3, x1);
135 ArrayConstructorStub stub(masm->isolate()); 135 ArrayConstructorStub stub(masm->isolate());
136 __ TailCallStub(&stub); 136 __ TailCallStub(&stub);
137 } 137 }
138 138
139 139
140 // static 140 // static
141 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) {
142 // ----------- S t a t e -------------
143 // -- x0 : number of arguments
144 // -- x1 : constructor function
145 // -- lr : return address
146 // -- sp[(argc - n - 1) * 8] : arg[n] (zero based)
147 // -- sp[argc * 8] : receiver
148 // -----------------------------------
149 ASM_LOCATION("Builtins::Generate_NumberConstructor");
150
151 // 1. Load the first argument into x0 and get rid of the rest (including the
152 // receiver).
153 Label no_arguments;
154 {
155 __ Cbz(x0, &no_arguments);
156 __ Sub(x0, x0, 1);
157 __ Drop(x0);
158 __ Ldr(x0, MemOperand(jssp, 2 * kPointerSize, PostIndex));
159 }
160
161 // 2a. Convert first argument to number.
162 ToNumberStub stub(masm->isolate());
163 __ TailCallStub(&stub);
164
165 // 2b. No arguments, return +0 (already in x0).
166 __ Bind(&no_arguments);
167 __ Drop(1);
168 __ Ret();
169 }
170
171
172 // static
173 void Builtins::Generate_NumberConstructor_ConstructStub(MacroAssembler* masm) {
174 // ----------- S t a t e -------------
175 // -- x0 : number of arguments
176 // -- x1 : constructor function
177 // -- x3 : new target
178 // -- lr : return address
179 // -- sp[(argc - n - 1) * 8] : arg[n] (zero based)
180 // -- sp[argc * 8] : receiver
181 // -----------------------------------
182 ASM_LOCATION("Builtins::Generate_NumberConstructor_ConstructStub");
183
184 // 1. Make sure we operate in the context of the called function.
185 __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
186
187 // 2. Load the first argument into x2 and get rid of the rest (including the
188 // receiver).
189 {
190 Label no_arguments, done;
191 __ Cbz(x0, &no_arguments);
192 __ Sub(x0, x0, 1);
193 __ Drop(x0);
194 __ Ldr(x2, MemOperand(jssp, 2 * kPointerSize, PostIndex));
195 __ B(&done);
196 __ Bind(&no_arguments);
197 __ Drop(1);
198 __ Mov(x2, Smi::FromInt(0));
199 __ Bind(&done);
200 }
201
202 // 3. Make sure x2 is a number.
203 {
204 Label done_convert;
205 __ JumpIfSmi(x2, &done_convert);
206 __ JumpIfObjectType(x2, x4, x4, HEAP_NUMBER_TYPE, &done_convert, eq);
207 {
208 FrameScope scope(masm, StackFrame::INTERNAL);
209 __ Push(x1, x3);
210 __ Move(x0, x2);
211 ToNumberStub stub(masm->isolate());
212 __ CallStub(&stub);
213 __ Move(x2, x0);
214 __ Pop(x3, x1);
215 }
216 __ Bind(&done_convert);
217 }
218
219 // 4. Check if new target and constructor differ.
220 Label new_object;
221 __ Cmp(x1, x3);
222 __ B(ne, &new_object);
223
224 // 5. Allocate a JSValue wrapper for the number.
225 __ AllocateJSValue(x0, x1, x2, x4, x5, &new_object);
226 __ Ret();
227
228 // 6. Fallback to the runtime to create new object.
229 __ bind(&new_object);
230 {
231 FrameScope scope(masm, StackFrame::INTERNAL);
232 __ Push(x2, x1, x3); // first argument, constructor, new target
233 __ CallRuntime(Runtime::kNewObject);
234 __ Pop(x2);
235 }
236 __ Str(x2, FieldMemOperand(x0, JSValue::kValueOffset));
237 __ Ret();
238 }
239
240
241 // static
141 void Builtins::Generate_StringConstructor(MacroAssembler* masm) { 242 void Builtins::Generate_StringConstructor(MacroAssembler* masm) {
142 // ----------- S t a t e ------------- 243 // ----------- S t a t e -------------
143 // -- x0 : number of arguments 244 // -- x0 : number of arguments
144 // -- x1 : constructor function 245 // -- x1 : constructor function
145 // -- lr : return address 246 // -- lr : return address
146 // -- sp[(argc - n - 1) * 8] : arg[n] (zero based) 247 // -- sp[(argc - n - 1) * 8] : arg[n] (zero based)
147 // -- sp[argc * 8] : receiver 248 // -- sp[argc * 8] : receiver
148 // ----------------------------------- 249 // -----------------------------------
149 ASM_LOCATION("Builtins::Generate_StringConstructor"); 250 ASM_LOCATION("Builtins::Generate_StringConstructor");
150 251
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // ----------- S t a t e ------------- 300 // ----------- S t a t e -------------
200 // -- x0 : number of arguments 301 // -- x0 : number of arguments
201 // -- x1 : constructor function 302 // -- x1 : constructor function
202 // -- x3 : new target 303 // -- x3 : new target
203 // -- lr : return address 304 // -- lr : return address
204 // -- sp[(argc - n - 1) * 8] : arg[n] (zero based) 305 // -- sp[(argc - n - 1) * 8] : arg[n] (zero based)
205 // -- sp[argc * 8] : receiver 306 // -- sp[argc * 8] : receiver
206 // ----------------------------------- 307 // -----------------------------------
207 ASM_LOCATION("Builtins::Generate_StringConstructor_ConstructStub"); 308 ASM_LOCATION("Builtins::Generate_StringConstructor_ConstructStub");
208 309
209 // 1. Load the first argument into x2 and get rid of the rest (including the 310 // 1. Make sure we operate in the context of the called function.
311 __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
312
313 // 2. Load the first argument into x2 and get rid of the rest (including the
210 // receiver). 314 // receiver).
211 { 315 {
212 Label no_arguments, done; 316 Label no_arguments, done;
213 __ Cbz(x0, &no_arguments); 317 __ Cbz(x0, &no_arguments);
214 __ Sub(x0, x0, 1); 318 __ Sub(x0, x0, 1);
215 __ Drop(x0); 319 __ Drop(x0);
216 __ Ldr(x2, MemOperand(jssp, 2 * kPointerSize, PostIndex)); 320 __ Ldr(x2, MemOperand(jssp, 2 * kPointerSize, PostIndex));
217 __ B(&done); 321 __ B(&done);
218 __ Bind(&no_arguments); 322 __ Bind(&no_arguments);
219 __ Drop(1); 323 __ Drop(1);
220 __ LoadRoot(x2, Heap::kempty_stringRootIndex); 324 __ LoadRoot(x2, Heap::kempty_stringRootIndex);
221 __ Bind(&done); 325 __ Bind(&done);
222 } 326 }
223 327
224 // 2. Make sure x2 is a string. 328 // 3. Make sure x2 is a string.
225 { 329 {
226 Label convert, done_convert; 330 Label convert, done_convert;
227 __ JumpIfSmi(x2, &convert); 331 __ JumpIfSmi(x2, &convert);
228 __ JumpIfObjectType(x2, x4, x4, FIRST_NONSTRING_TYPE, &done_convert, lo); 332 __ JumpIfObjectType(x2, x4, x4, FIRST_NONSTRING_TYPE, &done_convert, lo);
229 __ Bind(&convert); 333 __ Bind(&convert);
230 { 334 {
231 FrameScope scope(masm, StackFrame::INTERNAL); 335 FrameScope scope(masm, StackFrame::INTERNAL);
232 ToStringStub stub(masm->isolate()); 336 ToStringStub stub(masm->isolate());
233 __ Push(x1, x3); 337 __ Push(x1, x3);
234 __ Move(x0, x2); 338 __ Move(x0, x2);
235 __ CallStub(&stub); 339 __ CallStub(&stub);
236 __ Move(x2, x0); 340 __ Move(x2, x0);
237 __ Pop(x3, x1); 341 __ Pop(x3, x1);
238 } 342 }
239 __ Bind(&done_convert); 343 __ Bind(&done_convert);
240 } 344 }
241 345
242 // 3. Check if new target and constructor differ. 346 // 4. Check if new target and constructor differ.
243 Label new_object; 347 Label new_object;
244 __ Cmp(x1, x3); 348 __ Cmp(x1, x3);
245 __ B(ne, &new_object); 349 __ B(ne, &new_object);
246 350
247 // 4. Allocate a JSValue wrapper for the string. 351 // 5. Allocate a JSValue wrapper for the string.
248 { 352 __ AllocateJSValue(x0, x1, x2, x4, x5, &new_object);
249 // ----------- S t a t e ------------- 353 __ Ret();
250 // -- x2 : the first argument
251 // -- x1 : constructor function
252 // -- x3 : new target
253 // -- lr : return address
254 // -----------------------------------
255 __ Allocate(JSValue::kSize, x0, x4, x5, &new_object, TAG_OBJECT);
256 354
257 // Initialize the JSValue in eax. 355 // 6. Fallback to the runtime to create new object.
258 __ LoadGlobalFunctionInitialMap(x1, x3, x4);
259 __ Str(x3, FieldMemOperand(x0, HeapObject::kMapOffset));
260 __ LoadRoot(x3, Heap::kEmptyFixedArrayRootIndex);
261 __ Str(x3, FieldMemOperand(x0, JSObject::kPropertiesOffset));
262 __ Str(x3, FieldMemOperand(x0, JSObject::kElementsOffset));
263 __ Str(x2, FieldMemOperand(x0, JSValue::kValueOffset));
264 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize);
265 __ Ret();
266 }
267
268 // 5. Fallback to the runtime to create new object.
269 __ bind(&new_object); 356 __ bind(&new_object);
270 { 357 {
271 FrameScope scope(masm, StackFrame::INTERNAL); 358 FrameScope scope(masm, StackFrame::INTERNAL);
272 __ Push(x2, x1, x3); // first argument, constructor, new target 359 __ Push(x2, x1, x3); // first argument, constructor, new target
273 __ CallRuntime(Runtime::kNewObject); 360 __ CallRuntime(Runtime::kNewObject);
274 __ Pop(x2); 361 __ Pop(x2);
275 } 362 }
276 __ Str(x2, FieldMemOperand(x0, JSValue::kValueOffset)); 363 __ Str(x2, FieldMemOperand(x0, JSValue::kValueOffset));
277 __ Ret(); 364 __ Ret();
278 } 365 }
(...skipping 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 } 2578 }
2492 } 2579 }
2493 2580
2494 2581
2495 #undef __ 2582 #undef __
2496 2583
2497 } // namespace internal 2584 } // namespace internal
2498 } // namespace v8 2585 } // namespace v8
2499 2586
2500 #endif // V8_TARGET_ARCH_ARM 2587 #endif // V8_TARGET_ARCH_ARM
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698