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, PASS_ARGUMENTS);
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, PASS_ARGUMENTS);
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);
366 // All-zero means Infinity means equal.
370 __ li(r3, Operand(GREATER)); // NaN <= NaN should fail.
372 __ li(r3, Operand(LESS)); // NaN >= NaN should fail.
378 // No fall through here.
380 __ bind(¬_identical);
384 // See comment at call site.
385 static void EmitSmiNonsmiComparison(MacroAssembler* masm, Register lhs,
386 Register rhs, Label* lhs_not_nan,
387 Label* slow, bool strict) {
388 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
391 __ JumpIfSmi(rhs, &rhs_is_smi);
393 // Lhs is a Smi. Check whether the rhs is a heap number.
394 __ CompareObjectType(rhs, r6, r7, HEAP_NUMBER_TYPE);
396 // If rhs is not a number and lhs is a Smi then strict equality cannot
397 // succeed. Return non-equal
398 // If rhs is r3 then there is already a non zero value in it.
402 __ mov(r3, Operand(NOT_EQUAL));
407 // Smi compared non-strictly with a non-Smi non-heap-number. Call
412 // Lhs is a smi, rhs is a number.
413 // Convert lhs to a double in d7.
414 __ SmiToDouble(d7, lhs);
415 // Load the double from rhs, tagged HeapNumber r3, to d6.
416 __ lfd(d6, FieldMemOperand(rhs, HeapNumber::kValueOffset));
418 // We now have both loaded as doubles but we can skip the lhs nan check
422 __ bind(&rhs_is_smi);
423 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
424 __ CompareObjectType(lhs, r7, r7, HEAP_NUMBER_TYPE);
426 // If lhs is not a number and rhs is a smi then strict equality cannot
427 // succeed. Return non-equal.
428 // If lhs is r3 then there is already a non zero value in it.
432 __ mov(r3, Operand(NOT_EQUAL));
437 // Smi compared non-strictly with a non-smi non-heap-number. Call
442 // Rhs is a smi, lhs is a heap number.
443 // Load the double from lhs, tagged HeapNumber r4, to d7.
444 __ lfd(d7, FieldMemOperand(lhs, HeapNumber::kValueOffset));
445 // Convert rhs to a double in d6.
446 __ SmiToDouble(d6, rhs);
447 // Fall through to both_loaded_as_doubles.
451 // See comment at call site.
452 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register lhs,
454 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
456 // If either operand is a JS object or an oddball value, then they are
457 // not equal since their pointers are different.
458 // There is no test for undetectability in strict equality.
459 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
460 Label first_non_object;
461 // Get the type of the first operand into r5 and compare it with
462 // FIRST_SPEC_OBJECT_TYPE.
463 __ CompareObjectType(rhs, r5, r5, FIRST_SPEC_OBJECT_TYPE);
464 __ blt(&first_non_object);
466 // Return non-zero (r3 is not zero)
467 Label return_not_equal;
468 __ bind(&return_not_equal);
471 __ bind(&first_non_object);
472 // Check for oddballs: true, false, null, undefined.
473 __ cmpi(r5, Operand(ODDBALL_TYPE));
474 __ beq(&return_not_equal);
476 __ CompareObjectType(lhs, r6, r6, FIRST_SPEC_OBJECT_TYPE);
477 __ bge(&return_not_equal);
479 // Check for oddballs: true, false, null, undefined.
480 __ cmpi(r6, Operand(ODDBALL_TYPE));
481 __ beq(&return_not_equal);
483 // Now that we have the types we might as well check for
484 // internalized-internalized.
485 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
487 __ andi(r0, r5, Operand(kIsNotStringMask | kIsNotInternalizedMask));
488 __ beq(&return_not_equal, cr0);
492 // See comment at call site.
493 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, Register lhs,
495 Label* both_loaded_as_doubles,
496 Label* not_heap_numbers, Label* slow) {
497 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
499 __ CompareObjectType(rhs, r6, r5, HEAP_NUMBER_TYPE);
500 __ bne(not_heap_numbers);
501 __ LoadP(r5, FieldMemOperand(lhs, HeapObject::kMapOffset));
503 __ bne(slow); // First was a heap number, second wasn't. Go slow case.
505 // Both are heap numbers. Load them up then jump to the code we have
507 __ lfd(d6, FieldMemOperand(rhs, HeapNumber::kValueOffset));
508 __ lfd(d7, FieldMemOperand(lhs, HeapNumber::kValueOffset));
510 __ b(both_loaded_as_doubles);
514 // Fast negative check for internalized-to-internalized equality.
515 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
516 Register lhs, Register rhs,
517 Label* possible_strings,
518 Label* not_both_strings) {
519 DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
521 // r5 is object type of rhs.
523 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
524 __ andi(r0, r5, Operand(kIsNotStringMask));
525 __ bne(&object_test, cr0);
526 __ andi(r0, r5, Operand(kIsNotInternalizedMask));
527 __ bne(possible_strings, cr0);
528 __ CompareObjectType(lhs, r6, r6, FIRST_NONSTRING_TYPE);
529 __ bge(not_both_strings);
530 __ andi(r0, r6, Operand(kIsNotInternalizedMask));
531 __ bne(possible_strings, cr0);
533 // Both are internalized. We already checked they weren't the same pointer
534 // so they are not equal.
535 __ li(r3, Operand(NOT_EQUAL));
538 __ bind(&object_test);
539 __ cmpi(r5, Operand(FIRST_SPEC_OBJECT_TYPE));
540 __ blt(not_both_strings);
541 __ CompareObjectType(lhs, r5, r6, FIRST_SPEC_OBJECT_TYPE);
542 __ blt(not_both_strings);
543 // If both objects are undetectable, they are equal. Otherwise, they
544 // are not equal, since they are different objects and an object is not
545 // equal to undefined.
546 __ LoadP(r6, FieldMemOperand(rhs, HeapObject::kMapOffset));
547 __ lbz(r5, FieldMemOperand(r5, Map::kBitFieldOffset));
548 __ lbz(r6, FieldMemOperand(r6, Map::kBitFieldOffset));
550 __ andi(r3, r3, Operand(1 << Map::kIsUndetectable));
551 __ xori(r3, r3, Operand(1 << Map::kIsUndetectable));
556 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
558 CompareICState::State expected,
561 if (expected == CompareICState::SMI) {
562 __ JumpIfNotSmi(input, fail);
563 } else if (expected == CompareICState::NUMBER) {
564 __ JumpIfSmi(input, &ok);
565 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
568 // We could be strict about internalized/non-internalized here, but as long as
569 // hydrogen doesn't care, the stub doesn't have to care either.
574 // On entry r4 and r5 are the values to be compared.
575 // On exit r3 is 0, positive or negative to indicate the result of
577 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
580 Condition cc = GetCondition();
583 CompareICStub_CheckInputType(masm, lhs, r5, left(), &miss);
584 CompareICStub_CheckInputType(masm, rhs, r6, right(), &miss);
586 Label slow; // Call builtin.
587 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
589 Label not_two_smis, smi_done;
591 __ JumpIfNotSmi(r5, ¬_two_smis);
596 __ bind(¬_two_smis);
598 // NOTICE! This code is only reached after a smi-fast-case check, so
599 // it is certain that at least one operand isn't a smi.
601 // Handle the case where the objects are identical. Either returns the answer
602 // or goes to slow. Only falls through if the objects were not identical.
603 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
605 // If either is a Smi (we know that not both are), then they can only
606 // be strictly equal if the other is a HeapNumber.
607 STATIC_ASSERT(kSmiTag == 0);
608 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
609 __ and_(r5, lhs, rhs);
610 __ JumpIfNotSmi(r5, ¬_smis);
611 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
612 // 1) Return the answer.
614 // 3) Fall through to both_loaded_as_doubles.
615 // 4) Jump to lhs_not_nan.
616 // In cases 3 and 4 we have found out we were dealing with a number-number
617 // comparison. The double values of the numbers have been loaded
619 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
621 __ bind(&both_loaded_as_doubles);
622 // The arguments have been converted to doubles and stored in d6 and d7
623 __ bind(&lhs_not_nan);
627 Label nan, equal, less_than;
629 if (CpuFeatures::IsSupported(ISELECT)) {
631 __ li(r4, Operand(GREATER));
632 __ li(r5, Operand(LESS));
633 __ isel(eq, r3, r0, r4);
634 __ isel(lt, r3, r5, r3);
639 __ li(r3, Operand(GREATER));
642 __ li(r3, Operand(EQUAL));
645 __ li(r3, Operand(LESS));
650 // If one of the sides was a NaN then the v flag is set. Load r3 with
651 // whatever it takes to make the comparison fail, since comparisons with NaN
653 if (cc == lt || cc == le) {
654 __ li(r3, Operand(GREATER));
656 __ li(r3, Operand(LESS));
661 // At this point we know we are dealing with two different objects,
662 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
664 // This returns non-equal for some object types, or falls through if it
666 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
669 Label check_for_internalized_strings;
670 Label flat_string_check;
671 // Check for heap-number-heap-number comparison. Can jump to slow case,
672 // or load both doubles into r3, r4, r5, r6 and jump to the code that handles
673 // that case. If the inputs are not doubles then jumps to
674 // check_for_internalized_strings.
675 // In this case r5 will contain the type of rhs_. Never falls through.
676 EmitCheckForTwoHeapNumbers(masm, lhs, rhs, &both_loaded_as_doubles,
677 &check_for_internalized_strings,
680 __ bind(&check_for_internalized_strings);
681 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
682 // internalized strings.
683 if (cc == eq && !strict()) {
684 // Returns an answer for two internalized strings or two detectable objects.
685 // Otherwise jumps to string case or not both strings case.
686 // Assumes that r5 is the type of rhs_ on entry.
687 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, &flat_string_check,
691 // Check for both being sequential one-byte strings,
692 // and inline if that is the case.
693 __ bind(&flat_string_check);
695 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r5, r6, &slow);
697 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r5,
700 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r5, r6);
702 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r5, r6, r7);
704 // Never falls through to here.
709 // Figure out which native to call and setup the arguments.
710 Builtins::JavaScript native;
712 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
715 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
716 int ncr; // NaN compare result
717 if (cc == lt || cc == le) {
720 DCHECK(cc == gt || cc == ge); // remaining cases
723 __ LoadSmiLiteral(r3, Smi::FromInt(ncr));
727 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
728 // tagged as a small integer.
729 __ InvokeBuiltin(native, JUMP_FUNCTION);
736 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
737 // We don't allow a GC during a store buffer overflow so there is no need to
738 // store the registers in any particular way, but we do have to store and
741 __ MultiPush(kJSCallerSaved | r0.bit());
742 if (save_doubles()) {
743 __ SaveFPRegs(sp, 0, DoubleRegister::kNumVolatileRegisters);
745 const int argument_count = 1;
746 const int fp_argument_count = 0;
747 const Register scratch = r4;
749 AllowExternalCallThatCantCauseGC scope(masm);
750 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
751 __ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
752 __ CallCFunction(ExternalReference::store_buffer_overflow_function(isolate()),
754 if (save_doubles()) {
755 __ RestoreFPRegs(sp, 0, DoubleRegister::kNumVolatileRegisters);
757 __ MultiPop(kJSCallerSaved | r0.bit());
763 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
764 __ PushSafepointRegisters();
769 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
770 __ PopSafepointRegisters();
775 void MathPowStub::Generate(MacroAssembler* masm) {
776 const Register base = r4;
777 const Register exponent = MathPowTaggedDescriptor::exponent();
778 DCHECK(exponent.is(r5));
779 const Register heapnumbermap = r8;
780 const Register heapnumber = r3;
781 const DoubleRegister double_base = d1;
782 const DoubleRegister double_exponent = d2;
783 const DoubleRegister double_result = d3;
784 const DoubleRegister double_scratch = d0;
785 const Register scratch = r11;
786 const Register scratch2 = r10;
788 Label call_runtime, done, int_exponent;
789 if (exponent_type() == ON_STACK) {
790 Label base_is_smi, unpack_exponent;
791 // The exponent and base are supplied as arguments on the stack.
792 // This can only happen if the stub is called from non-optimized code.
793 // Load input parameters from stack to double registers.
794 __ LoadP(base, MemOperand(sp, 1 * kPointerSize));
795 __ LoadP(exponent, MemOperand(sp, 0 * kPointerSize));
797 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
799 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
800 __ LoadP(scratch, FieldMemOperand(base, JSObject::kMapOffset));
801 __ cmp(scratch, heapnumbermap);
802 __ bne(&call_runtime);
804 __ lfd(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
805 __ b(&unpack_exponent);
807 __ bind(&base_is_smi);
808 __ ConvertIntToDouble(scratch, double_base);
809 __ bind(&unpack_exponent);
811 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
812 __ LoadP(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
813 __ cmp(scratch, heapnumbermap);
814 __ bne(&call_runtime);
816 __ lfd(double_exponent,
817 FieldMemOperand(exponent, HeapNumber::kValueOffset));
818 } else if (exponent_type() == TAGGED) {
819 // Base is already in double_base.
820 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
822 __ lfd(double_exponent,
823 FieldMemOperand(exponent, HeapNumber::kValueOffset));
826 if (exponent_type() != INTEGER) {
827 // Detect integer exponents stored as double.
828 __ TryDoubleToInt32Exact(scratch, double_exponent, scratch2,
830 __ beq(&int_exponent);
832 if (exponent_type() == ON_STACK) {
833 // Detect square root case. Crankshaft detects constant +/-0.5 at
834 // compile time and uses DoMathPowHalf instead. We then skip this check
835 // for non-constant cases of +/-0.5 as these hardly occur.
836 Label not_plus_half, not_minus_inf1, not_minus_inf2;
839 __ LoadDoubleLiteral(double_scratch, 0.5, scratch);
840 __ fcmpu(double_exponent, double_scratch);
841 __ bne(¬_plus_half);
843 // Calculates square root of base. Check for the special case of
844 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
845 __ LoadDoubleLiteral(double_scratch, -V8_INFINITY, scratch);
846 __ fcmpu(double_base, double_scratch);
847 __ bne(¬_minus_inf1);
848 __ fneg(double_result, double_scratch);
850 __ bind(¬_minus_inf1);
852 // Add +0 to convert -0 to +0.
853 __ fadd(double_scratch, double_base, kDoubleRegZero);
854 __ fsqrt(double_result, double_scratch);
857 __ bind(¬_plus_half);
858 __ LoadDoubleLiteral(double_scratch, -0.5, scratch);
859 __ fcmpu(double_exponent, double_scratch);
860 __ bne(&call_runtime);
862 // Calculates square root of base. Check for the special case of
863 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
864 __ LoadDoubleLiteral(double_scratch, -V8_INFINITY, scratch);
865 __ fcmpu(double_base, double_scratch);
866 __ bne(¬_minus_inf2);
867 __ fmr(double_result, kDoubleRegZero);
869 __ bind(¬_minus_inf2);
871 // Add +0 to convert -0 to +0.
872 __ fadd(double_scratch, double_base, kDoubleRegZero);
873 __ LoadDoubleLiteral(double_result, 1.0, scratch);
874 __ fsqrt(double_scratch, double_scratch);
875 __ fdiv(double_result, double_result, double_scratch);
882 AllowExternalCallThatCantCauseGC scope(masm);
883 __ PrepareCallCFunction(0, 2, scratch);
884 __ MovToFloatParameters(double_base, double_exponent);
886 ExternalReference::power_double_double_function(isolate()), 0, 2);
890 __ MovFromFloatResult(double_result);
894 // Calculate power with integer exponent.
895 __ bind(&int_exponent);
897 // Get two copies of exponent in the registers scratch and exponent.
898 if (exponent_type() == INTEGER) {
899 __ mr(scratch, exponent);
901 // Exponent has previously been stored into scratch as untagged integer.
902 __ mr(exponent, scratch);
904 __ fmr(double_scratch, double_base); // Back up base.
905 __ li(scratch2, Operand(1));
906 __ ConvertIntToDouble(scratch2, double_result);
908 // Get absolute value of exponent.
909 __ cmpi(scratch, Operand::Zero());
910 if (CpuFeatures::IsSupported(ISELECT)) {
911 __ neg(scratch2, scratch);
912 __ isel(lt, scratch, scratch2, scratch);
914 Label positive_exponent;
915 __ bge(&positive_exponent);
916 __ neg(scratch, scratch);
917 __ bind(&positive_exponent);
920 Label while_true, no_carry, loop_end;
921 __ bind(&while_true);
922 __ andi(scratch2, scratch, Operand(1));
923 __ beq(&no_carry, cr0);
924 __ fmul(double_result, double_result, double_scratch);
926 __ ShiftRightArithImm(scratch, scratch, 1, SetRC);
927 __ beq(&loop_end, cr0);
928 __ fmul(double_scratch, double_scratch, double_scratch);
932 __ cmpi(exponent, Operand::Zero());
935 __ li(scratch2, Operand(1));
936 __ ConvertIntToDouble(scratch2, double_scratch);
937 __ fdiv(double_result, double_scratch, double_result);
938 // Test whether result is zero. Bail out to check for subnormal result.
939 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
940 __ fcmpu(double_result, kDoubleRegZero);
942 // double_exponent may not containe the exponent value if the input was a
943 // smi. We set it with exponent value before bailing out.
944 __ ConvertIntToDouble(exponent, double_exponent);
946 // Returning or bailing out.
947 Counters* counters = isolate()->counters();
948 if (exponent_type() == ON_STACK) {
949 // The arguments are still on the stack.
950 __ bind(&call_runtime);
951 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
953 // The stub is called from non-optimized code, which expects the result
954 // as heap number in exponent.
956 __ AllocateHeapNumber(heapnumber, scratch, scratch2, heapnumbermap,
958 __ stfd(double_result,
959 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
960 DCHECK(heapnumber.is(r3));
961 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
967 AllowExternalCallThatCantCauseGC scope(masm);
968 __ PrepareCallCFunction(0, 2, scratch);
969 __ MovToFloatParameters(double_base, double_exponent);
971 ExternalReference::power_double_double_function(isolate()), 0, 2);
975 __ MovFromFloatResult(double_result);
978 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
984 bool CEntryStub::NeedsImmovableCode() { return true; }
987 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
988 CEntryStub::GenerateAheadOfTime(isolate);
989 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
990 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
991 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
992 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
993 CreateWeakCellStub::GenerateAheadOfTime(isolate);
994 BinaryOpICStub::GenerateAheadOfTime(isolate);
995 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
996 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
997 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
998 StoreFastElementStub::GenerateAheadOfTime(isolate);
999 TypeofStub::GenerateAheadOfTime(isolate);
1003 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1004 StoreRegistersStateStub stub(isolate);
1009 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1010 RestoreRegistersStateStub stub(isolate);
1015 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1016 // Generate if not already in cache.
1017 SaveFPRegsMode mode = kSaveFPRegs;
1018 CEntryStub(isolate, 1, mode).GetCode();
1019 StoreBufferOverflowStub(isolate, mode).GetCode();
1020 isolate->set_fp_stubs_generated(true);
1024 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1025 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1030 void CEntryStub::Generate(MacroAssembler* masm) {
1031 // Called from JavaScript; parameters are on stack as if calling JS function.
1032 // r3: number of arguments including receiver
1033 // r4: pointer to builtin function
1034 // fp: frame pointer (restored after C call)
1035 // sp: stack pointer (restored as callee's sp after C call)
1036 // cp: current context (C callee-saved)
1038 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1042 // Compute the argv pointer.
1043 __ ShiftLeftImm(r4, r3, Operand(kPointerSizeLog2));
1045 __ subi(r4, r4, Operand(kPointerSize));
1047 // Enter the exit frame that transitions from JavaScript to C++.
1048 FrameScope scope(masm, StackFrame::MANUAL);
1050 // Need at least one extra slot for return address location.
1051 int arg_stack_space = 1;
1054 #if !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
1055 // Pass buffer for return value on stack if necessary
1056 if (result_size() > 1) {
1057 DCHECK_EQ(2, result_size());
1058 arg_stack_space += 2;
1062 __ EnterExitFrame(save_doubles(), arg_stack_space);
1064 // Store a copy of argc in callee-saved registers for later.
1067 // r3, r14: number of arguments including receiver (C callee-saved)
1068 // r4: pointer to the first argument
1069 // r15: pointer to builtin function (C callee-saved)
1071 // Result returned in registers or stack, depending on result size and ABI.
1073 Register isolate_reg = r5;
1074 #if !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
1075 if (result_size() > 1) {
1076 // The return value is 16-byte non-scalar value.
1077 // Use frame storage reserved by calling function to pass return
1078 // buffer as implicit first argument.
1081 __ addi(r3, sp, Operand((kStackFrameExtraParamSlot + 1) * kPointerSize));
1087 __ mov(isolate_reg, Operand(ExternalReference::isolate_address(isolate())));
1089 #if ABI_USES_FUNCTION_DESCRIPTORS && !defined(USE_SIMULATOR)
1090 // Native AIX/PPC64 Linux use a function descriptor.
1091 __ LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(r15, kPointerSize));
1092 __ LoadP(ip, MemOperand(r15, 0)); // Instruction address
1093 Register target = ip;
1094 #elif ABI_TOC_ADDRESSABILITY_VIA_IP
1096 Register target = ip;
1098 Register target = r15;
1101 // To let the GC traverse the return address of the exit frames, we need to
1102 // know where the return address is. The CEntryStub is unmovable, so
1103 // we can store the address on the stack to be able to find it again and
1104 // we never have to restore it, because it will not change.
1106 __ mov_label_addr(r0, &after_call);
1107 __ StoreP(r0, MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize));
1109 __ bind(&after_call);
1111 #if !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
1112 // If return value is on the stack, pop it to registers.
1113 if (result_size() > 1) {
1114 __ LoadP(r4, MemOperand(r3, kPointerSize));
1115 __ LoadP(r3, MemOperand(r3));
1119 // Check result for exception sentinel.
1120 Label exception_returned;
1121 __ CompareRoot(r3, Heap::kExceptionRootIndex);
1122 __ beq(&exception_returned);
1124 // Check that there is no pending exception, otherwise we
1125 // should have returned the exception sentinel.
1126 if (FLAG_debug_code) {
1128 ExternalReference pending_exception_address(
1129 Isolate::kPendingExceptionAddress, isolate());
1131 __ mov(r5, Operand(pending_exception_address));
1132 __ LoadP(r5, MemOperand(r5));
1133 __ CompareRoot(r5, Heap::kTheHoleValueRootIndex);
1134 // Cannot use check here as it attempts to generate call into runtime.
1136 __ stop("Unexpected pending exception");
1140 // Exit C frame and return.
1142 // sp: stack pointer
1143 // fp: frame pointer
1144 // r14: still holds argc (callee-saved).
1145 __ LeaveExitFrame(save_doubles(), r14, true);
1148 // Handling of exception.
1149 __ bind(&exception_returned);
1151 ExternalReference pending_handler_context_address(
1152 Isolate::kPendingHandlerContextAddress, isolate());
1153 ExternalReference pending_handler_code_address(
1154 Isolate::kPendingHandlerCodeAddress, isolate());
1155 ExternalReference pending_handler_offset_address(
1156 Isolate::kPendingHandlerOffsetAddress, isolate());
1157 ExternalReference pending_handler_fp_address(
1158 Isolate::kPendingHandlerFPAddress, isolate());
1159 ExternalReference pending_handler_sp_address(
1160 Isolate::kPendingHandlerSPAddress, isolate());
1162 // Ask the runtime for help to determine the handler. This will set r3 to
1163 // contain the current pending exception, don't clobber it.
1164 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1167 FrameScope scope(masm, StackFrame::MANUAL);
1168 __ PrepareCallCFunction(3, 0, r3);
1169 __ li(r3, Operand::Zero());
1170 __ li(r4, Operand::Zero());
1171 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
1172 __ CallCFunction(find_handler, 3);
1175 // Retrieve the handler context, SP and FP.
1176 __ mov(cp, Operand(pending_handler_context_address));
1177 __ LoadP(cp, MemOperand(cp));
1178 __ mov(sp, Operand(pending_handler_sp_address));
1179 __ LoadP(sp, MemOperand(sp));
1180 __ mov(fp, Operand(pending_handler_fp_address));
1181 __ LoadP(fp, MemOperand(fp));
1183 // If the handler is a JS frame, restore the context to the frame. Note that
1184 // the context will be set to (cp == 0) for non-JS frames.
1186 __ cmpi(cp, Operand::Zero());
1188 __ StoreP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1191 // Compute the handler entry address and jump to it.
1192 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1193 __ mov(r4, Operand(pending_handler_code_address));
1194 __ LoadP(r4, MemOperand(r4));
1195 __ mov(r5, Operand(pending_handler_offset_address));
1196 __ LoadP(r5, MemOperand(r5));
1197 __ addi(r4, r4, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1198 if (FLAG_enable_embedded_constant_pool) {
1199 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r4);
1206 void JSEntryStub::Generate(MacroAssembler* masm) {
1213 Label invoke, handler_entry, exit;
1216 __ function_descriptor();
1218 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1221 // preserve LR in pre-reserved slot in caller's frame
1223 __ StoreP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize));
1225 // Save callee saved registers on the stack.
1226 __ MultiPush(kCalleeSaved);
1228 // Floating point regs FPR0 - FRP13 are volatile
1229 // FPR14-FPR31 are non-volatile, but sub-calls will save them for us
1231 // int offset_to_argv = kPointerSize * 22; // matches (22*4) above
1232 // __ lwz(r7, MemOperand(sp, offset_to_argv));
1234 // Push a frame with special values setup to mark it as an entry frame.
1240 __ li(r0, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1242 if (FLAG_enable_embedded_constant_pool) {
1243 __ li(kConstantPoolRegister, Operand::Zero());
1244 __ push(kConstantPoolRegister);
1246 int marker = type();
1247 __ LoadSmiLiteral(r0, Smi::FromInt(marker));
1250 // Save copies of the top frame descriptor on the stack.
1251 __ mov(r8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1252 __ LoadP(r0, MemOperand(r8));
1255 // Set up frame pointer for the frame to be pushed.
1256 __ addi(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1258 // If this is the outermost JS call, set js_entry_sp value.
1259 Label non_outermost_js;
1260 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1261 __ mov(r8, Operand(ExternalReference(js_entry_sp)));
1262 __ LoadP(r9, MemOperand(r8));
1263 __ cmpi(r9, Operand::Zero());
1264 __ bne(&non_outermost_js);
1265 __ StoreP(fp, MemOperand(r8));
1266 __ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1269 __ bind(&non_outermost_js);
1270 __ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME));
1272 __ push(ip); // frame-type
1274 // Jump to a faked try block that does the invoke, with a faked catch
1275 // block that sets the pending exception.
1278 __ bind(&handler_entry);
1279 handler_offset_ = handler_entry.pos();
1280 // Caught exception: Store result (exception) in the pending exception
1281 // field in the JSEnv and return a failure sentinel. Coming in here the
1282 // fp will be invalid because the PushStackHandler below sets it to 0 to
1283 // signal the existence of the JSEntry frame.
1284 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1287 __ StoreP(r3, MemOperand(ip));
1288 __ LoadRoot(r3, Heap::kExceptionRootIndex);
1291 // Invoke: Link this frame into the handler chain.
1293 // Must preserve r3-r7.
1294 __ PushStackHandler();
1295 // If an exception not caught by another handler occurs, this handler
1296 // returns control to the code after the b(&invoke) above, which
1297 // restores all kCalleeSaved registers (including cp and fp) to their
1298 // saved values before returning a failure to C.
1300 // Clear any pending exceptions.
1301 __ mov(r8, Operand(isolate()->factory()->the_hole_value()));
1302 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1304 __ StoreP(r8, MemOperand(ip));
1306 // Invoke the function by calling through JS entry trampoline builtin.
1307 // Notice that we cannot store a reference to the trampoline code directly in
1308 // this stub, because runtime stubs are not traversed when doing GC.
1310 // Expected registers by Builtins::JSEntryTrampoline
1316 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1317 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1319 __ mov(ip, Operand(construct_entry));
1321 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
1322 __ mov(ip, Operand(entry));
1324 __ LoadP(ip, MemOperand(ip)); // deref address
1326 // Branch and link to JSEntryTrampoline.
1327 // the address points to the start of the code object, skip the header
1328 __ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1330 __ bctrl(); // make the call
1332 // Unlink this frame from the handler chain.
1333 __ PopStackHandler();
1335 __ bind(&exit); // r3 holds result
1336 // Check if the current stack frame is marked as the outermost JS frame.
1337 Label non_outermost_js_2;
1339 __ CmpSmiLiteral(r8, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME), r0);
1340 __ bne(&non_outermost_js_2);
1341 __ mov(r9, Operand::Zero());
1342 __ mov(r8, Operand(ExternalReference(js_entry_sp)));
1343 __ StoreP(r9, MemOperand(r8));
1344 __ bind(&non_outermost_js_2);
1346 // Restore the top frame descriptors from the stack.
1348 __ mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1349 __ StoreP(r6, MemOperand(ip));
1351 // Reset the stack to the callee saved registers.
1352 __ addi(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1354 // Restore callee-saved registers and return.
1356 if (FLAG_debug_code) {
1363 __ MultiPop(kCalleeSaved);
1365 __ LoadP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize));
1371 // Uses registers r3 to r7.
1372 // Expected input (depending on whether args are in registers or on the stack):
1373 // * object: r3 or at sp + 1 * kPointerSize.
1374 // * function: r4 or at sp.
1376 // An inlined call site may have been generated before calling this stub.
1377 // In this case the offset to the inline site to patch is passed in r8.
1378 // (See LCodeGen::DoInstanceOfKnownGlobal)
1379 void InstanceofStub::Generate(MacroAssembler* masm) {
1380 // Call site inlining and patching implies arguments in registers.
1381 DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck());
1383 // Fixed register usage throughout the stub:
1384 const Register object = r3; // Object (lhs).
1385 Register map = r6; // Map of the object.
1386 const Register function = r4; // Function (rhs).
1387 const Register prototype = r7; // Prototype of the function.
1388 // The map_check_delta was stored in r8
1389 // The bool_load_delta was stored in r9
1390 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1391 const Register map_check_delta = r8;
1392 const Register bool_load_delta = r9;
1393 const Register inline_site = r10;
1394 const Register scratch = r5;
1395 Register scratch3 = no_reg;
1396 Label slow, loop, is_instance, is_not_instance, not_js_object;
1398 if (!HasArgsInRegisters()) {
1399 __ LoadP(object, MemOperand(sp, 1 * kPointerSize));
1400 __ LoadP(function, MemOperand(sp, 0));
1403 // Check that the left hand is a JS object and load map.
1404 __ JumpIfSmi(object, ¬_js_object);
1405 __ IsObjectJSObjectType(object, map, scratch, ¬_js_object);
1407 // If there is a call site cache don't look in the global cache, but do the
1408 // real lookup and update the call site cache.
1409 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
1411 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1413 __ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex);
1415 __ LoadRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
1416 __ Ret(HasArgsInRegisters() ? 0 : 2);
1421 // Get the prototype of the function.
1422 __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
1424 // Check that the function prototype is a JS object.
1425 __ JumpIfSmi(prototype, &slow);
1426 __ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
1428 // Update the global instanceof or call site inlined cache with the current
1429 // map and function. The cached answer will be set when it is known below.
1430 if (!HasCallSiteInlineCheck()) {
1431 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1432 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1434 DCHECK(HasArgsInRegisters());
1435 // Patch the (relocated) inlined map check.
1437 const Register offset = map_check_delta;
1438 __ mflr(inline_site);
1439 __ sub(inline_site, inline_site, offset);
1440 // Get the map location in offset and patch it.
1441 __ GetRelocatedValue(inline_site, offset, scratch);
1442 __ StoreP(map, FieldMemOperand(offset, Cell::kValueOffset), r0);
1445 __ RecordWriteField(offset, Cell::kValueOffset, r11, function,
1446 kLRHasNotBeenSaved, kDontSaveFPRegs,
1447 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
1450 // Register mapping: r6 is object map and r7 is function prototype.
1451 // Get prototype of object into r5.
1452 __ LoadP(scratch, FieldMemOperand(map, Map::kPrototypeOffset));
1454 // We don't need map any more. Use it as a scratch register.
1458 // Loop through the prototype chain looking for the function prototype.
1459 __ LoadRoot(scratch3, Heap::kNullValueRootIndex);
1461 __ cmp(scratch, prototype);
1462 __ beq(&is_instance);
1463 __ cmp(scratch, scratch3);
1464 __ beq(&is_not_instance);
1465 __ LoadP(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
1466 __ LoadP(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset));
1468 Factory* factory = isolate()->factory();
1470 __ bind(&is_instance);
1471 if (!HasCallSiteInlineCheck()) {
1472 __ LoadSmiLiteral(r3, Smi::FromInt(0));
1473 __ StoreRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
1474 if (ReturnTrueFalseObject()) {
1475 __ Move(r3, factory->true_value());
1478 // Patch the call site to return true.
1479 __ LoadRoot(r3, Heap::kTrueValueRootIndex);
1480 __ add(inline_site, inline_site, bool_load_delta);
1481 // Get the boolean result location in scratch and patch it.
1482 __ SetRelocatedValue(inline_site, scratch, r3);
1484 if (!ReturnTrueFalseObject()) {
1485 __ LoadSmiLiteral(r3, Smi::FromInt(0));
1488 __ Ret(HasArgsInRegisters() ? 0 : 2);
1490 __ bind(&is_not_instance);
1491 if (!HasCallSiteInlineCheck()) {
1492 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1493 __ StoreRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
1494 if (ReturnTrueFalseObject()) {
1495 __ Move(r3, factory->false_value());
1498 // Patch the call site to return false.
1499 __ LoadRoot(r3, Heap::kFalseValueRootIndex);
1500 __ add(inline_site, inline_site, bool_load_delta);
1501 // Get the boolean result location in scratch and patch it.
1502 __ SetRelocatedValue(inline_site, scratch, r3);
1504 if (!ReturnTrueFalseObject()) {
1505 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1508 __ Ret(HasArgsInRegisters() ? 0 : 2);
1510 Label object_not_null, object_not_null_or_smi;
1511 __ bind(¬_js_object);
1512 // Before null, smi and string value checks, check that the rhs is a function
1513 // as for a non-function rhs an exception needs to be thrown.
1514 __ JumpIfSmi(function, &slow);
1515 __ CompareObjectType(function, scratch3, scratch, JS_FUNCTION_TYPE);
1518 // Null is not instance of anything.
1519 __ Cmpi(object, Operand(isolate()->factory()->null_value()), r0);
1520 __ bne(&object_not_null);
1521 if (ReturnTrueFalseObject()) {
1522 __ Move(r3, factory->false_value());
1524 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1526 __ Ret(HasArgsInRegisters() ? 0 : 2);
1528 __ bind(&object_not_null);
1529 // Smi values are not instances of anything.
1530 __ JumpIfNotSmi(object, &object_not_null_or_smi);
1531 if (ReturnTrueFalseObject()) {
1532 __ Move(r3, factory->false_value());
1534 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1536 __ Ret(HasArgsInRegisters() ? 0 : 2);
1538 __ bind(&object_not_null_or_smi);
1539 // String values are not instances of anything.
1540 __ IsObjectJSStringType(object, scratch, &slow);
1541 if (ReturnTrueFalseObject()) {
1542 __ Move(r3, factory->false_value());
1544 __ LoadSmiLiteral(r3, Smi::FromInt(1));
1546 __ Ret(HasArgsInRegisters() ? 0 : 2);
1548 // Slow-case. Tail call builtin.
1550 if (!ReturnTrueFalseObject()) {
1551 if (HasArgsInRegisters()) {
1554 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
1557 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
1559 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1561 if (CpuFeatures::IsSupported(ISELECT)) {
1562 __ cmpi(r3, Operand::Zero());
1563 __ LoadRoot(r3, Heap::kTrueValueRootIndex);
1564 __ LoadRoot(r4, Heap::kFalseValueRootIndex);
1565 __ isel(eq, r3, r3, r4);
1567 Label true_value, done;
1568 __ cmpi(r3, Operand::Zero());
1569 __ beq(&true_value);
1571 __ LoadRoot(r3, Heap::kFalseValueRootIndex);
1574 __ bind(&true_value);
1575 __ LoadRoot(r3, Heap::kTrueValueRootIndex);
1579 __ Ret(HasArgsInRegisters() ? 0 : 2);
1584 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1586 Register receiver = LoadDescriptor::ReceiverRegister();
1587 // Ensure that the vector and slot registers won't be clobbered before
1588 // calling the miss handler.
1589 DCHECK(!AreAliased(r7, r8, LoadWithVectorDescriptor::VectorRegister(),
1590 LoadWithVectorDescriptor::SlotRegister()));
1592 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r7,
1595 PropertyAccessCompiler::TailCallBuiltin(
1596 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1600 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1601 // Return address is in lr.
1604 Register receiver = LoadDescriptor::ReceiverRegister();
1605 Register index = LoadDescriptor::NameRegister();
1606 Register scratch = r8;
1607 Register result = r3;
1608 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1609 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1610 result.is(LoadWithVectorDescriptor::SlotRegister()));
1612 // StringCharAtGenerator doesn't use the result register until it's passed
1613 // the different miss possibilities. If it did, we would have a conflict
1614 // when FLAG_vector_ics is true.
1615 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1616 &miss, // When not a string.
1617 &miss, // When not a number.
1618 &miss, // When index out of range.
1619 STRING_INDEX_IS_ARRAY_INDEX,
1620 RECEIVER_IS_STRING);
1621 char_at_generator.GenerateFast(masm);
1624 StubRuntimeCallHelper call_helper;
1625 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1628 PropertyAccessCompiler::TailCallBuiltin(
1629 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1633 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1634 // The displacement is the offset of the last parameter (if any)
1635 // relative to the frame pointer.
1636 const int kDisplacement =
1637 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1638 DCHECK(r4.is(ArgumentsAccessReadDescriptor::index()));
1639 DCHECK(r3.is(ArgumentsAccessReadDescriptor::parameter_count()));
1641 // Check that the key is a smi.
1643 __ JumpIfNotSmi(r4, &slow);
1645 // Check if the calling frame is an arguments adaptor frame.
1647 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1648 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
1649 STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
1650 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
1653 // Check index against formal parameters count limit passed in
1654 // through register r3. Use unsigned comparison to get negative
1659 // Read the argument from the stack and return it.
1661 __ SmiToPtrArrayOffset(r6, r6);
1663 __ LoadP(r3, MemOperand(r6, kDisplacement));
1666 // Arguments adaptor case: Check index against actual arguments
1667 // limit found in the arguments adaptor frame. Use unsigned
1668 // comparison to get negative check for free.
1670 __ LoadP(r3, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
1674 // Read the argument from the adaptor frame and return it.
1676 __ SmiToPtrArrayOffset(r6, r6);
1678 __ LoadP(r3, MemOperand(r6, kDisplacement));
1681 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1682 // by calling the runtime system.
1685 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1689 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1690 // sp[0] : number of parameters
1691 // sp[1] : receiver displacement
1694 // Check if the calling frame is an arguments adaptor frame.
1696 __ LoadP(r6, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1697 __ LoadP(r5, MemOperand(r6, StandardFrameConstants::kContextOffset));
1698 STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
1699 __ CmpSmiLiteral(r5, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
1702 // Patch the arguments.length and the parameters pointer in the current frame.
1703 __ LoadP(r5, MemOperand(r6, ArgumentsAdaptorFrameConstants::kLengthOffset));
1704 __ StoreP(r5, MemOperand(sp, 0 * kPointerSize));
1705 __ SmiToPtrArrayOffset(r5, r5);
1707 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
1708 __ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
1711 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1715 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1717 // sp[0] : number of parameters (tagged)
1718 // sp[1] : address of receiver argument
1720 // Registers used over whole function:
1721 // r9 : allocated object (tagged)
1722 // r11 : mapped parameter count (tagged)
1724 __ LoadP(r4, MemOperand(sp, 0 * kPointerSize));
1725 // r4 = parameter count (tagged)
1727 // Check if the calling frame is an arguments adaptor frame.
1729 Label adaptor_frame, try_allocate;
1730 __ LoadP(r6, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1731 __ LoadP(r5, MemOperand(r6, StandardFrameConstants::kContextOffset));
1732 STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
1733 __ CmpSmiLiteral(r5, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
1734 __ beq(&adaptor_frame);
1736 // No adaptor, parameter count = argument count.
1738 __ b(&try_allocate);
1740 // We have an adaptor frame. Patch the parameters pointer.
1741 __ bind(&adaptor_frame);
1742 __ LoadP(r5, MemOperand(r6, ArgumentsAdaptorFrameConstants::kLengthOffset));
1743 __ SmiToPtrArrayOffset(r7, r5);
1745 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
1746 __ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
1748 // r4 = parameter count (tagged)
1749 // r5 = argument count (tagged)
1750 // Compute the mapped parameter count = min(r4, r5) in r4.
1752 if (CpuFeatures::IsSupported(ISELECT)) {
1753 __ isel(lt, r4, r4, r5);
1761 __ bind(&try_allocate);
1763 // Compute the sizes of backing store, parameter map, and arguments object.
1764 // 1. Parameter map, has 2 extra words containing context and backing store.
1765 const int kParameterMapHeaderSize =
1766 FixedArray::kHeaderSize + 2 * kPointerSize;
1767 // If there are no mapped parameters, we do not need the parameter_map.
1768 __ CmpSmiLiteral(r4, Smi::FromInt(0), r0);
1769 if (CpuFeatures::IsSupported(ISELECT)) {
1770 __ SmiToPtrArrayOffset(r11, r4);
1771 __ addi(r11, r11, Operand(kParameterMapHeaderSize));
1772 __ isel(eq, r11, r0, r11);
1776 __ li(r11, Operand::Zero());
1779 __ SmiToPtrArrayOffset(r11, r4);
1780 __ addi(r11, r11, Operand(kParameterMapHeaderSize));
1784 // 2. Backing store.
1785 __ SmiToPtrArrayOffset(r7, r5);
1786 __ add(r11, r11, r7);
1787 __ addi(r11, r11, Operand(FixedArray::kHeaderSize));
1789 // 3. Arguments object.
1790 __ addi(r11, r11, Operand(Heap::kSloppyArgumentsObjectSize));
1792 // Do the allocation of all three objects in one go.
1793 __ Allocate(r11, r3, r6, r7, &runtime, TAG_OBJECT);
1795 // r3 = address of new object(s) (tagged)
1796 // r5 = argument count (smi-tagged)
1797 // Get the arguments boilerplate from the current native context into r4.
1798 const int kNormalOffset =
1799 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1800 const int kAliasedOffset =
1801 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1804 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1805 __ LoadP(r7, FieldMemOperand(r7, GlobalObject::kNativeContextOffset));
1806 __ cmpi(r4, Operand::Zero());
1807 if (CpuFeatures::IsSupported(ISELECT)) {
1808 __ LoadP(r11, MemOperand(r7, kNormalOffset));
1809 __ LoadP(r7, MemOperand(r7, kAliasedOffset));
1810 __ isel(eq, r7, r11, r7);
1814 __ LoadP(r7, MemOperand(r7, kNormalOffset));
1817 __ LoadP(r7, MemOperand(r7, kAliasedOffset));
1821 // r3 = address of new object (tagged)
1822 // r4 = mapped parameter count (tagged)
1823 // r5 = argument count (smi-tagged)
1824 // r7 = address of arguments map (tagged)
1825 __ StoreP(r7, FieldMemOperand(r3, JSObject::kMapOffset), r0);
1826 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
1827 __ StoreP(r6, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
1828 __ StoreP(r6, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
1830 // Set up the callee in-object property.
1831 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1832 __ LoadP(r6, MemOperand(sp, 2 * kPointerSize));
1833 __ AssertNotSmi(r6);
1834 const int kCalleeOffset =
1835 JSObject::kHeaderSize + Heap::kArgumentsCalleeIndex * kPointerSize;
1836 __ StoreP(r6, FieldMemOperand(r3, kCalleeOffset), r0);
1838 // Use the length (smi tagged) and set that as an in-object property too.
1840 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1841 const int kLengthOffset =
1842 JSObject::kHeaderSize + Heap::kArgumentsLengthIndex * kPointerSize;
1843 __ StoreP(r5, FieldMemOperand(r3, kLengthOffset), r0);
1845 // Set up the elements pointer in the allocated arguments object.
1846 // If we allocated a parameter map, r7 will point there, otherwise
1847 // it will point to the backing store.
1848 __ addi(r7, r3, Operand(Heap::kSloppyArgumentsObjectSize));
1849 __ StoreP(r7, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
1851 // r3 = address of new object (tagged)
1852 // r4 = mapped parameter count (tagged)
1853 // r5 = argument count (tagged)
1854 // r7 = address of parameter map or backing store (tagged)
1855 // Initialize parameter map. If there are no mapped arguments, we're done.
1856 Label skip_parameter_map;
1857 __ CmpSmiLiteral(r4, Smi::FromInt(0), r0);
1858 if (CpuFeatures::IsSupported(ISELECT)) {
1859 __ isel(eq, r6, r7, r6);
1860 __ beq(&skip_parameter_map);
1864 // Move backing store address to r6, because it is
1865 // expected there when filling in the unmapped arguments.
1867 __ b(&skip_parameter_map);
1871 __ LoadRoot(r9, Heap::kSloppyArgumentsElementsMapRootIndex);
1872 __ StoreP(r9, FieldMemOperand(r7, FixedArray::kMapOffset), r0);
1873 __ AddSmiLiteral(r9, r4, Smi::FromInt(2), r0);
1874 __ StoreP(r9, FieldMemOperand(r7, FixedArray::kLengthOffset), r0);
1875 __ StoreP(cp, FieldMemOperand(r7, FixedArray::kHeaderSize + 0 * kPointerSize),
1877 __ SmiToPtrArrayOffset(r9, r4);
1879 __ addi(r9, r9, Operand(kParameterMapHeaderSize));
1880 __ StoreP(r9, FieldMemOperand(r7, FixedArray::kHeaderSize + 1 * kPointerSize),
1883 // Copy the parameter slots and the holes in the arguments.
1884 // We need to fill in mapped_parameter_count slots. They index the context,
1885 // where parameters are stored in reverse order, at
1886 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1887 // The mapped parameter thus need to get indices
1888 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1889 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1890 // We loop from right to left.
1891 Label parameters_loop, parameters_test;
1893 __ LoadP(r11, MemOperand(sp, 0 * kPointerSize));
1894 __ AddSmiLiteral(r11, r11, Smi::FromInt(Context::MIN_CONTEXT_SLOTS), r0);
1895 __ sub(r11, r11, r4);
1896 __ LoadRoot(r10, Heap::kTheHoleValueRootIndex);
1897 __ SmiToPtrArrayOffset(r6, r9);
1899 __ addi(r6, r6, Operand(kParameterMapHeaderSize));
1901 // r9 = loop variable (tagged)
1902 // r4 = mapping index (tagged)
1903 // r6 = address of backing store (tagged)
1904 // r7 = address of parameter map (tagged)
1905 // r8 = temporary scratch (a.o., for address calculation)
1906 // r10 = the hole value
1907 __ b(¶meters_test);
1909 __ bind(¶meters_loop);
1910 __ SubSmiLiteral(r9, r9, Smi::FromInt(1), r0);
1911 __ SmiToPtrArrayOffset(r8, r9);
1912 __ addi(r8, r8, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1913 __ StorePX(r11, MemOperand(r8, r7));
1914 __ subi(r8, r8, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1915 __ StorePX(r10, MemOperand(r8, r6));
1916 __ AddSmiLiteral(r11, r11, Smi::FromInt(1), r0);
1917 __ bind(¶meters_test);
1918 __ CmpSmiLiteral(r9, Smi::FromInt(0), r0);
1919 __ bne(¶meters_loop);
1921 __ bind(&skip_parameter_map);
1922 // r5 = argument count (tagged)
1923 // r6 = address of backing store (tagged)
1925 // Copy arguments header and remaining slots (if there are any).
1926 __ LoadRoot(r8, Heap::kFixedArrayMapRootIndex);
1927 __ StoreP(r8, FieldMemOperand(r6, FixedArray::kMapOffset), r0);
1928 __ StoreP(r5, FieldMemOperand(r6, FixedArray::kLengthOffset), r0);
1930 Label arguments_loop, arguments_test;
1932 __ LoadP(r7, MemOperand(sp, 1 * kPointerSize));
1933 __ SmiToPtrArrayOffset(r8, r11);
1935 __ b(&arguments_test);
1937 __ bind(&arguments_loop);
1938 __ subi(r7, r7, Operand(kPointerSize));
1939 __ LoadP(r9, MemOperand(r7, 0));
1940 __ SmiToPtrArrayOffset(r8, r11);
1942 __ StoreP(r9, FieldMemOperand(r8, FixedArray::kHeaderSize), r0);
1943 __ AddSmiLiteral(r11, r11, Smi::FromInt(1), r0);
1945 __ bind(&arguments_test);
1947 __ blt(&arguments_loop);
1949 // Return and remove the on-stack parameters.
1950 __ addi(sp, sp, Operand(3 * kPointerSize));
1953 // Do the runtime call to allocate the arguments object.
1954 // r5 = argument count (tagged)
1956 __ StoreP(r5, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1957 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1961 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1962 // Return address is in lr.
1965 Register receiver = LoadDescriptor::ReceiverRegister();
1966 Register key = LoadDescriptor::NameRegister();
1968 // Check that the key is an array index, that is Uint32.
1969 __ TestIfPositiveSmi(key, r0);
1972 // Everything is fine, call runtime.
1973 __ Push(receiver, key); // Receiver, key.
1975 // Perform tail call to the entry.
1976 __ TailCallExternalReference(
1977 ExternalReference(IC_Utility(IC::kLoadElementWithInterceptor),
1982 PropertyAccessCompiler::TailCallBuiltin(
1983 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1987 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1988 // sp[0] : number of parameters
1989 // sp[4] : receiver displacement
1991 // Check if the calling frame is an arguments adaptor frame.
1992 Label adaptor_frame, try_allocate, runtime;
1993 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1994 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
1995 STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
1996 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
1997 __ beq(&adaptor_frame);
1999 // Get the length from the frame.
2000 __ LoadP(r4, MemOperand(sp, 0));
2001 __ b(&try_allocate);
2003 // Patch the arguments.length and the parameters pointer.
2004 __ bind(&adaptor_frame);
2005 __ LoadP(r4, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
2006 __ StoreP(r4, MemOperand(sp, 0));
2007 __ SmiToPtrArrayOffset(r6, r4);
2009 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
2010 __ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
2012 // Try the new space allocation. Start out with computing the size
2013 // of the arguments object and the elements array in words.
2014 Label add_arguments_object;
2015 __ bind(&try_allocate);
2016 __ cmpi(r4, Operand::Zero());
2017 __ beq(&add_arguments_object);
2019 __ addi(r4, r4, Operand(FixedArray::kHeaderSize / kPointerSize));
2020 __ bind(&add_arguments_object);
2021 __ addi(r4, r4, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
2023 // Do the allocation of both objects in one go.
2024 __ Allocate(r4, r3, r5, r6, &runtime,
2025 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
2027 // Get the arguments boilerplate from the current native context.
2029 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
2030 __ LoadP(r7, FieldMemOperand(r7, GlobalObject::kNativeContextOffset));
2033 MemOperand(r7, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
2035 __ StoreP(r7, FieldMemOperand(r3, JSObject::kMapOffset), r0);
2036 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
2037 __ StoreP(r6, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
2038 __ StoreP(r6, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
2040 // Get the length (smi tagged) and set that as an in-object property too.
2041 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2042 __ LoadP(r4, MemOperand(sp, 0 * kPointerSize));
2045 FieldMemOperand(r3, JSObject::kHeaderSize +
2046 Heap::kArgumentsLengthIndex * kPointerSize),
2049 // If there are no actual arguments, we're done.
2051 __ cmpi(r4, Operand::Zero());
2054 // Get the parameters pointer from the stack.
2055 __ LoadP(r5, MemOperand(sp, 1 * kPointerSize));
2057 // Set up the elements pointer in the allocated arguments object and
2058 // initialize the header in the elements fixed array.
2059 __ addi(r7, r3, Operand(Heap::kStrictArgumentsObjectSize));
2060 __ StoreP(r7, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
2061 __ LoadRoot(r6, Heap::kFixedArrayMapRootIndex);
2062 __ StoreP(r6, FieldMemOperand(r7, FixedArray::kMapOffset), r0);
2063 __ StoreP(r4, FieldMemOperand(r7, FixedArray::kLengthOffset), r0);
2064 // Untag the length for the loop.
2067 // Copy the fixed array slots.
2069 // Set up r7 to point just prior to the first array slot.
2071 Operand(FixedArray::kHeaderSize - kHeapObjectTag - kPointerSize));
2074 // Pre-decrement r5 with kPointerSize on each iteration.
2075 // Pre-decrement in order to skip receiver.
2076 __ LoadPU(r6, MemOperand(r5, -kPointerSize));
2077 // Pre-increment r7 with kPointerSize on each iteration.
2078 __ StorePU(r6, MemOperand(r7, kPointerSize));
2081 // Return and remove the on-stack parameters.
2083 __ addi(sp, sp, Operand(3 * kPointerSize));
2086 // Do the runtime call to allocate the arguments object.
2088 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2092 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
2093 // Stack layout on entry.
2094 // sp[0] : language mode
2095 // sp[4] : index of rest parameter
2096 // sp[8] : number of parameters
2097 // sp[12] : receiver displacement
2100 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2101 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
2102 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
2105 // Patch the arguments.length and the parameters pointer.
2106 __ LoadP(r4, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
2107 __ StoreP(r4, MemOperand(sp, 2 * kPointerSize));
2108 __ SmiToPtrArrayOffset(r6, r4);
2110 __ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
2111 __ StoreP(r6, MemOperand(sp, 3 * kPointerSize));
2114 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
2118 void RegExpExecStub::Generate(MacroAssembler* masm) {
2119 // Just jump directly to runtime if native RegExp is not selected at compile
2120 // time or if regexp entry in generated code is turned off runtime switch or
2122 #ifdef V8_INTERPRETED_REGEXP
2123 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2124 #else // V8_INTERPRETED_REGEXP
2126 // Stack frame on entry.
2127 // sp[0]: last_match_info (expected JSArray)
2128 // sp[4]: previous index
2129 // sp[8]: subject string
2130 // sp[12]: JSRegExp object
2132 const int kLastMatchInfoOffset = 0 * kPointerSize;
2133 const int kPreviousIndexOffset = 1 * kPointerSize;
2134 const int kSubjectOffset = 2 * kPointerSize;
2135 const int kJSRegExpOffset = 3 * kPointerSize;
2137 Label runtime, br_over, encoding_type_UC16;
2139 // Allocation of registers for this function. These are in callee save
2140 // registers and will be preserved by the call to the native RegExp code, as
2141 // this code is called using the normal C calling convention. When calling
2142 // directly from generated code the native RegExp code will not do a GC and
2143 // therefore the content of these registers are safe to use after the call.
2144 Register subject = r14;
2145 Register regexp_data = r15;
2146 Register last_match_info_elements = r16;
2147 Register code = r17;
2149 // Ensure register assigments are consistent with callee save masks
2150 DCHECK(subject.bit() & kCalleeSaved);
2151 DCHECK(regexp_data.bit() & kCalleeSaved);
2152 DCHECK(last_match_info_elements.bit() & kCalleeSaved);
2153 DCHECK(code.bit() & kCalleeSaved);
2155 // Ensure that a RegExp stack is allocated.
2156 ExternalReference address_of_regexp_stack_memory_address =
2157 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2158 ExternalReference address_of_regexp_stack_memory_size =
2159 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2160 __ mov(r3, Operand(address_of_regexp_stack_memory_size));
2161 __ LoadP(r3, MemOperand(r3, 0));
2162 __ cmpi(r3, Operand::Zero());
2165 // Check that the first argument is a JSRegExp object.
2166 __ LoadP(r3, MemOperand(sp, kJSRegExpOffset));
2167 __ JumpIfSmi(r3, &runtime);
2168 __ CompareObjectType(r3, r4, r4, JS_REGEXP_TYPE);
2171 // Check that the RegExp has been compiled (data contains a fixed array).
2172 __ LoadP(regexp_data, FieldMemOperand(r3, JSRegExp::kDataOffset));
2173 if (FLAG_debug_code) {
2174 __ TestIfSmi(regexp_data, r0);
2175 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected, cr0);
2176 __ CompareObjectType(regexp_data, r3, r3, FIXED_ARRAY_TYPE);
2177 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2180 // regexp_data: RegExp data (FixedArray)
2181 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2182 __ LoadP(r3, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2183 // DCHECK(Smi::FromInt(JSRegExp::IRREGEXP) < (char *)0xffffu);
2184 __ CmpSmiLiteral(r3, Smi::FromInt(JSRegExp::IRREGEXP), r0);
2187 // regexp_data: RegExp data (FixedArray)
2188 // Check that the number of captures fit in the static offsets vector buffer.
2190 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2191 // Check (number_of_captures + 1) * 2 <= offsets vector size
2192 // Or number_of_captures * 2 <= offsets vector size - 2
2193 // SmiToShortArrayOffset accomplishes the multiplication by 2 and
2194 // SmiUntag (which is a nop for 32-bit).
2195 __ SmiToShortArrayOffset(r5, r5);
2196 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2197 __ cmpli(r5, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2200 // Reset offset for possibly sliced string.
2201 __ li(r11, Operand::Zero());
2202 __ LoadP(subject, MemOperand(sp, kSubjectOffset));
2203 __ JumpIfSmi(subject, &runtime);
2204 __ mr(r6, subject); // Make a copy of the original subject string.
2205 __ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
2206 __ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
2207 // subject: subject string
2208 // r6: subject string
2209 // r3: subject string instance type
2210 // regexp_data: RegExp data (FixedArray)
2211 // Handle subject string according to its encoding and representation:
2212 // (1) Sequential string? If yes, go to (5).
2213 // (2) Anything but sequential or cons? If yes, go to (6).
2214 // (3) Cons string. If the string is flat, replace subject with first string.
2215 // Otherwise bailout.
2216 // (4) Is subject external? If yes, go to (7).
2217 // (5) Sequential string. Load regexp code according to encoding.
2221 // Deferred code at the end of the stub:
2222 // (6) Not a long external string? If yes, go to (8).
2223 // (7) External string. Make it, offset-wise, look like a sequential string.
2225 // (8) Short external string or not a string? If yes, bail out to runtime.
2226 // (9) Sliced string. Replace subject with parent. Go to (4).
2228 Label seq_string /* 5 */, external_string /* 7 */, check_underlying /* 4 */,
2229 not_seq_nor_cons /* 6 */, not_long_external /* 8 */;
2231 // (1) Sequential string? If yes, go to (5).
2232 STATIC_ASSERT((kIsNotStringMask | kStringRepresentationMask |
2233 kShortExternalStringMask) == 0x93);
2234 __ andi(r4, r3, Operand(kIsNotStringMask | kStringRepresentationMask |
2235 kShortExternalStringMask));
2236 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2237 __ beq(&seq_string, cr0); // Go to (5).
2239 // (2) Anything but sequential or cons? If yes, go to (6).
2240 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2241 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2242 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2243 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2244 STATIC_ASSERT(kExternalStringTag < 0xffffu);
2245 __ cmpi(r4, Operand(kExternalStringTag));
2246 __ bge(¬_seq_nor_cons); // Go to (6).
2248 // (3) Cons string. Check that it's flat.
2249 // Replace subject with first string and reload instance type.
2250 __ LoadP(r3, FieldMemOperand(subject, ConsString::kSecondOffset));
2251 __ CompareRoot(r3, Heap::kempty_stringRootIndex);
2253 __ LoadP(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2255 // (4) Is subject external? If yes, go to (7).
2256 __ bind(&check_underlying);
2257 __ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
2258 __ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
2259 STATIC_ASSERT(kSeqStringTag == 0);
2260 STATIC_ASSERT(kStringRepresentationMask == 3);
2261 __ andi(r0, r3, Operand(kStringRepresentationMask));
2262 // The underlying external string is never a short external string.
2263 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2264 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2265 __ bne(&external_string, cr0); // Go to (7).
2267 // (5) Sequential string. Load regexp code according to encoding.
2268 __ bind(&seq_string);
2269 // subject: sequential subject string (or look-alike, external string)
2270 // r6: original subject string
2271 // Load previous index and check range before r6 is overwritten. We have to
2272 // use r6 instead of subject here because subject might have been only made
2273 // to look like a sequential string when it actually is an external string.
2274 __ LoadP(r4, MemOperand(sp, kPreviousIndexOffset));
2275 __ JumpIfNotSmi(r4, &runtime);
2276 __ LoadP(r6, FieldMemOperand(r6, String::kLengthOffset));
2281 STATIC_ASSERT(4 == kOneByteStringTag);
2282 STATIC_ASSERT(kTwoByteStringTag == 0);
2283 STATIC_ASSERT(kStringEncodingMask == 4);
2284 __ ExtractBitMask(r6, r3, kStringEncodingMask, SetRC);
2285 __ beq(&encoding_type_UC16, cr0);
2287 FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2289 __ bind(&encoding_type_UC16);
2290 __ LoadP(code, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2293 // (E) Carry on. String handling is done.
2294 // code: irregexp code
2295 // Check that the irregexp code has been generated for the actual string
2296 // encoding. If it has, the field contains a code object otherwise it contains
2297 // a smi (code flushing support).
2298 __ JumpIfSmi(code, &runtime);
2300 // r4: previous index
2301 // r6: encoding of subject string (1 if one_byte, 0 if two_byte);
2302 // code: Address of generated regexp code
2303 // subject: Subject string
2304 // regexp_data: RegExp data (FixedArray)
2305 // All checks done. Now push arguments for native regexp code.
2306 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r3, r5);
2308 // Isolates: note we add an additional parameter here (isolate pointer).
2309 const int kRegExpExecuteArguments = 10;
2310 const int kParameterRegisters = 8;
2311 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2313 // Stack pointer now points to cell where return address is to be written.
2314 // Arguments are before that on the stack or in registers.
2316 // Argument 10 (in stack parameter area): Pass current isolate address.
2317 __ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
2318 __ StoreP(r3, MemOperand(sp, (kStackFrameExtraParamSlot + 1) * kPointerSize));
2320 // Argument 9 is a dummy that reserves the space used for
2321 // the return address added by the ExitFrame in native calls.
2323 // Argument 8 (r10): Indicate that this is a direct call from JavaScript.
2324 __ li(r10, Operand(1));
2326 // Argument 7 (r9): Start (high end) of backtracking stack memory area.
2327 __ mov(r3, Operand(address_of_regexp_stack_memory_address));
2328 __ LoadP(r3, MemOperand(r3, 0));
2329 __ mov(r5, Operand(address_of_regexp_stack_memory_size));
2330 __ LoadP(r5, MemOperand(r5, 0));
2333 // Argument 6 (r8): Set the number of capture registers to zero to force
2334 // global egexps to behave as non-global. This does not affect non-global
2336 __ li(r8, Operand::Zero());
2338 // Argument 5 (r7): static offsets vector buffer.
2341 Operand(ExternalReference::address_of_static_offsets_vector(isolate())));
2343 // For arguments 4 (r6) and 3 (r5) get string length, calculate start of data
2344 // and calculate the shift of the index (0 for one-byte and 1 for two-byte).
2345 __ addi(r18, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2346 __ xori(r6, r6, Operand(1));
2347 // Load the length from the original subject string from the previous stack
2348 // frame. Therefore we have to use fp, which points exactly to two pointer
2349 // sizes below the previous sp. (Because creating a new stack frame pushes
2350 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2351 __ LoadP(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2352 // If slice offset is not 0, load the length from the original sliced string.
2353 // Argument 4, r6: End of string data
2354 // Argument 3, r5: Start of string data
2355 // Prepare start and end index of the input.
2356 __ ShiftLeft_(r11, r11, r6);
2357 __ add(r11, r18, r11);
2358 __ ShiftLeft_(r5, r4, r6);
2359 __ add(r5, r11, r5);
2361 __ LoadP(r18, FieldMemOperand(subject, String::kLengthOffset));
2363 __ ShiftLeft_(r6, r18, r6);
2364 __ add(r6, r11, r6);
2366 // Argument 2 (r4): Previous index.
2369 // Argument 1 (r3): Subject string.
2372 // Locate the code entry and call it.
2373 __ addi(code, code, Operand(Code::kHeaderSize - kHeapObjectTag));
2376 #if ABI_USES_FUNCTION_DESCRIPTORS && defined(USE_SIMULATOR)
2377 // Even Simulated AIX/PPC64 Linux uses a function descriptor for the
2378 // RegExp routine. Extract the instruction address here since
2379 // DirectCEntryStub::GenerateCall will not do it for calls out to
2380 // what it thinks is C code compiled for the simulator/host
2382 __ LoadP(code, MemOperand(code, 0)); // Instruction address
2385 DirectCEntryStub stub(isolate());
2386 stub.GenerateCall(masm, code);
2388 __ LeaveExitFrame(false, no_reg, true);
2390 // r3: result (int32)
2391 // subject: subject string (callee saved)
2392 // regexp_data: RegExp data (callee saved)
2393 // last_match_info_elements: Last match info elements (callee saved)
2394 // Check the result.
2396 __ cmpwi(r3, Operand(1));
2397 // We expect exactly one result since we force the called regexp to behave
2401 __ cmpwi(r3, Operand(NativeRegExpMacroAssembler::FAILURE));
2403 __ cmpwi(r3, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2404 // If not exception it can only be retry. Handle that in the runtime system.
2406 // Result must now be exception. If there is no pending exception already a
2407 // stack overflow (on the backtrack stack) was detected in RegExp code but
2408 // haven't created the exception yet. Handle that in the runtime system.
2409 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2410 __ mov(r4, Operand(isolate()->factory()->the_hole_value()));
2411 __ mov(r5, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2413 __ LoadP(r3, MemOperand(r5, 0));
2417 // For exception, throw the exception again.
2418 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2421 // For failure and exception return null.
2422 __ mov(r3, Operand(isolate()->factory()->null_value()));
2423 __ addi(sp, sp, Operand(4 * kPointerSize));
2426 // Process the result from the native regexp code.
2429 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2430 // Calculate number of capture registers (number_of_captures + 1) * 2.
2431 // SmiToShortArrayOffset accomplishes the multiplication by 2 and
2432 // SmiUntag (which is a nop for 32-bit).
2433 __ SmiToShortArrayOffset(r4, r4);
2434 __ addi(r4, r4, Operand(2));
2436 __ LoadP(r3, MemOperand(sp, kLastMatchInfoOffset));
2437 __ JumpIfSmi(r3, &runtime);
2438 __ CompareObjectType(r3, r5, r5, JS_ARRAY_TYPE);
2440 // Check that the JSArray is in fast case.
2441 __ LoadP(last_match_info_elements,
2442 FieldMemOperand(r3, JSArray::kElementsOffset));
2444 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2445 __ CompareRoot(r3, Heap::kFixedArrayMapRootIndex);
2447 // Check that the last match info has space for the capture registers and the
2448 // additional information.
2450 r3, FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2451 __ addi(r5, r4, Operand(RegExpImpl::kLastMatchOverhead));
2452 __ SmiUntag(r0, r3);
2456 // r4: number of capture registers
2457 // subject: subject string
2458 // Store the capture count.
2460 __ StoreP(r5, FieldMemOperand(last_match_info_elements,
2461 RegExpImpl::kLastCaptureCountOffset),
2463 // Store last subject and last input.
2464 __ StoreP(subject, FieldMemOperand(last_match_info_elements,
2465 RegExpImpl::kLastSubjectOffset),
2468 __ RecordWriteField(last_match_info_elements, RegExpImpl::kLastSubjectOffset,
2469 subject, r10, kLRHasNotBeenSaved, kDontSaveFPRegs);
2471 __ StoreP(subject, FieldMemOperand(last_match_info_elements,
2472 RegExpImpl::kLastInputOffset),
2474 __ RecordWriteField(last_match_info_elements, RegExpImpl::kLastInputOffset,
2475 subject, r10, kLRHasNotBeenSaved, kDontSaveFPRegs);
2477 // Get the static offsets vector filled by the native regexp code.
2478 ExternalReference address_of_static_offsets_vector =
2479 ExternalReference::address_of_static_offsets_vector(isolate());
2480 __ mov(r5, Operand(address_of_static_offsets_vector));
2482 // r4: number of capture registers
2483 // r5: offsets vector
2485 // Capture register counter starts from number of capture registers and
2486 // counts down until wraping after zero.
2488 r3, last_match_info_elements,
2489 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag - kPointerSize));
2490 __ addi(r5, r5, Operand(-kIntSize)); // bias down for lwzu
2492 __ bind(&next_capture);
2493 // Read the value from the static offsets vector buffer.
2494 __ lwzu(r6, MemOperand(r5, kIntSize));
2495 // Store the smi value in the last match info.
2497 __ StorePU(r6, MemOperand(r3, kPointerSize));
2498 __ bdnz(&next_capture);
2500 // Return last match info.
2501 __ LoadP(r3, MemOperand(sp, kLastMatchInfoOffset));
2502 __ addi(sp, sp, Operand(4 * kPointerSize));
2505 // Do the runtime call to execute the regexp.
2507 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2509 // Deferred code for string handling.
2510 // (6) Not a long external string? If yes, go to (8).
2511 __ bind(¬_seq_nor_cons);
2512 // Compare flags are still set.
2513 __ bgt(¬_long_external); // Go to (8).
2515 // (7) External string. Make it, offset-wise, look like a sequential string.
2516 __ bind(&external_string);
2517 __ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
2518 __ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
2519 if (FLAG_debug_code) {
2520 // Assert that we do not have a cons or slice (indirect strings) here.
2521 // Sequential strings have already been ruled out.
2522 STATIC_ASSERT(kIsIndirectStringMask == 1);
2523 __ andi(r0, r3, Operand(kIsIndirectStringMask));
2524 __ Assert(eq, kExternalStringExpectedButNotFound, cr0);
2527 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2528 // Move the pointer so that offset-wise, it looks like a sequential string.
2529 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2530 __ subi(subject, subject,
2531 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2532 __ b(&seq_string); // Go to (5).
2534 // (8) Short external string or not a string? If yes, bail out to runtime.
2535 __ bind(¬_long_external);
2536 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag != 0);
2537 __ andi(r0, r4, Operand(kIsNotStringMask | kShortExternalStringMask));
2538 __ bne(&runtime, cr0);
2540 // (9) Sliced string. Replace subject with parent. Go to (4).
2541 // Load offset into r11 and replace subject string with parent.
2542 __ LoadP(r11, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2544 __ LoadP(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2545 __ b(&check_underlying); // Go to (4).
2546 #endif // V8_INTERPRETED_REGEXP
2550 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
2551 // r3 : number of arguments to the construct function
2552 // r5 : Feedback vector
2553 // r6 : slot in feedback vector (Smi)
2554 // r4 : the function to call
2555 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2557 // Number-of-arguments register must be smi-tagged to call out.
2559 __ Push(r6, r5, r4, r3);
2563 __ Pop(r6, r5, r4, r3);
2568 static void GenerateRecordCallTarget(MacroAssembler* masm) {
2569 // Cache the called function in a feedback vector slot. Cache states
2570 // are uninitialized, monomorphic (indicated by a JSFunction), and
2572 // r3 : number of arguments to the construct function
2573 // r4 : the function to call
2574 // r5 : Feedback vector
2575 // r6 : slot in feedback vector (Smi)
2576 Label initialize, done, miss, megamorphic, not_array_function;
2578 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2579 masm->isolate()->heap()->megamorphic_symbol());
2580 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2581 masm->isolate()->heap()->uninitialized_symbol());
2583 // Load the cache state into r7.
2584 __ SmiToPtrArrayOffset(r7, r6);
2586 __ LoadP(r7, FieldMemOperand(r7, FixedArray::kHeaderSize));
2588 // A monomorphic cache hit or an already megamorphic state: invoke the
2589 // function without changing the state.
2590 // We don't know if r7 is a WeakCell or a Symbol, but it's harmless to read at
2591 // this position in a symbol (see static asserts in type-feedback-vector.h).
2592 Label check_allocation_site;
2593 Register feedback_map = r8;
2594 Register weak_value = r9;
2595 __ LoadP(weak_value, FieldMemOperand(r7, WeakCell::kValueOffset));
2596 __ cmp(r4, weak_value);
2598 __ CompareRoot(r7, Heap::kmegamorphic_symbolRootIndex);
2600 __ LoadP(feedback_map, FieldMemOperand(r7, HeapObject::kMapOffset));
2601 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2602 __ bne(FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2604 // If the weak cell is cleared, we have a new chance to become monomorphic.
2605 __ JumpIfSmi(weak_value, &initialize);
2608 if (!FLAG_pretenuring_call_new) {
2609 __ bind(&check_allocation_site);
2610 // If we came here, we need to see if we are the array function.
2611 // If we didn't have a matching function, and we didn't find the megamorph
2612 // sentinel, then we have in the slot either some other function or an
2614 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2617 // Make sure the function is the Array() function
2618 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
2620 __ bne(&megamorphic);
2626 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2628 __ CompareRoot(r7, Heap::kuninitialized_symbolRootIndex);
2629 __ beq(&initialize);
2630 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2631 // write-barrier is needed.
2632 __ bind(&megamorphic);
2633 __ SmiToPtrArrayOffset(r7, r6);
2635 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2636 __ StoreP(ip, FieldMemOperand(r7, FixedArray::kHeaderSize), r0);
2639 // An uninitialized cache is patched with the function
2640 __ bind(&initialize);
2642 if (!FLAG_pretenuring_call_new) {
2643 // Make sure the function is the Array() function.
2644 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
2646 __ bne(¬_array_function);
2648 // The target function is the Array constructor,
2649 // Create an AllocationSite if we don't already have it, store it in the
2651 CreateAllocationSiteStub create_stub(masm->isolate());
2652 CallStubInRecordCallTarget(masm, &create_stub);
2655 __ bind(¬_array_function);
2658 CreateWeakCellStub create_stub(masm->isolate());
2659 CallStubInRecordCallTarget(masm, &create_stub);
2664 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2665 // Do not transform the receiver for strict mode functions and natives.
2666 __ LoadP(r6, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
2667 __ lwz(r7, FieldMemOperand(r6, SharedFunctionInfo::kCompilerHintsOffset));
2669 #if V8_TARGET_ARCH_PPC64
2670 SharedFunctionInfo::kStrictModeFunction,
2672 SharedFunctionInfo::kStrictModeFunction + kSmiTagSize,
2677 // Do not transform the receiver for native.
2679 #if V8_TARGET_ARCH_PPC64
2680 SharedFunctionInfo::kNative,
2682 SharedFunctionInfo::kNative + kSmiTagSize,
2689 static void EmitSlowCase(MacroAssembler* masm, int argc, Label* non_function) {
2690 // Check for function proxy.
2691 STATIC_ASSERT(JS_FUNCTION_PROXY_TYPE < 0xffffu);
2692 __ cmpi(r7, Operand(JS_FUNCTION_PROXY_TYPE));
2693 __ bne(non_function);
2694 __ push(r4); // put proxy as additional argument
2695 __ li(r3, Operand(argc + 1));
2696 __ li(r5, Operand::Zero());
2697 __ GetBuiltinFunction(r4, Builtins::CALL_FUNCTION_PROXY);
2699 Handle<Code> adaptor =
2700 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2701 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2704 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2705 // of the original receiver from the call site).
2706 __ bind(non_function);
2707 __ StoreP(r4, MemOperand(sp, argc * kPointerSize), r0);
2708 __ li(r3, Operand(argc)); // Set up the number of arguments.
2709 __ li(r5, Operand::Zero());
2710 __ GetBuiltinFunction(r4, Builtins::CALL_NON_FUNCTION);
2711 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2712 RelocInfo::CODE_TARGET);
2716 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2717 // Wrap the receiver and patch it back onto the stack.
2719 FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2721 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2724 __ StoreP(r3, MemOperand(sp, argc * kPointerSize), r0);
2729 static void CallFunctionNoFeedback(MacroAssembler* masm, int argc,
2730 bool needs_checks, bool call_as_method) {
2731 // r4 : the function to call
2732 Label slow, non_function, wrap, cont;
2735 // Check that the function is really a JavaScript function.
2736 // r4: pushed function (to be verified)
2737 __ JumpIfSmi(r4, &non_function);
2739 // Goto slow case if we do not have a function.
2740 __ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
2744 // Fast-case: Invoke the function now.
2745 // r4: pushed function
2746 ParameterCount actual(argc);
2748 if (call_as_method) {
2750 EmitContinueIfStrictOrNative(masm, &cont);
2753 // Compute the receiver in sloppy mode.
2754 __ LoadP(r6, MemOperand(sp, argc * kPointerSize), r0);
2757 __ JumpIfSmi(r6, &wrap);
2758 __ CompareObjectType(r6, r7, r7, FIRST_SPEC_OBJECT_TYPE);
2767 __ InvokeFunction(r4, actual, JUMP_FUNCTION, NullCallWrapper());
2770 // Slow-case: Non-function called.
2772 EmitSlowCase(masm, argc, &non_function);
2775 if (call_as_method) {
2777 EmitWrapCase(masm, argc, &cont);
2782 void CallFunctionStub::Generate(MacroAssembler* masm) {
2783 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2787 void CallConstructStub::Generate(MacroAssembler* masm) {
2788 // r3 : number of arguments
2789 // r4 : the function to call
2790 // r5 : feedback vector
2791 // r6 : (only if r5 is not the megamorphic symbol) slot in feedback
2793 Label slow, non_function_call;
2795 // Check that the function is not a smi.
2796 __ JumpIfSmi(r4, &non_function_call);
2797 // Check that the function is a JSFunction.
2798 __ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
2801 if (RecordCallTarget()) {
2802 GenerateRecordCallTarget(masm);
2804 __ SmiToPtrArrayOffset(r8, r6);
2806 if (FLAG_pretenuring_call_new) {
2807 // Put the AllocationSite from the feedback vector into r5.
2808 // By adding kPointerSize we encode that we know the AllocationSite
2809 // entry is at the feedback vector slot given by r6 + 1.
2810 __ LoadP(r5, FieldMemOperand(r8, FixedArray::kHeaderSize + kPointerSize));
2812 // Put the AllocationSite from the feedback vector into r5, or undefined.
2813 __ LoadP(r5, FieldMemOperand(r8, FixedArray::kHeaderSize));
2814 __ LoadP(r8, FieldMemOperand(r5, AllocationSite::kMapOffset));
2815 __ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
2816 if (CpuFeatures::IsSupported(ISELECT)) {
2817 __ LoadRoot(r8, Heap::kUndefinedValueRootIndex);
2818 __ isel(eq, r5, r5, r8);
2820 Label feedback_register_initialized;
2821 __ beq(&feedback_register_initialized);
2822 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
2823 __ bind(&feedback_register_initialized);
2827 __ AssertUndefinedOrAllocationSite(r5, r8);
2830 // Pass function as original constructor.
2831 if (IsSuperConstructorCall()) {
2832 __ ShiftLeftImm(r7, r3, Operand(kPointerSizeLog2));
2833 __ addi(r7, r7, Operand(kPointerSize));
2834 __ LoadPX(r6, MemOperand(sp, r7));
2839 // Jump to the function-specific construct stub.
2840 Register jmp_reg = r7;
2841 __ LoadP(jmp_reg, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
2843 FieldMemOperand(jmp_reg, SharedFunctionInfo::kConstructStubOffset));
2844 __ addi(ip, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2845 __ JumpToJSEntry(ip);
2847 // r3: number of arguments
2848 // r4: called object
2852 STATIC_ASSERT(JS_FUNCTION_PROXY_TYPE < 0xffffu);
2853 __ cmpi(r7, Operand(JS_FUNCTION_PROXY_TYPE));
2854 __ bne(&non_function_call);
2855 __ GetBuiltinFunction(r4, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2858 __ bind(&non_function_call);
2859 __ GetBuiltinFunction(r4, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2861 // Set expected number of arguments to zero (not changing r3).
2862 __ li(r5, Operand::Zero());
2863 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2864 RelocInfo::CODE_TARGET);
2868 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2869 __ LoadP(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2871 FieldMemOperand(vector, JSFunction::kSharedFunctionInfoOffset));
2873 FieldMemOperand(vector, SharedFunctionInfo::kFeedbackVectorOffset));
2877 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2882 int argc = arg_count();
2883 ParameterCount actual(argc);
2885 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
2889 __ mov(r3, Operand(arg_count()));
2890 __ SmiToPtrArrayOffset(r9, r6);
2892 __ LoadP(r7, FieldMemOperand(r9, FixedArray::kHeaderSize));
2894 // Verify that r7 contains an AllocationSite
2895 __ LoadP(r8, FieldMemOperand(r7, HeapObject::kMapOffset));
2896 __ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
2899 // Increment the call count for monomorphic function calls.
2900 const int count_offset = FixedArray::kHeaderSize + kPointerSize;
2901 __ LoadP(r6, FieldMemOperand(r9, count_offset));
2902 __ AddSmiLiteral(r6, r6, Smi::FromInt(CallICNexus::kCallCountIncrement), r0);
2903 __ StoreP(r6, FieldMemOperand(r9, count_offset), r0);
2907 ArrayConstructorStub stub(masm->isolate(), arg_count());
2908 __ TailCallStub(&stub);
2913 // The slow case, we need this no matter what to complete a call after a miss.
2914 CallFunctionNoFeedback(masm, arg_count(), true, CallAsMethod());
2917 __ stop("Unexpected code address");
2921 void CallICStub::Generate(MacroAssembler* masm) {
2923 // r6 - slot id (Smi)
2925 const int with_types_offset =
2926 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2927 const int generic_offset =
2928 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2929 Label extra_checks_or_miss, slow_start;
2930 Label slow, non_function, wrap, cont;
2931 Label have_js_function;
2932 int argc = arg_count();
2933 ParameterCount actual(argc);
2935 // The checks. First, does r4 match the recorded monomorphic target?
2936 __ SmiToPtrArrayOffset(r9, r6);
2938 __ LoadP(r7, FieldMemOperand(r9, FixedArray::kHeaderSize));
2940 // We don't know that we have a weak cell. We might have a private symbol
2941 // or an AllocationSite, but the memory is safe to examine.
2942 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2944 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2945 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2946 // computed, meaning that it can't appear to be a pointer. If the low bit is
2947 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2949 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2950 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2951 WeakCell::kValueOffset &&
2952 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2954 __ LoadP(r8, FieldMemOperand(r7, WeakCell::kValueOffset));
2956 __ bne(&extra_checks_or_miss);
2958 // The compare above could have been a SMI/SMI comparison. Guard against this
2959 // convincing us that we have a monomorphic JSFunction.
2960 __ JumpIfSmi(r4, &extra_checks_or_miss);
2962 // Increment the call count for monomorphic function calls.
2963 const int count_offset = FixedArray::kHeaderSize + kPointerSize;
2964 __ LoadP(r6, FieldMemOperand(r9, count_offset));
2965 __ AddSmiLiteral(r6, r6, Smi::FromInt(CallICNexus::kCallCountIncrement), r0);
2966 __ StoreP(r6, FieldMemOperand(r9, count_offset), r0);
2968 __ bind(&have_js_function);
2969 if (CallAsMethod()) {
2970 EmitContinueIfStrictOrNative(masm, &cont);
2971 // Compute the receiver in sloppy mode.
2972 __ LoadP(r6, MemOperand(sp, argc * kPointerSize), r0);
2974 __ JumpIfSmi(r6, &wrap);
2975 __ CompareObjectType(r6, r7, r7, FIRST_SPEC_OBJECT_TYPE);
2981 __ InvokeFunction(r4, actual, JUMP_FUNCTION, NullCallWrapper());
2984 EmitSlowCase(masm, argc, &non_function);
2986 if (CallAsMethod()) {
2988 EmitWrapCase(masm, argc, &cont);
2991 __ bind(&extra_checks_or_miss);
2992 Label uninitialized, miss;
2994 __ CompareRoot(r7, Heap::kmegamorphic_symbolRootIndex);
2995 __ beq(&slow_start);
2997 // The following cases attempt to handle MISS cases without going to the
2999 if (FLAG_trace_ic) {
3003 __ CompareRoot(r7, Heap::kuninitialized_symbolRootIndex);
3004 __ beq(&uninitialized);
3006 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3007 // to handle it here. More complex cases are dealt with in the runtime.
3008 __ AssertNotSmi(r7);
3009 __ CompareObjectType(r7, r8, r8, JS_FUNCTION_TYPE);
3011 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
3012 __ StoreP(ip, FieldMemOperand(r9, FixedArray::kHeaderSize), r0);
3013 // We have to update statistics for runtime profiling.
3014 __ LoadP(r7, FieldMemOperand(r5, with_types_offset));
3015 __ SubSmiLiteral(r7, r7, Smi::FromInt(1), r0);
3016 __ StoreP(r7, FieldMemOperand(r5, with_types_offset), r0);
3017 __ LoadP(r7, FieldMemOperand(r5, generic_offset));
3018 __ AddSmiLiteral(r7, r7, Smi::FromInt(1), r0);
3019 __ StoreP(r7, FieldMemOperand(r5, generic_offset), r0);
3022 __ bind(&uninitialized);
3024 // We are going monomorphic, provided we actually have a JSFunction.
3025 __ JumpIfSmi(r4, &miss);
3027 // Goto miss case if we do not have a function.
3028 __ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
3031 // Make sure the function is not the Array() function, which requires special
3032 // behavior on MISS.
3033 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
3038 __ LoadP(r7, FieldMemOperand(r5, with_types_offset));
3039 __ AddSmiLiteral(r7, r7, Smi::FromInt(1), r0);
3040 __ StoreP(r7, FieldMemOperand(r5, with_types_offset), r0);
3042 // Initialize the call counter.
3043 __ LoadSmiLiteral(r8, Smi::FromInt(CallICNexus::kCallCountIncrement));
3044 __ StoreP(r8, FieldMemOperand(r9, count_offset), r0);
3046 // Store the function. Use a stub since we need a frame for allocation.
3051 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3052 CreateWeakCellStub create_stub(masm->isolate());
3054 __ CallStub(&create_stub);
3058 __ b(&have_js_function);
3060 // We are here because tracing is on or we encountered a MISS case we can't
3066 __ bind(&slow_start);
3067 // Check that the function is really a JavaScript function.
3068 // r4: pushed function (to be verified)
3069 __ JumpIfSmi(r4, &non_function);
3071 // Goto slow case if we do not have a function.
3072 __ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
3074 __ b(&have_js_function);
3078 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3079 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3081 // Push the function and feedback info.
3082 __ Push(r4, r5, r6);
3085 IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
3086 : IC::kCallIC_Customization_Miss;
3088 ExternalReference miss = ExternalReference(IC_Utility(id), masm->isolate());
3089 __ CallExternalReference(miss, 3);
3091 // Move result to r4 and exit the internal frame.
3096 // StringCharCodeAtGenerator
3097 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3098 // If the receiver is a smi trigger the non-string case.
3099 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3100 __ JumpIfSmi(object_, receiver_not_string_);
3102 // Fetch the instance type of the receiver into result register.
3103 __ LoadP(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3104 __ lbz(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3105 // If the receiver is not a string trigger the non-string case.
3106 __ andi(r0, result_, Operand(kIsNotStringMask));
3107 __ bne(receiver_not_string_, cr0);
3110 // If the index is non-smi trigger the non-smi case.
3111 __ JumpIfNotSmi(index_, &index_not_smi_);
3112 __ bind(&got_smi_index_);
3114 // Check for index out of range.
3115 __ LoadP(ip, FieldMemOperand(object_, String::kLengthOffset));
3116 __ cmpl(ip, index_);
3117 __ ble(index_out_of_range_);
3119 __ SmiUntag(index_);
3121 StringCharLoadGenerator::Generate(masm, object_, index_, result_,
3129 void StringCharCodeAtGenerator::GenerateSlow(
3130 MacroAssembler* masm, EmbedMode embed_mode,
3131 const RuntimeCallHelper& call_helper) {
3132 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3134 // Index is not a smi.
3135 __ bind(&index_not_smi_);
3136 // If index is a heap number, try converting it to an integer.
3137 __ CheckMap(index_, result_, Heap::kHeapNumberMapRootIndex, index_not_number_,
3139 call_helper.BeforeCall(masm);
3140 if (embed_mode == PART_OF_IC_HANDLER) {
3141 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3142 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3144 // index_ is consumed by runtime conversion function.
3145 __ Push(object_, index_);
3147 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3148 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3150 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3151 // NumberToSmi discards numbers that are not exact integers.
3152 __ CallRuntime(Runtime::kNumberToSmi, 1);
3154 // Save the conversion result before the pop instructions below
3155 // have a chance to overwrite it.
3156 __ Move(index_, r3);
3157 if (embed_mode == PART_OF_IC_HANDLER) {
3158 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3159 LoadWithVectorDescriptor::SlotRegister(), object_);
3163 // Reload the instance type.
3164 __ LoadP(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3165 __ lbz(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3166 call_helper.AfterCall(masm);
3167 // If index is still not a smi, it must be out of range.
3168 __ JumpIfNotSmi(index_, index_out_of_range_);
3169 // Otherwise, return to the fast path.
3170 __ b(&got_smi_index_);
3172 // Call runtime. We get here when the receiver is a string and the
3173 // index is a number, but the code of getting the actual character
3174 // is too complex (e.g., when the string needs to be flattened).
3175 __ bind(&call_runtime_);
3176 call_helper.BeforeCall(masm);
3178 __ Push(object_, index_);
3179 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3180 __ Move(result_, r3);
3181 call_helper.AfterCall(masm);
3184 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3188 // -------------------------------------------------------------------------
3189 // StringCharFromCodeGenerator
3191 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3192 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3193 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCode + 1));
3194 __ LoadSmiLiteral(r0, Smi::FromInt(~String::kMaxOneByteCharCode));
3195 __ ori(r0, r0, Operand(kSmiTagMask));
3196 __ and_(r0, code_, r0);
3197 __ cmpi(r0, Operand::Zero());
3198 __ bne(&slow_case_);
3200 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3201 // At this point code register contains smi tagged one-byte char code.
3203 __ SmiToPtrArrayOffset(code_, code_);
3204 __ add(result_, result_, code_);
3206 __ LoadP(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3207 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
3208 __ beq(&slow_case_);
3213 void StringCharFromCodeGenerator::GenerateSlow(
3214 MacroAssembler* masm, const RuntimeCallHelper& call_helper) {
3215 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3217 __ bind(&slow_case_);
3218 call_helper.BeforeCall(masm);
3220 __ CallRuntime(Runtime::kCharFromCode, 1);
3221 __ Move(result_, r3);
3222 call_helper.AfterCall(masm);
3225 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3229 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3232 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, Register dest,
3233 Register src, Register count,
3235 String::Encoding encoding) {
3236 if (FLAG_debug_code) {
3237 // Check that destination is word aligned.
3238 __ andi(r0, dest, Operand(kPointerAlignmentMask));
3239 __ Check(eq, kDestinationOfCopyNotAligned, cr0);
3242 // Nothing to do for zero characters.
3244 if (encoding == String::TWO_BYTE_ENCODING) {
3245 // double the length
3246 __ add(count, count, count, LeaveOE, SetRC);
3249 __ cmpi(count, Operand::Zero());
3253 // Copy count bytes from src to dst.
3256 __ bind(&byte_loop);
3257 __ lbz(scratch, MemOperand(src));
3258 __ addi(src, src, Operand(1));
3259 __ stb(scratch, MemOperand(dest));
3260 __ addi(dest, dest, Operand(1));
3261 __ bdnz(&byte_loop);
3267 void SubStringStub::Generate(MacroAssembler* masm) {
3270 // Stack frame on entry.
3271 // lr: return address
3276 // This stub is called from the native-call %_SubString(...), so
3277 // nothing can be assumed about the arguments. It is tested that:
3278 // "string" is a sequential string,
3279 // both "from" and "to" are smis, and
3280 // 0 <= from <= to <= string.length.
3281 // If any of these assumptions fail, we call the runtime system.
3283 const int kToOffset = 0 * kPointerSize;
3284 const int kFromOffset = 1 * kPointerSize;
3285 const int kStringOffset = 2 * kPointerSize;
3287 __ LoadP(r5, MemOperand(sp, kToOffset));
3288 __ LoadP(r6, MemOperand(sp, kFromOffset));
3290 // If either to or from had the smi tag bit set, then fail to generic runtime
3291 __ JumpIfNotSmi(r5, &runtime);
3292 __ JumpIfNotSmi(r6, &runtime);
3294 __ SmiUntag(r6, SetRC);
3295 // Both r5 and r6 are untagged integers.
3297 // We want to bailout to runtime here if From is negative.
3298 __ blt(&runtime, cr0); // From < 0.
3301 __ bgt(&runtime); // Fail if from > to.
3304 // Make sure first argument is a string.
3305 __ LoadP(r3, MemOperand(sp, kStringOffset));
3306 __ JumpIfSmi(r3, &runtime);
3307 Condition is_string = masm->IsObjectStringType(r3, r4);
3308 __ b(NegateCondition(is_string), &runtime, cr0);
3311 __ cmpi(r5, Operand(1));
3312 __ b(eq, &single_char);
3314 // Short-cut for the case of trivial substring.
3316 // r3: original string
3317 // r5: result string length
3318 __ LoadP(r7, FieldMemOperand(r3, String::kLengthOffset));
3319 __ SmiUntag(r0, r7);
3321 // Return original string.
3323 // Longer than original string's length or negative: unsafe arguments.
3325 // Shorter than original string's length: an actual substring.
3327 // Deal with different string types: update the index if necessary
3328 // and put the underlying string into r8.
3329 // r3: original string
3330 // r4: instance type
3332 // r6: from index (untagged)
3333 Label underlying_unpacked, sliced_string, seq_or_external_string;
3334 // If the string is not indirect, it can only be sequential or external.
3335 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3336 STATIC_ASSERT(kIsIndirectStringMask != 0);
3337 __ andi(r0, r4, Operand(kIsIndirectStringMask));
3338 __ beq(&seq_or_external_string, cr0);
3340 __ andi(r0, r4, Operand(kSlicedNotConsMask));
3341 __ bne(&sliced_string, cr0);
3342 // Cons string. Check whether it is flat, then fetch first part.
3343 __ LoadP(r8, FieldMemOperand(r3, ConsString::kSecondOffset));
3344 __ CompareRoot(r8, Heap::kempty_stringRootIndex);
3346 __ LoadP(r8, FieldMemOperand(r3, ConsString::kFirstOffset));
3347 // Update instance type.
3348 __ LoadP(r4, FieldMemOperand(r8, HeapObject::kMapOffset));
3349 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
3350 __ b(&underlying_unpacked);
3352 __ bind(&sliced_string);
3353 // Sliced string. Fetch parent and correct start index by offset.
3354 __ LoadP(r8, FieldMemOperand(r3, SlicedString::kParentOffset));
3355 __ LoadP(r7, FieldMemOperand(r3, SlicedString::kOffsetOffset));
3356 __ SmiUntag(r4, r7);
3357 __ add(r6, r6, r4); // Add offset to index.
3358 // Update instance type.
3359 __ LoadP(r4, FieldMemOperand(r8, HeapObject::kMapOffset));
3360 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
3361 __ b(&underlying_unpacked);
3363 __ bind(&seq_or_external_string);
3364 // Sequential or external string. Just move string to the expected register.
3367 __ bind(&underlying_unpacked);
3369 if (FLAG_string_slices) {
3371 // r8: underlying subject string
3372 // r4: instance type of underlying subject string
3374 // r6: adjusted start index (untagged)
3375 __ cmpi(r5, Operand(SlicedString::kMinLength));
3376 // Short slice. Copy instead of slicing.
3377 __ blt(©_routine);
3378 // Allocate new sliced string. At this point we do not reload the instance
3379 // type including the string encoding because we simply rely on the info
3380 // provided by the original string. It does not matter if the original
3381 // string's encoding is wrong because we always have to recheck encoding of
3382 // the newly created string's parent anyways due to externalized strings.
3383 Label two_byte_slice, set_slice_header;
3384 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3385 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3386 __ andi(r0, r4, Operand(kStringEncodingMask));
3387 __ beq(&two_byte_slice, cr0);
3388 __ AllocateOneByteSlicedString(r3, r5, r9, r10, &runtime);
3389 __ b(&set_slice_header);
3390 __ bind(&two_byte_slice);
3391 __ AllocateTwoByteSlicedString(r3, r5, r9, r10, &runtime);
3392 __ bind(&set_slice_header);
3394 __ StoreP(r8, FieldMemOperand(r3, SlicedString::kParentOffset), r0);
3395 __ StoreP(r6, FieldMemOperand(r3, SlicedString::kOffsetOffset), r0);
3398 __ bind(©_routine);
3401 // r8: underlying subject string
3402 // r4: instance type of underlying subject string
3404 // r6: adjusted start index (untagged)
3405 Label two_byte_sequential, sequential_string, allocate_result;
3406 STATIC_ASSERT(kExternalStringTag != 0);
3407 STATIC_ASSERT(kSeqStringTag == 0);
3408 __ andi(r0, r4, Operand(kExternalStringTag));
3409 __ beq(&sequential_string, cr0);
3411 // Handle external string.
3412 // Rule out short external strings.
3413 STATIC_ASSERT(kShortExternalStringTag != 0);
3414 __ andi(r0, r4, Operand(kShortExternalStringTag));
3415 __ bne(&runtime, cr0);
3416 __ LoadP(r8, FieldMemOperand(r8, ExternalString::kResourceDataOffset));
3417 // r8 already points to the first character of underlying string.
3418 __ b(&allocate_result);
3420 __ bind(&sequential_string);
3421 // Locate first character of underlying subject string.
3422 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3423 __ addi(r8, r8, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3425 __ bind(&allocate_result);
3426 // Sequential acii string. Allocate the result.
3427 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3428 __ andi(r0, r4, Operand(kStringEncodingMask));
3429 __ beq(&two_byte_sequential, cr0);
3431 // Allocate and copy the resulting one-byte string.
3432 __ AllocateOneByteString(r3, r5, r7, r9, r10, &runtime);
3434 // Locate first character of substring to copy.
3436 // Locate first character of result.
3437 __ addi(r4, r3, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3439 // r3: result string
3440 // r4: first character of result string
3441 // r5: result string length
3442 // r8: first character of substring to copy
3443 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3444 StringHelper::GenerateCopyCharacters(masm, r4, r8, r5, r6,
3445 String::ONE_BYTE_ENCODING);
3448 // Allocate and copy the resulting two-byte string.
3449 __ bind(&two_byte_sequential);
3450 __ AllocateTwoByteString(r3, r5, r7, r9, r10, &runtime);
3452 // Locate first character of substring to copy.
3453 __ ShiftLeftImm(r4, r6, Operand(1));
3455 // Locate first character of result.
3456 __ addi(r4, r3, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3458 // r3: result string.
3459 // r4: first character of result.
3460 // r5: result length.
3461 // r8: first character of substring to copy.
3462 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3463 StringHelper::GenerateCopyCharacters(masm, r4, r8, r5, r6,
3464 String::TWO_BYTE_ENCODING);
3466 __ bind(&return_r3);
3467 Counters* counters = isolate()->counters();
3468 __ IncrementCounter(counters->sub_string_native(), 1, r6, r7);
3472 // Just jump to runtime to create the sub string.
3474 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3476 __ bind(&single_char);
3477 // r3: original string
3478 // r4: instance type
3480 // r6: from index (untagged)
3482 StringCharAtGenerator generator(r3, r6, r5, r3, &runtime, &runtime, &runtime,
3483 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3484 generator.GenerateFast(masm);
3487 generator.SkipSlow(masm, &runtime);
3491 void ToNumberStub::Generate(MacroAssembler* masm) {
3492 // The ToNumber stub takes one argument in r3.
3494 __ JumpIfNotSmi(r3, ¬_smi);
3498 Label not_heap_number;
3499 __ LoadP(r4, FieldMemOperand(r3, HeapObject::kMapOffset));
3500 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
3502 // r4: instance type.
3503 __ cmpi(r4, Operand(HEAP_NUMBER_TYPE));
3504 __ bne(¬_heap_number);
3506 __ bind(¬_heap_number);
3508 Label not_string, slow_string;
3509 __ cmpli(r4, Operand(FIRST_NONSTRING_TYPE));
3510 __ bge(¬_string);
3511 // Check if string has a cached array index.
3512 __ lwz(r5, FieldMemOperand(r3, String::kHashFieldOffset));
3513 __ And(r0, r5, Operand(String::kContainsCachedArrayIndexMask), SetRC);
3514 __ bne(&slow_string, cr0);
3515 __ IndexFromHash(r5, r3);
3517 __ bind(&slow_string);
3518 __ push(r3); // Push argument.
3519 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3520 __ bind(¬_string);
3523 __ cmpi(r4, Operand(ODDBALL_TYPE));
3524 __ bne(¬_oddball);
3525 __ LoadP(r3, FieldMemOperand(r3, Oddball::kToNumberOffset));
3527 __ bind(¬_oddball);
3529 __ push(r3); // Push argument.
3530 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3534 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
3538 Register scratch2) {
3539 Register length = scratch1;
3542 Label strings_not_equal, check_zero_length;
3543 __ LoadP(length, FieldMemOperand(left, String::kLengthOffset));
3544 __ LoadP(scratch2, FieldMemOperand(right, String::kLengthOffset));
3545 __ cmp(length, scratch2);
3546 __ beq(&check_zero_length);
3547 __ bind(&strings_not_equal);
3548 __ LoadSmiLiteral(r3, Smi::FromInt(NOT_EQUAL));
3551 // Check if the length is zero.
3552 Label compare_chars;
3553 __ bind(&check_zero_length);
3554 STATIC_ASSERT(kSmiTag == 0);
3555 __ cmpi(length, Operand::Zero());
3556 __ bne(&compare_chars);
3557 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3560 // Compare characters.
3561 __ bind(&compare_chars);
3562 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2,
3563 &strings_not_equal);
3565 // Characters are equal.
3566 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3571 void StringHelper::GenerateCompareFlatOneByteStrings(
3572 MacroAssembler* masm, Register left, Register right, Register scratch1,
3573 Register scratch2, Register scratch3) {
3574 Label result_not_equal, compare_lengths;
3575 // Find minimum length and length difference.
3576 __ LoadP(scratch1, FieldMemOperand(left, String::kLengthOffset));
3577 __ LoadP(scratch2, FieldMemOperand(right, String::kLengthOffset));
3578 __ sub(scratch3, scratch1, scratch2, LeaveOE, SetRC);
3579 Register length_delta = scratch3;
3580 if (CpuFeatures::IsSupported(ISELECT)) {
3581 __ isel(gt, scratch1, scratch2, scratch1, cr0);
3585 __ mr(scratch1, scratch2);
3588 Register min_length = scratch1;
3589 STATIC_ASSERT(kSmiTag == 0);
3590 __ cmpi(min_length, Operand::Zero());
3591 __ beq(&compare_lengths);
3594 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3597 // Compare lengths - strings up to min-length are equal.
3598 __ bind(&compare_lengths);
3599 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3600 // Use length_delta as result if it's zero.
3601 __ mr(r3, length_delta);
3602 __ cmpi(r3, Operand::Zero());
3603 __ bind(&result_not_equal);
3604 // Conditionally update the result based either on length_delta or
3605 // the last comparion performed in the loop above.
3606 if (CpuFeatures::IsSupported(ISELECT)) {
3607 __ LoadSmiLiteral(r4, Smi::FromInt(GREATER));
3608 __ LoadSmiLiteral(r5, Smi::FromInt(LESS));
3609 __ isel(eq, r3, r0, r4);
3610 __ isel(lt, r3, r5, r3);
3613 Label less_equal, equal;
3614 __ ble(&less_equal);
3615 __ LoadSmiLiteral(r3, Smi::FromInt(GREATER));
3617 __ bind(&less_equal);
3619 __ LoadSmiLiteral(r3, Smi::FromInt(LESS));
3626 void StringHelper::GenerateOneByteCharsCompareLoop(
3627 MacroAssembler* masm, Register left, Register right, Register length,
3628 Register scratch1, Label* chars_not_equal) {
3629 // Change index to run from -length to -1 by adding length to string
3630 // start. This means that loop ends when index reaches zero, which
3631 // doesn't need an additional compare.
3632 __ SmiUntag(length);
3633 __ addi(scratch1, length,
3634 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3635 __ add(left, left, scratch1);
3636 __ add(right, right, scratch1);
3637 __ subfic(length, length, Operand::Zero());
3638 Register index = length; // index = -length;
3643 __ lbzx(scratch1, MemOperand(left, index));
3644 __ lbzx(r0, MemOperand(right, index));
3645 __ cmp(scratch1, r0);
3646 __ bne(chars_not_equal);
3647 __ addi(index, index, Operand(1));
3648 __ cmpi(index, Operand::Zero());
3653 void StringCompareStub::Generate(MacroAssembler* masm) {
3656 Counters* counters = isolate()->counters();
3658 // Stack frame on entry.
3659 // sp[0]: right string
3660 // sp[4]: left string
3661 __ LoadP(r3, MemOperand(sp)); // Load right in r3, left in r4.
3662 __ LoadP(r4, MemOperand(sp, kPointerSize));
3667 STATIC_ASSERT(EQUAL == 0);
3668 STATIC_ASSERT(kSmiTag == 0);
3669 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3670 __ IncrementCounter(counters->string_compare_native(), 1, r4, r5);
3671 __ addi(sp, sp, Operand(2 * kPointerSize));
3676 // Check that both objects are sequential one-byte strings.
3677 __ JumpIfNotBothSequentialOneByteStrings(r4, r3, r5, r6, &runtime);
3679 // Compare flat one-byte strings natively. Remove arguments from stack first.
3680 __ IncrementCounter(counters->string_compare_native(), 1, r5, r6);
3681 __ addi(sp, sp, Operand(2 * kPointerSize));
3682 StringHelper::GenerateCompareFlatOneByteStrings(masm, r4, r3, r5, r6, r7);
3684 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3685 // tagged as a small integer.
3687 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3691 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3692 // ----------- S t a t e -------------
3695 // -- lr : return address
3696 // -----------------------------------
3698 // Load r5 with the allocation site. We stick an undefined dummy value here
3699 // and replace it with the real allocation site later when we instantiate this
3700 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3701 __ Move(r5, handle(isolate()->heap()->undefined_value()));
3703 // Make sure that we actually patched the allocation site.
3704 if (FLAG_debug_code) {
3705 __ TestIfSmi(r5, r0);
3706 __ Assert(ne, kExpectedAllocationSite, cr0);
3708 __ LoadP(r5, FieldMemOperand(r5, HeapObject::kMapOffset));
3709 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3712 __ Assert(eq, kExpectedAllocationSite);
3715 // Tail call into the stub that handles binary operations with allocation
3717 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3718 __ TailCallStub(&stub);
3722 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3723 DCHECK(state() == CompareICState::SMI);
3726 __ JumpIfNotSmi(r5, &miss);
3728 if (GetCondition() == eq) {
3729 // For equality we do not care about the sign of the result.
3730 // __ sub(r3, r3, r4, SetCC);
3733 // Untag before subtracting to avoid handling overflow.
3745 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3746 DCHECK(state() == CompareICState::NUMBER);
3749 Label unordered, maybe_undefined1, maybe_undefined2;
3751 Label equal, less_than;
3753 if (left() == CompareICState::SMI) {
3754 __ JumpIfNotSmi(r4, &miss);
3756 if (right() == CompareICState::SMI) {
3757 __ JumpIfNotSmi(r3, &miss);
3760 // Inlining the double comparison and falling back to the general compare
3761 // stub if NaN is involved.
3762 // Load left and right operand.
3763 Label done, left, left_smi, right_smi;
3764 __ JumpIfSmi(r3, &right_smi);
3765 __ CheckMap(r3, r5, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3767 __ lfd(d1, FieldMemOperand(r3, HeapNumber::kValueOffset));
3769 __ bind(&right_smi);
3770 __ SmiToDouble(d1, r3);
3773 __ JumpIfSmi(r4, &left_smi);
3774 __ CheckMap(r4, r5, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3776 __ lfd(d0, FieldMemOperand(r4, HeapNumber::kValueOffset));
3779 __ SmiToDouble(d0, r4);
3786 // Don't base result on status bits when a NaN is involved.
3787 __ bunordered(&unordered);
3789 // Return a result of -1, 0, or 1, based on status bits.
3790 if (CpuFeatures::IsSupported(ISELECT)) {
3792 __ li(r4, Operand(GREATER));
3793 __ li(r5, Operand(LESS));
3794 __ isel(eq, r3, r0, r4);
3795 __ isel(lt, r3, r5, r3);
3800 // assume greater than
3801 __ li(r3, Operand(GREATER));
3804 __ li(r3, Operand(EQUAL));
3806 __ bind(&less_than);
3807 __ li(r3, Operand(LESS));
3811 __ bind(&unordered);
3812 __ bind(&generic_stub);
3813 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3814 CompareICState::GENERIC, CompareICState::GENERIC);
3815 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3817 __ bind(&maybe_undefined1);
3818 if (Token::IsOrderedRelationalCompareOp(op())) {
3819 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
3821 __ JumpIfSmi(r4, &unordered);
3822 __ CompareObjectType(r4, r5, r5, HEAP_NUMBER_TYPE);
3823 __ bne(&maybe_undefined2);
3827 __ bind(&maybe_undefined2);
3828 if (Token::IsOrderedRelationalCompareOp(op())) {
3829 __ CompareRoot(r4, Heap::kUndefinedValueRootIndex);
3838 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3839 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3840 Label miss, not_equal;
3842 // Registers containing left and right operands respectively.
3844 Register right = r3;
3848 // Check that both operands are heap objects.
3849 __ JumpIfEitherSmi(left, right, &miss);
3851 // Check that both operands are symbols.
3852 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3853 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3854 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3855 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3856 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3857 __ orx(tmp1, tmp1, tmp2);
3858 __ andi(r0, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3861 // Internalized strings are compared by identity.
3862 __ cmp(left, right);
3864 // Make sure r3 is non-zero. At this point input operands are
3865 // guaranteed to be non-zero.
3866 DCHECK(right.is(r3));
3867 STATIC_ASSERT(EQUAL == 0);
3868 STATIC_ASSERT(kSmiTag == 0);
3869 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3870 __ bind(¬_equal);
3878 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3879 DCHECK(state() == CompareICState::UNIQUE_NAME);
3880 DCHECK(GetCondition() == eq);
3883 // Registers containing left and right operands respectively.
3885 Register right = r3;
3889 // Check that both operands are heap objects.
3890 __ JumpIfEitherSmi(left, right, &miss);
3892 // Check that both operands are unique names. This leaves the instance
3893 // types loaded in tmp1 and tmp2.
3894 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3895 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3896 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3897 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3899 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3900 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3902 // Unique names are compared by identity.
3903 __ cmp(left, right);
3905 // Make sure r3 is non-zero. At this point input operands are
3906 // guaranteed to be non-zero.
3907 DCHECK(right.is(r3));
3908 STATIC_ASSERT(EQUAL == 0);
3909 STATIC_ASSERT(kSmiTag == 0);
3910 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3918 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3919 DCHECK(state() == CompareICState::STRING);
3920 Label miss, not_identical, is_symbol;
3922 bool equality = Token::IsEqualityOp(op());
3924 // Registers containing left and right operands respectively.
3926 Register right = r3;
3932 // Check that both operands are heap objects.
3933 __ JumpIfEitherSmi(left, right, &miss);
3935 // Check that both operands are strings. This leaves the instance
3936 // types loaded in tmp1 and tmp2.
3937 __ LoadP(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3938 __ LoadP(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3939 __ lbz(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3940 __ lbz(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3941 STATIC_ASSERT(kNotStringTag != 0);
3942 __ orx(tmp3, tmp1, tmp2);
3943 __ andi(r0, tmp3, Operand(kIsNotStringMask));
3946 // Fast check for identical strings.
3947 __ cmp(left, right);
3948 STATIC_ASSERT(EQUAL == 0);
3949 STATIC_ASSERT(kSmiTag == 0);
3950 __ bne(¬_identical);
3951 __ LoadSmiLiteral(r3, Smi::FromInt(EQUAL));
3953 __ bind(¬_identical);
3955 // Handle not identical strings.
3957 // Check that both strings are internalized strings. If they are, we're done
3958 // because we already know they are not identical. We know they are both
3961 DCHECK(GetCondition() == eq);
3962 STATIC_ASSERT(kInternalizedTag == 0);
3963 __ orx(tmp3, tmp1, tmp2);
3964 __ andi(r0, tmp3, Operand(kIsNotInternalizedMask));
3965 __ bne(&is_symbol, cr0);
3966 // Make sure r3 is non-zero. At this point input operands are
3967 // guaranteed to be non-zero.
3968 DCHECK(right.is(r3));
3970 __ bind(&is_symbol);
3973 // Check that both strings are sequential one-byte.
3975 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3978 // Compare flat one-byte strings. Returns when done.
3980 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1,
3983 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3987 // Handle more complex cases in runtime.
3989 __ Push(left, right);
3991 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3993 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
4001 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
4002 DCHECK(state() == CompareICState::OBJECT);
4004 __ and_(r5, r4, r3);
4005 __ JumpIfSmi(r5, &miss);
4007 __ CompareObjectType(r3, r5, r5, JS_OBJECT_TYPE);
4009 __ CompareObjectType(r4, r5, r5, JS_OBJECT_TYPE);
4012 DCHECK(GetCondition() == eq);
4021 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
4023 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
4024 __ and_(r5, r4, r3);
4025 __ JumpIfSmi(r5, &miss);
4026 __ GetWeakValue(r7, cell);
4027 __ LoadP(r5, FieldMemOperand(r3, HeapObject::kMapOffset));
4028 __ LoadP(r6, FieldMemOperand(r4, HeapObject::kMapOffset));
4042 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
4044 // Call the runtime system in a fresh internal frame.
4045 ExternalReference miss =
4046 ExternalReference(IC_Utility(IC::kCompareIC_Miss), isolate());
4048 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4051 __ LoadSmiLiteral(r0, Smi::FromInt(op()));
4053 __ CallExternalReference(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 element size.
4211 DCHECK(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 DCHECK(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 DCHECK(FAST_SMI_ELEMENTS == 0);
5040 DCHECK(FAST_HOLEY_SMI_ELEMENTS == 1);
5041 DCHECK(FAST_ELEMENTS == 2);
5042 DCHECK(FAST_HOLEY_ELEMENTS == 3);
5043 DCHECK(FAST_DOUBLE_ELEMENTS == 4);
5044 DCHECK(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 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5316 return ref0.address() - ref1.address();
5320 // Calls an API function. Allocates HandleScope, extracts returned value
5321 // from handle and propagates exceptions. Restores context. stack_space
5322 // - space to be unwound on exit (includes the call JS arguments space and
5323 // the additional space allocated for the fast call).
5324 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5325 Register function_address,
5326 ExternalReference thunk_ref,
5328 MemOperand* stack_space_operand,
5329 MemOperand return_value_operand,
5330 MemOperand* context_restore_operand) {
5331 Isolate* isolate = masm->isolate();
5332 ExternalReference next_address =
5333 ExternalReference::handle_scope_next_address(isolate);
5334 const int kNextOffset = 0;
5335 const int kLimitOffset = AddressOffset(
5336 ExternalReference::handle_scope_limit_address(isolate), next_address);
5337 const int kLevelOffset = AddressOffset(
5338 ExternalReference::handle_scope_level_address(isolate), next_address);
5340 // Additional parameter is the address of the actual callback.
5341 DCHECK(function_address.is(r4) || function_address.is(r5));
5342 Register scratch = r6;
5344 __ mov(scratch, Operand(ExternalReference::is_profiling_address(isolate)));
5345 __ lbz(scratch, MemOperand(scratch, 0));
5346 __ cmpi(scratch, Operand::Zero());
5348 if (CpuFeatures::IsSupported(ISELECT)) {
5349 __ mov(scratch, Operand(thunk_ref));
5350 __ isel(eq, scratch, function_address, scratch);
5352 Label profiler_disabled;
5353 Label end_profiler_check;
5354 __ beq(&profiler_disabled);
5355 __ mov(scratch, Operand(thunk_ref));
5356 __ b(&end_profiler_check);
5357 __ bind(&profiler_disabled);
5358 __ mr(scratch, function_address);
5359 __ bind(&end_profiler_check);
5362 // Allocate HandleScope in callee-save registers.
5363 // r17 - next_address
5364 // r14 - next_address->kNextOffset
5365 // r15 - next_address->kLimitOffset
5366 // r16 - next_address->kLevelOffset
5367 __ mov(r17, Operand(next_address));
5368 __ LoadP(r14, MemOperand(r17, kNextOffset));
5369 __ LoadP(r15, MemOperand(r17, kLimitOffset));
5370 __ lwz(r16, MemOperand(r17, kLevelOffset));
5371 __ addi(r16, r16, Operand(1));
5372 __ stw(r16, MemOperand(r17, kLevelOffset));
5374 if (FLAG_log_timer_events) {
5375 FrameScope frame(masm, StackFrame::MANUAL);
5376 __ PushSafepointRegisters();
5377 __ PrepareCallCFunction(1, r3);
5378 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5379 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5381 __ PopSafepointRegisters();
5384 // Native call returns to the DirectCEntry stub which redirects to the
5385 // return address pushed on stack (could have moved after GC).
5386 // DirectCEntry stub itself is generated early and never moves.
5387 DirectCEntryStub stub(isolate);
5388 stub.GenerateCall(masm, scratch);
5390 if (FLAG_log_timer_events) {
5391 FrameScope frame(masm, StackFrame::MANUAL);
5392 __ PushSafepointRegisters();
5393 __ PrepareCallCFunction(1, r3);
5394 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5395 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5397 __ PopSafepointRegisters();
5400 Label promote_scheduled_exception;
5401 Label delete_allocated_handles;
5402 Label leave_exit_frame;
5403 Label return_value_loaded;
5405 // load value from ReturnValue
5406 __ LoadP(r3, return_value_operand);
5407 __ bind(&return_value_loaded);
5408 // No more valid handles (the result handle was the last one). Restore
5409 // previous handle scope.
5410 __ StoreP(r14, MemOperand(r17, kNextOffset));
5411 if (__ emit_debug_code()) {
5412 __ lwz(r4, MemOperand(r17, kLevelOffset));
5414 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5416 __ subi(r16, r16, Operand(1));
5417 __ stw(r16, MemOperand(r17, kLevelOffset));
5418 __ LoadP(r0, MemOperand(r17, kLimitOffset));
5420 __ bne(&delete_allocated_handles);
5422 // Leave the API exit frame.
5423 __ bind(&leave_exit_frame);
5424 bool restore_context = context_restore_operand != NULL;
5425 if (restore_context) {
5426 __ LoadP(cp, *context_restore_operand);
5428 // LeaveExitFrame expects unwind space to be in a register.
5429 if (stack_space_operand != NULL) {
5430 __ lwz(r14, *stack_space_operand);
5432 __ mov(r14, Operand(stack_space));
5434 __ LeaveExitFrame(false, r14, !restore_context, stack_space_operand != NULL);
5436 // Check if the function scheduled an exception.
5437 __ LoadRoot(r14, Heap::kTheHoleValueRootIndex);
5438 __ mov(r15, Operand(ExternalReference::scheduled_exception_address(isolate)));
5439 __ LoadP(r15, MemOperand(r15));
5441 __ bne(&promote_scheduled_exception);
5445 // Re-throw by promoting a scheduled exception.
5446 __ bind(&promote_scheduled_exception);
5447 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5449 // HandleScope limit has changed. Delete allocated extensions.
5450 __ bind(&delete_allocated_handles);
5451 __ StoreP(r15, MemOperand(r17, kLimitOffset));
5453 __ PrepareCallCFunction(1, r15);
5454 __ mov(r3, Operand(ExternalReference::isolate_address(isolate)));
5455 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5458 __ b(&leave_exit_frame);
5462 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5463 const ParameterCount& argc,
5464 bool return_first_arg,
5465 bool call_data_undefined) {
5466 // ----------- S t a t e -------------
5468 // -- r7 : call_data
5470 // -- r4 : api_function_address
5471 // -- r6 : number of arguments if argc is a register
5474 // -- sp[0] : last argument
5476 // -- sp[(argc - 1)* 4] : first argument
5477 // -- sp[argc * 4] : receiver
5478 // -----------------------------------
5480 Register callee = r3;
5481 Register call_data = r7;
5482 Register holder = r5;
5483 Register api_function_address = r4;
5484 Register context = cp;
5486 typedef FunctionCallbackArguments FCA;
5488 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5489 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5490 STATIC_ASSERT(FCA::kDataIndex == 4);
5491 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5492 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5493 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5494 STATIC_ASSERT(FCA::kHolderIndex == 0);
5495 STATIC_ASSERT(FCA::kArgsLength == 7);
5497 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5501 // load context from callee
5502 __ LoadP(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5510 Register scratch = call_data;
5511 if (!call_data_undefined) {
5512 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5516 // return value default
5519 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5524 // Prepare arguments.
5527 // Allocate the v8::Arguments structure in the arguments' space since
5528 // it's not controlled by GC.
5531 // Create 5 extra slots on stack:
5532 // [0] space for DirectCEntryStub's LR save
5533 // [1-4] FunctionCallbackInfo
5534 const int kApiStackSpace = 5;
5535 const int kFunctionCallbackInfoOffset =
5536 (kStackFrameExtraParamSlot + 1) * kPointerSize;
5538 FrameScope frame_scope(masm, StackFrame::MANUAL);
5539 __ EnterExitFrame(false, kApiStackSpace);
5541 DCHECK(!api_function_address.is(r3) && !scratch.is(r3));
5542 // r3 = FunctionCallbackInfo&
5543 // Arguments is after the return address.
5544 __ addi(r3, sp, Operand(kFunctionCallbackInfoOffset));
5545 // FunctionCallbackInfo::implicit_args_
5546 __ StoreP(scratch, MemOperand(r3, 0 * kPointerSize));
5547 if (argc.is_immediate()) {
5548 // FunctionCallbackInfo::values_
5549 __ addi(ip, scratch,
5550 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5551 __ StoreP(ip, MemOperand(r3, 1 * kPointerSize));
5552 // FunctionCallbackInfo::length_ = argc
5553 __ li(ip, Operand(argc.immediate()));
5554 __ stw(ip, MemOperand(r3, 2 * kPointerSize));
5555 // FunctionCallbackInfo::is_construct_call_ = 0
5556 __ li(ip, Operand::Zero());
5557 __ stw(ip, MemOperand(r3, 2 * kPointerSize + kIntSize));
5559 __ ShiftLeftImm(ip, argc.reg(), Operand(kPointerSizeLog2));
5560 __ addi(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5561 // FunctionCallbackInfo::values_
5562 __ add(r0, scratch, ip);
5563 __ StoreP(r0, MemOperand(r3, 1 * kPointerSize));
5564 // FunctionCallbackInfo::length_ = argc
5565 __ stw(argc.reg(), MemOperand(r3, 2 * kPointerSize));
5566 // FunctionCallbackInfo::is_construct_call_
5567 __ stw(ip, MemOperand(r3, 2 * kPointerSize + kIntSize));
5570 ExternalReference thunk_ref =
5571 ExternalReference::invoke_function_callback(masm->isolate());
5573 AllowExternalCallThatCantCauseGC scope(masm);
5574 MemOperand context_restore_operand(
5575 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5576 // Stores return the first js argument
5577 int return_value_offset = 0;
5578 if (return_first_arg) {
5579 return_value_offset = 2 + FCA::kArgsLength;
5581 return_value_offset = 2 + FCA::kReturnValueOffset;
5583 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5584 int stack_space = 0;
5585 MemOperand is_construct_call_operand =
5586 MemOperand(sp, kFunctionCallbackInfoOffset + 2 * kPointerSize + kIntSize);
5587 MemOperand* stack_space_operand = &is_construct_call_operand;
5588 if (argc.is_immediate()) {
5589 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5590 stack_space_operand = NULL;
5592 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5593 stack_space_operand, return_value_operand,
5594 &context_restore_operand);
5598 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5599 bool call_data_undefined = this->call_data_undefined();
5600 CallApiFunctionStubHelper(masm, ParameterCount(r6), false,
5601 call_data_undefined);
5605 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5606 bool is_store = this->is_store();
5607 int argc = this->argc();
5608 bool call_data_undefined = this->call_data_undefined();
5609 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5610 call_data_undefined);
5614 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5615 // ----------- S t a t e -------------
5617 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5619 // -- r5 : api_function_address
5620 // -----------------------------------
5622 Register api_function_address = ApiGetterDescriptor::function_address();
5623 DCHECK(api_function_address.is(r5));
5625 __ mr(r3, sp); // r0 = Handle<Name>
5626 __ addi(r4, r3, Operand(1 * kPointerSize)); // r4 = PCA
5628 // If ABI passes Handles (pointer-sized struct) in a register:
5630 // Create 2 extra slots on stack:
5631 // [0] space for DirectCEntryStub's LR save
5632 // [1] AccessorInfo&
5636 // Create 3 extra slots on stack:
5637 // [0] space for DirectCEntryStub's LR save
5638 // [1] copy of Handle (first arg)
5639 // [2] AccessorInfo&
5640 #if ABI_PASSES_HANDLES_IN_REGS
5641 const int kAccessorInfoSlot = kStackFrameExtraParamSlot + 1;
5642 const int kApiStackSpace = 2;
5644 const int kArg0Slot = kStackFrameExtraParamSlot + 1;
5645 const int kAccessorInfoSlot = kArg0Slot + 1;
5646 const int kApiStackSpace = 3;
5649 FrameScope frame_scope(masm, StackFrame::MANUAL);
5650 __ EnterExitFrame(false, kApiStackSpace);
5652 #if !ABI_PASSES_HANDLES_IN_REGS
5653 // pass 1st arg by reference
5654 __ StoreP(r3, MemOperand(sp, kArg0Slot * kPointerSize));
5655 __ addi(r3, sp, Operand(kArg0Slot * kPointerSize));
5658 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5659 // r4 (internal::Object** args_) as the data.
5660 __ StoreP(r4, MemOperand(sp, kAccessorInfoSlot * kPointerSize));
5661 // r4 = AccessorInfo&
5662 __ addi(r4, sp, Operand(kAccessorInfoSlot * kPointerSize));
5664 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5666 ExternalReference thunk_ref =
5667 ExternalReference::invoke_accessor_getter_callback(isolate());
5668 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5669 kStackUnwindSpace, NULL,
5670 MemOperand(fp, 6 * kPointerSize), NULL);
5675 } // namespace internal
5678 #endif // V8_TARGET_ARCH_PPC