blob: 9693a52697aa5878ecb000930f5fe6122bba6c39 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Andrei Popescu31002712010-02-23 13:46:05 +00004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_MIPS
Leon Clarkef7060e22010-06-03 12:02:55 +01006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/codegen.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/debug/debug.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/deoptimizer.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/full-codegen/full-codegen.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040011#include "src/runtime/runtime.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012
Andrei Popescu31002712010-02-23 13:46:05 +000013
14namespace v8 {
15namespace internal {
16
17
18#define __ ACCESS_MASM(masm)
19
20
21void Builtins::Generate_Adaptor(MacroAssembler* masm,
22 CFunctionId id,
23 BuiltinExtraArguments extra_args) {
Ben Murdoch257744e2011-11-30 15:57:28 +000024 // ----------- S t a t e -------------
25 // -- a0 : number of arguments excluding receiver
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026 // -- a1 : target
27 // -- a3 : new.target
Ben Murdoch257744e2011-11-30 15:57:28 +000028 // -- sp[0] : last argument
29 // -- ...
30 // -- sp[4 * (argc - 1)] : first argument
31 // -- sp[4 * agrc] : receiver
32 // -----------------------------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 __ AssertFunction(a1);
34
35 // Make sure we operate in the context of the called function (for example
36 // ConstructStubs implemented in C++ will be run in the context of the caller
37 // instead of the callee, due to the way that [[Construct]] is defined for
38 // ordinary functions).
39 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +000040
41 // Insert extra arguments.
42 int num_extra_args = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000043 switch (extra_args) {
44 case BuiltinExtraArguments::kTarget:
45 __ Push(a1);
46 ++num_extra_args;
47 break;
48 case BuiltinExtraArguments::kNewTarget:
49 __ Push(a3);
50 ++num_extra_args;
51 break;
52 case BuiltinExtraArguments::kTargetAndNewTarget:
53 __ Push(a1, a3);
54 num_extra_args += 2;
55 break;
56 case BuiltinExtraArguments::kNone:
57 break;
Ben Murdoch257744e2011-11-30 15:57:28 +000058 }
59
Emily Bernierd0a1eb72015-03-24 16:35:39 -040060 // JumpToExternalReference expects a0 to contain the number of arguments
Ben Murdoch257744e2011-11-30 15:57:28 +000061 // including the receiver and the extra arguments.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040062 __ Addu(a0, a0, num_extra_args + 1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000063
Ben Murdoch257744e2011-11-30 15:57:28 +000064 __ JumpToExternalReference(ExternalReference(id, masm->isolate()));
65}
66
67
Ben Murdoch3ef787d2012-04-12 10:51:47 +010068// Load the built-in InternalArray function from the current context.
69static void GenerateLoadInternalArrayFunction(MacroAssembler* masm,
70 Register result) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 // Load the InternalArray function from the native context.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072 __ LoadNativeContextSlot(Context::INTERNAL_ARRAY_FUNCTION_INDEX, result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010073}
74
75
Ben Murdoch257744e2011-11-30 15:57:28 +000076// Load the built-in Array function from the current context.
77static void GenerateLoadArrayFunction(MacroAssembler* masm, Register result) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000078 // Load the Array function from the native context.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000079 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, result);
Ben Murdoch257744e2011-11-30 15:57:28 +000080}
81
82
Ben Murdoch3ef787d2012-04-12 10:51:47 +010083void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
84 // ----------- S t a t e -------------
85 // -- a0 : number of arguments
86 // -- ra : return address
87 // -- sp[...]: constructor arguments
88 // -----------------------------------
89 Label generic_array_code, one_or_more_arguments, two_or_more_arguments;
90
91 // Get the InternalArray function.
92 GenerateLoadInternalArrayFunction(masm, a1);
93
94 if (FLAG_debug_code) {
95 // Initial map for the builtin InternalArray functions should be maps.
96 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097 __ SmiTst(a2, t0);
98 __ Assert(ne, kUnexpectedInitialMapForInternalArrayFunction,
Ben Murdoch3ef787d2012-04-12 10:51:47 +010099 t0, Operand(zero_reg));
100 __ GetObjectType(a2, a3, t0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101 __ Assert(eq, kUnexpectedInitialMapForInternalArrayFunction,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100102 t0, Operand(MAP_TYPE));
103 }
104
105 // Run the native code for the InternalArray function called as a normal
106 // function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 // Tail call a stub.
108 InternalArrayConstructorStub stub(masm->isolate());
109 __ TailCallStub(&stub);
Andrei Popescu31002712010-02-23 13:46:05 +0000110}
111
112
113void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000114 // ----------- S t a t e -------------
115 // -- a0 : number of arguments
116 // -- ra : return address
117 // -- sp[...]: constructor arguments
118 // -----------------------------------
119 Label generic_array_code;
120
121 // Get the Array function.
122 GenerateLoadArrayFunction(masm, a1);
123
124 if (FLAG_debug_code) {
125 // Initial map for the builtin Array functions should be maps.
126 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000127 __ SmiTst(a2, t0);
128 __ Assert(ne, kUnexpectedInitialMapForArrayFunction1,
Ben Murdoch257744e2011-11-30 15:57:28 +0000129 t0, Operand(zero_reg));
130 __ GetObjectType(a2, a3, t0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000131 __ Assert(eq, kUnexpectedInitialMapForArrayFunction2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000132 t0, Operand(MAP_TYPE));
133 }
134
135 // Run the native code for the Array function called as a normal function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000136 // Tail call a stub.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000137 __ mov(a3, a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
139 ArrayConstructorStub stub(masm->isolate());
140 __ TailCallStub(&stub);
Andrei Popescu31002712010-02-23 13:46:05 +0000141}
142
143
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000144// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100145void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) {
146 // ----------- S t a t e -------------
147 // -- a0 : number of arguments
148 // -- ra : return address
149 // -- sp[(argc - n) * 8] : arg[n] (zero-based)
150 // -- sp[(argc + 1) * 8] : receiver
151 // -----------------------------------
Ben Murdoch097c5b22016-05-18 11:27:45 +0100152 Heap::RootListIndex const root_index =
153 (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex
154 : Heap::kMinusInfinityValueRootIndex;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100155
156 // Load the accumulator with the default return value (either -Infinity or
157 // +Infinity), with the tagged value in a1 and the double value in f0.
158 __ LoadRoot(a1, root_index);
159 __ ldc1(f0, FieldMemOperand(a1, HeapNumber::kValueOffset));
Ben Murdochda12d292016-06-02 14:46:10 +0100160 __ Addu(a3, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100161
162 Label done_loop, loop;
163 __ bind(&loop);
164 {
165 // Check if all parameters done.
166 __ Subu(a0, a0, Operand(1));
167 __ Branch(&done_loop, lt, a0, Operand(zero_reg));
168
169 // Load the next parameter tagged value into a2.
170 __ Lsa(at, sp, a0, kPointerSizeLog2);
171 __ lw(a2, MemOperand(at));
172
173 // Load the double value of the parameter into f2, maybe converting the
174 // parameter to a number first using the ToNumberStub if necessary.
175 Label convert, convert_smi, convert_number, done_convert;
176 __ bind(&convert);
177 __ JumpIfSmi(a2, &convert_smi);
178 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
179 __ JumpIfRoot(t0, Heap::kHeapNumberMapRootIndex, &convert_number);
180 {
181 // Parameter is not a Number, use the ToNumberStub to convert it.
182 FrameScope scope(masm, StackFrame::INTERNAL);
183 __ SmiTag(a0);
184 __ SmiTag(a3);
185 __ Push(a0, a1, a3);
186 __ mov(a0, a2);
187 ToNumberStub stub(masm->isolate());
188 __ CallStub(&stub);
189 __ mov(a2, v0);
190 __ Pop(a0, a1, a3);
191 {
192 // Restore the double accumulator value (f0).
193 Label restore_smi, done_restore;
194 __ JumpIfSmi(a1, &restore_smi);
195 __ ldc1(f0, FieldMemOperand(a1, HeapNumber::kValueOffset));
196 __ jmp(&done_restore);
197 __ bind(&restore_smi);
198 __ SmiToDoubleFPURegister(a1, f0, t0);
199 __ bind(&done_restore);
200 }
201 __ SmiUntag(a3);
202 __ SmiUntag(a0);
203 }
204 __ jmp(&convert);
205 __ bind(&convert_number);
206 __ ldc1(f2, FieldMemOperand(a2, HeapNumber::kValueOffset));
207 __ jmp(&done_convert);
208 __ bind(&convert_smi);
209 __ SmiToDoubleFPURegister(a2, f2, t0);
210 __ bind(&done_convert);
211
Ben Murdochda12d292016-06-02 14:46:10 +0100212 // Perform the actual comparison with using Min/Max macro instructions the
213 // accumulator value on the left hand side (f0) and the next parameter value
214 // on the right hand side (f2).
215 // We need to work out which HeapNumber (or smi) the result came from.
216 Label compare_nan, set_value;
217 __ BranchF(nullptr, &compare_nan, eq, f0, f2);
218 __ Move(t0, t1, f0);
219 if (kind == MathMaxMinKind::kMin) {
220 __ MinNaNCheck_d(f0, f0, f2);
221 } else {
222 DCHECK(kind == MathMaxMinKind::kMax);
223 __ MaxNaNCheck_d(f0, f0, f2);
224 }
225 __ Move(at, t8, f0);
226 __ Branch(&set_value, ne, t0, Operand(at));
227 __ Branch(&set_value, ne, t1, Operand(t8));
228 __ jmp(&loop);
229 __ bind(&set_value);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100230 __ mov(a1, a2);
231 __ jmp(&loop);
232
233 // At least one side is NaN, which means that the result will be NaN too.
234 __ bind(&compare_nan);
235 __ LoadRoot(a1, Heap::kNanValueRootIndex);
236 __ ldc1(f0, FieldMemOperand(a1, HeapNumber::kValueOffset));
237 __ jmp(&loop);
238 }
239
240 __ bind(&done_loop);
241 __ Lsa(sp, sp, a3, kPointerSizeLog2);
Ben Murdochda12d292016-06-02 14:46:10 +0100242 __ Ret(USE_DELAY_SLOT);
243 __ mov(v0, a1); // In delay slot.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100244}
245
246// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000247void Builtins::Generate_NumberConstructor(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000248 // ----------- S t a t e -------------
249 // -- a0 : number of arguments
250 // -- a1 : constructor function
251 // -- ra : return address
252 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
253 // -- sp[argc * 4] : receiver
254 // -----------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000255
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000256 // 1. Load the first argument into a0 and get rid of the rest (including the
257 // receiver).
258 Label no_arguments;
259 {
260 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
261 __ Subu(a0, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100262 __ Lsa(sp, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000263 __ lw(a0, MemOperand(sp));
264 __ Drop(2);
Ben Murdoch257744e2011-11-30 15:57:28 +0000265 }
266
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000267 // 2a. Convert first argument to number.
268 ToNumberStub stub(masm->isolate());
269 __ TailCallStub(&stub);
Ben Murdoch257744e2011-11-30 15:57:28 +0000270
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000271 // 2b. No arguments, return +0.
272 __ bind(&no_arguments);
273 __ Move(v0, Smi::FromInt(0));
274 __ DropAndRet(1);
275}
Ben Murdoch257744e2011-11-30 15:57:28 +0000276
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000277
278// static
279void Builtins::Generate_NumberConstructor_ConstructStub(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000280 // ----------- S t a t e -------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000281 // -- a0 : number of arguments
282 // -- a1 : constructor function
283 // -- a3 : new target
284 // -- ra : return address
285 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
286 // -- sp[argc * 4] : receiver
Ben Murdoch257744e2011-11-30 15:57:28 +0000287 // -----------------------------------
288
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000289 // 1. Make sure we operate in the context of the called function.
290 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000291
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000292 // 2. Load the first argument into a0 and get rid of the rest (including the
293 // receiver).
294 {
295 Label no_arguments, done;
296 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
297 __ Subu(a0, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100298 __ Lsa(sp, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000299 __ lw(a0, MemOperand(sp));
300 __ Drop(2);
301 __ jmp(&done);
302 __ bind(&no_arguments);
303 __ Move(a0, Smi::FromInt(0));
304 __ Drop(1);
305 __ bind(&done);
Ben Murdoch257744e2011-11-30 15:57:28 +0000306 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000307
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000308 // 3. Make sure a0 is a number.
309 {
310 Label done_convert;
311 __ JumpIfSmi(a0, &done_convert);
312 __ GetObjectType(a0, a2, a2);
313 __ Branch(&done_convert, eq, a2, Operand(HEAP_NUMBER_TYPE));
314 {
315 FrameScope scope(masm, StackFrame::INTERNAL);
316 __ Push(a1, a3);
317 ToNumberStub stub(masm->isolate());
318 __ CallStub(&stub);
319 __ Move(a0, v0);
320 __ Pop(a1, a3);
321 }
322 __ bind(&done_convert);
323 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000324
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000325 // 4. Check if new target and constructor differ.
326 Label new_object;
327 __ Branch(&new_object, ne, a1, Operand(a3));
Ben Murdoch257744e2011-11-30 15:57:28 +0000328
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000329 // 5. Allocate a JSValue wrapper for the number.
330 __ AllocateJSValue(v0, a1, a0, a2, t0, &new_object);
Ben Murdoch257744e2011-11-30 15:57:28 +0000331 __ Ret();
332
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000333 // 6. Fallback to the runtime to create new object.
334 __ bind(&new_object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100335 {
336 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100337 __ Push(a0); // first argument
338 FastNewObjectStub stub(masm->isolate());
339 __ CallStub(&stub);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000340 __ Pop(a0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100341 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000342 __ Ret(USE_DELAY_SLOT);
343 __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot
344}
Ben Murdoch257744e2011-11-30 15:57:28 +0000345
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000346
347// static
348void Builtins::Generate_StringConstructor(MacroAssembler* masm) {
349 // ----------- S t a t e -------------
350 // -- a0 : number of arguments
351 // -- a1 : constructor function
352 // -- ra : return address
353 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
354 // -- sp[argc * 4] : receiver
355 // -----------------------------------
356
357 // 1. Load the first argument into a0 and get rid of the rest (including the
358 // receiver).
359 Label no_arguments;
360 {
361 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
362 __ Subu(a0, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100363 __ Lsa(sp, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000364 __ lw(a0, MemOperand(sp));
365 __ Drop(2);
366 }
367
368 // 2a. At least one argument, return a0 if it's a string, otherwise
369 // dispatch to appropriate conversion.
370 Label to_string, symbol_descriptive_string;
371 {
372 __ JumpIfSmi(a0, &to_string);
373 __ GetObjectType(a0, a1, a1);
374 STATIC_ASSERT(FIRST_NONSTRING_TYPE == SYMBOL_TYPE);
375 __ Subu(a1, a1, Operand(FIRST_NONSTRING_TYPE));
376 __ Branch(&symbol_descriptive_string, eq, a1, Operand(zero_reg));
377 __ Branch(&to_string, gt, a1, Operand(zero_reg));
378 __ Ret(USE_DELAY_SLOT);
379 __ mov(v0, a0);
380 }
381
382 // 2b. No arguments, return the empty string (and pop the receiver).
Ben Murdoch257744e2011-11-30 15:57:28 +0000383 __ bind(&no_arguments);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000384 {
385 __ LoadRoot(v0, Heap::kempty_stringRootIndex);
386 __ DropAndRet(1);
387 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000388
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000389 // 3a. Convert a0 to a string.
390 __ bind(&to_string);
391 {
392 ToStringStub stub(masm->isolate());
393 __ TailCallStub(&stub);
394 }
395
396 // 3b. Convert symbol in a0 to a string.
397 __ bind(&symbol_descriptive_string);
398 {
399 __ Push(a0);
400 __ TailCallRuntime(Runtime::kSymbolDescriptiveString);
401 }
402}
403
404
405// static
406void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
407 // ----------- S t a t e -------------
408 // -- a0 : number of arguments
409 // -- a1 : constructor function
410 // -- a3 : new target
411 // -- ra : return address
412 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
413 // -- sp[argc * 4] : receiver
414 // -----------------------------------
415
416 // 1. Make sure we operate in the context of the called function.
417 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
418
419 // 2. Load the first argument into a0 and get rid of the rest (including the
420 // receiver).
421 {
422 Label no_arguments, done;
423 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
424 __ Subu(a0, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100425 __ Lsa(sp, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000426 __ lw(a0, MemOperand(sp));
427 __ Drop(2);
428 __ jmp(&done);
429 __ bind(&no_arguments);
430 __ LoadRoot(a0, Heap::kempty_stringRootIndex);
431 __ Drop(1);
432 __ bind(&done);
433 }
434
435 // 3. Make sure a0 is a string.
436 {
437 Label convert, done_convert;
438 __ JumpIfSmi(a0, &convert);
439 __ GetObjectType(a0, a2, a2);
440 __ And(t0, a2, Operand(kIsNotStringMask));
441 __ Branch(&done_convert, eq, t0, Operand(zero_reg));
442 __ bind(&convert);
443 {
444 FrameScope scope(masm, StackFrame::INTERNAL);
445 ToStringStub stub(masm->isolate());
446 __ Push(a1, a3);
447 __ CallStub(&stub);
448 __ Move(a0, v0);
449 __ Pop(a1, a3);
450 }
451 __ bind(&done_convert);
452 }
453
454 // 4. Check if new target and constructor differ.
455 Label new_object;
456 __ Branch(&new_object, ne, a1, Operand(a3));
457
458 // 5. Allocate a JSValue wrapper for the string.
459 __ AllocateJSValue(v0, a1, a0, a2, t0, &new_object);
460 __ Ret();
461
462 // 6. Fallback to the runtime to create new object.
463 __ bind(&new_object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100464 {
465 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100466 __ Push(a0); // first argument
467 FastNewObjectStub stub(masm->isolate());
468 __ CallStub(&stub);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000469 __ Pop(a0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100470 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000471 __ Ret(USE_DELAY_SLOT);
472 __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot
Steve Block44f0eee2011-05-26 01:26:41 +0100473}
474
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000475static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
476 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
477 __ lw(a2, FieldMemOperand(a2, SharedFunctionInfo::kCodeOffset));
478 __ Addu(at, a2, Operand(Code::kHeaderSize - kHeapObjectTag));
479 __ Jump(at);
480}
481
Ben Murdoch097c5b22016-05-18 11:27:45 +0100482static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
483 Runtime::FunctionId function_id) {
484 // ----------- S t a t e -------------
485 // -- a0 : argument count (preserved for callee)
486 // -- a1 : target function (preserved for callee)
487 // -- a3 : new target (preserved for callee)
488 // -----------------------------------
489 {
490 FrameScope scope(masm, StackFrame::INTERNAL);
491 // Push a copy of the target function and the new target.
492 // Push function as parameter to the runtime call.
493 __ SmiTag(a0);
494 __ Push(a0, a1, a3, a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000495
Ben Murdoch097c5b22016-05-18 11:27:45 +0100496 __ CallRuntime(function_id, 1);
497
498 // Restore target function and new target.
499 __ Pop(a0, a1, a3);
500 __ SmiUntag(a0);
501 }
502
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000503 __ Addu(at, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
504 __ Jump(at);
505}
506
507
508void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
509 // Checking whether the queued function is ready for install is optional,
510 // since we come across interrupts and stack checks elsewhere. However,
511 // not checking may delay installing ready functions, and always checking
512 // would be quite expensive. A good compromise is to first check against
513 // stack limit as a cue for an interrupt signal.
514 Label ok;
515 __ LoadRoot(t0, Heap::kStackLimitRootIndex);
516 __ Branch(&ok, hs, sp, Operand(t0));
517
Ben Murdoch097c5b22016-05-18 11:27:45 +0100518 GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000519
520 __ bind(&ok);
521 GenerateTailCallToSharedCode(masm);
522}
523
524
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100525static void Generate_JSConstructStubHelper(MacroAssembler* masm,
526 bool is_api_function,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100527 bool create_implicit_receiver,
528 bool check_derived_construct) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000529 // ----------- S t a t e -------------
530 // -- a0 : number of arguments
531 // -- a1 : constructor function
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000532 // -- a2 : allocation site or undefined
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000533 // -- a3 : new target
Ben Murdochda12d292016-06-02 14:46:10 +0100534 // -- cp : context
Ben Murdoch257744e2011-11-30 15:57:28 +0000535 // -- ra : return address
536 // -- sp[...]: constructor arguments
537 // -----------------------------------
538
Ben Murdoch257744e2011-11-30 15:57:28 +0000539 Isolate* isolate = masm->isolate();
540
Ben Murdoch257744e2011-11-30 15:57:28 +0000541 // Enter a construct frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100542 {
543 FrameScope scope(masm, StackFrame::CONSTRUCT);
Ben Murdoch257744e2011-11-30 15:57:28 +0000544
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000545 // Preserve the incoming parameters on the stack.
546 __ AssertUndefinedOrAllocationSite(a2, t0);
547 __ SmiTag(a0);
Ben Murdochda12d292016-06-02 14:46:10 +0100548 __ Push(cp, a2, a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000549
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000550 if (create_implicit_receiver) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100551 // Allocate the new receiver object.
552 __ Push(a1, a3);
553 FastNewObjectStub stub(masm->isolate());
554 __ CallStub(&stub);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000555 __ mov(t4, v0);
556 __ Pop(a1, a3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100557
Ben Murdoch097c5b22016-05-18 11:27:45 +0100558 // ----------- S t a t e -------------
559 // -- a1: constructor function
560 // -- a3: new target
561 // -- t0: newly allocated object
562 // -----------------------------------
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100563
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000564 // Retrieve smi-tagged arguments count from the stack.
565 __ lw(a0, MemOperand(sp));
Ben Murdoch257744e2011-11-30 15:57:28 +0000566 }
567
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000568 __ SmiUntag(a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000569
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000570 if (create_implicit_receiver) {
571 // Push the allocated receiver to the stack. We need two copies
572 // because we may have to return the original one and the calling
573 // conventions dictate that the called function pops the receiver.
574 __ Push(t4, t4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000575 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000576 __ PushRoot(Heap::kTheHoleValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000577 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000578
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100579 // Set up pointer to last argument.
580 __ Addu(a2, fp, Operand(StandardFrameConstants::kCallerSPOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000581
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100582 // Copy arguments and receiver to the expression stack.
583 // a0: number of arguments
584 // a1: constructor function
585 // a2: address of last argument (caller sp)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000586 // a3: new target
587 // t4: number of arguments (smi-tagged)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100588 // sp[0]: receiver
589 // sp[1]: receiver
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000590 // sp[2]: number of arguments (smi-tagged)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100591 Label loop, entry;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000592 __ SmiTag(t4, a0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100593 __ jmp(&entry);
594 __ bind(&loop);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100595 __ Lsa(t0, a2, t4, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100596 __ lw(t1, MemOperand(t0));
597 __ push(t1);
598 __ bind(&entry);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000599 __ Addu(t4, t4, Operand(-2));
600 __ Branch(&loop, greater_equal, t4, Operand(zero_reg));
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000601
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100602 // Call the function.
603 // a0: number of arguments
604 // a1: constructor function
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000605 // a3: new target
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100606 if (is_api_function) {
607 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
608 Handle<Code> code =
609 masm->isolate()->builtins()->HandleApiCallConstruct();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000610 __ Call(code, RelocInfo::CODE_TARGET);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100611 } else {
612 ParameterCount actual(a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000613 __ InvokeFunction(a1, a3, actual, CALL_FUNCTION,
614 CheckDebugStepCallWrapper());
Ben Murdoch257744e2011-11-30 15:57:28 +0000615 }
616
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100617 // Store offset of return address for deoptimizer.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000618 if (create_implicit_receiver && !is_api_function) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100619 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset());
620 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000621
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100622 // Restore context from the frame.
Ben Murdochda12d292016-06-02 14:46:10 +0100623 __ lw(cp, MemOperand(fp, ConstructFrameConstants::kContextOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000624
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000625 if (create_implicit_receiver) {
626 // If the result is an object (in the ECMA sense), we should get rid
627 // of the receiver and use the result; see ECMA-262 section 13.2.2-7
628 // on page 74.
629 Label use_receiver, exit;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100630
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000631 // If the result is a smi, it is *not* an object in the ECMA sense.
632 // v0: result
633 // sp[0]: receiver (newly allocated object)
634 // sp[1]: number of arguments (smi-tagged)
635 __ JumpIfSmi(v0, &use_receiver);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100636
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000637 // If the type of the result (stored in its map) is less than
638 // FIRST_JS_RECEIVER_TYPE, it is not an object in the ECMA sense.
639 __ GetObjectType(v0, a1, a3);
640 __ Branch(&exit, greater_equal, a3, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100641
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000642 // Throw away the result of the constructor invocation and use the
643 // on-stack receiver as the result.
644 __ bind(&use_receiver);
645 __ lw(v0, MemOperand(sp));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100646
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000647 // Remove receiver from the stack, remove caller arguments, and
648 // return.
649 __ bind(&exit);
650 // v0: result
651 // sp[0]: receiver (newly allocated object)
652 // sp[1]: number of arguments (smi-tagged)
653 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
654 } else {
655 __ lw(a1, MemOperand(sp));
656 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100657
658 // Leave construct frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000659 }
660
Ben Murdoch097c5b22016-05-18 11:27:45 +0100661 // ES6 9.2.2. Step 13+
662 // Check that the result is not a Smi, indicating that the constructor result
663 // from a derived class is neither undefined nor an Object.
664 if (check_derived_construct) {
665 Label dont_throw;
666 __ JumpIfNotSmi(v0, &dont_throw);
667 {
668 FrameScope scope(masm, StackFrame::INTERNAL);
669 __ CallRuntime(Runtime::kThrowDerivedConstructorReturnedNonObject);
670 }
671 __ bind(&dont_throw);
672 }
673
674 __ Lsa(sp, sp, a1, kPointerSizeLog2 - 1);
Ben Murdoch257744e2011-11-30 15:57:28 +0000675 __ Addu(sp, sp, kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000676 if (create_implicit_receiver) {
677 __ IncrementCounter(isolate->counters()->constructed_objects(), 1, a1, a2);
678 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000679 __ Ret();
Andrei Popescu31002712010-02-23 13:46:05 +0000680}
681
682
683void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100684 Generate_JSConstructStubHelper(masm, false, true, false);
Andrei Popescu31002712010-02-23 13:46:05 +0000685}
686
687
688void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100689 Generate_JSConstructStubHelper(masm, true, false, false);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000690}
691
692
693void Builtins::Generate_JSBuiltinsConstructStub(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100694 Generate_JSConstructStubHelper(masm, false, false, false);
695}
696
697
698void Builtins::Generate_JSBuiltinsConstructStubForDerived(
699 MacroAssembler* masm) {
700 Generate_JSConstructStubHelper(masm, false, false, true);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000701}
702
703
704void Builtins::Generate_ConstructedNonConstructable(MacroAssembler* masm) {
705 FrameScope scope(masm, StackFrame::INTERNAL);
706 __ Push(a1);
707 __ CallRuntime(Runtime::kThrowConstructedNonConstructable);
708}
709
710
711enum IsTagged { kArgcIsSmiTagged, kArgcIsUntaggedInt };
712
713
714// Clobbers a2; preserves all other registers.
715static void Generate_CheckStackOverflow(MacroAssembler* masm, Register argc,
716 IsTagged argc_is_tagged) {
717 // Check the stack for overflow. We are not trying to catch
718 // interruptions (e.g. debug break and preemption) here, so the "real stack
719 // limit" is checked.
720 Label okay;
721 __ LoadRoot(a2, Heap::kRealStackLimitRootIndex);
722 // Make a2 the space we have left. The stack might already be overflowed
723 // here which will cause a2 to become negative.
724 __ Subu(a2, sp, a2);
725 // Check if the arguments will overflow the stack.
726 if (argc_is_tagged == kArgcIsSmiTagged) {
727 __ sll(t3, argc, kPointerSizeLog2 - kSmiTagSize);
728 } else {
729 DCHECK(argc_is_tagged == kArgcIsUntaggedInt);
730 __ sll(t3, argc, kPointerSizeLog2);
731 }
732 // Signed comparison.
733 __ Branch(&okay, gt, a2, Operand(t3));
734
735 // Out of stack space.
736 __ CallRuntime(Runtime::kThrowStackOverflow);
737
738 __ bind(&okay);
Ben Murdoch257744e2011-11-30 15:57:28 +0000739}
740
741
742static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
743 bool is_construct) {
744 // Called from JSEntryStub::GenerateBody
745
746 // ----------- S t a t e -------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000747 // -- a0: new.target
Ben Murdoch257744e2011-11-30 15:57:28 +0000748 // -- a1: function
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100749 // -- a2: receiver_pointer
Ben Murdoch257744e2011-11-30 15:57:28 +0000750 // -- a3: argc
751 // -- s0: argv
752 // -----------------------------------
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000753 ProfileEntryHookStub::MaybeCallEntryHook(masm);
Ben Murdoch257744e2011-11-30 15:57:28 +0000754
Ben Murdoch257744e2011-11-30 15:57:28 +0000755 // Enter an internal frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100756 {
757 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch257744e2011-11-30 15:57:28 +0000758
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000759 // Setup the context (we need to use the caller context from the isolate).
760 ExternalReference context_address(Isolate::kContextAddress,
761 masm->isolate());
762 __ li(cp, Operand(context_address));
763 __ lw(cp, MemOperand(cp));
Ben Murdoch257744e2011-11-30 15:57:28 +0000764
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100765 // Push the function and the receiver onto the stack.
766 __ Push(a1, a2);
Ben Murdoch257744e2011-11-30 15:57:28 +0000767
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000768 // Check if we have enough stack space to push all arguments.
769 // Clobbers a2.
770 Generate_CheckStackOverflow(masm, a3, kArgcIsUntaggedInt);
771
772 // Remember new.target.
773 __ mov(t1, a0);
774
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100775 // Copy arguments to the stack in a loop.
776 // a3: argc
777 // s0: argv, i.e. points to first arg
778 Label loop, entry;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100779 __ Lsa(t2, s0, a3, kPointerSizeLog2);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100780 __ b(&entry);
781 __ nop(); // Branch delay slot nop.
782 // t2 points past last arg.
783 __ bind(&loop);
784 __ lw(t0, MemOperand(s0)); // Read next parameter.
785 __ addiu(s0, s0, kPointerSize);
786 __ lw(t0, MemOperand(t0)); // Dereference handle.
787 __ push(t0); // Push parameter.
788 __ bind(&entry);
789 __ Branch(&loop, ne, s0, Operand(t2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000790
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000791 // Setup new.target and argc.
792 __ mov(a0, a3);
793 __ mov(a3, t1);
794
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100795 // Initialize all JavaScript callee-saved registers, since they will be seen
796 // by the garbage collector as part of handlers.
797 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
798 __ mov(s1, t0);
799 __ mov(s2, t0);
800 __ mov(s3, t0);
801 __ mov(s4, t0);
802 __ mov(s5, t0);
803 // s6 holds the root address. Do not clobber.
804 // s7 is cp. Do not init.
Ben Murdoch257744e2011-11-30 15:57:28 +0000805
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000806 // Invoke the code.
807 Handle<Code> builtin = is_construct
808 ? masm->isolate()->builtins()->Construct()
809 : masm->isolate()->builtins()->Call();
810 __ Call(builtin, RelocInfo::CODE_TARGET);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000811
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100812 // Leave internal frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000813 }
814
Ben Murdoch257744e2011-11-30 15:57:28 +0000815 __ Jump(ra);
Andrei Popescu31002712010-02-23 13:46:05 +0000816}
817
818
Andrei Popescu31002712010-02-23 13:46:05 +0000819void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000820 Generate_JSEntryTrampolineHelper(masm, false);
Andrei Popescu31002712010-02-23 13:46:05 +0000821}
822
823
824void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000825 Generate_JSEntryTrampolineHelper(masm, true);
Steve Block44f0eee2011-05-26 01:26:41 +0100826}
827
828
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000829// Generate code for entering a JS function with the interpreter.
830// On entry to the function the receiver and arguments have been pushed on the
831// stack left to right. The actual argument count matches the formal parameter
832// count expected by the function.
833//
834// The live registers are:
835// o a1: the JS function object being called.
836// o a3: the new target
837// o cp: our context
838// o fp: the caller's frame pointer
839// o sp: stack pointer
840// o ra: return address
841//
Ben Murdoch097c5b22016-05-18 11:27:45 +0100842// The function builds an interpreter frame. See InterpreterFrameConstants in
843// frames.h for its layout.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000844void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
845 // Open a frame scope to indicate that there is a frame on the stack. The
846 // MANUAL indicates that the scope shouldn't actually generate code to set up
847 // the frame (that is done below).
848 FrameScope frame_scope(masm, StackFrame::MANUAL);
Ben Murdochda12d292016-06-02 14:46:10 +0100849 __ PushStandardFrame(a1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000850
851 // Get the bytecode array from the function object and load the pointer to the
852 // first entry into kInterpreterBytecodeRegister.
853 __ lw(a0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100854 Label load_debug_bytecode_array, bytecode_array_loaded;
855 Register debug_info = kInterpreterBytecodeArrayRegister;
856 DCHECK(!debug_info.is(a0));
857 __ lw(debug_info, FieldMemOperand(a0, SharedFunctionInfo::kDebugInfoOffset));
858 __ Branch(&load_debug_bytecode_array, ne, debug_info,
859 Operand(DebugInfo::uninitialized()));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000860 __ lw(kInterpreterBytecodeArrayRegister,
861 FieldMemOperand(a0, SharedFunctionInfo::kFunctionDataOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100862 __ bind(&bytecode_array_loaded);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000863
864 if (FLAG_debug_code) {
865 // Check function data field is actually a BytecodeArray object.
866 __ SmiTst(kInterpreterBytecodeArrayRegister, t0);
867 __ Assert(ne, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, t0,
868 Operand(zero_reg));
869 __ GetObjectType(kInterpreterBytecodeArrayRegister, t0, t0);
870 __ Assert(eq, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, t0,
871 Operand(BYTECODE_ARRAY_TYPE));
872 }
873
Ben Murdoch097c5b22016-05-18 11:27:45 +0100874 // Push new.target, bytecode array and zero for bytecode array offset.
875 __ Push(a3, kInterpreterBytecodeArrayRegister, zero_reg);
876
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000877 // Allocate the local and temporary register file on the stack.
878 {
879 // Load frame size from the BytecodeArray object.
880 __ lw(t0, FieldMemOperand(kInterpreterBytecodeArrayRegister,
881 BytecodeArray::kFrameSizeOffset));
882
883 // Do a stack check to ensure we don't go over the limit.
884 Label ok;
885 __ Subu(t1, sp, Operand(t0));
886 __ LoadRoot(a2, Heap::kRealStackLimitRootIndex);
887 __ Branch(&ok, hs, t1, Operand(a2));
888 __ CallRuntime(Runtime::kThrowStackOverflow);
889 __ bind(&ok);
890
891 // If ok, push undefined as the initial value for all register file entries.
892 Label loop_header;
893 Label loop_check;
894 __ LoadRoot(t1, Heap::kUndefinedValueRootIndex);
895 __ Branch(&loop_check);
896 __ bind(&loop_header);
897 // TODO(rmcilroy): Consider doing more than one push per loop iteration.
898 __ push(t1);
899 // Continue loop if not done.
900 __ bind(&loop_check);
901 __ Subu(t0, t0, Operand(kPointerSize));
902 __ Branch(&loop_header, ge, t0, Operand(zero_reg));
903 }
904
905 // TODO(rmcilroy): List of things not currently dealt with here but done in
906 // fullcodegen's prologue:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000907 // - Call ProfileEntryHookStub when isolate has a function_entry_hook.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000908 // - Code aging of the BytecodeArray object.
909
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000910 // Load bytecode offset and dispatch table into registers.
911 __ LoadRoot(kInterpreterAccumulatorRegister, Heap::kUndefinedValueRootIndex);
912 __ Addu(kInterpreterRegisterFileRegister, fp,
913 Operand(InterpreterFrameConstants::kRegisterFilePointerFromFp));
914 __ li(kInterpreterBytecodeOffsetRegister,
915 Operand(BytecodeArray::kHeaderSize - kHeapObjectTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100916 __ li(kInterpreterDispatchTableRegister,
917 Operand(ExternalReference::interpreter_dispatch_table_address(
918 masm->isolate())));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000919
920 // Dispatch to the first bytecode handler for the function.
921 __ Addu(a0, kInterpreterBytecodeArrayRegister,
922 kInterpreterBytecodeOffsetRegister);
923 __ lbu(a0, MemOperand(a0));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100924 __ Lsa(at, kInterpreterDispatchTableRegister, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000925 __ lw(at, MemOperand(at));
926 // TODO(rmcilroy): Make dispatch table point to code entrys to avoid untagging
927 // and header removal.
928 __ Addu(at, at, Operand(Code::kHeaderSize - kHeapObjectTag));
929 __ Call(at);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100930
931 // Even though the first bytecode handler was called, we will never return.
932 __ Abort(kUnexpectedReturnFromBytecodeHandler);
933
934 // Load debug copy of the bytecode array.
935 __ bind(&load_debug_bytecode_array);
936 __ lw(kInterpreterBytecodeArrayRegister,
937 FieldMemOperand(debug_info, DebugInfo::kAbstractCodeIndex));
938 __ Branch(&bytecode_array_loaded);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000939}
940
941
942void Builtins::Generate_InterpreterExitTrampoline(MacroAssembler* masm) {
943 // TODO(rmcilroy): List of things not currently dealt with here but done in
944 // fullcodegen's EmitReturnSequence.
945 // - Supporting FLAG_trace for Runtime::TraceExit.
946 // - Support profiler (specifically decrementing profiling_counter
947 // appropriately and calling out to HandleInterrupts if necessary).
948
949 // The return value is in accumulator, which is already in v0.
950
951 // Leave the frame (also dropping the register file).
952 __ LeaveFrame(StackFrame::JAVA_SCRIPT);
953
954 // Drop receiver + arguments and return.
955 __ lw(at, FieldMemOperand(kInterpreterBytecodeArrayRegister,
956 BytecodeArray::kParameterSizeOffset));
957 __ Addu(sp, sp, at);
958 __ Jump(ra);
959}
960
961
962// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100963void Builtins::Generate_InterpreterPushArgsAndCallImpl(
964 MacroAssembler* masm, TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000965 // ----------- S t a t e -------------
966 // -- a0 : the number of arguments (not including the receiver)
967 // -- a2 : the address of the first argument to be pushed. Subsequent
968 // arguments should be consecutive above this, in the same order as
969 // they are to be pushed onto the stack.
970 // -- a1 : the target to call (can be any Object).
971 // -----------------------------------
972
973 // Find the address of the last argument.
974 __ Addu(a3, a0, Operand(1)); // Add one for receiver.
975 __ sll(a3, a3, kPointerSizeLog2);
976 __ Subu(a3, a2, Operand(a3));
977
978 // Push the arguments.
979 Label loop_header, loop_check;
980 __ Branch(&loop_check);
981 __ bind(&loop_header);
982 __ lw(t0, MemOperand(a2));
983 __ Addu(a2, a2, Operand(-kPointerSize));
984 __ push(t0);
985 __ bind(&loop_check);
986 __ Branch(&loop_header, gt, a2, Operand(a3));
987
988 // Call the target.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100989 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny,
990 tail_call_mode),
991 RelocInfo::CODE_TARGET);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000992}
993
994
995// static
996void Builtins::Generate_InterpreterPushArgsAndConstruct(MacroAssembler* masm) {
997 // ----------- S t a t e -------------
998 // -- a0 : argument count (not including receiver)
999 // -- a3 : new target
1000 // -- a1 : constructor to call
1001 // -- a2 : address of the first argument
1002 // -----------------------------------
1003
1004 // Find the address of the last argument.
1005 __ sll(t0, a0, kPointerSizeLog2);
1006 __ Subu(t0, a2, Operand(t0));
1007
1008 // Push a slot for the receiver.
1009 __ push(zero_reg);
1010
1011 // Push the arguments.
1012 Label loop_header, loop_check;
1013 __ Branch(&loop_check);
1014 __ bind(&loop_header);
1015 __ lw(t1, MemOperand(a2));
1016 __ Addu(a2, a2, Operand(-kPointerSize));
1017 __ push(t1);
1018 __ bind(&loop_check);
1019 __ Branch(&loop_header, gt, a2, Operand(t0));
1020
1021 // Call the constructor with a0, a1, and a3 unmodified.
1022 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
1023}
1024
1025
Ben Murdoch097c5b22016-05-18 11:27:45 +01001026static void Generate_EnterBytecodeDispatch(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001027 // Initialize register file register and dispatch table register.
1028 __ Addu(kInterpreterRegisterFileRegister, fp,
1029 Operand(InterpreterFrameConstants::kRegisterFilePointerFromFp));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001030 __ li(kInterpreterDispatchTableRegister,
1031 Operand(ExternalReference::interpreter_dispatch_table_address(
1032 masm->isolate())));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001033
1034 // Get the context from the frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001035 __ lw(kContextRegister,
1036 MemOperand(kInterpreterRegisterFileRegister,
1037 InterpreterFrameConstants::kContextFromRegisterPointer));
1038
1039 // Get the bytecode array pointer from the frame.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001040 __ lw(
1041 kInterpreterBytecodeArrayRegister,
1042 MemOperand(kInterpreterRegisterFileRegister,
1043 InterpreterFrameConstants::kBytecodeArrayFromRegisterPointer));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001044
1045 if (FLAG_debug_code) {
1046 // Check function data field is actually a BytecodeArray object.
1047 __ SmiTst(kInterpreterBytecodeArrayRegister, at);
1048 __ Assert(ne, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, at,
1049 Operand(zero_reg));
1050 __ GetObjectType(kInterpreterBytecodeArrayRegister, a1, a1);
1051 __ Assert(eq, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, a1,
1052 Operand(BYTECODE_ARRAY_TYPE));
1053 }
1054
1055 // Get the target bytecode offset from the frame.
1056 __ lw(kInterpreterBytecodeOffsetRegister,
1057 MemOperand(
1058 kInterpreterRegisterFileRegister,
1059 InterpreterFrameConstants::kBytecodeOffsetFromRegisterPointer));
1060 __ SmiUntag(kInterpreterBytecodeOffsetRegister);
1061
1062 // Dispatch to the target bytecode.
1063 __ Addu(a1, kInterpreterBytecodeArrayRegister,
1064 kInterpreterBytecodeOffsetRegister);
1065 __ lbu(a1, MemOperand(a1));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001066 __ Lsa(a1, kInterpreterDispatchTableRegister, a1, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001067 __ lw(a1, MemOperand(a1));
1068 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1069 __ Jump(a1);
1070}
1071
1072
Ben Murdoch097c5b22016-05-18 11:27:45 +01001073static void Generate_InterpreterNotifyDeoptimizedHelper(
1074 MacroAssembler* masm, Deoptimizer::BailoutType type) {
1075 // Enter an internal frame.
1076 {
1077 FrameScope scope(masm, StackFrame::INTERNAL);
1078
1079 // Pass the deoptimization type to the runtime system.
1080 __ li(a1, Operand(Smi::FromInt(static_cast<int>(type))));
1081 __ push(a1);
1082 __ CallRuntime(Runtime::kNotifyDeoptimized);
1083 // Tear down internal frame.
1084 }
1085
1086 // Drop state (we don't use these for interpreter deopts) and and pop the
1087 // accumulator value into the accumulator register.
1088 __ Drop(1);
1089 __ Pop(kInterpreterAccumulatorRegister);
1090
1091 // Enter the bytecode dispatch.
1092 Generate_EnterBytecodeDispatch(masm);
1093}
1094
1095
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001096void Builtins::Generate_InterpreterNotifyDeoptimized(MacroAssembler* masm) {
1097 Generate_InterpreterNotifyDeoptimizedHelper(masm, Deoptimizer::EAGER);
1098}
1099
1100
1101void Builtins::Generate_InterpreterNotifySoftDeoptimized(MacroAssembler* masm) {
1102 Generate_InterpreterNotifyDeoptimizedHelper(masm, Deoptimizer::SOFT);
1103}
1104
1105
1106void Builtins::Generate_InterpreterNotifyLazyDeoptimized(MacroAssembler* masm) {
1107 Generate_InterpreterNotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
1108}
1109
Ben Murdoch097c5b22016-05-18 11:27:45 +01001110void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
1111 // Set the address of the interpreter entry trampoline as a return address.
1112 // This simulates the initial call to bytecode handlers in interpreter entry
1113 // trampoline. The return will never actually be taken, but our stack walker
1114 // uses this address to determine whether a frame is interpreted.
1115 __ li(ra, Operand(masm->isolate()->builtins()->InterpreterEntryTrampoline()));
1116
1117 Generate_EnterBytecodeDispatch(masm);
1118}
1119
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001120
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001121void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001122 GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
Steve Block44f0eee2011-05-26 01:26:41 +01001123}
1124
1125
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001126void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001127 GenerateTailCallToReturnedCode(masm,
1128 Runtime::kCompileOptimized_NotConcurrent);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001129}
1130
1131
1132void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001133 GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001134}
1135
1136
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001137static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) {
1138 // For now, we are relying on the fact that make_code_young doesn't do any
1139 // garbage collection which allows us to save/restore the registers without
1140 // worrying about which of them contain pointers. We also don't build an
1141 // internal frame to make the code faster, since we shouldn't have to do stack
1142 // crawls in MakeCodeYoung. This seems a bit fragile.
1143
1144 // Set a0 to point to the head of the PlatformCodeAge sequence.
1145 __ Subu(a0, a0,
1146 Operand(kNoCodeAgeSequenceLength - Assembler::kInstrSize));
1147
1148 // The following registers must be saved and restored when calling through to
1149 // the runtime:
1150 // a0 - contains return address (beginning of patch sequence)
1151 // a1 - isolate
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001152 // a3 - new target
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001153 RegList saved_regs =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001154 (a0.bit() | a1.bit() | a3.bit() | ra.bit() | fp.bit()) & ~sp.bit();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001155 FrameScope scope(masm, StackFrame::MANUAL);
1156 __ MultiPush(saved_regs);
1157 __ PrepareCallCFunction(2, 0, a2);
1158 __ li(a1, Operand(ExternalReference::isolate_address(masm->isolate())));
1159 __ CallCFunction(
1160 ExternalReference::get_make_code_young_function(masm->isolate()), 2);
1161 __ MultiPop(saved_regs);
1162 __ Jump(a0);
1163}
1164
1165#define DEFINE_CODE_AGE_BUILTIN_GENERATOR(C) \
1166void Builtins::Generate_Make##C##CodeYoungAgainEvenMarking( \
1167 MacroAssembler* masm) { \
1168 GenerateMakeCodeYoungAgainCommon(masm); \
1169} \
1170void Builtins::Generate_Make##C##CodeYoungAgainOddMarking( \
1171 MacroAssembler* masm) { \
1172 GenerateMakeCodeYoungAgainCommon(masm); \
1173}
1174CODE_AGE_LIST(DEFINE_CODE_AGE_BUILTIN_GENERATOR)
1175#undef DEFINE_CODE_AGE_BUILTIN_GENERATOR
1176
1177
1178void Builtins::Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm) {
1179 // For now, as in GenerateMakeCodeYoungAgainCommon, we are relying on the fact
1180 // that make_code_young doesn't do any garbage collection which allows us to
1181 // save/restore the registers without worrying about which of them contain
1182 // pointers.
1183
1184 // Set a0 to point to the head of the PlatformCodeAge sequence.
1185 __ Subu(a0, a0,
1186 Operand(kNoCodeAgeSequenceLength - Assembler::kInstrSize));
1187
1188 // The following registers must be saved and restored when calling through to
1189 // the runtime:
1190 // a0 - contains return address (beginning of patch sequence)
1191 // a1 - isolate
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001192 // a3 - new target
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001193 RegList saved_regs =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001194 (a0.bit() | a1.bit() | a3.bit() | ra.bit() | fp.bit()) & ~sp.bit();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001195 FrameScope scope(masm, StackFrame::MANUAL);
1196 __ MultiPush(saved_regs);
1197 __ PrepareCallCFunction(2, 0, a2);
1198 __ li(a1, Operand(ExternalReference::isolate_address(masm->isolate())));
1199 __ CallCFunction(
1200 ExternalReference::get_mark_code_as_executed_function(masm->isolate()),
1201 2);
1202 __ MultiPop(saved_regs);
1203
1204 // Perform prologue operations usually performed by the young code stub.
Ben Murdochda12d292016-06-02 14:46:10 +01001205 __ PushStandardFrame(a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001206
1207 // Jump to point after the code-age stub.
1208 __ Addu(a0, a0, Operand(kNoCodeAgeSequenceLength));
1209 __ Jump(a0);
1210}
1211
1212
1213void Builtins::Generate_MarkCodeAsExecutedTwice(MacroAssembler* masm) {
1214 GenerateMakeCodeYoungAgainCommon(masm);
1215}
1216
1217
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001218void Builtins::Generate_MarkCodeAsToBeExecutedOnce(MacroAssembler* masm) {
1219 Generate_MarkCodeAsExecutedOnce(masm);
1220}
1221
1222
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001223static void Generate_NotifyStubFailureHelper(MacroAssembler* masm,
1224 SaveFPRegsMode save_doubles) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001225 {
1226 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch257744e2011-11-30 15:57:28 +00001227
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001228 // Preserve registers across notification, this is important for compiled
1229 // stubs that tail call the runtime on deopts passing their parameters in
1230 // registers.
1231 __ MultiPush(kJSCallerSaved | kCalleeSaved);
1232 // Pass the function and deoptimization type to the runtime system.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001233 __ CallRuntime(Runtime::kNotifyStubFailure, save_doubles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001234 __ MultiPop(kJSCallerSaved | kCalleeSaved);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001235 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001236
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001237 __ Addu(sp, sp, Operand(kPointerSize)); // Ignore state
1238 __ Jump(ra); // Jump to miss handler
1239}
1240
1241
1242void Builtins::Generate_NotifyStubFailure(MacroAssembler* masm) {
1243 Generate_NotifyStubFailureHelper(masm, kDontSaveFPRegs);
1244}
1245
1246
1247void Builtins::Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm) {
1248 Generate_NotifyStubFailureHelper(masm, kSaveFPRegs);
Steve Block44f0eee2011-05-26 01:26:41 +01001249}
1250
1251
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001252static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm,
1253 Deoptimizer::BailoutType type) {
1254 {
1255 FrameScope scope(masm, StackFrame::INTERNAL);
1256 // Pass the function and deoptimization type to the runtime system.
1257 __ li(a0, Operand(Smi::FromInt(static_cast<int>(type))));
1258 __ push(a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001259 __ CallRuntime(Runtime::kNotifyDeoptimized);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001260 }
1261
1262 // Get the full codegen state from the stack and untag it -> t2.
1263 __ lw(t2, MemOperand(sp, 0 * kPointerSize));
1264 __ SmiUntag(t2);
1265 // Switch on the state.
1266 Label with_tos_register, unknown_state;
1267 __ Branch(&with_tos_register,
1268 ne, t2, Operand(FullCodeGenerator::NO_REGISTERS));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001269 __ Ret(USE_DELAY_SLOT);
1270 // Safe to fill delay slot Addu will emit one instruction.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001271 __ Addu(sp, sp, Operand(1 * kPointerSize)); // Remove state.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001272
1273 __ bind(&with_tos_register);
1274 __ lw(v0, MemOperand(sp, 1 * kPointerSize));
1275 __ Branch(&unknown_state, ne, t2, Operand(FullCodeGenerator::TOS_REG));
1276
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001277 __ Ret(USE_DELAY_SLOT);
1278 // Safe to fill delay slot Addu will emit one instruction.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001279 __ Addu(sp, sp, Operand(2 * kPointerSize)); // Remove state.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001280
1281 __ bind(&unknown_state);
1282 __ stop("no cases left");
1283}
1284
1285
Steve Block44f0eee2011-05-26 01:26:41 +01001286void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001287 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER);
Steve Block44f0eee2011-05-26 01:26:41 +01001288}
1289
1290
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001291void Builtins::Generate_NotifySoftDeoptimized(MacroAssembler* masm) {
1292 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::SOFT);
1293}
1294
1295
Steve Block44f0eee2011-05-26 01:26:41 +01001296void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001297 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
Steve Block44f0eee2011-05-26 01:26:41 +01001298}
1299
1300
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001301// Clobbers {t2, t3, t4, t5}.
1302static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
1303 Register function_template_info,
1304 Label* receiver_check_failed) {
1305 Register signature = t2;
1306 Register map = t3;
1307 Register constructor = t4;
1308 Register scratch = t5;
1309
1310 // If there is no signature, return the holder.
1311 __ lw(signature, FieldMemOperand(function_template_info,
1312 FunctionTemplateInfo::kSignatureOffset));
1313 Label receiver_check_passed;
1314 __ JumpIfRoot(signature, Heap::kUndefinedValueRootIndex,
1315 &receiver_check_passed);
1316
1317 // Walk the prototype chain.
1318 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
1319 Label prototype_loop_start;
1320 __ bind(&prototype_loop_start);
1321
1322 // Get the constructor, if any.
1323 __ GetMapConstructor(constructor, map, scratch, scratch);
1324 Label next_prototype;
1325 __ Branch(&next_prototype, ne, scratch, Operand(JS_FUNCTION_TYPE));
1326 Register type = constructor;
1327 __ lw(type,
1328 FieldMemOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
1329 __ lw(type, FieldMemOperand(type, SharedFunctionInfo::kFunctionDataOffset));
1330
1331 // Loop through the chain of inheriting function templates.
1332 Label function_template_loop;
1333 __ bind(&function_template_loop);
1334
1335 // If the signatures match, we have a compatible receiver.
1336 __ Branch(&receiver_check_passed, eq, signature, Operand(type),
1337 USE_DELAY_SLOT);
1338
1339 // If the current type is not a FunctionTemplateInfo, load the next prototype
1340 // in the chain.
1341 __ JumpIfSmi(type, &next_prototype);
1342 __ GetObjectType(type, scratch, scratch);
1343 __ Branch(&next_prototype, ne, scratch, Operand(FUNCTION_TEMPLATE_INFO_TYPE));
1344
1345 // Otherwise load the parent function template and iterate.
1346 __ lw(type,
1347 FieldMemOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
1348 __ Branch(&function_template_loop);
1349
1350 // Load the next prototype and iterate.
1351 __ bind(&next_prototype);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001352 __ lw(scratch, FieldMemOperand(map, Map::kBitField3Offset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001353 __ DecodeField<Map::HasHiddenPrototype>(scratch);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001354 __ Branch(receiver_check_failed, eq, scratch, Operand(zero_reg));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001355 __ lw(receiver, FieldMemOperand(map, Map::kPrototypeOffset));
1356 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001357
1358 __ Branch(&prototype_loop_start);
1359
1360 __ bind(&receiver_check_passed);
1361}
1362
1363
1364void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
1365 // ----------- S t a t e -------------
1366 // -- a0 : number of arguments excluding receiver
1367 // -- a1 : callee
1368 // -- ra : return address
1369 // -- sp[0] : last argument
1370 // -- ...
1371 // -- sp[4 * (argc - 1)] : first argument
1372 // -- sp[4 * argc] : receiver
1373 // -----------------------------------
1374
1375 // Load the FunctionTemplateInfo.
1376 __ lw(t1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1377 __ lw(t1, FieldMemOperand(t1, SharedFunctionInfo::kFunctionDataOffset));
1378
1379 // Do the compatible receiver check.
1380 Label receiver_check_failed;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001381 __ Lsa(t8, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001382 __ lw(t0, MemOperand(t8));
1383 CompatibleReceiverCheck(masm, t0, t1, &receiver_check_failed);
1384
1385 // Get the callback offset from the FunctionTemplateInfo, and jump to the
1386 // beginning of the code.
1387 __ lw(t2, FieldMemOperand(t1, FunctionTemplateInfo::kCallCodeOffset));
1388 __ lw(t2, FieldMemOperand(t2, CallHandlerInfo::kFastHandlerOffset));
1389 __ Addu(t2, t2, Operand(Code::kHeaderSize - kHeapObjectTag));
1390 __ Jump(t2);
1391
1392 // Compatible receiver check failed: throw an Illegal Invocation exception.
1393 __ bind(&receiver_check_failed);
1394 // Drop the arguments (including the receiver);
1395 __ Addu(t8, t8, Operand(kPointerSize));
1396 __ addu(sp, t8, zero_reg);
1397 __ TailCallRuntime(Runtime::kThrowIllegalInvocation);
1398}
1399
1400
Steve Block44f0eee2011-05-26 01:26:41 +01001401void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001402 // Lookup the function in the JavaScript frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001403 __ lw(a0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1404 {
1405 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001406 // Pass function as argument.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001407 __ push(a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001408 __ CallRuntime(Runtime::kCompileForOnStackReplacement);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001409 }
1410
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001411 // If the code object is null, just return to the unoptimized code.
1412 __ Ret(eq, v0, Operand(Smi::FromInt(0)));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001413
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001414 // Load deoptimization data from the code object.
1415 // <deopt_data> = <code>[#deoptimization_data_offset]
1416 __ lw(a1, MemOperand(v0, Code::kDeoptimizationDataOffset - kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001417
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001418 // Load the OSR entrypoint offset from the deoptimization data.
1419 // <osr_offset> = <deopt_data>[#header_size + #osr_pc_offset]
1420 __ lw(a1, MemOperand(a1, FixedArray::OffsetOfElementAt(
1421 DeoptimizationInputData::kOsrPcOffsetIndex) - kHeapObjectTag));
1422 __ SmiUntag(a1);
1423
1424 // Compute the target address = code_obj + header_size + osr_offset
1425 // <entry_addr> = <code_obj> + #header_size + <osr_offset>
1426 __ addu(v0, v0, a1);
1427 __ addiu(ra, v0, Code::kHeaderSize - kHeapObjectTag);
1428
1429 // And "return" to the OSR entry point of the function.
1430 __ Ret();
1431}
1432
1433
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001434// static
1435void Builtins::Generate_DatePrototype_GetField(MacroAssembler* masm,
1436 int field_index) {
1437 // ----------- S t a t e -------------
1438 // -- sp[0] : receiver
1439 // -----------------------------------
1440
1441 // 1. Pop receiver into a0 and check that it's actually a JSDate object.
1442 Label receiver_not_date;
1443 {
1444 __ Pop(a0);
1445 __ JumpIfSmi(a0, &receiver_not_date);
1446 __ GetObjectType(a0, t0, t0);
1447 __ Branch(&receiver_not_date, ne, t0, Operand(JS_DATE_TYPE));
1448 }
1449
1450 // 2. Load the specified date field, falling back to the runtime as necessary.
1451 if (field_index == JSDate::kDateValue) {
1452 __ Ret(USE_DELAY_SLOT);
1453 __ lw(v0, FieldMemOperand(a0, JSDate::kValueOffset)); // In delay slot.
1454 } else {
1455 if (field_index < JSDate::kFirstUncachedField) {
1456 Label stamp_mismatch;
1457 __ li(a1, Operand(ExternalReference::date_cache_stamp(masm->isolate())));
1458 __ lw(a1, MemOperand(a1));
1459 __ lw(t0, FieldMemOperand(a0, JSDate::kCacheStampOffset));
1460 __ Branch(&stamp_mismatch, ne, t0, Operand(a1));
1461 __ Ret(USE_DELAY_SLOT);
1462 __ lw(v0, FieldMemOperand(
1463 a0, JSDate::kValueOffset +
1464 field_index * kPointerSize)); // In delay slot.
1465 __ bind(&stamp_mismatch);
1466 }
1467 FrameScope scope(masm, StackFrame::INTERNAL);
1468 __ PrepareCallCFunction(2, t0);
1469 __ li(a1, Operand(Smi::FromInt(field_index)));
1470 __ CallCFunction(
1471 ExternalReference::get_date_field_function(masm->isolate()), 2);
1472 }
1473 __ Ret();
1474
1475 // 3. Raise a TypeError if the receiver is not a date.
1476 __ bind(&receiver_not_date);
1477 __ TailCallRuntime(Runtime::kThrowNotDateError);
1478}
1479
Ben Murdochda12d292016-06-02 14:46:10 +01001480// static
1481void Builtins::Generate_FunctionHasInstance(MacroAssembler* masm) {
1482 // ----------- S t a t e -------------
1483 // -- a0 : argc
1484 // -- sp[0] : first argument (left-hand side)
1485 // -- sp[4] : receiver (right-hand side)
1486 // -----------------------------------
1487
1488 {
1489 FrameScope scope(masm, StackFrame::INTERNAL);
1490 __ lw(InstanceOfDescriptor::LeftRegister(),
1491 MemOperand(fp, 2 * kPointerSize)); // Load left-hand side.
1492 __ lw(InstanceOfDescriptor::RightRegister(),
1493 MemOperand(fp, 3 * kPointerSize)); // Load right-hand side.
1494 InstanceOfStub stub(masm->isolate(), true);
1495 __ CallStub(&stub);
1496 }
1497
1498 // Pop the argument and the receiver.
1499 __ DropAndRet(2);
1500}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001501
1502// static
1503void Builtins::Generate_FunctionPrototypeApply(MacroAssembler* masm) {
1504 // ----------- S t a t e -------------
1505 // -- a0 : argc
1506 // -- sp[0] : argArray
1507 // -- sp[4] : thisArg
1508 // -- sp[8] : receiver
1509 // -----------------------------------
1510
1511 // 1. Load receiver into a1, argArray into a0 (if present), remove all
1512 // arguments from the stack (including the receiver), and push thisArg (if
1513 // present) instead.
1514 {
1515 Label no_arg;
1516 Register scratch = t0;
1517 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
1518 __ mov(a3, a2);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001519 // Lsa() cannot be used hare as scratch value used later.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001520 __ sll(scratch, a0, kPointerSizeLog2);
1521 __ Addu(a0, sp, Operand(scratch));
1522 __ lw(a1, MemOperand(a0)); // receiver
1523 __ Subu(a0, a0, Operand(kPointerSize));
1524 __ Branch(&no_arg, lt, a0, Operand(sp));
1525 __ lw(a2, MemOperand(a0)); // thisArg
1526 __ Subu(a0, a0, Operand(kPointerSize));
1527 __ Branch(&no_arg, lt, a0, Operand(sp));
1528 __ lw(a3, MemOperand(a0)); // argArray
1529 __ bind(&no_arg);
1530 __ Addu(sp, sp, Operand(scratch));
1531 __ sw(a2, MemOperand(sp));
1532 __ mov(a0, a3);
1533 }
1534
1535 // ----------- S t a t e -------------
1536 // -- a0 : argArray
1537 // -- a1 : receiver
1538 // -- sp[0] : thisArg
1539 // -----------------------------------
1540
1541 // 2. Make sure the receiver is actually callable.
1542 Label receiver_not_callable;
1543 __ JumpIfSmi(a1, &receiver_not_callable);
1544 __ lw(t0, FieldMemOperand(a1, HeapObject::kMapOffset));
1545 __ lbu(t0, FieldMemOperand(t0, Map::kBitFieldOffset));
1546 __ And(t0, t0, Operand(1 << Map::kIsCallable));
1547 __ Branch(&receiver_not_callable, eq, t0, Operand(zero_reg));
1548
1549 // 3. Tail call with no arguments if argArray is null or undefined.
1550 Label no_arguments;
1551 __ JumpIfRoot(a0, Heap::kNullValueRootIndex, &no_arguments);
1552 __ JumpIfRoot(a0, Heap::kUndefinedValueRootIndex, &no_arguments);
1553
1554 // 4a. Apply the receiver to the given argArray (passing undefined for
1555 // new.target).
1556 __ LoadRoot(a3, Heap::kUndefinedValueRootIndex);
1557 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1558
1559 // 4b. The argArray is either null or undefined, so we tail call without any
1560 // arguments to the receiver.
1561 __ bind(&no_arguments);
1562 {
1563 __ mov(a0, zero_reg);
1564 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1565 }
1566
1567 // 4c. The receiver is not callable, throw an appropriate TypeError.
1568 __ bind(&receiver_not_callable);
1569 {
1570 __ sw(a1, MemOperand(sp));
1571 __ TailCallRuntime(Runtime::kThrowApplyNonFunction);
1572 }
1573}
1574
1575
1576// static
1577void Builtins::Generate_FunctionPrototypeCall(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +00001578 // 1. Make sure we have at least one argument.
1579 // a0: actual number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001580 {
1581 Label done;
Ben Murdoch257744e2011-11-30 15:57:28 +00001582 __ Branch(&done, ne, a0, Operand(zero_reg));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001583 __ PushRoot(Heap::kUndefinedValueRootIndex);
Ben Murdoch257744e2011-11-30 15:57:28 +00001584 __ Addu(a0, a0, Operand(1));
1585 __ bind(&done);
1586 }
1587
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001588 // 2. Get the function to call (passed as receiver) from the stack.
Ben Murdoch257744e2011-11-30 15:57:28 +00001589 // a0: actual number of arguments
Ben Murdoch097c5b22016-05-18 11:27:45 +01001590 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch257744e2011-11-30 15:57:28 +00001591 __ lw(a1, MemOperand(at));
Ben Murdoch257744e2011-11-30 15:57:28 +00001592
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001593 // 3. Shift arguments and return address one slot down on the stack
Ben Murdoch257744e2011-11-30 15:57:28 +00001594 // (overwriting the original receiver). Adjust argument count to make
1595 // the original first argument the new receiver.
1596 // a0: actual number of arguments
1597 // a1: function
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001598 {
1599 Label loop;
Ben Murdoch257744e2011-11-30 15:57:28 +00001600 // Calculate the copy start address (destination). Copy end address is sp.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001601 __ Lsa(a2, sp, a0, kPointerSizeLog2);
Ben Murdoch257744e2011-11-30 15:57:28 +00001602
1603 __ bind(&loop);
1604 __ lw(at, MemOperand(a2, -kPointerSize));
1605 __ sw(at, MemOperand(a2));
1606 __ Subu(a2, a2, Operand(kPointerSize));
1607 __ Branch(&loop, ne, a2, Operand(sp));
1608 // Adjust the actual number of arguments and remove the top element
1609 // (which is a copy of the last argument).
1610 __ Subu(a0, a0, Operand(1));
1611 __ Pop();
1612 }
1613
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001614 // 4. Call the callable.
1615 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
Andrei Popescu31002712010-02-23 13:46:05 +00001616}
1617
1618
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001619void Builtins::Generate_ReflectApply(MacroAssembler* masm) {
1620 // ----------- S t a t e -------------
1621 // -- a0 : argc
1622 // -- sp[0] : argumentsList
1623 // -- sp[4] : thisArgument
1624 // -- sp[8] : target
1625 // -- sp[12] : receiver
1626 // -----------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001627
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001628 // 1. Load target into a1 (if present), argumentsList into a0 (if present),
1629 // remove all arguments from the stack (including the receiver), and push
1630 // thisArgument (if present) instead.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001631 {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001632 Label no_arg;
1633 Register scratch = t0;
1634 __ LoadRoot(a1, Heap::kUndefinedValueRootIndex);
1635 __ mov(a2, a1);
1636 __ mov(a3, a1);
1637 __ sll(scratch, a0, kPointerSizeLog2);
1638 __ mov(a0, scratch);
1639 __ Subu(a0, a0, Operand(kPointerSize));
1640 __ Branch(&no_arg, lt, a0, Operand(zero_reg));
1641 __ Addu(a0, sp, Operand(a0));
1642 __ lw(a1, MemOperand(a0)); // target
1643 __ Subu(a0, a0, Operand(kPointerSize));
1644 __ Branch(&no_arg, lt, a0, Operand(sp));
1645 __ lw(a2, MemOperand(a0)); // thisArgument
1646 __ Subu(a0, a0, Operand(kPointerSize));
1647 __ Branch(&no_arg, lt, a0, Operand(sp));
1648 __ lw(a3, MemOperand(a0)); // argumentsList
1649 __ bind(&no_arg);
1650 __ Addu(sp, sp, Operand(scratch));
1651 __ sw(a2, MemOperand(sp));
1652 __ mov(a0, a3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001653 }
1654
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001655 // ----------- S t a t e -------------
1656 // -- a0 : argumentsList
1657 // -- a1 : target
1658 // -- sp[0] : thisArgument
1659 // -----------------------------------
1660
1661 // 2. Make sure the target is actually callable.
1662 Label target_not_callable;
1663 __ JumpIfSmi(a1, &target_not_callable);
1664 __ lw(t0, FieldMemOperand(a1, HeapObject::kMapOffset));
1665 __ lbu(t0, FieldMemOperand(t0, Map::kBitFieldOffset));
1666 __ And(t0, t0, Operand(1 << Map::kIsCallable));
1667 __ Branch(&target_not_callable, eq, t0, Operand(zero_reg));
1668
1669 // 3a. Apply the target to the given argumentsList (passing undefined for
1670 // new.target).
1671 __ LoadRoot(a3, Heap::kUndefinedValueRootIndex);
1672 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1673
1674 // 3b. The target is not callable, throw an appropriate TypeError.
1675 __ bind(&target_not_callable);
1676 {
1677 __ sw(a1, MemOperand(sp));
1678 __ TailCallRuntime(Runtime::kThrowApplyNonFunction);
1679 }
1680}
1681
1682
1683void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
1684 // ----------- S t a t e -------------
1685 // -- a0 : argc
1686 // -- sp[0] : new.target (optional)
1687 // -- sp[4] : argumentsList
1688 // -- sp[8] : target
1689 // -- sp[12] : receiver
1690 // -----------------------------------
1691
1692 // 1. Load target into a1 (if present), argumentsList into a0 (if present),
1693 // new.target into a3 (if present, otherwise use target), remove all
1694 // arguments from the stack (including the receiver), and push thisArgument
1695 // (if present) instead.
1696 {
1697 Label no_arg;
1698 Register scratch = t0;
1699 __ LoadRoot(a1, Heap::kUndefinedValueRootIndex);
1700 __ mov(a2, a1);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001701 // Lsa() cannot be used hare as scratch value used later.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001702 __ sll(scratch, a0, kPointerSizeLog2);
1703 __ Addu(a0, sp, Operand(scratch));
1704 __ sw(a2, MemOperand(a0)); // receiver
1705 __ Subu(a0, a0, Operand(kPointerSize));
1706 __ Branch(&no_arg, lt, a0, Operand(sp));
1707 __ lw(a1, MemOperand(a0)); // target
1708 __ mov(a3, a1); // new.target defaults to target
1709 __ Subu(a0, a0, Operand(kPointerSize));
1710 __ Branch(&no_arg, lt, a0, Operand(sp));
1711 __ lw(a2, MemOperand(a0)); // argumentsList
1712 __ Subu(a0, a0, Operand(kPointerSize));
1713 __ Branch(&no_arg, lt, a0, Operand(sp));
1714 __ lw(a3, MemOperand(a0)); // new.target
1715 __ bind(&no_arg);
1716 __ Addu(sp, sp, Operand(scratch));
1717 __ mov(a0, a2);
1718 }
1719
1720 // ----------- S t a t e -------------
1721 // -- a0 : argumentsList
1722 // -- a3 : new.target
1723 // -- a1 : target
1724 // -- sp[0] : receiver (undefined)
1725 // -----------------------------------
1726
1727 // 2. Make sure the target is actually a constructor.
1728 Label target_not_constructor;
1729 __ JumpIfSmi(a1, &target_not_constructor);
1730 __ lw(t0, FieldMemOperand(a1, HeapObject::kMapOffset));
1731 __ lbu(t0, FieldMemOperand(t0, Map::kBitFieldOffset));
1732 __ And(t0, t0, Operand(1 << Map::kIsConstructor));
1733 __ Branch(&target_not_constructor, eq, t0, Operand(zero_reg));
1734
1735 // 3. Make sure the target is actually a constructor.
1736 Label new_target_not_constructor;
1737 __ JumpIfSmi(a3, &new_target_not_constructor);
1738 __ lw(t0, FieldMemOperand(a3, HeapObject::kMapOffset));
1739 __ lbu(t0, FieldMemOperand(t0, Map::kBitFieldOffset));
1740 __ And(t0, t0, Operand(1 << Map::kIsConstructor));
1741 __ Branch(&new_target_not_constructor, eq, t0, Operand(zero_reg));
1742
1743 // 4a. Construct the target with the given new.target and argumentsList.
1744 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1745
1746 // 4b. The target is not a constructor, throw an appropriate TypeError.
1747 __ bind(&target_not_constructor);
1748 {
1749 __ sw(a1, MemOperand(sp));
1750 __ TailCallRuntime(Runtime::kThrowCalledNonCallable);
1751 }
1752
1753 // 4c. The new.target is not a constructor, throw an appropriate TypeError.
1754 __ bind(&new_target_not_constructor);
1755 {
1756 __ sw(a3, MemOperand(sp));
1757 __ TailCallRuntime(Runtime::kThrowCalledNonCallable);
1758 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001759}
1760
1761
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001762static void ArgumentAdaptorStackCheck(MacroAssembler* masm,
1763 Label* stack_overflow) {
1764 // ----------- S t a t e -------------
1765 // -- a0 : actual number of arguments
1766 // -- a1 : function (passed through to callee)
1767 // -- a2 : expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001768 // -- a3 : new target (passed through to callee)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001769 // -----------------------------------
1770 // Check the stack for overflow. We are not trying to catch
1771 // interruptions (e.g. debug break and preemption) here, so the "real stack
1772 // limit" is checked.
1773 __ LoadRoot(t1, Heap::kRealStackLimitRootIndex);
1774 // Make t1 the space we have left. The stack might already be overflowed
1775 // here which will cause t1 to become negative.
1776 __ subu(t1, sp, t1);
1777 // Check if the arguments will overflow the stack.
1778 __ sll(at, a2, kPointerSizeLog2);
1779 // Signed comparison.
1780 __ Branch(stack_overflow, le, t1, Operand(at));
1781}
1782
1783
Ben Murdoch257744e2011-11-30 15:57:28 +00001784static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
1785 __ sll(a0, a0, kSmiTagSize);
1786 __ li(t0, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1787 __ MultiPush(a0.bit() | a1.bit() | t0.bit() | fp.bit() | ra.bit());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001788 __ Addu(fp, sp,
1789 Operand(StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize));
Ben Murdoch257744e2011-11-30 15:57:28 +00001790}
1791
1792
1793static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
1794 // ----------- S t a t e -------------
1795 // -- v0 : result being passed through
1796 // -----------------------------------
1797 // Get the number of arguments passed (as a smi), tear down the frame and
1798 // then tear down the parameters.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001799 __ lw(a1, MemOperand(fp, -(StandardFrameConstants::kFixedFrameSizeFromFp +
1800 kPointerSize)));
Ben Murdoch257744e2011-11-30 15:57:28 +00001801 __ mov(sp, fp);
1802 __ MultiPop(fp.bit() | ra.bit());
Ben Murdoch097c5b22016-05-18 11:27:45 +01001803 __ Lsa(sp, sp, a1, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00001804 // Adjust for the receiver.
1805 __ Addu(sp, sp, Operand(kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +00001806}
1807
1808
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001809// static
1810void Builtins::Generate_Apply(MacroAssembler* masm) {
1811 // ----------- S t a t e -------------
1812 // -- a0 : argumentsList
1813 // -- a1 : target
1814 // -- a3 : new.target (checked to be constructor or undefined)
1815 // -- sp[0] : thisArgument
1816 // -----------------------------------
1817
1818 // Create the list of arguments from the array-like argumentsList.
1819 {
1820 Label create_arguments, create_array, create_runtime, done_create;
1821 __ JumpIfSmi(a0, &create_runtime);
1822
1823 // Load the map of argumentsList into a2.
1824 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
1825
1826 // Load native context into t0.
1827 __ lw(t0, NativeContextMemOperand());
1828
1829 // Check if argumentsList is an (unmodified) arguments object.
1830 __ lw(at, ContextMemOperand(t0, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1831 __ Branch(&create_arguments, eq, a2, Operand(at));
1832 __ lw(at, ContextMemOperand(t0, Context::STRICT_ARGUMENTS_MAP_INDEX));
1833 __ Branch(&create_arguments, eq, a2, Operand(at));
1834
1835 // Check if argumentsList is a fast JSArray.
1836 __ lw(v0, FieldMemOperand(a2, HeapObject::kMapOffset));
1837 __ lbu(v0, FieldMemOperand(v0, Map::kInstanceTypeOffset));
1838 __ Branch(&create_array, eq, v0, Operand(JS_ARRAY_TYPE));
1839
1840 // Ask the runtime to create the list (actually a FixedArray).
1841 __ bind(&create_runtime);
1842 {
1843 FrameScope scope(masm, StackFrame::INTERNAL);
1844 __ Push(a1, a3, a0);
1845 __ CallRuntime(Runtime::kCreateListFromArrayLike);
1846 __ mov(a0, v0);
1847 __ Pop(a1, a3);
1848 __ lw(a2, FieldMemOperand(v0, FixedArray::kLengthOffset));
1849 __ SmiUntag(a2);
1850 }
1851 __ Branch(&done_create);
1852
1853 // Try to create the list from an arguments object.
1854 __ bind(&create_arguments);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001855 __ lw(a2, FieldMemOperand(a0, JSArgumentsObject::kLengthOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001856 __ lw(t0, FieldMemOperand(a0, JSObject::kElementsOffset));
1857 __ lw(at, FieldMemOperand(t0, FixedArray::kLengthOffset));
1858 __ Branch(&create_runtime, ne, a2, Operand(at));
1859 __ SmiUntag(a2);
1860 __ mov(a0, t0);
1861 __ Branch(&done_create);
1862
1863 // Try to create the list from a JSArray object.
1864 __ bind(&create_array);
1865 __ lw(a2, FieldMemOperand(a2, Map::kBitField2Offset));
1866 __ DecodeField<Map::ElementsKindBits>(a2);
1867 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
1868 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
1869 STATIC_ASSERT(FAST_ELEMENTS == 2);
1870 __ Branch(&create_runtime, hi, a2, Operand(FAST_ELEMENTS));
1871 __ Branch(&create_runtime, eq, a2, Operand(FAST_HOLEY_SMI_ELEMENTS));
1872 __ lw(a2, FieldMemOperand(a0, JSArray::kLengthOffset));
1873 __ lw(a0, FieldMemOperand(a0, JSArray::kElementsOffset));
1874 __ SmiUntag(a2);
1875
1876 __ bind(&done_create);
1877 }
1878
1879 // Check for stack overflow.
1880 {
1881 // Check the stack for overflow. We are not trying to catch interruptions
1882 // (i.e. debug break and preemption) here, so check the "real stack limit".
1883 Label done;
1884 __ LoadRoot(t0, Heap::kRealStackLimitRootIndex);
1885 // Make ip the space we have left. The stack might already be overflowed
1886 // here which will cause ip to become negative.
1887 __ Subu(t0, sp, t0);
1888 // Check if the arguments will overflow the stack.
1889 __ sll(at, a2, kPointerSizeLog2);
1890 __ Branch(&done, gt, t0, Operand(at)); // Signed comparison.
1891 __ TailCallRuntime(Runtime::kThrowStackOverflow);
1892 __ bind(&done);
1893 }
1894
1895 // ----------- S t a t e -------------
1896 // -- a1 : target
1897 // -- a0 : args (a FixedArray built from argumentsList)
1898 // -- a2 : len (number of elements to push from args)
1899 // -- a3 : new.target (checked to be constructor or undefined)
1900 // -- sp[0] : thisArgument
1901 // -----------------------------------
1902
1903 // Push arguments onto the stack (thisArgument is already on the stack).
1904 {
1905 __ mov(t0, zero_reg);
1906 Label done, loop;
1907 __ bind(&loop);
1908 __ Branch(&done, eq, t0, Operand(a2));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001909 __ Lsa(at, a0, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001910 __ lw(at, FieldMemOperand(at, FixedArray::kHeaderSize));
1911 __ Push(at);
1912 __ Addu(t0, t0, Operand(1));
1913 __ Branch(&loop);
1914 __ bind(&done);
1915 __ Move(a0, t0);
1916 }
1917
1918 // Dispatch to Call or Construct depending on whether new.target is undefined.
1919 {
1920 Label construct;
1921 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
1922 __ Branch(&construct, ne, a3, Operand(at));
1923 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1924 __ bind(&construct);
1925 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
1926 }
1927}
1928
Ben Murdoch097c5b22016-05-18 11:27:45 +01001929namespace {
1930
1931// Drops top JavaScript frame and an arguments adaptor frame below it (if
1932// present) preserving all the arguments prepared for current call.
1933// Does nothing if debugger is currently active.
1934// ES6 14.6.3. PrepareForTailCall
1935//
1936// Stack structure for the function g() tail calling f():
1937//
1938// ------- Caller frame: -------
1939// | ...
1940// | g()'s arg M
1941// | ...
1942// | g()'s arg 1
1943// | g()'s receiver arg
1944// | g()'s caller pc
1945// ------- g()'s frame: -------
1946// | g()'s caller fp <- fp
1947// | g()'s context
1948// | function pointer: g
1949// | -------------------------
1950// | ...
1951// | ...
1952// | f()'s arg N
1953// | ...
1954// | f()'s arg 1
1955// | f()'s receiver arg <- sp (f()'s caller pc is not on the stack yet!)
1956// ----------------------
1957//
1958void PrepareForTailCall(MacroAssembler* masm, Register args_reg,
1959 Register scratch1, Register scratch2,
1960 Register scratch3) {
1961 DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3));
1962 Comment cmnt(masm, "[ PrepareForTailCall");
1963
Ben Murdochda12d292016-06-02 14:46:10 +01001964 // Prepare for tail call only if ES2015 tail call elimination is enabled.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001965 Label done;
Ben Murdochda12d292016-06-02 14:46:10 +01001966 ExternalReference is_tail_call_elimination_enabled =
1967 ExternalReference::is_tail_call_elimination_enabled_address(
1968 masm->isolate());
1969 __ li(at, Operand(is_tail_call_elimination_enabled));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001970 __ lb(scratch1, MemOperand(at));
Ben Murdochda12d292016-06-02 14:46:10 +01001971 __ Branch(&done, eq, scratch1, Operand(zero_reg));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001972
1973 // Drop possible interpreter handler/stub frame.
1974 {
1975 Label no_interpreter_frame;
Ben Murdochda12d292016-06-02 14:46:10 +01001976 __ lw(scratch3,
1977 MemOperand(fp, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001978 __ Branch(&no_interpreter_frame, ne, scratch3,
1979 Operand(Smi::FromInt(StackFrame::STUB)));
1980 __ lw(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1981 __ bind(&no_interpreter_frame);
1982 }
1983
1984 // Check if next frame is an arguments adaptor frame.
Ben Murdochda12d292016-06-02 14:46:10 +01001985 Register caller_args_count_reg = scratch1;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001986 Label no_arguments_adaptor, formal_parameter_count_loaded;
1987 __ lw(scratch2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01001988 __ lw(scratch3,
1989 MemOperand(scratch2, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001990 __ Branch(&no_arguments_adaptor, ne, scratch3,
1991 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1992
Ben Murdochda12d292016-06-02 14:46:10 +01001993 // Drop current frame and load arguments count from arguments adaptor frame.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001994 __ mov(fp, scratch2);
Ben Murdochda12d292016-06-02 14:46:10 +01001995 __ lw(caller_args_count_reg,
Ben Murdoch097c5b22016-05-18 11:27:45 +01001996 MemOperand(fp, ArgumentsAdaptorFrameConstants::kLengthOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01001997 __ SmiUntag(caller_args_count_reg);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001998 __ Branch(&formal_parameter_count_loaded);
1999
2000 __ bind(&no_arguments_adaptor);
2001 // Load caller's formal parameter count
Ben Murdochda12d292016-06-02 14:46:10 +01002002 __ lw(scratch1,
2003 MemOperand(fp, ArgumentsAdaptorFrameConstants::kFunctionOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002004 __ lw(scratch1,
2005 FieldMemOperand(scratch1, JSFunction::kSharedFunctionInfoOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01002006 __ lw(caller_args_count_reg,
Ben Murdoch097c5b22016-05-18 11:27:45 +01002007 FieldMemOperand(scratch1,
2008 SharedFunctionInfo::kFormalParameterCountOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01002009 __ SmiUntag(caller_args_count_reg);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002010
2011 __ bind(&formal_parameter_count_loaded);
2012
Ben Murdochda12d292016-06-02 14:46:10 +01002013 ParameterCount callee_args_count(args_reg);
2014 __ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2,
2015 scratch3);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002016 __ bind(&done);
2017}
2018} // namespace
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002019
2020// static
2021void Builtins::Generate_CallFunction(MacroAssembler* masm,
Ben Murdoch097c5b22016-05-18 11:27:45 +01002022 ConvertReceiverMode mode,
2023 TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002024 // ----------- S t a t e -------------
2025 // -- a0 : the number of arguments (not including the receiver)
2026 // -- a1 : the function to call (checked to be a JSFunction)
2027 // -----------------------------------
2028 __ AssertFunction(a1);
2029
2030 // See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
2031 // Check that the function is not a "classConstructor".
2032 Label class_constructor;
2033 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2034 __ lbu(a3, FieldMemOperand(a2, SharedFunctionInfo::kFunctionKindByteOffset));
2035 __ And(at, a3, Operand(SharedFunctionInfo::kClassConstructorBitsWithinByte));
2036 __ Branch(&class_constructor, ne, at, Operand(zero_reg));
2037
2038 // Enter the context of the function; ToObject has to run in the function
2039 // context, and we also need to take the global proxy from the function
2040 // context in case of conversion.
2041 STATIC_ASSERT(SharedFunctionInfo::kNativeByteOffset ==
2042 SharedFunctionInfo::kStrictModeByteOffset);
2043 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2044 // We need to convert the receiver for non-native sloppy mode functions.
2045 Label done_convert;
2046 __ lbu(a3, FieldMemOperand(a2, SharedFunctionInfo::kNativeByteOffset));
2047 __ And(at, a3, Operand((1 << SharedFunctionInfo::kNativeBitWithinByte) |
2048 (1 << SharedFunctionInfo::kStrictModeBitWithinByte)));
2049 __ Branch(&done_convert, ne, at, Operand(zero_reg));
2050 {
2051 // ----------- S t a t e -------------
2052 // -- a0 : the number of arguments (not including the receiver)
2053 // -- a1 : the function to call (checked to be a JSFunction)
2054 // -- a2 : the shared function info.
2055 // -- cp : the function context.
2056 // -----------------------------------
2057
2058 if (mode == ConvertReceiverMode::kNullOrUndefined) {
2059 // Patch receiver to global proxy.
2060 __ LoadGlobalProxy(a3);
2061 } else {
2062 Label convert_to_object, convert_receiver;
Ben Murdoch097c5b22016-05-18 11:27:45 +01002063 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002064 __ lw(a3, MemOperand(at));
2065 __ JumpIfSmi(a3, &convert_to_object);
2066 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
2067 __ GetObjectType(a3, t0, t0);
2068 __ Branch(&done_convert, hs, t0, Operand(FIRST_JS_RECEIVER_TYPE));
2069 if (mode != ConvertReceiverMode::kNotNullOrUndefined) {
2070 Label convert_global_proxy;
2071 __ JumpIfRoot(a3, Heap::kUndefinedValueRootIndex,
2072 &convert_global_proxy);
2073 __ JumpIfNotRoot(a3, Heap::kNullValueRootIndex, &convert_to_object);
2074 __ bind(&convert_global_proxy);
2075 {
2076 // Patch receiver to global proxy.
2077 __ LoadGlobalProxy(a3);
2078 }
2079 __ Branch(&convert_receiver);
2080 }
2081 __ bind(&convert_to_object);
2082 {
2083 // Convert receiver using ToObject.
2084 // TODO(bmeurer): Inline the allocation here to avoid building the frame
2085 // in the fast case? (fall back to AllocateInNewSpace?)
2086 FrameScope scope(masm, StackFrame::INTERNAL);
2087 __ sll(a0, a0, kSmiTagSize); // Smi tagged.
2088 __ Push(a0, a1);
2089 __ mov(a0, a3);
2090 ToObjectStub stub(masm->isolate());
2091 __ CallStub(&stub);
2092 __ mov(a3, v0);
2093 __ Pop(a0, a1);
2094 __ sra(a0, a0, kSmiTagSize); // Un-tag.
2095 }
2096 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2097 __ bind(&convert_receiver);
2098 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002099 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002100 __ sw(a3, MemOperand(at));
2101 }
2102 __ bind(&done_convert);
2103
2104 // ----------- S t a t e -------------
2105 // -- a0 : the number of arguments (not including the receiver)
2106 // -- a1 : the function to call (checked to be a JSFunction)
2107 // -- a2 : the shared function info.
2108 // -- cp : the function context.
2109 // -----------------------------------
2110
Ben Murdoch097c5b22016-05-18 11:27:45 +01002111 if (tail_call_mode == TailCallMode::kAllow) {
2112 PrepareForTailCall(masm, a0, t0, t1, t2);
2113 }
2114
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002115 __ lw(a2,
2116 FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
2117 __ sra(a2, a2, kSmiTagSize); // Un-tag.
2118 ParameterCount actual(a0);
2119 ParameterCount expected(a2);
2120 __ InvokeFunctionCode(a1, no_reg, expected, actual, JUMP_FUNCTION,
2121 CheckDebugStepCallWrapper());
2122
2123 // The function is a "classConstructor", need to raise an exception.
2124 __ bind(&class_constructor);
2125 {
2126 FrameScope frame(masm, StackFrame::INTERNAL);
2127 __ Push(a1);
2128 __ CallRuntime(Runtime::kThrowConstructorNonCallableError);
2129 }
2130}
2131
2132
2133// static
Ben Murdoch097c5b22016-05-18 11:27:45 +01002134void Builtins::Generate_CallBoundFunctionImpl(MacroAssembler* masm,
2135 TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002136 // ----------- S t a t e -------------
2137 // -- a0 : the number of arguments (not including the receiver)
2138 // -- a1 : the function to call (checked to be a JSBoundFunction)
2139 // -----------------------------------
2140 __ AssertBoundFunction(a1);
2141
Ben Murdoch097c5b22016-05-18 11:27:45 +01002142 if (tail_call_mode == TailCallMode::kAllow) {
2143 PrepareForTailCall(masm, a0, t0, t1, t2);
2144 }
2145
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002146 // Patch the receiver to [[BoundThis]].
2147 {
2148 __ lw(at, FieldMemOperand(a1, JSBoundFunction::kBoundThisOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002149 __ Lsa(t0, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002150 __ sw(at, MemOperand(t0));
2151 }
2152
2153 // Load [[BoundArguments]] into a2 and length of that into t0.
2154 __ lw(a2, FieldMemOperand(a1, JSBoundFunction::kBoundArgumentsOffset));
2155 __ lw(t0, FieldMemOperand(a2, FixedArray::kLengthOffset));
2156 __ SmiUntag(t0);
2157
2158 // ----------- S t a t e -------------
2159 // -- a0 : the number of arguments (not including the receiver)
2160 // -- a1 : the function to call (checked to be a JSBoundFunction)
2161 // -- a2 : the [[BoundArguments]] (implemented as FixedArray)
2162 // -- t0 : the number of [[BoundArguments]]
2163 // -----------------------------------
2164
2165 // Reserve stack space for the [[BoundArguments]].
2166 {
2167 Label done;
2168 __ sll(t1, t0, kPointerSizeLog2);
2169 __ Subu(sp, sp, Operand(t1));
2170 // Check the stack for overflow. We are not trying to catch interruptions
2171 // (i.e. debug break and preemption) here, so check the "real stack limit".
2172 __ LoadRoot(at, Heap::kRealStackLimitRootIndex);
2173 __ Branch(&done, gt, sp, Operand(at)); // Signed comparison.
2174 // Restore the stack pointer.
2175 __ Addu(sp, sp, Operand(t1));
2176 {
2177 FrameScope scope(masm, StackFrame::MANUAL);
2178 __ EnterFrame(StackFrame::INTERNAL);
2179 __ CallRuntime(Runtime::kThrowStackOverflow);
2180 }
2181 __ bind(&done);
2182 }
2183
2184 // Relocate arguments down the stack.
2185 {
2186 Label loop, done_loop;
2187 __ mov(t1, zero_reg);
2188 __ bind(&loop);
2189 __ Branch(&done_loop, gt, t1, Operand(a0));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002190 __ Lsa(t2, sp, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002191 __ lw(at, MemOperand(t2));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002192 __ Lsa(t2, sp, t1, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002193 __ sw(at, MemOperand(t2));
2194 __ Addu(t0, t0, Operand(1));
2195 __ Addu(t1, t1, Operand(1));
2196 __ Branch(&loop);
2197 __ bind(&done_loop);
2198 }
2199
2200 // Copy [[BoundArguments]] to the stack (below the arguments).
2201 {
2202 Label loop, done_loop;
2203 __ lw(t0, FieldMemOperand(a2, FixedArray::kLengthOffset));
2204 __ SmiUntag(t0);
2205 __ Addu(a2, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2206 __ bind(&loop);
2207 __ Subu(t0, t0, Operand(1));
2208 __ Branch(&done_loop, lt, t0, Operand(zero_reg));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002209 __ Lsa(t1, a2, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002210 __ lw(at, MemOperand(t1));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002211 __ Lsa(t1, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002212 __ sw(at, MemOperand(t1));
2213 __ Addu(a0, a0, Operand(1));
2214 __ Branch(&loop);
2215 __ bind(&done_loop);
2216 }
2217
2218 // Call the [[BoundTargetFunction]] via the Call builtin.
2219 __ lw(a1, FieldMemOperand(a1, JSBoundFunction::kBoundTargetFunctionOffset));
2220 __ li(at, Operand(ExternalReference(Builtins::kCall_ReceiverIsAny,
2221 masm->isolate())));
2222 __ lw(at, MemOperand(at));
2223 __ Addu(at, at, Operand(Code::kHeaderSize - kHeapObjectTag));
2224 __ Jump(at);
2225}
2226
2227
2228// static
Ben Murdoch097c5b22016-05-18 11:27:45 +01002229void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode,
2230 TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002231 // ----------- S t a t e -------------
2232 // -- a0 : the number of arguments (not including the receiver)
2233 // -- a1 : the target to call (can be any Object).
2234 // -----------------------------------
2235
2236 Label non_callable, non_function, non_smi;
2237 __ JumpIfSmi(a1, &non_callable);
2238 __ bind(&non_smi);
2239 __ GetObjectType(a1, t1, t2);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002240 __ Jump(masm->isolate()->builtins()->CallFunction(mode, tail_call_mode),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002241 RelocInfo::CODE_TARGET, eq, t2, Operand(JS_FUNCTION_TYPE));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002242 __ Jump(masm->isolate()->builtins()->CallBoundFunction(tail_call_mode),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002243 RelocInfo::CODE_TARGET, eq, t2, Operand(JS_BOUND_FUNCTION_TYPE));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002244
2245 // Check if target has a [[Call]] internal method.
2246 __ lbu(t1, FieldMemOperand(t1, Map::kBitFieldOffset));
2247 __ And(t1, t1, Operand(1 << Map::kIsCallable));
2248 __ Branch(&non_callable, eq, t1, Operand(zero_reg));
2249
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002250 __ Branch(&non_function, ne, t2, Operand(JS_PROXY_TYPE));
2251
Ben Murdoch097c5b22016-05-18 11:27:45 +01002252 // 0. Prepare for tail call if necessary.
2253 if (tail_call_mode == TailCallMode::kAllow) {
2254 PrepareForTailCall(masm, a0, t0, t1, t2);
2255 }
2256
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002257 // 1. Runtime fallback for Proxy [[Call]].
2258 __ Push(a1);
2259 // Increase the arguments size to include the pushed function and the
2260 // existing receiver on the stack.
2261 __ Addu(a0, a0, 2);
2262 // Tail-call to the runtime.
2263 __ JumpToExternalReference(
2264 ExternalReference(Runtime::kJSProxyCall, masm->isolate()));
2265
2266 // 2. Call to something else, which might have a [[Call]] internal method (if
2267 // not we raise an exception).
2268 __ bind(&non_function);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002269 // Overwrite the original receiver with the (original) target.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002270 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002271 __ sw(a1, MemOperand(at));
2272 // Let the "call_as_function_delegate" take care of the rest.
2273 __ LoadNativeContextSlot(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, a1);
2274 __ Jump(masm->isolate()->builtins()->CallFunction(
Ben Murdoch097c5b22016-05-18 11:27:45 +01002275 ConvertReceiverMode::kNotNullOrUndefined, tail_call_mode),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002276 RelocInfo::CODE_TARGET);
2277
2278 // 3. Call to something that is not callable.
2279 __ bind(&non_callable);
2280 {
2281 FrameScope scope(masm, StackFrame::INTERNAL);
2282 __ Push(a1);
2283 __ CallRuntime(Runtime::kThrowCalledNonCallable);
2284 }
2285}
2286
2287
2288// static
2289void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
2290 // ----------- S t a t e -------------
2291 // -- a0 : the number of arguments (not including the receiver)
2292 // -- a1 : the constructor to call (checked to be a JSFunction)
2293 // -- a3 : the new target (checked to be a constructor)
2294 // -----------------------------------
2295 __ AssertFunction(a1);
2296
2297 // Calling convention for function specific ConstructStubs require
2298 // a2 to contain either an AllocationSite or undefined.
2299 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2300
2301 // Tail call to the function-specific construct stub (still in the caller
2302 // context at this point).
2303 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2304 __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset));
2305 __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag));
2306 __ Jump(at);
2307}
2308
2309
2310// static
2311void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) {
2312 // ----------- S t a t e -------------
2313 // -- a0 : the number of arguments (not including the receiver)
2314 // -- a1 : the function to call (checked to be a JSBoundFunction)
2315 // -- a3 : the new target (checked to be a constructor)
2316 // -----------------------------------
2317 __ AssertBoundFunction(a1);
2318
2319 // Load [[BoundArguments]] into a2 and length of that into t0.
2320 __ lw(a2, FieldMemOperand(a1, JSBoundFunction::kBoundArgumentsOffset));
2321 __ lw(t0, FieldMemOperand(a2, FixedArray::kLengthOffset));
2322 __ SmiUntag(t0);
2323
2324 // ----------- S t a t e -------------
2325 // -- a0 : the number of arguments (not including the receiver)
2326 // -- a1 : the function to call (checked to be a JSBoundFunction)
2327 // -- a2 : the [[BoundArguments]] (implemented as FixedArray)
2328 // -- a3 : the new target (checked to be a constructor)
2329 // -- t0 : the number of [[BoundArguments]]
2330 // -----------------------------------
2331
2332 // Reserve stack space for the [[BoundArguments]].
2333 {
2334 Label done;
2335 __ sll(t1, t0, kPointerSizeLog2);
2336 __ Subu(sp, sp, Operand(t1));
2337 // Check the stack for overflow. We are not trying to catch interruptions
2338 // (i.e. debug break and preemption) here, so check the "real stack limit".
2339 __ LoadRoot(at, Heap::kRealStackLimitRootIndex);
2340 __ Branch(&done, gt, sp, Operand(at)); // Signed comparison.
2341 // Restore the stack pointer.
2342 __ Addu(sp, sp, Operand(t1));
2343 {
2344 FrameScope scope(masm, StackFrame::MANUAL);
2345 __ EnterFrame(StackFrame::INTERNAL);
2346 __ CallRuntime(Runtime::kThrowStackOverflow);
2347 }
2348 __ bind(&done);
2349 }
2350
2351 // Relocate arguments down the stack.
2352 {
2353 Label loop, done_loop;
2354 __ mov(t1, zero_reg);
2355 __ bind(&loop);
2356 __ Branch(&done_loop, ge, t1, Operand(a0));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002357 __ Lsa(t2, sp, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002358 __ lw(at, MemOperand(t2));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002359 __ Lsa(t2, sp, t1, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002360 __ sw(at, MemOperand(t2));
2361 __ Addu(t0, t0, Operand(1));
2362 __ Addu(t1, t1, Operand(1));
2363 __ Branch(&loop);
2364 __ bind(&done_loop);
2365 }
2366
2367 // Copy [[BoundArguments]] to the stack (below the arguments).
2368 {
2369 Label loop, done_loop;
2370 __ lw(t0, FieldMemOperand(a2, FixedArray::kLengthOffset));
2371 __ SmiUntag(t0);
2372 __ Addu(a2, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2373 __ bind(&loop);
2374 __ Subu(t0, t0, Operand(1));
2375 __ Branch(&done_loop, lt, t0, Operand(zero_reg));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002376 __ Lsa(t1, a2, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002377 __ lw(at, MemOperand(t1));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002378 __ Lsa(t1, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002379 __ sw(at, MemOperand(t1));
2380 __ Addu(a0, a0, Operand(1));
2381 __ Branch(&loop);
2382 __ bind(&done_loop);
2383 }
2384
2385 // Patch new.target to [[BoundTargetFunction]] if new.target equals target.
2386 {
2387 Label skip_load;
2388 __ Branch(&skip_load, ne, a1, Operand(a3));
2389 __ lw(a3, FieldMemOperand(a1, JSBoundFunction::kBoundTargetFunctionOffset));
2390 __ bind(&skip_load);
2391 }
2392
2393 // Construct the [[BoundTargetFunction]] via the Construct builtin.
2394 __ lw(a1, FieldMemOperand(a1, JSBoundFunction::kBoundTargetFunctionOffset));
2395 __ li(at, Operand(ExternalReference(Builtins::kConstruct, masm->isolate())));
2396 __ lw(at, MemOperand(at));
2397 __ Addu(at, at, Operand(Code::kHeaderSize - kHeapObjectTag));
2398 __ Jump(at);
2399}
2400
2401
2402// static
2403void Builtins::Generate_ConstructProxy(MacroAssembler* masm) {
2404 // ----------- S t a t e -------------
2405 // -- a0 : the number of arguments (not including the receiver)
2406 // -- a1 : the constructor to call (checked to be a JSProxy)
2407 // -- a3 : the new target (either the same as the constructor or
2408 // the JSFunction on which new was invoked initially)
2409 // -----------------------------------
2410
2411 // Call into the Runtime for Proxy [[Construct]].
2412 __ Push(a1, a3);
2413 // Include the pushed new_target, constructor and the receiver.
2414 __ Addu(a0, a0, Operand(3));
2415 // Tail-call to the runtime.
2416 __ JumpToExternalReference(
2417 ExternalReference(Runtime::kJSProxyConstruct, masm->isolate()));
2418}
2419
2420
2421// static
2422void Builtins::Generate_Construct(MacroAssembler* masm) {
2423 // ----------- S t a t e -------------
2424 // -- a0 : the number of arguments (not including the receiver)
2425 // -- a1 : the constructor to call (can be any Object)
2426 // -- a3 : the new target (either the same as the constructor or
2427 // the JSFunction on which new was invoked initially)
2428 // -----------------------------------
2429
2430 // Check if target is a Smi.
2431 Label non_constructor;
2432 __ JumpIfSmi(a1, &non_constructor);
2433
2434 // Dispatch based on instance type.
2435 __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset));
2436 __ lbu(t2, FieldMemOperand(t1, Map::kInstanceTypeOffset));
2437 __ Jump(masm->isolate()->builtins()->ConstructFunction(),
2438 RelocInfo::CODE_TARGET, eq, t2, Operand(JS_FUNCTION_TYPE));
2439
2440 // Check if target has a [[Construct]] internal method.
2441 __ lbu(t3, FieldMemOperand(t1, Map::kBitFieldOffset));
2442 __ And(t3, t3, Operand(1 << Map::kIsConstructor));
2443 __ Branch(&non_constructor, eq, t3, Operand(zero_reg));
2444
2445 // Only dispatch to bound functions after checking whether they are
2446 // constructors.
2447 __ Jump(masm->isolate()->builtins()->ConstructBoundFunction(),
2448 RelocInfo::CODE_TARGET, eq, t2, Operand(JS_BOUND_FUNCTION_TYPE));
2449
2450 // Only dispatch to proxies after checking whether they are constructors.
2451 __ Jump(masm->isolate()->builtins()->ConstructProxy(), RelocInfo::CODE_TARGET,
2452 eq, t2, Operand(JS_PROXY_TYPE));
2453
2454 // Called Construct on an exotic Object with a [[Construct]] internal method.
2455 {
2456 // Overwrite the original receiver with the (original) target.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002457 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002458 __ sw(a1, MemOperand(at));
2459 // Let the "call_as_constructor_delegate" take care of the rest.
2460 __ LoadNativeContextSlot(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, a1);
2461 __ Jump(masm->isolate()->builtins()->CallFunction(),
2462 RelocInfo::CODE_TARGET);
2463 }
2464
2465 // Called Construct on an Object that doesn't have a [[Construct]] internal
2466 // method.
2467 __ bind(&non_constructor);
2468 __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(),
2469 RelocInfo::CODE_TARGET);
2470}
2471
2472
Andrei Popescu31002712010-02-23 13:46:05 +00002473void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002474 // State setup as expected by MacroAssembler::InvokePrologue.
2475 // ----------- S t a t e -------------
2476 // -- a0: actual arguments count
2477 // -- a1: function (passed through to callee)
2478 // -- a2: expected arguments count
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002479 // -- a3: new target (passed through to callee)
Ben Murdoch257744e2011-11-30 15:57:28 +00002480 // -----------------------------------
2481
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002482 Label invoke, dont_adapt_arguments, stack_overflow;
Ben Murdoch257744e2011-11-30 15:57:28 +00002483
2484 Label enough, too_few;
2485 __ Branch(&dont_adapt_arguments, eq,
2486 a2, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
2487 // We use Uless as the number of argument should always be greater than 0.
2488 __ Branch(&too_few, Uless, a0, Operand(a2));
2489
2490 { // Enough parameters: actual >= expected.
2491 // a0: actual number of arguments as a smi
2492 // a1: function
2493 // a2: expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002494 // a3: new target (passed through to callee)
Ben Murdoch257744e2011-11-30 15:57:28 +00002495 __ bind(&enough);
2496 EnterArgumentsAdaptorFrame(masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002497 ArgumentAdaptorStackCheck(masm, &stack_overflow);
Ben Murdoch257744e2011-11-30 15:57:28 +00002498
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002499 // Calculate copy start address into a0 and copy end address into t1.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002500 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002501 // Adjust for return address and receiver.
2502 __ Addu(a0, a0, Operand(2 * kPointerSize));
2503 // Compute copy end address.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002504 __ sll(t1, a2, kPointerSizeLog2);
2505 __ subu(t1, a0, t1);
Ben Murdoch257744e2011-11-30 15:57:28 +00002506
2507 // Copy the arguments (including the receiver) to the new stack frame.
2508 // a0: copy start address
2509 // a1: function
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002510 // a2: expected number of arguments
2511 // a3: new target (passed through to callee)
2512 // t1: copy end address
Ben Murdoch257744e2011-11-30 15:57:28 +00002513
2514 Label copy;
2515 __ bind(&copy);
2516 __ lw(t0, MemOperand(a0));
2517 __ push(t0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002518 __ Branch(USE_DELAY_SLOT, &copy, ne, a0, Operand(t1));
Ben Murdoch257744e2011-11-30 15:57:28 +00002519 __ addiu(a0, a0, -kPointerSize); // In delay slot.
2520
2521 __ jmp(&invoke);
2522 }
2523
2524 { // Too few parameters: Actual < expected.
2525 __ bind(&too_few);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002526 EnterArgumentsAdaptorFrame(masm);
2527 ArgumentAdaptorStackCheck(masm, &stack_overflow);
2528
2529 // Calculate copy start address into a0 and copy end address into t3.
Ben Murdoch257744e2011-11-30 15:57:28 +00002530 // a0: actual number of arguments as a smi
2531 // a1: function
2532 // a2: expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002533 // a3: new target (passed through to callee)
Ben Murdoch097c5b22016-05-18 11:27:45 +01002534 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002535 // Adjust for return address and receiver.
2536 __ Addu(a0, a0, Operand(2 * kPointerSize));
2537 // Compute copy end address. Also adjust for return address.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002538 __ Addu(t3, fp, kPointerSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002539
2540 // Copy the arguments (including the receiver) to the new stack frame.
2541 // a0: copy start address
2542 // a1: function
2543 // a2: expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002544 // a3: new target (passed through to callee)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002545 // t3: copy end address
Ben Murdoch257744e2011-11-30 15:57:28 +00002546 Label copy;
2547 __ bind(&copy);
2548 __ lw(t0, MemOperand(a0)); // Adjusted above for return addr and receiver.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002549 __ Subu(sp, sp, kPointerSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002550 __ Subu(a0, a0, kPointerSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002551 __ Branch(USE_DELAY_SLOT, &copy, ne, a0, Operand(t3));
2552 __ sw(t0, MemOperand(sp)); // In the delay slot.
Ben Murdoch257744e2011-11-30 15:57:28 +00002553
2554 // Fill the remaining expected arguments with undefined.
2555 // a1: function
2556 // a2: expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002557 // a3: new target (passed through to callee)
Ben Murdoch257744e2011-11-30 15:57:28 +00002558 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
2559 __ sll(t2, a2, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002560 __ Subu(t1, fp, Operand(t2));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002561 // Adjust for frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002562 __ Subu(t1, t1, Operand(StandardFrameConstants::kFixedFrameSizeFromFp +
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002563 2 * kPointerSize));
Ben Murdoch257744e2011-11-30 15:57:28 +00002564
2565 Label fill;
2566 __ bind(&fill);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002567 __ Subu(sp, sp, kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002568 __ Branch(USE_DELAY_SLOT, &fill, ne, sp, Operand(t1));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002569 __ sw(t0, MemOperand(sp));
Ben Murdoch257744e2011-11-30 15:57:28 +00002570 }
2571
2572 // Call the entry point.
2573 __ bind(&invoke);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002574 __ mov(a0, a2);
2575 // a0 : expected number of arguments
2576 // a1 : function (passed through to callee)
2577 // a3 : new target (passed through to callee)
2578 __ lw(t0, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2579 __ Call(t0);
Ben Murdoch257744e2011-11-30 15:57:28 +00002580
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002581 // Store offset of return address for deoptimizer.
2582 masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset());
2583
Ben Murdoch257744e2011-11-30 15:57:28 +00002584 // Exit frame and return.
2585 LeaveArgumentsAdaptorFrame(masm);
2586 __ Ret();
2587
2588
2589 // -------------------------------------------
2590 // Don't adapt arguments.
2591 // -------------------------------------------
2592 __ bind(&dont_adapt_arguments);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002593 __ lw(t0, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2594 __ Jump(t0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002595
2596 __ bind(&stack_overflow);
2597 {
2598 FrameScope frame(masm, StackFrame::MANUAL);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002599 __ CallRuntime(Runtime::kThrowStackOverflow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002600 __ break_(0xCC);
2601 }
Andrei Popescu31002712010-02-23 13:46:05 +00002602}
2603
2604
2605#undef __
2606
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002607} // namespace internal
2608} // namespace v8
Andrei Popescu31002712010-02-23 13:46:05 +00002609
Leon Clarkef7060e22010-06-03 12:02:55 +01002610#endif // V8_TARGET_ARCH_MIPS