blob: 0671f990e8c5a6c1d48bf9d53541daf9be4277e7 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005#if V8_TARGET_ARCH_PPC
6
Ben Murdochda12d292016-06-02 14:46:10 +01007#include "src/code-stubs.h"
8#include "src/api-arguments.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009#include "src/base/bits.h"
10#include "src/bootstrapper.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040011#include "src/codegen.h"
12#include "src/ic/handler-compiler.h"
13#include "src/ic/ic.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000014#include "src/ic/stub-cache.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040015#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016#include "src/ppc/code-stubs-ppc.h"
17#include "src/regexp/jsregexp.h"
18#include "src/regexp/regexp-macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040019#include "src/runtime/runtime.h"
20
21namespace v8 {
22namespace internal {
23
24
25static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
28 Address deopt_handler =
29 Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
30
31 if (constant_stack_parameter_count == 0) {
32 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
33 JS_FUNCTION_STUB_MODE);
34 } else {
35 descriptor->Initialize(r3, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036 JS_FUNCTION_STUB_MODE);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040037 }
38}
39
40
41static void InitializeInternalArrayConstructorDescriptor(
42 Isolate* isolate, CodeStubDescriptor* descriptor,
43 int constant_stack_parameter_count) {
44 Address deopt_handler =
45 Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
46
47 if (constant_stack_parameter_count == 0) {
48 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
49 JS_FUNCTION_STUB_MODE);
50 } else {
51 descriptor->Initialize(r3, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052 JS_FUNCTION_STUB_MODE);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040053 }
54}
55
56
57void ArrayNoArgumentConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
60}
61
62
63void ArraySingleArgumentConstructorStub::InitializeDescriptor(
64 CodeStubDescriptor* descriptor) {
65 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
66}
67
68
69void ArrayNArgumentsConstructorStub::InitializeDescriptor(
70 CodeStubDescriptor* descriptor) {
71 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
72}
73
74
75void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
76 CodeStubDescriptor* descriptor) {
77 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
78}
79
Ben Murdochda12d292016-06-02 14:46:10 +010080void FastArrayPushStub::InitializeDescriptor(CodeStubDescriptor* descriptor) {
81 Address deopt_handler = Runtime::FunctionForId(Runtime::kArrayPush)->entry;
82 descriptor->Initialize(r3, deopt_handler, -1, JS_FUNCTION_STUB_MODE);
83}
Emily Bernierd0a1eb72015-03-24 16:35:39 -040084
85void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
86 CodeStubDescriptor* descriptor) {
87 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
88}
89
90
91void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
92 CodeStubDescriptor* descriptor) {
93 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
94}
95
96
97#define __ ACCESS_MASM(masm)
98
Emily Bernierd0a1eb72015-03-24 16:35:39 -040099static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100100 Condition cond);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400101static void EmitSmiNonsmiComparison(MacroAssembler* masm, Register lhs,
102 Register rhs, Label* lhs_not_nan,
103 Label* slow, bool strict);
104static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register lhs,
105 Register rhs);
106
107
108void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
109 ExternalReference miss) {
110 // Update the static counter each time a new code stub is generated.
111 isolate()->counters()->code_stubs()->Increment();
112
113 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000114 int param_count = descriptor.GetRegisterParameterCount();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400115 {
116 // Call the runtime system in a fresh internal frame.
117 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
118 DCHECK(param_count == 0 ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000119 r3.is(descriptor.GetRegisterParameter(param_count - 1)));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400120 // Push arguments
121 for (int i = 0; i < param_count; ++i) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000122 __ push(descriptor.GetRegisterParameter(i));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400123 }
124 __ CallExternalReference(miss, param_count);
125 }
126
127 __ Ret();
128}
129
130
131void DoubleToIStub::Generate(MacroAssembler* masm) {
132 Label out_of_range, only_low, negate, done, fastpath_done;
133 Register input_reg = source();
134 Register result_reg = destination();
135 DCHECK(is_truncating());
136
137 int double_offset = offset();
138
139 // Immediate values for this stub fit in instructions, so it's safe to use ip.
140 Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
141 Register scratch_low =
142 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
143 Register scratch_high =
144 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
145 DoubleRegister double_scratch = kScratchDoubleReg;
146
147 __ push(scratch);
148 // Account for saved regs if input is sp.
149 if (input_reg.is(sp)) double_offset += kPointerSize;
150
151 if (!skip_fastpath()) {
152 // Load double input.
153 __ lfd(double_scratch, MemOperand(input_reg, double_offset));
154
155 // Do fast-path convert from double to int.
156 __ ConvertDoubleToInt64(double_scratch,
157#if !V8_TARGET_ARCH_PPC64
158 scratch,
159#endif
160 result_reg, d0);
161
162// Test for overflow
163#if V8_TARGET_ARCH_PPC64
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000164 __ TestIfInt32(result_reg, r0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400165#else
166 __ TestIfInt32(scratch, result_reg, r0);
167#endif
168 __ beq(&fastpath_done);
169 }
170
171 __ Push(scratch_high, scratch_low);
172 // Account for saved regs if input is sp.
173 if (input_reg.is(sp)) double_offset += 2 * kPointerSize;
174
175 __ lwz(scratch_high,
176 MemOperand(input_reg, double_offset + Register::kExponentOffset));
177 __ lwz(scratch_low,
178 MemOperand(input_reg, double_offset + Register::kMantissaOffset));
179
180 __ ExtractBitMask(scratch, scratch_high, HeapNumber::kExponentMask);
181 // Load scratch with exponent - 1. This is faster than loading
182 // with exponent because Bias + 1 = 1024 which is a *PPC* immediate value.
183 STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
184 __ subi(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
185 // If exponent is greater than or equal to 84, the 32 less significant
186 // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
187 // the result is 0.
188 // Compare exponent with 84 (compare exponent - 1 with 83).
189 __ cmpi(scratch, Operand(83));
190 __ bge(&out_of_range);
191
192 // If we reach this code, 31 <= exponent <= 83.
193 // So, we don't have to handle cases where 0 <= exponent <= 20 for
194 // which we would need to shift right the high part of the mantissa.
195 // Scratch contains exponent - 1.
196 // Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
197 __ subfic(scratch, scratch, Operand(51));
198 __ cmpi(scratch, Operand::Zero());
199 __ ble(&only_low);
200 // 21 <= exponent <= 51, shift scratch_low and scratch_high
201 // to generate the result.
202 __ srw(scratch_low, scratch_low, scratch);
203 // Scratch contains: 52 - exponent.
204 // We needs: exponent - 20.
205 // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
206 __ subfic(scratch, scratch, Operand(32));
207 __ ExtractBitMask(result_reg, scratch_high, HeapNumber::kMantissaMask);
208 // Set the implicit 1 before the mantissa part in scratch_high.
209 STATIC_ASSERT(HeapNumber::kMantissaBitsInTopWord >= 16);
210 __ oris(result_reg, result_reg,
211 Operand(1 << ((HeapNumber::kMantissaBitsInTopWord) - 16)));
212 __ slw(r0, result_reg, scratch);
213 __ orx(result_reg, scratch_low, r0);
214 __ b(&negate);
215
216 __ bind(&out_of_range);
217 __ mov(result_reg, Operand::Zero());
218 __ b(&done);
219
220 __ bind(&only_low);
221 // 52 <= exponent <= 83, shift only scratch_low.
222 // On entry, scratch contains: 52 - exponent.
223 __ neg(scratch, scratch);
224 __ slw(result_reg, scratch_low, scratch);
225
226 __ bind(&negate);
227 // If input was positive, scratch_high ASR 31 equals 0 and
228 // scratch_high LSR 31 equals zero.
229 // New result = (result eor 0) + 0 = result.
230 // If the input was negative, we have to negate the result.
231 // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
232 // New result = (result eor 0xffffffff) + 1 = 0 - result.
233 __ srawi(r0, scratch_high, 31);
234#if V8_TARGET_ARCH_PPC64
235 __ srdi(r0, r0, Operand(32));
236#endif
237 __ xor_(result_reg, result_reg, r0);
238 __ srwi(r0, scratch_high, Operand(31));
239 __ add(result_reg, result_reg, r0);
240
241 __ bind(&done);
242 __ Pop(scratch_high, scratch_low);
243
244 __ bind(&fastpath_done);
245 __ pop(scratch);
246
247 __ Ret();
248}
249
250
251// Handle the case where the lhs and rhs are the same object.
252// Equality is almost reflexive (everything but NaN), so this is a test
253// for "identity and not NaN".
254static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100255 Condition cond) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400256 Label not_identical;
257 Label heap_number, return_equal;
258 __ cmp(r3, r4);
259 __ bne(&not_identical);
260
261 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
262 // so we do the second best thing - test it ourselves.
263 // They are both equal and they are not both Smis so both of them are not
264 // Smis. If it's not a heap number, then return equal.
265 if (cond == lt || cond == gt) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000266 // Call runtime on identical JSObjects.
267 __ CompareObjectType(r3, r7, r7, FIRST_JS_RECEIVER_TYPE);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400268 __ bge(slow);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000269 // Call runtime on identical symbols since we need to throw a TypeError.
270 __ cmpi(r7, Operand(SYMBOL_TYPE));
271 __ beq(slow);
272 // Call runtime on identical SIMD values since we must throw a TypeError.
273 __ cmpi(r7, Operand(SIMD128_VALUE_TYPE));
274 __ beq(slow);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400275 } else {
276 __ CompareObjectType(r3, r7, r7, HEAP_NUMBER_TYPE);
277 __ beq(&heap_number);
278 // Comparing JS objects with <=, >= is complicated.
279 if (cond != eq) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000280 __ cmpi(r7, Operand(FIRST_JS_RECEIVER_TYPE));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400281 __ bge(slow);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000282 // Call runtime on identical symbols since we need to throw a TypeError.
283 __ cmpi(r7, Operand(SYMBOL_TYPE));
284 __ beq(slow);
285 // Call runtime on identical SIMD values since we must throw a TypeError.
286 __ cmpi(r7, Operand(SIMD128_VALUE_TYPE));
287 __ beq(slow);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400288 // Normally here we fall through to return_equal, but undefined is
289 // special: (undefined == undefined) == true, but
290 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
291 if (cond == le || cond == ge) {
292 __ cmpi(r7, Operand(ODDBALL_TYPE));
293 __ bne(&return_equal);
294 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
295 __ cmp(r3, r5);
296 __ bne(&return_equal);
297 if (cond == le) {
298 // undefined <= undefined should fail.
299 __ li(r3, Operand(GREATER));
300 } else {
301 // undefined >= undefined should fail.
302 __ li(r3, Operand(LESS));
303 }
304 __ Ret();
305 }
306 }
307 }
308
309 __ bind(&return_equal);
310 if (cond == lt) {
311 __ li(r3, Operand(GREATER)); // Things aren't less than themselves.
312 } else if (cond == gt) {
313 __ li(r3, Operand(LESS)); // Things aren't greater than themselves.
314 } else {
315 __ li(r3, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
316 }
317 __ Ret();
318
319 // For less and greater we don't have to check for NaN since the result of
320 // x < x is false regardless. For the others here is some code to check
321 // for NaN.
322 if (cond != lt && cond != gt) {
323 __ bind(&heap_number);
324 // It is a heap number, so return non-equal if it's NaN and equal if it's
325 // not NaN.
326
327 // The representation of NaN values has all exponent bits (52..62) set,
328 // and not all mantissa bits (0..51) clear.
329 // Read top bits of double representation (second word of value).
330 __ lwz(r5, FieldMemOperand(r3, HeapNumber::kExponentOffset));
331 // Test that exponent bits are all set.
332 STATIC_ASSERT(HeapNumber::kExponentMask == 0x7ff00000u);
333 __ ExtractBitMask(r6, r5, HeapNumber::kExponentMask);
334 __ cmpli(r6, Operand(0x7ff));
335 __ bne(&return_equal);
336
337 // Shift out flag and all exponent bits, retaining only mantissa.
338 __ slwi(r5, r5, Operand(HeapNumber::kNonMantissaBitsInTopWord));
339 // Or with all low-bits of mantissa.
340 __ lwz(r6, FieldMemOperand(r3, HeapNumber::kMantissaOffset));
341 __ orx(r3, r6, r5);
342 __ cmpi(r3, Operand::Zero());
343 // For equal we already have the right value in r3: Return zero (equal)
344 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
345 // not (it's a NaN). For <= and >= we need to load r0 with the failing
346 // value if it's a NaN.
347 if (cond != eq) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000348 if (CpuFeatures::IsSupported(ISELECT)) {
349 __ li(r4, Operand((cond == le) ? GREATER : LESS));
350 __ isel(eq, r3, r3, r4);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400351 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000352 // All-zero means Infinity means equal.
353 __ Ret(eq);
354 if (cond == le) {
355 __ li(r3, Operand(GREATER)); // NaN <= NaN should fail.
356 } else {
357 __ li(r3, Operand(LESS)); // NaN >= NaN should fail.
358 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400359 }
360 }
361 __ Ret();
362 }
363 // No fall through here.
364
365 __ bind(&not_identical);
366}
367
368
369// See comment at call site.
370static void EmitSmiNonsmiComparison(MacroAssembler* masm, Register lhs,
371 Register rhs, Label* lhs_not_nan,
372 Label* slow, bool strict) {
373 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
374
375 Label rhs_is_smi;
376 __ JumpIfSmi(rhs, &rhs_is_smi);
377
378 // Lhs is a Smi. Check whether the rhs is a heap number.
379 __ CompareObjectType(rhs, r6, r7, HEAP_NUMBER_TYPE);
380 if (strict) {
381 // If rhs is not a number and lhs is a Smi then strict equality cannot
382 // succeed. Return non-equal
383 // If rhs is r3 then there is already a non zero value in it.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400384 if (!rhs.is(r3)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000385 Label skip;
386 __ beq(&skip);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400387 __ mov(r3, Operand(NOT_EQUAL));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000388 __ Ret();
389 __ bind(&skip);
390 } else {
391 __ Ret(ne);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400392 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400393 } else {
394 // Smi compared non-strictly with a non-Smi non-heap-number. Call
395 // the runtime.
396 __ bne(slow);
397 }
398
399 // Lhs is a smi, rhs is a number.
400 // Convert lhs to a double in d7.
401 __ SmiToDouble(d7, lhs);
402 // Load the double from rhs, tagged HeapNumber r3, to d6.
403 __ lfd(d6, FieldMemOperand(rhs, HeapNumber::kValueOffset));
404
405 // We now have both loaded as doubles but we can skip the lhs nan check
406 // since it's a smi.
407 __ b(lhs_not_nan);
408
409 __ bind(&rhs_is_smi);
410 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
411 __ CompareObjectType(lhs, r7, r7, HEAP_NUMBER_TYPE);
412 if (strict) {
413 // If lhs is not a number and rhs is a smi then strict equality cannot
414 // succeed. Return non-equal.
415 // If lhs is r3 then there is already a non zero value in it.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400416 if (!lhs.is(r3)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000417 Label skip;
418 __ beq(&skip);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400419 __ mov(r3, Operand(NOT_EQUAL));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000420 __ Ret();
421 __ bind(&skip);
422 } else {
423 __ Ret(ne);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400424 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400425 } else {
426 // Smi compared non-strictly with a non-smi non-heap-number. Call
427 // the runtime.
428 __ bne(slow);
429 }
430
431 // Rhs is a smi, lhs is a heap number.
432 // Load the double from lhs, tagged HeapNumber r4, to d7.
433 __ lfd(d7, FieldMemOperand(lhs, HeapNumber::kValueOffset));
434 // Convert rhs to a double in d6.
435 __ SmiToDouble(d6, rhs);
436 // Fall through to both_loaded_as_doubles.
437}
438
439
440// See comment at call site.
441static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register lhs,
442 Register rhs) {
443 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
444
445 // If either operand is a JS object or an oddball value, then they are
446 // not equal since their pointers are different.
447 // There is no test for undetectability in strict equality.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400449 Label first_non_object;
450 // Get the type of the first operand into r5 and compare it with
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000451 // FIRST_JS_RECEIVER_TYPE.
452 __ CompareObjectType(rhs, r5, r5, FIRST_JS_RECEIVER_TYPE);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400453 __ blt(&first_non_object);
454
455 // Return non-zero (r3 is not zero)
456 Label return_not_equal;
457 __ bind(&return_not_equal);
458 __ Ret();
459
460 __ bind(&first_non_object);
461 // Check for oddballs: true, false, null, undefined.
462 __ cmpi(r5, Operand(ODDBALL_TYPE));
463 __ beq(&return_not_equal);
464
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000465 __ CompareObjectType(lhs, r6, r6, FIRST_JS_RECEIVER_TYPE);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400466 __ bge(&return_not_equal);
467
468 // Check for oddballs: true, false, null, undefined.
469 __ cmpi(r6, Operand(ODDBALL_TYPE));
470 __ beq(&return_not_equal);
471
472 // Now that we have the types we might as well check for
473 // internalized-internalized.
474 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
475 __ orx(r5, r5, r6);
476 __ andi(r0, r5, Operand(kIsNotStringMask | kIsNotInternalizedMask));
477 __ beq(&return_not_equal, cr0);
478}
479
480
481// See comment at call site.
482static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, Register lhs,
483 Register rhs,
484 Label* both_loaded_as_doubles,
485 Label* not_heap_numbers, Label* slow) {
486 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
487
488 __ CompareObjectType(rhs, r6, r5, HEAP_NUMBER_TYPE);
489 __ bne(not_heap_numbers);
490 __ LoadP(r5, FieldMemOperand(lhs, HeapObject::kMapOffset));
491 __ cmp(r5, r6);
492 __ bne(slow); // First was a heap number, second wasn't. Go slow case.
493
494 // Both are heap numbers. Load them up then jump to the code we have
495 // for that.
496 __ lfd(d6, FieldMemOperand(rhs, HeapNumber::kValueOffset));
497 __ lfd(d7, FieldMemOperand(lhs, HeapNumber::kValueOffset));
498
499 __ b(both_loaded_as_doubles);
500}
501
Ben Murdochda12d292016-06-02 14:46:10 +0100502// Fast negative check for internalized-to-internalized equality or receiver
503// equality. Also handles the undetectable receiver to null/undefined
504// comparison.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400505static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
506 Register lhs, Register rhs,
507 Label* possible_strings,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100508 Label* runtime_call) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400509 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
510
511 // r5 is object type of rhs.
Ben Murdochda12d292016-06-02 14:46:10 +0100512 Label object_test, return_equal, return_unequal, undetectable;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400513 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
514 __ andi(r0, r5, Operand(kIsNotStringMask));
515 __ bne(&object_test, cr0);
516 __ andi(r0, r5, Operand(kIsNotInternalizedMask));
517 __ bne(possible_strings, cr0);
518 __ CompareObjectType(lhs, r6, r6, FIRST_NONSTRING_TYPE);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100519 __ bge(runtime_call);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400520 __ andi(r0, r6, Operand(kIsNotInternalizedMask));
521 __ bne(possible_strings, cr0);
522
Ben Murdoch097c5b22016-05-18 11:27:45 +0100523 // Both are internalized. We already checked they weren't the same pointer so
524 // they are not equal. Return non-equal by returning the non-zero object
525 // pointer in r3.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400526 __ Ret();
527
528 __ bind(&object_test);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100529 __ LoadP(r5, FieldMemOperand(lhs, HeapObject::kMapOffset));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400530 __ LoadP(r6, FieldMemOperand(rhs, HeapObject::kMapOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100531 __ lbz(r7, FieldMemOperand(r5, Map::kBitFieldOffset));
532 __ lbz(r8, FieldMemOperand(r6, Map::kBitFieldOffset));
533 __ andi(r0, r7, Operand(1 << Map::kIsUndetectable));
534 __ bne(&undetectable, cr0);
535 __ andi(r0, r8, Operand(1 << Map::kIsUndetectable));
536 __ bne(&return_unequal, cr0);
537
538 __ CompareInstanceType(r5, r5, FIRST_JS_RECEIVER_TYPE);
539 __ blt(runtime_call);
540 __ CompareInstanceType(r6, r6, FIRST_JS_RECEIVER_TYPE);
541 __ blt(runtime_call);
542
543 __ bind(&return_unequal);
544 // Return non-equal by returning the non-zero object pointer in r3.
545 __ Ret();
546
547 __ bind(&undetectable);
548 __ andi(r0, r8, Operand(1 << Map::kIsUndetectable));
549 __ beq(&return_unequal, cr0);
Ben Murdochda12d292016-06-02 14:46:10 +0100550
551 // If both sides are JSReceivers, then the result is false according to
552 // the HTML specification, which says that only comparisons with null or
553 // undefined are affected by special casing for document.all.
554 __ CompareInstanceType(r5, r5, ODDBALL_TYPE);
555 __ beq(&return_equal);
556 __ CompareInstanceType(r6, r6, ODDBALL_TYPE);
557 __ bne(&return_unequal);
558
559 __ bind(&return_equal);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100560 __ li(r3, Operand(EQUAL));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400561 __ Ret();
562}
563
564
565static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
566 Register scratch,
567 CompareICState::State expected,
568 Label* fail) {
569 Label ok;
570 if (expected == CompareICState::SMI) {
571 __ JumpIfNotSmi(input, fail);
572 } else if (expected == CompareICState::NUMBER) {
573 __ JumpIfSmi(input, &ok);
574 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
575 DONT_DO_SMI_CHECK);
576 }
577 // We could be strict about internalized/non-internalized here, but as long as
578 // hydrogen doesn't care, the stub doesn't have to care either.
579 __ bind(&ok);
580}
581
582
583// On entry r4 and r5 are the values to be compared.
584// On exit r3 is 0, positive or negative to indicate the result of
585// the comparison.
586void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
587 Register lhs = r4;
588 Register rhs = r3;
589 Condition cc = GetCondition();
590
591 Label miss;
592 CompareICStub_CheckInputType(masm, lhs, r5, left(), &miss);
593 CompareICStub_CheckInputType(masm, rhs, r6, right(), &miss);
594
595 Label slow; // Call builtin.
596 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
597
598 Label not_two_smis, smi_done;
599 __ orx(r5, r4, r3);
600 __ JumpIfNotSmi(r5, &not_two_smis);
601 __ SmiUntag(r4);
602 __ SmiUntag(r3);
603 __ sub(r3, r4, r3);
604 __ Ret();
605 __ bind(&not_two_smis);
606
607 // NOTICE! This code is only reached after a smi-fast-case check, so
608 // it is certain that at least one operand isn't a smi.
609
610 // Handle the case where the objects are identical. Either returns the answer
611 // or goes to slow. Only falls through if the objects were not identical.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100612 EmitIdenticalObjectComparison(masm, &slow, cc);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400613
614 // If either is a Smi (we know that not both are), then they can only
615 // be strictly equal if the other is a HeapNumber.
616 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000617 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400618 __ and_(r5, lhs, rhs);
619 __ JumpIfNotSmi(r5, &not_smis);
620 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
621 // 1) Return the answer.
622 // 2) Go to slow.
623 // 3) Fall through to both_loaded_as_doubles.
624 // 4) Jump to lhs_not_nan.
625 // In cases 3 and 4 we have found out we were dealing with a number-number
626 // comparison. The double values of the numbers have been loaded
627 // into d7 and d6.
628 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
629
630 __ bind(&both_loaded_as_doubles);
631 // The arguments have been converted to doubles and stored in d6 and d7
632 __ bind(&lhs_not_nan);
633 Label no_nan;
634 __ fcmpu(d7, d6);
635
636 Label nan, equal, less_than;
637 __ bunordered(&nan);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000638 if (CpuFeatures::IsSupported(ISELECT)) {
639 DCHECK(EQUAL == 0);
640 __ li(r4, Operand(GREATER));
641 __ li(r5, Operand(LESS));
642 __ isel(eq, r3, r0, r4);
643 __ isel(lt, r3, r5, r3);
644 __ Ret();
645 } else {
646 __ beq(&equal);
647 __ blt(&less_than);
648 __ li(r3, Operand(GREATER));
649 __ Ret();
650 __ bind(&equal);
651 __ li(r3, Operand(EQUAL));
652 __ Ret();
653 __ bind(&less_than);
654 __ li(r3, Operand(LESS));
655 __ Ret();
656 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400657
658 __ bind(&nan);
659 // If one of the sides was a NaN then the v flag is set. Load r3 with
660 // whatever it takes to make the comparison fail, since comparisons with NaN
661 // always fail.
662 if (cc == lt || cc == le) {
663 __ li(r3, Operand(GREATER));
664 } else {
665 __ li(r3, Operand(LESS));
666 }
667 __ Ret();
668
669 __ bind(&not_smis);
670 // At this point we know we are dealing with two different objects,
671 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
672 if (strict()) {
673 // This returns non-equal for some object types, or falls through if it
674 // was not lucky.
675 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
676 }
677
678 Label check_for_internalized_strings;
679 Label flat_string_check;
680 // Check for heap-number-heap-number comparison. Can jump to slow case,
681 // or load both doubles into r3, r4, r5, r6 and jump to the code that handles
682 // that case. If the inputs are not doubles then jumps to
683 // check_for_internalized_strings.
684 // In this case r5 will contain the type of rhs_. Never falls through.
685 EmitCheckForTwoHeapNumbers(masm, lhs, rhs, &both_loaded_as_doubles,
686 &check_for_internalized_strings,
687 &flat_string_check);
688
689 __ bind(&check_for_internalized_strings);
690 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
691 // internalized strings.
692 if (cc == eq && !strict()) {
693 // Returns an answer for two internalized strings or two detectable objects.
694 // Otherwise jumps to string case or not both strings case.
695 // Assumes that r5 is the type of rhs_ on entry.
696 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, &flat_string_check,
697 &slow);
698 }
699
700 // Check for both being sequential one-byte strings,
701 // and inline if that is the case.
702 __ bind(&flat_string_check);
703
704 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r5, r6, &slow);
705
706 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r5,
707 r6);
708 if (cc == eq) {
709 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r5, r6);
710 } else {
711 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r5, r6, r7);
712 }
713 // Never falls through to here.
714
715 __ bind(&slow);
716
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400717 if (cc == eq) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100718 {
719 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
720 __ Push(lhs, rhs);
721 __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual);
722 }
723 // Turn true into 0 and false into some non-zero value.
724 STATIC_ASSERT(EQUAL == 0);
725 __ LoadRoot(r4, Heap::kTrueValueRootIndex);
726 __ sub(r3, r3, r4);
727 __ Ret();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400728 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100729 __ Push(lhs, rhs);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400730 int ncr; // NaN compare result
731 if (cc == lt || cc == le) {
732 ncr = GREATER;
733 } else {
734 DCHECK(cc == gt || cc == ge); // remaining cases
735 ncr = LESS;
736 }
737 __ LoadSmiLiteral(r3, Smi::FromInt(ncr));
738 __ push(r3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400739
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000740 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
741 // tagged as a small integer.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100742 __ TailCallRuntime(Runtime::kCompare);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000743 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400744
745 __ bind(&miss);
746 GenerateMiss(masm);
747}
748
749
750void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
751 // We don't allow a GC during a store buffer overflow so there is no need to
752 // store the registers in any particular way, but we do have to store and
753 // restore them.
754 __ mflr(r0);
755 __ MultiPush(kJSCallerSaved | r0.bit());
756 if (save_doubles()) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000757 __ MultiPushDoubles(kCallerSavedDoubles);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400758 }
759 const int argument_count = 1;
760 const int fp_argument_count = 0;
761 const Register scratch = r4;
762
763 AllowExternalCallThatCantCauseGC scope(masm);
764 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
765 __ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
766 __ CallCFunction(ExternalReference::store_buffer_overflow_function(isolate()),
767 argument_count);
768 if (save_doubles()) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000769 __ MultiPopDoubles(kCallerSavedDoubles);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400770 }
771 __ MultiPop(kJSCallerSaved | r0.bit());
772 __ mtlr(r0);
773 __ Ret();
774}
775
776
777void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
778 __ PushSafepointRegisters();
779 __ blr();
780}
781
782
783void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
784 __ PopSafepointRegisters();
785 __ blr();
786}
787
788
789void MathPowStub::Generate(MacroAssembler* masm) {
790 const Register base = r4;
791 const Register exponent = MathPowTaggedDescriptor::exponent();
792 DCHECK(exponent.is(r5));
793 const Register heapnumbermap = r8;
794 const Register heapnumber = r3;
795 const DoubleRegister double_base = d1;
796 const DoubleRegister double_exponent = d2;
797 const DoubleRegister double_result = d3;
798 const DoubleRegister double_scratch = d0;
799 const Register scratch = r11;
800 const Register scratch2 = r10;
801
802 Label call_runtime, done, int_exponent;
803 if (exponent_type() == ON_STACK) {
804 Label base_is_smi, unpack_exponent;
805 // The exponent and base are supplied as arguments on the stack.
806 // This can only happen if the stub is called from non-optimized code.
807 // Load input parameters from stack to double registers.
808 __ LoadP(base, MemOperand(sp, 1 * kPointerSize));
809 __ LoadP(exponent, MemOperand(sp, 0 * kPointerSize));
810
811 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
812
813 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
814 __ LoadP(scratch, FieldMemOperand(base, JSObject::kMapOffset));
815 __ cmp(scratch, heapnumbermap);
816 __ bne(&call_runtime);
817
818 __ lfd(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
819 __ b(&unpack_exponent);
820
821 __ bind(&base_is_smi);
822 __ ConvertIntToDouble(scratch, double_base);
823 __ bind(&unpack_exponent);
824
825 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
826 __ LoadP(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
827 __ cmp(scratch, heapnumbermap);
828 __ bne(&call_runtime);
829
830 __ lfd(double_exponent,
831 FieldMemOperand(exponent, HeapNumber::kValueOffset));
832 } else if (exponent_type() == TAGGED) {
833 // Base is already in double_base.
834 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
835
836 __ lfd(double_exponent,
837 FieldMemOperand(exponent, HeapNumber::kValueOffset));
838 }
839
840 if (exponent_type() != INTEGER) {
841 // Detect integer exponents stored as double.
842 __ TryDoubleToInt32Exact(scratch, double_exponent, scratch2,
843 double_scratch);
844 __ beq(&int_exponent);
845
846 if (exponent_type() == ON_STACK) {
847 // Detect square root case. Crankshaft detects constant +/-0.5 at
848 // compile time and uses DoMathPowHalf instead. We then skip this check
849 // for non-constant cases of +/-0.5 as these hardly occur.
850 Label not_plus_half, not_minus_inf1, not_minus_inf2;
851
852 // Test for 0.5.
853 __ LoadDoubleLiteral(double_scratch, 0.5, scratch);
854 __ fcmpu(double_exponent, double_scratch);
855 __ bne(&not_plus_half);
856
857 // Calculates square root of base. Check for the special case of
858 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
859 __ LoadDoubleLiteral(double_scratch, -V8_INFINITY, scratch);
860 __ fcmpu(double_base, double_scratch);
861 __ bne(&not_minus_inf1);
862 __ fneg(double_result, double_scratch);
863 __ b(&done);
864 __ bind(&not_minus_inf1);
865
866 // Add +0 to convert -0 to +0.
867 __ fadd(double_scratch, double_base, kDoubleRegZero);
868 __ fsqrt(double_result, double_scratch);
869 __ b(&done);
870
871 __ bind(&not_plus_half);
872 __ LoadDoubleLiteral(double_scratch, -0.5, scratch);
873 __ fcmpu(double_exponent, double_scratch);
874 __ bne(&call_runtime);
875
876 // Calculates square root of base. Check for the special case of
877 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
878 __ LoadDoubleLiteral(double_scratch, -V8_INFINITY, scratch);
879 __ fcmpu(double_base, double_scratch);
880 __ bne(&not_minus_inf2);
881 __ fmr(double_result, kDoubleRegZero);
882 __ b(&done);
883 __ bind(&not_minus_inf2);
884
885 // Add +0 to convert -0 to +0.
886 __ fadd(double_scratch, double_base, kDoubleRegZero);
887 __ LoadDoubleLiteral(double_result, 1.0, scratch);
888 __ fsqrt(double_scratch, double_scratch);
889 __ fdiv(double_result, double_result, double_scratch);
890 __ b(&done);
891 }
892
893 __ mflr(r0);
894 __ push(r0);
895 {
896 AllowExternalCallThatCantCauseGC scope(masm);
897 __ PrepareCallCFunction(0, 2, scratch);
898 __ MovToFloatParameters(double_base, double_exponent);
899 __ CallCFunction(
900 ExternalReference::power_double_double_function(isolate()), 0, 2);
901 }
902 __ pop(r0);
903 __ mtlr(r0);
904 __ MovFromFloatResult(double_result);
905 __ b(&done);
906 }
907
908 // Calculate power with integer exponent.
909 __ bind(&int_exponent);
910
911 // Get two copies of exponent in the registers scratch and exponent.
912 if (exponent_type() == INTEGER) {
913 __ mr(scratch, exponent);
914 } else {
915 // Exponent has previously been stored into scratch as untagged integer.
916 __ mr(exponent, scratch);
917 }
918 __ fmr(double_scratch, double_base); // Back up base.
919 __ li(scratch2, Operand(1));
920 __ ConvertIntToDouble(scratch2, double_result);
921
922 // Get absolute value of exponent.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400923 __ cmpi(scratch, Operand::Zero());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000924 if (CpuFeatures::IsSupported(ISELECT)) {
925 __ neg(scratch2, scratch);
926 __ isel(lt, scratch, scratch2, scratch);
927 } else {
928 Label positive_exponent;
929 __ bge(&positive_exponent);
930 __ neg(scratch, scratch);
931 __ bind(&positive_exponent);
932 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400933
934 Label while_true, no_carry, loop_end;
935 __ bind(&while_true);
936 __ andi(scratch2, scratch, Operand(1));
937 __ beq(&no_carry, cr0);
938 __ fmul(double_result, double_result, double_scratch);
939 __ bind(&no_carry);
940 __ ShiftRightArithImm(scratch, scratch, 1, SetRC);
941 __ beq(&loop_end, cr0);
942 __ fmul(double_scratch, double_scratch, double_scratch);
943 __ b(&while_true);
944 __ bind(&loop_end);
945
946 __ cmpi(exponent, Operand::Zero());
947 __ bge(&done);
948
949 __ li(scratch2, Operand(1));
950 __ ConvertIntToDouble(scratch2, double_scratch);
951 __ fdiv(double_result, double_scratch, double_result);
952 // Test whether result is zero. Bail out to check for subnormal result.
953 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
954 __ fcmpu(double_result, kDoubleRegZero);
955 __ bne(&done);
956 // double_exponent may not containe the exponent value if the input was a
957 // smi. We set it with exponent value before bailing out.
958 __ ConvertIntToDouble(exponent, double_exponent);
959
960 // Returning or bailing out.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400961 if (exponent_type() == ON_STACK) {
962 // The arguments are still on the stack.
963 __ bind(&call_runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000964 __ TailCallRuntime(Runtime::kMathPowRT);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400965
966 // The stub is called from non-optimized code, which expects the result
967 // as heap number in exponent.
968 __ bind(&done);
969 __ AllocateHeapNumber(heapnumber, scratch, scratch2, heapnumbermap,
970 &call_runtime);
971 __ stfd(double_result,
972 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
973 DCHECK(heapnumber.is(r3));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400974 __ Ret(2);
975 } else {
976 __ mflr(r0);
977 __ push(r0);
978 {
979 AllowExternalCallThatCantCauseGC scope(masm);
980 __ PrepareCallCFunction(0, 2, scratch);
981 __ MovToFloatParameters(double_base, double_exponent);
982 __ CallCFunction(
983 ExternalReference::power_double_double_function(isolate()), 0, 2);
984 }
985 __ pop(r0);
986 __ mtlr(r0);
987 __ MovFromFloatResult(double_result);
988
989 __ bind(&done);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400990 __ Ret();
991 }
992}
993
994
995bool CEntryStub::NeedsImmovableCode() { return true; }
996
997
998void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
999 CEntryStub::GenerateAheadOfTime(isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001000 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1001 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1002 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1003 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001004 CreateWeakCellStub::GenerateAheadOfTime(isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001005 BinaryOpICStub::GenerateAheadOfTime(isolate);
1006 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1007 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1008 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001009 StoreFastElementStub::GenerateAheadOfTime(isolate);
1010 TypeofStub::GenerateAheadOfTime(isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001011}
1012
1013
1014void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1015 StoreRegistersStateStub stub(isolate);
1016 stub.GetCode();
1017}
1018
1019
1020void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1021 RestoreRegistersStateStub stub(isolate);
1022 stub.GetCode();
1023}
1024
1025
1026void CodeStub::GenerateFPStubs(Isolate* isolate) {
1027 // Generate if not already in cache.
1028 SaveFPRegsMode mode = kSaveFPRegs;
1029 CEntryStub(isolate, 1, mode).GetCode();
1030 StoreBufferOverflowStub(isolate, mode).GetCode();
1031 isolate->set_fp_stubs_generated(true);
1032}
1033
1034
1035void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1036 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1037 stub.GetCode();
1038}
1039
1040
1041void CEntryStub::Generate(MacroAssembler* masm) {
1042 // Called from JavaScript; parameters are on stack as if calling JS function.
1043 // r3: number of arguments including receiver
1044 // r4: pointer to builtin function
1045 // fp: frame pointer (restored after C call)
1046 // sp: stack pointer (restored as callee's sp after C call)
1047 // cp: current context (C callee-saved)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001048 //
1049 // If argv_in_register():
1050 // r5: pointer to the first argument
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001051 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1052
1053 __ mr(r15, r4);
1054
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001055 if (argv_in_register()) {
1056 // Move argv into the correct register.
1057 __ mr(r4, r5);
1058 } else {
1059 // Compute the argv pointer.
1060 __ ShiftLeftImm(r4, r3, Operand(kPointerSizeLog2));
1061 __ add(r4, r4, sp);
1062 __ subi(r4, r4, Operand(kPointerSize));
1063 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001064
1065 // Enter the exit frame that transitions from JavaScript to C++.
1066 FrameScope scope(masm, StackFrame::MANUAL);
1067
1068 // Need at least one extra slot for return address location.
1069 int arg_stack_space = 1;
1070
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001071 // Pass buffer for return value on stack if necessary
Ben Murdoch097c5b22016-05-18 11:27:45 +01001072 bool needs_return_buffer =
1073 result_size() > 2 ||
1074 (result_size() == 2 && !ABI_RETURNS_OBJECT_PAIRS_IN_REGS);
1075 if (needs_return_buffer) {
1076 arg_stack_space += result_size();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001077 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001078
1079 __ EnterExitFrame(save_doubles(), arg_stack_space);
1080
1081 // Store a copy of argc in callee-saved registers for later.
1082 __ mr(r14, r3);
1083
1084 // r3, r14: number of arguments including receiver (C callee-saved)
1085 // r4: pointer to the first argument
1086 // r15: pointer to builtin function (C callee-saved)
1087
1088 // Result returned in registers or stack, depending on result size and ABI.
1089
1090 Register isolate_reg = r5;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001091 if (needs_return_buffer) {
1092 // The return value is a non-scalar value.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001093 // Use frame storage reserved by calling function to pass return
1094 // buffer as implicit first argument.
1095 __ mr(r5, r4);
1096 __ mr(r4, r3);
1097 __ addi(r3, sp, Operand((kStackFrameExtraParamSlot + 1) * kPointerSize));
1098 isolate_reg = r6;
1099 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001100
1101 // Call C built-in.
1102 __ mov(isolate_reg, Operand(ExternalReference::isolate_address(isolate())));
1103
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001104 Register target = r15;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001105 if (ABI_USES_FUNCTION_DESCRIPTORS) {
1106 // AIX/PPC64BE Linux use a function descriptor.
1107 __ LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(r15, kPointerSize));
1108 __ LoadP(ip, MemOperand(r15, 0)); // Instruction address
1109 target = ip;
1110 } else if (ABI_CALL_VIA_IP) {
1111 __ Move(ip, r15);
1112 target = ip;
1113 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001114
1115 // To let the GC traverse the return address of the exit frames, we need to
1116 // know where the return address is. The CEntryStub is unmovable, so
1117 // we can store the address on the stack to be able to find it again and
1118 // we never have to restore it, because it will not change.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001119 Label after_call;
1120 __ mov_label_addr(r0, &after_call);
1121 __ StoreP(r0, MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize));
1122 __ Call(target);
1123 __ bind(&after_call);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001124
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001125 // If return value is on the stack, pop it to registers.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001126 if (needs_return_buffer) {
1127 if (result_size() > 2) __ LoadP(r5, MemOperand(r3, 2 * kPointerSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001128 __ LoadP(r4, MemOperand(r3, kPointerSize));
1129 __ LoadP(r3, MemOperand(r3));
1130 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001131
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001132 // Check result for exception sentinel.
1133 Label exception_returned;
1134 __ CompareRoot(r3, Heap::kExceptionRootIndex);
1135 __ beq(&exception_returned);
1136
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001137 // Check that there is no pending exception, otherwise we
1138 // should have returned the exception sentinel.
1139 if (FLAG_debug_code) {
1140 Label okay;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001141 ExternalReference pending_exception_address(
1142 Isolate::kPendingExceptionAddress, isolate());
1143
Ben Murdoch097c5b22016-05-18 11:27:45 +01001144 __ mov(r6, Operand(pending_exception_address));
1145 __ LoadP(r6, MemOperand(r6));
1146 __ CompareRoot(r6, Heap::kTheHoleValueRootIndex);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001147 // Cannot use check here as it attempts to generate call into runtime.
1148 __ beq(&okay);
1149 __ stop("Unexpected pending exception");
1150 __ bind(&okay);
1151 }
1152
1153 // Exit C frame and return.
1154 // r3:r4: result
1155 // sp: stack pointer
1156 // fp: frame pointer
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001157 Register argc;
1158 if (argv_in_register()) {
1159 // We don't want to pop arguments so set argc to no_reg.
1160 argc = no_reg;
1161 } else {
1162 // r14: still holds argc (callee-saved).
1163 argc = r14;
1164 }
1165 __ LeaveExitFrame(save_doubles(), argc, true);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001166 __ blr();
1167
1168 // Handling of exception.
1169 __ bind(&exception_returned);
1170
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001171 ExternalReference pending_handler_context_address(
1172 Isolate::kPendingHandlerContextAddress, isolate());
1173 ExternalReference pending_handler_code_address(
1174 Isolate::kPendingHandlerCodeAddress, isolate());
1175 ExternalReference pending_handler_offset_address(
1176 Isolate::kPendingHandlerOffsetAddress, isolate());
1177 ExternalReference pending_handler_fp_address(
1178 Isolate::kPendingHandlerFPAddress, isolate());
1179 ExternalReference pending_handler_sp_address(
1180 Isolate::kPendingHandlerSPAddress, isolate());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001181
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001182 // Ask the runtime for help to determine the handler. This will set r3 to
1183 // contain the current pending exception, don't clobber it.
1184 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1185 isolate());
1186 {
1187 FrameScope scope(masm, StackFrame::MANUAL);
1188 __ PrepareCallCFunction(3, 0, r3);
1189 __ li(r3, Operand::Zero());
1190 __ li(r4, Operand::Zero());
1191 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
1192 __ CallCFunction(find_handler, 3);
1193 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001194
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001195 // Retrieve the handler context, SP and FP.
1196 __ mov(cp, Operand(pending_handler_context_address));
1197 __ LoadP(cp, MemOperand(cp));
1198 __ mov(sp, Operand(pending_handler_sp_address));
1199 __ LoadP(sp, MemOperand(sp));
1200 __ mov(fp, Operand(pending_handler_fp_address));
1201 __ LoadP(fp, MemOperand(fp));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001202
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001203 // If the handler is a JS frame, restore the context to the frame. Note that
1204 // the context will be set to (cp == 0) for non-JS frames.
1205 Label skip;
1206 __ cmpi(cp, Operand::Zero());
1207 __ beq(&skip);
1208 __ StoreP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1209 __ bind(&skip);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001210
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001211 // Compute the handler entry address and jump to it.
1212 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1213 __ mov(r4, Operand(pending_handler_code_address));
1214 __ LoadP(r4, MemOperand(r4));
1215 __ mov(r5, Operand(pending_handler_offset_address));
1216 __ LoadP(r5, MemOperand(r5));
1217 __ addi(r4, r4, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1218 if (FLAG_enable_embedded_constant_pool) {
1219 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r4);
1220 }
1221 __ add(ip, r4, r5);
1222 __ Jump(ip);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001223}
1224
1225
1226void JSEntryStub::Generate(MacroAssembler* masm) {
1227 // r3: code entry
1228 // r4: function
1229 // r5: receiver
1230 // r6: argc
1231 // [sp+0]: argv
1232
1233 Label invoke, handler_entry, exit;
1234
1235// Called from C
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001236 __ function_descriptor();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001237
1238 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1239
1240 // PPC LINUX ABI:
1241 // preserve LR in pre-reserved slot in caller's frame
1242 __ mflr(r0);
1243 __ StoreP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize));
1244
1245 // Save callee saved registers on the stack.
1246 __ MultiPush(kCalleeSaved);
1247
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001248 // Save callee-saved double registers.
1249 __ MultiPushDoubles(kCalleeSavedDoubles);
1250 // Set up the reserved register for 0.0.
1251 __ LoadDoubleLiteral(kDoubleRegZero, 0.0, r0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001252
1253 // Push a frame with special values setup to mark it as an entry frame.
1254 // r3: code entry
1255 // r4: function
1256 // r5: receiver
1257 // r6: argc
1258 // r7: argv
1259 __ li(r0, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1260 __ push(r0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001261 if (FLAG_enable_embedded_constant_pool) {
1262 __ li(kConstantPoolRegister, Operand::Zero());
1263 __ push(kConstantPoolRegister);
1264 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001265 int marker = type();
1266 __ LoadSmiLiteral(r0, Smi::FromInt(marker));
1267 __ push(r0);
1268 __ push(r0);
1269 // Save copies of the top frame descriptor on the stack.
1270 __ mov(r8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1271 __ LoadP(r0, MemOperand(r8));
1272 __ push(r0);
1273
1274 // Set up frame pointer for the frame to be pushed.
1275 __ addi(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1276
1277 // If this is the outermost JS call, set js_entry_sp value.
1278 Label non_outermost_js;
1279 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1280 __ mov(r8, Operand(ExternalReference(js_entry_sp)));
1281 __ LoadP(r9, MemOperand(r8));
1282 __ cmpi(r9, Operand::Zero());
1283 __ bne(&non_outermost_js);
1284 __ StoreP(fp, MemOperand(r8));
1285 __ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1286 Label cont;
1287 __ b(&cont);
1288 __ bind(&non_outermost_js);
1289 __ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME));
1290 __ bind(&cont);
1291 __ push(ip); // frame-type
1292
1293 // Jump to a faked try block that does the invoke, with a faked catch
1294 // block that sets the pending exception.
1295 __ b(&invoke);
1296
1297 __ bind(&handler_entry);
1298 handler_offset_ = handler_entry.pos();
1299 // Caught exception: Store result (exception) in the pending exception
1300 // field in the JSEnv and return a failure sentinel. Coming in here the
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001301 // fp will be invalid because the PushStackHandler below sets it to 0 to
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001302 // signal the existence of the JSEntry frame.
1303 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1304 isolate())));
1305
1306 __ StoreP(r3, MemOperand(ip));
1307 __ LoadRoot(r3, Heap::kExceptionRootIndex);
1308 __ b(&exit);
1309
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001310 // Invoke: Link this frame into the handler chain.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001311 __ bind(&invoke);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001312 // Must preserve r3-r7.
1313 __ PushStackHandler();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001314 // If an exception not caught by another handler occurs, this handler
1315 // returns control to the code after the b(&invoke) above, which
1316 // restores all kCalleeSaved registers (including cp and fp) to their
1317 // saved values before returning a failure to C.
1318
1319 // Clear any pending exceptions.
1320 __ mov(r8, Operand(isolate()->factory()->the_hole_value()));
1321 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1322 isolate())));
1323 __ StoreP(r8, MemOperand(ip));
1324
1325 // Invoke the function by calling through JS entry trampoline builtin.
1326 // Notice that we cannot store a reference to the trampoline code directly in
1327 // this stub, because runtime stubs are not traversed when doing GC.
1328
1329 // Expected registers by Builtins::JSEntryTrampoline
1330 // r3: code entry
1331 // r4: function
1332 // r5: receiver
1333 // r6: argc
1334 // r7: argv
1335 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1336 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1337 isolate());
1338 __ mov(ip, Operand(construct_entry));
1339 } else {
1340 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
1341 __ mov(ip, Operand(entry));
1342 }
1343 __ LoadP(ip, MemOperand(ip)); // deref address
1344
1345 // Branch and link to JSEntryTrampoline.
1346 // the address points to the start of the code object, skip the header
1347 __ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1348 __ mtctr(ip);
1349 __ bctrl(); // make the call
1350
1351 // Unlink this frame from the handler chain.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001352 __ PopStackHandler();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001353
1354 __ bind(&exit); // r3 holds result
1355 // Check if the current stack frame is marked as the outermost JS frame.
1356 Label non_outermost_js_2;
1357 __ pop(r8);
1358 __ CmpSmiLiteral(r8, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME), r0);
1359 __ bne(&non_outermost_js_2);
1360 __ mov(r9, Operand::Zero());
1361 __ mov(r8, Operand(ExternalReference(js_entry_sp)));
1362 __ StoreP(r9, MemOperand(r8));
1363 __ bind(&non_outermost_js_2);
1364
1365 // Restore the top frame descriptors from the stack.
1366 __ pop(r6);
1367 __ mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1368 __ StoreP(r6, MemOperand(ip));
1369
1370 // Reset the stack to the callee saved registers.
1371 __ addi(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1372
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001373 // Restore callee-saved double registers.
1374 __ MultiPopDoubles(kCalleeSavedDoubles);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001375
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001376 // Restore callee-saved registers.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001377 __ MultiPop(kCalleeSaved);
1378
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001379 // Return
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001380 __ LoadP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001381 __ mtlr(r0);
1382 __ blr();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001383}
1384
1385
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001386void InstanceOfStub::Generate(MacroAssembler* masm) {
1387 Register const object = r4; // Object (lhs).
1388 Register const function = r3; // Function (rhs).
1389 Register const object_map = r5; // Map of {object}.
1390 Register const function_map = r6; // Map of {function}.
1391 Register const function_prototype = r7; // Prototype of {function}.
1392 Register const scratch = r8;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001393
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001394 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1395 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001396
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001397 // Check if {object} is a smi.
1398 Label object_is_smi;
1399 __ JumpIfSmi(object, &object_is_smi);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001400
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001401 // Lookup the {function} and the {object} map in the global instanceof cache.
1402 // Note: This is safe because we clear the global instanceof cache whenever
1403 // we change the prototype of any object.
1404 Label fast_case, slow_case;
1405 __ LoadP(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1406 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1407 __ bne(&fast_case);
1408 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1409 __ bne(&fast_case);
1410 __ LoadRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
1411 __ Ret();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001412
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001413 // If {object} is a smi we can safely return false if {function} is a JS
1414 // function, otherwise we have to miss to the runtime and throw an exception.
1415 __ bind(&object_is_smi);
1416 __ JumpIfSmi(function, &slow_case);
1417 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1418 __ bne(&slow_case);
1419 __ LoadRoot(r3, Heap::kFalseValueRootIndex);
1420 __ Ret();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001421
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001422 // Fast-case: The {function} must be a valid JSFunction.
1423 __ bind(&fast_case);
1424 __ JumpIfSmi(function, &slow_case);
1425 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1426 __ bne(&slow_case);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001427
Ben Murdochda12d292016-06-02 14:46:10 +01001428 // Go to the runtime if the function is not a constructor.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001429 __ lbz(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01001430 __ TestBit(scratch, Map::kIsConstructor, r0);
1431 __ beq(&slow_case, cr0);
1432
1433 // Ensure that {function} has an instance prototype.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001434 __ TestBit(scratch, Map::kHasNonInstancePrototype, r0);
1435 __ bne(&slow_case, cr0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001436
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001437 // Get the "prototype" (or initial map) of the {function}.
1438 __ LoadP(function_prototype,
1439 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1440 __ AssertNotSmi(function_prototype);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001441
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001442 // Resolve the prototype if the {function} has an initial map. Afterwards the
1443 // {function_prototype} will be either the JSReceiver prototype object or the
1444 // hole value, which means that no instances of the {function} were created so
1445 // far and hence we should return false.
1446 Label function_prototype_valid;
1447 __ CompareObjectType(function_prototype, scratch, scratch, MAP_TYPE);
1448 __ bne(&function_prototype_valid);
1449 __ LoadP(function_prototype,
1450 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1451 __ bind(&function_prototype_valid);
1452 __ AssertNotSmi(function_prototype);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001453
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001454 // Update the global instanceof cache with the current {object} map and
1455 // {function}. The cached answer will be set when it is known below.
1456 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1457 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001458
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001459 // Loop through the prototype chain looking for the {function} prototype.
1460 // Assume true, and change to false if not found.
1461 Register const object_instance_type = function_map;
1462 Register const map_bit_field = function_map;
1463 Register const null = scratch;
1464 Register const result = r3;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001465
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001466 Label done, loop, fast_runtime_fallback;
1467 __ LoadRoot(result, Heap::kTrueValueRootIndex);
1468 __ LoadRoot(null, Heap::kNullValueRootIndex);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001469 __ bind(&loop);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001470
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001471 // Check if the object needs to be access checked.
1472 __ lbz(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset));
1473 __ TestBit(map_bit_field, Map::kIsAccessCheckNeeded, r0);
1474 __ bne(&fast_runtime_fallback, cr0);
1475 // Check if the current object is a Proxy.
1476 __ CompareInstanceType(object_map, object_instance_type, JS_PROXY_TYPE);
1477 __ beq(&fast_runtime_fallback);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001478
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001479 __ LoadP(object, FieldMemOperand(object_map, Map::kPrototypeOffset));
1480 __ cmp(object, function_prototype);
1481 __ beq(&done);
1482 __ cmp(object, null);
1483 __ LoadP(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1484 __ bne(&loop);
1485 __ LoadRoot(result, Heap::kFalseValueRootIndex);
1486 __ bind(&done);
1487 __ StoreRoot(result, Heap::kInstanceofCacheAnswerRootIndex);
1488 __ Ret();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001489
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001490 // Found Proxy or access check needed: Call the runtime
1491 __ bind(&fast_runtime_fallback);
1492 __ Push(object, function_prototype);
1493 // Invalidate the instanceof cache.
1494 __ LoadSmiLiteral(scratch, Smi::FromInt(0));
1495 __ StoreRoot(scratch, Heap::kInstanceofCacheFunctionRootIndex);
1496 __ TailCallRuntime(Runtime::kHasInPrototypeChain);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001497
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001498 // Slow-case: Call the %InstanceOf runtime function.
1499 __ bind(&slow_case);
1500 __ Push(object, function);
Ben Murdochda12d292016-06-02 14:46:10 +01001501 __ TailCallRuntime(is_es6_instanceof() ? Runtime::kOrdinaryHasInstance
1502 : Runtime::kInstanceOf);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001503}
1504
1505
1506void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1507 Label miss;
1508 Register receiver = LoadDescriptor::ReceiverRegister();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001509 // Ensure that the vector and slot registers won't be clobbered before
1510 // calling the miss handler.
1511 DCHECK(!AreAliased(r7, r8, LoadWithVectorDescriptor::VectorRegister(),
1512 LoadWithVectorDescriptor::SlotRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001513
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001514 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r7,
1515 r8, &miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001516 __ bind(&miss);
1517 PropertyAccessCompiler::TailCallBuiltin(
1518 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1519}
1520
1521
1522void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1523 // Return address is in lr.
1524 Label miss;
1525
1526 Register receiver = LoadDescriptor::ReceiverRegister();
1527 Register index = LoadDescriptor::NameRegister();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001528 Register scratch = r8;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001529 Register result = r3;
1530 DCHECK(!scratch.is(receiver) && !scratch.is(index));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001531 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1532 result.is(LoadWithVectorDescriptor::SlotRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001533
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001534 // StringCharAtGenerator doesn't use the result register until it's passed
1535 // the different miss possibilities. If it did, we would have a conflict
1536 // when FLAG_vector_ics is true.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001537 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1538 &miss, // When not a string.
1539 &miss, // When not a number.
1540 &miss, // When index out of range.
1541 STRING_INDEX_IS_ARRAY_INDEX,
1542 RECEIVER_IS_STRING);
1543 char_at_generator.GenerateFast(masm);
1544 __ Ret();
1545
1546 StubRuntimeCallHelper call_helper;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001547 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001548
1549 __ bind(&miss);
1550 PropertyAccessCompiler::TailCallBuiltin(
1551 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1552}
1553
1554
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001555void RegExpExecStub::Generate(MacroAssembler* masm) {
1556// Just jump directly to runtime if native RegExp is not selected at compile
1557// time or if regexp entry in generated code is turned off runtime switch or
1558// at compilation.
1559#ifdef V8_INTERPRETED_REGEXP
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001560 __ TailCallRuntime(Runtime::kRegExpExec);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001561#else // V8_INTERPRETED_REGEXP
1562
1563 // Stack frame on entry.
1564 // sp[0]: last_match_info (expected JSArray)
1565 // sp[4]: previous index
1566 // sp[8]: subject string
1567 // sp[12]: JSRegExp object
1568
1569 const int kLastMatchInfoOffset = 0 * kPointerSize;
1570 const int kPreviousIndexOffset = 1 * kPointerSize;
1571 const int kSubjectOffset = 2 * kPointerSize;
1572 const int kJSRegExpOffset = 3 * kPointerSize;
1573
1574 Label runtime, br_over, encoding_type_UC16;
1575
1576 // Allocation of registers for this function. These are in callee save
1577 // registers and will be preserved by the call to the native RegExp code, as
1578 // this code is called using the normal C calling convention. When calling
1579 // directly from generated code the native RegExp code will not do a GC and
1580 // therefore the content of these registers are safe to use after the call.
1581 Register subject = r14;
1582 Register regexp_data = r15;
1583 Register last_match_info_elements = r16;
1584 Register code = r17;
1585
1586 // Ensure register assigments are consistent with callee save masks
1587 DCHECK(subject.bit() & kCalleeSaved);
1588 DCHECK(regexp_data.bit() & kCalleeSaved);
1589 DCHECK(last_match_info_elements.bit() & kCalleeSaved);
1590 DCHECK(code.bit() & kCalleeSaved);
1591
1592 // Ensure that a RegExp stack is allocated.
1593 ExternalReference address_of_regexp_stack_memory_address =
1594 ExternalReference::address_of_regexp_stack_memory_address(isolate());
1595 ExternalReference address_of_regexp_stack_memory_size =
1596 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1597 __ mov(r3, Operand(address_of_regexp_stack_memory_size));
1598 __ LoadP(r3, MemOperand(r3, 0));
1599 __ cmpi(r3, Operand::Zero());
1600 __ beq(&runtime);
1601
1602 // Check that the first argument is a JSRegExp object.
1603 __ LoadP(r3, MemOperand(sp, kJSRegExpOffset));
1604 __ JumpIfSmi(r3, &runtime);
1605 __ CompareObjectType(r3, r4, r4, JS_REGEXP_TYPE);
1606 __ bne(&runtime);
1607
1608 // Check that the RegExp has been compiled (data contains a fixed array).
1609 __ LoadP(regexp_data, FieldMemOperand(r3, JSRegExp::kDataOffset));
1610 if (FLAG_debug_code) {
1611 __ TestIfSmi(regexp_data, r0);
1612 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected, cr0);
1613 __ CompareObjectType(regexp_data, r3, r3, FIXED_ARRAY_TYPE);
1614 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1615 }
1616
1617 // regexp_data: RegExp data (FixedArray)
1618 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1619 __ LoadP(r3, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1620 // DCHECK(Smi::FromInt(JSRegExp::IRREGEXP) < (char *)0xffffu);
1621 __ CmpSmiLiteral(r3, Smi::FromInt(JSRegExp::IRREGEXP), r0);
1622 __ bne(&runtime);
1623
1624 // regexp_data: RegExp data (FixedArray)
1625 // Check that the number of captures fit in the static offsets vector buffer.
1626 __ LoadP(r5,
1627 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1628 // Check (number_of_captures + 1) * 2 <= offsets vector size
1629 // Or number_of_captures * 2 <= offsets vector size - 2
1630 // SmiToShortArrayOffset accomplishes the multiplication by 2 and
1631 // SmiUntag (which is a nop for 32-bit).
1632 __ SmiToShortArrayOffset(r5, r5);
1633 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1634 __ cmpli(r5, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
1635 __ bgt(&runtime);
1636
1637 // Reset offset for possibly sliced string.
1638 __ li(r11, Operand::Zero());
1639 __ LoadP(subject, MemOperand(sp, kSubjectOffset));
1640 __ JumpIfSmi(subject, &runtime);
1641 __ mr(r6, subject); // Make a copy of the original subject string.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001642 // subject: subject string
1643 // r6: subject string
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001644 // regexp_data: RegExp data (FixedArray)
1645 // Handle subject string according to its encoding and representation:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001646 // (1) Sequential string? If yes, go to (4).
1647 // (2) Sequential or cons? If not, go to (5).
1648 // (3) Cons string. If the string is flat, replace subject with first string
1649 // and go to (1). Otherwise bail out to runtime.
1650 // (4) Sequential string. Load regexp code according to encoding.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001651 // (E) Carry on.
1652 /// [...]
1653
1654 // Deferred code at the end of the stub:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001655 // (5) Long external string? If not, go to (7).
1656 // (6) External string. Make it, offset-wise, look like a sequential string.
1657 // Go to (4).
1658 // (7) Short external string or not a string? If yes, bail out to runtime.
1659 // (8) Sliced string. Replace subject with parent. Go to (1).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001660
Ben Murdoch097c5b22016-05-18 11:27:45 +01001661 Label seq_string /* 4 */, external_string /* 6 */, check_underlying /* 1 */,
1662 not_seq_nor_cons /* 5 */, not_long_external /* 7 */;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001663
Ben Murdoch097c5b22016-05-18 11:27:45 +01001664 __ bind(&check_underlying);
1665 __ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
1666 __ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
1667
1668 // (1) Sequential string? If yes, go to (4).
1669
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001670 STATIC_ASSERT((kIsNotStringMask | kStringRepresentationMask |
1671 kShortExternalStringMask) == 0x93);
1672 __ andi(r4, r3, Operand(kIsNotStringMask | kStringRepresentationMask |
1673 kShortExternalStringMask));
1674 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001675 __ beq(&seq_string, cr0); // Go to (4).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001676
Ben Murdoch097c5b22016-05-18 11:27:45 +01001677 // (2) Sequential or cons? If not, go to (5).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001678 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1679 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
1680 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1681 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
1682 STATIC_ASSERT(kExternalStringTag < 0xffffu);
1683 __ cmpi(r4, Operand(kExternalStringTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001684 __ bge(&not_seq_nor_cons); // Go to (5).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001685
1686 // (3) Cons string. Check that it's flat.
1687 // Replace subject with first string and reload instance type.
1688 __ LoadP(r3, FieldMemOperand(subject, ConsString::kSecondOffset));
1689 __ CompareRoot(r3, Heap::kempty_stringRootIndex);
1690 __ bne(&runtime);
1691 __ LoadP(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001692 __ b(&check_underlying);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001693
Ben Murdoch097c5b22016-05-18 11:27:45 +01001694 // (4) Sequential string. Load regexp code according to encoding.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001695 __ bind(&seq_string);
1696 // subject: sequential subject string (or look-alike, external string)
1697 // r6: original subject string
1698 // Load previous index and check range before r6 is overwritten. We have to
1699 // use r6 instead of subject here because subject might have been only made
1700 // to look like a sequential string when it actually is an external string.
1701 __ LoadP(r4, MemOperand(sp, kPreviousIndexOffset));
1702 __ JumpIfNotSmi(r4, &runtime);
1703 __ LoadP(r6, FieldMemOperand(r6, String::kLengthOffset));
1704 __ cmpl(r6, r4);
1705 __ ble(&runtime);
1706 __ SmiUntag(r4);
1707
1708 STATIC_ASSERT(4 == kOneByteStringTag);
1709 STATIC_ASSERT(kTwoByteStringTag == 0);
1710 STATIC_ASSERT(kStringEncodingMask == 4);
1711 __ ExtractBitMask(r6, r3, kStringEncodingMask, SetRC);
1712 __ beq(&encoding_type_UC16, cr0);
1713 __ LoadP(code,
1714 FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
1715 __ b(&br_over);
1716 __ bind(&encoding_type_UC16);
1717 __ LoadP(code, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
1718 __ bind(&br_over);
1719
1720 // (E) Carry on. String handling is done.
1721 // code: irregexp code
1722 // Check that the irregexp code has been generated for the actual string
1723 // encoding. If it has, the field contains a code object otherwise it contains
1724 // a smi (code flushing support).
1725 __ JumpIfSmi(code, &runtime);
1726
1727 // r4: previous index
1728 // r6: encoding of subject string (1 if one_byte, 0 if two_byte);
1729 // code: Address of generated regexp code
1730 // subject: Subject string
1731 // regexp_data: RegExp data (FixedArray)
1732 // All checks done. Now push arguments for native regexp code.
1733 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r3, r5);
1734
1735 // Isolates: note we add an additional parameter here (isolate pointer).
1736 const int kRegExpExecuteArguments = 10;
1737 const int kParameterRegisters = 8;
1738 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
1739
1740 // Stack pointer now points to cell where return address is to be written.
1741 // Arguments are before that on the stack or in registers.
1742
1743 // Argument 10 (in stack parameter area): Pass current isolate address.
1744 __ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
1745 __ StoreP(r3, MemOperand(sp, (kStackFrameExtraParamSlot + 1) * kPointerSize));
1746
1747 // Argument 9 is a dummy that reserves the space used for
1748 // the return address added by the ExitFrame in native calls.
1749
1750 // Argument 8 (r10): Indicate that this is a direct call from JavaScript.
1751 __ li(r10, Operand(1));
1752
1753 // Argument 7 (r9): Start (high end) of backtracking stack memory area.
1754 __ mov(r3, Operand(address_of_regexp_stack_memory_address));
1755 __ LoadP(r3, MemOperand(r3, 0));
1756 __ mov(r5, Operand(address_of_regexp_stack_memory_size));
1757 __ LoadP(r5, MemOperand(r5, 0));
1758 __ add(r9, r3, r5);
1759
1760 // Argument 6 (r8): Set the number of capture registers to zero to force
1761 // global egexps to behave as non-global. This does not affect non-global
1762 // regexps.
1763 __ li(r8, Operand::Zero());
1764
1765 // Argument 5 (r7): static offsets vector buffer.
1766 __ mov(
1767 r7,
1768 Operand(ExternalReference::address_of_static_offsets_vector(isolate())));
1769
1770 // For arguments 4 (r6) and 3 (r5) get string length, calculate start of data
1771 // and calculate the shift of the index (0 for one-byte and 1 for two-byte).
1772 __ addi(r18, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
1773 __ xori(r6, r6, Operand(1));
1774 // Load the length from the original subject string from the previous stack
1775 // frame. Therefore we have to use fp, which points exactly to two pointer
1776 // sizes below the previous sp. (Because creating a new stack frame pushes
1777 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
1778 __ LoadP(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
1779 // If slice offset is not 0, load the length from the original sliced string.
1780 // Argument 4, r6: End of string data
1781 // Argument 3, r5: Start of string data
1782 // Prepare start and end index of the input.
1783 __ ShiftLeft_(r11, r11, r6);
1784 __ add(r11, r18, r11);
1785 __ ShiftLeft_(r5, r4, r6);
1786 __ add(r5, r11, r5);
1787
1788 __ LoadP(r18, FieldMemOperand(subject, String::kLengthOffset));
1789 __ SmiUntag(r18);
1790 __ ShiftLeft_(r6, r18, r6);
1791 __ add(r6, r11, r6);
1792
1793 // Argument 2 (r4): Previous index.
1794 // Already there
1795
1796 // Argument 1 (r3): Subject string.
1797 __ mr(r3, subject);
1798
1799 // Locate the code entry and call it.
1800 __ addi(code, code, Operand(Code::kHeaderSize - kHeapObjectTag));
1801
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001802 DirectCEntryStub stub(isolate());
1803 stub.GenerateCall(masm, code);
1804
1805 __ LeaveExitFrame(false, no_reg, true);
1806
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001807 // r3: result (int32)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001808 // subject: subject string (callee saved)
1809 // regexp_data: RegExp data (callee saved)
1810 // last_match_info_elements: Last match info elements (callee saved)
1811 // Check the result.
1812 Label success;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001813 __ cmpwi(r3, Operand(1));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001814 // We expect exactly one result since we force the called regexp to behave
1815 // as non-global.
1816 __ beq(&success);
1817 Label failure;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001818 __ cmpwi(r3, Operand(NativeRegExpMacroAssembler::FAILURE));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001819 __ beq(&failure);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001820 __ cmpwi(r3, Operand(NativeRegExpMacroAssembler::EXCEPTION));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001821 // If not exception it can only be retry. Handle that in the runtime system.
1822 __ bne(&runtime);
1823 // Result must now be exception. If there is no pending exception already a
1824 // stack overflow (on the backtrack stack) was detected in RegExp code but
1825 // haven't created the exception yet. Handle that in the runtime system.
1826 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
1827 __ mov(r4, Operand(isolate()->factory()->the_hole_value()));
1828 __ mov(r5, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1829 isolate())));
1830 __ LoadP(r3, MemOperand(r5, 0));
1831 __ cmp(r3, r4);
1832 __ beq(&runtime);
1833
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001834 // For exception, throw the exception again.
1835 __ TailCallRuntime(Runtime::kRegExpExecReThrow);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001836
1837 __ bind(&failure);
1838 // For failure and exception return null.
1839 __ mov(r3, Operand(isolate()->factory()->null_value()));
1840 __ addi(sp, sp, Operand(4 * kPointerSize));
1841 __ Ret();
1842
1843 // Process the result from the native regexp code.
1844 __ bind(&success);
1845 __ LoadP(r4,
1846 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1847 // Calculate number of capture registers (number_of_captures + 1) * 2.
1848 // SmiToShortArrayOffset accomplishes the multiplication by 2 and
1849 // SmiUntag (which is a nop for 32-bit).
1850 __ SmiToShortArrayOffset(r4, r4);
1851 __ addi(r4, r4, Operand(2));
1852
1853 __ LoadP(r3, MemOperand(sp, kLastMatchInfoOffset));
1854 __ JumpIfSmi(r3, &runtime);
1855 __ CompareObjectType(r3, r5, r5, JS_ARRAY_TYPE);
1856 __ bne(&runtime);
1857 // Check that the JSArray is in fast case.
1858 __ LoadP(last_match_info_elements,
1859 FieldMemOperand(r3, JSArray::kElementsOffset));
1860 __ LoadP(r3,
1861 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
1862 __ CompareRoot(r3, Heap::kFixedArrayMapRootIndex);
1863 __ bne(&runtime);
1864 // Check that the last match info has space for the capture registers and the
1865 // additional information.
1866 __ LoadP(
1867 r3, FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
1868 __ addi(r5, r4, Operand(RegExpImpl::kLastMatchOverhead));
1869 __ SmiUntag(r0, r3);
1870 __ cmp(r5, r0);
1871 __ bgt(&runtime);
1872
1873 // r4: number of capture registers
1874 // subject: subject string
1875 // Store the capture count.
1876 __ SmiTag(r5, r4);
1877 __ StoreP(r5, FieldMemOperand(last_match_info_elements,
1878 RegExpImpl::kLastCaptureCountOffset),
1879 r0);
1880 // Store last subject and last input.
1881 __ StoreP(subject, FieldMemOperand(last_match_info_elements,
1882 RegExpImpl::kLastSubjectOffset),
1883 r0);
1884 __ mr(r5, subject);
1885 __ RecordWriteField(last_match_info_elements, RegExpImpl::kLastSubjectOffset,
1886 subject, r10, kLRHasNotBeenSaved, kDontSaveFPRegs);
1887 __ mr(subject, r5);
1888 __ StoreP(subject, FieldMemOperand(last_match_info_elements,
1889 RegExpImpl::kLastInputOffset),
1890 r0);
1891 __ RecordWriteField(last_match_info_elements, RegExpImpl::kLastInputOffset,
1892 subject, r10, kLRHasNotBeenSaved, kDontSaveFPRegs);
1893
1894 // Get the static offsets vector filled by the native regexp code.
1895 ExternalReference address_of_static_offsets_vector =
1896 ExternalReference::address_of_static_offsets_vector(isolate());
1897 __ mov(r5, Operand(address_of_static_offsets_vector));
1898
1899 // r4: number of capture registers
1900 // r5: offsets vector
1901 Label next_capture;
1902 // Capture register counter starts from number of capture registers and
1903 // counts down until wraping after zero.
1904 __ addi(
1905 r3, last_match_info_elements,
1906 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag - kPointerSize));
1907 __ addi(r5, r5, Operand(-kIntSize)); // bias down for lwzu
1908 __ mtctr(r4);
1909 __ bind(&next_capture);
1910 // Read the value from the static offsets vector buffer.
1911 __ lwzu(r6, MemOperand(r5, kIntSize));
1912 // Store the smi value in the last match info.
1913 __ SmiTag(r6);
1914 __ StorePU(r6, MemOperand(r3, kPointerSize));
1915 __ bdnz(&next_capture);
1916
1917 // Return last match info.
1918 __ LoadP(r3, MemOperand(sp, kLastMatchInfoOffset));
1919 __ addi(sp, sp, Operand(4 * kPointerSize));
1920 __ Ret();
1921
1922 // Do the runtime call to execute the regexp.
1923 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001924 __ TailCallRuntime(Runtime::kRegExpExec);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001925
1926 // Deferred code for string handling.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001927 // (5) Long external string? If not, go to (7).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001928 __ bind(&not_seq_nor_cons);
1929 // Compare flags are still set.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001930 __ bgt(&not_long_external); // Go to (7).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001931
Ben Murdoch097c5b22016-05-18 11:27:45 +01001932 // (6) External string. Make it, offset-wise, look like a sequential string.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001933 __ bind(&external_string);
1934 __ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
1935 __ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
1936 if (FLAG_debug_code) {
1937 // Assert that we do not have a cons or slice (indirect strings) here.
1938 // Sequential strings have already been ruled out.
1939 STATIC_ASSERT(kIsIndirectStringMask == 1);
1940 __ andi(r0, r3, Operand(kIsIndirectStringMask));
1941 __ Assert(eq, kExternalStringExpectedButNotFound, cr0);
1942 }
1943 __ LoadP(subject,
1944 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
1945 // Move the pointer so that offset-wise, it looks like a sequential string.
1946 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
1947 __ subi(subject, subject,
1948 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001949 __ b(&seq_string); // Go to (4).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001950
Ben Murdoch097c5b22016-05-18 11:27:45 +01001951 // (7) Short external string or not a string? If yes, bail out to runtime.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001952 __ bind(&not_long_external);
1953 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag != 0);
1954 __ andi(r0, r4, Operand(kIsNotStringMask | kShortExternalStringMask));
1955 __ bne(&runtime, cr0);
1956
Ben Murdoch097c5b22016-05-18 11:27:45 +01001957 // (8) Sliced string. Replace subject with parent. Go to (4).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001958 // Load offset into r11 and replace subject string with parent.
1959 __ LoadP(r11, FieldMemOperand(subject, SlicedString::kOffsetOffset));
1960 __ SmiUntag(r11);
1961 __ LoadP(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
1962 __ b(&check_underlying); // Go to (4).
1963#endif // V8_INTERPRETED_REGEXP
1964}
1965
1966
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001967static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
1968 // r3 : number of arguments to the construct function
1969 // r4 : the function to call
1970 // r5 : feedback vector
1971 // r6 : slot in feedback vector (Smi)
1972 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
1973
1974 // Number-of-arguments register must be smi-tagged to call out.
1975 __ SmiTag(r3);
1976 __ Push(r6, r5, r4, r3);
1977
1978 __ CallStub(stub);
1979
1980 __ Pop(r6, r5, r4, r3);
1981 __ SmiUntag(r3);
1982}
1983
1984
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001985static void GenerateRecordCallTarget(MacroAssembler* masm) {
1986 // Cache the called function in a feedback vector slot. Cache states
1987 // are uninitialized, monomorphic (indicated by a JSFunction), and
1988 // megamorphic.
1989 // r3 : number of arguments to the construct function
1990 // r4 : the function to call
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001991 // r5 : feedback vector
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001992 // r6 : slot in feedback vector (Smi)
1993 Label initialize, done, miss, megamorphic, not_array_function;
1994
1995 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
1996 masm->isolate()->heap()->megamorphic_symbol());
1997 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
1998 masm->isolate()->heap()->uninitialized_symbol());
1999
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002000 // Load the cache state into r8.
2001 __ SmiToPtrArrayOffset(r8, r6);
2002 __ add(r8, r5, r8);
2003 __ LoadP(r8, FieldMemOperand(r8, FixedArray::kHeaderSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002004
2005 // A monomorphic cache hit or an already megamorphic state: invoke the
2006 // function without changing the state.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002007 // We don't know if r8 is a WeakCell or a Symbol, but it's harmless to read at
2008 // this position in a symbol (see static asserts in type-feedback-vector.h).
2009 Label check_allocation_site;
2010 Register feedback_map = r9;
2011 Register weak_value = r10;
2012 __ LoadP(weak_value, FieldMemOperand(r8, WeakCell::kValueOffset));
2013 __ cmp(r4, weak_value);
2014 __ beq(&done);
2015 __ CompareRoot(r8, Heap::kmegamorphic_symbolRootIndex);
2016 __ beq(&done);
2017 __ LoadP(feedback_map, FieldMemOperand(r8, HeapObject::kMapOffset));
2018 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2019 __ bne(&check_allocation_site);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002020
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002021 // If the weak cell is cleared, we have a new chance to become monomorphic.
2022 __ JumpIfSmi(weak_value, &initialize);
2023 __ b(&megamorphic);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002024
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002025 __ bind(&check_allocation_site);
2026 // If we came here, we need to see if we are the array function.
2027 // If we didn't have a matching function, and we didn't find the megamorph
2028 // sentinel, then we have in the slot either some other function or an
2029 // AllocationSite.
2030 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2031 __ bne(&miss);
2032
2033 // Make sure the function is the Array() function
2034 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r8);
2035 __ cmp(r4, r8);
2036 __ bne(&megamorphic);
2037 __ b(&done);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002038
2039 __ bind(&miss);
2040
2041 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2042 // megamorphic.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002043 __ CompareRoot(r8, Heap::kuninitialized_symbolRootIndex);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002044 __ beq(&initialize);
2045 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2046 // write-barrier is needed.
2047 __ bind(&megamorphic);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002048 __ SmiToPtrArrayOffset(r8, r6);
2049 __ add(r8, r5, r8);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002050 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002051 __ StoreP(ip, FieldMemOperand(r8, FixedArray::kHeaderSize), r0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002052 __ jmp(&done);
2053
2054 // An uninitialized cache is patched with the function
2055 __ bind(&initialize);
2056
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002057 // Make sure the function is the Array() function.
2058 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r8);
2059 __ cmp(r4, r8);
2060 __ bne(&not_array_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002061
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002062 // The target function is the Array constructor,
2063 // Create an AllocationSite if we don't already have it, store it in the
2064 // slot.
2065 CreateAllocationSiteStub create_stub(masm->isolate());
2066 CallStubInRecordCallTarget(masm, &create_stub);
2067 __ b(&done);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002068
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002069 __ bind(&not_array_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002070
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002071 CreateWeakCellStub weak_cell_stub(masm->isolate());
2072 CallStubInRecordCallTarget(masm, &weak_cell_stub);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002073 __ bind(&done);
2074}
2075
2076
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002077void CallConstructStub::Generate(MacroAssembler* masm) {
2078 // r3 : number of arguments
2079 // r4 : the function to call
2080 // r5 : feedback vector
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002081 // r6 : slot in feedback vector (Smi, for RecordCallTarget)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002082
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002083 Label non_function;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002084 // Check that the function is not a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002085 __ JumpIfSmi(r4, &non_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002086 // Check that the function is a JSFunction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002087 __ CompareObjectType(r4, r8, r8, JS_FUNCTION_TYPE);
2088 __ bne(&non_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002089
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002090 GenerateRecordCallTarget(masm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002091
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002092 __ SmiToPtrArrayOffset(r8, r6);
2093 __ add(r8, r5, r8);
2094 // Put the AllocationSite from the feedback vector into r5, or undefined.
2095 __ LoadP(r5, FieldMemOperand(r8, FixedArray::kHeaderSize));
2096 __ LoadP(r8, FieldMemOperand(r5, AllocationSite::kMapOffset));
2097 __ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
2098 if (CpuFeatures::IsSupported(ISELECT)) {
2099 __ LoadRoot(r8, Heap::kUndefinedValueRootIndex);
2100 __ isel(eq, r5, r5, r8);
2101 } else {
2102 Label feedback_register_initialized;
2103 __ beq(&feedback_register_initialized);
2104 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
2105 __ bind(&feedback_register_initialized);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002106 }
2107
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002108 __ AssertUndefinedOrAllocationSite(r5, r8);
2109
2110 // Pass function as new target.
2111 __ mr(r6, r4);
2112
2113 // Tail call to the function-specific construct stub (still in the caller
2114 // context at this point).
2115 __ LoadP(r7, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
2116 __ LoadP(r7, FieldMemOperand(r7, SharedFunctionInfo::kConstructStubOffset));
2117 __ addi(ip, r7, Operand(Code::kHeaderSize - kHeapObjectTag));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002118 __ JumpToJSEntry(ip);
2119
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002120 __ bind(&non_function);
2121 __ mr(r6, r4);
2122 __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002123}
2124
2125
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002126void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002127 // r4 - function
2128 // r6 - slot id
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002129 // r5 - vector
2130 // r7 - allocation site (loaded from vector[slot])
2131 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r8);
2132 __ cmp(r4, r8);
2133 __ bne(miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002134
2135 __ mov(r3, Operand(arg_count()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002136
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002137 // Increment the call count for monomorphic function calls.
2138 const int count_offset = FixedArray::kHeaderSize + kPointerSize;
2139 __ SmiToPtrArrayOffset(r8, r6);
2140 __ add(r5, r5, r8);
2141 __ LoadP(r6, FieldMemOperand(r5, count_offset));
2142 __ AddSmiLiteral(r6, r6, Smi::FromInt(CallICNexus::kCallCountIncrement), r0);
2143 __ StoreP(r6, FieldMemOperand(r5, count_offset), r0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002144
2145 __ mr(r5, r7);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002146 __ mr(r6, r4);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002147 ArrayConstructorStub stub(masm->isolate(), arg_count());
2148 __ TailCallStub(&stub);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002149}
2150
2151
2152void CallICStub::Generate(MacroAssembler* masm) {
2153 // r4 - function
2154 // r6 - slot id (Smi)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002155 // r5 - vector
2156 Label extra_checks_or_miss, call, call_function;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002157 int argc = arg_count();
2158 ParameterCount actual(argc);
2159
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002160 // The checks. First, does r4 match the recorded monomorphic target?
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002161 __ SmiToPtrArrayOffset(r9, r6);
2162 __ add(r9, r5, r9);
2163 __ LoadP(r7, FieldMemOperand(r9, FixedArray::kHeaderSize));
2164
2165 // We don't know that we have a weak cell. We might have a private symbol
2166 // or an AllocationSite, but the memory is safe to examine.
2167 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2168 // FixedArray.
2169 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2170 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2171 // computed, meaning that it can't appear to be a pointer. If the low bit is
2172 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2173 // to be a pointer.
2174 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2175 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2176 WeakCell::kValueOffset &&
2177 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2178
2179 __ LoadP(r8, FieldMemOperand(r7, WeakCell::kValueOffset));
2180 __ cmp(r4, r8);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002181 __ bne(&extra_checks_or_miss);
2182
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002183 // The compare above could have been a SMI/SMI comparison. Guard against this
2184 // convincing us that we have a monomorphic JSFunction.
2185 __ JumpIfSmi(r4, &extra_checks_or_miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002186
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002187 // Increment the call count for monomorphic function calls.
2188 const int count_offset = FixedArray::kHeaderSize + kPointerSize;
2189 __ LoadP(r6, FieldMemOperand(r9, count_offset));
2190 __ AddSmiLiteral(r6, r6, Smi::FromInt(CallICNexus::kCallCountIncrement), r0);
2191 __ StoreP(r6, FieldMemOperand(r9, count_offset), r0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002192
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002193 __ bind(&call_function);
2194 __ mov(r3, Operand(argc));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002195 __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(),
2196 tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002197 RelocInfo::CODE_TARGET);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002198
2199 __ bind(&extra_checks_or_miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002200 Label uninitialized, miss, not_allocation_site;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002201
2202 __ CompareRoot(r7, Heap::kmegamorphic_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002203 __ beq(&call);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002204
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002205 // Verify that r7 contains an AllocationSite
2206 __ LoadP(r8, FieldMemOperand(r7, HeapObject::kMapOffset));
2207 __ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
2208 __ bne(&not_allocation_site);
2209
2210 // We have an allocation site.
2211 HandleArrayCase(masm, &miss);
2212
2213 __ bind(&not_allocation_site);
2214
2215 // The following cases attempt to handle MISS cases without going to the
2216 // runtime.
2217 if (FLAG_trace_ic) {
2218 __ b(&miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002219 }
2220
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002221 __ CompareRoot(r7, Heap::kuninitialized_symbolRootIndex);
2222 __ beq(&uninitialized);
2223
2224 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2225 // to handle it here. More complex cases are dealt with in the runtime.
2226 __ AssertNotSmi(r7);
2227 __ CompareObjectType(r7, r8, r8, JS_FUNCTION_TYPE);
2228 __ bne(&miss);
2229 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2230 __ StoreP(ip, FieldMemOperand(r9, FixedArray::kHeaderSize), r0);
2231
2232 __ bind(&call);
2233 __ mov(r3, Operand(argc));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002234 __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002235 RelocInfo::CODE_TARGET);
2236
2237 __ bind(&uninitialized);
2238
2239 // We are going monomorphic, provided we actually have a JSFunction.
2240 __ JumpIfSmi(r4, &miss);
2241
2242 // Goto miss case if we do not have a function.
2243 __ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
2244 __ bne(&miss);
2245
2246 // Make sure the function is not the Array() function, which requires special
2247 // behavior on MISS.
2248 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r7);
2249 __ cmp(r4, r7);
2250 __ beq(&miss);
2251
2252 // Make sure the function belongs to the same native context.
2253 __ LoadP(r7, FieldMemOperand(r4, JSFunction::kContextOffset));
2254 __ LoadP(r7, ContextMemOperand(r7, Context::NATIVE_CONTEXT_INDEX));
2255 __ LoadP(ip, NativeContextMemOperand());
2256 __ cmp(r7, ip);
2257 __ bne(&miss);
2258
2259 // Initialize the call counter.
2260 __ LoadSmiLiteral(r8, Smi::FromInt(CallICNexus::kCallCountIncrement));
2261 __ StoreP(r8, FieldMemOperand(r9, count_offset), r0);
2262
2263 // Store the function. Use a stub since we need a frame for allocation.
2264 // r5 - vector
2265 // r6 - slot
2266 // r4 - function
2267 {
2268 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2269 CreateWeakCellStub create_stub(masm->isolate());
2270 __ Push(r4);
2271 __ CallStub(&create_stub);
2272 __ Pop(r4);
2273 }
2274
2275 __ b(&call_function);
2276
2277 // We are here because tracing is on or we encountered a MISS case we can't
2278 // handle here.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002279 __ bind(&miss);
2280 GenerateMiss(masm);
2281
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002282 __ b(&call);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002283}
2284
2285
2286void CallICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002287 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002288
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002289 // Push the function and feedback info.
2290 __ Push(r4, r5, r6);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002291
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002292 // Call the entry.
2293 __ CallRuntime(Runtime::kCallIC_Miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002294
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002295 // Move result to r4 and exit the internal frame.
2296 __ mr(r4, r3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002297}
2298
2299
2300// StringCharCodeAtGenerator
2301void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2302 // If the receiver is a smi trigger the non-string case.
2303 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2304 __ JumpIfSmi(object_, receiver_not_string_);
2305
2306 // Fetch the instance type of the receiver into result register.
2307 __ LoadP(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2308 __ lbz(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2309 // If the receiver is not a string trigger the non-string case.
2310 __ andi(r0, result_, Operand(kIsNotStringMask));
2311 __ bne(receiver_not_string_, cr0);
2312 }
2313
2314 // If the index is non-smi trigger the non-smi case.
2315 __ JumpIfNotSmi(index_, &index_not_smi_);
2316 __ bind(&got_smi_index_);
2317
2318 // Check for index out of range.
2319 __ LoadP(ip, FieldMemOperand(object_, String::kLengthOffset));
2320 __ cmpl(ip, index_);
2321 __ ble(index_out_of_range_);
2322
2323 __ SmiUntag(index_);
2324
2325 StringCharLoadGenerator::Generate(masm, object_, index_, result_,
2326 &call_runtime_);
2327
2328 __ SmiTag(result_);
2329 __ bind(&exit_);
2330}
2331
2332
2333void StringCharCodeAtGenerator::GenerateSlow(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002334 MacroAssembler* masm, EmbedMode embed_mode,
2335 const RuntimeCallHelper& call_helper) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002336 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2337
2338 // Index is not a smi.
2339 __ bind(&index_not_smi_);
2340 // If index is a heap number, try converting it to an integer.
2341 __ CheckMap(index_, result_, Heap::kHeapNumberMapRootIndex, index_not_number_,
2342 DONT_DO_SMI_CHECK);
2343 call_helper.BeforeCall(masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002344 if (embed_mode == PART_OF_IC_HANDLER) {
2345 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2346 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2347 } else {
2348 // index_ is consumed by runtime conversion function.
2349 __ Push(object_, index_);
2350 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002351 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002352 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002353 } else {
2354 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2355 // NumberToSmi discards numbers that are not exact integers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002356 __ CallRuntime(Runtime::kNumberToSmi);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002357 }
2358 // Save the conversion result before the pop instructions below
2359 // have a chance to overwrite it.
2360 __ Move(index_, r3);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002361 if (embed_mode == PART_OF_IC_HANDLER) {
2362 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2363 LoadWithVectorDescriptor::SlotRegister(), object_);
2364 } else {
2365 __ pop(object_);
2366 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002367 // Reload the instance type.
2368 __ LoadP(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2369 __ lbz(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2370 call_helper.AfterCall(masm);
2371 // If index is still not a smi, it must be out of range.
2372 __ JumpIfNotSmi(index_, index_out_of_range_);
2373 // Otherwise, return to the fast path.
2374 __ b(&got_smi_index_);
2375
2376 // Call runtime. We get here when the receiver is a string and the
2377 // index is a number, but the code of getting the actual character
2378 // is too complex (e.g., when the string needs to be flattened).
2379 __ bind(&call_runtime_);
2380 call_helper.BeforeCall(masm);
2381 __ SmiTag(index_);
2382 __ Push(object_, index_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002383 __ CallRuntime(Runtime::kStringCharCodeAtRT);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002384 __ Move(result_, r3);
2385 call_helper.AfterCall(masm);
2386 __ b(&exit_);
2387
2388 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2389}
2390
2391
2392// -------------------------------------------------------------------------
2393// StringCharFromCodeGenerator
2394
2395void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2396 // Fast case of Heap::LookupSingleCharacterStringFromCode.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002397 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2398 __ LoadSmiLiteral(r0, Smi::FromInt(~String::kMaxOneByteCharCodeU));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002399 __ ori(r0, r0, Operand(kSmiTagMask));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002400 __ and_(r0, code_, r0, SetRC);
2401 __ bne(&slow_case_, cr0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002402
2403 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2404 // At this point code register contains smi tagged one-byte char code.
2405 __ mr(r0, code_);
2406 __ SmiToPtrArrayOffset(code_, code_);
2407 __ add(result_, result_, code_);
2408 __ mr(code_, r0);
2409 __ LoadP(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
2410 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
2411 __ beq(&slow_case_);
2412 __ bind(&exit_);
2413}
2414
2415
2416void StringCharFromCodeGenerator::GenerateSlow(
2417 MacroAssembler* masm, const RuntimeCallHelper& call_helper) {
2418 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2419
2420 __ bind(&slow_case_);
2421 call_helper.BeforeCall(masm);
2422 __ push(code_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002423 __ CallRuntime(Runtime::kStringCharFromCode);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002424 __ Move(result_, r3);
2425 call_helper.AfterCall(masm);
2426 __ b(&exit_);
2427
2428 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2429}
2430
2431
2432enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
2433
2434
2435void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, Register dest,
2436 Register src, Register count,
2437 Register scratch,
2438 String::Encoding encoding) {
2439 if (FLAG_debug_code) {
2440 // Check that destination is word aligned.
2441 __ andi(r0, dest, Operand(kPointerAlignmentMask));
2442 __ Check(eq, kDestinationOfCopyNotAligned, cr0);
2443 }
2444
2445 // Nothing to do for zero characters.
2446 Label done;
2447 if (encoding == String::TWO_BYTE_ENCODING) {
2448 // double the length
2449 __ add(count, count, count, LeaveOE, SetRC);
2450 __ beq(&done, cr0);
2451 } else {
2452 __ cmpi(count, Operand::Zero());
2453 __ beq(&done);
2454 }
2455
2456 // Copy count bytes from src to dst.
2457 Label byte_loop;
2458 __ mtctr(count);
2459 __ bind(&byte_loop);
2460 __ lbz(scratch, MemOperand(src));
2461 __ addi(src, src, Operand(1));
2462 __ stb(scratch, MemOperand(dest));
2463 __ addi(dest, dest, Operand(1));
2464 __ bdnz(&byte_loop);
2465
2466 __ bind(&done);
2467}
2468
2469
2470void SubStringStub::Generate(MacroAssembler* masm) {
2471 Label runtime;
2472
2473 // Stack frame on entry.
2474 // lr: return address
2475 // sp[0]: to
2476 // sp[4]: from
2477 // sp[8]: string
2478
2479 // This stub is called from the native-call %_SubString(...), so
2480 // nothing can be assumed about the arguments. It is tested that:
2481 // "string" is a sequential string,
2482 // both "from" and "to" are smis, and
2483 // 0 <= from <= to <= string.length.
2484 // If any of these assumptions fail, we call the runtime system.
2485
2486 const int kToOffset = 0 * kPointerSize;
2487 const int kFromOffset = 1 * kPointerSize;
2488 const int kStringOffset = 2 * kPointerSize;
2489
2490 __ LoadP(r5, MemOperand(sp, kToOffset));
2491 __ LoadP(r6, MemOperand(sp, kFromOffset));
2492
2493 // If either to or from had the smi tag bit set, then fail to generic runtime
2494 __ JumpIfNotSmi(r5, &runtime);
2495 __ JumpIfNotSmi(r6, &runtime);
2496 __ SmiUntag(r5);
2497 __ SmiUntag(r6, SetRC);
2498 // Both r5 and r6 are untagged integers.
2499
2500 // We want to bailout to runtime here if From is negative.
2501 __ blt(&runtime, cr0); // From < 0.
2502
2503 __ cmpl(r6, r5);
2504 __ bgt(&runtime); // Fail if from > to.
2505 __ sub(r5, r5, r6);
2506
2507 // Make sure first argument is a string.
2508 __ LoadP(r3, MemOperand(sp, kStringOffset));
2509 __ JumpIfSmi(r3, &runtime);
2510 Condition is_string = masm->IsObjectStringType(r3, r4);
2511 __ b(NegateCondition(is_string), &runtime, cr0);
2512
2513 Label single_char;
2514 __ cmpi(r5, Operand(1));
2515 __ b(eq, &single_char);
2516
2517 // Short-cut for the case of trivial substring.
2518 Label return_r3;
2519 // r3: original string
2520 // r5: result string length
2521 __ LoadP(r7, FieldMemOperand(r3, String::kLengthOffset));
2522 __ SmiUntag(r0, r7);
2523 __ cmpl(r5, r0);
2524 // Return original string.
2525 __ beq(&return_r3);
2526 // Longer than original string's length or negative: unsafe arguments.
2527 __ bgt(&runtime);
2528 // Shorter than original string's length: an actual substring.
2529
2530 // Deal with different string types: update the index if necessary
2531 // and put the underlying string into r8.
2532 // r3: original string
2533 // r4: instance type
2534 // r5: length
2535 // r6: from index (untagged)
2536 Label underlying_unpacked, sliced_string, seq_or_external_string;
2537 // If the string is not indirect, it can only be sequential or external.
2538 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2539 STATIC_ASSERT(kIsIndirectStringMask != 0);
2540 __ andi(r0, r4, Operand(kIsIndirectStringMask));
2541 __ beq(&seq_or_external_string, cr0);
2542
2543 __ andi(r0, r4, Operand(kSlicedNotConsMask));
2544 __ bne(&sliced_string, cr0);
2545 // Cons string. Check whether it is flat, then fetch first part.
2546 __ LoadP(r8, FieldMemOperand(r3, ConsString::kSecondOffset));
2547 __ CompareRoot(r8, Heap::kempty_stringRootIndex);
2548 __ bne(&runtime);
2549 __ LoadP(r8, FieldMemOperand(r3, ConsString::kFirstOffset));
2550 // Update instance type.
2551 __ LoadP(r4, FieldMemOperand(r8, HeapObject::kMapOffset));
2552 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
2553 __ b(&underlying_unpacked);
2554
2555 __ bind(&sliced_string);
2556 // Sliced string. Fetch parent and correct start index by offset.
2557 __ LoadP(r8, FieldMemOperand(r3, SlicedString::kParentOffset));
2558 __ LoadP(r7, FieldMemOperand(r3, SlicedString::kOffsetOffset));
2559 __ SmiUntag(r4, r7);
2560 __ add(r6, r6, r4); // Add offset to index.
2561 // Update instance type.
2562 __ LoadP(r4, FieldMemOperand(r8, HeapObject::kMapOffset));
2563 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
2564 __ b(&underlying_unpacked);
2565
2566 __ bind(&seq_or_external_string);
2567 // Sequential or external string. Just move string to the expected register.
2568 __ mr(r8, r3);
2569
2570 __ bind(&underlying_unpacked);
2571
2572 if (FLAG_string_slices) {
2573 Label copy_routine;
2574 // r8: underlying subject string
2575 // r4: instance type of underlying subject string
2576 // r5: length
2577 // r6: adjusted start index (untagged)
2578 __ cmpi(r5, Operand(SlicedString::kMinLength));
2579 // Short slice. Copy instead of slicing.
2580 __ blt(&copy_routine);
2581 // Allocate new sliced string. At this point we do not reload the instance
2582 // type including the string encoding because we simply rely on the info
2583 // provided by the original string. It does not matter if the original
2584 // string's encoding is wrong because we always have to recheck encoding of
2585 // the newly created string's parent anyways due to externalized strings.
2586 Label two_byte_slice, set_slice_header;
2587 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
2588 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2589 __ andi(r0, r4, Operand(kStringEncodingMask));
2590 __ beq(&two_byte_slice, cr0);
2591 __ AllocateOneByteSlicedString(r3, r5, r9, r10, &runtime);
2592 __ b(&set_slice_header);
2593 __ bind(&two_byte_slice);
2594 __ AllocateTwoByteSlicedString(r3, r5, r9, r10, &runtime);
2595 __ bind(&set_slice_header);
2596 __ SmiTag(r6);
2597 __ StoreP(r8, FieldMemOperand(r3, SlicedString::kParentOffset), r0);
2598 __ StoreP(r6, FieldMemOperand(r3, SlicedString::kOffsetOffset), r0);
2599 __ b(&return_r3);
2600
2601 __ bind(&copy_routine);
2602 }
2603
2604 // r8: underlying subject string
2605 // r4: instance type of underlying subject string
2606 // r5: length
2607 // r6: adjusted start index (untagged)
2608 Label two_byte_sequential, sequential_string, allocate_result;
2609 STATIC_ASSERT(kExternalStringTag != 0);
2610 STATIC_ASSERT(kSeqStringTag == 0);
2611 __ andi(r0, r4, Operand(kExternalStringTag));
2612 __ beq(&sequential_string, cr0);
2613
2614 // Handle external string.
2615 // Rule out short external strings.
2616 STATIC_ASSERT(kShortExternalStringTag != 0);
2617 __ andi(r0, r4, Operand(kShortExternalStringTag));
2618 __ bne(&runtime, cr0);
2619 __ LoadP(r8, FieldMemOperand(r8, ExternalString::kResourceDataOffset));
2620 // r8 already points to the first character of underlying string.
2621 __ b(&allocate_result);
2622
2623 __ bind(&sequential_string);
2624 // Locate first character of underlying subject string.
2625 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2626 __ addi(r8, r8, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2627
2628 __ bind(&allocate_result);
2629 // Sequential acii string. Allocate the result.
2630 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
2631 __ andi(r0, r4, Operand(kStringEncodingMask));
2632 __ beq(&two_byte_sequential, cr0);
2633
2634 // Allocate and copy the resulting one-byte string.
2635 __ AllocateOneByteString(r3, r5, r7, r9, r10, &runtime);
2636
2637 // Locate first character of substring to copy.
2638 __ add(r8, r8, r6);
2639 // Locate first character of result.
2640 __ addi(r4, r3, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2641
2642 // r3: result string
2643 // r4: first character of result string
2644 // r5: result string length
2645 // r8: first character of substring to copy
2646 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2647 StringHelper::GenerateCopyCharacters(masm, r4, r8, r5, r6,
2648 String::ONE_BYTE_ENCODING);
2649 __ b(&return_r3);
2650
2651 // Allocate and copy the resulting two-byte string.
2652 __ bind(&two_byte_sequential);
2653 __ AllocateTwoByteString(r3, r5, r7, r9, r10, &runtime);
2654
2655 // Locate first character of substring to copy.
2656 __ ShiftLeftImm(r4, r6, Operand(1));
2657 __ add(r8, r8, r4);
2658 // Locate first character of result.
2659 __ addi(r4, r3, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2660
2661 // r3: result string.
2662 // r4: first character of result.
2663 // r5: result length.
2664 // r8: first character of substring to copy.
2665 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2666 StringHelper::GenerateCopyCharacters(masm, r4, r8, r5, r6,
2667 String::TWO_BYTE_ENCODING);
2668
2669 __ bind(&return_r3);
2670 Counters* counters = isolate()->counters();
2671 __ IncrementCounter(counters->sub_string_native(), 1, r6, r7);
2672 __ Drop(3);
2673 __ Ret();
2674
2675 // Just jump to runtime to create the sub string.
2676 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002677 __ TailCallRuntime(Runtime::kSubString);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002678
2679 __ bind(&single_char);
2680 // r3: original string
2681 // r4: instance type
2682 // r5: length
2683 // r6: from index (untagged)
2684 __ SmiTag(r6, r6);
2685 StringCharAtGenerator generator(r3, r6, r5, r3, &runtime, &runtime, &runtime,
2686 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
2687 generator.GenerateFast(masm);
2688 __ Drop(3);
2689 __ Ret();
2690 generator.SkipSlow(masm, &runtime);
2691}
2692
2693
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002694void ToNumberStub::Generate(MacroAssembler* masm) {
2695 // The ToNumber stub takes one argument in r3.
Ben Murdochda12d292016-06-02 14:46:10 +01002696 STATIC_ASSERT(kSmiTag == 0);
2697 __ TestIfSmi(r3, r0);
2698 __ Ret(eq, cr0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002699
2700 __ CompareObjectType(r3, r4, r4, HEAP_NUMBER_TYPE);
2701 // r3: receiver
2702 // r4: receiver instance type
2703 __ Ret(eq);
2704
Ben Murdochda12d292016-06-02 14:46:10 +01002705 NonNumberToNumberStub stub(masm->isolate());
2706 __ TailCallStub(&stub);
2707}
2708
2709void NonNumberToNumberStub::Generate(MacroAssembler* masm) {
2710 // The NonNumberToNumber stub takes one argument in r3.
2711 __ AssertNotNumber(r3);
2712
2713 __ CompareObjectType(r3, r4, r4, FIRST_NONSTRING_TYPE);
2714 // r3: receiver
2715 // r4: receiver instance type
2716 StringToNumberStub stub(masm->isolate());
2717 __ TailCallStub(&stub, lt);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002718
2719 Label not_oddball;
2720 __ cmpi(r4, Operand(ODDBALL_TYPE));
2721 __ bne(&not_oddball);
2722 __ LoadP(r3, FieldMemOperand(r3, Oddball::kToNumberOffset));
2723 __ blr();
2724 __ bind(&not_oddball);
2725
2726 __ push(r3); // Push argument.
2727 __ TailCallRuntime(Runtime::kToNumber);
2728}
2729
Ben Murdochda12d292016-06-02 14:46:10 +01002730void StringToNumberStub::Generate(MacroAssembler* masm) {
2731 // The StringToNumber stub takes one argument in r3.
2732 __ AssertString(r3);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002733
Ben Murdochda12d292016-06-02 14:46:10 +01002734 // Check if string has a cached array index.
2735 Label runtime;
2736 __ lwz(r5, FieldMemOperand(r3, String::kHashFieldOffset));
2737 __ And(r0, r5, Operand(String::kContainsCachedArrayIndexMask), SetRC);
2738 __ bne(&runtime, cr0);
2739 __ IndexFromHash(r5, r3);
2740 __ blr();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002741
Ben Murdochda12d292016-06-02 14:46:10 +01002742 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002743 __ push(r3); // Push argument.
Ben Murdochda12d292016-06-02 14:46:10 +01002744 __ TailCallRuntime(Runtime::kStringToNumber);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002745}
2746
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002747void ToStringStub::Generate(MacroAssembler* masm) {
2748 // The ToString stub takes one argument in r3.
2749 Label is_number;
2750 __ JumpIfSmi(r3, &is_number);
2751
2752 __ CompareObjectType(r3, r4, r4, FIRST_NONSTRING_TYPE);
2753 // r3: receiver
2754 // r4: receiver instance type
2755 __ Ret(lt);
2756
2757 Label not_heap_number;
2758 __ cmpi(r4, Operand(HEAP_NUMBER_TYPE));
2759 __ bne(&not_heap_number);
2760 __ bind(&is_number);
2761 NumberToStringStub stub(isolate());
2762 __ TailCallStub(&stub);
2763 __ bind(&not_heap_number);
2764
2765 Label not_oddball;
2766 __ cmpi(r4, Operand(ODDBALL_TYPE));
2767 __ bne(&not_oddball);
2768 __ LoadP(r3, FieldMemOperand(r3, Oddball::kToStringOffset));
2769 __ Ret();
2770 __ bind(&not_oddball);
2771
2772 __ push(r3); // Push argument.
2773 __ TailCallRuntime(Runtime::kToString);
2774}
2775
2776
Ben Murdoch097c5b22016-05-18 11:27:45 +01002777void ToNameStub::Generate(MacroAssembler* masm) {
2778 // The ToName stub takes one argument in r3.
2779 Label is_number;
2780 __ JumpIfSmi(r3, &is_number);
2781
2782 STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
2783 __ CompareObjectType(r3, r4, r4, LAST_NAME_TYPE);
2784 // r3: receiver
2785 // r4: receiver instance type
2786 __ Ret(le);
2787
2788 Label not_heap_number;
2789 __ cmpi(r4, Operand(HEAP_NUMBER_TYPE));
2790 __ bne(&not_heap_number);
2791 __ bind(&is_number);
2792 NumberToStringStub stub(isolate());
2793 __ TailCallStub(&stub);
2794 __ bind(&not_heap_number);
2795
2796 Label not_oddball;
2797 __ cmpi(r4, Operand(ODDBALL_TYPE));
2798 __ bne(&not_oddball);
2799 __ LoadP(r3, FieldMemOperand(r3, Oddball::kToStringOffset));
2800 __ Ret();
2801 __ bind(&not_oddball);
2802
2803 __ push(r3); // Push argument.
2804 __ TailCallRuntime(Runtime::kToName);
2805}
2806
2807
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002808void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
2809 Register left,
2810 Register right,
2811 Register scratch1,
2812 Register scratch2) {
2813 Register length = scratch1;
2814
2815 // Compare lengths.
2816 Label strings_not_equal, check_zero_length;
2817 __ LoadP(length, FieldMemOperand(left, String::kLengthOffset));
2818 __ LoadP(scratch2, FieldMemOperand(right, String::kLengthOffset));
2819 __ cmp(length, scratch2);
2820 __ beq(&check_zero_length);
2821 __ bind(&strings_not_equal);
2822 __ LoadSmiLiteral(r3, Smi::FromInt(NOT_EQUAL));
2823 __ Ret();
2824
2825 // Check if the length is zero.
2826 Label compare_chars;
2827 __ bind(&check_zero_length);
2828 STATIC_ASSERT(kSmiTag == 0);
2829 __ cmpi(length, Operand::Zero());
2830 __ bne(&compare_chars);
2831 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
2832 __ Ret();
2833
2834 // Compare characters.
2835 __ bind(&compare_chars);
2836 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2,
2837 &strings_not_equal);
2838
2839 // Characters are equal.
2840 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
2841 __ Ret();
2842}
2843
2844
2845void StringHelper::GenerateCompareFlatOneByteStrings(
2846 MacroAssembler* masm, Register left, Register right, Register scratch1,
2847 Register scratch2, Register scratch3) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002848 Label result_not_equal, compare_lengths;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002849 // Find minimum length and length difference.
2850 __ LoadP(scratch1, FieldMemOperand(left, String::kLengthOffset));
2851 __ LoadP(scratch2, FieldMemOperand(right, String::kLengthOffset));
2852 __ sub(scratch3, scratch1, scratch2, LeaveOE, SetRC);
2853 Register length_delta = scratch3;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002854 if (CpuFeatures::IsSupported(ISELECT)) {
2855 __ isel(gt, scratch1, scratch2, scratch1, cr0);
2856 } else {
2857 Label skip;
2858 __ ble(&skip, cr0);
2859 __ mr(scratch1, scratch2);
2860 __ bind(&skip);
2861 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002862 Register min_length = scratch1;
2863 STATIC_ASSERT(kSmiTag == 0);
2864 __ cmpi(min_length, Operand::Zero());
2865 __ beq(&compare_lengths);
2866
2867 // Compare loop.
2868 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
2869 &result_not_equal);
2870
2871 // Compare lengths - strings up to min-length are equal.
2872 __ bind(&compare_lengths);
2873 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
2874 // Use length_delta as result if it's zero.
2875 __ mr(r3, length_delta);
2876 __ cmpi(r3, Operand::Zero());
2877 __ bind(&result_not_equal);
2878 // Conditionally update the result based either on length_delta or
2879 // the last comparion performed in the loop above.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002880 if (CpuFeatures::IsSupported(ISELECT)) {
2881 __ LoadSmiLiteral(r4, Smi::FromInt(GREATER));
2882 __ LoadSmiLiteral(r5, Smi::FromInt(LESS));
2883 __ isel(eq, r3, r0, r4);
2884 __ isel(lt, r3, r5, r3);
2885 __ Ret();
2886 } else {
2887 Label less_equal, equal;
2888 __ ble(&less_equal);
2889 __ LoadSmiLiteral(r3, Smi::FromInt(GREATER));
2890 __ Ret();
2891 __ bind(&less_equal);
2892 __ beq(&equal);
2893 __ LoadSmiLiteral(r3, Smi::FromInt(LESS));
2894 __ bind(&equal);
2895 __ Ret();
2896 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002897}
2898
2899
2900void StringHelper::GenerateOneByteCharsCompareLoop(
2901 MacroAssembler* masm, Register left, Register right, Register length,
2902 Register scratch1, Label* chars_not_equal) {
2903 // Change index to run from -length to -1 by adding length to string
2904 // start. This means that loop ends when index reaches zero, which
2905 // doesn't need an additional compare.
2906 __ SmiUntag(length);
2907 __ addi(scratch1, length,
2908 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2909 __ add(left, left, scratch1);
2910 __ add(right, right, scratch1);
2911 __ subfic(length, length, Operand::Zero());
2912 Register index = length; // index = -length;
2913
2914 // Compare loop.
2915 Label loop;
2916 __ bind(&loop);
2917 __ lbzx(scratch1, MemOperand(left, index));
2918 __ lbzx(r0, MemOperand(right, index));
2919 __ cmp(scratch1, r0);
2920 __ bne(chars_not_equal);
2921 __ addi(index, index, Operand(1));
2922 __ cmpi(index, Operand::Zero());
2923 __ bne(&loop);
2924}
2925
2926
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002927void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
2928 // ----------- S t a t e -------------
2929 // -- r4 : left
2930 // -- r3 : right
2931 // -- lr : return address
2932 // -----------------------------------
2933
2934 // Load r5 with the allocation site. We stick an undefined dummy value here
2935 // and replace it with the real allocation site later when we instantiate this
2936 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
2937 __ Move(r5, handle(isolate()->heap()->undefined_value()));
2938
2939 // Make sure that we actually patched the allocation site.
2940 if (FLAG_debug_code) {
2941 __ TestIfSmi(r5, r0);
2942 __ Assert(ne, kExpectedAllocationSite, cr0);
2943 __ push(r5);
2944 __ LoadP(r5, FieldMemOperand(r5, HeapObject::kMapOffset));
2945 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
2946 __ cmp(r5, ip);
2947 __ pop(r5);
2948 __ Assert(eq, kExpectedAllocationSite);
2949 }
2950
2951 // Tail call into the stub that handles binary operations with allocation
2952 // sites.
2953 BinaryOpWithAllocationSiteStub stub(isolate(), state());
2954 __ TailCallStub(&stub);
2955}
2956
2957
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002958void CompareICStub::GenerateBooleans(MacroAssembler* masm) {
2959 DCHECK_EQ(CompareICState::BOOLEAN, state());
2960 Label miss;
2961
2962 __ CheckMap(r4, r5, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
2963 __ CheckMap(r3, r6, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002964 if (!Token::IsEqualityOp(op())) {
2965 __ LoadP(r4, FieldMemOperand(r4, Oddball::kToNumberOffset));
2966 __ AssertSmi(r4);
2967 __ LoadP(r3, FieldMemOperand(r3, Oddball::kToNumberOffset));
2968 __ AssertSmi(r3);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002969 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002970 __ sub(r3, r4, r3);
2971 __ Ret();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002972
2973 __ bind(&miss);
2974 GenerateMiss(masm);
2975}
2976
2977
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002978void CompareICStub::GenerateSmis(MacroAssembler* masm) {
2979 DCHECK(state() == CompareICState::SMI);
2980 Label miss;
2981 __ orx(r5, r4, r3);
2982 __ JumpIfNotSmi(r5, &miss);
2983
2984 if (GetCondition() == eq) {
2985 // For equality we do not care about the sign of the result.
2986 // __ sub(r3, r3, r4, SetCC);
2987 __ sub(r3, r3, r4);
2988 } else {
2989 // Untag before subtracting to avoid handling overflow.
2990 __ SmiUntag(r4);
2991 __ SmiUntag(r3);
2992 __ sub(r3, r4, r3);
2993 }
2994 __ Ret();
2995
2996 __ bind(&miss);
2997 GenerateMiss(masm);
2998}
2999
3000
3001void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3002 DCHECK(state() == CompareICState::NUMBER);
3003
3004 Label generic_stub;
3005 Label unordered, maybe_undefined1, maybe_undefined2;
3006 Label miss;
3007 Label equal, less_than;
3008
3009 if (left() == CompareICState::SMI) {
3010 __ JumpIfNotSmi(r4, &miss);
3011 }
3012 if (right() == CompareICState::SMI) {
3013 __ JumpIfNotSmi(r3, &miss);
3014 }
3015
3016 // Inlining the double comparison and falling back to the general compare
3017 // stub if NaN is involved.
3018 // Load left and right operand.
3019 Label done, left, left_smi, right_smi;
3020 __ JumpIfSmi(r3, &right_smi);
3021 __ CheckMap(r3, r5, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3022 DONT_DO_SMI_CHECK);
3023 __ lfd(d1, FieldMemOperand(r3, HeapNumber::kValueOffset));
3024 __ b(&left);
3025 __ bind(&right_smi);
3026 __ SmiToDouble(d1, r3);
3027
3028 __ bind(&left);
3029 __ JumpIfSmi(r4, &left_smi);
3030 __ CheckMap(r4, r5, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3031 DONT_DO_SMI_CHECK);
3032 __ lfd(d0, FieldMemOperand(r4, HeapNumber::kValueOffset));
3033 __ b(&done);
3034 __ bind(&left_smi);
3035 __ SmiToDouble(d0, r4);
3036
3037 __ bind(&done);
3038
3039 // Compare operands
3040 __ fcmpu(d0, d1);
3041
3042 // Don't base result on status bits when a NaN is involved.
3043 __ bunordered(&unordered);
3044
3045 // Return a result of -1, 0, or 1, based on status bits.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003046 if (CpuFeatures::IsSupported(ISELECT)) {
3047 DCHECK(EQUAL == 0);
3048 __ li(r4, Operand(GREATER));
3049 __ li(r5, Operand(LESS));
3050 __ isel(eq, r3, r0, r4);
3051 __ isel(lt, r3, r5, r3);
3052 __ Ret();
3053 } else {
3054 __ beq(&equal);
3055 __ blt(&less_than);
3056 // assume greater than
3057 __ li(r3, Operand(GREATER));
3058 __ Ret();
3059 __ bind(&equal);
3060 __ li(r3, Operand(EQUAL));
3061 __ Ret();
3062 __ bind(&less_than);
3063 __ li(r3, Operand(LESS));
3064 __ Ret();
3065 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003066
3067 __ bind(&unordered);
3068 __ bind(&generic_stub);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003069 CompareICStub stub(isolate(), op(), CompareICState::GENERIC,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003070 CompareICState::GENERIC, CompareICState::GENERIC);
3071 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3072
3073 __ bind(&maybe_undefined1);
3074 if (Token::IsOrderedRelationalCompareOp(op())) {
3075 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
3076 __ bne(&miss);
3077 __ JumpIfSmi(r4, &unordered);
3078 __ CompareObjectType(r4, r5, r5, HEAP_NUMBER_TYPE);
3079 __ bne(&maybe_undefined2);
3080 __ b(&unordered);
3081 }
3082
3083 __ bind(&maybe_undefined2);
3084 if (Token::IsOrderedRelationalCompareOp(op())) {
3085 __ CompareRoot(r4, Heap::kUndefinedValueRootIndex);
3086 __ beq(&unordered);
3087 }
3088
3089 __ bind(&miss);
3090 GenerateMiss(masm);
3091}
3092
3093
3094void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3095 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3096 Label miss, not_equal;
3097
3098 // Registers containing left and right operands respectively.
3099 Register left = r4;
3100 Register right = r3;
3101 Register tmp1 = r5;
3102 Register tmp2 = r6;
3103
3104 // Check that both operands are heap objects.
3105 __ JumpIfEitherSmi(left, right, &miss);
3106
3107 // Check that both operands are symbols.
3108 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3109 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3110 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3111 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3112 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3113 __ orx(tmp1, tmp1, tmp2);
3114 __ andi(r0, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3115 __ bne(&miss, cr0);
3116
3117 // Internalized strings are compared by identity.
3118 __ cmp(left, right);
3119 __ bne(&not_equal);
3120 // Make sure r3 is non-zero. At this point input operands are
3121 // guaranteed to be non-zero.
3122 DCHECK(right.is(r3));
3123 STATIC_ASSERT(EQUAL == 0);
3124 STATIC_ASSERT(kSmiTag == 0);
3125 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3126 __ bind(&not_equal);
3127 __ Ret();
3128
3129 __ bind(&miss);
3130 GenerateMiss(masm);
3131}
3132
3133
3134void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3135 DCHECK(state() == CompareICState::UNIQUE_NAME);
3136 DCHECK(GetCondition() == eq);
3137 Label miss;
3138
3139 // Registers containing left and right operands respectively.
3140 Register left = r4;
3141 Register right = r3;
3142 Register tmp1 = r5;
3143 Register tmp2 = r6;
3144
3145 // Check that both operands are heap objects.
3146 __ JumpIfEitherSmi(left, right, &miss);
3147
3148 // Check that both operands are unique names. This leaves the instance
3149 // types loaded in tmp1 and tmp2.
3150 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3151 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3152 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3153 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3154
3155 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3156 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3157
3158 // Unique names are compared by identity.
3159 __ cmp(left, right);
3160 __ bne(&miss);
3161 // Make sure r3 is non-zero. At this point input operands are
3162 // guaranteed to be non-zero.
3163 DCHECK(right.is(r3));
3164 STATIC_ASSERT(EQUAL == 0);
3165 STATIC_ASSERT(kSmiTag == 0);
3166 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3167 __ Ret();
3168
3169 __ bind(&miss);
3170 GenerateMiss(masm);
3171}
3172
3173
3174void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3175 DCHECK(state() == CompareICState::STRING);
3176 Label miss, not_identical, is_symbol;
3177
3178 bool equality = Token::IsEqualityOp(op());
3179
3180 // Registers containing left and right operands respectively.
3181 Register left = r4;
3182 Register right = r3;
3183 Register tmp1 = r5;
3184 Register tmp2 = r6;
3185 Register tmp3 = r7;
3186 Register tmp4 = r8;
3187
3188 // Check that both operands are heap objects.
3189 __ JumpIfEitherSmi(left, right, &miss);
3190
3191 // Check that both operands are strings. This leaves the instance
3192 // types loaded in tmp1 and tmp2.
3193 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3194 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3195 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3196 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3197 STATIC_ASSERT(kNotStringTag != 0);
3198 __ orx(tmp3, tmp1, tmp2);
3199 __ andi(r0, tmp3, Operand(kIsNotStringMask));
3200 __ bne(&miss, cr0);
3201
3202 // Fast check for identical strings.
3203 __ cmp(left, right);
3204 STATIC_ASSERT(EQUAL == 0);
3205 STATIC_ASSERT(kSmiTag == 0);
3206 __ bne(&not_identical);
3207 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3208 __ Ret();
3209 __ bind(&not_identical);
3210
3211 // Handle not identical strings.
3212
3213 // Check that both strings are internalized strings. If they are, we're done
3214 // because we already know they are not identical. We know they are both
3215 // strings.
3216 if (equality) {
3217 DCHECK(GetCondition() == eq);
3218 STATIC_ASSERT(kInternalizedTag == 0);
3219 __ orx(tmp3, tmp1, tmp2);
3220 __ andi(r0, tmp3, Operand(kIsNotInternalizedMask));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003221 // Make sure r3 is non-zero. At this point input operands are
3222 // guaranteed to be non-zero.
3223 DCHECK(right.is(r3));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003224 __ Ret(eq, cr0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003225 }
3226
3227 // Check that both strings are sequential one-byte.
3228 Label runtime;
3229 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3230 &runtime);
3231
3232 // Compare flat one-byte strings. Returns when done.
3233 if (equality) {
3234 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1,
3235 tmp2);
3236 } else {
3237 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3238 tmp2, tmp3);
3239 }
3240
3241 // Handle more complex cases in runtime.
3242 __ bind(&runtime);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003243 if (equality) {
Ben Murdochda12d292016-06-02 14:46:10 +01003244 {
3245 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3246 __ Push(left, right);
3247 __ CallRuntime(Runtime::kStringEqual);
3248 }
3249 __ LoadRoot(r4, Heap::kTrueValueRootIndex);
3250 __ sub(r3, r3, r4);
3251 __ Ret();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003252 } else {
Ben Murdochda12d292016-06-02 14:46:10 +01003253 __ Push(left, right);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003254 __ TailCallRuntime(Runtime::kStringCompare);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003255 }
3256
3257 __ bind(&miss);
3258 GenerateMiss(masm);
3259}
3260
3261
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003262void CompareICStub::GenerateReceivers(MacroAssembler* masm) {
3263 DCHECK_EQ(CompareICState::RECEIVER, state());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003264 Label miss;
3265 __ and_(r5, r4, r3);
3266 __ JumpIfSmi(r5, &miss);
3267
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003268 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
3269 __ CompareObjectType(r3, r5, r5, FIRST_JS_RECEIVER_TYPE);
3270 __ blt(&miss);
3271 __ CompareObjectType(r4, r5, r5, FIRST_JS_RECEIVER_TYPE);
3272 __ blt(&miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003273
3274 DCHECK(GetCondition() == eq);
3275 __ sub(r3, r3, r4);
3276 __ Ret();
3277
3278 __ bind(&miss);
3279 GenerateMiss(masm);
3280}
3281
3282
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003283void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003284 Label miss;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003285 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003286 __ and_(r5, r4, r3);
3287 __ JumpIfSmi(r5, &miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003288 __ GetWeakValue(r7, cell);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003289 __ LoadP(r5, FieldMemOperand(r3, HeapObject::kMapOffset));
3290 __ LoadP(r6, FieldMemOperand(r4, HeapObject::kMapOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003291 __ cmp(r5, r7);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003292 __ bne(&miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003293 __ cmp(r6, r7);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003294 __ bne(&miss);
3295
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003296 if (Token::IsEqualityOp(op())) {
3297 __ sub(r3, r3, r4);
3298 __ Ret();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003299 } else {
3300 if (op() == Token::LT || op() == Token::LTE) {
3301 __ LoadSmiLiteral(r5, Smi::FromInt(GREATER));
3302 } else {
3303 __ LoadSmiLiteral(r5, Smi::FromInt(LESS));
3304 }
3305 __ Push(r4, r3, r5);
3306 __ TailCallRuntime(Runtime::kCompare);
3307 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003308
3309 __ bind(&miss);
3310 GenerateMiss(masm);
3311}
3312
3313
3314void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3315 {
3316 // Call the runtime system in a fresh internal frame.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003317 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3318 __ Push(r4, r3);
3319 __ Push(r4, r3);
3320 __ LoadSmiLiteral(r0, Smi::FromInt(op()));
3321 __ push(r0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003322 __ CallRuntime(Runtime::kCompareIC_Miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003323 // Compute the entry point of the rewritten stub.
3324 __ addi(r5, r3, Operand(Code::kHeaderSize - kHeapObjectTag));
3325 // Restore registers.
3326 __ Pop(r4, r3);
3327 }
3328
3329 __ JumpToJSEntry(r5);
3330}
3331
3332
3333// This stub is paired with DirectCEntryStub::GenerateCall
3334void DirectCEntryStub::Generate(MacroAssembler* masm) {
3335 // Place the return address on the stack, making the call
3336 // GC safe. The RegExp backend also relies on this.
3337 __ mflr(r0);
3338 __ StoreP(r0, MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize));
3339 __ Call(ip); // Call the C++ function.
3340 __ LoadP(r0, MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize));
3341 __ mtlr(r0);
3342 __ blr();
3343}
3344
3345
3346void DirectCEntryStub::GenerateCall(MacroAssembler* masm, Register target) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01003347 if (ABI_USES_FUNCTION_DESCRIPTORS) {
3348 // AIX/PPC64BE Linux use a function descriptor.
3349 __ LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(target, kPointerSize));
3350 __ LoadP(ip, MemOperand(target, 0)); // Instruction address
3351 } else {
3352 // ip needs to be set for DirectCEentryStub::Generate, and also
3353 // for ABI_CALL_VIA_IP.
3354 __ Move(ip, target);
3355 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003356
3357 intptr_t code = reinterpret_cast<intptr_t>(GetCode().location());
3358 __ mov(r0, Operand(code, RelocInfo::CODE_TARGET));
3359 __ Call(r0); // Call the stub.
3360}
3361
3362
3363void NameDictionaryLookupStub::GenerateNegativeLookup(
3364 MacroAssembler* masm, Label* miss, Label* done, Register receiver,
3365 Register properties, Handle<Name> name, Register scratch0) {
3366 DCHECK(name->IsUniqueName());
3367 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3368 // not equal to the name and kProbes-th slot is not used (its name is the
3369 // undefined value), it guarantees the hash table doesn't contain the
3370 // property. It's true even if some slots represent deleted properties
3371 // (their names are the hole value).
3372 for (int i = 0; i < kInlinedProbes; i++) {
3373 // scratch0 points to properties hash.
3374 // Compute the masked index: (hash + i + i * i) & mask.
3375 Register index = scratch0;
3376 // Capacity is smi 2^n.
3377 __ LoadP(index, FieldMemOperand(properties, kCapacityOffset));
3378 __ subi(index, index, Operand(1));
3379 __ LoadSmiLiteral(
3380 ip, Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i)));
3381 __ and_(index, index, ip);
3382
3383 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003384 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003385 __ ShiftLeftImm(ip, index, Operand(1));
3386 __ add(index, index, ip); // index *= 3.
3387
3388 Register entity_name = scratch0;
3389 // Having undefined at this place means the name is not contained.
3390 Register tmp = properties;
3391 __ SmiToPtrArrayOffset(ip, index);
3392 __ add(tmp, properties, ip);
3393 __ LoadP(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3394
3395 DCHECK(!tmp.is(entity_name));
3396 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3397 __ cmp(entity_name, tmp);
3398 __ beq(done);
3399
3400 // Load the hole ready for use below:
3401 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3402
3403 // Stop if found the property.
3404 __ Cmpi(entity_name, Operand(Handle<Name>(name)), r0);
3405 __ beq(miss);
3406
3407 Label good;
3408 __ cmp(entity_name, tmp);
3409 __ beq(&good);
3410
3411 // Check if the entry name is not a unique name.
3412 __ LoadP(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3413 __ lbz(entity_name, FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3414 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3415 __ bind(&good);
3416
3417 // Restore the properties.
3418 __ LoadP(properties,
3419 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3420 }
3421
3422 const int spill_mask = (r0.bit() | r9.bit() | r8.bit() | r7.bit() | r6.bit() |
3423 r5.bit() | r4.bit() | r3.bit());
3424
3425 __ mflr(r0);
3426 __ MultiPush(spill_mask);
3427
3428 __ LoadP(r3, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3429 __ mov(r4, Operand(Handle<Name>(name)));
3430 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3431 __ CallStub(&stub);
3432 __ cmpi(r3, Operand::Zero());
3433
3434 __ MultiPop(spill_mask); // MultiPop does not touch condition flags
3435 __ mtlr(r0);
3436
3437 __ beq(done);
3438 __ bne(miss);
3439}
3440
3441
3442// Probe the name dictionary in the |elements| register. Jump to the
3443// |done| label if a property with the given name is found. Jump to
3444// the |miss| label otherwise.
3445// If lookup was successful |scratch2| will be equal to elements + 4 * index.
3446void NameDictionaryLookupStub::GeneratePositiveLookup(
3447 MacroAssembler* masm, Label* miss, Label* done, Register elements,
3448 Register name, Register scratch1, Register scratch2) {
3449 DCHECK(!elements.is(scratch1));
3450 DCHECK(!elements.is(scratch2));
3451 DCHECK(!name.is(scratch1));
3452 DCHECK(!name.is(scratch2));
3453
3454 __ AssertName(name);
3455
3456 // Compute the capacity mask.
3457 __ LoadP(scratch1, FieldMemOperand(elements, kCapacityOffset));
3458 __ SmiUntag(scratch1); // convert smi to int
3459 __ subi(scratch1, scratch1, Operand(1));
3460
3461 // Generate an unrolled loop that performs a few probes before
3462 // giving up. Measurements done on Gmail indicate that 2 probes
3463 // cover ~93% of loads from dictionaries.
3464 for (int i = 0; i < kInlinedProbes; i++) {
3465 // Compute the masked index: (hash + i + i * i) & mask.
3466 __ lwz(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3467 if (i > 0) {
3468 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3469 // the hash in a separate instruction. The value hash + i + i * i is right
3470 // shifted in the following and instruction.
3471 DCHECK(NameDictionary::GetProbeOffset(i) <
3472 1 << (32 - Name::kHashFieldOffset));
3473 __ addi(scratch2, scratch2,
3474 Operand(NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3475 }
3476 __ srwi(scratch2, scratch2, Operand(Name::kHashShift));
3477 __ and_(scratch2, scratch1, scratch2);
3478
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003479 // Scale the index by multiplying by the entry size.
3480 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003481 // scratch2 = scratch2 * 3.
3482 __ ShiftLeftImm(ip, scratch2, Operand(1));
3483 __ add(scratch2, scratch2, ip);
3484
3485 // Check if the key is identical to the name.
3486 __ ShiftLeftImm(ip, scratch2, Operand(kPointerSizeLog2));
3487 __ add(scratch2, elements, ip);
3488 __ LoadP(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3489 __ cmp(name, ip);
3490 __ beq(done);
3491 }
3492
3493 const int spill_mask = (r0.bit() | r9.bit() | r8.bit() | r7.bit() | r6.bit() |
3494 r5.bit() | r4.bit() | r3.bit()) &
3495 ~(scratch1.bit() | scratch2.bit());
3496
3497 __ mflr(r0);
3498 __ MultiPush(spill_mask);
3499 if (name.is(r3)) {
3500 DCHECK(!elements.is(r4));
3501 __ mr(r4, name);
3502 __ mr(r3, elements);
3503 } else {
3504 __ mr(r3, elements);
3505 __ mr(r4, name);
3506 }
3507 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
3508 __ CallStub(&stub);
3509 __ cmpi(r3, Operand::Zero());
3510 __ mr(scratch2, r5);
3511 __ MultiPop(spill_mask);
3512 __ mtlr(r0);
3513
3514 __ bne(done);
3515 __ beq(miss);
3516}
3517
3518
3519void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3520 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3521 // we cannot call anything that could cause a GC from this stub.
3522 // Registers:
3523 // result: NameDictionary to probe
3524 // r4: key
3525 // dictionary: NameDictionary to probe.
3526 // index: will hold an index of entry if lookup is successful.
3527 // might alias with result_.
3528 // Returns:
3529 // result_ is zero if lookup failed, non zero otherwise.
3530
3531 Register result = r3;
3532 Register dictionary = r3;
3533 Register key = r4;
3534 Register index = r5;
3535 Register mask = r6;
3536 Register hash = r7;
3537 Register undefined = r8;
3538 Register entry_key = r9;
3539 Register scratch = r9;
3540
3541 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3542
3543 __ LoadP(mask, FieldMemOperand(dictionary, kCapacityOffset));
3544 __ SmiUntag(mask);
3545 __ subi(mask, mask, Operand(1));
3546
3547 __ lwz(hash, FieldMemOperand(key, Name::kHashFieldOffset));
3548
3549 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3550
3551 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3552 // Compute the masked index: (hash + i + i * i) & mask.
3553 // Capacity is smi 2^n.
3554 if (i > 0) {
3555 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3556 // the hash in a separate instruction. The value hash + i + i * i is right
3557 // shifted in the following and instruction.
3558 DCHECK(NameDictionary::GetProbeOffset(i) <
3559 1 << (32 - Name::kHashFieldOffset));
3560 __ addi(index, hash,
3561 Operand(NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3562 } else {
3563 __ mr(index, hash);
3564 }
3565 __ srwi(r0, index, Operand(Name::kHashShift));
3566 __ and_(index, mask, r0);
3567
3568 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003569 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003570 __ ShiftLeftImm(scratch, index, Operand(1));
3571 __ add(index, index, scratch); // index *= 3.
3572
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003573 __ ShiftLeftImm(scratch, index, Operand(kPointerSizeLog2));
3574 __ add(index, dictionary, scratch);
3575 __ LoadP(entry_key, FieldMemOperand(index, kElementsStartOffset));
3576
3577 // Having undefined at this place means the name is not contained.
3578 __ cmp(entry_key, undefined);
3579 __ beq(&not_in_dictionary);
3580
3581 // Stop if found the property.
3582 __ cmp(entry_key, key);
3583 __ beq(&in_dictionary);
3584
3585 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3586 // Check if the entry name is not a unique name.
3587 __ LoadP(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3588 __ lbz(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
3589 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
3590 }
3591 }
3592
3593 __ bind(&maybe_in_dictionary);
3594 // If we are doing negative lookup then probing failure should be
3595 // treated as a lookup success. For positive lookup probing failure
3596 // should be treated as lookup failure.
3597 if (mode() == POSITIVE_LOOKUP) {
3598 __ li(result, Operand::Zero());
3599 __ Ret();
3600 }
3601
3602 __ bind(&in_dictionary);
3603 __ li(result, Operand(1));
3604 __ Ret();
3605
3606 __ bind(&not_in_dictionary);
3607 __ li(result, Operand::Zero());
3608 __ Ret();
3609}
3610
3611
3612void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3613 Isolate* isolate) {
3614 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3615 stub1.GetCode();
3616 // Hydrogen code stubs need stub2 at snapshot time.
3617 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3618 stub2.GetCode();
3619}
3620
3621
3622// Takes the input in 3 registers: address_ value_ and object_. A pointer to
3623// the value has just been written into the object, now this stub makes sure
3624// we keep the GC informed. The word in the object where the value has been
3625// written is in the address register.
3626void RecordWriteStub::Generate(MacroAssembler* masm) {
3627 Label skip_to_incremental_noncompacting;
3628 Label skip_to_incremental_compacting;
3629
3630 // The first two branch instructions are generated with labels so as to
3631 // get the offset fixed up correctly by the bind(Label*) call. We patch
3632 // it back and forth between branch condition True and False
3633 // when we start and stop incremental heap marking.
3634 // See RecordWriteStub::Patch for details.
3635
3636 // Clear the bit, branch on True for NOP action initially
3637 __ crclr(Assembler::encode_crbit(cr2, CR_LT));
3638 __ blt(&skip_to_incremental_noncompacting, cr2);
3639 __ blt(&skip_to_incremental_compacting, cr2);
3640
3641 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3642 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3643 MacroAssembler::kReturnAtEnd);
3644 }
3645 __ Ret();
3646
3647 __ bind(&skip_to_incremental_noncompacting);
3648 GenerateIncremental(masm, INCREMENTAL);
3649
3650 __ bind(&skip_to_incremental_compacting);
3651 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3652
3653 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3654 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
3655 // patching not required on PPC as the initial path is effectively NOP
3656}
3657
3658
3659void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3660 regs_.Save(masm);
3661
3662 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3663 Label dont_need_remembered_set;
3664
3665 __ LoadP(regs_.scratch0(), MemOperand(regs_.address(), 0));
3666 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
3667 regs_.scratch0(), &dont_need_remembered_set);
3668
Ben Murdoch097c5b22016-05-18 11:27:45 +01003669 __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(),
3670 &dont_need_remembered_set);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003671
3672 // First notify the incremental marker if necessary, then update the
3673 // remembered set.
3674 CheckNeedsToInformIncrementalMarker(
3675 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
3676 InformIncrementalMarker(masm);
3677 regs_.Restore(masm);
3678 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3679 MacroAssembler::kReturnAtEnd);
3680
3681 __ bind(&dont_need_remembered_set);
3682 }
3683
3684 CheckNeedsToInformIncrementalMarker(
3685 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
3686 InformIncrementalMarker(masm);
3687 regs_.Restore(masm);
3688 __ Ret();
3689}
3690
3691
3692void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
3693 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
3694 int argument_count = 3;
3695 __ PrepareCallCFunction(argument_count, regs_.scratch0());
3696 Register address =
3697 r3.is(regs_.address()) ? regs_.scratch0() : regs_.address();
3698 DCHECK(!address.is(regs_.object()));
3699 DCHECK(!address.is(r3));
3700 __ mr(address, regs_.address());
3701 __ mr(r3, regs_.object());
3702 __ mr(r4, address);
3703 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
3704
3705 AllowExternalCallThatCantCauseGC scope(masm);
3706 __ CallCFunction(
3707 ExternalReference::incremental_marking_record_write_function(isolate()),
3708 argument_count);
3709 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
3710}
3711
3712
3713void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
3714 MacroAssembler* masm, OnNoNeedToInformIncrementalMarker on_no_need,
3715 Mode mode) {
3716 Label on_black;
3717 Label need_incremental;
3718 Label need_incremental_pop_scratch;
3719
3720 DCHECK((~Page::kPageAlignmentMask & 0xffff) == 0);
3721 __ lis(r0, Operand((~Page::kPageAlignmentMask >> 16)));
3722 __ and_(regs_.scratch0(), regs_.object(), r0);
3723 __ LoadP(
3724 regs_.scratch1(),
3725 MemOperand(regs_.scratch0(), MemoryChunk::kWriteBarrierCounterOffset));
3726 __ subi(regs_.scratch1(), regs_.scratch1(), Operand(1));
3727 __ StoreP(
3728 regs_.scratch1(),
3729 MemOperand(regs_.scratch0(), MemoryChunk::kWriteBarrierCounterOffset));
3730 __ cmpi(regs_.scratch1(), Operand::Zero()); // PPC, we could do better here
3731 __ blt(&need_incremental);
3732
3733 // Let's look at the color of the object: If it is not black we don't have
3734 // to inform the incremental marker.
3735 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
3736
3737 regs_.Restore(masm);
3738 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
3739 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3740 MacroAssembler::kReturnAtEnd);
3741 } else {
3742 __ Ret();
3743 }
3744
3745 __ bind(&on_black);
3746
3747 // Get the value from the slot.
3748 __ LoadP(regs_.scratch0(), MemOperand(regs_.address(), 0));
3749
3750 if (mode == INCREMENTAL_COMPACTION) {
3751 Label ensure_not_white;
3752
3753 __ CheckPageFlag(regs_.scratch0(), // Contains value.
3754 regs_.scratch1(), // Scratch.
3755 MemoryChunk::kEvacuationCandidateMask, eq,
3756 &ensure_not_white);
3757
3758 __ CheckPageFlag(regs_.object(),
3759 regs_.scratch1(), // Scratch.
3760 MemoryChunk::kSkipEvacuationSlotsRecordingMask, eq,
3761 &need_incremental);
3762
3763 __ bind(&ensure_not_white);
3764 }
3765
3766 // We need extra registers for this, so we push the object and the address
3767 // register temporarily.
3768 __ Push(regs_.object(), regs_.address());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003769 __ JumpIfWhite(regs_.scratch0(), // The value.
3770 regs_.scratch1(), // Scratch.
3771 regs_.object(), // Scratch.
3772 regs_.address(), // Scratch.
3773 &need_incremental_pop_scratch);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003774 __ Pop(regs_.object(), regs_.address());
3775
3776 regs_.Restore(masm);
3777 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
3778 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3779 MacroAssembler::kReturnAtEnd);
3780 } else {
3781 __ Ret();
3782 }
3783
3784 __ bind(&need_incremental_pop_scratch);
3785 __ Pop(regs_.object(), regs_.address());
3786
3787 __ bind(&need_incremental);
3788
3789 // Fall through when we need to inform the incremental marker.
3790}
3791
3792
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003793void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
3794 CEntryStub ces(isolate(), 1, kSaveFPRegs);
3795 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
3796 int parameter_count_offset =
Ben Murdochda12d292016-06-02 14:46:10 +01003797 StubFailureTrampolineFrameConstants::kArgumentsLengthOffset;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003798 __ LoadP(r4, MemOperand(fp, parameter_count_offset));
3799 if (function_mode() == JS_FUNCTION_STUB_MODE) {
3800 __ addi(r4, r4, Operand(1));
3801 }
3802 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
3803 __ slwi(r4, r4, Operand(kPointerSizeLog2));
3804 __ add(sp, sp, r4);
3805 __ Ret();
3806}
3807
3808
3809void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003810 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3811 LoadICStub stub(isolate(), state());
3812 stub.GenerateForTrampoline(masm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003813}
3814
3815
3816void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003817 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3818 KeyedLoadICStub stub(isolate(), state());
3819 stub.GenerateForTrampoline(masm);
3820}
3821
3822
3823void CallICTrampolineStub::Generate(MacroAssembler* masm) {
3824 __ EmitLoadTypeFeedbackVector(r5);
3825 CallICStub stub(isolate(), state());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003826 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3827}
3828
3829
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003830void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
3831
3832
3833void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3834 GenerateImpl(masm, true);
3835}
3836
3837
3838static void HandleArrayCases(MacroAssembler* masm, Register feedback,
3839 Register receiver_map, Register scratch1,
3840 Register scratch2, bool is_polymorphic,
3841 Label* miss) {
3842 // feedback initially contains the feedback array
3843 Label next_loop, prepare_next;
3844 Label start_polymorphic;
3845
3846 Register cached_map = scratch1;
3847
3848 __ LoadP(cached_map,
3849 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
3850 __ LoadP(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3851 __ cmp(receiver_map, cached_map);
3852 __ bne(&start_polymorphic);
3853 // found, now call handler.
3854 Register handler = feedback;
3855 __ LoadP(handler,
3856 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
3857 __ addi(ip, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3858 __ Jump(ip);
3859
3860
3861 Register length = scratch2;
3862 __ bind(&start_polymorphic);
3863 __ LoadP(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
3864 if (!is_polymorphic) {
3865 // If the IC could be monomorphic we have to make sure we don't go past the
3866 // end of the feedback array.
3867 __ CmpSmiLiteral(length, Smi::FromInt(2), r0);
3868 __ beq(miss);
3869 }
3870
3871 Register too_far = length;
3872 Register pointer_reg = feedback;
3873
3874 // +-----+------+------+-----+-----+ ... ----+
3875 // | map | len | wm0 | h0 | wm1 | hN |
3876 // +-----+------+------+-----+-----+ ... ----+
3877 // 0 1 2 len-1
3878 // ^ ^
3879 // | |
3880 // pointer_reg too_far
3881 // aka feedback scratch2
3882 // also need receiver_map
3883 // use cached_map (scratch1) to look in the weak map values.
3884 __ SmiToPtrArrayOffset(r0, length);
3885 __ add(too_far, feedback, r0);
3886 __ addi(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3887 __ addi(pointer_reg, feedback,
3888 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
3889
3890 __ bind(&next_loop);
3891 __ LoadP(cached_map, MemOperand(pointer_reg));
3892 __ LoadP(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3893 __ cmp(receiver_map, cached_map);
3894 __ bne(&prepare_next);
3895 __ LoadP(handler, MemOperand(pointer_reg, kPointerSize));
3896 __ addi(ip, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3897 __ Jump(ip);
3898
3899 __ bind(&prepare_next);
3900 __ addi(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
3901 __ cmp(pointer_reg, too_far);
3902 __ blt(&next_loop);
3903
3904 // We exhausted our array of map handler pairs.
3905 __ b(miss);
3906}
3907
3908
3909static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
3910 Register receiver_map, Register feedback,
3911 Register vector, Register slot,
3912 Register scratch, Label* compare_map,
3913 Label* load_smi_map, Label* try_array) {
3914 __ JumpIfSmi(receiver, load_smi_map);
3915 __ LoadP(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
3916 __ bind(compare_map);
3917 Register cached_map = scratch;
3918 // Move the weak map into the weak_cell register.
3919 __ LoadP(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
3920 __ cmp(cached_map, receiver_map);
3921 __ bne(try_array);
3922 Register handler = feedback;
3923 __ SmiToPtrArrayOffset(r0, slot);
3924 __ add(handler, vector, r0);
3925 __ LoadP(handler,
3926 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
3927 __ addi(ip, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3928 __ Jump(ip);
3929}
3930
3931
3932void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3933 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r4
3934 Register name = LoadWithVectorDescriptor::NameRegister(); // r5
3935 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r6
3936 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r3
3937 Register feedback = r7;
3938 Register receiver_map = r8;
3939 Register scratch1 = r9;
3940
3941 __ SmiToPtrArrayOffset(r0, slot);
3942 __ add(feedback, vector, r0);
3943 __ LoadP(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3944
3945 // Try to quickly handle the monomorphic case without knowing for sure
3946 // if we have a weak cell in feedback. We do know it's safe to look
3947 // at WeakCell::kValueOffset.
3948 Label try_array, load_smi_map, compare_map;
3949 Label not_array, miss;
3950 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3951 scratch1, &compare_map, &load_smi_map, &try_array);
3952
3953 // Is it a fixed array?
3954 __ bind(&try_array);
3955 __ LoadP(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3956 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
3957 __ bne(&not_array);
3958 HandleArrayCases(masm, feedback, receiver_map, scratch1, r10, true, &miss);
3959
3960 __ bind(&not_array);
3961 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
3962 __ bne(&miss);
3963 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
3964 Code::ComputeHandlerFlags(Code::LOAD_IC));
3965 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
3966 receiver, name, feedback,
3967 receiver_map, scratch1, r10);
3968
3969 __ bind(&miss);
3970 LoadIC::GenerateMiss(masm);
3971
3972 __ bind(&load_smi_map);
3973 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3974 __ b(&compare_map);
3975}
3976
3977
3978void KeyedLoadICStub::Generate(MacroAssembler* masm) {
3979 GenerateImpl(masm, false);
3980}
3981
3982
3983void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3984 GenerateImpl(masm, true);
3985}
3986
3987
3988void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3989 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r4
3990 Register key = LoadWithVectorDescriptor::NameRegister(); // r5
3991 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r6
3992 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r3
3993 Register feedback = r7;
3994 Register receiver_map = r8;
3995 Register scratch1 = r9;
3996
3997 __ SmiToPtrArrayOffset(r0, slot);
3998 __ add(feedback, vector, r0);
3999 __ LoadP(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4000
4001 // Try to quickly handle the monomorphic case without knowing for sure
4002 // if we have a weak cell in feedback. We do know it's safe to look
4003 // at WeakCell::kValueOffset.
4004 Label try_array, load_smi_map, compare_map;
4005 Label not_array, miss;
4006 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4007 scratch1, &compare_map, &load_smi_map, &try_array);
4008
4009 __ bind(&try_array);
4010 // Is it a fixed array?
4011 __ LoadP(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4012 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4013 __ bne(&not_array);
4014
4015 // We have a polymorphic element handler.
4016 Label polymorphic, try_poly_name;
4017 __ bind(&polymorphic);
4018 HandleArrayCases(masm, feedback, receiver_map, scratch1, r10, true, &miss);
4019
4020 __ bind(&not_array);
4021 // Is it generic?
4022 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4023 __ bne(&try_poly_name);
4024 Handle<Code> megamorphic_stub =
4025 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4026 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4027
4028 __ bind(&try_poly_name);
4029 // We might have a name in feedback, and a fixed array in the next slot.
4030 __ cmp(key, feedback);
4031 __ bne(&miss);
4032 // If the name comparison succeeded, we know we have a fixed array with
4033 // at least one map/handler pair.
4034 __ SmiToPtrArrayOffset(r0, slot);
4035 __ add(feedback, vector, r0);
4036 __ LoadP(feedback,
4037 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4038 HandleArrayCases(masm, feedback, receiver_map, scratch1, r10, false, &miss);
4039
4040 __ bind(&miss);
4041 KeyedLoadIC::GenerateMiss(masm);
4042
4043 __ bind(&load_smi_map);
4044 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4045 __ b(&compare_map);
4046}
4047
4048
4049void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4050 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
4051 VectorStoreICStub stub(isolate(), state());
4052 stub.GenerateForTrampoline(masm);
4053}
4054
4055
4056void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4057 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
4058 VectorKeyedStoreICStub stub(isolate(), state());
4059 stub.GenerateForTrampoline(masm);
4060}
4061
4062
4063void VectorStoreICStub::Generate(MacroAssembler* masm) {
4064 GenerateImpl(masm, false);
4065}
4066
4067
4068void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4069 GenerateImpl(masm, true);
4070}
4071
4072
4073void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4074 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r4
4075 Register key = VectorStoreICDescriptor::NameRegister(); // r5
4076 Register vector = VectorStoreICDescriptor::VectorRegister(); // r6
4077 Register slot = VectorStoreICDescriptor::SlotRegister(); // r7
4078 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r3)); // r3
4079 Register feedback = r8;
4080 Register receiver_map = r9;
4081 Register scratch1 = r10;
4082
4083 __ SmiToPtrArrayOffset(r0, slot);
4084 __ add(feedback, vector, r0);
4085 __ LoadP(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4086
4087 // Try to quickly handle the monomorphic case without knowing for sure
4088 // if we have a weak cell in feedback. We do know it's safe to look
4089 // at WeakCell::kValueOffset.
4090 Label try_array, load_smi_map, compare_map;
4091 Label not_array, miss;
4092 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4093 scratch1, &compare_map, &load_smi_map, &try_array);
4094
4095 // Is it a fixed array?
4096 __ bind(&try_array);
4097 __ LoadP(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4098 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4099 __ bne(&not_array);
4100
4101 Register scratch2 = r11;
4102 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4103 &miss);
4104
4105 __ bind(&not_array);
4106 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4107 __ bne(&miss);
4108 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4109 Code::ComputeHandlerFlags(Code::STORE_IC));
4110 masm->isolate()->stub_cache()->GenerateProbe(
4111 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4112 scratch1, scratch2);
4113
4114 __ bind(&miss);
4115 StoreIC::GenerateMiss(masm);
4116
4117 __ bind(&load_smi_map);
4118 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4119 __ b(&compare_map);
4120}
4121
4122
4123void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4124 GenerateImpl(masm, false);
4125}
4126
4127
4128void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4129 GenerateImpl(masm, true);
4130}
4131
4132
4133static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4134 Register receiver_map, Register scratch1,
4135 Register scratch2, Label* miss) {
4136 // feedback initially contains the feedback array
4137 Label next_loop, prepare_next;
4138 Label start_polymorphic;
4139 Label transition_call;
4140
4141 Register cached_map = scratch1;
4142 Register too_far = scratch2;
4143 Register pointer_reg = feedback;
4144 __ LoadP(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4145
4146 // +-----+------+------+-----+-----+-----+ ... ----+
4147 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4148 // +-----+------+------+-----+-----+ ----+ ... ----+
4149 // 0 1 2 len-1
4150 // ^ ^
4151 // | |
4152 // pointer_reg too_far
4153 // aka feedback scratch2
4154 // also need receiver_map
4155 // use cached_map (scratch1) to look in the weak map values.
4156 __ SmiToPtrArrayOffset(r0, too_far);
4157 __ add(too_far, feedback, r0);
4158 __ addi(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4159 __ addi(pointer_reg, feedback,
4160 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4161
4162 __ bind(&next_loop);
4163 __ LoadP(cached_map, MemOperand(pointer_reg));
4164 __ LoadP(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4165 __ cmp(receiver_map, cached_map);
4166 __ bne(&prepare_next);
4167 // Is it a transitioning store?
4168 __ LoadP(too_far, MemOperand(pointer_reg, kPointerSize));
4169 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4170 __ bne(&transition_call);
4171 __ LoadP(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4172 __ addi(ip, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4173 __ Jump(ip);
4174
4175 __ bind(&transition_call);
4176 __ LoadP(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4177 __ JumpIfSmi(too_far, miss);
4178
4179 __ LoadP(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4180
4181 // Load the map into the correct register.
4182 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4183 __ mr(feedback, too_far);
4184
4185 __ addi(ip, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4186 __ Jump(ip);
4187
4188 __ bind(&prepare_next);
4189 __ addi(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4190 __ cmpl(pointer_reg, too_far);
4191 __ blt(&next_loop);
4192
4193 // We exhausted our array of map handler pairs.
4194 __ b(miss);
4195}
4196
4197
4198void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4199 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r4
4200 Register key = VectorStoreICDescriptor::NameRegister(); // r5
4201 Register vector = VectorStoreICDescriptor::VectorRegister(); // r6
4202 Register slot = VectorStoreICDescriptor::SlotRegister(); // r7
4203 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r3)); // r3
4204 Register feedback = r8;
4205 Register receiver_map = r9;
4206 Register scratch1 = r10;
4207
4208 __ SmiToPtrArrayOffset(r0, slot);
4209 __ add(feedback, vector, r0);
4210 __ LoadP(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4211
4212 // Try to quickly handle the monomorphic case without knowing for sure
4213 // if we have a weak cell in feedback. We do know it's safe to look
4214 // at WeakCell::kValueOffset.
4215 Label try_array, load_smi_map, compare_map;
4216 Label not_array, miss;
4217 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4218 scratch1, &compare_map, &load_smi_map, &try_array);
4219
4220 __ bind(&try_array);
4221 // Is it a fixed array?
4222 __ LoadP(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4223 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4224 __ bne(&not_array);
4225
4226 // We have a polymorphic element handler.
4227 Label polymorphic, try_poly_name;
4228 __ bind(&polymorphic);
4229
4230 Register scratch2 = r11;
4231
4232 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4233 &miss);
4234
4235 __ bind(&not_array);
4236 // Is it generic?
4237 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4238 __ bne(&try_poly_name);
4239 Handle<Code> megamorphic_stub =
4240 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4241 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4242
4243 __ bind(&try_poly_name);
4244 // We might have a name in feedback, and a fixed array in the next slot.
4245 __ cmp(key, feedback);
4246 __ bne(&miss);
4247 // If the name comparison succeeded, we know we have a fixed array with
4248 // at least one map/handler pair.
4249 __ SmiToPtrArrayOffset(r0, slot);
4250 __ add(feedback, vector, r0);
4251 __ LoadP(feedback,
4252 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4253 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4254 &miss);
4255
4256 __ bind(&miss);
4257 KeyedStoreIC::GenerateMiss(masm);
4258
4259 __ bind(&load_smi_map);
4260 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4261 __ b(&compare_map);
4262}
4263
4264
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004265void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4266 if (masm->isolate()->function_entry_hook() != NULL) {
4267 PredictableCodeSizeScope predictable(masm,
4268#if V8_TARGET_ARCH_PPC64
4269 14 * Assembler::kInstrSize);
4270#else
4271 11 * Assembler::kInstrSize);
4272#endif
4273 ProfileEntryHookStub stub(masm->isolate());
4274 __ mflr(r0);
4275 __ Push(r0, ip);
4276 __ CallStub(&stub);
4277 __ Pop(r0, ip);
4278 __ mtlr(r0);
4279 }
4280}
4281
4282
4283void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4284 // The entry hook is a "push lr, ip" instruction, followed by a call.
4285 const int32_t kReturnAddressDistanceFromFunctionStart =
4286 Assembler::kCallTargetAddressOffset + 3 * Assembler::kInstrSize;
4287
4288 // This should contain all kJSCallerSaved registers.
4289 const RegList kSavedRegs = kJSCallerSaved | // Caller saved registers.
4290 r15.bit(); // Saved stack pointer.
4291
4292 // We also save lr, so the count here is one higher than the mask indicates.
4293 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4294
4295 // Save all caller-save registers as this may be called from anywhere.
4296 __ mflr(ip);
4297 __ MultiPush(kSavedRegs | ip.bit());
4298
4299 // Compute the function's address for the first argument.
4300 __ subi(r3, ip, Operand(kReturnAddressDistanceFromFunctionStart));
4301
4302 // The caller's return address is two slots above the saved temporaries.
4303 // Grab that for the second argument to the hook.
4304 __ addi(r4, sp, Operand((kNumSavedRegs + 1) * kPointerSize));
4305
4306 // Align the stack if necessary.
4307 int frame_alignment = masm->ActivationFrameAlignment();
4308 if (frame_alignment > kPointerSize) {
4309 __ mr(r15, sp);
4310 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4311 __ ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
4312 }
4313
4314#if !defined(USE_SIMULATOR)
4315 uintptr_t entry_hook =
4316 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
Ben Murdoch097c5b22016-05-18 11:27:45 +01004317#else
4318 // Under the simulator we need to indirect the entry hook through a
4319 // trampoline function at a known address.
4320 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4321 ExternalReference entry_hook = ExternalReference(
4322 &dispatcher, ExternalReference::BUILTIN_CALL, isolate());
4323
4324 // It additionally takes an isolate as a third parameter
4325 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
4326#endif
4327
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004328 __ mov(ip, Operand(entry_hook));
4329
Ben Murdoch097c5b22016-05-18 11:27:45 +01004330 if (ABI_USES_FUNCTION_DESCRIPTORS) {
4331 __ LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(ip, kPointerSize));
4332 __ LoadP(ip, MemOperand(ip, 0));
4333 }
4334 // ip set above, so nothing more to do for ABI_CALL_VIA_IP.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004335
4336 // PPC LINUX ABI:
4337 __ li(r0, Operand::Zero());
4338 __ StorePU(r0, MemOperand(sp, -kNumRequiredStackFrameSlots * kPointerSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004339
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004340 __ Call(ip);
4341
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004342 __ addi(sp, sp, Operand(kNumRequiredStackFrameSlots * kPointerSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004343
4344 // Restore the stack pointer if needed.
4345 if (frame_alignment > kPointerSize) {
4346 __ mr(sp, r15);
4347 }
4348
4349 // Also pop lr to get Ret(0).
4350 __ MultiPop(kSavedRegs | ip.bit());
4351 __ mtlr(ip);
4352 __ Ret();
4353}
4354
4355
4356template <class T>
4357static void CreateArrayDispatch(MacroAssembler* masm,
4358 AllocationSiteOverrideMode mode) {
4359 if (mode == DISABLE_ALLOCATION_SITES) {
4360 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4361 __ TailCallStub(&stub);
4362 } else if (mode == DONT_OVERRIDE) {
4363 int last_index =
4364 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
4365 for (int i = 0; i <= last_index; ++i) {
4366 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4367 __ Cmpi(r6, Operand(kind), r0);
4368 T stub(masm->isolate(), kind);
4369 __ TailCallStub(&stub, eq);
4370 }
4371
4372 // If we reached this point there is a problem.
4373 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4374 } else {
4375 UNREACHABLE();
4376 }
4377}
4378
4379
4380static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4381 AllocationSiteOverrideMode mode) {
4382 // r5 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4383 // r6 - kind (if mode != DISABLE_ALLOCATION_SITES)
4384 // r3 - number of arguments
4385 // r4 - constructor?
4386 // sp[0] - last argument
4387 Label normal_sequence;
4388 if (mode == DONT_OVERRIDE) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004389 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4390 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4391 STATIC_ASSERT(FAST_ELEMENTS == 2);
4392 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4393 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4394 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004395
4396 // is the low bit set? If so, we are holey and that is good.
4397 __ andi(r0, r6, Operand(1));
4398 __ bne(&normal_sequence, cr0);
4399 }
4400
4401 // look at the first argument
4402 __ LoadP(r8, MemOperand(sp, 0));
4403 __ cmpi(r8, Operand::Zero());
4404 __ beq(&normal_sequence);
4405
4406 if (mode == DISABLE_ALLOCATION_SITES) {
4407 ElementsKind initial = GetInitialFastElementsKind();
4408 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4409
4410 ArraySingleArgumentConstructorStub stub_holey(
4411 masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES);
4412 __ TailCallStub(&stub_holey);
4413
4414 __ bind(&normal_sequence);
4415 ArraySingleArgumentConstructorStub stub(masm->isolate(), initial,
4416 DISABLE_ALLOCATION_SITES);
4417 __ TailCallStub(&stub);
4418 } else if (mode == DONT_OVERRIDE) {
4419 // We are going to create a holey array, but our kind is non-holey.
4420 // Fix kind and retry (only if we have an allocation site in the slot).
4421 __ addi(r6, r6, Operand(1));
4422
4423 if (FLAG_debug_code) {
4424 __ LoadP(r8, FieldMemOperand(r5, 0));
4425 __ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
4426 __ Assert(eq, kExpectedAllocationSite);
4427 }
4428
4429 // Save the resulting elements kind in type info. We can't just store r6
4430 // in the AllocationSite::transition_info field because elements kind is
4431 // restricted to a portion of the field...upper bits need to be left alone.
4432 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4433 __ LoadP(r7, FieldMemOperand(r5, AllocationSite::kTransitionInfoOffset));
4434 __ AddSmiLiteral(r7, r7, Smi::FromInt(kFastElementsKindPackedToHoley), r0);
4435 __ StoreP(r7, FieldMemOperand(r5, AllocationSite::kTransitionInfoOffset),
4436 r0);
4437
4438 __ bind(&normal_sequence);
4439 int last_index =
4440 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
4441 for (int i = 0; i <= last_index; ++i) {
4442 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4443 __ mov(r0, Operand(kind));
4444 __ cmp(r6, r0);
4445 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4446 __ TailCallStub(&stub, eq);
4447 }
4448
4449 // If we reached this point there is a problem.
4450 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4451 } else {
4452 UNREACHABLE();
4453 }
4454}
4455
4456
4457template <class T>
4458static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4459 int to_index =
4460 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
4461 for (int i = 0; i <= to_index; ++i) {
4462 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4463 T stub(isolate, kind);
4464 stub.GetCode();
4465 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4466 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4467 stub1.GetCode();
4468 }
4469 }
4470}
4471
4472
4473void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4474 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4475 isolate);
4476 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4477 isolate);
4478 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4479 isolate);
4480}
4481
4482
4483void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4484 Isolate* isolate) {
4485 ElementsKind kinds[2] = {FAST_ELEMENTS, FAST_HOLEY_ELEMENTS};
4486 for (int i = 0; i < 2; i++) {
4487 // For internal arrays we only need a few things
4488 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4489 stubh1.GetCode();
4490 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4491 stubh2.GetCode();
4492 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4493 stubh3.GetCode();
4494 }
4495}
4496
4497
4498void ArrayConstructorStub::GenerateDispatchToArrayStub(
4499 MacroAssembler* masm, AllocationSiteOverrideMode mode) {
4500 if (argument_count() == ANY) {
4501 Label not_zero_case, not_one_case;
4502 __ cmpi(r3, Operand::Zero());
4503 __ bne(&not_zero_case);
4504 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4505
4506 __ bind(&not_zero_case);
4507 __ cmpi(r3, Operand(1));
4508 __ bgt(&not_one_case);
4509 CreateArrayDispatchOneArgument(masm, mode);
4510
4511 __ bind(&not_one_case);
4512 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4513 } else if (argument_count() == NONE) {
4514 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4515 } else if (argument_count() == ONE) {
4516 CreateArrayDispatchOneArgument(masm, mode);
4517 } else if (argument_count() == MORE_THAN_ONE) {
4518 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4519 } else {
4520 UNREACHABLE();
4521 }
4522}
4523
4524
4525void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4526 // ----------- S t a t e -------------
4527 // -- r3 : argc (only if argument_count() == ANY)
4528 // -- r4 : constructor
4529 // -- r5 : AllocationSite or undefined
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004530 // -- r6 : new target
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004531 // -- sp[0] : return address
4532 // -- sp[4] : last argument
4533 // -----------------------------------
4534
4535 if (FLAG_debug_code) {
4536 // The array construct code is only set for the global and natives
4537 // builtin Array functions which always have maps.
4538
4539 // Initial map for the builtin Array function should be a map.
4540 __ LoadP(r7, FieldMemOperand(r4, JSFunction::kPrototypeOrInitialMapOffset));
4541 // Will both indicate a NULL and a Smi.
4542 __ TestIfSmi(r7, r0);
4543 __ Assert(ne, kUnexpectedInitialMapForArrayFunction, cr0);
4544 __ CompareObjectType(r7, r7, r8, MAP_TYPE);
4545 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4546
4547 // We should either have undefined in r5 or a valid AllocationSite
4548 __ AssertUndefinedOrAllocationSite(r5, r7);
4549 }
4550
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004551 // Enter the context of the Array function.
4552 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
4553
4554 Label subclassing;
4555 __ cmp(r6, r4);
4556 __ bne(&subclassing);
4557
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004558 Label no_info;
4559 // Get the elements kind and case on that.
4560 __ CompareRoot(r5, Heap::kUndefinedValueRootIndex);
4561 __ beq(&no_info);
4562
4563 __ LoadP(r6, FieldMemOperand(r5, AllocationSite::kTransitionInfoOffset));
4564 __ SmiUntag(r6);
4565 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4566 __ And(r6, r6, Operand(AllocationSite::ElementsKindBits::kMask));
4567 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4568
4569 __ bind(&no_info);
4570 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004571
4572 __ bind(&subclassing);
4573 switch (argument_count()) {
4574 case ANY:
4575 case MORE_THAN_ONE:
4576 __ ShiftLeftImm(r0, r3, Operand(kPointerSizeLog2));
4577 __ StorePX(r4, MemOperand(sp, r0));
4578 __ addi(r3, r3, Operand(3));
4579 break;
4580 case NONE:
4581 __ StoreP(r4, MemOperand(sp, 0 * kPointerSize));
4582 __ li(r3, Operand(3));
4583 break;
4584 case ONE:
4585 __ StoreP(r4, MemOperand(sp, 1 * kPointerSize));
4586 __ li(r3, Operand(4));
4587 break;
4588 }
4589
4590 __ Push(r6, r5);
4591 __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004592}
4593
4594
4595void InternalArrayConstructorStub::GenerateCase(MacroAssembler* masm,
4596 ElementsKind kind) {
4597 __ cmpli(r3, Operand(1));
4598
4599 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4600 __ TailCallStub(&stub0, lt);
4601
4602 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4603 __ TailCallStub(&stubN, gt);
4604
4605 if (IsFastPackedElementsKind(kind)) {
4606 // We might need to create a holey array
4607 // look at the first argument
4608 __ LoadP(r6, MemOperand(sp, 0));
4609 __ cmpi(r6, Operand::Zero());
4610
4611 InternalArraySingleArgumentConstructorStub stub1_holey(
4612 isolate(), GetHoleyElementsKind(kind));
4613 __ TailCallStub(&stub1_holey, ne);
4614 }
4615
4616 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4617 __ TailCallStub(&stub1);
4618}
4619
4620
4621void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4622 // ----------- S t a t e -------------
4623 // -- r3 : argc
4624 // -- r4 : constructor
4625 // -- sp[0] : return address
4626 // -- sp[4] : last argument
4627 // -----------------------------------
4628
4629 if (FLAG_debug_code) {
4630 // The array construct code is only set for the global and natives
4631 // builtin Array functions which always have maps.
4632
4633 // Initial map for the builtin Array function should be a map.
4634 __ LoadP(r6, FieldMemOperand(r4, JSFunction::kPrototypeOrInitialMapOffset));
4635 // Will both indicate a NULL and a Smi.
4636 __ TestIfSmi(r6, r0);
4637 __ Assert(ne, kUnexpectedInitialMapForArrayFunction, cr0);
4638 __ CompareObjectType(r6, r6, r7, MAP_TYPE);
4639 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4640 }
4641
4642 // Figure out the right elements kind
4643 __ LoadP(r6, FieldMemOperand(r4, JSFunction::kPrototypeOrInitialMapOffset));
4644 // Load the map's "bit field 2" into |result|.
4645 __ lbz(r6, FieldMemOperand(r6, Map::kBitField2Offset));
4646 // Retrieve elements_kind from bit field 2.
4647 __ DecodeField<Map::ElementsKindBits>(r6);
4648
4649 if (FLAG_debug_code) {
4650 Label done;
4651 __ cmpi(r6, Operand(FAST_ELEMENTS));
4652 __ beq(&done);
4653 __ cmpi(r6, Operand(FAST_HOLEY_ELEMENTS));
4654 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
4655 __ bind(&done);
4656 }
4657
4658 Label fast_elements_case;
4659 __ cmpi(r6, Operand(FAST_ELEMENTS));
4660 __ beq(&fast_elements_case);
4661 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4662
4663 __ bind(&fast_elements_case);
4664 GenerateCase(masm, FAST_ELEMENTS);
4665}
4666
Ben Murdoch097c5b22016-05-18 11:27:45 +01004667void FastNewObjectStub::Generate(MacroAssembler* masm) {
4668 // ----------- S t a t e -------------
4669 // -- r4 : target
4670 // -- r6 : new target
4671 // -- cp : context
4672 // -- lr : return address
4673 // -----------------------------------
4674 __ AssertFunction(r4);
4675 __ AssertReceiver(r6);
4676
4677 // Verify that the new target is a JSFunction.
4678 Label new_object;
4679 __ CompareObjectType(r6, r5, r5, JS_FUNCTION_TYPE);
4680 __ bne(&new_object);
4681
4682 // Load the initial map and verify that it's in fact a map.
4683 __ LoadP(r5, FieldMemOperand(r6, JSFunction::kPrototypeOrInitialMapOffset));
4684 __ JumpIfSmi(r5, &new_object);
4685 __ CompareObjectType(r5, r3, r3, MAP_TYPE);
4686 __ bne(&new_object);
4687
4688 // Fall back to runtime if the target differs from the new target's
4689 // initial map constructor.
4690 __ LoadP(r3, FieldMemOperand(r5, Map::kConstructorOrBackPointerOffset));
4691 __ cmp(r3, r4);
4692 __ bne(&new_object);
4693
4694 // Allocate the JSObject on the heap.
4695 Label allocate, done_allocate;
4696 __ lbz(r7, FieldMemOperand(r5, Map::kInstanceSizeOffset));
4697 __ Allocate(r7, r3, r8, r9, &allocate, SIZE_IN_WORDS);
4698 __ bind(&done_allocate);
4699
4700 // Initialize the JSObject fields.
4701 __ StoreP(r5, MemOperand(r3, JSObject::kMapOffset));
4702 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
4703 __ StoreP(r6, MemOperand(r3, JSObject::kPropertiesOffset));
4704 __ StoreP(r6, MemOperand(r3, JSObject::kElementsOffset));
4705 STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize);
4706 __ addi(r4, r3, Operand(JSObject::kHeaderSize));
4707
4708 // ----------- S t a t e -------------
4709 // -- r3 : result (untagged)
4710 // -- r4 : result fields (untagged)
4711 // -- r8 : result end (untagged)
4712 // -- r5 : initial map
4713 // -- cp : context
4714 // -- lr : return address
4715 // -----------------------------------
4716
4717 // Perform in-object slack tracking if requested.
4718 Label slack_tracking;
4719 STATIC_ASSERT(Map::kNoSlackTracking == 0);
4720 __ LoadRoot(r9, Heap::kUndefinedValueRootIndex);
4721 __ lwz(r6, FieldMemOperand(r5, Map::kBitField3Offset));
4722 __ DecodeField<Map::ConstructionCounter>(r10, r6, SetRC);
4723 __ bne(&slack_tracking, cr0);
4724 {
4725 // Initialize all in-object fields with undefined.
4726 __ InitializeFieldsWithFiller(r4, r8, r9);
4727
4728 // Add the object tag to make the JSObject real.
4729 __ addi(r3, r3, Operand(kHeapObjectTag));
4730 __ Ret();
4731 }
4732 __ bind(&slack_tracking);
4733 {
4734 // Decrease generous allocation count.
4735 STATIC_ASSERT(Map::ConstructionCounter::kNext == 32);
4736 __ Add(r6, r6, -(1 << Map::ConstructionCounter::kShift), r0);
4737 __ stw(r6, FieldMemOperand(r5, Map::kBitField3Offset));
4738
4739 // Initialize the in-object fields with undefined.
4740 __ lbz(r7, FieldMemOperand(r5, Map::kUnusedPropertyFieldsOffset));
4741 __ ShiftLeftImm(r7, r7, Operand(kPointerSizeLog2));
4742 __ sub(r7, r8, r7);
4743 __ InitializeFieldsWithFiller(r4, r7, r9);
4744
4745 // Initialize the remaining (reserved) fields with one pointer filler map.
4746 __ LoadRoot(r9, Heap::kOnePointerFillerMapRootIndex);
4747 __ InitializeFieldsWithFiller(r4, r8, r9);
4748
4749 // Add the object tag to make the JSObject real.
4750 __ addi(r3, r3, Operand(kHeapObjectTag));
4751
4752 // Check if we can finalize the instance size.
4753 __ cmpi(r10, Operand(Map::kSlackTrackingCounterEnd));
4754 __ Ret(ne);
4755
4756 // Finalize the instance size.
4757 {
4758 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4759 __ Push(r3, r5);
4760 __ CallRuntime(Runtime::kFinalizeInstanceSize);
4761 __ Pop(r3);
4762 }
4763 __ Ret();
4764 }
4765
4766 // Fall back to %AllocateInNewSpace.
4767 __ bind(&allocate);
4768 {
4769 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4770 STATIC_ASSERT(kSmiTag == 0);
4771 __ ShiftLeftImm(r7, r7,
4772 Operand(kPointerSizeLog2 + kSmiTagSize + kSmiShiftSize));
4773 __ Push(r5, r7);
4774 __ CallRuntime(Runtime::kAllocateInNewSpace);
4775 __ Pop(r5);
4776 }
4777 __ subi(r3, r3, Operand(kHeapObjectTag));
4778 __ lbz(r8, FieldMemOperand(r5, Map::kInstanceSizeOffset));
4779 __ ShiftLeftImm(r8, r8, Operand(kPointerSizeLog2));
4780 __ add(r8, r3, r8);
4781 __ b(&done_allocate);
4782
4783 // Fall back to %NewObject.
4784 __ bind(&new_object);
4785 __ Push(r4, r6);
4786 __ TailCallRuntime(Runtime::kNewObject);
4787}
4788
4789void FastNewRestParameterStub::Generate(MacroAssembler* masm) {
4790 // ----------- S t a t e -------------
4791 // -- r4 : function
4792 // -- cp : context
4793 // -- fp : frame pointer
4794 // -- lr : return address
4795 // -----------------------------------
4796 __ AssertFunction(r4);
4797
4798 // For Ignition we need to skip all possible handler/stub frames until
4799 // we reach the JavaScript frame for the function (similar to what the
4800 // runtime fallback implementation does). So make r5 point to that
4801 // JavaScript frame.
4802 {
4803 Label loop, loop_entry;
4804 __ mr(r5, fp);
4805 __ b(&loop_entry);
4806 __ bind(&loop);
4807 __ LoadP(r5, MemOperand(r5, StandardFrameConstants::kCallerFPOffset));
4808 __ bind(&loop_entry);
Ben Murdochda12d292016-06-02 14:46:10 +01004809 __ LoadP(ip, MemOperand(r5, StandardFrameConstants::kFunctionOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004810 __ cmp(ip, r4);
4811 __ bne(&loop);
4812 }
4813
4814 // Check if we have rest parameters (only possible if we have an
4815 // arguments adaptor frame below the function frame).
4816 Label no_rest_parameters;
4817 __ LoadP(r5, MemOperand(r5, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01004818 __ LoadP(ip, MemOperand(r5, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004819 __ CmpSmiLiteral(ip, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
4820 __ bne(&no_rest_parameters);
4821
4822 // Check if the arguments adaptor frame contains more arguments than
4823 // specified by the function's internal formal parameter count.
4824 Label rest_parameters;
4825 __ LoadP(r3, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
4826 __ LoadP(r4, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
4827 __ LoadWordArith(
4828 r4, FieldMemOperand(r4, SharedFunctionInfo::kFormalParameterCountOffset));
4829#if V8_TARGET_ARCH_PPC64
4830 __ SmiTag(r4);
4831#endif
4832 __ sub(r3, r3, r4, LeaveOE, SetRC);
4833 __ bgt(&rest_parameters, cr0);
4834
4835 // Return an empty rest parameter array.
4836 __ bind(&no_rest_parameters);
4837 {
4838 // ----------- S t a t e -------------
4839 // -- cp : context
4840 // -- lr : return address
4841 // -----------------------------------
4842
4843 // Allocate an empty rest parameter array.
4844 Label allocate, done_allocate;
4845 __ Allocate(JSArray::kSize, r3, r4, r5, &allocate, TAG_OBJECT);
4846 __ bind(&done_allocate);
4847
4848 // Setup the rest parameter array in r0.
4849 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, r4);
4850 __ StoreP(r4, FieldMemOperand(r3, JSArray::kMapOffset), r0);
4851 __ LoadRoot(r4, Heap::kEmptyFixedArrayRootIndex);
4852 __ StoreP(r4, FieldMemOperand(r3, JSArray::kPropertiesOffset), r0);
4853 __ StoreP(r4, FieldMemOperand(r3, JSArray::kElementsOffset), r0);
4854 __ li(r4, Operand::Zero());
4855 __ StoreP(r4, FieldMemOperand(r3, JSArray::kLengthOffset), r0);
4856 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4857 __ Ret();
4858
4859 // Fall back to %AllocateInNewSpace.
4860 __ bind(&allocate);
4861 {
4862 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4863 __ Push(Smi::FromInt(JSArray::kSize));
4864 __ CallRuntime(Runtime::kAllocateInNewSpace);
4865 }
4866 __ b(&done_allocate);
4867 }
4868
4869 __ bind(&rest_parameters);
4870 {
4871 // Compute the pointer to the first rest parameter (skippping the receiver).
4872 __ SmiToPtrArrayOffset(r9, r3);
4873 __ add(r5, r5, r9);
4874 __ addi(r5, r5, Operand(StandardFrameConstants::kCallerSPOffset));
4875
4876 // ----------- S t a t e -------------
4877 // -- cp : context
4878 // -- r3 : number of rest parameters (tagged)
4879 // -- r5 : pointer just past first rest parameters
4880 // -- r9 : size of rest parameters
4881 // -- lr : return address
4882 // -----------------------------------
4883
4884 // Allocate space for the rest parameter array plus the backing store.
4885 Label allocate, done_allocate;
4886 __ mov(r4, Operand(JSArray::kSize + FixedArray::kHeaderSize));
4887 __ add(r4, r4, r9);
4888 __ Allocate(r4, r6, r7, r8, &allocate, TAG_OBJECT);
4889 __ bind(&done_allocate);
4890
4891 // Setup the elements array in r6.
4892 __ LoadRoot(r4, Heap::kFixedArrayMapRootIndex);
4893 __ StoreP(r4, FieldMemOperand(r6, FixedArray::kMapOffset), r0);
4894 __ StoreP(r3, FieldMemOperand(r6, FixedArray::kLengthOffset), r0);
4895 __ addi(r7, r6,
4896 Operand(FixedArray::kHeaderSize - kHeapObjectTag - kPointerSize));
4897 {
4898 Label loop;
4899 __ SmiUntag(r0, r3);
4900 __ mtctr(r0);
4901 __ bind(&loop);
4902 __ LoadPU(ip, MemOperand(r5, -kPointerSize));
4903 __ StorePU(ip, MemOperand(r7, kPointerSize));
4904 __ bdnz(&loop);
4905 __ addi(r7, r7, Operand(kPointerSize));
4906 }
4907
4908 // Setup the rest parameter array in r7.
4909 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, r4);
4910 __ StoreP(r4, MemOperand(r7, JSArray::kMapOffset));
4911 __ LoadRoot(r4, Heap::kEmptyFixedArrayRootIndex);
4912 __ StoreP(r4, MemOperand(r7, JSArray::kPropertiesOffset));
4913 __ StoreP(r6, MemOperand(r7, JSArray::kElementsOffset));
4914 __ StoreP(r3, MemOperand(r7, JSArray::kLengthOffset));
4915 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4916 __ addi(r3, r7, Operand(kHeapObjectTag));
4917 __ Ret();
4918
4919 // Fall back to %AllocateInNewSpace.
4920 __ bind(&allocate);
4921 {
4922 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4923 __ SmiTag(r4);
4924 __ Push(r3, r5, r4);
4925 __ CallRuntime(Runtime::kAllocateInNewSpace);
4926 __ mr(r6, r3);
4927 __ Pop(r3, r5);
4928 }
4929 __ b(&done_allocate);
4930 }
4931}
4932
4933void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) {
4934 // ----------- S t a t e -------------
4935 // -- r4 : function
4936 // -- cp : context
4937 // -- fp : frame pointer
4938 // -- lr : return address
4939 // -----------------------------------
4940 __ AssertFunction(r4);
4941
4942 // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub.
4943 __ LoadP(r5, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
4944 __ LoadWordArith(
4945 r5, FieldMemOperand(r5, SharedFunctionInfo::kFormalParameterCountOffset));
4946#if V8_TARGET_ARCH_PPC64
4947 __ SmiTag(r5);
4948#endif
4949 __ SmiToPtrArrayOffset(r6, r5);
4950 __ add(r6, fp, r6);
4951 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
4952
4953 // r4 : function
4954 // r5 : number of parameters (tagged)
4955 // r6 : parameters pointer
4956 // Registers used over whole function:
4957 // r8 : arguments count (tagged)
4958 // r9 : mapped parameter count (tagged)
4959
4960 // Check if the calling frame is an arguments adaptor frame.
4961 Label adaptor_frame, try_allocate, runtime;
4962 __ LoadP(r7, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01004963 __ LoadP(r3, MemOperand(r7, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004964 __ CmpSmiLiteral(r3, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
4965 __ beq(&adaptor_frame);
4966
4967 // No adaptor, parameter count = argument count.
4968 __ mr(r8, r5);
4969 __ mr(r9, r5);
4970 __ b(&try_allocate);
4971
4972 // We have an adaptor frame. Patch the parameters pointer.
4973 __ bind(&adaptor_frame);
4974 __ LoadP(r8, MemOperand(r7, ArgumentsAdaptorFrameConstants::kLengthOffset));
4975 __ SmiToPtrArrayOffset(r6, r8);
4976 __ add(r6, r6, r7);
4977 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
4978
4979 // r8 = argument count (tagged)
4980 // r9 = parameter count (tagged)
4981 // Compute the mapped parameter count = min(r5, r8) in r9.
4982 __ cmp(r5, r8);
4983 if (CpuFeatures::IsSupported(ISELECT)) {
4984 __ isel(lt, r9, r5, r8);
4985 } else {
4986 Label skip;
4987 __ mr(r9, r5);
4988 __ blt(&skip);
4989 __ mr(r9, r8);
4990 __ bind(&skip);
4991 }
4992
4993 __ bind(&try_allocate);
4994
4995 // Compute the sizes of backing store, parameter map, and arguments object.
4996 // 1. Parameter map, has 2 extra words containing context and backing store.
4997 const int kParameterMapHeaderSize =
4998 FixedArray::kHeaderSize + 2 * kPointerSize;
4999 // If there are no mapped parameters, we do not need the parameter_map.
5000 __ CmpSmiLiteral(r9, Smi::FromInt(0), r0);
5001 if (CpuFeatures::IsSupported(ISELECT)) {
5002 __ SmiToPtrArrayOffset(r11, r9);
5003 __ addi(r11, r11, Operand(kParameterMapHeaderSize));
5004 __ isel(eq, r11, r0, r11);
5005 } else {
5006 Label skip2, skip3;
5007 __ bne(&skip2);
5008 __ li(r11, Operand::Zero());
5009 __ b(&skip3);
5010 __ bind(&skip2);
5011 __ SmiToPtrArrayOffset(r11, r9);
5012 __ addi(r11, r11, Operand(kParameterMapHeaderSize));
5013 __ bind(&skip3);
5014 }
5015
5016 // 2. Backing store.
5017 __ SmiToPtrArrayOffset(r7, r8);
5018 __ add(r11, r11, r7);
5019 __ addi(r11, r11, Operand(FixedArray::kHeaderSize));
5020
5021 // 3. Arguments object.
5022 __ addi(r11, r11, Operand(JSSloppyArgumentsObject::kSize));
5023
5024 // Do the allocation of all three objects in one go.
5025 __ Allocate(r11, r3, r11, r7, &runtime, TAG_OBJECT);
5026
5027 // r3 = address of new object(s) (tagged)
5028 // r5 = argument count (smi-tagged)
5029 // Get the arguments boilerplate from the current native context into r4.
5030 const int kNormalOffset =
5031 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
5032 const int kAliasedOffset =
5033 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
5034
5035 __ LoadP(r7, NativeContextMemOperand());
5036 __ cmpi(r9, Operand::Zero());
5037 if (CpuFeatures::IsSupported(ISELECT)) {
5038 __ LoadP(r11, MemOperand(r7, kNormalOffset));
5039 __ LoadP(r7, MemOperand(r7, kAliasedOffset));
5040 __ isel(eq, r7, r11, r7);
5041 } else {
5042 Label skip4, skip5;
5043 __ bne(&skip4);
5044 __ LoadP(r7, MemOperand(r7, kNormalOffset));
5045 __ b(&skip5);
5046 __ bind(&skip4);
5047 __ LoadP(r7, MemOperand(r7, kAliasedOffset));
5048 __ bind(&skip5);
5049 }
5050
5051 // r3 = address of new object (tagged)
5052 // r5 = argument count (smi-tagged)
5053 // r7 = address of arguments map (tagged)
5054 // r9 = mapped parameter count (tagged)
5055 __ StoreP(r7, FieldMemOperand(r3, JSObject::kMapOffset), r0);
5056 __ LoadRoot(r11, Heap::kEmptyFixedArrayRootIndex);
5057 __ StoreP(r11, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
5058 __ StoreP(r11, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
5059
5060 // Set up the callee in-object property.
5061 __ AssertNotSmi(r4);
5062 __ StoreP(r4, FieldMemOperand(r3, JSSloppyArgumentsObject::kCalleeOffset),
5063 r0);
5064
5065 // Use the length (smi tagged) and set that as an in-object property too.
5066 __ AssertSmi(r8);
5067 __ StoreP(r8, FieldMemOperand(r3, JSSloppyArgumentsObject::kLengthOffset),
5068 r0);
5069
5070 // Set up the elements pointer in the allocated arguments object.
5071 // If we allocated a parameter map, r7 will point there, otherwise
5072 // it will point to the backing store.
5073 __ addi(r7, r3, Operand(JSSloppyArgumentsObject::kSize));
5074 __ StoreP(r7, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
5075
5076 // r3 = address of new object (tagged)
5077 // r5 = argument count (tagged)
5078 // r7 = address of parameter map or backing store (tagged)
5079 // r9 = mapped parameter count (tagged)
5080 // Initialize parameter map. If there are no mapped arguments, we're done.
5081 Label skip_parameter_map;
5082 __ CmpSmiLiteral(r9, Smi::FromInt(0), r0);
5083 if (CpuFeatures::IsSupported(ISELECT)) {
5084 __ isel(eq, r4, r7, r4);
5085 __ beq(&skip_parameter_map);
5086 } else {
5087 Label skip6;
5088 __ bne(&skip6);
5089 // Move backing store address to r4, because it is
5090 // expected there when filling in the unmapped arguments.
5091 __ mr(r4, r7);
5092 __ b(&skip_parameter_map);
5093 __ bind(&skip6);
5094 }
5095
5096 __ LoadRoot(r8, Heap::kSloppyArgumentsElementsMapRootIndex);
5097 __ StoreP(r8, FieldMemOperand(r7, FixedArray::kMapOffset), r0);
5098 __ AddSmiLiteral(r8, r9, Smi::FromInt(2), r0);
5099 __ StoreP(r8, FieldMemOperand(r7, FixedArray::kLengthOffset), r0);
5100 __ StoreP(cp, FieldMemOperand(r7, FixedArray::kHeaderSize + 0 * kPointerSize),
5101 r0);
5102 __ SmiToPtrArrayOffset(r8, r9);
5103 __ add(r8, r8, r7);
5104 __ addi(r8, r8, Operand(kParameterMapHeaderSize));
5105 __ StoreP(r8, FieldMemOperand(r7, FixedArray::kHeaderSize + 1 * kPointerSize),
5106 r0);
5107
5108 // Copy the parameter slots and the holes in the arguments.
5109 // We need to fill in mapped_parameter_count slots. They index the context,
5110 // where parameters are stored in reverse order, at
5111 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
5112 // The mapped parameter thus need to get indices
5113 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
5114 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
5115 // We loop from right to left.
5116 Label parameters_loop;
5117 __ mr(r8, r9);
5118 __ AddSmiLiteral(r11, r5, Smi::FromInt(Context::MIN_CONTEXT_SLOTS), r0);
5119 __ sub(r11, r11, r9);
5120 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
5121 __ SmiToPtrArrayOffset(r4, r8);
5122 __ add(r4, r4, r7);
5123 __ addi(r4, r4, Operand(kParameterMapHeaderSize));
5124
5125 // r4 = address of backing store (tagged)
5126 // r7 = address of parameter map (tagged)
5127 // r8 = temporary scratch (a.o., for address calculation)
5128 // r10 = temporary scratch (a.o., for address calculation)
5129 // ip = the hole value
5130 __ SmiUntag(r8);
5131 __ mtctr(r8);
5132 __ ShiftLeftImm(r8, r8, Operand(kPointerSizeLog2));
5133 __ add(r10, r4, r8);
5134 __ add(r8, r7, r8);
5135 __ addi(r10, r10, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
5136 __ addi(r8, r8, Operand(kParameterMapHeaderSize - kHeapObjectTag));
5137
5138 __ bind(&parameters_loop);
5139 __ StorePU(r11, MemOperand(r8, -kPointerSize));
5140 __ StorePU(ip, MemOperand(r10, -kPointerSize));
5141 __ AddSmiLiteral(r11, r11, Smi::FromInt(1), r0);
5142 __ bdnz(&parameters_loop);
5143
5144 // Restore r8 = argument count (tagged).
5145 __ LoadP(r8, FieldMemOperand(r3, JSSloppyArgumentsObject::kLengthOffset));
5146
5147 __ bind(&skip_parameter_map);
5148 // r3 = address of new object (tagged)
5149 // r4 = address of backing store (tagged)
5150 // r8 = argument count (tagged)
5151 // r9 = mapped parameter count (tagged)
5152 // r11 = scratch
5153 // Copy arguments header and remaining slots (if there are any).
5154 __ LoadRoot(r11, Heap::kFixedArrayMapRootIndex);
5155 __ StoreP(r11, FieldMemOperand(r4, FixedArray::kMapOffset), r0);
5156 __ StoreP(r8, FieldMemOperand(r4, FixedArray::kLengthOffset), r0);
5157 __ sub(r11, r8, r9, LeaveOE, SetRC);
5158 __ Ret(eq, cr0);
5159
5160 Label arguments_loop;
5161 __ SmiUntag(r11);
5162 __ mtctr(r11);
5163
5164 __ SmiToPtrArrayOffset(r0, r9);
5165 __ sub(r6, r6, r0);
5166 __ add(r11, r4, r0);
5167 __ addi(r11, r11,
5168 Operand(FixedArray::kHeaderSize - kHeapObjectTag - kPointerSize));
5169
5170 __ bind(&arguments_loop);
5171 __ LoadPU(r7, MemOperand(r6, -kPointerSize));
5172 __ StorePU(r7, MemOperand(r11, kPointerSize));
5173 __ bdnz(&arguments_loop);
5174
5175 // Return.
5176 __ Ret();
5177
5178 // Do the runtime call to allocate the arguments object.
5179 // r8 = argument count (tagged)
5180 __ bind(&runtime);
5181 __ Push(r4, r6, r8);
5182 __ TailCallRuntime(Runtime::kNewSloppyArguments);
5183}
5184
5185void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) {
5186 // ----------- S t a t e -------------
5187 // -- r4 : function
5188 // -- cp : context
5189 // -- fp : frame pointer
5190 // -- lr : return address
5191 // -----------------------------------
5192 __ AssertFunction(r4);
5193
5194 // For Ignition we need to skip all possible handler/stub frames until
5195 // we reach the JavaScript frame for the function (similar to what the
5196 // runtime fallback implementation does). So make r5 point to that
5197 // JavaScript frame.
5198 {
5199 Label loop, loop_entry;
5200 __ mr(r5, fp);
5201 __ b(&loop_entry);
5202 __ bind(&loop);
5203 __ LoadP(r5, MemOperand(r5, StandardFrameConstants::kCallerFPOffset));
5204 __ bind(&loop_entry);
Ben Murdochda12d292016-06-02 14:46:10 +01005205 __ LoadP(ip, MemOperand(r5, StandardFrameConstants::kFunctionOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005206 __ cmp(ip, r4);
5207 __ bne(&loop);
5208 }
5209
5210 // Check if we have an arguments adaptor frame below the function frame.
5211 Label arguments_adaptor, arguments_done;
5212 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01005213 __ LoadP(ip, MemOperand(r6, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005214 __ CmpSmiLiteral(ip, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
5215 __ beq(&arguments_adaptor);
5216 {
5217 __ LoadP(r4, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
5218 __ LoadWordArith(
5219 r3,
5220 FieldMemOperand(r4, SharedFunctionInfo::kFormalParameterCountOffset));
5221#if V8_TARGET_ARCH_PPC64
5222 __ SmiTag(r3);
5223#endif
5224 __ SmiToPtrArrayOffset(r9, r3);
5225 __ add(r5, r5, r9);
5226 }
5227 __ b(&arguments_done);
5228 __ bind(&arguments_adaptor);
5229 {
5230 __ LoadP(r3, MemOperand(r6, ArgumentsAdaptorFrameConstants::kLengthOffset));
5231 __ SmiToPtrArrayOffset(r9, r3);
5232 __ add(r5, r6, r9);
5233 }
5234 __ bind(&arguments_done);
5235 __ addi(r5, r5, Operand(StandardFrameConstants::kCallerSPOffset));
5236
5237 // ----------- S t a t e -------------
5238 // -- cp : context
5239 // -- r3 : number of rest parameters (tagged)
5240 // -- r5 : pointer just past first rest parameters
5241 // -- r9 : size of rest parameters
5242 // -- lr : return address
5243 // -----------------------------------
5244
5245 // Allocate space for the strict arguments object plus the backing store.
5246 Label allocate, done_allocate;
5247 __ mov(r4, Operand(JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize));
5248 __ add(r4, r4, r9);
5249 __ Allocate(r4, r6, r7, r8, &allocate, TAG_OBJECT);
5250 __ bind(&done_allocate);
5251
5252 // Setup the elements array in r6.
5253 __ LoadRoot(r4, Heap::kFixedArrayMapRootIndex);
5254 __ StoreP(r4, FieldMemOperand(r6, FixedArray::kMapOffset), r0);
5255 __ StoreP(r3, FieldMemOperand(r6, FixedArray::kLengthOffset), r0);
5256 __ addi(r7, r6,
5257 Operand(FixedArray::kHeaderSize - kHeapObjectTag - kPointerSize));
5258 {
5259 Label loop, done_loop;
5260 __ SmiUntag(r0, r3, SetRC);
5261 __ beq(&done_loop, cr0);
5262 __ mtctr(r0);
5263 __ bind(&loop);
5264 __ LoadPU(ip, MemOperand(r5, -kPointerSize));
5265 __ StorePU(ip, MemOperand(r7, kPointerSize));
5266 __ bdnz(&loop);
5267 __ bind(&done_loop);
5268 __ addi(r7, r7, Operand(kPointerSize));
5269 }
5270
5271 // Setup the rest parameter array in r7.
5272 __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, r4);
5273 __ StoreP(r4, MemOperand(r7, JSStrictArgumentsObject::kMapOffset));
5274 __ LoadRoot(r4, Heap::kEmptyFixedArrayRootIndex);
5275 __ StoreP(r4, MemOperand(r7, JSStrictArgumentsObject::kPropertiesOffset));
5276 __ StoreP(r6, MemOperand(r7, JSStrictArgumentsObject::kElementsOffset));
5277 __ StoreP(r3, MemOperand(r7, JSStrictArgumentsObject::kLengthOffset));
5278 STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize);
5279 __ addi(r3, r7, Operand(kHeapObjectTag));
5280 __ Ret();
5281
5282 // Fall back to %AllocateInNewSpace.
5283 __ bind(&allocate);
5284 {
5285 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
5286 __ SmiTag(r4);
5287 __ Push(r3, r5, r4);
5288 __ CallRuntime(Runtime::kAllocateInNewSpace);
5289 __ mr(r6, r3);
5290 __ Pop(r3, r5);
5291 }
5292 __ b(&done_allocate);
5293}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005294
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005295void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5296 Register context = cp;
5297 Register result = r3;
5298 Register slot = r5;
5299
5300 // Go up the context chain to the script context.
5301 for (int i = 0; i < depth(); ++i) {
5302 __ LoadP(result, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5303 context = result;
5304 }
5305
5306 // Load the PropertyCell value at the specified slot.
5307 __ ShiftLeftImm(r0, slot, Operand(kPointerSizeLog2));
5308 __ add(result, context, r0);
5309 __ LoadP(result, ContextMemOperand(result));
5310 __ LoadP(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5311
5312 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5313 __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
5314 __ Ret(ne);
5315
5316 // Fallback to runtime.
5317 __ SmiTag(slot);
5318 __ Push(slot);
5319 __ TailCallRuntime(Runtime::kLoadGlobalViaContext);
5320}
5321
5322
5323void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5324 Register value = r3;
5325 Register slot = r5;
5326
5327 Register cell = r4;
5328 Register cell_details = r6;
5329 Register cell_value = r7;
5330 Register cell_value_map = r8;
5331 Register scratch = r9;
5332
5333 Register context = cp;
5334 Register context_temp = cell;
5335
5336 Label fast_heapobject_case, fast_smi_case, slow_case;
5337
5338 if (FLAG_debug_code) {
5339 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5340 __ Check(ne, kUnexpectedValue);
5341 }
5342
5343 // Go up the context chain to the script context.
5344 for (int i = 0; i < depth(); i++) {
5345 __ LoadP(context_temp, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5346 context = context_temp;
5347 }
5348
5349 // Load the PropertyCell at the specified slot.
5350 __ ShiftLeftImm(r0, slot, Operand(kPointerSizeLog2));
5351 __ add(cell, context, r0);
5352 __ LoadP(cell, ContextMemOperand(cell));
5353
5354 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5355 __ LoadP(cell_details, FieldMemOperand(cell, PropertyCell::kDetailsOffset));
5356 __ SmiUntag(cell_details);
5357 __ andi(cell_details, cell_details,
5358 Operand(PropertyDetails::PropertyCellTypeField::kMask |
5359 PropertyDetails::KindField::kMask |
5360 PropertyDetails::kAttributesReadOnlyMask));
5361
5362 // Check if PropertyCell holds mutable data.
5363 Label not_mutable_data;
5364 __ cmpi(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5365 PropertyCellType::kMutable) |
5366 PropertyDetails::KindField::encode(kData)));
5367 __ bne(&not_mutable_data);
5368 __ JumpIfSmi(value, &fast_smi_case);
5369
5370 __ bind(&fast_heapobject_case);
5371 __ StoreP(value, FieldMemOperand(cell, PropertyCell::kValueOffset), r0);
5372 // RecordWriteField clobbers the value register, so we copy it before the
5373 // call.
5374 __ mr(r6, value);
5375 __ RecordWriteField(cell, PropertyCell::kValueOffset, r6, scratch,
5376 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5377 OMIT_SMI_CHECK);
5378 __ Ret();
5379
5380 __ bind(&not_mutable_data);
5381 // Check if PropertyCell value matches the new value (relevant for Constant,
5382 // ConstantType and Undefined cells).
5383 Label not_same_value;
5384 __ LoadP(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5385 __ cmp(cell_value, value);
5386 __ bne(&not_same_value);
5387
5388 // Make sure the PropertyCell is not marked READ_ONLY.
5389 __ andi(r0, cell_details, Operand(PropertyDetails::kAttributesReadOnlyMask));
5390 __ bne(&slow_case, cr0);
5391
5392 if (FLAG_debug_code) {
5393 Label done;
5394 // This can only be true for Constant, ConstantType and Undefined cells,
5395 // because we never store the_hole via this stub.
5396 __ cmpi(cell_details,
5397 Operand(PropertyDetails::PropertyCellTypeField::encode(
5398 PropertyCellType::kConstant) |
5399 PropertyDetails::KindField::encode(kData)));
5400 __ beq(&done);
5401 __ cmpi(cell_details,
5402 Operand(PropertyDetails::PropertyCellTypeField::encode(
5403 PropertyCellType::kConstantType) |
5404 PropertyDetails::KindField::encode(kData)));
5405 __ beq(&done);
5406 __ cmpi(cell_details,
5407 Operand(PropertyDetails::PropertyCellTypeField::encode(
5408 PropertyCellType::kUndefined) |
5409 PropertyDetails::KindField::encode(kData)));
5410 __ Check(eq, kUnexpectedValue);
5411 __ bind(&done);
5412 }
5413 __ Ret();
5414 __ bind(&not_same_value);
5415
5416 // Check if PropertyCell contains data with constant type (and is not
5417 // READ_ONLY).
5418 __ cmpi(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5419 PropertyCellType::kConstantType) |
5420 PropertyDetails::KindField::encode(kData)));
5421 __ bne(&slow_case);
5422
5423 // Now either both old and new values must be smis or both must be heap
5424 // objects with same map.
5425 Label value_is_heap_object;
5426 __ JumpIfNotSmi(value, &value_is_heap_object);
5427 __ JumpIfNotSmi(cell_value, &slow_case);
5428 // Old and new values are smis, no need for a write barrier here.
5429 __ bind(&fast_smi_case);
5430 __ StoreP(value, FieldMemOperand(cell, PropertyCell::kValueOffset), r0);
5431 __ Ret();
5432
5433 __ bind(&value_is_heap_object);
5434 __ JumpIfSmi(cell_value, &slow_case);
5435
5436 __ LoadP(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5437 __ LoadP(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5438 __ cmp(cell_value_map, scratch);
5439 __ beq(&fast_heapobject_case);
5440
5441 // Fallback to runtime.
5442 __ bind(&slow_case);
5443 __ SmiTag(slot);
5444 __ Push(slot, value);
5445 __ TailCallRuntime(is_strict(language_mode())
5446 ? Runtime::kStoreGlobalViaContext_Strict
5447 : Runtime::kStoreGlobalViaContext_Sloppy);
5448}
5449
5450
5451static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5452 return ref0.address() - ref1.address();
5453}
5454
5455
5456// Calls an API function. Allocates HandleScope, extracts returned value
5457// from handle and propagates exceptions. Restores context. stack_space
5458// - space to be unwound on exit (includes the call JS arguments space and
5459// the additional space allocated for the fast call).
5460static void CallApiFunctionAndReturn(MacroAssembler* masm,
5461 Register function_address,
5462 ExternalReference thunk_ref,
5463 int stack_space,
5464 MemOperand* stack_space_operand,
5465 MemOperand return_value_operand,
5466 MemOperand* context_restore_operand) {
5467 Isolate* isolate = masm->isolate();
5468 ExternalReference next_address =
5469 ExternalReference::handle_scope_next_address(isolate);
5470 const int kNextOffset = 0;
5471 const int kLimitOffset = AddressOffset(
5472 ExternalReference::handle_scope_limit_address(isolate), next_address);
5473 const int kLevelOffset = AddressOffset(
5474 ExternalReference::handle_scope_level_address(isolate), next_address);
5475
5476 // Additional parameter is the address of the actual callback.
5477 DCHECK(function_address.is(r4) || function_address.is(r5));
5478 Register scratch = r6;
5479
5480 __ mov(scratch, Operand(ExternalReference::is_profiling_address(isolate)));
5481 __ lbz(scratch, MemOperand(scratch, 0));
5482 __ cmpi(scratch, Operand::Zero());
5483
5484 if (CpuFeatures::IsSupported(ISELECT)) {
5485 __ mov(scratch, Operand(thunk_ref));
5486 __ isel(eq, scratch, function_address, scratch);
5487 } else {
5488 Label profiler_disabled;
5489 Label end_profiler_check;
5490 __ beq(&profiler_disabled);
5491 __ mov(scratch, Operand(thunk_ref));
5492 __ b(&end_profiler_check);
5493 __ bind(&profiler_disabled);
5494 __ mr(scratch, function_address);
5495 __ bind(&end_profiler_check);
5496 }
5497
5498 // Allocate HandleScope in callee-save registers.
5499 // r17 - next_address
5500 // r14 - next_address->kNextOffset
5501 // r15 - next_address->kLimitOffset
5502 // r16 - next_address->kLevelOffset
5503 __ mov(r17, Operand(next_address));
5504 __ LoadP(r14, MemOperand(r17, kNextOffset));
5505 __ LoadP(r15, MemOperand(r17, kLimitOffset));
5506 __ lwz(r16, MemOperand(r17, kLevelOffset));
5507 __ addi(r16, r16, Operand(1));
5508 __ stw(r16, MemOperand(r17, kLevelOffset));
5509
5510 if (FLAG_log_timer_events) {
5511 FrameScope frame(masm, StackFrame::MANUAL);
5512 __ PushSafepointRegisters();
5513 __ PrepareCallCFunction(1, r3);
5514 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5515 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5516 1);
5517 __ PopSafepointRegisters();
5518 }
5519
5520 // Native call returns to the DirectCEntry stub which redirects to the
5521 // return address pushed on stack (could have moved after GC).
5522 // DirectCEntry stub itself is generated early and never moves.
5523 DirectCEntryStub stub(isolate);
5524 stub.GenerateCall(masm, scratch);
5525
5526 if (FLAG_log_timer_events) {
5527 FrameScope frame(masm, StackFrame::MANUAL);
5528 __ PushSafepointRegisters();
5529 __ PrepareCallCFunction(1, r3);
5530 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5531 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5532 1);
5533 __ PopSafepointRegisters();
5534 }
5535
5536 Label promote_scheduled_exception;
5537 Label delete_allocated_handles;
5538 Label leave_exit_frame;
5539 Label return_value_loaded;
5540
5541 // load value from ReturnValue
5542 __ LoadP(r3, return_value_operand);
5543 __ bind(&return_value_loaded);
5544 // No more valid handles (the result handle was the last one). Restore
5545 // previous handle scope.
5546 __ StoreP(r14, MemOperand(r17, kNextOffset));
5547 if (__ emit_debug_code()) {
5548 __ lwz(r4, MemOperand(r17, kLevelOffset));
5549 __ cmp(r4, r16);
5550 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5551 }
5552 __ subi(r16, r16, Operand(1));
5553 __ stw(r16, MemOperand(r17, kLevelOffset));
5554 __ LoadP(r0, MemOperand(r17, kLimitOffset));
5555 __ cmp(r15, r0);
5556 __ bne(&delete_allocated_handles);
5557
5558 // Leave the API exit frame.
5559 __ bind(&leave_exit_frame);
5560 bool restore_context = context_restore_operand != NULL;
5561 if (restore_context) {
5562 __ LoadP(cp, *context_restore_operand);
5563 }
5564 // LeaveExitFrame expects unwind space to be in a register.
5565 if (stack_space_operand != NULL) {
5566 __ lwz(r14, *stack_space_operand);
5567 } else {
5568 __ mov(r14, Operand(stack_space));
5569 }
5570 __ LeaveExitFrame(false, r14, !restore_context, stack_space_operand != NULL);
5571
5572 // Check if the function scheduled an exception.
5573 __ LoadRoot(r14, Heap::kTheHoleValueRootIndex);
5574 __ mov(r15, Operand(ExternalReference::scheduled_exception_address(isolate)));
5575 __ LoadP(r15, MemOperand(r15));
5576 __ cmp(r14, r15);
5577 __ bne(&promote_scheduled_exception);
5578
5579 __ blr();
5580
5581 // Re-throw by promoting a scheduled exception.
5582 __ bind(&promote_scheduled_exception);
5583 __ TailCallRuntime(Runtime::kPromoteScheduledException);
5584
5585 // HandleScope limit has changed. Delete allocated extensions.
5586 __ bind(&delete_allocated_handles);
5587 __ StoreP(r15, MemOperand(r17, kLimitOffset));
5588 __ mr(r14, r3);
5589 __ PrepareCallCFunction(1, r15);
5590 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5591 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5592 1);
5593 __ mr(r3, r14);
5594 __ b(&leave_exit_frame);
5595}
5596
Ben Murdochda12d292016-06-02 14:46:10 +01005597void CallApiCallbackStub::Generate(MacroAssembler* masm) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005598 // ----------- S t a t e -------------
5599 // -- r3 : callee
5600 // -- r7 : call_data
5601 // -- r5 : holder
5602 // -- r4 : api_function_address
5603 // -- cp : context
5604 // --
5605 // -- sp[0] : last argument
5606 // -- ...
5607 // -- sp[(argc - 1)* 4] : first argument
5608 // -- sp[argc * 4] : receiver
5609 // -----------------------------------
5610
5611 Register callee = r3;
5612 Register call_data = r7;
5613 Register holder = r5;
5614 Register api_function_address = r4;
5615 Register context = cp;
5616
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005617 typedef FunctionCallbackArguments FCA;
5618
5619 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5620 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5621 STATIC_ASSERT(FCA::kDataIndex == 4);
5622 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5623 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5624 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5625 STATIC_ASSERT(FCA::kHolderIndex == 0);
5626 STATIC_ASSERT(FCA::kArgsLength == 7);
5627
5628 // context save
5629 __ push(context);
Ben Murdochda12d292016-06-02 14:46:10 +01005630 if (!is_lazy()) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01005631 // load context from callee
5632 __ LoadP(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5633 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005634
5635 // callee
5636 __ push(callee);
5637
5638 // call data
5639 __ push(call_data);
5640
5641 Register scratch = call_data;
Ben Murdochda12d292016-06-02 14:46:10 +01005642 if (!call_data_undefined()) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005643 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5644 }
5645 // return value
5646 __ push(scratch);
5647 // return value default
5648 __ push(scratch);
5649 // isolate
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005650 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005651 __ push(scratch);
5652 // holder
5653 __ push(holder);
5654
5655 // Prepare arguments.
5656 __ mr(scratch, sp);
5657
5658 // Allocate the v8::Arguments structure in the arguments' space since
5659 // it's not controlled by GC.
5660 // PPC LINUX ABI:
5661 //
5662 // Create 5 extra slots on stack:
5663 // [0] space for DirectCEntryStub's LR save
5664 // [1-4] FunctionCallbackInfo
5665 const int kApiStackSpace = 5;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005666 const int kFunctionCallbackInfoOffset =
5667 (kStackFrameExtraParamSlot + 1) * kPointerSize;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005668
5669 FrameScope frame_scope(masm, StackFrame::MANUAL);
5670 __ EnterExitFrame(false, kApiStackSpace);
5671
5672 DCHECK(!api_function_address.is(r3) && !scratch.is(r3));
5673 // r3 = FunctionCallbackInfo&
5674 // Arguments is after the return address.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005675 __ addi(r3, sp, Operand(kFunctionCallbackInfoOffset));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005676 // FunctionCallbackInfo::implicit_args_
5677 __ StoreP(scratch, MemOperand(r3, 0 * kPointerSize));
Ben Murdochda12d292016-06-02 14:46:10 +01005678 // FunctionCallbackInfo::values_
5679 __ addi(ip, scratch, Operand((FCA::kArgsLength - 1 + argc()) * kPointerSize));
5680 __ StoreP(ip, MemOperand(r3, 1 * kPointerSize));
5681 // FunctionCallbackInfo::length_ = argc
5682 __ li(ip, Operand(argc()));
5683 __ stw(ip, MemOperand(r3, 2 * kPointerSize));
5684 // FunctionCallbackInfo::is_construct_call_ = 0
5685 __ li(ip, Operand::Zero());
5686 __ stw(ip, MemOperand(r3, 2 * kPointerSize + kIntSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005687
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005688 ExternalReference thunk_ref =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005689 ExternalReference::invoke_function_callback(masm->isolate());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005690
5691 AllowExternalCallThatCantCauseGC scope(masm);
5692 MemOperand context_restore_operand(
5693 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5694 // Stores return the first js argument
5695 int return_value_offset = 0;
Ben Murdochda12d292016-06-02 14:46:10 +01005696 if (is_store()) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005697 return_value_offset = 2 + FCA::kArgsLength;
5698 } else {
5699 return_value_offset = 2 + FCA::kReturnValueOffset;
5700 }
5701 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005702 int stack_space = 0;
5703 MemOperand is_construct_call_operand =
5704 MemOperand(sp, kFunctionCallbackInfoOffset + 2 * kPointerSize + kIntSize);
5705 MemOperand* stack_space_operand = &is_construct_call_operand;
Ben Murdochda12d292016-06-02 14:46:10 +01005706 stack_space = argc() + FCA::kArgsLength + 1;
5707 stack_space_operand = NULL;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005708 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5709 stack_space_operand, return_value_operand,
5710 &context_restore_operand);
5711}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005712
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005713
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005714void CallApiGetterStub::Generate(MacroAssembler* masm) {
5715 // ----------- S t a t e -------------
Ben Murdoch097c5b22016-05-18 11:27:45 +01005716 // -- sp[0] : name
5717 // -- sp[4 .. (4 + kArgsLength*4)] : v8::PropertyCallbackInfo::args_
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005718 // -- ...
Ben Murdoch097c5b22016-05-18 11:27:45 +01005719 // -- r5 : api_function_address
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005720 // -----------------------------------
5721
5722 Register api_function_address = ApiGetterDescriptor::function_address();
Ben Murdoch097c5b22016-05-18 11:27:45 +01005723 int arg0Slot = 0;
5724 int accessorInfoSlot = 0;
5725 int apiStackSpace = 0;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005726 DCHECK(api_function_address.is(r5));
5727
Ben Murdoch097c5b22016-05-18 11:27:45 +01005728 // v8::PropertyCallbackInfo::args_ array and name handle.
5729 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5730
5731 // Load address of v8::PropertyAccessorInfo::args_ array and name handle.
5732 __ mr(r3, sp); // r3 = Handle<Name>
5733 __ addi(r4, r3, Operand(1 * kPointerSize)); // r4 = v8::PCI::args_
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005734
5735// If ABI passes Handles (pointer-sized struct) in a register:
5736//
5737// Create 2 extra slots on stack:
5738// [0] space for DirectCEntryStub's LR save
5739// [1] AccessorInfo&
5740//
5741// Otherwise:
5742//
5743// Create 3 extra slots on stack:
5744// [0] space for DirectCEntryStub's LR save
5745// [1] copy of Handle (first arg)
5746// [2] AccessorInfo&
Ben Murdoch097c5b22016-05-18 11:27:45 +01005747 if (ABI_PASSES_HANDLES_IN_REGS) {
5748 accessorInfoSlot = kStackFrameExtraParamSlot + 1;
5749 apiStackSpace = 2;
5750 } else {
5751 arg0Slot = kStackFrameExtraParamSlot + 1;
5752 accessorInfoSlot = arg0Slot + 1;
5753 apiStackSpace = 3;
5754 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005755
5756 FrameScope frame_scope(masm, StackFrame::MANUAL);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005757 __ EnterExitFrame(false, apiStackSpace);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005758
Ben Murdoch097c5b22016-05-18 11:27:45 +01005759 if (!ABI_PASSES_HANDLES_IN_REGS) {
5760 // pass 1st arg by reference
5761 __ StoreP(r3, MemOperand(sp, arg0Slot * kPointerSize));
5762 __ addi(r3, sp, Operand(arg0Slot * kPointerSize));
5763 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005764
Ben Murdoch097c5b22016-05-18 11:27:45 +01005765 // Create v8::PropertyCallbackInfo object on the stack and initialize
5766 // it's args_ field.
5767 __ StoreP(r4, MemOperand(sp, accessorInfoSlot * kPointerSize));
5768 __ addi(r4, sp, Operand(accessorInfoSlot * kPointerSize));
5769 // r4 = v8::PropertyCallbackInfo&
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005770
5771 ExternalReference thunk_ref =
5772 ExternalReference::invoke_accessor_getter_callback(isolate());
Ben Murdoch097c5b22016-05-18 11:27:45 +01005773
5774 // +3 is to skip prolog, return address and name handle.
5775 MemOperand return_value_operand(
5776 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005777 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005778 kStackUnwindSpace, NULL, return_value_operand, NULL);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005779}
5780
5781
5782#undef __
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005783} // namespace internal
5784} // namespace v8
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005785
5786#endif // V8_TARGET_ARCH_PPC