1 // 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.
9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h"
11 #include "src/code-stubs.h"
12 #include "src/codegen.h"
13 #include "src/ic/handler-compiler.h"
14 #include "src/ic/ic.h"
15 #include "src/ic/stub-cache.h"
16 #include "src/isolate.h"
17 #include "src/jsregexp.h"
18 #include "src/regexp-macro-assembler.h"
19 #include "src/runtime/runtime.h"
25 static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
28 Address deopt_handler =
29 Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
31 if (constant_stack_parameter_count == 0) {
32 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
33 JS_FUNCTION_STUB_MODE);
35 descriptor->Initialize(r3, deopt_handler, constant_stack_parameter_count,
36 JS_FUNCTION_STUB_MODE);
41 static void InitializeInternalArrayConstructorDescriptor(
42 Isolate* isolate, CodeStubDescriptor* descriptor,
43 int constant_stack_parameter_count) {
44 Address deopt_handler =
45 Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
47 if (constant_stack_parameter_count == 0) {
48 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
49 JS_FUNCTION_STUB_MODE);
51 descriptor->Initialize(r3, deopt_handler, constant_stack_parameter_count,
52 JS_FUNCTION_STUB_MODE);
57 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
63 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
64 CodeStubDescriptor* descriptor) {
65 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
69 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
70 CodeStubDescriptor* descriptor) {
71 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
75 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
76 CodeStubDescriptor* descriptor) {
77 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
81 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
82 CodeStubDescriptor* descriptor) {
83 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
87 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
88 CodeStubDescriptor* descriptor) {
89 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
93 #define __ ACCESS_MASM(masm)
96 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
97 Condition cond, Strength strength);
98 static void EmitSmiNonsmiComparison(MacroAssembler* masm, Register lhs,
99 Register rhs, Label* lhs_not_nan,
100 Label* slow, bool strict);
101 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register lhs,
105 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
106 ExternalReference miss) {
107 // Update the static counter each time a new code stub is generated.
108 isolate()->counters()->code_stubs()->Increment();
110 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
111 int param_count = descriptor.GetRegisterParameterCount();
113 // Call the runtime system in a fresh internal frame.
114 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
115 DCHECK(param_count == 0 ||
116 r3.is(descriptor.GetRegisterParameter(param_count - 1)));
118 for (int i = 0; i < param_count; ++i) {
119 __ push(descriptor.GetRegisterParameter(i));
121 __ CallExternalReference(miss, param_count);
128 void DoubleToIStub::Generate(MacroAssembler* masm) {
129 Label out_of_range, only_low, negate, done, fastpath_done;
130 Register input_reg = source();
131 Register result_reg = destination();
132 DCHECK(is_truncating());
134 int double_offset = offset();
136 // Immediate values for this stub fit in instructions, so it's safe to use ip.
137 Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
138 Register scratch_low =
139 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
140 Register scratch_high =
141 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
142 DoubleRegister double_scratch = kScratchDoubleReg;
145 // Account for saved regs if input is sp.
146 if (input_reg.is(sp)) double_offset += kPointerSize;
148 if (!skip_fastpath()) {
149 // Load double input.
150 __ lfd(double_scratch, MemOperand(input_reg, double_offset));
152 // Do fast-path convert from double to int.
153 __ ConvertDoubleToInt64(double_scratch,
154 #if !V8_TARGET_ARCH_PPC64
160 #if V8_TARGET_ARCH_PPC64
161 __ TestIfInt32(result_reg, r0);
163 __ TestIfInt32(scratch, result_reg, r0);
165 __ beq(&fastpath_done);
168 __ Push(scratch_high, scratch_low);
169 // Account for saved regs if input is sp.
170 if (input_reg.is(sp)) double_offset += 2 * kPointerSize;
173 MemOperand(input_reg, double_offset + Register::kExponentOffset));
175 MemOperand(input_reg, double_offset + Register::kMantissaOffset));
177 __ ExtractBitMask(scratch, scratch_high, HeapNumber::kExponentMask);
178 // Load scratch with exponent - 1. This is faster than loading
179 // with exponent because Bias + 1 = 1024 which is a *PPC* immediate value.
180 STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
181 __ subi(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
182 // If exponent is greater than or equal to 84, the 32 less significant
183 // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
185 // Compare exponent with 84 (compare exponent - 1 with 83).
186 __ cmpi(scratch, Operand(83));
187 __ bge(&out_of_range);
189 // If we reach this code, 31 <= exponent <= 83.
190 // So, we don't have to handle cases where 0 <= exponent <= 20 for
191 // which we would need to shift right the high part of the mantissa.
192 // Scratch contains exponent - 1.
193 // Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
194 __ subfic(scratch, scratch, Operand(51));
195 __ cmpi(scratch, Operand::Zero());
197 // 21 <= exponent <= 51, shift scratch_low and scratch_high
198 // to generate the result.
199 __ srw(scratch_low, scratch_low, scratch);
200 // Scratch contains: 52 - exponent.
201 // We needs: exponent - 20.
202 // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
203 __ subfic(scratch, scratch, Operand(32));
204 __ ExtractBitMask(result_reg, scratch_high, HeapNumber::kMantissaMask);
205 // Set the implicit 1 before the mantissa part in scratch_high.
206 STATIC_ASSERT(HeapNumber::kMantissaBitsInTopWord >= 16);
207 __ oris(result_reg, result_reg,
208 Operand(1 << ((HeapNumber::kMantissaBitsInTopWord) - 16)));
209 __ slw(r0, result_reg, scratch);
210 __ orx(result_reg, scratch_low, r0);
213 __ bind(&out_of_range);
214 __ mov(result_reg, Operand::Zero());
218 // 52 <= exponent <= 83, shift only scratch_low.
219 // On entry, scratch contains: 52 - exponent.
220 __ neg(scratch, scratch);
221 __ slw(result_reg, scratch_low, scratch);
224 // If input was positive, scratch_high ASR 31 equals 0 and
225 // scratch_high LSR 31 equals zero.
226 // New result = (result eor 0) + 0 = result.
227 // If the input was negative, we have to negate the result.
228 // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
229 // New result = (result eor 0xffffffff) + 1 = 0 - result.
230 __ srawi(r0, scratch_high, 31);
231 #if V8_TARGET_ARCH_PPC64
232 __ srdi(r0, r0, Operand(32));
234 __ xor_(result_reg, result_reg, r0);
235 __ srwi(r0, scratch_high, Operand(31));
236 __ add(result_reg, result_reg, r0);
239 __ Pop(scratch_high, scratch_low);
241 __ bind(&fastpath_done);
248 // Handle the case where the lhs and rhs are the same object.
249 // Equality is almost reflexive (everything but NaN), so this is a test
250 // for "identity and not NaN".
251 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
252 Condition cond, Strength strength) {
254 Label heap_number, return_equal;
256 __ bne(¬_identical);
258 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
259 // so we do the second best thing - test it ourselves.
260 // They are both equal and they are not both Smis so both of them are not
261 // Smis. If it's not a heap number, then return equal.
262 if (cond == lt || cond == gt) {
263 // Call runtime on identical JSObjects.
264 __ CompareObjectType(r3, r7, r7, FIRST_SPEC_OBJECT_TYPE);
266 // Call runtime on identical symbols since we need to throw a TypeError.
267 __ cmpi(r7, Operand(SYMBOL_TYPE));
269 // Call runtime on identical SIMD values since we must throw a TypeError.
270 __ cmpi(r7, Operand(FLOAT32X4_TYPE));
272 if (is_strong(strength)) {
273 // Call the runtime on anything that is converted in the semantics, since
274 // we need to throw a TypeError. Smis have already been ruled out.
275 __ cmpi(r7, Operand(HEAP_NUMBER_TYPE));
276 __ beq(&return_equal);
277 __ andi(r0, r7, Operand(kIsNotStringMask));
281 __ CompareObjectType(r3, r7, r7, HEAP_NUMBER_TYPE);
282 __ beq(&heap_number);
283 // Comparing JS objects with <=, >= is complicated.
285 __ cmpi(r7, Operand(FIRST_SPEC_OBJECT_TYPE));
287 // Call runtime on identical symbols since we need to throw a TypeError.
288 __ cmpi(r7, Operand(SYMBOL_TYPE));
290 // Call runtime on identical SIMD values since we must throw a TypeError.
291 __ cmpi(r7, Operand(FLOAT32X4_TYPE));
293 if (is_strong(strength)) {
294 // Call the runtime on anything that is converted in the semantics,
295 // since we need to throw a TypeError. Smis and heap numbers have
296 // already been ruled out.
297 __ andi(r0, r7, Operand(kIsNotStringMask));
300 // Normally here we fall through to return_equal, but undefined is
301 // special: (undefined == undefined) == true, but
302 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
303 if (cond == le || cond == ge) {
304 __ cmpi(r7, Operand(ODDBALL_TYPE));
305 __ bne(&return_equal);
306 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
308 __ bne(&return_equal);
310 // undefined <= undefined should fail.
311 __ li(r3, Operand(GREATER));
313 // undefined >= undefined should fail.
314 __ li(r3, Operand(LESS));
321 __ bind(&return_equal);
323 __ li(r3, Operand(GREATER)); // Things aren't less than themselves.
324 } else if (cond == gt) {
325 __ li(r3, Operand(LESS)); // Things aren't greater than themselves.
327 __ li(r3, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
331 // For less and greater we don't have to check for NaN since the result of
332 // x < x is false regardless. For the others here is some code to check
334 if (cond != lt && cond != gt) {
335 __ bind(&heap_number);
336 // It is a heap number, so return non-equal if it's NaN and equal if it's
339 // The representation of NaN values has all exponent bits (52..62) set,
340 // and not all mantissa bits (0..51) clear.
341 // Read top bits of double representation (second word of value).
342 __ lwz(r5, FieldMemOperand(r3, HeapNumber::kExponentOffset));
343 // Test that exponent bits are all set.
344 STATIC_ASSERT(HeapNumber::kExponentMask == 0x7ff00000u);
345 __ ExtractBitMask(r6, r5, HeapNumber::kExponentMask);
346 __ cmpli(r6, Operand(0x7ff));
347 __ bne(&return_equal);
349 // Shift out flag and all exponent bits, retaining only mantissa.
350 __ slwi(r5, r5, Operand(HeapNumber::kNonMantissaBitsInTopWord));
351 // Or with all low-bits of mantissa.
352 __ lwz(r6, FieldMemOperand(r3, HeapNumber::kMantissaOffset));
354 __ cmpi(r3, Operand::Zero());
355 // For equal we already have the right value in r3: Return zero (equal)
356 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
357 // not (it's a NaN). For <= and >= we need to load r0 with the failing
358 // value if it's a NaN.
360 if (CpuFeatures::IsSupported(ISELECT)) {
361 __ li(r4, Operand((cond == le) ? GREATER : LESS));
362 __ isel(eq, r3, r3, r4);
364 // All-zero means Infinity means equal.
367 __ li(r3, Operand(GREATER)); // NaN <= NaN should fail.
369 __ li(r3, Operand(LESS)); // NaN >= NaN should fail.
375 // No fall through here.
377 __ bind(¬_identical);
381 // See comment at call site.
382 static void EmitSmiNonsmiComparison(MacroAssembler* masm, Register lhs,
383 Register rhs, Label* lhs_not_nan,
384 Label* slow, bool strict) {
385 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
388 __ JumpIfSmi(rhs, &rhs_is_smi);
390 // Lhs is a Smi. Check whether the rhs is a heap number.
391 __ CompareObjectType(rhs, r6, r7, HEAP_NUMBER_TYPE);
393 // If rhs is not a number and lhs is a Smi then strict equality cannot
394 // succeed. Return non-equal
395 // If rhs is r3 then there is already a non zero value in it.
399 __ mov(r3, Operand(NOT_EQUAL));
406 // Smi compared non-strictly with a non-Smi non-heap-number. Call
411 // Lhs is a smi, rhs is a number.
412 // Convert lhs to a double in d7.
413 __ SmiToDouble(d7, lhs);
414 // Load the double from rhs, tagged HeapNumber r3, to d6.
415 __ lfd(d6, FieldMemOperand(rhs, HeapNumber::kValueOffset));
417 // We now have both loaded as doubles but we can skip the lhs nan check
421 __ bind(&rhs_is_smi);
422 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
423 __ CompareObjectType(lhs, r7, r7, HEAP_NUMBER_TYPE);
425 // If lhs is not a number and rhs is a smi then strict equality cannot
426 // succeed. Return non-equal.
427 // If lhs is r3 then there is already a non zero value in it.
431 __ mov(r3, Operand(NOT_EQUAL));
438 // Smi compared non-strictly with a non-smi non-heap-number. Call
443 // Rhs is a smi, lhs is a heap number.
444 // Load the double from lhs, tagged HeapNumber r4, to d7.
445 __ lfd(d7, FieldMemOperand(lhs, HeapNumber::kValueOffset));
446 // Convert rhs to a double in d6.
447 __ SmiToDouble(d6, rhs);
448 // Fall through to both_loaded_as_doubles.
452 // See comment at call site.
453 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register lhs,
455 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
457 // If either operand is a JS object or an oddball value, then they are
458 // not equal since their pointers are different.
459 // There is no test for undetectability in strict equality.
460 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
461 Label first_non_object;
462 // Get the type of the first operand into r5 and compare it with
463 // FIRST_SPEC_OBJECT_TYPE.
464 __ CompareObjectType(rhs, r5, r5, FIRST_SPEC_OBJECT_TYPE);
465 __ blt(&first_non_object);
467 // Return non-zero (r3 is not zero)
468 Label return_not_equal;
469 __ bind(&return_not_equal);
472 __ bind(&first_non_object);
473 // Check for oddballs: true, false, null, undefined.
474 __ cmpi(r5, Operand(ODDBALL_TYPE));
475 __ beq(&return_not_equal);
477 __ CompareObjectType(lhs, r6, r6, FIRST_SPEC_OBJECT_TYPE);
478 __ bge(&return_not_equal);
480 // Check for oddballs: true, false, null, undefined.
481 __ cmpi(r6, Operand(ODDBALL_TYPE));
482 __ beq(&return_not_equal);
484 // Now that we have the types we might as well check for
485 // internalized-internalized.
486 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
488 __ andi(r0, r5, Operand(kIsNotStringMask | kIsNotInternalizedMask));
489 __ beq(&return_not_equal, cr0);
493 // See comment at call site.
494 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, Register lhs,
496 Label* both_loaded_as_doubles,
497 Label* not_heap_numbers, Label* slow) {
498 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
500 __ CompareObjectType(rhs, r6, r5, HEAP_NUMBER_TYPE);
501 __ bne(not_heap_numbers);
502 __ LoadP(r5, FieldMemOperand(lhs, HeapObject::kMapOffset));
504 __ bne(slow); // First was a heap number, second wasn't. Go slow case.
506 // Both are heap numbers. Load them up then jump to the code we have
508 __ lfd(d6, FieldMemOperand(rhs, HeapNumber::kValueOffset));
509 __ lfd(d7, FieldMemOperand(lhs, HeapNumber::kValueOffset));
511 __ b(both_loaded_as_doubles);
515 // Fast negative check for internalized-to-internalized equality.
516 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
517 Register lhs, Register rhs,
518 Label* possible_strings,
519 Label* not_both_strings) {
520 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
522 // r5 is object type of rhs.
524 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
525 __ andi(r0, r5, Operand(kIsNotStringMask));
526 __ bne(&object_test, cr0);
527 __ andi(r0, r5, Operand(kIsNotInternalizedMask));
528 __ bne(possible_strings, cr0);
529 __ CompareObjectType(lhs, r6, r6, FIRST_NONSTRING_TYPE);
530 __ bge(not_both_strings);
531 __ andi(r0, r6, Operand(kIsNotInternalizedMask));
532 __ bne(possible_strings, cr0);
534 // Both are internalized. We already checked they weren't the same pointer
535 // so they are not equal.
536 __ li(r3, Operand(NOT_EQUAL));
539 __ bind(&object_test);
540 __ cmpi(r5, Operand(FIRST_SPEC_OBJECT_TYPE));
541 __ blt(not_both_strings);
542 __ CompareObjectType(lhs, r5, r6, FIRST_SPEC_OBJECT_TYPE);
543 __ blt(not_both_strings);
544 // If both objects are undetectable, they are equal. Otherwise, they
545 // are not equal, since they are different objects and an object is not
546 // equal to undefined.
547 __ LoadP(r6, FieldMemOperand(rhs, HeapObject::kMapOffset));
548 __ lbz(r5, FieldMemOperand(r5, Map::kBitFieldOffset));
549 __ lbz(r6, FieldMemOperand(r6, Map::kBitFieldOffset));
551 __ andi(r3, r3, Operand(1 << Map::kIsUndetectable));
552 __ xori(r3, r3, Operand(1 << Map::kIsUndetectable));
557 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
559 CompareICState::State expected,
562 if (expected == CompareICState::SMI) {
563 __ JumpIfNotSmi(input, fail);
564 } else if (expected == CompareICState::NUMBER) {
565 __ JumpIfSmi(input, &ok);
566 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
569 // We could be strict about internalized/non-internalized here, but as long as
570 // hydrogen doesn't care, the stub doesn't have to care either.
575 // On entry r4 and r5 are the values to be compared.
576 // On exit r3 is 0, positive or negative to indicate the result of
578 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
581 Condition cc = GetCondition();
584 CompareICStub_CheckInputType(masm, lhs, r5, left(), &miss);
585 CompareICStub_CheckInputType(masm, rhs, r6, right(), &miss);
587 Label slow; // Call builtin.
588 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
590 Label not_two_smis, smi_done;
592 __ JumpIfNotSmi(r5, ¬_two_smis);
597 __ bind(¬_two_smis);
599 // NOTICE! This code is only reached after a smi-fast-case check, so
600 // it is certain that at least one operand isn't a smi.
602 // Handle the case where the objects are identical. Either returns the answer
603 // or goes to slow. Only falls through if the objects were not identical.
604 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
606 // If either is a Smi (we know that not both are), then they can only
607 // be strictly equal if the other is a HeapNumber.
608 STATIC_ASSERT(kSmiTag == 0);
609 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
610 __ and_(r5, lhs, rhs);
611 __ JumpIfNotSmi(r5, ¬_smis);
612 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
613 // 1) Return the answer.
615 // 3) Fall through to both_loaded_as_doubles.
616 // 4) Jump to lhs_not_nan.
617 // In cases 3 and 4 we have found out we were dealing with a number-number
618 // comparison. The double values of the numbers have been loaded
620 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
622 __ bind(&both_loaded_as_doubles);
623 // The arguments have been converted to doubles and stored in d6 and d7
624 __ bind(&lhs_not_nan);
628 Label nan, equal, less_than;
630 if (CpuFeatures::IsSupported(ISELECT)) {
632 __ li(r4, Operand(GREATER));
633 __ li(r5, Operand(LESS));
634 __ isel(eq, r3, r0, r4);
635 __ isel(lt, r3, r5, r3);
640 __ li(r3, Operand(GREATER));
643 __ li(r3, Operand(EQUAL));
646 __ li(r3, Operand(LESS));
651 // If one of the sides was a NaN then the v flag is set. Load r3 with
652 // whatever it takes to make the comparison fail, since comparisons with NaN
654 if (cc == lt || cc == le) {
655 __ li(r3, Operand(GREATER));
657 __ li(r3, Operand(LESS));
662 // At this point we know we are dealing with two different objects,
663 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
665 // This returns non-equal for some object types, or falls through if it
667 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
670 Label check_for_internalized_strings;
671 Label flat_string_check;
672 // Check for heap-number-heap-number comparison. Can jump to slow case,
673 // or load both doubles into r3, r4, r5, r6 and jump to the code that handles
674 // that case. If the inputs are not doubles then jumps to
675 // check_for_internalized_strings.
676 // In this case r5 will contain the type of rhs_. Never falls through.
677 EmitCheckForTwoHeapNumbers(masm, lhs, rhs, &both_loaded_as_doubles,
678 &check_for_internalized_strings,
681 __ bind(&check_for_internalized_strings);
682 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
683 // internalized strings.
684 if (cc == eq && !strict()) {
685 // Returns an answer for two internalized strings or two detectable objects.
686 // Otherwise jumps to string case or not both strings case.
687 // Assumes that r5 is the type of rhs_ on entry.
688 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, &flat_string_check,
692 // Check for both being sequential one-byte strings,
693 // and inline if that is the case.
694 __ bind(&flat_string_check);
696 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r5, r6, &slow);
698 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r5,
701 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r5, r6);
703 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r5, r6, r7);
705 // Never falls through to here.
710 // Figure out which native to call and setup the arguments.
711 Builtins::JavaScript native;
713 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
716 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
717 int ncr; // NaN compare result
718 if (cc == lt || cc == le) {
721 DCHECK(cc == gt || cc == ge); // remaining cases
724 __ LoadSmiLiteral(r3, Smi::FromInt(ncr));
728 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
729 // tagged as a small integer.
730 __ InvokeBuiltin(native, JUMP_FUNCTION);
737 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
738 // We don't allow a GC during a store buffer overflow so there is no need to
739 // store the registers in any particular way, but we do have to store and
742 __ MultiPush(kJSCallerSaved | r0.bit());
743 if (save_doubles()) {
744 __ SaveFPRegs(sp, 0, DoubleRegister::kNumVolatileRegisters);
746 const int argument_count = 1;
747 const int fp_argument_count = 0;
748 const Register scratch = r4;
750 AllowExternalCallThatCantCauseGC scope(masm);
751 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
752 __ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
753 __ CallCFunction(ExternalReference::store_buffer_overflow_function(isolate()),
755 if (save_doubles()) {
756 __ RestoreFPRegs(sp, 0, DoubleRegister::kNumVolatileRegisters);
758 __ MultiPop(kJSCallerSaved | r0.bit());
764 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
765 __ PushSafepointRegisters();
770 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
771 __ PopSafepointRegisters();
776 void MathPowStub::Generate(MacroAssembler* masm) {
777 const Register base = r4;
778 const Register exponent = MathPowTaggedDescriptor::exponent();
779 DCHECK(exponent.is(r5));
780 const Register heapnumbermap = r8;
781 const Register heapnumber = r3;
782 const DoubleRegister double_base = d1;
783 const DoubleRegister double_exponent = d2;
784 const DoubleRegister double_result = d3;
785 const DoubleRegister double_scratch = d0;
786 const Register scratch = r11;
787 const Register scratch2 = r10;
789 Label call_runtime, done, int_exponent;
790 if (exponent_type() == ON_STACK) {
791 Label base_is_smi, unpack_exponent;
792 // The exponent and base are supplied as arguments on the stack.
793 // This can only happen if the stub is called from non-optimized code.
794 // Load input parameters from stack to double registers.
795 __ LoadP(base, MemOperand(sp, 1 * kPointerSize));
796 __ LoadP(exponent, MemOperand(sp, 0 * kPointerSize));
798 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
800 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
801 __ LoadP(scratch, FieldMemOperand(base, JSObject::kMapOffset));
802 __ cmp(scratch, heapnumbermap);
803 __ bne(&call_runtime);
805 __ lfd(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
806 __ b(&unpack_exponent);
808 __ bind(&base_is_smi);
809 __ ConvertIntToDouble(scratch, double_base);
810 __ bind(&unpack_exponent);
812 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
813 __ LoadP(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
814 __ cmp(scratch, heapnumbermap);
815 __ bne(&call_runtime);
817 __ lfd(double_exponent,
818 FieldMemOperand(exponent, HeapNumber::kValueOffset));
819 } else if (exponent_type() == TAGGED) {
820 // Base is already in double_base.
821 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
823 __ lfd(double_exponent,
824 FieldMemOperand(exponent, HeapNumber::kValueOffset));
827 if (exponent_type() != INTEGER) {
828 // Detect integer exponents stored as double.
829 __ TryDoubleToInt32Exact(scratch, double_exponent, scratch2,
831 __ beq(&int_exponent);
833 if (exponent_type() == ON_STACK) {
834 // Detect square root case. Crankshaft detects constant +/-0.5 at
835 // compile time and uses DoMathPowHalf instead. We then skip this check
836 // for non-constant cases of +/-0.5 as these hardly occur.
837 Label not_plus_half, not_minus_inf1, not_minus_inf2;
840 __ LoadDoubleLiteral(double_scratch, 0.5, scratch);
841 __ fcmpu(double_exponent, double_scratch);
842 __ bne(¬_plus_half);
844 // Calculates square root of base. Check for the special case of
845 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
846 __ LoadDoubleLiteral(double_scratch, -V8_INFINITY, scratch);
847 __ fcmpu(double_base, double_scratch);
848 __ bne(¬_minus_inf1);
849 __ fneg(double_result, double_scratch);
851 __ bind(¬_minus_inf1);
853 // Add +0 to convert -0 to +0.
854 __ fadd(double_scratch, double_base, kDoubleRegZero);
855 __ fsqrt(double_result, double_scratch);
858 __ bind(¬_plus_half);
859 __ LoadDoubleLiteral(double_scratch, -0.5, scratch);
860 __ fcmpu(double_exponent, double_scratch);
861 __ bne(&call_runtime);
863 // Calculates square root of base. Check for the special case of
864 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
865 __ LoadDoubleLiteral(double_scratch, -V8_INFINITY, scratch);
866 __ fcmpu(double_base, double_scratch);
867 __ bne(¬_minus_inf2);
868 __ fmr(double_result, kDoubleRegZero);
870 __ bind(¬_minus_inf2);
872 // Add +0 to convert -0 to +0.
873 __ fadd(double_scratch, double_base, kDoubleRegZero);
874 __ LoadDoubleLiteral(double_result, 1.0, scratch);
875 __ fsqrt(double_scratch, double_scratch);
876 __ fdiv(double_result, double_result, double_scratch);
883 AllowExternalCallThatCantCauseGC scope(masm);
884 __ PrepareCallCFunction(0, 2, scratch);
885 __ MovToFloatParameters(double_base, double_exponent);
887 ExternalReference::power_double_double_function(isolate()), 0, 2);
891 __ MovFromFloatResult(double_result);
895 // Calculate power with integer exponent.
896 __ bind(&int_exponent);
898 // Get two copies of exponent in the registers scratch and exponent.
899 if (exponent_type() == INTEGER) {
900 __ mr(scratch, exponent);
902 // Exponent has previously been stored into scratch as untagged integer.
903 __ mr(exponent, scratch);
905 __ fmr(double_scratch, double_base); // Back up base.
906 __ li(scratch2, Operand(1));
907 __ ConvertIntToDouble(scratch2, double_result);
909 // Get absolute value of exponent.
910 __ cmpi(scratch, Operand::Zero());
911 if (CpuFeatures::IsSupported(ISELECT)) {
912 __ neg(scratch2, scratch);
913 __ isel(lt, scratch, scratch2, scratch);
915 Label positive_exponent;
916 __ bge(&positive_exponent);
917 __ neg(scratch, scratch);
918 __ bind(&positive_exponent);
921 Label while_true, no_carry, loop_end;
922 __ bind(&while_true);
923 __ andi(scratch2, scratch, Operand(1));
924 __ beq(&no_carry, cr0);
925 __ fmul(double_result, double_result, double_scratch);
927 __ ShiftRightArithImm(scratch, scratch, 1, SetRC);
928 __ beq(&loop_end, cr0);
929 __ fmul(double_scratch, double_scratch, double_scratch);
933 __ cmpi(exponent, Operand::Zero());
936 __ li(scratch2, Operand(1));
937 __ ConvertIntToDouble(scratch2, double_scratch);
938 __ fdiv(double_result, double_scratch, double_result);
939 // Test whether result is zero. Bail out to check for subnormal result.
940 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
941 __ fcmpu(double_result, kDoubleRegZero);
943 // double_exponent may not containe the exponent value if the input was a
944 // smi. We set it with exponent value before bailing out.
945 __ ConvertIntToDouble(exponent, double_exponent);
947 // Returning or bailing out.
948 Counters* counters = isolate()->counters();
949 if (exponent_type() == ON_STACK) {
950 // The arguments are still on the stack.
951 __ bind(&call_runtime);
952 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
954 // The stub is called from non-optimized code, which expects the result
955 // as heap number in exponent.
957 __ AllocateHeapNumber(heapnumber, scratch, scratch2, heapnumbermap,
959 __ stfd(double_result,
960 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
961 DCHECK(heapnumber.is(r3));
962 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
968 AllowExternalCallThatCantCauseGC scope(masm);
969 __ PrepareCallCFunction(0, 2, scratch);
970 __ MovToFloatParameters(double_base, double_exponent);
972 ExternalReference::power_double_double_function(isolate()), 0, 2);
976 __ MovFromFloatResult(double_result);
979 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
985 bool CEntryStub::NeedsImmovableCode() { return true; }
988 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
989 CEntryStub::GenerateAheadOfTime(isolate);
990 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
991 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
992 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
993 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
994 CreateWeakCellStub::GenerateAheadOfTime(isolate);
995 BinaryOpICStub::GenerateAheadOfTime(isolate);
996 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
997 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
998 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
999 StoreFastElementStub::GenerateAheadOfTime(isolate);
1000 TypeofStub::GenerateAheadOfTime(isolate);
1004 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1005 StoreRegistersStateStub stub(isolate);
1010 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1011 RestoreRegistersStateStub stub(isolate);
1016 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1017 // Generate if not already in cache.
1018 SaveFPRegsMode mode = kSaveFPRegs;
1019 CEntryStub(isolate, 1, mode).GetCode();
1020 StoreBufferOverflowStub(isolate, mode).GetCode();
1021 isolate->set_fp_stubs_generated(true);
1025 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1026 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1031 void CEntryStub::Generate(MacroAssembler* masm) {
1032 // Called from JavaScript; parameters are on stack as if calling JS function.
1033 // r3: number of arguments including receiver
1034 // r4: pointer to builtin function
1035 // fp: frame pointer (restored after C call)
1036 // sp: stack pointer (restored as callee's sp after C call)
1037 // cp: current context (C callee-saved)
1039 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1043 // Compute the argv pointer.
1044 __ ShiftLeftImm(r4, r3, Operand(kPointerSizeLog2));
1046 __ subi(r4, r4, Operand(kPointerSize));
1048 // Enter the exit frame that transitions from JavaScript to C++.
1049 FrameScope scope(masm, StackFrame::MANUAL);
1051 // Need at least one extra slot for return address location.
1052 int arg_stack_space = 1;
1055 #if !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
1056 // Pass buffer for return value on stack if necessary
1057 if (result_size() > 1) {
1058 DCHECK_EQ(2, result_size());
1059 arg_stack_space += 2;
1063 __ EnterExitFrame(save_doubles(), arg_stack_space);
1065 // Store a copy of argc in callee-saved registers for later.
1068 // r3, r14: number of arguments including receiver (C callee-saved)
1069 // r4: pointer to the first argument
1070 // r15: pointer to builtin function (C callee-saved)
1072 // Result returned in registers or stack, depending on result size and ABI.
1074 Register isolate_reg = r5;
1075 #if !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
1076 if (result_size() > 1) {
1077 // The return value is 16-byte non-scalar value.
1078 // Use frame storage reserved by calling function to pass return
1079 // buffer as implicit first argument.
1082 __ addi(r3, sp, Operand((kStackFrameExtraParamSlot + 1) * kPointerSize));
1088 __ mov(isolate_reg, Operand(ExternalReference::isolate_address(isolate())));
1090 #if ABI_USES_FUNCTION_DESCRIPTORS && !defined(USE_SIMULATOR)
1091 // Native AIX/PPC64 Linux use a function descriptor.
1092 __ LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(r15, kPointerSize));
1093 __ LoadP(ip, MemOperand(r15, 0)); // Instruction address
1094 Register target = ip;
1095 #elif ABI_TOC_ADDRESSABILITY_VIA_IP
1097 Register target = ip;
1099 Register target = r15;
1102 // To let the GC traverse the return address of the exit frames, we need to
1103 // know where the return address is. The CEntryStub is unmovable, so
1104 // we can store the address on the stack to be able to find it again and
1105 // we never have to restore it, because it will not change.
1107 __ mov_label_addr(r0, &after_call);
1108 __ StoreP(r0, MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize));
1110 __ bind(&after_call);
1112 #if !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
1113 // If return value is on the stack, pop it to registers.
1114 if (result_size() > 1) {
1115 __ LoadP(r4, MemOperand(r3, kPointerSize));
1116 __ LoadP(r3, MemOperand(r3));
1120 // Check result for exception sentinel.
1121 Label exception_returned;
1122 __ CompareRoot(r3, Heap::kExceptionRootIndex);
1123 __ beq(&exception_returned);
1125 // Check that there is no pending exception, otherwise we
1126 // should have returned the exception sentinel.
1127 if (FLAG_debug_code) {
1129 ExternalReference pending_exception_address(
1130 Isolate::kPendingExceptionAddress, isolate());
1132 __ mov(r5, Operand(pending_exception_address));
1133 __ LoadP(r5, MemOperand(r5));
1134 __ CompareRoot(r5, Heap::kTheHoleValueRootIndex);
1135 // Cannot use check here as it attempts to generate call into runtime.
1137 __ stop("Unexpected pending exception");
1141 // Exit C frame and return.
1143 // sp: stack pointer
1144 // fp: frame pointer
1145 // r14: still holds argc (callee-saved).
1146 __ LeaveExitFrame(save_doubles(), r14, true);
1149 // Handling of exception.
1150 __ bind(&exception_returned);
1152 ExternalReference pending_handler_context_address(
1153 Isolate::kPendingHandlerContextAddress, isolate());
1154 ExternalReference pending_handler_code_address(
1155 Isolate::kPendingHandlerCodeAddress, isolate());
1156 ExternalReference pending_handler_offset_address(
1157 Isolate::kPendingHandlerOffsetAddress, isolate());
1158 ExternalReference pending_handler_fp_address(
1159 Isolate::kPendingHandlerFPAddress, isolate());
1160 ExternalReference pending_handler_sp_address(
1161 Isolate::kPendingHandlerSPAddress, isolate());
1163 // Ask the runtime for help to determine the handler. This will set r3 to
1164 // contain the current pending exception, don't clobber it.
1165 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1168 FrameScope scope(masm, StackFrame::MANUAL);
1169 __ PrepareCallCFunction(3, 0, r3);
1170 __ li(r3, Operand::Zero());
1171 __ li(r4, Operand::Zero());
1172 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
1173 __ CallCFunction(find_handler, 3);
1176 // Retrieve the handler context, SP and FP.
1177 __ mov(cp, Operand(pending_handler_context_address));
1178 __ LoadP(cp, MemOperand(cp));
1179 __ mov(sp, Operand(pending_handler_sp_address));
1180 __ LoadP(sp, MemOperand(sp));
1181 __ mov(fp, Operand(pending_handler_fp_address));
1182 __ LoadP(fp, MemOperand(fp));
1184 // If the handler is a JS frame, restore the context to the frame. Note that
1185 // the context will be set to (cp == 0) for non-JS frames.
1187 __ cmpi(cp, Operand::Zero());
1189 __ StoreP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1192 // Compute the handler entry address and jump to it.
1193 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1194 __ mov(r4, Operand(pending_handler_code_address));
1195 __ LoadP(r4, MemOperand(r4));
1196 __ mov(r5, Operand(pending_handler_offset_address));
1197 __ LoadP(r5, MemOperand(r5));
1198 __ addi(r4, r4, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1199 if (FLAG_enable_embedded_constant_pool) {
1200 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r4);
1207 void JSEntryStub::Generate(MacroAssembler* masm) {
1214 Label invoke, handler_entry, exit;
1217 __ function_descriptor();
1219 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1222 // preserve LR in pre-reserved slot in caller's frame
1224 __ StoreP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize));
1226 // Save callee saved registers on the stack.
1227 __ MultiPush(kCalleeSaved);
1229 // Floating point regs FPR0 - FRP13 are volatile
1230 // FPR14-FPR31 are non-volatile, but sub-calls will save them for us
1232 // int offset_to_argv = kPointerSize * 22; // matches (22*4) above
1233 // __ lwz(r7, MemOperand(sp, offset_to_argv));
1235 // Push a frame with special values setup to mark it as an entry frame.
1241 __ li(r0, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1243 if (FLAG_enable_embedded_constant_pool) {
1244 __ li(kConstantPoolRegister, Operand::Zero());
1245 __ push(kConstantPoolRegister);
1247 int marker = type();
1248 __ LoadSmiLiteral(r0, Smi::FromInt(marker));
1251 // Save copies of the top frame descriptor on the stack.
1252 __ mov(r8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1253 __ LoadP(r0, MemOperand(r8));
1256 // Set up frame pointer for the frame to be pushed.
1257 __ addi(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1259 // If this is the outermost JS call, set js_entry_sp value.
1260 Label non_outermost_js;
1261 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1262 __ mov(r8, Operand(ExternalReference(js_entry_sp)));
1263 __ LoadP(r9, MemOperand(r8));
1264 __ cmpi(r9, Operand::Zero());
1265 __ bne(&non_outermost_js);
1266 __ StoreP(fp, MemOperand(r8));
1267 __ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1270 __ bind(&non_outermost_js);
1271 __ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME));
1273 __ push(ip); // frame-type
1275 // Jump to a faked try block that does the invoke, with a faked catch
1276 // block that sets the pending exception.
1279 __ bind(&handler_entry);
1280 handler_offset_ = handler_entry.pos();
1281 // Caught exception: Store result (exception) in the pending exception
1282 // field in the JSEnv and return a failure sentinel. Coming in here the
1283 // fp will be invalid because the PushStackHandler below sets it to 0 to
1284 // signal the existence of the JSEntry frame.
1285 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1288 __ StoreP(r3, MemOperand(ip));
1289 __ LoadRoot(r3, Heap::kExceptionRootIndex);
1292 // Invoke: Link this frame into the handler chain.
1294 // Must preserve r3-r7.
1295 __ PushStackHandler();
1296 // If an exception not caught by another handler occurs, this handler
1297 // returns control to the code after the b(&invoke) above, which
1298 // restores all kCalleeSaved registers (including cp and fp) to their
1299 // saved values before returning a failure to C.
1301 // Clear any pending exceptions.
1302 __ mov(r8, Operand(isolate()->factory()->the_hole_value()));
1303 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1305 __ StoreP(r8, MemOperand(ip));
1307 // Invoke the function by calling through JS entry trampoline builtin.
1308 // Notice that we cannot store a reference to the trampoline code directly in
1309 // this stub, because runtime stubs are not traversed when doing GC.
1311 // Expected registers by Builtins::JSEntryTrampoline
1317 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1318 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1320 __ mov(ip, Operand(construct_entry));
1322 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
1323 __ mov(ip, Operand(entry));
1325 __ LoadP(ip, MemOperand(ip)); // deref address
1327 // Branch and link to JSEntryTrampoline.
1328 // the address points to the start of the code object, skip the header
1329 __ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1331 __ bctrl(); // make the call
1333 // Unlink this frame from the handler chain.
1334 __ PopStackHandler();
1336 __ bind(&exit); // r3 holds result
1337 // Check if the current stack frame is marked as the outermost JS frame.
1338 Label non_outermost_js_2;
1340 __ CmpSmiLiteral(r8, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME), r0);
1341 __ bne(&non_outermost_js_2);
1342 __ mov(r9, Operand::Zero());
1343 __ mov(r8, Operand(ExternalReference(js_entry_sp)));
1344 __ StoreP(r9, MemOperand(r8));
1345 __ bind(&non_outermost_js_2);
1347 // Restore the top frame descriptors from the stack.
1349 __ mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1350 __ StoreP(r6, MemOperand(ip));
1352 // Reset the stack to the callee saved registers.
1353 __ addi(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1355 // Restore callee-saved registers and return.
1357 if (FLAG_debug_code) {
1364 __ MultiPop(kCalleeSaved);
1366 __ LoadP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize));
1372 // Uses registers r3 to r7.
1373 // Expected input (depending on whether args are in registers or on the stack):
1374 // * object: r3 or at sp + 1 * kPointerSize.
1375 // * function: r4 or at sp.
1377 // An inlined call site may have been generated before calling this stub.
1378 // In this case the offset to the inline site to patch is passed in r8.
1379 // (See LCodeGen::DoInstanceOfKnownGlobal)
1380 void InstanceofStub::Generate(MacroAssembler* masm) {
1381 // Call site inlining and patching implies arguments in registers.
1382 DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck());
1384 // Fixed register usage throughout the stub:
1385 const Register object = r3; // Object (lhs).
1386 Register map = r6; // Map of the object.
1387 const Register function = r4; // Function (rhs).
1388 const Register prototype = r7; // Prototype of the function.
1389 // The map_check_delta was stored in r8
1390 // The bool_load_delta was stored in r9
1391 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1392 const Register map_check_delta = r8;
1393 const Register bool_load_delta = r9;
1394 const Register inline_site = r10;
1395 const Register scratch = r5;
1396 Register scratch3 = no_reg;
1397 Label slow, loop, is_instance, is_not_instance, not_js_object;
1399 if (!HasArgsInRegisters()) {
1400 __ LoadP(object, MemOperand(sp, 1 * kPointerSize));
1401 __ LoadP(function, MemOperand(sp, 0));
1404 // Check that the left hand is a JS object and load map.
1405 __ JumpIfSmi(object, ¬_js_object);
1406 __ IsObjectJSObjectType(object, map, scratch, ¬_js_object);
1408 // If there is a call site cache don't look in the global cache, but do the
1409 // real lookup and update the call site cache.
1410 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
1412 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1414 __ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex);
1416 __ LoadRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
1417 __ Ret(HasArgsInRegisters() ? 0 : 2);
1422 // Get the prototype of the function.
1423 __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
1425 // Check that the function prototype is a JS object.
1426 __ JumpIfSmi(prototype, &slow);
1427 __ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
1429 // Update the global instanceof or call site inlined cache with the current
1430 // map and function. The cached answer will be set when it is known below.
1431 if (!HasCallSiteInlineCheck()) {
1432 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1433 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1435 DCHECK(HasArgsInRegisters());
1436 // Patch the (relocated) inlined map check.
1438 const Register offset = map_check_delta;
1439 __ mflr(inline_site);
1440 __ sub(inline_site, inline_site, offset);
1441 // Get the map location in offset and patch it.
1442 __ GetRelocatedValue(inline_site, offset, scratch);
1443 __ StoreP(map, FieldMemOperand(offset, Cell::kValueOffset), r0);
1446 __ RecordWriteField(offset, Cell::kValueOffset, r11, function,
1447 kLRHasNotBeenSaved, kDontSaveFPRegs,
1448 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
1451 // Register mapping: r6 is object map and r7 is function prototype.
1452 // Get prototype of object into r5.
1453 __ LoadP(scratch, FieldMemOperand(map, Map::kPrototypeOffset));
1455 // We don't need map any more. Use it as a scratch register.
1459 // Loop through the prototype chain looking for the function prototype.
1460 __ LoadRoot(scratch3, Heap::kNullValueRootIndex);
1462 __ cmp(scratch, prototype);
1463 __ beq(&is_instance);
1464 __ cmp(scratch, scratch3);
1465 __ beq(&is_not_instance);
1466 __ LoadP(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
1467 __ LoadP(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset));
1469 Factory* factory = isolate()->factory();
1471 __ bind(&is_instance);
1472 if (!HasCallSiteInlineCheck()) {
1473 __ LoadSmiLiteral(r3, Smi::FromInt(0));
1474 __ StoreRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
1475 if (ReturnTrueFalseObject()) {
1476 __ Move(r3, factory->true_value());
1479 // Patch the call site to return true.
1480 __ LoadRoot(r3, Heap::kTrueValueRootIndex);
1481 __ add(inline_site, inline_site, bool_load_delta);
1482 // Get the boolean result location in scratch and patch it.
1483 __ SetRelocatedValue(inline_site, scratch, r3);
1485 if (!ReturnTrueFalseObject()) {
1486 __ LoadSmiLiteral(r3, Smi::FromInt(0));
1489 __ Ret(HasArgsInRegisters() ? 0 : 2);
1491 __ bind(&is_not_instance);
1492 if (!HasCallSiteInlineCheck()) {
1493 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1494 __ StoreRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
1495 if (ReturnTrueFalseObject()) {
1496 __ Move(r3, factory->false_value());
1499 // Patch the call site to return false.
1500 __ LoadRoot(r3, Heap::kFalseValueRootIndex);
1501 __ add(inline_site, inline_site, bool_load_delta);
1502 // Get the boolean result location in scratch and patch it.
1503 __ SetRelocatedValue(inline_site, scratch, r3);
1505 if (!ReturnTrueFalseObject()) {
1506 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1509 __ Ret(HasArgsInRegisters() ? 0 : 2);
1511 Label object_not_null, object_not_null_or_smi;
1512 __ bind(¬_js_object);
1513 // Before null, smi and string value checks, check that the rhs is a function
1514 // as for a non-function rhs an exception needs to be thrown.
1515 __ JumpIfSmi(function, &slow);
1516 __ CompareObjectType(function, scratch3, scratch, JS_FUNCTION_TYPE);
1519 // Null is not instance of anything.
1520 __ Cmpi(object, Operand(isolate()->factory()->null_value()), r0);
1521 __ bne(&object_not_null);
1522 if (ReturnTrueFalseObject()) {
1523 __ Move(r3, factory->false_value());
1525 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1527 __ Ret(HasArgsInRegisters() ? 0 : 2);
1529 __ bind(&object_not_null);
1530 // Smi values are not instances of anything.
1531 __ JumpIfNotSmi(object, &object_not_null_or_smi);
1532 if (ReturnTrueFalseObject()) {
1533 __ Move(r3, factory->false_value());
1535 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1537 __ Ret(HasArgsInRegisters() ? 0 : 2);
1539 __ bind(&object_not_null_or_smi);
1540 // String values are not instances of anything.
1541 __ IsObjectJSStringType(object, scratch, &slow);
1542 if (ReturnTrueFalseObject()) {
1543 __ Move(r3, factory->false_value());
1545 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1547 __ Ret(HasArgsInRegisters() ? 0 : 2);
1549 // Slow-case. Tail call builtin.
1551 if (!ReturnTrueFalseObject()) {
1552 if (HasArgsInRegisters()) {
1555 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
1558 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
1560 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1562 if (CpuFeatures::IsSupported(ISELECT)) {
1563 __ cmpi(r3, Operand::Zero());
1564 __ LoadRoot(r3, Heap::kTrueValueRootIndex);
1565 __ LoadRoot(r4, Heap::kFalseValueRootIndex);
1566 __ isel(eq, r3, r3, r4);
1568 Label true_value, done;
1569 __ cmpi(r3, Operand::Zero());
1570 __ beq(&true_value);
1572 __ LoadRoot(r3, Heap::kFalseValueRootIndex);
1575 __ bind(&true_value);
1576 __ LoadRoot(r3, Heap::kTrueValueRootIndex);
1580 __ Ret(HasArgsInRegisters() ? 0 : 2);
1585 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1587 Register receiver = LoadDescriptor::ReceiverRegister();
1588 // Ensure that the vector and slot registers won't be clobbered before
1589 // calling the miss handler.
1590 DCHECK(!AreAliased(r7, r8, LoadWithVectorDescriptor::VectorRegister(),
1591 LoadWithVectorDescriptor::SlotRegister()));
1593 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r7,
1596 PropertyAccessCompiler::TailCallBuiltin(
1597 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1601 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1602 // Return address is in lr.
1605 Register receiver = LoadDescriptor::ReceiverRegister();
1606 Register index = LoadDescriptor::NameRegister();
1607 Register scratch = r8;
1608 Register result = r3;
1609 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1610 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1611 result.is(LoadWithVectorDescriptor::SlotRegister()));
1613 // StringCharAtGenerator doesn't use the result register until it's passed
1614 // the different miss possibilities. If it did, we would have a conflict
1615 // when FLAG_vector_ics is true.
1616 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1617 &miss, // When not a string.
1618 &miss, // When not a number.
1619 &miss, // When index out of range.
1620 STRING_INDEX_IS_ARRAY_INDEX,
1621 RECEIVER_IS_STRING);
1622 char_at_generator.GenerateFast(masm);
1625 StubRuntimeCallHelper call_helper;
1626 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1629 PropertyAccessCompiler::TailCallBuiltin(
1630 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1634 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1635 // The displacement is the offset of the last parameter (if any)
1636 // relative to the frame pointer.
1637 const int kDisplacement =
1638 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1639 DCHECK(r4.is(ArgumentsAccessReadDescriptor::index()));
1640 DCHECK(r3.is(ArgumentsAccessReadDescriptor::parameter_count()));
1642 // Check that the key is a smi.
1644 __ JumpIfNotSmi(r4, &slow);
1646 // Check if the calling frame is an arguments adaptor frame.
1648 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1649 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
1650 STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
1651 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
1654 // Check index against formal parameters count limit passed in
1655 // through register r3. Use unsigned comparison to get negative
1660 // Read the argument from the stack and return it.
1662 __ SmiToPtrArrayOffset(r6, r6);
1664 __ LoadP(r3, MemOperand(r6, kDisplacement));
1667 // Arguments adaptor case: Check index against actual arguments
1668 // limit found in the arguments adaptor frame. Use unsigned
1669 // comparison to get negative check for free.
1671 __ LoadP(r3, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
1675 // Read the argument from the adaptor frame and return it.
1677 __ SmiToPtrArrayOffset(r6, r6);
1679 __ LoadP(r3, MemOperand(r6, kDisplacement));
1682 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1683 // by calling the runtime system.
1686 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1690 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1691 // sp[0] : number of parameters
1692 // sp[1] : receiver displacement
1695 // Check if the calling frame is an arguments adaptor frame.
1697 __ LoadP(r6, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1698 __ LoadP(r5, MemOperand(r6, StandardFrameConstants::kContextOffset));
1699 STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
1700 __ CmpSmiLiteral(r5, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
1703 // Patch the arguments.length and the parameters pointer in the current frame.
1704 __ LoadP(r5, MemOperand(r6, ArgumentsAdaptorFrameConstants::kLengthOffset));
1705 __ StoreP(r5, MemOperand(sp, 0 * kPointerSize));
1706 __ SmiToPtrArrayOffset(r5, r5);
1708 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
1709 __ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
1712 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1716 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1718 // sp[0] : number of parameters (tagged)
1719 // sp[1] : address of receiver argument
1721 // Registers used over whole function:
1722 // r9 : allocated object (tagged)
1723 // r11 : mapped parameter count (tagged)
1725 __ LoadP(r4, MemOperand(sp, 0 * kPointerSize));
1726 // r4 = parameter count (tagged)
1728 // Check if the calling frame is an arguments adaptor frame.
1730 Label adaptor_frame, try_allocate;
1731 __ LoadP(r6, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1732 __ LoadP(r5, MemOperand(r6, StandardFrameConstants::kContextOffset));
1733 STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
1734 __ CmpSmiLiteral(r5, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
1735 __ beq(&adaptor_frame);
1737 // No adaptor, parameter count = argument count.
1739 __ b(&try_allocate);
1741 // We have an adaptor frame. Patch the parameters pointer.
1742 __ bind(&adaptor_frame);
1743 __ LoadP(r5, MemOperand(r6, ArgumentsAdaptorFrameConstants::kLengthOffset));
1744 __ SmiToPtrArrayOffset(r7, r5);
1746 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
1747 __ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
1749 // r4 = parameter count (tagged)
1750 // r5 = argument count (tagged)
1751 // Compute the mapped parameter count = min(r4, r5) in r4.
1753 if (CpuFeatures::IsSupported(ISELECT)) {
1754 __ isel(lt, r4, r4, r5);
1762 __ bind(&try_allocate);
1764 // Compute the sizes of backing store, parameter map, and arguments object.
1765 // 1. Parameter map, has 2 extra words containing context and backing store.
1766 const int kParameterMapHeaderSize =
1767 FixedArray::kHeaderSize + 2 * kPointerSize;
1768 // If there are no mapped parameters, we do not need the parameter_map.
1769 __ CmpSmiLiteral(r4, Smi::FromInt(0), r0);
1770 if (CpuFeatures::IsSupported(ISELECT)) {
1771 __ SmiToPtrArrayOffset(r11, r4);
1772 __ addi(r11, r11, Operand(kParameterMapHeaderSize));
1773 __ isel(eq, r11, r0, r11);
1777 __ li(r11, Operand::Zero());
1780 __ SmiToPtrArrayOffset(r11, r4);
1781 __ addi(r11, r11, Operand(kParameterMapHeaderSize));
1785 // 2. Backing store.
1786 __ SmiToPtrArrayOffset(r7, r5);
1787 __ add(r11, r11, r7);
1788 __ addi(r11, r11, Operand(FixedArray::kHeaderSize));
1790 // 3. Arguments object.
1791 __ addi(r11, r11, Operand(Heap::kSloppyArgumentsObjectSize));
1793 // Do the allocation of all three objects in one go.
1794 __ Allocate(r11, r3, r6, r7, &runtime, TAG_OBJECT);
1796 // r3 = address of new object(s) (tagged)
1797 // r5 = argument count (smi-tagged)
1798 // Get the arguments boilerplate from the current native context into r4.
1799 const int kNormalOffset =
1800 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1801 const int kAliasedOffset =
1802 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1805 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1806 __ LoadP(r7, FieldMemOperand(r7, GlobalObject::kNativeContextOffset));
1807 __ cmpi(r4, Operand::Zero());
1808 if (CpuFeatures::IsSupported(ISELECT)) {
1809 __ LoadP(r11, MemOperand(r7, kNormalOffset));
1810 __ LoadP(r7, MemOperand(r7, kAliasedOffset));
1811 __ isel(eq, r7, r11, r7);
1815 __ LoadP(r7, MemOperand(r7, kNormalOffset));
1818 __ LoadP(r7, MemOperand(r7, kAliasedOffset));
1822 // r3 = address of new object (tagged)
1823 // r4 = mapped parameter count (tagged)
1824 // r5 = argument count (smi-tagged)
1825 // r7 = address of arguments map (tagged)
1826 __ StoreP(r7, FieldMemOperand(r3, JSObject::kMapOffset), r0);
1827 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
1828 __ StoreP(r6, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
1829 __ StoreP(r6, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
1831 // Set up the callee in-object property.
1832 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1833 __ LoadP(r6, MemOperand(sp, 2 * kPointerSize));
1834 __ AssertNotSmi(r6);
1835 const int kCalleeOffset =
1836 JSObject::kHeaderSize + Heap::kArgumentsCalleeIndex * kPointerSize;
1837 __ StoreP(r6, FieldMemOperand(r3, kCalleeOffset), r0);
1839 // Use the length (smi tagged) and set that as an in-object property too.
1841 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1842 const int kLengthOffset =
1843 JSObject::kHeaderSize + Heap::kArgumentsLengthIndex * kPointerSize;
1844 __ StoreP(r5, FieldMemOperand(r3, kLengthOffset), r0);
1846 // Set up the elements pointer in the allocated arguments object.
1847 // If we allocated a parameter map, r7 will point there, otherwise
1848 // it will point to the backing store.
1849 __ addi(r7, r3, Operand(Heap::kSloppyArgumentsObjectSize));
1850 __ StoreP(r7, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
1852 // r3 = address of new object (tagged)
1853 // r4 = mapped parameter count (tagged)
1854 // r5 = argument count (tagged)
1855 // r7 = address of parameter map or backing store (tagged)
1856 // Initialize parameter map. If there are no mapped arguments, we're done.
1857 Label skip_parameter_map;
1858 __ CmpSmiLiteral(r4, Smi::FromInt(0), r0);
1859 if (CpuFeatures::IsSupported(ISELECT)) {
1860 __ isel(eq, r6, r7, r6);
1861 __ beq(&skip_parameter_map);
1865 // Move backing store address to r6, because it is
1866 // expected there when filling in the unmapped arguments.
1868 __ b(&skip_parameter_map);
1872 __ LoadRoot(r9, Heap::kSloppyArgumentsElementsMapRootIndex);
1873 __ StoreP(r9, FieldMemOperand(r7, FixedArray::kMapOffset), r0);
1874 __ AddSmiLiteral(r9, r4, Smi::FromInt(2), r0);
1875 __ StoreP(r9, FieldMemOperand(r7, FixedArray::kLengthOffset), r0);
1876 __ StoreP(cp, FieldMemOperand(r7, FixedArray::kHeaderSize + 0 * kPointerSize),
1878 __ SmiToPtrArrayOffset(r9, r4);
1880 __ addi(r9, r9, Operand(kParameterMapHeaderSize));
1881 __ StoreP(r9, FieldMemOperand(r7, FixedArray::kHeaderSize + 1 * kPointerSize),
1884 // Copy the parameter slots and the holes in the arguments.
1885 // We need to fill in mapped_parameter_count slots. They index the context,
1886 // where parameters are stored in reverse order, at
1887 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1888 // The mapped parameter thus need to get indices
1889 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1890 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1891 // We loop from right to left.
1892 Label parameters_loop, parameters_test;
1894 __ LoadP(r11, MemOperand(sp, 0 * kPointerSize));
1895 __ AddSmiLiteral(r11, r11, Smi::FromInt(Context::MIN_CONTEXT_SLOTS), r0);
1896 __ sub(r11, r11, r4);
1897 __ LoadRoot(r10, Heap::kTheHoleValueRootIndex);
1898 __ SmiToPtrArrayOffset(r6, r9);
1900 __ addi(r6, r6, Operand(kParameterMapHeaderSize));
1902 // r9 = loop variable (tagged)
1903 // r4 = mapping index (tagged)
1904 // r6 = address of backing store (tagged)
1905 // r7 = address of parameter map (tagged)
1906 // r8 = temporary scratch (a.o., for address calculation)
1907 // r10 = the hole value
1908 __ b(¶meters_test);
1910 __ bind(¶meters_loop);
1911 __ SubSmiLiteral(r9, r9, Smi::FromInt(1), r0);
1912 __ SmiToPtrArrayOffset(r8, r9);
1913 __ addi(r8, r8, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1914 __ StorePX(r11, MemOperand(r8, r7));
1915 __ subi(r8, r8, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1916 __ StorePX(r10, MemOperand(r8, r6));
1917 __ AddSmiLiteral(r11, r11, Smi::FromInt(1), r0);
1918 __ bind(¶meters_test);
1919 __ CmpSmiLiteral(r9, Smi::FromInt(0), r0);
1920 __ bne(¶meters_loop);
1922 __ bind(&skip_parameter_map);
1923 // r5 = argument count (tagged)
1924 // r6 = address of backing store (tagged)
1926 // Copy arguments header and remaining slots (if there are any).
1927 __ LoadRoot(r8, Heap::kFixedArrayMapRootIndex);
1928 __ StoreP(r8, FieldMemOperand(r6, FixedArray::kMapOffset), r0);
1929 __ StoreP(r5, FieldMemOperand(r6, FixedArray::kLengthOffset), r0);
1931 Label arguments_loop, arguments_test;
1933 __ LoadP(r7, MemOperand(sp, 1 * kPointerSize));
1934 __ SmiToPtrArrayOffset(r8, r11);
1936 __ b(&arguments_test);
1938 __ bind(&arguments_loop);
1939 __ subi(r7, r7, Operand(kPointerSize));
1940 __ LoadP(r9, MemOperand(r7, 0));
1941 __ SmiToPtrArrayOffset(r8, r11);
1943 __ StoreP(r9, FieldMemOperand(r8, FixedArray::kHeaderSize), r0);
1944 __ AddSmiLiteral(r11, r11, Smi::FromInt(1), r0);
1946 __ bind(&arguments_test);
1948 __ blt(&arguments_loop);
1950 // Return and remove the on-stack parameters.
1951 __ addi(sp, sp, Operand(3 * kPointerSize));
1954 // Do the runtime call to allocate the arguments object.
1955 // r5 = argument count (tagged)
1957 __ StoreP(r5, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1958 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1962 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1963 // Return address is in lr.
1966 Register receiver = LoadDescriptor::ReceiverRegister();
1967 Register key = LoadDescriptor::NameRegister();
1969 // Check that the key is an array index, that is Uint32.
1970 __ TestIfPositiveSmi(key, r0);
1973 // Everything is fine, call runtime.
1974 __ Push(receiver, key); // Receiver, key.
1976 // Perform tail call to the entry.
1977 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1980 PropertyAccessCompiler::TailCallBuiltin(
1981 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1985 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1986 // sp[0] : number of parameters
1987 // sp[4] : receiver displacement
1989 // Check if the calling frame is an arguments adaptor frame.
1990 Label adaptor_frame, try_allocate, runtime;
1991 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1992 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
1993 STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
1994 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
1995 __ beq(&adaptor_frame);
1997 // Get the length from the frame.
1998 __ LoadP(r4, MemOperand(sp, 0));
1999 __ b(&try_allocate);
2001 // Patch the arguments.length and the parameters pointer.
2002 __ bind(&adaptor_frame);
2003 __ LoadP(r4, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
2004 __ StoreP(r4, MemOperand(sp, 0));
2005 __ SmiToPtrArrayOffset(r6, r4);
2007 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
2008 __ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
2010 // Try the new space allocation. Start out with computing the size
2011 // of the arguments object and the elements array in words.
2012 Label add_arguments_object;
2013 __ bind(&try_allocate);
2014 __ cmpi(r4, Operand::Zero());
2015 __ beq(&add_arguments_object);
2017 __ addi(r4, r4, Operand(FixedArray::kHeaderSize / kPointerSize));
2018 __ bind(&add_arguments_object);
2019 __ addi(r4, r4, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
2021 // Do the allocation of both objects in one go.
2022 __ Allocate(r4, r3, r5, r6, &runtime,
2023 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
2025 // Get the arguments boilerplate from the current native context.
2027 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
2028 __ LoadP(r7, FieldMemOperand(r7, GlobalObject::kNativeContextOffset));
2031 MemOperand(r7, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
2033 __ StoreP(r7, FieldMemOperand(r3, JSObject::kMapOffset), r0);
2034 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
2035 __ StoreP(r6, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
2036 __ StoreP(r6, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
2038 // Get the length (smi tagged) and set that as an in-object property too.
2039 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2040 __ LoadP(r4, MemOperand(sp, 0 * kPointerSize));
2043 FieldMemOperand(r3, JSObject::kHeaderSize +
2044 Heap::kArgumentsLengthIndex * kPointerSize),
2047 // If there are no actual arguments, we're done.
2049 __ cmpi(r4, Operand::Zero());
2052 // Get the parameters pointer from the stack.
2053 __ LoadP(r5, MemOperand(sp, 1 * kPointerSize));
2055 // Set up the elements pointer in the allocated arguments object and
2056 // initialize the header in the elements fixed array.
2057 __ addi(r7, r3, Operand(Heap::kStrictArgumentsObjectSize));
2058 __ StoreP(r7, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
2059 __ LoadRoot(r6, Heap::kFixedArrayMapRootIndex);
2060 __ StoreP(r6, FieldMemOperand(r7, FixedArray::kMapOffset), r0);
2061 __ StoreP(r4, FieldMemOperand(r7, FixedArray::kLengthOffset), r0);
2062 // Untag the length for the loop.
2065 // Copy the fixed array slots.
2067 // Set up r7 to point just prior to the first array slot.
2069 Operand(FixedArray::kHeaderSize - kHeapObjectTag - kPointerSize));
2072 // Pre-decrement r5 with kPointerSize on each iteration.
2073 // Pre-decrement in order to skip receiver.
2074 __ LoadPU(r6, MemOperand(r5, -kPointerSize));
2075 // Pre-increment r7 with kPointerSize on each iteration.
2076 __ StorePU(r6, MemOperand(r7, kPointerSize));
2079 // Return and remove the on-stack parameters.
2081 __ addi(sp, sp, Operand(3 * kPointerSize));
2084 // Do the runtime call to allocate the arguments object.
2086 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2090 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
2091 // Stack layout on entry.
2092 // sp[0] : language mode
2093 // sp[4] : index of rest parameter
2094 // sp[8] : number of parameters
2095 // sp[12] : receiver displacement
2098 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2099 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
2100 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
2103 // Patch the arguments.length and the parameters pointer.
2104 __ LoadP(r4, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
2105 __ StoreP(r4, MemOperand(sp, 2 * kPointerSize));
2106 __ SmiToPtrArrayOffset(r6, r4);
2108 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
2109 __ StoreP(r6, MemOperand(sp, 3 * kPointerSize));
2112 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
2116 void RegExpExecStub::Generate(MacroAssembler* masm) {
2117 // Just jump directly to runtime if native RegExp is not selected at compile
2118 // time or if regexp entry in generated code is turned off runtime switch or
2120 #ifdef V8_INTERPRETED_REGEXP
2121 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2122 #else // V8_INTERPRETED_REGEXP
2124 // Stack frame on entry.
2125 // sp[0]: last_match_info (expected JSArray)
2126 // sp[4]: previous index
2127 // sp[8]: subject string
2128 // sp[12]: JSRegExp object
2130 const int kLastMatchInfoOffset = 0 * kPointerSize;
2131 const int kPreviousIndexOffset = 1 * kPointerSize;
2132 const int kSubjectOffset = 2 * kPointerSize;
2133 const int kJSRegExpOffset = 3 * kPointerSize;
2135 Label runtime, br_over, encoding_type_UC16;
2137 // Allocation of registers for this function. These are in callee save
2138 // registers and will be preserved by the call to the native RegExp code, as
2139 // this code is called using the normal C calling convention. When calling
2140 // directly from generated code the native RegExp code will not do a GC and
2141 // therefore the content of these registers are safe to use after the call.
2142 Register subject = r14;
2143 Register regexp_data = r15;
2144 Register last_match_info_elements = r16;
2145 Register code = r17;
2147 // Ensure register assigments are consistent with callee save masks
2148 DCHECK(subject.bit() & kCalleeSaved);
2149 DCHECK(regexp_data.bit() & kCalleeSaved);
2150 DCHECK(last_match_info_elements.bit() & kCalleeSaved);
2151 DCHECK(code.bit() & kCalleeSaved);
2153 // Ensure that a RegExp stack is allocated.
2154 ExternalReference address_of_regexp_stack_memory_address =
2155 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2156 ExternalReference address_of_regexp_stack_memory_size =
2157 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2158 __ mov(r3, Operand(address_of_regexp_stack_memory_size));
2159 __ LoadP(r3, MemOperand(r3, 0));
2160 __ cmpi(r3, Operand::Zero());
2163 // Check that the first argument is a JSRegExp object.
2164 __ LoadP(r3, MemOperand(sp, kJSRegExpOffset));
2165 __ JumpIfSmi(r3, &runtime);
2166 __ CompareObjectType(r3, r4, r4, JS_REGEXP_TYPE);
2169 // Check that the RegExp has been compiled (data contains a fixed array).
2170 __ LoadP(regexp_data, FieldMemOperand(r3, JSRegExp::kDataOffset));
2171 if (FLAG_debug_code) {
2172 __ TestIfSmi(regexp_data, r0);
2173 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected, cr0);
2174 __ CompareObjectType(regexp_data, r3, r3, FIXED_ARRAY_TYPE);
2175 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2178 // regexp_data: RegExp data (FixedArray)
2179 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2180 __ LoadP(r3, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2181 // DCHECK(Smi::FromInt(JSRegExp::IRREGEXP) < (char *)0xffffu);
2182 __ CmpSmiLiteral(r3, Smi::FromInt(JSRegExp::IRREGEXP), r0);
2185 // regexp_data: RegExp data (FixedArray)
2186 // Check that the number of captures fit in the static offsets vector buffer.
2188 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2189 // Check (number_of_captures + 1) * 2 <= offsets vector size
2190 // Or number_of_captures * 2 <= offsets vector size - 2
2191 // SmiToShortArrayOffset accomplishes the multiplication by 2 and
2192 // SmiUntag (which is a nop for 32-bit).
2193 __ SmiToShortArrayOffset(r5, r5);
2194 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2195 __ cmpli(r5, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2198 // Reset offset for possibly sliced string.
2199 __ li(r11, Operand::Zero());
2200 __ LoadP(subject, MemOperand(sp, kSubjectOffset));
2201 __ JumpIfSmi(subject, &runtime);
2202 __ mr(r6, subject); // Make a copy of the original subject string.
2203 __ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
2204 __ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
2205 // subject: subject string
2206 // r6: subject string
2207 // r3: subject string instance type
2208 // regexp_data: RegExp data (FixedArray)
2209 // Handle subject string according to its encoding and representation:
2210 // (1) Sequential string? If yes, go to (5).
2211 // (2) Anything but sequential or cons? If yes, go to (6).
2212 // (3) Cons string. If the string is flat, replace subject with first string.
2213 // Otherwise bailout.
2214 // (4) Is subject external? If yes, go to (7).
2215 // (5) Sequential string. Load regexp code according to encoding.
2219 // Deferred code at the end of the stub:
2220 // (6) Not a long external string? If yes, go to (8).
2221 // (7) External string. Make it, offset-wise, look like a sequential string.
2223 // (8) Short external string or not a string? If yes, bail out to runtime.
2224 // (9) Sliced string. Replace subject with parent. Go to (4).
2226 Label seq_string /* 5 */, external_string /* 7 */, check_underlying /* 4 */,
2227 not_seq_nor_cons /* 6 */, not_long_external /* 8 */;
2229 // (1) Sequential string? If yes, go to (5).
2230 STATIC_ASSERT((kIsNotStringMask | kStringRepresentationMask |
2231 kShortExternalStringMask) == 0x93);
2232 __ andi(r4, r3, Operand(kIsNotStringMask | kStringRepresentationMask |
2233 kShortExternalStringMask));
2234 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2235 __ beq(&seq_string, cr0); // Go to (5).
2237 // (2) Anything but sequential or cons? If yes, go to (6).
2238 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2239 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2240 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2241 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2242 STATIC_ASSERT(kExternalStringTag < 0xffffu);
2243 __ cmpi(r4, Operand(kExternalStringTag));
2244 __ bge(¬_seq_nor_cons); // Go to (6).
2246 // (3) Cons string. Check that it's flat.
2247 // Replace subject with first string and reload instance type.
2248 __ LoadP(r3, FieldMemOperand(subject, ConsString::kSecondOffset));
2249 __ CompareRoot(r3, Heap::kempty_stringRootIndex);
2251 __ LoadP(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2253 // (4) Is subject external? If yes, go to (7).
2254 __ bind(&check_underlying);
2255 __ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
2256 __ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
2257 STATIC_ASSERT(kSeqStringTag == 0);
2258 STATIC_ASSERT(kStringRepresentationMask == 3);
2259 __ andi(r0, r3, Operand(kStringRepresentationMask));
2260 // The underlying external string is never a short external string.
2261 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2262 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2263 __ bne(&external_string, cr0); // Go to (7).
2265 // (5) Sequential string. Load regexp code according to encoding.
2266 __ bind(&seq_string);
2267 // subject: sequential subject string (or look-alike, external string)
2268 // r6: original subject string
2269 // Load previous index and check range before r6 is overwritten. We have to
2270 // use r6 instead of subject here because subject might have been only made
2271 // to look like a sequential string when it actually is an external string.
2272 __ LoadP(r4, MemOperand(sp, kPreviousIndexOffset));
2273 __ JumpIfNotSmi(r4, &runtime);
2274 __ LoadP(r6, FieldMemOperand(r6, String::kLengthOffset));
2279 STATIC_ASSERT(4 == kOneByteStringTag);
2280 STATIC_ASSERT(kTwoByteStringTag == 0);
2281 STATIC_ASSERT(kStringEncodingMask == 4);
2282 __ ExtractBitMask(r6, r3, kStringEncodingMask, SetRC);
2283 __ beq(&encoding_type_UC16, cr0);
2285 FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2287 __ bind(&encoding_type_UC16);
2288 __ LoadP(code, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2291 // (E) Carry on. String handling is done.
2292 // code: irregexp code
2293 // Check that the irregexp code has been generated for the actual string
2294 // encoding. If it has, the field contains a code object otherwise it contains
2295 // a smi (code flushing support).
2296 __ JumpIfSmi(code, &runtime);
2298 // r4: previous index
2299 // r6: encoding of subject string (1 if one_byte, 0 if two_byte);
2300 // code: Address of generated regexp code
2301 // subject: Subject string
2302 // regexp_data: RegExp data (FixedArray)
2303 // All checks done. Now push arguments for native regexp code.
2304 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r3, r5);
2306 // Isolates: note we add an additional parameter here (isolate pointer).
2307 const int kRegExpExecuteArguments = 10;
2308 const int kParameterRegisters = 8;
2309 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2311 // Stack pointer now points to cell where return address is to be written.
2312 // Arguments are before that on the stack or in registers.
2314 // Argument 10 (in stack parameter area): Pass current isolate address.
2315 __ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
2316 __ StoreP(r3, MemOperand(sp, (kStackFrameExtraParamSlot + 1) * kPointerSize));
2318 // Argument 9 is a dummy that reserves the space used for
2319 // the return address added by the ExitFrame in native calls.
2321 // Argument 8 (r10): Indicate that this is a direct call from JavaScript.
2322 __ li(r10, Operand(1));
2324 // Argument 7 (r9): Start (high end) of backtracking stack memory area.
2325 __ mov(r3, Operand(address_of_regexp_stack_memory_address));
2326 __ LoadP(r3, MemOperand(r3, 0));
2327 __ mov(r5, Operand(address_of_regexp_stack_memory_size));
2328 __ LoadP(r5, MemOperand(r5, 0));
2331 // Argument 6 (r8): Set the number of capture registers to zero to force
2332 // global egexps to behave as non-global. This does not affect non-global
2334 __ li(r8, Operand::Zero());
2336 // Argument 5 (r7): static offsets vector buffer.
2339 Operand(ExternalReference::address_of_static_offsets_vector(isolate())));
2341 // For arguments 4 (r6) and 3 (r5) get string length, calculate start of data
2342 // and calculate the shift of the index (0 for one-byte and 1 for two-byte).
2343 __ addi(r18, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2344 __ xori(r6, r6, Operand(1));
2345 // Load the length from the original subject string from the previous stack
2346 // frame. Therefore we have to use fp, which points exactly to two pointer
2347 // sizes below the previous sp. (Because creating a new stack frame pushes
2348 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2349 __ LoadP(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2350 // If slice offset is not 0, load the length from the original sliced string.
2351 // Argument 4, r6: End of string data
2352 // Argument 3, r5: Start of string data
2353 // Prepare start and end index of the input.
2354 __ ShiftLeft_(r11, r11, r6);
2355 __ add(r11, r18, r11);
2356 __ ShiftLeft_(r5, r4, r6);
2357 __ add(r5, r11, r5);
2359 __ LoadP(r18, FieldMemOperand(subject, String::kLengthOffset));
2361 __ ShiftLeft_(r6, r18, r6);
2362 __ add(r6, r11, r6);
2364 // Argument 2 (r4): Previous index.
2367 // Argument 1 (r3): Subject string.
2370 // Locate the code entry and call it.
2371 __ addi(code, code, Operand(Code::kHeaderSize - kHeapObjectTag));
2374 #if ABI_USES_FUNCTION_DESCRIPTORS && defined(USE_SIMULATOR)
2375 // Even Simulated AIX/PPC64 Linux uses a function descriptor for the
2376 // RegExp routine. Extract the instruction address here since
2377 // DirectCEntryStub::GenerateCall will not do it for calls out to
2378 // what it thinks is C code compiled for the simulator/host
2380 __ LoadP(code, MemOperand(code, 0)); // Instruction address
2383 DirectCEntryStub stub(isolate());
2384 stub.GenerateCall(masm, code);
2386 __ LeaveExitFrame(false, no_reg, true);
2388 // r3: result (int32)
2389 // subject: subject string (callee saved)
2390 // regexp_data: RegExp data (callee saved)
2391 // last_match_info_elements: Last match info elements (callee saved)
2392 // Check the result.
2394 __ cmpwi(r3, Operand(1));
2395 // We expect exactly one result since we force the called regexp to behave
2399 __ cmpwi(r3, Operand(NativeRegExpMacroAssembler::FAILURE));
2401 __ cmpwi(r3, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2402 // If not exception it can only be retry. Handle that in the runtime system.
2404 // Result must now be exception. If there is no pending exception already a
2405 // stack overflow (on the backtrack stack) was detected in RegExp code but
2406 // haven't created the exception yet. Handle that in the runtime system.
2407 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2408 __ mov(r4, Operand(isolate()->factory()->the_hole_value()));
2409 __ mov(r5, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2411 __ LoadP(r3, MemOperand(r5, 0));
2415 // For exception, throw the exception again.
2416 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2419 // For failure and exception return null.
2420 __ mov(r3, Operand(isolate()->factory()->null_value()));
2421 __ addi(sp, sp, Operand(4 * kPointerSize));
2424 // Process the result from the native regexp code.
2427 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2428 // Calculate number of capture registers (number_of_captures + 1) * 2.
2429 // SmiToShortArrayOffset accomplishes the multiplication by 2 and
2430 // SmiUntag (which is a nop for 32-bit).
2431 __ SmiToShortArrayOffset(r4, r4);
2432 __ addi(r4, r4, Operand(2));
2434 __ LoadP(r3, MemOperand(sp, kLastMatchInfoOffset));
2435 __ JumpIfSmi(r3, &runtime);
2436 __ CompareObjectType(r3, r5, r5, JS_ARRAY_TYPE);
2438 // Check that the JSArray is in fast case.
2439 __ LoadP(last_match_info_elements,
2440 FieldMemOperand(r3, JSArray::kElementsOffset));
2442 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2443 __ CompareRoot(r3, Heap::kFixedArrayMapRootIndex);
2445 // Check that the last match info has space for the capture registers and the
2446 // additional information.
2448 r3, FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2449 __ addi(r5, r4, Operand(RegExpImpl::kLastMatchOverhead));
2450 __ SmiUntag(r0, r3);
2454 // r4: number of capture registers
2455 // subject: subject string
2456 // Store the capture count.
2458 __ StoreP(r5, FieldMemOperand(last_match_info_elements,
2459 RegExpImpl::kLastCaptureCountOffset),
2461 // Store last subject and last input.
2462 __ StoreP(subject, FieldMemOperand(last_match_info_elements,
2463 RegExpImpl::kLastSubjectOffset),
2466 __ RecordWriteField(last_match_info_elements, RegExpImpl::kLastSubjectOffset,
2467 subject, r10, kLRHasNotBeenSaved, kDontSaveFPRegs);
2469 __ StoreP(subject, FieldMemOperand(last_match_info_elements,
2470 RegExpImpl::kLastInputOffset),
2472 __ RecordWriteField(last_match_info_elements, RegExpImpl::kLastInputOffset,
2473 subject, r10, kLRHasNotBeenSaved, kDontSaveFPRegs);
2475 // Get the static offsets vector filled by the native regexp code.
2476 ExternalReference address_of_static_offsets_vector =
2477 ExternalReference::address_of_static_offsets_vector(isolate());
2478 __ mov(r5, Operand(address_of_static_offsets_vector));
2480 // r4: number of capture registers
2481 // r5: offsets vector
2483 // Capture register counter starts from number of capture registers and
2484 // counts down until wraping after zero.
2486 r3, last_match_info_elements,
2487 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag - kPointerSize));
2488 __ addi(r5, r5, Operand(-kIntSize)); // bias down for lwzu
2490 __ bind(&next_capture);
2491 // Read the value from the static offsets vector buffer.
2492 __ lwzu(r6, MemOperand(r5, kIntSize));
2493 // Store the smi value in the last match info.
2495 __ StorePU(r6, MemOperand(r3, kPointerSize));
2496 __ bdnz(&next_capture);
2498 // Return last match info.
2499 __ LoadP(r3, MemOperand(sp, kLastMatchInfoOffset));
2500 __ addi(sp, sp, Operand(4 * kPointerSize));
2503 // Do the runtime call to execute the regexp.
2505 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2507 // Deferred code for string handling.
2508 // (6) Not a long external string? If yes, go to (8).
2509 __ bind(¬_seq_nor_cons);
2510 // Compare flags are still set.
2511 __ bgt(¬_long_external); // Go to (8).
2513 // (7) External string. Make it, offset-wise, look like a sequential string.
2514 __ bind(&external_string);
2515 __ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
2516 __ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
2517 if (FLAG_debug_code) {
2518 // Assert that we do not have a cons or slice (indirect strings) here.
2519 // Sequential strings have already been ruled out.
2520 STATIC_ASSERT(kIsIndirectStringMask == 1);
2521 __ andi(r0, r3, Operand(kIsIndirectStringMask));
2522 __ Assert(eq, kExternalStringExpectedButNotFound, cr0);
2525 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2526 // Move the pointer so that offset-wise, it looks like a sequential string.
2527 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2528 __ subi(subject, subject,
2529 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2530 __ b(&seq_string); // Go to (5).
2532 // (8) Short external string or not a string? If yes, bail out to runtime.
2533 __ bind(¬_long_external);
2534 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag != 0);
2535 __ andi(r0, r4, Operand(kIsNotStringMask | kShortExternalStringMask));
2536 __ bne(&runtime, cr0);
2538 // (9) Sliced string. Replace subject with parent. Go to (4).
2539 // Load offset into r11 and replace subject string with parent.
2540 __ LoadP(r11, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2542 __ LoadP(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2543 __ b(&check_underlying); // Go to (4).
2544 #endif // V8_INTERPRETED_REGEXP
2548 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2550 // r3 : number of arguments to the construct function
2551 // r4 : the function to call
2552 // r5 : feedback vector
2553 // r6 : slot in feedback vector (Smi)
2554 // r7 : original constructor (for IsSuperConstructorCall)
2555 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2557 // Number-of-arguments register must be smi-tagged to call out.
2560 __ Push(r6, r5, r4, r3, r7);
2562 __ Push(r6, r5, r4, r3);
2568 __ Pop(r6, r5, r4, r3, r7);
2570 __ Pop(r6, r5, r4, r3);
2576 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2577 // Cache the called function in a feedback vector slot. Cache states
2578 // are uninitialized, monomorphic (indicated by a JSFunction), and
2580 // r3 : number of arguments to the construct function
2581 // r4 : the function to call
2582 // r5 : feedback vector
2583 // r6 : slot in feedback vector (Smi)
2584 // r7 : original constructor (for IsSuperConstructorCall)
2585 Label initialize, done, miss, megamorphic, not_array_function;
2587 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2588 masm->isolate()->heap()->megamorphic_symbol());
2589 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2590 masm->isolate()->heap()->uninitialized_symbol());
2592 // Load the cache state into r8.
2593 __ SmiToPtrArrayOffset(r8, r6);
2595 __ LoadP(r8, FieldMemOperand(r8, FixedArray::kHeaderSize));
2597 // A monomorphic cache hit or an already megamorphic state: invoke the
2598 // function without changing the state.
2599 // We don't know if r8 is a WeakCell or a Symbol, but it's harmless to read at
2600 // this position in a symbol (see static asserts in type-feedback-vector.h).
2601 Label check_allocation_site;
2602 Register feedback_map = r9;
2603 Register weak_value = r10;
2604 __ LoadP(weak_value, FieldMemOperand(r8, WeakCell::kValueOffset));
2605 __ cmp(r4, weak_value);
2607 __ CompareRoot(r8, Heap::kmegamorphic_symbolRootIndex);
2609 __ LoadP(feedback_map, FieldMemOperand(r8, HeapObject::kMapOffset));
2610 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2611 __ bne(FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2613 // If the weak cell is cleared, we have a new chance to become monomorphic.
2614 __ JumpIfSmi(weak_value, &initialize);
2617 if (!FLAG_pretenuring_call_new) {
2618 __ bind(&check_allocation_site);
2619 // If we came here, we need to see if we are the array function.
2620 // If we didn't have a matching function, and we didn't find the megamorph
2621 // sentinel, then we have in the slot either some other function or an
2623 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2626 // Make sure the function is the Array() function
2627 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r8);
2629 __ bne(&megamorphic);
2635 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2637 __ CompareRoot(r8, Heap::kuninitialized_symbolRootIndex);
2638 __ beq(&initialize);
2639 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2640 // write-barrier is needed.
2641 __ bind(&megamorphic);
2642 __ SmiToPtrArrayOffset(r8, r6);
2644 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2645 __ StoreP(ip, FieldMemOperand(r8, FixedArray::kHeaderSize), r0);
2648 // An uninitialized cache is patched with the function
2649 __ bind(&initialize);
2651 if (!FLAG_pretenuring_call_new) {
2652 // Make sure the function is the Array() function.
2653 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r8);
2655 __ bne(¬_array_function);
2657 // The target function is the Array constructor,
2658 // Create an AllocationSite if we don't already have it, store it in the
2660 CreateAllocationSiteStub create_stub(masm->isolate());
2661 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2664 __ bind(¬_array_function);
2667 CreateWeakCellStub create_stub(masm->isolate());
2668 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2673 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2674 // Do not transform the receiver for strict mode functions and natives.
2675 __ LoadP(r6, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
2676 __ lwz(r7, FieldMemOperand(r6, SharedFunctionInfo::kCompilerHintsOffset));
2678 #if V8_TARGET_ARCH_PPC64
2679 SharedFunctionInfo::kStrictModeFunction,
2681 SharedFunctionInfo::kStrictModeFunction + kSmiTagSize,
2686 // Do not transform the receiver for native.
2688 #if V8_TARGET_ARCH_PPC64
2689 SharedFunctionInfo::kNative,
2691 SharedFunctionInfo::kNative + kSmiTagSize,
2698 static void EmitSlowCase(MacroAssembler* masm, int argc, Label* non_function) {
2699 // Check for function proxy.
2700 STATIC_ASSERT(JS_FUNCTION_PROXY_TYPE < 0xffffu);
2701 __ cmpi(r7, Operand(JS_FUNCTION_PROXY_TYPE));
2702 __ bne(non_function);
2703 __ push(r4); // put proxy as additional argument
2704 __ li(r3, Operand(argc + 1));
2705 __ li(r5, Operand::Zero());
2706 __ GetBuiltinFunction(r4, Builtins::CALL_FUNCTION_PROXY);
2708 Handle<Code> adaptor =
2709 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2710 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2713 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2714 // of the original receiver from the call site).
2715 __ bind(non_function);
2716 __ StoreP(r4, MemOperand(sp, argc * kPointerSize), r0);
2717 __ li(r3, Operand(argc)); // Set up the number of arguments.
2718 __ li(r5, Operand::Zero());
2719 __ GetBuiltinFunction(r4, Builtins::CALL_NON_FUNCTION);
2720 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2721 RelocInfo::CODE_TARGET);
2725 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2726 // Wrap the receiver and patch it back onto the stack.
2728 FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2730 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2733 __ StoreP(r3, MemOperand(sp, argc * kPointerSize), r0);
2738 static void CallFunctionNoFeedback(MacroAssembler* masm, int argc,
2739 bool needs_checks, bool call_as_method) {
2740 // r4 : the function to call
2741 Label slow, non_function, wrap, cont;
2744 // Check that the function is really a JavaScript function.
2745 // r4: pushed function (to be verified)
2746 __ JumpIfSmi(r4, &non_function);
2748 // Goto slow case if we do not have a function.
2749 __ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
2753 // Fast-case: Invoke the function now.
2754 // r4: pushed function
2755 ParameterCount actual(argc);
2757 if (call_as_method) {
2759 EmitContinueIfStrictOrNative(masm, &cont);
2762 // Compute the receiver in sloppy mode.
2763 __ LoadP(r6, MemOperand(sp, argc * kPointerSize), r0);
2766 __ JumpIfSmi(r6, &wrap);
2767 __ CompareObjectType(r6, r7, r7, FIRST_SPEC_OBJECT_TYPE);
2776 __ InvokeFunction(r4, actual, JUMP_FUNCTION, NullCallWrapper());
2779 // Slow-case: Non-function called.
2781 EmitSlowCase(masm, argc, &non_function);
2784 if (call_as_method) {
2786 EmitWrapCase(masm, argc, &cont);
2791 void CallFunctionStub::Generate(MacroAssembler* masm) {
2792 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2796 void CallConstructStub::Generate(MacroAssembler* masm) {
2797 // r3 : number of arguments
2798 // r4 : the function to call
2799 // r5 : feedback vector
2800 // r6 : slot in feedback vector (Smi, for RecordCallTarget)
2801 // r7 : original constructor (for IsSuperConstructorCall)
2802 Label slow, non_function_call;
2804 // Check that the function is not a smi.
2805 __ JumpIfSmi(r4, &non_function_call);
2806 // Check that the function is a JSFunction.
2807 __ CompareObjectType(r4, r8, r8, JS_FUNCTION_TYPE);
2810 if (RecordCallTarget()) {
2811 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2813 __ SmiToPtrArrayOffset(r8, r6);
2815 if (FLAG_pretenuring_call_new) {
2816 // Put the AllocationSite from the feedback vector into r5.
2817 // By adding kPointerSize we encode that we know the AllocationSite
2818 // entry is at the feedback vector slot given by r6 + 1.
2819 __ LoadP(r5, FieldMemOperand(r8, FixedArray::kHeaderSize + kPointerSize));
2821 // Put the AllocationSite from the feedback vector into r5, or undefined.
2822 __ LoadP(r5, FieldMemOperand(r8, FixedArray::kHeaderSize));
2823 __ LoadP(r8, FieldMemOperand(r5, AllocationSite::kMapOffset));
2824 __ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
2825 if (CpuFeatures::IsSupported(ISELECT)) {
2826 __ LoadRoot(r8, Heap::kUndefinedValueRootIndex);
2827 __ isel(eq, r5, r5, r8);
2829 Label feedback_register_initialized;
2830 __ beq(&feedback_register_initialized);
2831 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
2832 __ bind(&feedback_register_initialized);
2836 __ AssertUndefinedOrAllocationSite(r5, r8);
2839 // Pass function as original constructor.
2840 if (IsSuperConstructorCall()) {
2846 // Jump to the function-specific construct stub.
2847 Register jmp_reg = r7;
2848 __ LoadP(jmp_reg, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
2850 FieldMemOperand(jmp_reg, SharedFunctionInfo::kConstructStubOffset));
2851 __ addi(ip, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2852 __ JumpToJSEntry(ip);
2854 // r3: number of arguments
2855 // r4: called object
2859 STATIC_ASSERT(JS_FUNCTION_PROXY_TYPE < 0xffffu);
2860 __ cmpi(r8, Operand(JS_FUNCTION_PROXY_TYPE));
2861 __ bne(&non_function_call);
2862 __ GetBuiltinFunction(r4, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2865 __ bind(&non_function_call);
2866 __ GetBuiltinFunction(r4, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2868 // Set expected number of arguments to zero (not changing r3).
2869 __ li(r5, Operand::Zero());
2870 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2871 RelocInfo::CODE_TARGET);
2875 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2876 __ LoadP(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2878 FieldMemOperand(vector, JSFunction::kSharedFunctionInfoOffset));
2880 FieldMemOperand(vector, SharedFunctionInfo::kFeedbackVectorOffset));
2884 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2889 int argc = arg_count();
2890 ParameterCount actual(argc);
2892 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
2896 __ mov(r3, Operand(arg_count()));
2897 __ SmiToPtrArrayOffset(r9, r6);
2899 __ LoadP(r7, FieldMemOperand(r9, FixedArray::kHeaderSize));
2901 // Verify that r7 contains an AllocationSite
2902 __ LoadP(r8, FieldMemOperand(r7, HeapObject::kMapOffset));
2903 __ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
2906 // Increment the call count for monomorphic function calls.
2907 const int count_offset = FixedArray::kHeaderSize + kPointerSize;
2908 __ LoadP(r6, FieldMemOperand(r9, count_offset));
2909 __ AddSmiLiteral(r6, r6, Smi::FromInt(CallICNexus::kCallCountIncrement), r0);
2910 __ StoreP(r6, FieldMemOperand(r9, count_offset), r0);
2914 ArrayConstructorStub stub(masm->isolate(), arg_count());
2915 __ TailCallStub(&stub);
2920 // The slow case, we need this no matter what to complete a call after a miss.
2921 CallFunctionNoFeedback(masm, arg_count(), true, CallAsMethod());
2924 __ stop("Unexpected code address");
2928 void CallICStub::Generate(MacroAssembler* masm) {
2930 // r6 - slot id (Smi)
2932 const int with_types_offset =
2933 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2934 const int generic_offset =
2935 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2936 Label extra_checks_or_miss, slow_start;
2937 Label slow, non_function, wrap, cont;
2938 Label have_js_function;
2939 int argc = arg_count();
2940 ParameterCount actual(argc);
2942 // The checks. First, does r4 match the recorded monomorphic target?
2943 __ SmiToPtrArrayOffset(r9, r6);
2945 __ LoadP(r7, FieldMemOperand(r9, FixedArray::kHeaderSize));
2947 // We don't know that we have a weak cell. We might have a private symbol
2948 // or an AllocationSite, but the memory is safe to examine.
2949 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2951 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2952 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2953 // computed, meaning that it can't appear to be a pointer. If the low bit is
2954 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2956 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2957 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2958 WeakCell::kValueOffset &&
2959 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2961 __ LoadP(r8, FieldMemOperand(r7, WeakCell::kValueOffset));
2963 __ bne(&extra_checks_or_miss);
2965 // The compare above could have been a SMI/SMI comparison. Guard against this
2966 // convincing us that we have a monomorphic JSFunction.
2967 __ JumpIfSmi(r4, &extra_checks_or_miss);
2969 // Increment the call count for monomorphic function calls.
2970 const int count_offset = FixedArray::kHeaderSize + kPointerSize;
2971 __ LoadP(r6, FieldMemOperand(r9, count_offset));
2972 __ AddSmiLiteral(r6, r6, Smi::FromInt(CallICNexus::kCallCountIncrement), r0);
2973 __ StoreP(r6, FieldMemOperand(r9, count_offset), r0);
2975 __ bind(&have_js_function);
2976 if (CallAsMethod()) {
2977 EmitContinueIfStrictOrNative(masm, &cont);
2978 // Compute the receiver in sloppy mode.
2979 __ LoadP(r6, MemOperand(sp, argc * kPointerSize), r0);
2981 __ JumpIfSmi(r6, &wrap);
2982 __ CompareObjectType(r6, r7, r7, FIRST_SPEC_OBJECT_TYPE);
2988 __ InvokeFunction(r4, actual, JUMP_FUNCTION, NullCallWrapper());
2991 EmitSlowCase(masm, argc, &non_function);
2993 if (CallAsMethod()) {
2995 EmitWrapCase(masm, argc, &cont);
2998 __ bind(&extra_checks_or_miss);
2999 Label uninitialized, miss;
3001 __ CompareRoot(r7, Heap::kmegamorphic_symbolRootIndex);
3002 __ beq(&slow_start);
3004 // The following cases attempt to handle MISS cases without going to the
3006 if (FLAG_trace_ic) {
3010 __ CompareRoot(r7, Heap::kuninitialized_symbolRootIndex);
3011 __ beq(&uninitialized);
3013 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3014 // to handle it here. More complex cases are dealt with in the runtime.
3015 __ AssertNotSmi(r7);
3016 __ CompareObjectType(r7, r8, r8, JS_FUNCTION_TYPE);
3018 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
3019 __ StoreP(ip, FieldMemOperand(r9, FixedArray::kHeaderSize), r0);
3020 // We have to update statistics for runtime profiling.
3021 __ LoadP(r7, FieldMemOperand(r5, with_types_offset));
3022 __ SubSmiLiteral(r7, r7, Smi::FromInt(1), r0);
3023 __ StoreP(r7, FieldMemOperand(r5, with_types_offset), r0);
3024 __ LoadP(r7, FieldMemOperand(r5, generic_offset));
3025 __ AddSmiLiteral(r7, r7, Smi::FromInt(1), r0);
3026 __ StoreP(r7, FieldMemOperand(r5, generic_offset), r0);
3029 __ bind(&uninitialized);
3031 // We are going monomorphic, provided we actually have a JSFunction.
3032 __ JumpIfSmi(r4, &miss);
3034 // Goto miss case if we do not have a function.
3035 __ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
3038 // Make sure the function is not the Array() function, which requires special
3039 // behavior on MISS.
3040 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
3045 __ LoadP(r7, FieldMemOperand(r5, with_types_offset));
3046 __ AddSmiLiteral(r7, r7, Smi::FromInt(1), r0);
3047 __ StoreP(r7, FieldMemOperand(r5, with_types_offset), r0);
3049 // Initialize the call counter.
3050 __ LoadSmiLiteral(r8, Smi::FromInt(CallICNexus::kCallCountIncrement));
3051 __ StoreP(r8, FieldMemOperand(r9, count_offset), r0);
3053 // Store the function. Use a stub since we need a frame for allocation.
3058 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3059 CreateWeakCellStub create_stub(masm->isolate());
3061 __ CallStub(&create_stub);
3065 __ b(&have_js_function);
3067 // We are here because tracing is on or we encountered a MISS case we can't
3073 __ bind(&slow_start);
3074 // Check that the function is really a JavaScript function.
3075 // r4: pushed function (to be verified)
3076 __ JumpIfSmi(r4, &non_function);
3078 // Goto slow case if we do not have a function.
3079 __ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
3081 __ b(&have_js_function);
3085 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3086 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3088 // Push the function and feedback info.
3089 __ Push(r4, r5, r6);
3092 Runtime::FunctionId id = GetICState() == DEFAULT
3093 ? Runtime::kCallIC_Miss
3094 : Runtime::kCallIC_Customization_Miss;
3095 __ CallRuntime(id, 3);
3097 // Move result to r4 and exit the internal frame.
3102 // StringCharCodeAtGenerator
3103 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3104 // If the receiver is a smi trigger the non-string case.
3105 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3106 __ JumpIfSmi(object_, receiver_not_string_);
3108 // Fetch the instance type of the receiver into result register.
3109 __ LoadP(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3110 __ lbz(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3111 // If the receiver is not a string trigger the non-string case.
3112 __ andi(r0, result_, Operand(kIsNotStringMask));
3113 __ bne(receiver_not_string_, cr0);
3116 // If the index is non-smi trigger the non-smi case.
3117 __ JumpIfNotSmi(index_, &index_not_smi_);
3118 __ bind(&got_smi_index_);
3120 // Check for index out of range.
3121 __ LoadP(ip, FieldMemOperand(object_, String::kLengthOffset));
3122 __ cmpl(ip, index_);
3123 __ ble(index_out_of_range_);
3125 __ SmiUntag(index_);
3127 StringCharLoadGenerator::Generate(masm, object_, index_, result_,
3135 void StringCharCodeAtGenerator::GenerateSlow(
3136 MacroAssembler* masm, EmbedMode embed_mode,
3137 const RuntimeCallHelper& call_helper) {
3138 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3140 // Index is not a smi.
3141 __ bind(&index_not_smi_);
3142 // If index is a heap number, try converting it to an integer.
3143 __ CheckMap(index_, result_, Heap::kHeapNumberMapRootIndex, index_not_number_,
3145 call_helper.BeforeCall(masm);
3146 if (embed_mode == PART_OF_IC_HANDLER) {
3147 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3148 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3150 // index_ is consumed by runtime conversion function.
3151 __ Push(object_, index_);
3153 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3154 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3156 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3157 // NumberToSmi discards numbers that are not exact integers.
3158 __ CallRuntime(Runtime::kNumberToSmi, 1);
3160 // Save the conversion result before the pop instructions below
3161 // have a chance to overwrite it.
3162 __ Move(index_, r3);
3163 if (embed_mode == PART_OF_IC_HANDLER) {
3164 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3165 LoadWithVectorDescriptor::SlotRegister(), object_);
3169 // Reload the instance type.
3170 __ LoadP(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3171 __ lbz(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3172 call_helper.AfterCall(masm);
3173 // If index is still not a smi, it must be out of range.
3174 __ JumpIfNotSmi(index_, index_out_of_range_);
3175 // Otherwise, return to the fast path.
3176 __ b(&got_smi_index_);
3178 // Call runtime. We get here when the receiver is a string and the
3179 // index is a number, but the code of getting the actual character
3180 // is too complex (e.g., when the string needs to be flattened).
3181 __ bind(&call_runtime_);
3182 call_helper.BeforeCall(masm);
3184 __ Push(object_, index_);
3185 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3186 __ Move(result_, r3);
3187 call_helper.AfterCall(masm);
3190 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3194 // -------------------------------------------------------------------------
3195 // StringCharFromCodeGenerator
3197 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3198 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3199 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3200 __ LoadSmiLiteral(r0, Smi::FromInt(~String::kMaxOneByteCharCodeU));
3201 __ ori(r0, r0, Operand(kSmiTagMask));
3202 __ and_(r0, code_, r0, SetRC);
3203 __ bne(&slow_case_, cr0);
3205 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3206 // At this point code register contains smi tagged one-byte char code.
3208 __ SmiToPtrArrayOffset(code_, code_);
3209 __ add(result_, result_, code_);
3211 __ LoadP(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3212 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
3213 __ beq(&slow_case_);
3218 void StringCharFromCodeGenerator::GenerateSlow(
3219 MacroAssembler* masm, const RuntimeCallHelper& call_helper) {
3220 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3222 __ bind(&slow_case_);
3223 call_helper.BeforeCall(masm);
3225 __ CallRuntime(Runtime::kCharFromCode, 1);
3226 __ Move(result_, r3);
3227 call_helper.AfterCall(masm);
3230 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3234 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3237 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, Register dest,
3238 Register src, Register count,
3240 String::Encoding encoding) {
3241 if (FLAG_debug_code) {
3242 // Check that destination is word aligned.
3243 __ andi(r0, dest, Operand(kPointerAlignmentMask));
3244 __ Check(eq, kDestinationOfCopyNotAligned, cr0);
3247 // Nothing to do for zero characters.
3249 if (encoding == String::TWO_BYTE_ENCODING) {
3250 // double the length
3251 __ add(count, count, count, LeaveOE, SetRC);
3254 __ cmpi(count, Operand::Zero());
3258 // Copy count bytes from src to dst.
3261 __ bind(&byte_loop);
3262 __ lbz(scratch, MemOperand(src));
3263 __ addi(src, src, Operand(1));
3264 __ stb(scratch, MemOperand(dest));
3265 __ addi(dest, dest, Operand(1));
3266 __ bdnz(&byte_loop);
3272 void SubStringStub::Generate(MacroAssembler* masm) {
3275 // Stack frame on entry.
3276 // lr: return address
3281 // This stub is called from the native-call %_SubString(...), so
3282 // nothing can be assumed about the arguments. It is tested that:
3283 // "string" is a sequential string,
3284 // both "from" and "to" are smis, and
3285 // 0 <= from <= to <= string.length.
3286 // If any of these assumptions fail, we call the runtime system.
3288 const int kToOffset = 0 * kPointerSize;
3289 const int kFromOffset = 1 * kPointerSize;
3290 const int kStringOffset = 2 * kPointerSize;
3292 __ LoadP(r5, MemOperand(sp, kToOffset));
3293 __ LoadP(r6, MemOperand(sp, kFromOffset));
3295 // If either to or from had the smi tag bit set, then fail to generic runtime
3296 __ JumpIfNotSmi(r5, &runtime);
3297 __ JumpIfNotSmi(r6, &runtime);
3299 __ SmiUntag(r6, SetRC);
3300 // Both r5 and r6 are untagged integers.
3302 // We want to bailout to runtime here if From is negative.
3303 __ blt(&runtime, cr0); // From < 0.
3306 __ bgt(&runtime); // Fail if from > to.
3309 // Make sure first argument is a string.
3310 __ LoadP(r3, MemOperand(sp, kStringOffset));
3311 __ JumpIfSmi(r3, &runtime);
3312 Condition is_string = masm->IsObjectStringType(r3, r4);
3313 __ b(NegateCondition(is_string), &runtime, cr0);
3316 __ cmpi(r5, Operand(1));
3317 __ b(eq, &single_char);
3319 // Short-cut for the case of trivial substring.
3321 // r3: original string
3322 // r5: result string length
3323 __ LoadP(r7, FieldMemOperand(r3, String::kLengthOffset));
3324 __ SmiUntag(r0, r7);
3326 // Return original string.
3328 // Longer than original string's length or negative: unsafe arguments.
3330 // Shorter than original string's length: an actual substring.
3332 // Deal with different string types: update the index if necessary
3333 // and put the underlying string into r8.
3334 // r3: original string
3335 // r4: instance type
3337 // r6: from index (untagged)
3338 Label underlying_unpacked, sliced_string, seq_or_external_string;
3339 // If the string is not indirect, it can only be sequential or external.
3340 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3341 STATIC_ASSERT(kIsIndirectStringMask != 0);
3342 __ andi(r0, r4, Operand(kIsIndirectStringMask));
3343 __ beq(&seq_or_external_string, cr0);
3345 __ andi(r0, r4, Operand(kSlicedNotConsMask));
3346 __ bne(&sliced_string, cr0);
3347 // Cons string. Check whether it is flat, then fetch first part.
3348 __ LoadP(r8, FieldMemOperand(r3, ConsString::kSecondOffset));
3349 __ CompareRoot(r8, Heap::kempty_stringRootIndex);
3351 __ LoadP(r8, FieldMemOperand(r3, ConsString::kFirstOffset));
3352 // Update instance type.
3353 __ LoadP(r4, FieldMemOperand(r8, HeapObject::kMapOffset));
3354 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
3355 __ b(&underlying_unpacked);
3357 __ bind(&sliced_string);
3358 // Sliced string. Fetch parent and correct start index by offset.
3359 __ LoadP(r8, FieldMemOperand(r3, SlicedString::kParentOffset));
3360 __ LoadP(r7, FieldMemOperand(r3, SlicedString::kOffsetOffset));
3361 __ SmiUntag(r4, r7);
3362 __ add(r6, r6, r4); // Add offset to index.
3363 // Update instance type.
3364 __ LoadP(r4, FieldMemOperand(r8, HeapObject::kMapOffset));
3365 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
3366 __ b(&underlying_unpacked);
3368 __ bind(&seq_or_external_string);
3369 // Sequential or external string. Just move string to the expected register.
3372 __ bind(&underlying_unpacked);
3374 if (FLAG_string_slices) {
3376 // r8: underlying subject string
3377 // r4: instance type of underlying subject string
3379 // r6: adjusted start index (untagged)
3380 __ cmpi(r5, Operand(SlicedString::kMinLength));
3381 // Short slice. Copy instead of slicing.
3382 __ blt(©_routine);
3383 // Allocate new sliced string. At this point we do not reload the instance
3384 // type including the string encoding because we simply rely on the info
3385 // provided by the original string. It does not matter if the original
3386 // string's encoding is wrong because we always have to recheck encoding of
3387 // the newly created string's parent anyways due to externalized strings.
3388 Label two_byte_slice, set_slice_header;
3389 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3390 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3391 __ andi(r0, r4, Operand(kStringEncodingMask));
3392 __ beq(&two_byte_slice, cr0);
3393 __ AllocateOneByteSlicedString(r3, r5, r9, r10, &runtime);
3394 __ b(&set_slice_header);
3395 __ bind(&two_byte_slice);
3396 __ AllocateTwoByteSlicedString(r3, r5, r9, r10, &runtime);
3397 __ bind(&set_slice_header);
3399 __ StoreP(r8, FieldMemOperand(r3, SlicedString::kParentOffset), r0);
3400 __ StoreP(r6, FieldMemOperand(r3, SlicedString::kOffsetOffset), r0);
3403 __ bind(©_routine);
3406 // r8: underlying subject string
3407 // r4: instance type of underlying subject string
3409 // r6: adjusted start index (untagged)
3410 Label two_byte_sequential, sequential_string, allocate_result;
3411 STATIC_ASSERT(kExternalStringTag != 0);
3412 STATIC_ASSERT(kSeqStringTag == 0);
3413 __ andi(r0, r4, Operand(kExternalStringTag));
3414 __ beq(&sequential_string, cr0);
3416 // Handle external string.
3417 // Rule out short external strings.
3418 STATIC_ASSERT(kShortExternalStringTag != 0);
3419 __ andi(r0, r4, Operand(kShortExternalStringTag));
3420 __ bne(&runtime, cr0);
3421 __ LoadP(r8, FieldMemOperand(r8, ExternalString::kResourceDataOffset));
3422 // r8 already points to the first character of underlying string.
3423 __ b(&allocate_result);
3425 __ bind(&sequential_string);
3426 // Locate first character of underlying subject string.
3427 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3428 __ addi(r8, r8, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3430 __ bind(&allocate_result);
3431 // Sequential acii string. Allocate the result.
3432 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3433 __ andi(r0, r4, Operand(kStringEncodingMask));
3434 __ beq(&two_byte_sequential, cr0);
3436 // Allocate and copy the resulting one-byte string.
3437 __ AllocateOneByteString(r3, r5, r7, r9, r10, &runtime);
3439 // Locate first character of substring to copy.
3441 // Locate first character of result.
3442 __ addi(r4, r3, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3444 // r3: result string
3445 // r4: first character of result string
3446 // r5: result string length
3447 // r8: first character of substring to copy
3448 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3449 StringHelper::GenerateCopyCharacters(masm, r4, r8, r5, r6,
3450 String::ONE_BYTE_ENCODING);
3453 // Allocate and copy the resulting two-byte string.
3454 __ bind(&two_byte_sequential);
3455 __ AllocateTwoByteString(r3, r5, r7, r9, r10, &runtime);
3457 // Locate first character of substring to copy.
3458 __ ShiftLeftImm(r4, r6, Operand(1));
3460 // Locate first character of result.
3461 __ addi(r4, r3, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3463 // r3: result string.
3464 // r4: first character of result.
3465 // r5: result length.
3466 // r8: first character of substring to copy.
3467 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3468 StringHelper::GenerateCopyCharacters(masm, r4, r8, r5, r6,
3469 String::TWO_BYTE_ENCODING);
3471 __ bind(&return_r3);
3472 Counters* counters = isolate()->counters();
3473 __ IncrementCounter(counters->sub_string_native(), 1, r6, r7);
3477 // Just jump to runtime to create the sub string.
3479 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3481 __ bind(&single_char);
3482 // r3: original string
3483 // r4: instance type
3485 // r6: from index (untagged)
3487 StringCharAtGenerator generator(r3, r6, r5, r3, &runtime, &runtime, &runtime,
3488 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3489 generator.GenerateFast(masm);
3492 generator.SkipSlow(masm, &runtime);
3496 void ToNumberStub::Generate(MacroAssembler* masm) {
3497 // The ToNumber stub takes one argument in r3.
3499 __ JumpIfNotSmi(r3, ¬_smi);
3503 Label not_heap_number;
3504 __ LoadP(r4, FieldMemOperand(r3, HeapObject::kMapOffset));
3505 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
3507 // r4: instance type.
3508 __ cmpi(r4, Operand(HEAP_NUMBER_TYPE));
3509 __ bne(¬_heap_number);
3511 __ bind(¬_heap_number);
3513 Label not_string, slow_string;
3514 __ cmpli(r4, Operand(FIRST_NONSTRING_TYPE));
3515 __ bge(¬_string);
3516 // Check if string has a cached array index.
3517 __ lwz(r5, FieldMemOperand(r3, String::kHashFieldOffset));
3518 __ And(r0, r5, Operand(String::kContainsCachedArrayIndexMask), SetRC);
3519 __ bne(&slow_string, cr0);
3520 __ IndexFromHash(r5, r3);
3522 __ bind(&slow_string);
3523 __ push(r3); // Push argument.
3524 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3525 __ bind(¬_string);
3528 __ cmpi(r4, Operand(ODDBALL_TYPE));
3529 __ bne(¬_oddball);
3530 __ LoadP(r3, FieldMemOperand(r3, Oddball::kToNumberOffset));
3532 __ bind(¬_oddball);
3534 __ push(r3); // Push argument.
3535 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3539 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
3543 Register scratch2) {
3544 Register length = scratch1;
3547 Label strings_not_equal, check_zero_length;
3548 __ LoadP(length, FieldMemOperand(left, String::kLengthOffset));
3549 __ LoadP(scratch2, FieldMemOperand(right, String::kLengthOffset));
3550 __ cmp(length, scratch2);
3551 __ beq(&check_zero_length);
3552 __ bind(&strings_not_equal);
3553 __ LoadSmiLiteral(r3, Smi::FromInt(NOT_EQUAL));
3556 // Check if the length is zero.
3557 Label compare_chars;
3558 __ bind(&check_zero_length);
3559 STATIC_ASSERT(kSmiTag == 0);
3560 __ cmpi(length, Operand::Zero());
3561 __ bne(&compare_chars);
3562 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3565 // Compare characters.
3566 __ bind(&compare_chars);
3567 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2,
3568 &strings_not_equal);
3570 // Characters are equal.
3571 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3576 void StringHelper::GenerateCompareFlatOneByteStrings(
3577 MacroAssembler* masm, Register left, Register right, Register scratch1,
3578 Register scratch2, Register scratch3) {
3579 Label result_not_equal, compare_lengths;
3580 // Find minimum length and length difference.
3581 __ LoadP(scratch1, FieldMemOperand(left, String::kLengthOffset));
3582 __ LoadP(scratch2, FieldMemOperand(right, String::kLengthOffset));
3583 __ sub(scratch3, scratch1, scratch2, LeaveOE, SetRC);
3584 Register length_delta = scratch3;
3585 if (CpuFeatures::IsSupported(ISELECT)) {
3586 __ isel(gt, scratch1, scratch2, scratch1, cr0);
3590 __ mr(scratch1, scratch2);
3593 Register min_length = scratch1;
3594 STATIC_ASSERT(kSmiTag == 0);
3595 __ cmpi(min_length, Operand::Zero());
3596 __ beq(&compare_lengths);
3599 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3602 // Compare lengths - strings up to min-length are equal.
3603 __ bind(&compare_lengths);
3604 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3605 // Use length_delta as result if it's zero.
3606 __ mr(r3, length_delta);
3607 __ cmpi(r3, Operand::Zero());
3608 __ bind(&result_not_equal);
3609 // Conditionally update the result based either on length_delta or
3610 // the last comparion performed in the loop above.
3611 if (CpuFeatures::IsSupported(ISELECT)) {
3612 __ LoadSmiLiteral(r4, Smi::FromInt(GREATER));
3613 __ LoadSmiLiteral(r5, Smi::FromInt(LESS));
3614 __ isel(eq, r3, r0, r4);
3615 __ isel(lt, r3, r5, r3);
3618 Label less_equal, equal;
3619 __ ble(&less_equal);
3620 __ LoadSmiLiteral(r3, Smi::FromInt(GREATER));
3622 __ bind(&less_equal);
3624 __ LoadSmiLiteral(r3, Smi::FromInt(LESS));
3631 void StringHelper::GenerateOneByteCharsCompareLoop(
3632 MacroAssembler* masm, Register left, Register right, Register length,
3633 Register scratch1, Label* chars_not_equal) {
3634 // Change index to run from -length to -1 by adding length to string
3635 // start. This means that loop ends when index reaches zero, which
3636 // doesn't need an additional compare.
3637 __ SmiUntag(length);
3638 __ addi(scratch1, length,
3639 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3640 __ add(left, left, scratch1);
3641 __ add(right, right, scratch1);
3642 __ subfic(length, length, Operand::Zero());
3643 Register index = length; // index = -length;
3648 __ lbzx(scratch1, MemOperand(left, index));
3649 __ lbzx(r0, MemOperand(right, index));
3650 __ cmp(scratch1, r0);
3651 __ bne(chars_not_equal);
3652 __ addi(index, index, Operand(1));
3653 __ cmpi(index, Operand::Zero());
3658 void StringCompareStub::Generate(MacroAssembler* masm) {
3661 Counters* counters = isolate()->counters();
3663 // Stack frame on entry.
3664 // sp[0]: right string
3665 // sp[4]: left string
3666 __ LoadP(r3, MemOperand(sp)); // Load right in r3, left in r4.
3667 __ LoadP(r4, MemOperand(sp, kPointerSize));
3672 STATIC_ASSERT(EQUAL == 0);
3673 STATIC_ASSERT(kSmiTag == 0);
3674 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3675 __ IncrementCounter(counters->string_compare_native(), 1, r4, r5);
3676 __ addi(sp, sp, Operand(2 * kPointerSize));
3681 // Check that both objects are sequential one-byte strings.
3682 __ JumpIfNotBothSequentialOneByteStrings(r4, r3, r5, r6, &runtime);
3684 // Compare flat one-byte strings natively. Remove arguments from stack first.
3685 __ IncrementCounter(counters->string_compare_native(), 1, r5, r6);
3686 __ addi(sp, sp, Operand(2 * kPointerSize));
3687 StringHelper::GenerateCompareFlatOneByteStrings(masm, r4, r3, r5, r6, r7);
3689 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3690 // tagged as a small integer.
3692 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3696 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3697 // ----------- S t a t e -------------
3700 // -- lr : return address
3701 // -----------------------------------
3703 // Load r5 with the allocation site. We stick an undefined dummy value here
3704 // and replace it with the real allocation site later when we instantiate this
3705 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3706 __ Move(r5, handle(isolate()->heap()->undefined_value()));
3708 // Make sure that we actually patched the allocation site.
3709 if (FLAG_debug_code) {
3710 __ TestIfSmi(r5, r0);
3711 __ Assert(ne, kExpectedAllocationSite, cr0);
3713 __ LoadP(r5, FieldMemOperand(r5, HeapObject::kMapOffset));
3714 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3717 __ Assert(eq, kExpectedAllocationSite);
3720 // Tail call into the stub that handles binary operations with allocation
3722 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3723 __ TailCallStub(&stub);
3727 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3728 DCHECK(state() == CompareICState::SMI);
3731 __ JumpIfNotSmi(r5, &miss);
3733 if (GetCondition() == eq) {
3734 // For equality we do not care about the sign of the result.
3735 // __ sub(r3, r3, r4, SetCC);
3738 // Untag before subtracting to avoid handling overflow.
3750 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3751 DCHECK(state() == CompareICState::NUMBER);
3754 Label unordered, maybe_undefined1, maybe_undefined2;
3756 Label equal, less_than;
3758 if (left() == CompareICState::SMI) {
3759 __ JumpIfNotSmi(r4, &miss);
3761 if (right() == CompareICState::SMI) {
3762 __ JumpIfNotSmi(r3, &miss);
3765 // Inlining the double comparison and falling back to the general compare
3766 // stub if NaN is involved.
3767 // Load left and right operand.
3768 Label done, left, left_smi, right_smi;
3769 __ JumpIfSmi(r3, &right_smi);
3770 __ CheckMap(r3, r5, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3772 __ lfd(d1, FieldMemOperand(r3, HeapNumber::kValueOffset));
3774 __ bind(&right_smi);
3775 __ SmiToDouble(d1, r3);
3778 __ JumpIfSmi(r4, &left_smi);
3779 __ CheckMap(r4, r5, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3781 __ lfd(d0, FieldMemOperand(r4, HeapNumber::kValueOffset));
3784 __ SmiToDouble(d0, r4);
3791 // Don't base result on status bits when a NaN is involved.
3792 __ bunordered(&unordered);
3794 // Return a result of -1, 0, or 1, based on status bits.
3795 if (CpuFeatures::IsSupported(ISELECT)) {
3797 __ li(r4, Operand(GREATER));
3798 __ li(r5, Operand(LESS));
3799 __ isel(eq, r3, r0, r4);
3800 __ isel(lt, r3, r5, r3);
3805 // assume greater than
3806 __ li(r3, Operand(GREATER));
3809 __ li(r3, Operand(EQUAL));
3811 __ bind(&less_than);
3812 __ li(r3, Operand(LESS));
3816 __ bind(&unordered);
3817 __ bind(&generic_stub);
3818 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3819 CompareICState::GENERIC, CompareICState::GENERIC);
3820 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3822 __ bind(&maybe_undefined1);
3823 if (Token::IsOrderedRelationalCompareOp(op())) {
3824 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
3826 __ JumpIfSmi(r4, &unordered);
3827 __ CompareObjectType(r4, r5, r5, HEAP_NUMBER_TYPE);
3828 __ bne(&maybe_undefined2);
3832 __ bind(&maybe_undefined2);
3833 if (Token::IsOrderedRelationalCompareOp(op())) {
3834 __ CompareRoot(r4, Heap::kUndefinedValueRootIndex);
3843 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3844 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3845 Label miss, not_equal;
3847 // Registers containing left and right operands respectively.
3849 Register right = r3;
3853 // Check that both operands are heap objects.
3854 __ JumpIfEitherSmi(left, right, &miss);
3856 // Check that both operands are symbols.
3857 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3858 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3859 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3860 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3861 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3862 __ orx(tmp1, tmp1, tmp2);
3863 __ andi(r0, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3866 // Internalized strings are compared by identity.
3867 __ cmp(left, right);
3869 // Make sure r3 is non-zero. At this point input operands are
3870 // guaranteed to be non-zero.
3871 DCHECK(right.is(r3));
3872 STATIC_ASSERT(EQUAL == 0);
3873 STATIC_ASSERT(kSmiTag == 0);
3874 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3875 __ bind(¬_equal);
3883 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3884 DCHECK(state() == CompareICState::UNIQUE_NAME);
3885 DCHECK(GetCondition() == eq);
3888 // Registers containing left and right operands respectively.
3890 Register right = r3;
3894 // Check that both operands are heap objects.
3895 __ JumpIfEitherSmi(left, right, &miss);
3897 // Check that both operands are unique names. This leaves the instance
3898 // types loaded in tmp1 and tmp2.
3899 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3900 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3901 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3902 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3904 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3905 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3907 // Unique names are compared by identity.
3908 __ cmp(left, right);
3910 // Make sure r3 is non-zero. At this point input operands are
3911 // guaranteed to be non-zero.
3912 DCHECK(right.is(r3));
3913 STATIC_ASSERT(EQUAL == 0);
3914 STATIC_ASSERT(kSmiTag == 0);
3915 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3923 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3924 DCHECK(state() == CompareICState::STRING);
3925 Label miss, not_identical, is_symbol;
3927 bool equality = Token::IsEqualityOp(op());
3929 // Registers containing left and right operands respectively.
3931 Register right = r3;
3937 // Check that both operands are heap objects.
3938 __ JumpIfEitherSmi(left, right, &miss);
3940 // Check that both operands are strings. This leaves the instance
3941 // types loaded in tmp1 and tmp2.
3942 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3943 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3944 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3945 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3946 STATIC_ASSERT(kNotStringTag != 0);
3947 __ orx(tmp3, tmp1, tmp2);
3948 __ andi(r0, tmp3, Operand(kIsNotStringMask));
3951 // Fast check for identical strings.
3952 __ cmp(left, right);
3953 STATIC_ASSERT(EQUAL == 0);
3954 STATIC_ASSERT(kSmiTag == 0);
3955 __ bne(¬_identical);
3956 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3958 __ bind(¬_identical);
3960 // Handle not identical strings.
3962 // Check that both strings are internalized strings. If they are, we're done
3963 // because we already know they are not identical. We know they are both
3966 DCHECK(GetCondition() == eq);
3967 STATIC_ASSERT(kInternalizedTag == 0);
3968 __ orx(tmp3, tmp1, tmp2);
3969 __ andi(r0, tmp3, Operand(kIsNotInternalizedMask));
3970 // Make sure r3 is non-zero. At this point input operands are
3971 // guaranteed to be non-zero.
3972 DCHECK(right.is(r3));
3976 // Check that both strings are sequential one-byte.
3978 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3981 // Compare flat one-byte strings. Returns when done.
3983 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1,
3986 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3990 // Handle more complex cases in runtime.
3992 __ Push(left, right);
3994 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3996 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
4004 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
4005 DCHECK(state() == CompareICState::OBJECT);
4007 __ and_(r5, r4, r3);
4008 __ JumpIfSmi(r5, &miss);
4010 __ CompareObjectType(r3, r5, r5, JS_OBJECT_TYPE);
4012 __ CompareObjectType(r4, r5, r5, JS_OBJECT_TYPE);
4015 DCHECK(GetCondition() == eq);
4024 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
4026 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
4027 __ and_(r5, r4, r3);
4028 __ JumpIfSmi(r5, &miss);
4029 __ GetWeakValue(r7, cell);
4030 __ LoadP(r5, FieldMemOperand(r3, HeapObject::kMapOffset));
4031 __ LoadP(r6, FieldMemOperand(r4, HeapObject::kMapOffset));
4045 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
4047 // Call the runtime system in a fresh internal frame.
4048 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4051 __ LoadSmiLiteral(r0, Smi::FromInt(op()));
4053 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
4054 // Compute the entry point of the rewritten stub.
4055 __ addi(r5, r3, Operand(Code::kHeaderSize - kHeapObjectTag));
4056 // Restore registers.
4060 __ JumpToJSEntry(r5);
4064 // This stub is paired with DirectCEntryStub::GenerateCall
4065 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4066 // Place the return address on the stack, making the call
4067 // GC safe. The RegExp backend also relies on this.
4069 __ StoreP(r0, MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize));
4070 __ Call(ip); // Call the C++ function.
4071 __ LoadP(r0, MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize));
4077 void DirectCEntryStub::GenerateCall(MacroAssembler* masm, Register target) {
4078 #if ABI_USES_FUNCTION_DESCRIPTORS && !defined(USE_SIMULATOR)
4079 // Native AIX/PPC64 Linux use a function descriptor.
4080 __ LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(target, kPointerSize));
4081 __ LoadP(ip, MemOperand(target, 0)); // Instruction address
4083 // ip needs to be set for DirectCEentryStub::Generate, and also
4084 // for ABI_TOC_ADDRESSABILITY_VIA_IP.
4085 __ Move(ip, target);
4088 intptr_t code = reinterpret_cast<intptr_t>(GetCode().location());
4089 __ mov(r0, Operand(code, RelocInfo::CODE_TARGET));
4090 __ Call(r0); // Call the stub.
4094 void NameDictionaryLookupStub::GenerateNegativeLookup(
4095 MacroAssembler* masm, Label* miss, Label* done, Register receiver,
4096 Register properties, Handle<Name> name, Register scratch0) {
4097 DCHECK(name->IsUniqueName());
4098 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4099 // not equal to the name and kProbes-th slot is not used (its name is the
4100 // undefined value), it guarantees the hash table doesn't contain the
4101 // property. It's true even if some slots represent deleted properties
4102 // (their names are the hole value).
4103 for (int i = 0; i < kInlinedProbes; i++) {
4104 // scratch0 points to properties hash.
4105 // Compute the masked index: (hash + i + i * i) & mask.
4106 Register index = scratch0;
4107 // Capacity is smi 2^n.
4108 __ LoadP(index, FieldMemOperand(properties, kCapacityOffset));
4109 __ subi(index, index, Operand(1));
4111 ip, Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i)));
4112 __ and_(index, index, ip);
4114 // Scale the index by multiplying by the entry size.
4115 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4116 __ ShiftLeftImm(ip, index, Operand(1));
4117 __ add(index, index, ip); // index *= 3.
4119 Register entity_name = scratch0;
4120 // Having undefined at this place means the name is not contained.
4121 Register tmp = properties;
4122 __ SmiToPtrArrayOffset(ip, index);
4123 __ add(tmp, properties, ip);
4124 __ LoadP(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4126 DCHECK(!tmp.is(entity_name));
4127 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
4128 __ cmp(entity_name, tmp);
4131 // Load the hole ready for use below:
4132 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4134 // Stop if found the property.
4135 __ Cmpi(entity_name, Operand(Handle<Name>(name)), r0);
4139 __ cmp(entity_name, tmp);
4142 // Check if the entry name is not a unique name.
4143 __ LoadP(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4144 __ lbz(entity_name, FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4145 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4148 // Restore the properties.
4149 __ LoadP(properties,
4150 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4153 const int spill_mask = (r0.bit() | r9.bit() | r8.bit() | r7.bit() | r6.bit() |
4154 r5.bit() | r4.bit() | r3.bit());
4157 __ MultiPush(spill_mask);
4159 __ LoadP(r3, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4160 __ mov(r4, Operand(Handle<Name>(name)));
4161 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4163 __ cmpi(r3, Operand::Zero());
4165 __ MultiPop(spill_mask); // MultiPop does not touch condition flags
4173 // Probe the name dictionary in the |elements| register. Jump to the
4174 // |done| label if a property with the given name is found. Jump to
4175 // the |miss| label otherwise.
4176 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4177 void NameDictionaryLookupStub::GeneratePositiveLookup(
4178 MacroAssembler* masm, Label* miss, Label* done, Register elements,
4179 Register name, Register scratch1, Register scratch2) {
4180 DCHECK(!elements.is(scratch1));
4181 DCHECK(!elements.is(scratch2));
4182 DCHECK(!name.is(scratch1));
4183 DCHECK(!name.is(scratch2));
4185 __ AssertName(name);
4187 // Compute the capacity mask.
4188 __ LoadP(scratch1, FieldMemOperand(elements, kCapacityOffset));
4189 __ SmiUntag(scratch1); // convert smi to int
4190 __ subi(scratch1, scratch1, Operand(1));
4192 // Generate an unrolled loop that performs a few probes before
4193 // giving up. Measurements done on Gmail indicate that 2 probes
4194 // cover ~93% of loads from dictionaries.
4195 for (int i = 0; i < kInlinedProbes; i++) {
4196 // Compute the masked index: (hash + i + i * i) & mask.
4197 __ lwz(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4199 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4200 // the hash in a separate instruction. The value hash + i + i * i is right
4201 // shifted in the following and instruction.
4202 DCHECK(NameDictionary::GetProbeOffset(i) <
4203 1 << (32 - Name::kHashFieldOffset));
4204 __ addi(scratch2, scratch2,
4205 Operand(NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4207 __ srwi(scratch2, scratch2, Operand(Name::kHashShift));
4208 __ and_(scratch2, scratch1, scratch2);
4210 // Scale the index by multiplying by the entry size.
4211 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4212 // scratch2 = scratch2 * 3.
4213 __ ShiftLeftImm(ip, scratch2, Operand(1));
4214 __ add(scratch2, scratch2, ip);
4216 // Check if the key is identical to the name.
4217 __ ShiftLeftImm(ip, scratch2, Operand(kPointerSizeLog2));
4218 __ add(scratch2, elements, ip);
4219 __ LoadP(ip, FieldMemOperand(scratch2, kElementsStartOffset));
4224 const int spill_mask = (r0.bit() | r9.bit() | r8.bit() | r7.bit() | r6.bit() |
4225 r5.bit() | r4.bit() | r3.bit()) &
4226 ~(scratch1.bit() | scratch2.bit());
4229 __ MultiPush(spill_mask);
4231 DCHECK(!elements.is(r4));
4233 __ mr(r3, elements);
4235 __ mr(r3, elements);
4238 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4240 __ cmpi(r3, Operand::Zero());
4241 __ mr(scratch2, r5);
4242 __ MultiPop(spill_mask);
4250 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4251 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4252 // we cannot call anything that could cause a GC from this stub.
4254 // result: NameDictionary to probe
4256 // dictionary: NameDictionary to probe.
4257 // index: will hold an index of entry if lookup is successful.
4258 // might alias with result_.
4260 // result_ is zero if lookup failed, non zero otherwise.
4262 Register result = r3;
4263 Register dictionary = r3;
4265 Register index = r5;
4268 Register undefined = r8;
4269 Register entry_key = r9;
4270 Register scratch = r9;
4272 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4274 __ LoadP(mask, FieldMemOperand(dictionary, kCapacityOffset));
4276 __ subi(mask, mask, Operand(1));
4278 __ lwz(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4280 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4282 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4283 // Compute the masked index: (hash + i + i * i) & mask.
4284 // Capacity is smi 2^n.
4286 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4287 // the hash in a separate instruction. The value hash + i + i * i is right
4288 // shifted in the following and instruction.
4289 DCHECK(NameDictionary::GetProbeOffset(i) <
4290 1 << (32 - Name::kHashFieldOffset));
4291 __ addi(index, hash,
4292 Operand(NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4296 __ srwi(r0, index, Operand(Name::kHashShift));
4297 __ and_(index, mask, r0);
4299 // Scale the index by multiplying by the entry size.
4300 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4301 __ ShiftLeftImm(scratch, index, Operand(1));
4302 __ add(index, index, scratch); // index *= 3.
4304 __ ShiftLeftImm(scratch, index, Operand(kPointerSizeLog2));
4305 __ add(index, dictionary, scratch);
4306 __ LoadP(entry_key, FieldMemOperand(index, kElementsStartOffset));
4308 // Having undefined at this place means the name is not contained.
4309 __ cmp(entry_key, undefined);
4310 __ beq(¬_in_dictionary);
4312 // Stop if found the property.
4313 __ cmp(entry_key, key);
4314 __ beq(&in_dictionary);
4316 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4317 // Check if the entry name is not a unique name.
4318 __ LoadP(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4319 __ lbz(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4320 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4324 __ bind(&maybe_in_dictionary);
4325 // If we are doing negative lookup then probing failure should be
4326 // treated as a lookup success. For positive lookup probing failure
4327 // should be treated as lookup failure.
4328 if (mode() == POSITIVE_LOOKUP) {
4329 __ li(result, Operand::Zero());
4333 __ bind(&in_dictionary);
4334 __ li(result, Operand(1));
4337 __ bind(¬_in_dictionary);
4338 __ li(result, Operand::Zero());
4343 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4345 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4347 // Hydrogen code stubs need stub2 at snapshot time.
4348 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4353 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4354 // the value has just been written into the object, now this stub makes sure
4355 // we keep the GC informed. The word in the object where the value has been
4356 // written is in the address register.
4357 void RecordWriteStub::Generate(MacroAssembler* masm) {
4358 Label skip_to_incremental_noncompacting;
4359 Label skip_to_incremental_compacting;
4361 // The first two branch instructions are generated with labels so as to
4362 // get the offset fixed up correctly by the bind(Label*) call. We patch
4363 // it back and forth between branch condition True and False
4364 // when we start and stop incremental heap marking.
4365 // See RecordWriteStub::Patch for details.
4367 // Clear the bit, branch on True for NOP action initially
4368 __ crclr(Assembler::encode_crbit(cr2, CR_LT));
4369 __ blt(&skip_to_incremental_noncompacting, cr2);
4370 __ blt(&skip_to_incremental_compacting, cr2);
4372 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4373 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4374 MacroAssembler::kReturnAtEnd);
4378 __ bind(&skip_to_incremental_noncompacting);
4379 GenerateIncremental(masm, INCREMENTAL);
4381 __ bind(&skip_to_incremental_compacting);
4382 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4384 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4385 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4386 // patching not required on PPC as the initial path is effectively NOP
4390 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4393 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4394 Label dont_need_remembered_set;
4396 __ LoadP(regs_.scratch0(), MemOperand(regs_.address(), 0));
4397 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4398 regs_.scratch0(), &dont_need_remembered_set);
4400 __ CheckPageFlag(regs_.object(), regs_.scratch0(),
4401 1 << MemoryChunk::SCAN_ON_SCAVENGE, ne,
4402 &dont_need_remembered_set);
4404 // First notify the incremental marker if necessary, then update the
4406 CheckNeedsToInformIncrementalMarker(
4407 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4408 InformIncrementalMarker(masm);
4409 regs_.Restore(masm);
4410 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4411 MacroAssembler::kReturnAtEnd);
4413 __ bind(&dont_need_remembered_set);
4416 CheckNeedsToInformIncrementalMarker(
4417 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4418 InformIncrementalMarker(masm);
4419 regs_.Restore(masm);
4424 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4425 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4426 int argument_count = 3;
4427 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4429 r3.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4430 DCHECK(!address.is(regs_.object()));
4431 DCHECK(!address.is(r3));
4432 __ mr(address, regs_.address());
4433 __ mr(r3, regs_.object());
4435 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
4437 AllowExternalCallThatCantCauseGC scope(masm);
4439 ExternalReference::incremental_marking_record_write_function(isolate()),
4441 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4445 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4446 MacroAssembler* masm, OnNoNeedToInformIncrementalMarker on_no_need,
4449 Label need_incremental;
4450 Label need_incremental_pop_scratch;
4452 DCHECK((~Page::kPageAlignmentMask & 0xffff) == 0);
4453 __ lis(r0, Operand((~Page::kPageAlignmentMask >> 16)));
4454 __ and_(regs_.scratch0(), regs_.object(), r0);
4457 MemOperand(regs_.scratch0(), MemoryChunk::kWriteBarrierCounterOffset));
4458 __ subi(regs_.scratch1(), regs_.scratch1(), Operand(1));
4461 MemOperand(regs_.scratch0(), MemoryChunk::kWriteBarrierCounterOffset));
4462 __ cmpi(regs_.scratch1(), Operand::Zero()); // PPC, we could do better here
4463 __ blt(&need_incremental);
4465 // Let's look at the color of the object: If it is not black we don't have
4466 // to inform the incremental marker.
4467 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4469 regs_.Restore(masm);
4470 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4471 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4472 MacroAssembler::kReturnAtEnd);
4479 // Get the value from the slot.
4480 __ LoadP(regs_.scratch0(), MemOperand(regs_.address(), 0));
4482 if (mode == INCREMENTAL_COMPACTION) {
4483 Label ensure_not_white;
4485 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4486 regs_.scratch1(), // Scratch.
4487 MemoryChunk::kEvacuationCandidateMask, eq,
4490 __ CheckPageFlag(regs_.object(),
4491 regs_.scratch1(), // Scratch.
4492 MemoryChunk::kSkipEvacuationSlotsRecordingMask, eq,
4495 __ bind(&ensure_not_white);
4498 // We need extra registers for this, so we push the object and the address
4499 // register temporarily.
4500 __ Push(regs_.object(), regs_.address());
4501 __ EnsureNotWhite(regs_.scratch0(), // The value.
4502 regs_.scratch1(), // Scratch.
4503 regs_.object(), // Scratch.
4504 regs_.address(), // Scratch.
4505 &need_incremental_pop_scratch);
4506 __ Pop(regs_.object(), regs_.address());
4508 regs_.Restore(masm);
4509 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4510 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4511 MacroAssembler::kReturnAtEnd);
4516 __ bind(&need_incremental_pop_scratch);
4517 __ Pop(regs_.object(), regs_.address());
4519 __ bind(&need_incremental);
4521 // Fall through when we need to inform the incremental marker.
4525 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4526 // ----------- S t a t e -------------
4527 // -- r3 : element value to store
4528 // -- r6 : element index as smi
4529 // -- sp[0] : array literal index in function as smi
4530 // -- sp[4] : array literal
4531 // clobbers r3, r5, r7
4532 // -----------------------------------
4535 Label double_elements;
4537 Label slow_elements;
4538 Label fast_elements;
4540 // Get array literal index, array literal and its map.
4541 __ LoadP(r7, MemOperand(sp, 0 * kPointerSize));
4542 __ LoadP(r4, MemOperand(sp, 1 * kPointerSize));
4543 __ LoadP(r5, FieldMemOperand(r4, JSObject::kMapOffset));
4545 __ CheckFastElements(r5, r8, &double_elements);
4546 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4547 __ JumpIfSmi(r3, &smi_element);
4548 __ CheckFastSmiElements(r5, r8, &fast_elements);
4550 // Store into the array literal requires a elements transition. Call into
4552 __ bind(&slow_elements);
4554 __ Push(r4, r6, r3);
4555 __ LoadP(r8, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4556 __ LoadP(r8, FieldMemOperand(r8, JSFunction::kLiteralsOffset));
4558 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4560 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4561 __ bind(&fast_elements);
4562 __ LoadP(r8, FieldMemOperand(r4, JSObject::kElementsOffset));
4563 __ SmiToPtrArrayOffset(r9, r6);
4565 #if V8_TARGET_ARCH_PPC64
4566 // add due to offset alignment requirements of StorePU
4567 __ addi(r9, r9, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4568 __ StoreP(r3, MemOperand(r9));
4570 __ StorePU(r3, MemOperand(r9, FixedArray::kHeaderSize - kHeapObjectTag));
4572 // Update the write barrier for the array store.
4573 __ RecordWrite(r8, r9, r3, kLRHasNotBeenSaved, kDontSaveFPRegs,
4574 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4577 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4578 // and value is Smi.
4579 __ bind(&smi_element);
4580 __ LoadP(r8, FieldMemOperand(r4, JSObject::kElementsOffset));
4581 __ SmiToPtrArrayOffset(r9, r6);
4583 __ StoreP(r3, FieldMemOperand(r9, FixedArray::kHeaderSize), r0);
4586 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4587 __ bind(&double_elements);
4588 __ LoadP(r8, FieldMemOperand(r4, JSObject::kElementsOffset));
4589 __ StoreNumberToDoubleElements(r3, r6, r8, r9, d0, &slow_elements);
4594 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4595 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4596 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4597 int parameter_count_offset =
4598 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4599 __ LoadP(r4, MemOperand(fp, parameter_count_offset));
4600 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4601 __ addi(r4, r4, Operand(1));
4603 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4604 __ slwi(r4, r4, Operand(kPointerSizeLog2));
4610 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4611 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4612 LoadICStub stub(isolate(), state());
4613 stub.GenerateForTrampoline(masm);
4617 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4618 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4619 KeyedLoadICStub stub(isolate(), state());
4620 stub.GenerateForTrampoline(masm);
4624 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4625 EmitLoadTypeFeedbackVector(masm, r5);
4626 CallICStub stub(isolate(), state());
4627 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4631 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4632 EmitLoadTypeFeedbackVector(masm, r5);
4633 CallIC_ArrayStub stub(isolate(), state());
4634 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4638 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4641 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4642 GenerateImpl(masm, true);
4646 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4647 Register key, Register vector, Register slot,
4648 Register feedback, Register receiver_map,
4649 Register scratch1, Register scratch2,
4650 bool is_polymorphic, Label* miss) {
4651 // feedback initially contains the feedback array
4652 Label next_loop, prepare_next;
4653 Label start_polymorphic;
4655 Register cached_map = scratch1;
4657 __ LoadP(cached_map,
4658 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4659 __ LoadP(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4660 __ cmp(receiver_map, cached_map);
4661 __ bne(&start_polymorphic);
4662 // found, now call handler.
4663 Register handler = feedback;
4665 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4666 __ addi(ip, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4670 Register length = scratch2;
4671 __ bind(&start_polymorphic);
4672 __ LoadP(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4673 if (!is_polymorphic) {
4674 // If the IC could be monomorphic we have to make sure we don't go past the
4675 // end of the feedback array.
4676 __ CmpSmiLiteral(length, Smi::FromInt(2), r0);
4680 Register too_far = length;
4681 Register pointer_reg = feedback;
4683 // +-----+------+------+-----+-----+ ... ----+
4684 // | map | len | wm0 | h0 | wm1 | hN |
4685 // +-----+------+------+-----+-----+ ... ----+
4689 // pointer_reg too_far
4690 // aka feedback scratch2
4691 // also need receiver_map
4692 // use cached_map (scratch1) to look in the weak map values.
4693 __ SmiToPtrArrayOffset(r0, length);
4694 __ add(too_far, feedback, r0);
4695 __ addi(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4696 __ addi(pointer_reg, feedback,
4697 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4699 __ bind(&next_loop);
4700 __ LoadP(cached_map, MemOperand(pointer_reg));
4701 __ LoadP(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4702 __ cmp(receiver_map, cached_map);
4703 __ bne(&prepare_next);
4704 __ LoadP(handler, MemOperand(pointer_reg, kPointerSize));
4705 __ addi(ip, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4708 __ bind(&prepare_next);
4709 __ addi(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4710 __ cmp(pointer_reg, too_far);
4713 // We exhausted our array of map handler pairs.
4718 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4719 Register receiver_map, Register feedback,
4720 Register vector, Register slot,
4721 Register scratch, Label* compare_map,
4722 Label* load_smi_map, Label* try_array) {
4723 __ JumpIfSmi(receiver, load_smi_map);
4724 __ LoadP(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4725 __ bind(compare_map);
4726 Register cached_map = scratch;
4727 // Move the weak map into the weak_cell register.
4728 __ LoadP(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4729 __ cmp(cached_map, receiver_map);
4731 Register handler = feedback;
4732 __ SmiToPtrArrayOffset(r0, slot);
4733 __ add(handler, vector, r0);
4735 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4736 __ addi(ip, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4741 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4742 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r4
4743 Register name = LoadWithVectorDescriptor::NameRegister(); // r5
4744 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r6
4745 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r3
4746 Register feedback = r7;
4747 Register receiver_map = r8;
4748 Register scratch1 = r9;
4750 __ SmiToPtrArrayOffset(r0, slot);
4751 __ add(feedback, vector, r0);
4752 __ LoadP(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4754 // Try to quickly handle the monomorphic case without knowing for sure
4755 // if we have a weak cell in feedback. We do know it's safe to look
4756 // at WeakCell::kValueOffset.
4757 Label try_array, load_smi_map, compare_map;
4758 Label not_array, miss;
4759 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4760 scratch1, &compare_map, &load_smi_map, &try_array);
4762 // Is it a fixed array?
4763 __ bind(&try_array);
4764 __ LoadP(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4765 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4767 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4768 scratch1, r10, true, &miss);
4770 __ bind(¬_array);
4771 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4773 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4774 Code::ComputeHandlerFlags(Code::LOAD_IC));
4775 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4776 false, receiver, name, feedback,
4777 receiver_map, scratch1, r10);
4780 LoadIC::GenerateMiss(masm);
4782 __ bind(&load_smi_map);
4783 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4788 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4789 GenerateImpl(masm, false);
4793 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4794 GenerateImpl(masm, true);
4798 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4799 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r4
4800 Register key = LoadWithVectorDescriptor::NameRegister(); // r5
4801 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r6
4802 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r3
4803 Register feedback = r7;
4804 Register receiver_map = r8;
4805 Register scratch1 = r9;
4807 __ SmiToPtrArrayOffset(r0, slot);
4808 __ add(feedback, vector, r0);
4809 __ LoadP(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4811 // Try to quickly handle the monomorphic case without knowing for sure
4812 // if we have a weak cell in feedback. We do know it's safe to look
4813 // at WeakCell::kValueOffset.
4814 Label try_array, load_smi_map, compare_map;
4815 Label not_array, miss;
4816 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4817 scratch1, &compare_map, &load_smi_map, &try_array);
4819 __ bind(&try_array);
4820 // Is it a fixed array?
4821 __ LoadP(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4822 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4825 // We have a polymorphic element handler.
4826 Label polymorphic, try_poly_name;
4827 __ bind(&polymorphic);
4828 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4829 scratch1, r10, true, &miss);
4831 __ bind(¬_array);
4833 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4834 __ bne(&try_poly_name);
4835 Handle<Code> megamorphic_stub =
4836 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4837 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4839 __ bind(&try_poly_name);
4840 // We might have a name in feedback, and a fixed array in the next slot.
4841 __ cmp(key, feedback);
4843 // If the name comparison succeeded, we know we have a fixed array with
4844 // at least one map/handler pair.
4845 __ SmiToPtrArrayOffset(r0, slot);
4846 __ add(feedback, vector, r0);
4848 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4849 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4850 scratch1, r10, false, &miss);
4853 KeyedLoadIC::GenerateMiss(masm);
4855 __ bind(&load_smi_map);
4856 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4861 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4862 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4863 VectorStoreICStub stub(isolate(), state());
4864 stub.GenerateForTrampoline(masm);
4868 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4869 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4870 VectorKeyedStoreICStub stub(isolate(), state());
4871 stub.GenerateForTrampoline(masm);
4875 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4876 GenerateImpl(masm, false);
4880 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4881 GenerateImpl(masm, true);
4885 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4888 // TODO(mvstanton): Implement.
4890 StoreIC::GenerateMiss(masm);
4894 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4895 GenerateImpl(masm, false);
4899 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4900 GenerateImpl(masm, true);
4904 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4907 // TODO(mvstanton): Implement.
4909 KeyedStoreIC::GenerateMiss(masm);
4913 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4914 if (masm->isolate()->function_entry_hook() != NULL) {
4915 PredictableCodeSizeScope predictable(masm,
4916 #if V8_TARGET_ARCH_PPC64
4917 14 * Assembler::kInstrSize);
4919 11 * Assembler::kInstrSize);
4921 ProfileEntryHookStub stub(masm->isolate());
4931 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4932 // The entry hook is a "push lr, ip" instruction, followed by a call.
4933 const int32_t kReturnAddressDistanceFromFunctionStart =
4934 Assembler::kCallTargetAddressOffset + 3 * Assembler::kInstrSize;
4936 // This should contain all kJSCallerSaved registers.
4937 const RegList kSavedRegs = kJSCallerSaved | // Caller saved registers.
4938 r15.bit(); // Saved stack pointer.
4940 // We also save lr, so the count here is one higher than the mask indicates.
4941 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4943 // Save all caller-save registers as this may be called from anywhere.
4945 __ MultiPush(kSavedRegs | ip.bit());
4947 // Compute the function's address for the first argument.
4948 __ subi(r3, ip, Operand(kReturnAddressDistanceFromFunctionStart));
4950 // The caller's return address is two slots above the saved temporaries.
4951 // Grab that for the second argument to the hook.
4952 __ addi(r4, sp, Operand((kNumSavedRegs + 1) * kPointerSize));
4954 // Align the stack if necessary.
4955 int frame_alignment = masm->ActivationFrameAlignment();
4956 if (frame_alignment > kPointerSize) {
4958 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4959 __ ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
4962 #if !defined(USE_SIMULATOR)
4963 uintptr_t entry_hook =
4964 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
4965 __ mov(ip, Operand(entry_hook));
4967 #if ABI_USES_FUNCTION_DESCRIPTORS
4968 // Function descriptor
4969 __ LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(ip, kPointerSize));
4970 __ LoadP(ip, MemOperand(ip, 0));
4971 #elif ABI_TOC_ADDRESSABILITY_VIA_IP
4972 // ip set above, so nothing to do.
4976 __ li(r0, Operand::Zero());
4977 __ StorePU(r0, MemOperand(sp, -kNumRequiredStackFrameSlots * kPointerSize));
4979 // Under the simulator we need to indirect the entry hook through a
4980 // trampoline function at a known address.
4981 // It additionally takes an isolate as a third parameter
4982 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
4984 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4985 __ mov(ip, Operand(ExternalReference(
4986 &dispatcher, ExternalReference::BUILTIN_CALL, isolate())));
4990 #if !defined(USE_SIMULATOR)
4991 __ addi(sp, sp, Operand(kNumRequiredStackFrameSlots * kPointerSize));
4994 // Restore the stack pointer if needed.
4995 if (frame_alignment > kPointerSize) {
4999 // Also pop lr to get Ret(0).
5000 __ MultiPop(kSavedRegs | ip.bit());
5007 static void CreateArrayDispatch(MacroAssembler* masm,
5008 AllocationSiteOverrideMode mode) {
5009 if (mode == DISABLE_ALLOCATION_SITES) {
5010 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5011 __ TailCallStub(&stub);
5012 } else if (mode == DONT_OVERRIDE) {
5014 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5015 for (int i = 0; i <= last_index; ++i) {
5016 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5017 __ Cmpi(r6, Operand(kind), r0);
5018 T stub(masm->isolate(), kind);
5019 __ TailCallStub(&stub, eq);
5022 // If we reached this point there is a problem.
5023 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5030 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5031 AllocationSiteOverrideMode mode) {
5032 // r5 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5033 // r6 - kind (if mode != DISABLE_ALLOCATION_SITES)
5034 // r3 - number of arguments
5035 // r4 - constructor?
5036 // sp[0] - last argument
5037 Label normal_sequence;
5038 if (mode == DONT_OVERRIDE) {
5039 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5040 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5041 STATIC_ASSERT(FAST_ELEMENTS == 2);
5042 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5043 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5044 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5046 // is the low bit set? If so, we are holey and that is good.
5047 __ andi(r0, r6, Operand(1));
5048 __ bne(&normal_sequence, cr0);
5051 // look at the first argument
5052 __ LoadP(r8, MemOperand(sp, 0));
5053 __ cmpi(r8, Operand::Zero());
5054 __ beq(&normal_sequence);
5056 if (mode == DISABLE_ALLOCATION_SITES) {
5057 ElementsKind initial = GetInitialFastElementsKind();
5058 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5060 ArraySingleArgumentConstructorStub stub_holey(
5061 masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES);
5062 __ TailCallStub(&stub_holey);
5064 __ bind(&normal_sequence);
5065 ArraySingleArgumentConstructorStub stub(masm->isolate(), initial,
5066 DISABLE_ALLOCATION_SITES);
5067 __ TailCallStub(&stub);
5068 } else if (mode == DONT_OVERRIDE) {
5069 // We are going to create a holey array, but our kind is non-holey.
5070 // Fix kind and retry (only if we have an allocation site in the slot).
5071 __ addi(r6, r6, Operand(1));
5073 if (FLAG_debug_code) {
5074 __ LoadP(r8, FieldMemOperand(r5, 0));
5075 __ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
5076 __ Assert(eq, kExpectedAllocationSite);
5079 // Save the resulting elements kind in type info. We can't just store r6
5080 // in the AllocationSite::transition_info field because elements kind is
5081 // restricted to a portion of the field...upper bits need to be left alone.
5082 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5083 __ LoadP(r7, FieldMemOperand(r5, AllocationSite::kTransitionInfoOffset));
5084 __ AddSmiLiteral(r7, r7, Smi::FromInt(kFastElementsKindPackedToHoley), r0);
5085 __ StoreP(r7, FieldMemOperand(r5, AllocationSite::kTransitionInfoOffset),
5088 __ bind(&normal_sequence);
5090 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5091 for (int i = 0; i <= last_index; ++i) {
5092 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5093 __ mov(r0, Operand(kind));
5095 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5096 __ TailCallStub(&stub, eq);
5099 // If we reached this point there is a problem.
5100 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5108 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5110 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5111 for (int i = 0; i <= to_index; ++i) {
5112 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5113 T stub(isolate, kind);
5115 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5116 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5123 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5124 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5126 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5128 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5133 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5135 ElementsKind kinds[2] = {FAST_ELEMENTS, FAST_HOLEY_ELEMENTS};
5136 for (int i = 0; i < 2; i++) {
5137 // For internal arrays we only need a few things
5138 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5140 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5142 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5148 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5149 MacroAssembler* masm, AllocationSiteOverrideMode mode) {
5150 if (argument_count() == ANY) {
5151 Label not_zero_case, not_one_case;
5152 __ cmpi(r3, Operand::Zero());
5153 __ bne(¬_zero_case);
5154 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5156 __ bind(¬_zero_case);
5157 __ cmpi(r3, Operand(1));
5158 __ bgt(¬_one_case);
5159 CreateArrayDispatchOneArgument(masm, mode);
5161 __ bind(¬_one_case);
5162 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5163 } else if (argument_count() == NONE) {
5164 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5165 } else if (argument_count() == ONE) {
5166 CreateArrayDispatchOneArgument(masm, mode);
5167 } else if (argument_count() == MORE_THAN_ONE) {
5168 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5175 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5176 // ----------- S t a t e -------------
5177 // -- r3 : argc (only if argument_count() == ANY)
5178 // -- r4 : constructor
5179 // -- r5 : AllocationSite or undefined
5180 // -- r6 : original constructor
5181 // -- sp[0] : return address
5182 // -- sp[4] : last argument
5183 // -----------------------------------
5185 if (FLAG_debug_code) {
5186 // The array construct code is only set for the global and natives
5187 // builtin Array functions which always have maps.
5189 // Initial map for the builtin Array function should be a map.
5190 __ LoadP(r7, FieldMemOperand(r4, JSFunction::kPrototypeOrInitialMapOffset));
5191 // Will both indicate a NULL and a Smi.
5192 __ TestIfSmi(r7, r0);
5193 __ Assert(ne, kUnexpectedInitialMapForArrayFunction, cr0);
5194 __ CompareObjectType(r7, r7, r8, MAP_TYPE);
5195 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5197 // We should either have undefined in r5 or a valid AllocationSite
5198 __ AssertUndefinedOrAllocationSite(r5, r7);
5203 __ bne(&subclassing);
5206 // Get the elements kind and case on that.
5207 __ CompareRoot(r5, Heap::kUndefinedValueRootIndex);
5210 __ LoadP(r6, FieldMemOperand(r5, AllocationSite::kTransitionInfoOffset));
5212 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5213 __ And(r6, r6, Operand(AllocationSite::ElementsKindBits::kMask));
5214 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5217 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5219 __ bind(&subclassing);
5224 switch (argument_count()) {
5227 __ addi(r3, r3, Operand(2));
5230 __ li(r3, Operand(2));
5233 __ li(r3, Operand(3));
5237 __ JumpToExternalReference(
5238 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5242 void InternalArrayConstructorStub::GenerateCase(MacroAssembler* masm,
5243 ElementsKind kind) {
5244 __ cmpli(r3, Operand(1));
5246 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5247 __ TailCallStub(&stub0, lt);
5249 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5250 __ TailCallStub(&stubN, gt);
5252 if (IsFastPackedElementsKind(kind)) {
5253 // We might need to create a holey array
5254 // look at the first argument
5255 __ LoadP(r6, MemOperand(sp, 0));
5256 __ cmpi(r6, Operand::Zero());
5258 InternalArraySingleArgumentConstructorStub stub1_holey(
5259 isolate(), GetHoleyElementsKind(kind));
5260 __ TailCallStub(&stub1_holey, ne);
5263 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5264 __ TailCallStub(&stub1);
5268 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5269 // ----------- S t a t e -------------
5271 // -- r4 : constructor
5272 // -- sp[0] : return address
5273 // -- sp[4] : last argument
5274 // -----------------------------------
5276 if (FLAG_debug_code) {
5277 // The array construct code is only set for the global and natives
5278 // builtin Array functions which always have maps.
5280 // Initial map for the builtin Array function should be a map.
5281 __ LoadP(r6, FieldMemOperand(r4, JSFunction::kPrototypeOrInitialMapOffset));
5282 // Will both indicate a NULL and a Smi.
5283 __ TestIfSmi(r6, r0);
5284 __ Assert(ne, kUnexpectedInitialMapForArrayFunction, cr0);
5285 __ CompareObjectType(r6, r6, r7, MAP_TYPE);
5286 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5289 // Figure out the right elements kind
5290 __ LoadP(r6, FieldMemOperand(r4, JSFunction::kPrototypeOrInitialMapOffset));
5291 // Load the map's "bit field 2" into |result|.
5292 __ lbz(r6, FieldMemOperand(r6, Map::kBitField2Offset));
5293 // Retrieve elements_kind from bit field 2.
5294 __ DecodeField<Map::ElementsKindBits>(r6);
5296 if (FLAG_debug_code) {
5298 __ cmpi(r6, Operand(FAST_ELEMENTS));
5300 __ cmpi(r6, Operand(FAST_HOLEY_ELEMENTS));
5301 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5305 Label fast_elements_case;
5306 __ cmpi(r6, Operand(FAST_ELEMENTS));
5307 __ beq(&fast_elements_case);
5308 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5310 __ bind(&fast_elements_case);
5311 GenerateCase(masm, FAST_ELEMENTS);
5315 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5316 Register context = cp;
5317 Register result = r3;
5320 // Go up the context chain to the script context.
5321 for (int i = 0; i < depth(); ++i) {
5322 __ LoadP(result, ContextOperand(context, Context::PREVIOUS_INDEX));
5326 // Load the PropertyCell value at the specified slot.
5327 __ ShiftLeftImm(r0, slot, Operand(kPointerSizeLog2));
5328 __ add(result, context, r0);
5329 __ LoadP(result, ContextOperand(result));
5330 __ LoadP(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5332 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5333 __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
5336 // Fallback to runtime.
5339 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5343 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5344 Register value = r3;
5348 Register cell_details = r6;
5349 Register cell_value = r7;
5350 Register cell_value_map = r8;
5351 Register scratch = r9;
5353 Register context = cp;
5354 Register context_temp = cell;
5356 Label fast_heapobject_case, fast_smi_case, slow_case;
5358 if (FLAG_debug_code) {
5359 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5360 __ Check(ne, kUnexpectedValue);
5363 // Go up the context chain to the script context.
5364 for (int i = 0; i < depth(); i++) {
5365 __ LoadP(context_temp, ContextOperand(context, Context::PREVIOUS_INDEX));
5366 context = context_temp;
5369 // Load the PropertyCell at the specified slot.
5370 __ ShiftLeftImm(r0, slot, Operand(kPointerSizeLog2));
5371 __ add(cell, context, r0);
5372 __ LoadP(cell, ContextOperand(cell));
5374 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5375 __ LoadP(cell_details, FieldMemOperand(cell, PropertyCell::kDetailsOffset));
5376 __ SmiUntag(cell_details);
5377 __ andi(cell_details, cell_details,
5378 Operand(PropertyDetails::PropertyCellTypeField::kMask |
5379 PropertyDetails::KindField::kMask |
5380 PropertyDetails::kAttributesReadOnlyMask));
5382 // Check if PropertyCell holds mutable data.
5383 Label not_mutable_data;
5384 __ cmpi(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5385 PropertyCellType::kMutable) |
5386 PropertyDetails::KindField::encode(kData)));
5387 __ bne(¬_mutable_data);
5388 __ JumpIfSmi(value, &fast_smi_case);
5390 __ bind(&fast_heapobject_case);
5391 __ StoreP(value, FieldMemOperand(cell, PropertyCell::kValueOffset), r0);
5392 // RecordWriteField clobbers the value register, so we copy it before the
5395 __ RecordWriteField(cell, PropertyCell::kValueOffset, r6, scratch,
5396 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5400 __ bind(¬_mutable_data);
5401 // Check if PropertyCell value matches the new value (relevant for Constant,
5402 // ConstantType and Undefined cells).
5403 Label not_same_value;
5404 __ LoadP(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5405 __ cmp(cell_value, value);
5406 __ bne(¬_same_value);
5408 // Make sure the PropertyCell is not marked READ_ONLY.
5409 __ andi(r0, cell_details, Operand(PropertyDetails::kAttributesReadOnlyMask));
5410 __ bne(&slow_case, cr0);
5412 if (FLAG_debug_code) {
5414 // This can only be true for Constant, ConstantType and Undefined cells,
5415 // because we never store the_hole via this stub.
5416 __ cmpi(cell_details,
5417 Operand(PropertyDetails::PropertyCellTypeField::encode(
5418 PropertyCellType::kConstant) |
5419 PropertyDetails::KindField::encode(kData)));
5421 __ cmpi(cell_details,
5422 Operand(PropertyDetails::PropertyCellTypeField::encode(
5423 PropertyCellType::kConstantType) |
5424 PropertyDetails::KindField::encode(kData)));
5426 __ cmpi(cell_details,
5427 Operand(PropertyDetails::PropertyCellTypeField::encode(
5428 PropertyCellType::kUndefined) |
5429 PropertyDetails::KindField::encode(kData)));
5430 __ Check(eq, kUnexpectedValue);
5434 __ bind(¬_same_value);
5436 // Check if PropertyCell contains data with constant type (and is not
5438 __ cmpi(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5439 PropertyCellType::kConstantType) |
5440 PropertyDetails::KindField::encode(kData)));
5443 // Now either both old and new values must be smis or both must be heap
5444 // objects with same map.
5445 Label value_is_heap_object;
5446 __ JumpIfNotSmi(value, &value_is_heap_object);
5447 __ JumpIfNotSmi(cell_value, &slow_case);
5448 // Old and new values are smis, no need for a write barrier here.
5449 __ bind(&fast_smi_case);
5450 __ StoreP(value, FieldMemOperand(cell, PropertyCell::kValueOffset), r0);
5453 __ bind(&value_is_heap_object);
5454 __ JumpIfSmi(cell_value, &slow_case);
5456 __ LoadP(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5457 __ LoadP(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5458 __ cmp(cell_value_map, scratch);
5459 __ beq(&fast_heapobject_case);
5461 // Fallback to runtime.
5462 __ bind(&slow_case);
5464 __ Push(slot, value);
5465 __ TailCallRuntime(is_strict(language_mode())
5466 ? Runtime::kStoreGlobalViaContext_Strict
5467 : Runtime::kStoreGlobalViaContext_Sloppy,
5472 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5473 return ref0.address() - ref1.address();
5477 // Calls an API function. Allocates HandleScope, extracts returned value
5478 // from handle and propagates exceptions. Restores context. stack_space
5479 // - space to be unwound on exit (includes the call JS arguments space and
5480 // the additional space allocated for the fast call).
5481 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5482 Register function_address,
5483 ExternalReference thunk_ref,
5485 MemOperand* stack_space_operand,
5486 MemOperand return_value_operand,
5487 MemOperand* context_restore_operand) {
5488 Isolate* isolate = masm->isolate();
5489 ExternalReference next_address =
5490 ExternalReference::handle_scope_next_address(isolate);
5491 const int kNextOffset = 0;
5492 const int kLimitOffset = AddressOffset(
5493 ExternalReference::handle_scope_limit_address(isolate), next_address);
5494 const int kLevelOffset = AddressOffset(
5495 ExternalReference::handle_scope_level_address(isolate), next_address);
5497 // Additional parameter is the address of the actual callback.
5498 DCHECK(function_address.is(r4) || function_address.is(r5));
5499 Register scratch = r6;
5501 __ mov(scratch, Operand(ExternalReference::is_profiling_address(isolate)));
5502 __ lbz(scratch, MemOperand(scratch, 0));
5503 __ cmpi(scratch, Operand::Zero());
5505 if (CpuFeatures::IsSupported(ISELECT)) {
5506 __ mov(scratch, Operand(thunk_ref));
5507 __ isel(eq, scratch, function_address, scratch);
5509 Label profiler_disabled;
5510 Label end_profiler_check;
5511 __ beq(&profiler_disabled);
5512 __ mov(scratch, Operand(thunk_ref));
5513 __ b(&end_profiler_check);
5514 __ bind(&profiler_disabled);
5515 __ mr(scratch, function_address);
5516 __ bind(&end_profiler_check);
5519 // Allocate HandleScope in callee-save registers.
5520 // r17 - next_address
5521 // r14 - next_address->kNextOffset
5522 // r15 - next_address->kLimitOffset
5523 // r16 - next_address->kLevelOffset
5524 __ mov(r17, Operand(next_address));
5525 __ LoadP(r14, MemOperand(r17, kNextOffset));
5526 __ LoadP(r15, MemOperand(r17, kLimitOffset));
5527 __ lwz(r16, MemOperand(r17, kLevelOffset));
5528 __ addi(r16, r16, Operand(1));
5529 __ stw(r16, MemOperand(r17, kLevelOffset));
5531 if (FLAG_log_timer_events) {
5532 FrameScope frame(masm, StackFrame::MANUAL);
5533 __ PushSafepointRegisters();
5534 __ PrepareCallCFunction(1, r3);
5535 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5536 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5538 __ PopSafepointRegisters();
5541 // Native call returns to the DirectCEntry stub which redirects to the
5542 // return address pushed on stack (could have moved after GC).
5543 // DirectCEntry stub itself is generated early and never moves.
5544 DirectCEntryStub stub(isolate);
5545 stub.GenerateCall(masm, scratch);
5547 if (FLAG_log_timer_events) {
5548 FrameScope frame(masm, StackFrame::MANUAL);
5549 __ PushSafepointRegisters();
5550 __ PrepareCallCFunction(1, r3);
5551 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5552 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5554 __ PopSafepointRegisters();
5557 Label promote_scheduled_exception;
5558 Label delete_allocated_handles;
5559 Label leave_exit_frame;
5560 Label return_value_loaded;
5562 // load value from ReturnValue
5563 __ LoadP(r3, return_value_operand);
5564 __ bind(&return_value_loaded);
5565 // No more valid handles (the result handle was the last one). Restore
5566 // previous handle scope.
5567 __ StoreP(r14, MemOperand(r17, kNextOffset));
5568 if (__ emit_debug_code()) {
5569 __ lwz(r4, MemOperand(r17, kLevelOffset));
5571 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5573 __ subi(r16, r16, Operand(1));
5574 __ stw(r16, MemOperand(r17, kLevelOffset));
5575 __ LoadP(r0, MemOperand(r17, kLimitOffset));
5577 __ bne(&delete_allocated_handles);
5579 // Leave the API exit frame.
5580 __ bind(&leave_exit_frame);
5581 bool restore_context = context_restore_operand != NULL;
5582 if (restore_context) {
5583 __ LoadP(cp, *context_restore_operand);
5585 // LeaveExitFrame expects unwind space to be in a register.
5586 if (stack_space_operand != NULL) {
5587 __ lwz(r14, *stack_space_operand);
5589 __ mov(r14, Operand(stack_space));
5591 __ LeaveExitFrame(false, r14, !restore_context, stack_space_operand != NULL);
5593 // Check if the function scheduled an exception.
5594 __ LoadRoot(r14, Heap::kTheHoleValueRootIndex);
5595 __ mov(r15, Operand(ExternalReference::scheduled_exception_address(isolate)));
5596 __ LoadP(r15, MemOperand(r15));
5598 __ bne(&promote_scheduled_exception);
5602 // Re-throw by promoting a scheduled exception.
5603 __ bind(&promote_scheduled_exception);
5604 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5606 // HandleScope limit has changed. Delete allocated extensions.
5607 __ bind(&delete_allocated_handles);
5608 __ StoreP(r15, MemOperand(r17, kLimitOffset));
5610 __ PrepareCallCFunction(1, r15);
5611 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5612 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5615 __ b(&leave_exit_frame);
5619 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5620 const ParameterCount& argc,
5621 bool return_first_arg,
5622 bool call_data_undefined) {
5623 // ----------- S t a t e -------------
5625 // -- r7 : call_data
5627 // -- r4 : api_function_address
5628 // -- r6 : number of arguments if argc is a register
5631 // -- sp[0] : last argument
5633 // -- sp[(argc - 1)* 4] : first argument
5634 // -- sp[argc * 4] : receiver
5635 // -----------------------------------
5637 Register callee = r3;
5638 Register call_data = r7;
5639 Register holder = r5;
5640 Register api_function_address = r4;
5641 Register context = cp;
5643 typedef FunctionCallbackArguments FCA;
5645 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5646 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5647 STATIC_ASSERT(FCA::kDataIndex == 4);
5648 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5649 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5650 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5651 STATIC_ASSERT(FCA::kHolderIndex == 0);
5652 STATIC_ASSERT(FCA::kArgsLength == 7);
5654 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5658 // load context from callee
5659 __ LoadP(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5667 Register scratch = call_data;
5668 if (!call_data_undefined) {
5669 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5673 // return value default
5676 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5681 // Prepare arguments.
5684 // Allocate the v8::Arguments structure in the arguments' space since
5685 // it's not controlled by GC.
5688 // Create 5 extra slots on stack:
5689 // [0] space for DirectCEntryStub's LR save
5690 // [1-4] FunctionCallbackInfo
5691 const int kApiStackSpace = 5;
5692 const int kFunctionCallbackInfoOffset =
5693 (kStackFrameExtraParamSlot + 1) * kPointerSize;
5695 FrameScope frame_scope(masm, StackFrame::MANUAL);
5696 __ EnterExitFrame(false, kApiStackSpace);
5698 DCHECK(!api_function_address.is(r3) && !scratch.is(r3));
5699 // r3 = FunctionCallbackInfo&
5700 // Arguments is after the return address.
5701 __ addi(r3, sp, Operand(kFunctionCallbackInfoOffset));
5702 // FunctionCallbackInfo::implicit_args_
5703 __ StoreP(scratch, MemOperand(r3, 0 * kPointerSize));
5704 if (argc.is_immediate()) {
5705 // FunctionCallbackInfo::values_
5706 __ addi(ip, scratch,
5707 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5708 __ StoreP(ip, MemOperand(r3, 1 * kPointerSize));
5709 // FunctionCallbackInfo::length_ = argc
5710 __ li(ip, Operand(argc.immediate()));
5711 __ stw(ip, MemOperand(r3, 2 * kPointerSize));
5712 // FunctionCallbackInfo::is_construct_call_ = 0
5713 __ li(ip, Operand::Zero());
5714 __ stw(ip, MemOperand(r3, 2 * kPointerSize + kIntSize));
5716 __ ShiftLeftImm(ip, argc.reg(), Operand(kPointerSizeLog2));
5717 __ addi(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5718 // FunctionCallbackInfo::values_
5719 __ add(r0, scratch, ip);
5720 __ StoreP(r0, MemOperand(r3, 1 * kPointerSize));
5721 // FunctionCallbackInfo::length_ = argc
5722 __ stw(argc.reg(), MemOperand(r3, 2 * kPointerSize));
5723 // FunctionCallbackInfo::is_construct_call_
5724 __ stw(ip, MemOperand(r3, 2 * kPointerSize + kIntSize));
5727 ExternalReference thunk_ref =
5728 ExternalReference::invoke_function_callback(masm->isolate());
5730 AllowExternalCallThatCantCauseGC scope(masm);
5731 MemOperand context_restore_operand(
5732 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5733 // Stores return the first js argument
5734 int return_value_offset = 0;
5735 if (return_first_arg) {
5736 return_value_offset = 2 + FCA::kArgsLength;
5738 return_value_offset = 2 + FCA::kReturnValueOffset;
5740 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5741 int stack_space = 0;
5742 MemOperand is_construct_call_operand =
5743 MemOperand(sp, kFunctionCallbackInfoOffset + 2 * kPointerSize + kIntSize);
5744 MemOperand* stack_space_operand = &is_construct_call_operand;
5745 if (argc.is_immediate()) {
5746 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5747 stack_space_operand = NULL;
5749 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5750 stack_space_operand, return_value_operand,
5751 &context_restore_operand);
5755 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5756 bool call_data_undefined = this->call_data_undefined();
5757 CallApiFunctionStubHelper(masm, ParameterCount(r6), false,
5758 call_data_undefined);
5762 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5763 bool is_store = this->is_store();
5764 int argc = this->argc();
5765 bool call_data_undefined = this->call_data_undefined();
5766 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5767 call_data_undefined);
5771 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5772 // ----------- S t a t e -------------
5774 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5776 // -- r5 : api_function_address
5777 // -----------------------------------
5779 Register api_function_address = ApiGetterDescriptor::function_address();
5780 DCHECK(api_function_address.is(r5));
5782 __ mr(r3, sp); // r0 = Handle<Name>
5783 __ addi(r4, r3, Operand(1 * kPointerSize)); // r4 = PCA
5785 // If ABI passes Handles (pointer-sized struct) in a register:
5787 // Create 2 extra slots on stack:
5788 // [0] space for DirectCEntryStub's LR save
5789 // [1] AccessorInfo&
5793 // Create 3 extra slots on stack:
5794 // [0] space for DirectCEntryStub's LR save
5795 // [1] copy of Handle (first arg)
5796 // [2] AccessorInfo&
5797 #if ABI_PASSES_HANDLES_IN_REGS
5798 const int kAccessorInfoSlot = kStackFrameExtraParamSlot + 1;
5799 const int kApiStackSpace = 2;
5801 const int kArg0Slot = kStackFrameExtraParamSlot + 1;
5802 const int kAccessorInfoSlot = kArg0Slot + 1;
5803 const int kApiStackSpace = 3;
5806 FrameScope frame_scope(masm, StackFrame::MANUAL);
5807 __ EnterExitFrame(false, kApiStackSpace);
5809 #if !ABI_PASSES_HANDLES_IN_REGS
5810 // pass 1st arg by reference
5811 __ StoreP(r3, MemOperand(sp, kArg0Slot * kPointerSize));
5812 __ addi(r3, sp, Operand(kArg0Slot * kPointerSize));
5815 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5816 // r4 (internal::Object** args_) as the data.
5817 __ StoreP(r4, MemOperand(sp, kAccessorInfoSlot * kPointerSize));
5818 // r4 = AccessorInfo&
5819 __ addi(r4, sp, Operand(kAccessorInfoSlot * kPointerSize));
5821 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5823 ExternalReference thunk_ref =
5824 ExternalReference::invoke_accessor_getter_callback(isolate());
5825 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5826 kStackUnwindSpace, NULL,
5827 MemOperand(fp, 6 * kPointerSize), NULL);
5832 } // namespace internal
5835 #endif // V8_TARGET_ARCH_PPC