1 // Copyright 2012 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.
7 #include "src/base/bits.h"
8 #include "src/bootstrapper.h"
9 #include "src/code-stubs.h"
10 #include "src/codegen.h"
11 #include "src/ic/handler-compiler.h"
12 #include "src/ic/ic.h"
13 #include "src/ic/stub-cache.h"
14 #include "src/isolate.h"
15 #include "src/regexp/jsregexp.h"
16 #include "src/regexp/regexp-macro-assembler.h"
17 #include "src/runtime/runtime.h"
19 #include "src/arm/code-stubs-arm.h"
25 static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
28 Address deopt_handler = Runtime::FunctionForId(
29 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(r0, deopt_handler, constant_stack_parameter_count,
36 JS_FUNCTION_STUB_MODE);
41 static void InitializeInternalArrayConstructorDescriptor(
42 Isolate* isolate, CodeStubDescriptor* descriptor,
43 int constant_stack_parameter_count) {
44 Address deopt_handler = Runtime::FunctionForId(
45 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(r0, deopt_handler, constant_stack_parameter_count,
52 JS_FUNCTION_STUB_MODE);
57 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
63 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
64 CodeStubDescriptor* descriptor) {
65 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
69 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
70 CodeStubDescriptor* descriptor) {
71 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
75 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
76 CodeStubDescriptor* descriptor) {
77 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
81 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
82 CodeStubDescriptor* descriptor) {
83 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
87 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
88 CodeStubDescriptor* descriptor) {
89 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
93 #define __ ACCESS_MASM(masm)
96 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
97 Condition cond, Strength strength);
98 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
104 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
109 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
110 ExternalReference miss) {
111 // Update the static counter each time a new code stub is generated.
112 isolate()->counters()->code_stubs()->Increment();
114 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
115 int param_count = descriptor.GetRegisterParameterCount();
117 // Call the runtime system in a fresh internal frame.
118 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
119 DCHECK(param_count == 0 ||
120 r0.is(descriptor.GetRegisterParameter(param_count - 1)));
122 for (int i = 0; i < param_count; ++i) {
123 __ push(descriptor.GetRegisterParameter(i));
125 __ CallExternalReference(miss, param_count);
132 void DoubleToIStub::Generate(MacroAssembler* masm) {
133 Label out_of_range, only_low, negate, done;
134 Register input_reg = source();
135 Register result_reg = destination();
136 DCHECK(is_truncating());
138 int double_offset = offset();
139 // Account for saved regs if input is sp.
140 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
142 Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
143 Register scratch_low =
144 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
145 Register scratch_high =
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
147 LowDwVfpRegister double_scratch = kScratchDoubleReg;
149 __ Push(scratch_high, scratch_low, scratch);
151 if (!skip_fastpath()) {
152 // Load double input.
153 __ vldr(double_scratch, MemOperand(input_reg, double_offset));
154 __ vmov(scratch_low, scratch_high, double_scratch);
156 // Do fast-path convert from double to int.
157 __ vcvt_s32_f64(double_scratch.low(), double_scratch);
158 __ vmov(result_reg, double_scratch.low());
160 // If result is not saturated (0x7fffffff or 0x80000000), we are done.
161 __ sub(scratch, result_reg, Operand(1));
162 __ cmp(scratch, Operand(0x7ffffffe));
165 // We've already done MacroAssembler::TryFastTruncatedDoubleToILoad, so we
166 // know exponent > 31, so we can skip the vcvt_s32_f64 which will saturate.
167 if (double_offset == 0) {
168 __ ldm(ia, input_reg, scratch_low.bit() | scratch_high.bit());
170 __ ldr(scratch_low, MemOperand(input_reg, double_offset));
171 __ ldr(scratch_high, MemOperand(input_reg, double_offset + kIntSize));
175 __ Ubfx(scratch, scratch_high,
176 HeapNumber::kExponentShift, HeapNumber::kExponentBits);
177 // Load scratch with exponent - 1. This is faster than loading
178 // with exponent because Bias + 1 = 1024 which is an *ARM* immediate value.
179 STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
180 __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
181 // If exponent is greater than or equal to 84, the 32 less significant
182 // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
184 // Compare exponent with 84 (compare exponent - 1 with 83).
185 __ cmp(scratch, Operand(83));
186 __ b(ge, &out_of_range);
188 // If we reach this code, 31 <= exponent <= 83.
189 // So, we don't have to handle cases where 0 <= exponent <= 20 for
190 // which we would need to shift right the high part of the mantissa.
191 // Scratch contains exponent - 1.
192 // Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
193 __ rsb(scratch, scratch, Operand(51), SetCC);
195 // 21 <= exponent <= 51, shift scratch_low and scratch_high
196 // to generate the result.
197 __ mov(scratch_low, Operand(scratch_low, LSR, scratch));
198 // Scratch contains: 52 - exponent.
199 // We needs: exponent - 20.
200 // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
201 __ rsb(scratch, scratch, Operand(32));
202 __ Ubfx(result_reg, scratch_high,
203 0, HeapNumber::kMantissaBitsInTopWord);
204 // Set the implicit 1 before the mantissa part in scratch_high.
205 __ orr(result_reg, result_reg,
206 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
207 __ orr(result_reg, scratch_low, Operand(result_reg, LSL, scratch));
210 __ bind(&out_of_range);
211 __ mov(result_reg, Operand::Zero());
215 // 52 <= exponent <= 83, shift only scratch_low.
216 // On entry, scratch contains: 52 - exponent.
217 __ rsb(scratch, scratch, Operand::Zero());
218 __ mov(result_reg, Operand(scratch_low, LSL, scratch));
221 // If input was positive, scratch_high ASR 31 equals 0 and
222 // scratch_high LSR 31 equals zero.
223 // New result = (result eor 0) + 0 = result.
224 // If the input was negative, we have to negate the result.
225 // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
226 // New result = (result eor 0xffffffff) + 1 = 0 - result.
227 __ eor(result_reg, result_reg, Operand(scratch_high, ASR, 31));
228 __ add(result_reg, result_reg, Operand(scratch_high, LSR, 31));
232 __ Pop(scratch_high, scratch_low, scratch);
237 // Handle the case where the lhs and rhs are the same object.
238 // Equality is almost reflexive (everything but NaN), so this is a test
239 // for "identity and not NaN".
240 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
241 Condition cond, Strength strength) {
243 Label heap_number, return_equal;
245 __ b(ne, ¬_identical);
247 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
248 // so we do the second best thing - test it ourselves.
249 // They are both equal and they are not both Smis so both of them are not
250 // Smis. If it's not a heap number, then return equal.
251 if (cond == lt || cond == gt) {
252 // Call runtime on identical JSObjects.
253 __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE);
255 // Call runtime on identical symbols since we need to throw a TypeError.
256 __ cmp(r4, Operand(SYMBOL_TYPE));
258 // Call runtime on identical SIMD values since we must throw a TypeError.
259 __ cmp(r4, Operand(SIMD128_VALUE_TYPE));
261 if (is_strong(strength)) {
262 // Call the runtime on anything that is converted in the semantics, since
263 // we need to throw a TypeError. Smis have already been ruled out.
264 __ cmp(r4, Operand(HEAP_NUMBER_TYPE));
265 __ b(eq, &return_equal);
266 __ tst(r4, Operand(kIsNotStringMask));
270 __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE);
271 __ b(eq, &heap_number);
272 // Comparing JS objects with <=, >= is complicated.
274 __ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE));
276 // Call runtime on identical symbols since we need to throw a TypeError.
277 __ cmp(r4, Operand(SYMBOL_TYPE));
279 // Call runtime on identical SIMD values since we must throw a TypeError.
280 __ cmp(r4, Operand(SIMD128_VALUE_TYPE));
282 if (is_strong(strength)) {
283 // Call the runtime on anything that is converted in the semantics,
284 // since we need to throw a TypeError. Smis and heap numbers have
285 // already been ruled out.
286 __ tst(r4, Operand(kIsNotStringMask));
289 // Normally here we fall through to return_equal, but undefined is
290 // special: (undefined == undefined) == true, but
291 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
292 if (cond == le || cond == ge) {
293 __ cmp(r4, Operand(ODDBALL_TYPE));
294 __ b(ne, &return_equal);
295 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
297 __ b(ne, &return_equal);
299 // undefined <= undefined should fail.
300 __ mov(r0, Operand(GREATER));
302 // undefined >= undefined should fail.
303 __ mov(r0, Operand(LESS));
310 __ bind(&return_equal);
312 __ mov(r0, Operand(GREATER)); // Things aren't less than themselves.
313 } else if (cond == gt) {
314 __ mov(r0, Operand(LESS)); // Things aren't greater than themselves.
316 __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
320 // For less and greater we don't have to check for NaN since the result of
321 // x < x is false regardless. For the others here is some code to check
323 if (cond != lt && cond != gt) {
324 __ bind(&heap_number);
325 // It is a heap number, so return non-equal if it's NaN and equal if it's
328 // The representation of NaN values has all exponent bits (52..62) set,
329 // and not all mantissa bits (0..51) clear.
330 // Read top bits of double representation (second word of value).
331 __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
332 // Test that exponent bits are all set.
333 __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits);
334 // NaNs have all-one exponents so they sign extend to -1.
335 __ cmp(r3, Operand(-1));
336 __ b(ne, &return_equal);
338 // Shift out flag and all exponent bits, retaining only mantissa.
339 __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord));
340 // Or with all low-bits of mantissa.
341 __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
342 __ orr(r0, r3, Operand(r2), SetCC);
343 // For equal we already have the right value in r0: Return zero (equal)
344 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
345 // not (it's a NaN). For <= and >= we need to load r0 with the failing
346 // value if it's a NaN.
348 // All-zero means Infinity means equal.
351 __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail.
353 __ mov(r0, Operand(LESS)); // NaN >= NaN should fail.
358 // No fall through here.
360 __ bind(¬_identical);
364 // See comment at call site.
365 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
371 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
372 (lhs.is(r1) && rhs.is(r0)));
375 __ JumpIfSmi(rhs, &rhs_is_smi);
377 // Lhs is a Smi. Check whether the rhs is a heap number.
378 __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE);
380 // If rhs is not a number and lhs is a Smi then strict equality cannot
381 // succeed. Return non-equal
382 // If rhs is r0 then there is already a non zero value in it.
384 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
388 // Smi compared non-strictly with a non-Smi non-heap-number. Call
393 // Lhs is a smi, rhs is a number.
394 // Convert lhs to a double in d7.
395 __ SmiToDouble(d7, lhs);
396 // Load the double from rhs, tagged HeapNumber r0, to d6.
397 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
399 // We now have both loaded as doubles but we can skip the lhs nan check
403 __ bind(&rhs_is_smi);
404 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
405 __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE);
407 // If lhs is not a number and rhs is a smi then strict equality cannot
408 // succeed. Return non-equal.
409 // If lhs is r0 then there is already a non zero value in it.
411 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
415 // Smi compared non-strictly with a non-smi non-heap-number. Call
420 // Rhs is a smi, lhs is a heap number.
421 // Load the double from lhs, tagged HeapNumber r1, to d7.
422 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
423 // Convert rhs to a double in d6 .
424 __ SmiToDouble(d6, rhs);
425 // Fall through to both_loaded_as_doubles.
429 // See comment at call site.
430 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
433 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
434 (lhs.is(r1) && rhs.is(r0)));
436 // If either operand is a JS object or an oddball value, then they are
437 // not equal since their pointers are different.
438 // There is no test for undetectability in strict equality.
439 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
440 Label first_non_object;
441 // Get the type of the first operand into r2 and compare it with
442 // FIRST_SPEC_OBJECT_TYPE.
443 __ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE);
444 __ b(lt, &first_non_object);
446 // Return non-zero (r0 is not zero)
447 Label return_not_equal;
448 __ bind(&return_not_equal);
451 __ bind(&first_non_object);
452 // Check for oddballs: true, false, null, undefined.
453 __ cmp(r2, Operand(ODDBALL_TYPE));
454 __ b(eq, &return_not_equal);
456 __ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE);
457 __ b(ge, &return_not_equal);
459 // Check for oddballs: true, false, null, undefined.
460 __ cmp(r3, Operand(ODDBALL_TYPE));
461 __ b(eq, &return_not_equal);
463 // Now that we have the types we might as well check for
464 // internalized-internalized.
465 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
466 __ orr(r2, r2, Operand(r3));
467 __ tst(r2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
468 __ b(eq, &return_not_equal);
472 // See comment at call site.
473 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
476 Label* both_loaded_as_doubles,
477 Label* not_heap_numbers,
479 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
480 (lhs.is(r1) && rhs.is(r0)));
482 __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE);
483 __ b(ne, not_heap_numbers);
484 __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset));
486 __ b(ne, slow); // First was a heap number, second wasn't. Go slow case.
488 // Both are heap numbers. Load them up then jump to the code we have
490 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
491 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
492 __ jmp(both_loaded_as_doubles);
496 // Fast negative check for internalized-to-internalized equality.
497 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
500 Label* possible_strings,
501 Label* not_both_strings) {
502 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
503 (lhs.is(r1) && rhs.is(r0)));
505 // r2 is object type of rhs.
507 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
508 __ tst(r2, Operand(kIsNotStringMask));
509 __ b(ne, &object_test);
510 __ tst(r2, Operand(kIsNotInternalizedMask));
511 __ b(ne, possible_strings);
512 __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE);
513 __ b(ge, not_both_strings);
514 __ tst(r3, Operand(kIsNotInternalizedMask));
515 __ b(ne, possible_strings);
517 // Both are internalized. We already checked they weren't the same pointer
518 // so they are not equal.
519 __ mov(r0, Operand(NOT_EQUAL));
522 __ bind(&object_test);
523 __ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE));
524 __ b(lt, not_both_strings);
525 __ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE);
526 __ b(lt, not_both_strings);
527 // If both objects are undetectable, they are equal. Otherwise, they
528 // are not equal, since they are different objects and an object is not
529 // equal to undefined.
530 __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset));
531 __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset));
532 __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset));
533 __ and_(r0, r2, Operand(r3));
534 __ and_(r0, r0, Operand(1 << Map::kIsUndetectable));
535 __ eor(r0, r0, Operand(1 << Map::kIsUndetectable));
540 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
542 CompareICState::State expected,
545 if (expected == CompareICState::SMI) {
546 __ JumpIfNotSmi(input, fail);
547 } else if (expected == CompareICState::NUMBER) {
548 __ JumpIfSmi(input, &ok);
549 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
552 // We could be strict about internalized/non-internalized here, but as long as
553 // hydrogen doesn't care, the stub doesn't have to care either.
558 // On entry r1 and r2 are the values to be compared.
559 // On exit r0 is 0, positive or negative to indicate the result of
561 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
564 Condition cc = GetCondition();
567 CompareICStub_CheckInputType(masm, lhs, r2, left(), &miss);
568 CompareICStub_CheckInputType(masm, rhs, r3, right(), &miss);
570 Label slow; // Call builtin.
571 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
573 Label not_two_smis, smi_done;
575 __ JumpIfNotSmi(r2, ¬_two_smis);
576 __ mov(r1, Operand(r1, ASR, 1));
577 __ sub(r0, r1, Operand(r0, ASR, 1));
579 __ bind(¬_two_smis);
581 // NOTICE! This code is only reached after a smi-fast-case check, so
582 // it is certain that at least one operand isn't a smi.
584 // Handle the case where the objects are identical. Either returns the answer
585 // or goes to slow. Only falls through if the objects were not identical.
586 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
588 // If either is a Smi (we know that not both are), then they can only
589 // be strictly equal if the other is a HeapNumber.
590 STATIC_ASSERT(kSmiTag == 0);
591 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
592 __ and_(r2, lhs, Operand(rhs));
593 __ JumpIfNotSmi(r2, ¬_smis);
594 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
595 // 1) Return the answer.
597 // 3) Fall through to both_loaded_as_doubles.
598 // 4) Jump to lhs_not_nan.
599 // In cases 3 and 4 we have found out we were dealing with a number-number
600 // comparison. If VFP3 is supported the double values of the numbers have
601 // been loaded into d7 and d6. Otherwise, the double values have been loaded
602 // into r0, r1, r2, and r3.
603 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
605 __ bind(&both_loaded_as_doubles);
606 // The arguments have been converted to doubles and stored in d6 and d7, if
607 // VFP3 is supported, or in r0, r1, r2, and r3.
608 __ bind(&lhs_not_nan);
610 // ARMv7 VFP3 instructions to implement double precision comparison.
611 __ VFPCompareAndSetFlags(d7, d6);
614 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
615 __ mov(r0, Operand(LESS), LeaveCC, lt);
616 __ mov(r0, Operand(GREATER), LeaveCC, gt);
620 // If one of the sides was a NaN then the v flag is set. Load r0 with
621 // whatever it takes to make the comparison fail, since comparisons with NaN
623 if (cc == lt || cc == le) {
624 __ mov(r0, Operand(GREATER));
626 __ mov(r0, Operand(LESS));
631 // At this point we know we are dealing with two different objects,
632 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
634 // This returns non-equal for some object types, or falls through if it
636 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
639 Label check_for_internalized_strings;
640 Label flat_string_check;
641 // Check for heap-number-heap-number comparison. Can jump to slow case,
642 // or load both doubles into r0, r1, r2, r3 and jump to the code that handles
643 // that case. If the inputs are not doubles then jumps to
644 // check_for_internalized_strings.
645 // In this case r2 will contain the type of rhs_. Never falls through.
646 EmitCheckForTwoHeapNumbers(masm,
649 &both_loaded_as_doubles,
650 &check_for_internalized_strings,
653 __ bind(&check_for_internalized_strings);
654 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
655 // internalized strings.
656 if (cc == eq && !strict()) {
657 // Returns an answer for two internalized strings or two detectable objects.
658 // Otherwise jumps to string case or not both strings case.
659 // Assumes that r2 is the type of rhs_ on entry.
660 EmitCheckForInternalizedStringsOrObjects(
661 masm, lhs, rhs, &flat_string_check, &slow);
664 // Check for both being sequential one-byte strings,
665 // and inline if that is the case.
666 __ bind(&flat_string_check);
668 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r2, r3, &slow);
670 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
673 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r2, r3, r4);
675 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r2, r3, r4,
678 // Never falls through to here.
683 // Figure out which native to call and setup the arguments.
685 __ TailCallRuntime(strict() ? Runtime::kStrictEquals : Runtime::kEquals, 2,
688 int ncr; // NaN compare result
689 if (cc == lt || cc == le) {
692 DCHECK(cc == gt || cc == ge); // remaining cases
695 __ mov(r0, Operand(Smi::FromInt(ncr)));
698 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
699 // tagged as a small integer.
701 is_strong(strength()) ? Runtime::kCompare_Strong : Runtime::kCompare, 3,
710 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
711 // We don't allow a GC during a store buffer overflow so there is no need to
712 // store the registers in any particular way, but we do have to store and
714 __ stm(db_w, sp, kCallerSaved | lr.bit());
716 const Register scratch = r1;
718 if (save_doubles()) {
719 __ SaveFPRegs(sp, scratch);
721 const int argument_count = 1;
722 const int fp_argument_count = 0;
724 AllowExternalCallThatCantCauseGC scope(masm);
725 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
726 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
728 ExternalReference::store_buffer_overflow_function(isolate()),
730 if (save_doubles()) {
731 __ RestoreFPRegs(sp, scratch);
733 __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0).
737 void MathPowStub::Generate(MacroAssembler* masm) {
738 const Register base = r1;
739 const Register exponent = MathPowTaggedDescriptor::exponent();
740 DCHECK(exponent.is(r2));
741 const Register heapnumbermap = r5;
742 const Register heapnumber = r0;
743 const DwVfpRegister double_base = d0;
744 const DwVfpRegister double_exponent = d1;
745 const DwVfpRegister double_result = d2;
746 const DwVfpRegister double_scratch = d3;
747 const SwVfpRegister single_scratch = s6;
748 const Register scratch = r9;
749 const Register scratch2 = r4;
751 Label call_runtime, done, int_exponent;
752 if (exponent_type() == ON_STACK) {
753 Label base_is_smi, unpack_exponent;
754 // The exponent and base are supplied as arguments on the stack.
755 // This can only happen if the stub is called from non-optimized code.
756 // Load input parameters from stack to double registers.
757 __ ldr(base, MemOperand(sp, 1 * kPointerSize));
758 __ ldr(exponent, MemOperand(sp, 0 * kPointerSize));
760 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
762 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
763 __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset));
764 __ cmp(scratch, heapnumbermap);
765 __ b(ne, &call_runtime);
767 __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
768 __ jmp(&unpack_exponent);
770 __ bind(&base_is_smi);
771 __ vmov(single_scratch, scratch);
772 __ vcvt_f64_s32(double_base, single_scratch);
773 __ bind(&unpack_exponent);
775 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
777 __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
778 __ cmp(scratch, heapnumbermap);
779 __ b(ne, &call_runtime);
780 __ vldr(double_exponent,
781 FieldMemOperand(exponent, HeapNumber::kValueOffset));
782 } else if (exponent_type() == TAGGED) {
783 // Base is already in double_base.
784 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
786 __ vldr(double_exponent,
787 FieldMemOperand(exponent, HeapNumber::kValueOffset));
790 if (exponent_type() != INTEGER) {
791 Label int_exponent_convert;
792 // Detect integer exponents stored as double.
793 __ vcvt_u32_f64(single_scratch, double_exponent);
794 // We do not check for NaN or Infinity here because comparing numbers on
795 // ARM correctly distinguishes NaNs. We end up calling the built-in.
796 __ vcvt_f64_u32(double_scratch, single_scratch);
797 __ VFPCompareAndSetFlags(double_scratch, double_exponent);
798 __ b(eq, &int_exponent_convert);
800 if (exponent_type() == ON_STACK) {
801 // Detect square root case. Crankshaft detects constant +/-0.5 at
802 // compile time and uses DoMathPowHalf instead. We then skip this check
803 // for non-constant cases of +/-0.5 as these hardly occur.
807 __ vmov(double_scratch, 0.5, scratch);
808 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
809 __ b(ne, ¬_plus_half);
811 // Calculates square root of base. Check for the special case of
812 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
813 __ vmov(double_scratch, -V8_INFINITY, scratch);
814 __ VFPCompareAndSetFlags(double_base, double_scratch);
815 __ vneg(double_result, double_scratch, eq);
818 // Add +0 to convert -0 to +0.
819 __ vadd(double_scratch, double_base, kDoubleRegZero);
820 __ vsqrt(double_result, double_scratch);
823 __ bind(¬_plus_half);
824 __ vmov(double_scratch, -0.5, scratch);
825 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
826 __ b(ne, &call_runtime);
828 // Calculates square root of base. Check for the special case of
829 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
830 __ vmov(double_scratch, -V8_INFINITY, scratch);
831 __ VFPCompareAndSetFlags(double_base, double_scratch);
832 __ vmov(double_result, kDoubleRegZero, eq);
835 // Add +0 to convert -0 to +0.
836 __ vadd(double_scratch, double_base, kDoubleRegZero);
837 __ vmov(double_result, 1.0, scratch);
838 __ vsqrt(double_scratch, double_scratch);
839 __ vdiv(double_result, double_result, double_scratch);
845 AllowExternalCallThatCantCauseGC scope(masm);
846 __ PrepareCallCFunction(0, 2, scratch);
847 __ MovToFloatParameters(double_base, double_exponent);
849 ExternalReference::power_double_double_function(isolate()),
853 __ MovFromFloatResult(double_result);
856 __ bind(&int_exponent_convert);
857 __ vcvt_u32_f64(single_scratch, double_exponent);
858 __ vmov(scratch, single_scratch);
861 // Calculate power with integer exponent.
862 __ bind(&int_exponent);
864 // Get two copies of exponent in the registers scratch and exponent.
865 if (exponent_type() == INTEGER) {
866 __ mov(scratch, exponent);
868 // Exponent has previously been stored into scratch as untagged integer.
869 __ mov(exponent, scratch);
871 __ vmov(double_scratch, double_base); // Back up base.
872 __ vmov(double_result, 1.0, scratch2);
874 // Get absolute value of exponent.
875 __ cmp(scratch, Operand::Zero());
876 __ mov(scratch2, Operand::Zero(), LeaveCC, mi);
877 __ sub(scratch, scratch2, scratch, LeaveCC, mi);
880 __ bind(&while_true);
881 __ mov(scratch, Operand(scratch, ASR, 1), SetCC);
882 __ vmul(double_result, double_result, double_scratch, cs);
883 __ vmul(double_scratch, double_scratch, double_scratch, ne);
884 __ b(ne, &while_true);
886 __ cmp(exponent, Operand::Zero());
888 __ vmov(double_scratch, 1.0, scratch);
889 __ vdiv(double_result, double_scratch, double_result);
890 // Test whether result is zero. Bail out to check for subnormal result.
891 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
892 __ VFPCompareAndSetFlags(double_result, 0.0);
894 // double_exponent may not containe the exponent value if the input was a
895 // smi. We set it with exponent value before bailing out.
896 __ vmov(single_scratch, exponent);
897 __ vcvt_f64_s32(double_exponent, single_scratch);
899 // Returning or bailing out.
900 Counters* counters = isolate()->counters();
901 if (exponent_type() == ON_STACK) {
902 // The arguments are still on the stack.
903 __ bind(&call_runtime);
904 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
906 // The stub is called from non-optimized code, which expects the result
907 // as heap number in exponent.
909 __ AllocateHeapNumber(
910 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
911 __ vstr(double_result,
912 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
913 DCHECK(heapnumber.is(r0));
914 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
919 AllowExternalCallThatCantCauseGC scope(masm);
920 __ PrepareCallCFunction(0, 2, scratch);
921 __ MovToFloatParameters(double_base, double_exponent);
923 ExternalReference::power_double_double_function(isolate()),
927 __ MovFromFloatResult(double_result);
930 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
936 bool CEntryStub::NeedsImmovableCode() {
941 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
942 CEntryStub::GenerateAheadOfTime(isolate);
943 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
944 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
945 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
946 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
947 CreateWeakCellStub::GenerateAheadOfTime(isolate);
948 BinaryOpICStub::GenerateAheadOfTime(isolate);
949 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
950 StoreFastElementStub::GenerateAheadOfTime(isolate);
951 TypeofStub::GenerateAheadOfTime(isolate);
955 void CodeStub::GenerateFPStubs(Isolate* isolate) {
956 // Generate if not already in cache.
957 SaveFPRegsMode mode = kSaveFPRegs;
958 CEntryStub(isolate, 1, mode).GetCode();
959 StoreBufferOverflowStub(isolate, mode).GetCode();
960 isolate->set_fp_stubs_generated(true);
964 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
965 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
970 void CEntryStub::Generate(MacroAssembler* masm) {
971 // Called from JavaScript; parameters are on stack as if calling JS function.
972 // r0: number of arguments including receiver
973 // r1: pointer to builtin function
974 // fp: frame pointer (restored after C call)
975 // sp: stack pointer (restored as callee's sp after C call)
976 // cp: current context (C callee-saved)
978 ProfileEntryHookStub::MaybeCallEntryHook(masm);
980 __ mov(r5, Operand(r1));
982 // Compute the argv pointer in a callee-saved register.
983 __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2));
984 __ sub(r1, r1, Operand(kPointerSize));
986 // Enter the exit frame that transitions from JavaScript to C++.
987 FrameScope scope(masm, StackFrame::MANUAL);
988 __ EnterExitFrame(save_doubles());
990 // Store a copy of argc in callee-saved registers for later.
991 __ mov(r4, Operand(r0));
993 // r0, r4: number of arguments including receiver (C callee-saved)
994 // r1: pointer to the first argument (C callee-saved)
995 // r5: pointer to builtin function (C callee-saved)
997 // Result returned in r0 or r0+r1 by default.
1000 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
1001 int frame_alignment_mask = frame_alignment - 1;
1002 if (FLAG_debug_code) {
1003 if (frame_alignment > kPointerSize) {
1004 Label alignment_as_expected;
1005 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
1006 __ tst(sp, Operand(frame_alignment_mask));
1007 __ b(eq, &alignment_as_expected);
1008 // Don't use Check here, as it will call Runtime_Abort re-entering here.
1009 __ stop("Unexpected alignment");
1010 __ bind(&alignment_as_expected);
1016 // r0 = argc, r1 = argv
1017 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1019 // To let the GC traverse the return address of the exit frames, we need to
1020 // know where the return address is. The CEntryStub is unmovable, so
1021 // we can store the address on the stack to be able to find it again and
1022 // we never have to restore it, because it will not change.
1023 // Compute the return address in lr to return to after the jump below. Pc is
1024 // already at '+ 8' from the current instruction but return is after three
1025 // instructions so add another 4 to pc to get the return address.
1027 // Prevent literal pool emission before return address.
1028 Assembler::BlockConstPoolScope block_const_pool(masm);
1029 __ add(lr, pc, Operand(4));
1030 __ str(lr, MemOperand(sp, 0));
1034 __ VFPEnsureFPSCRState(r2);
1036 // Check result for exception sentinel.
1037 Label exception_returned;
1038 __ CompareRoot(r0, Heap::kExceptionRootIndex);
1039 __ b(eq, &exception_returned);
1041 // Check that there is no pending exception, otherwise we
1042 // should have returned the exception sentinel.
1043 if (FLAG_debug_code) {
1045 ExternalReference pending_exception_address(
1046 Isolate::kPendingExceptionAddress, isolate());
1047 __ mov(r2, Operand(pending_exception_address));
1048 __ ldr(r2, MemOperand(r2));
1049 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex);
1050 // Cannot use check here as it attempts to generate call into runtime.
1052 __ stop("Unexpected pending exception");
1056 // Exit C frame and return.
1058 // sp: stack pointer
1059 // fp: frame pointer
1060 // Callee-saved register r4 still holds argc.
1061 __ LeaveExitFrame(save_doubles(), r4, true);
1064 // Handling of exception.
1065 __ bind(&exception_returned);
1067 ExternalReference pending_handler_context_address(
1068 Isolate::kPendingHandlerContextAddress, isolate());
1069 ExternalReference pending_handler_code_address(
1070 Isolate::kPendingHandlerCodeAddress, isolate());
1071 ExternalReference pending_handler_offset_address(
1072 Isolate::kPendingHandlerOffsetAddress, isolate());
1073 ExternalReference pending_handler_fp_address(
1074 Isolate::kPendingHandlerFPAddress, isolate());
1075 ExternalReference pending_handler_sp_address(
1076 Isolate::kPendingHandlerSPAddress, isolate());
1078 // Ask the runtime for help to determine the handler. This will set r0 to
1079 // contain the current pending exception, don't clobber it.
1080 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1083 FrameScope scope(masm, StackFrame::MANUAL);
1084 __ PrepareCallCFunction(3, 0, r0);
1085 __ mov(r0, Operand(0));
1086 __ mov(r1, Operand(0));
1087 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1088 __ CallCFunction(find_handler, 3);
1091 // Retrieve the handler context, SP and FP.
1092 __ mov(cp, Operand(pending_handler_context_address));
1093 __ ldr(cp, MemOperand(cp));
1094 __ mov(sp, Operand(pending_handler_sp_address));
1095 __ ldr(sp, MemOperand(sp));
1096 __ mov(fp, Operand(pending_handler_fp_address));
1097 __ ldr(fp, MemOperand(fp));
1099 // If the handler is a JS frame, restore the context to the frame. Note that
1100 // the context will be set to (cp == 0) for non-JS frames.
1101 __ cmp(cp, Operand(0));
1102 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne);
1104 // Compute the handler entry address and jump to it.
1105 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1106 __ mov(r1, Operand(pending_handler_code_address));
1107 __ ldr(r1, MemOperand(r1));
1108 __ mov(r2, Operand(pending_handler_offset_address));
1109 __ ldr(r2, MemOperand(r2));
1110 __ add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1111 if (FLAG_enable_embedded_constant_pool) {
1112 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r1);
1118 void JSEntryStub::Generate(MacroAssembler* masm) {
1125 Label invoke, handler_entry, exit;
1127 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1129 // Called from C, so do not pop argc and args on exit (preserve sp)
1130 // No need to save register-passed args
1131 // Save callee-saved registers (incl. cp and fp), sp, and lr
1132 __ stm(db_w, sp, kCalleeSaved | lr.bit());
1134 // Save callee-saved vfp registers.
1135 __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1136 // Set up the reserved register for 0.0.
1137 __ vmov(kDoubleRegZero, 0.0);
1138 __ VFPEnsureFPSCRState(r4);
1140 // Get address of argv, see stm above.
1146 // Set up argv in r4.
1147 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1148 offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize;
1149 __ ldr(r4, MemOperand(sp, offset_to_argv));
1151 // Push a frame with special values setup to mark it as an entry frame.
1157 int marker = type();
1158 if (FLAG_enable_embedded_constant_pool) {
1159 __ mov(r8, Operand::Zero());
1161 __ mov(r7, Operand(Smi::FromInt(marker)));
1162 __ mov(r6, Operand(Smi::FromInt(marker)));
1164 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1165 __ ldr(r5, MemOperand(r5));
1166 __ mov(ip, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1167 __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() |
1168 (FLAG_enable_embedded_constant_pool ? r8.bit() : 0) |
1171 // Set up frame pointer for the frame to be pushed.
1172 __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1174 // If this is the outermost JS call, set js_entry_sp value.
1175 Label non_outermost_js;
1176 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1177 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1178 __ ldr(r6, MemOperand(r5));
1179 __ cmp(r6, Operand::Zero());
1180 __ b(ne, &non_outermost_js);
1181 __ str(fp, MemOperand(r5));
1182 __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1185 __ bind(&non_outermost_js);
1186 __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1190 // Jump to a faked try block that does the invoke, with a faked catch
1191 // block that sets the pending exception.
1194 // Block literal pool emission whilst taking the position of the handler
1195 // entry. This avoids making the assumption that literal pools are always
1196 // emitted after an instruction is emitted, rather than before.
1198 Assembler::BlockConstPoolScope block_const_pool(masm);
1199 __ bind(&handler_entry);
1200 handler_offset_ = handler_entry.pos();
1201 // Caught exception: Store result (exception) in the pending exception
1202 // field in the JSEnv and return a failure sentinel. Coming in here the
1203 // fp will be invalid because the PushStackHandler below sets it to 0 to
1204 // signal the existence of the JSEntry frame.
1205 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1208 __ str(r0, MemOperand(ip));
1209 __ LoadRoot(r0, Heap::kExceptionRootIndex);
1212 // Invoke: Link this frame into the handler chain.
1214 // Must preserve r0-r4, r5-r6 are available.
1215 __ PushStackHandler();
1216 // If an exception not caught by another handler occurs, this handler
1217 // returns control to the code after the bl(&invoke) above, which
1218 // restores all kCalleeSaved registers (including cp and fp) to their
1219 // saved values before returning a failure to C.
1221 // Clear any pending exceptions.
1222 __ mov(r5, Operand(isolate()->factory()->the_hole_value()));
1223 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1225 __ str(r5, MemOperand(ip));
1227 // Invoke the function by calling through JS entry trampoline builtin.
1228 // Notice that we cannot store a reference to the trampoline code directly in
1229 // this stub, because runtime stubs are not traversed when doing GC.
1231 // Expected registers by Builtins::JSEntryTrampoline
1237 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1238 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1240 __ mov(ip, Operand(construct_entry));
1242 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
1243 __ mov(ip, Operand(entry));
1245 __ ldr(ip, MemOperand(ip)); // deref address
1246 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1248 // Branch and link to JSEntryTrampoline.
1251 // Unlink this frame from the handler chain.
1252 __ PopStackHandler();
1254 __ bind(&exit); // r0 holds result
1255 // Check if the current stack frame is marked as the outermost JS frame.
1256 Label non_outermost_js_2;
1258 __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1259 __ b(ne, &non_outermost_js_2);
1260 __ mov(r6, Operand::Zero());
1261 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1262 __ str(r6, MemOperand(r5));
1263 __ bind(&non_outermost_js_2);
1265 // Restore the top frame descriptors from the stack.
1268 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1269 __ str(r3, MemOperand(ip));
1271 // Reset the stack to the callee saved registers.
1272 __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1274 // Restore callee-saved registers and return.
1276 if (FLAG_debug_code) {
1277 __ mov(lr, Operand(pc));
1281 // Restore callee-saved vfp registers.
1282 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1284 __ ldm(ia_w, sp, kCalleeSaved | pc.bit());
1288 void InstanceOfStub::Generate(MacroAssembler* masm) {
1289 Register const object = r1; // Object (lhs).
1290 Register const function = r0; // Function (rhs).
1291 Register const object_map = r2; // Map of {object}.
1292 Register const function_map = r3; // Map of {function}.
1293 Register const function_prototype = r4; // Prototype of {function}.
1294 Register const scratch = r5;
1296 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1297 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1299 // Check if {object} is a smi.
1300 Label object_is_smi;
1301 __ JumpIfSmi(object, &object_is_smi);
1303 // Lookup the {function} and the {object} map in the global instanceof cache.
1304 // Note: This is safe because we clear the global instanceof cache whenever
1305 // we change the prototype of any object.
1306 Label fast_case, slow_case;
1307 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1308 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1309 __ b(ne, &fast_case);
1310 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1311 __ b(ne, &fast_case);
1312 __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1315 // If {object} is a smi we can safely return false if {function} is a JS
1316 // function, otherwise we have to miss to the runtime and throw an exception.
1317 __ bind(&object_is_smi);
1318 __ JumpIfSmi(function, &slow_case);
1319 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1320 __ b(ne, &slow_case);
1321 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1324 // Fast-case: The {function} must be a valid JSFunction.
1325 __ bind(&fast_case);
1326 __ JumpIfSmi(function, &slow_case);
1327 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1328 __ b(ne, &slow_case);
1330 // Ensure that {function} has an instance prototype.
1331 __ ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1332 __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
1333 __ b(ne, &slow_case);
1335 // Ensure that {function} is not bound.
1336 Register const shared_info = scratch;
1338 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1339 __ ldr(scratch, FieldMemOperand(shared_info,
1340 SharedFunctionInfo::kCompilerHintsOffset));
1342 Operand(Smi::FromInt(1 << SharedFunctionInfo::kBoundFunction)));
1343 __ b(ne, &slow_case);
1345 // Get the "prototype" (or initial map) of the {function}.
1346 __ ldr(function_prototype,
1347 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1348 __ AssertNotSmi(function_prototype);
1350 // Resolve the prototype if the {function} has an initial map. Afterwards the
1351 // {function_prototype} will be either the JSReceiver prototype object or the
1352 // hole value, which means that no instances of the {function} were created so
1353 // far and hence we should return false.
1354 Label function_prototype_valid;
1355 __ CompareObjectType(function_prototype, scratch, scratch, MAP_TYPE);
1356 __ b(ne, &function_prototype_valid);
1357 __ ldr(function_prototype,
1358 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1359 __ bind(&function_prototype_valid);
1360 __ AssertNotSmi(function_prototype);
1362 // Update the global instanceof cache with the current {object} map and
1363 // {function}. The cached answer will be set when it is known below.
1364 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1365 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1367 // Loop through the prototype chain looking for the {function} prototype.
1368 // Assume true, and change to false if not found.
1369 Register const object_prototype = object_map;
1370 Register const null = scratch;
1372 __ LoadRoot(r0, Heap::kTrueValueRootIndex);
1373 __ LoadRoot(null, Heap::kNullValueRootIndex);
1375 __ ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1376 __ cmp(object_prototype, function_prototype);
1378 __ cmp(object_prototype, null);
1379 __ ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1381 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1383 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1386 // Slow-case: Call the runtime function.
1387 __ bind(&slow_case);
1388 __ Push(object, function);
1389 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1393 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1395 Register receiver = LoadDescriptor::ReceiverRegister();
1396 // Ensure that the vector and slot registers won't be clobbered before
1397 // calling the miss handler.
1398 DCHECK(!AreAliased(r4, r5, LoadWithVectorDescriptor::VectorRegister(),
1399 LoadWithVectorDescriptor::SlotRegister()));
1401 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4,
1404 PropertyAccessCompiler::TailCallBuiltin(
1405 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1409 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1410 // Return address is in lr.
1413 Register receiver = LoadDescriptor::ReceiverRegister();
1414 Register index = LoadDescriptor::NameRegister();
1415 Register scratch = r5;
1416 Register result = r0;
1417 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1418 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1419 result.is(LoadWithVectorDescriptor::SlotRegister()));
1421 // StringCharAtGenerator doesn't use the result register until it's passed
1422 // the different miss possibilities. If it did, we would have a conflict
1423 // when FLAG_vector_ics is true.
1424 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1425 &miss, // When not a string.
1426 &miss, // When not a number.
1427 &miss, // When index out of range.
1428 STRING_INDEX_IS_ARRAY_INDEX,
1429 RECEIVER_IS_STRING);
1430 char_at_generator.GenerateFast(masm);
1433 StubRuntimeCallHelper call_helper;
1434 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1437 PropertyAccessCompiler::TailCallBuiltin(
1438 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1442 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1443 // The displacement is the offset of the last parameter (if any)
1444 // relative to the frame pointer.
1445 const int kDisplacement =
1446 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1447 DCHECK(r1.is(ArgumentsAccessReadDescriptor::index()));
1448 DCHECK(r0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1450 // Check that the key is a smi.
1452 __ JumpIfNotSmi(r1, &slow);
1454 // Check if the calling frame is an arguments adaptor frame.
1456 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1457 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1458 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1461 // Check index against formal parameters count limit passed in
1462 // through register r0. Use unsigned comparison to get negative
1467 // Read the argument from the stack and return it.
1469 __ add(r3, fp, Operand::PointerOffsetFromSmiKey(r3));
1470 __ ldr(r0, MemOperand(r3, kDisplacement));
1473 // Arguments adaptor case: Check index against actual arguments
1474 // limit found in the arguments adaptor frame. Use unsigned
1475 // comparison to get negative check for free.
1477 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1481 // Read the argument from the adaptor frame and return it.
1483 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r3));
1484 __ ldr(r0, MemOperand(r3, kDisplacement));
1487 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1488 // by calling the runtime system.
1491 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1495 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1496 // sp[0] : number of parameters
1497 // sp[4] : receiver displacement
1500 // Check if the calling frame is an arguments adaptor frame.
1502 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1503 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1504 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1507 // Patch the arguments.length and the parameters pointer in the current frame.
1508 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1509 __ str(r2, MemOperand(sp, 0 * kPointerSize));
1510 __ add(r3, r3, Operand(r2, LSL, 1));
1511 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1512 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1515 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1519 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1521 // sp[0] : number of parameters (tagged)
1522 // sp[4] : address of receiver argument
1524 // Registers used over whole function:
1525 // r6 : allocated object (tagged)
1526 // r9 : mapped parameter count (tagged)
1528 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1529 // r1 = parameter count (tagged)
1531 // Check if the calling frame is an arguments adaptor frame.
1533 Label adaptor_frame, try_allocate;
1534 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1535 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1536 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1537 __ b(eq, &adaptor_frame);
1539 // No adaptor, parameter count = argument count.
1541 __ b(&try_allocate);
1543 // We have an adaptor frame. Patch the parameters pointer.
1544 __ bind(&adaptor_frame);
1545 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1546 __ add(r3, r3, Operand(r2, LSL, 1));
1547 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1548 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1550 // r1 = parameter count (tagged)
1551 // r2 = argument count (tagged)
1552 // Compute the mapped parameter count = min(r1, r2) in r1.
1553 __ cmp(r1, Operand(r2));
1554 __ mov(r1, Operand(r2), LeaveCC, gt);
1556 __ bind(&try_allocate);
1558 // Compute the sizes of backing store, parameter map, and arguments object.
1559 // 1. Parameter map, has 2 extra words containing context and backing store.
1560 const int kParameterMapHeaderSize =
1561 FixedArray::kHeaderSize + 2 * kPointerSize;
1562 // If there are no mapped parameters, we do not need the parameter_map.
1563 __ cmp(r1, Operand(Smi::FromInt(0)));
1564 __ mov(r9, Operand::Zero(), LeaveCC, eq);
1565 __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne);
1566 __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne);
1568 // 2. Backing store.
1569 __ add(r9, r9, Operand(r2, LSL, 1));
1570 __ add(r9, r9, Operand(FixedArray::kHeaderSize));
1572 // 3. Arguments object.
1573 __ add(r9, r9, Operand(Heap::kSloppyArgumentsObjectSize));
1575 // Do the allocation of all three objects in one go.
1576 __ Allocate(r9, r0, r3, r4, &runtime, TAG_OBJECT);
1578 // r0 = address of new object(s) (tagged)
1579 // r2 = argument count (smi-tagged)
1580 // Get the arguments boilerplate from the current native context into r4.
1581 const int kNormalOffset =
1582 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1583 const int kAliasedOffset =
1584 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1586 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1587 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1588 __ cmp(r1, Operand::Zero());
1589 __ ldr(r4, MemOperand(r4, kNormalOffset), eq);
1590 __ ldr(r4, MemOperand(r4, kAliasedOffset), ne);
1592 // r0 = address of new object (tagged)
1593 // r1 = mapped parameter count (tagged)
1594 // r2 = argument count (smi-tagged)
1595 // r4 = address of arguments map (tagged)
1596 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1597 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1598 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1599 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1601 // Set up the callee in-object property.
1602 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1603 __ ldr(r3, MemOperand(sp, 2 * kPointerSize));
1604 __ AssertNotSmi(r3);
1605 const int kCalleeOffset = JSObject::kHeaderSize +
1606 Heap::kArgumentsCalleeIndex * kPointerSize;
1607 __ str(r3, FieldMemOperand(r0, kCalleeOffset));
1609 // Use the length (smi tagged) and set that as an in-object property too.
1611 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1612 const int kLengthOffset = JSObject::kHeaderSize +
1613 Heap::kArgumentsLengthIndex * kPointerSize;
1614 __ str(r2, FieldMemOperand(r0, kLengthOffset));
1616 // Set up the elements pointer in the allocated arguments object.
1617 // If we allocated a parameter map, r4 will point there, otherwise
1618 // it will point to the backing store.
1619 __ add(r4, r0, Operand(Heap::kSloppyArgumentsObjectSize));
1620 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1622 // r0 = address of new object (tagged)
1623 // r1 = mapped parameter count (tagged)
1624 // r2 = argument count (tagged)
1625 // r4 = address of parameter map or backing store (tagged)
1626 // Initialize parameter map. If there are no mapped arguments, we're done.
1627 Label skip_parameter_map;
1628 __ cmp(r1, Operand(Smi::FromInt(0)));
1629 // Move backing store address to r3, because it is
1630 // expected there when filling in the unmapped arguments.
1631 __ mov(r3, r4, LeaveCC, eq);
1632 __ b(eq, &skip_parameter_map);
1634 __ LoadRoot(r6, Heap::kSloppyArgumentsElementsMapRootIndex);
1635 __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset));
1636 __ add(r6, r1, Operand(Smi::FromInt(2)));
1637 __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset));
1638 __ str(cp, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize));
1639 __ add(r6, r4, Operand(r1, LSL, 1));
1640 __ add(r6, r6, Operand(kParameterMapHeaderSize));
1641 __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize));
1643 // Copy the parameter slots and the holes in the arguments.
1644 // We need to fill in mapped_parameter_count slots. They index the context,
1645 // where parameters are stored in reverse order, at
1646 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1647 // The mapped parameter thus need to get indices
1648 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1649 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1650 // We loop from right to left.
1651 Label parameters_loop, parameters_test;
1653 __ ldr(r9, MemOperand(sp, 0 * kPointerSize));
1654 __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1655 __ sub(r9, r9, Operand(r1));
1656 __ LoadRoot(r5, Heap::kTheHoleValueRootIndex);
1657 __ add(r3, r4, Operand(r6, LSL, 1));
1658 __ add(r3, r3, Operand(kParameterMapHeaderSize));
1660 // r6 = loop variable (tagged)
1661 // r1 = mapping index (tagged)
1662 // r3 = address of backing store (tagged)
1663 // r4 = address of parameter map (tagged), which is also the address of new
1664 // object + Heap::kSloppyArgumentsObjectSize (tagged)
1665 // r0 = temporary scratch (a.o., for address calculation)
1666 // r5 = the hole value
1667 __ jmp(¶meters_test);
1669 __ bind(¶meters_loop);
1670 __ sub(r6, r6, Operand(Smi::FromInt(1)));
1671 __ mov(r0, Operand(r6, LSL, 1));
1672 __ add(r0, r0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1673 __ str(r9, MemOperand(r4, r0));
1674 __ sub(r0, r0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1675 __ str(r5, MemOperand(r3, r0));
1676 __ add(r9, r9, Operand(Smi::FromInt(1)));
1677 __ bind(¶meters_test);
1678 __ cmp(r6, Operand(Smi::FromInt(0)));
1679 __ b(ne, ¶meters_loop);
1681 // Restore r0 = new object (tagged)
1682 __ sub(r0, r4, Operand(Heap::kSloppyArgumentsObjectSize));
1684 __ bind(&skip_parameter_map);
1685 // r0 = address of new object (tagged)
1686 // r2 = argument count (tagged)
1687 // r3 = address of backing store (tagged)
1689 // Copy arguments header and remaining slots (if there are any).
1690 __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex);
1691 __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset));
1692 __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset));
1694 Label arguments_loop, arguments_test;
1696 __ ldr(r4, MemOperand(sp, 1 * kPointerSize));
1697 __ sub(r4, r4, Operand(r9, LSL, 1));
1698 __ jmp(&arguments_test);
1700 __ bind(&arguments_loop);
1701 __ sub(r4, r4, Operand(kPointerSize));
1702 __ ldr(r6, MemOperand(r4, 0));
1703 __ add(r5, r3, Operand(r9, LSL, 1));
1704 __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize));
1705 __ add(r9, r9, Operand(Smi::FromInt(1)));
1707 __ bind(&arguments_test);
1708 __ cmp(r9, Operand(r2));
1709 __ b(lt, &arguments_loop);
1711 // Return and remove the on-stack parameters.
1712 __ add(sp, sp, Operand(3 * kPointerSize));
1715 // Do the runtime call to allocate the arguments object.
1716 // r0 = address of new object (tagged)
1717 // r2 = argument count (tagged)
1719 __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1720 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1724 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1725 // Return address is in lr.
1728 Register receiver = LoadDescriptor::ReceiverRegister();
1729 Register key = LoadDescriptor::NameRegister();
1731 // Check that the key is an array index, that is Uint32.
1732 __ NonNegativeSmiTst(key);
1735 // Everything is fine, call runtime.
1736 __ Push(receiver, key); // Receiver, key.
1738 // Perform tail call to the entry.
1739 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1742 PropertyAccessCompiler::TailCallBuiltin(
1743 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1747 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1748 // sp[0] : number of parameters
1749 // sp[4] : receiver displacement
1751 // Check if the calling frame is an arguments adaptor frame.
1752 Label adaptor_frame, try_allocate, runtime;
1753 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1754 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1755 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1756 __ b(eq, &adaptor_frame);
1758 // Get the length from the frame.
1759 __ ldr(r1, MemOperand(sp, 0));
1760 __ b(&try_allocate);
1762 // Patch the arguments.length and the parameters pointer.
1763 __ bind(&adaptor_frame);
1764 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1765 __ str(r1, MemOperand(sp, 0));
1766 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1767 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1768 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1770 // Try the new space allocation. Start out with computing the size
1771 // of the arguments object and the elements array in words.
1772 Label add_arguments_object;
1773 __ bind(&try_allocate);
1774 __ SmiUntag(r1, SetCC);
1775 __ b(eq, &add_arguments_object);
1776 __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize));
1777 __ bind(&add_arguments_object);
1778 __ add(r1, r1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1780 // Do the allocation of both objects in one go.
1781 __ Allocate(r1, r0, r2, r3, &runtime,
1782 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1784 // Get the arguments boilerplate from the current native context.
1785 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1786 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1787 __ ldr(r4, MemOperand(
1788 r4, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1790 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1791 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1792 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1793 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1795 // Get the length (smi tagged) and set that as an in-object property too.
1796 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1797 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1799 __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize +
1800 Heap::kArgumentsLengthIndex * kPointerSize));
1802 // If there are no actual arguments, we're done.
1804 __ cmp(r1, Operand::Zero());
1807 // Get the parameters pointer from the stack.
1808 __ ldr(r2, MemOperand(sp, 1 * kPointerSize));
1810 // Set up the elements pointer in the allocated arguments object and
1811 // initialize the header in the elements fixed array.
1812 __ add(r4, r0, Operand(Heap::kStrictArgumentsObjectSize));
1813 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1814 __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex);
1815 __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset));
1816 __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset));
1819 // Copy the fixed array slots.
1821 // Set up r4 to point to the first array slot.
1822 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1824 // Pre-decrement r2 with kPointerSize on each iteration.
1825 // Pre-decrement in order to skip receiver.
1826 __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
1827 // Post-increment r4 with kPointerSize on each iteration.
1828 __ str(r3, MemOperand(r4, kPointerSize, PostIndex));
1829 __ sub(r1, r1, Operand(1));
1830 __ cmp(r1, Operand::Zero());
1833 // Return and remove the on-stack parameters.
1835 __ add(sp, sp, Operand(3 * kPointerSize));
1838 // Do the runtime call to allocate the arguments object.
1840 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1844 void RegExpExecStub::Generate(MacroAssembler* masm) {
1845 // Just jump directly to runtime if native RegExp is not selected at compile
1846 // time or if regexp entry in generated code is turned off runtime switch or
1848 #ifdef V8_INTERPRETED_REGEXP
1849 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1850 #else // V8_INTERPRETED_REGEXP
1852 // Stack frame on entry.
1853 // sp[0]: last_match_info (expected JSArray)
1854 // sp[4]: previous index
1855 // sp[8]: subject string
1856 // sp[12]: JSRegExp object
1858 const int kLastMatchInfoOffset = 0 * kPointerSize;
1859 const int kPreviousIndexOffset = 1 * kPointerSize;
1860 const int kSubjectOffset = 2 * kPointerSize;
1861 const int kJSRegExpOffset = 3 * kPointerSize;
1864 // Allocation of registers for this function. These are in callee save
1865 // registers and will be preserved by the call to the native RegExp code, as
1866 // this code is called using the normal C calling convention. When calling
1867 // directly from generated code the native RegExp code will not do a GC and
1868 // therefore the content of these registers are safe to use after the call.
1869 Register subject = r4;
1870 Register regexp_data = r5;
1871 Register last_match_info_elements = no_reg; // will be r6;
1873 // Ensure that a RegExp stack is allocated.
1874 ExternalReference address_of_regexp_stack_memory_address =
1875 ExternalReference::address_of_regexp_stack_memory_address(isolate());
1876 ExternalReference address_of_regexp_stack_memory_size =
1877 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1878 __ mov(r0, Operand(address_of_regexp_stack_memory_size));
1879 __ ldr(r0, MemOperand(r0, 0));
1880 __ cmp(r0, Operand::Zero());
1883 // Check that the first argument is a JSRegExp object.
1884 __ ldr(r0, MemOperand(sp, kJSRegExpOffset));
1885 __ JumpIfSmi(r0, &runtime);
1886 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
1889 // Check that the RegExp has been compiled (data contains a fixed array).
1890 __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
1891 if (FLAG_debug_code) {
1892 __ SmiTst(regexp_data);
1893 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1894 __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
1895 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1898 // regexp_data: RegExp data (FixedArray)
1899 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1900 __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1901 __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
1904 // regexp_data: RegExp data (FixedArray)
1905 // Check that the number of captures fit in the static offsets vector buffer.
1907 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1908 // Check (number_of_captures + 1) * 2 <= offsets vector size
1909 // Or number_of_captures * 2 <= offsets vector size - 2
1910 // Multiplying by 2 comes for free since r2 is smi-tagged.
1911 STATIC_ASSERT(kSmiTag == 0);
1912 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
1913 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1914 __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
1917 // Reset offset for possibly sliced string.
1918 __ mov(r9, Operand::Zero());
1919 __ ldr(subject, MemOperand(sp, kSubjectOffset));
1920 __ JumpIfSmi(subject, &runtime);
1921 __ mov(r3, subject); // Make a copy of the original subject string.
1922 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1923 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
1924 // subject: subject string
1925 // r3: subject string
1926 // r0: subject string instance type
1927 // regexp_data: RegExp data (FixedArray)
1928 // Handle subject string according to its encoding and representation:
1929 // (1) Sequential string? If yes, go to (5).
1930 // (2) Anything but sequential or cons? If yes, go to (6).
1931 // (3) Cons string. If the string is flat, replace subject with first string.
1932 // Otherwise bailout.
1933 // (4) Is subject external? If yes, go to (7).
1934 // (5) Sequential string. Load regexp code according to encoding.
1938 // Deferred code at the end of the stub:
1939 // (6) Not a long external string? If yes, go to (8).
1940 // (7) External string. Make it, offset-wise, look like a sequential string.
1942 // (8) Short external string or not a string? If yes, bail out to runtime.
1943 // (9) Sliced string. Replace subject with parent. Go to (4).
1945 Label seq_string /* 5 */, external_string /* 7 */,
1946 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
1947 not_long_external /* 8 */;
1949 // (1) Sequential string? If yes, go to (5).
1952 Operand(kIsNotStringMask |
1953 kStringRepresentationMask |
1954 kShortExternalStringMask),
1956 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
1957 __ b(eq, &seq_string); // Go to (5).
1959 // (2) Anything but sequential or cons? If yes, go to (6).
1960 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1961 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
1962 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1963 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
1964 __ cmp(r1, Operand(kExternalStringTag));
1965 __ b(ge, ¬_seq_nor_cons); // Go to (6).
1967 // (3) Cons string. Check that it's flat.
1968 // Replace subject with first string and reload instance type.
1969 __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
1970 __ CompareRoot(r0, Heap::kempty_stringRootIndex);
1972 __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
1974 // (4) Is subject external? If yes, go to (7).
1975 __ bind(&check_underlying);
1976 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1977 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
1978 STATIC_ASSERT(kSeqStringTag == 0);
1979 __ tst(r0, Operand(kStringRepresentationMask));
1980 // The underlying external string is never a short external string.
1981 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
1982 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
1983 __ b(ne, &external_string); // Go to (7).
1985 // (5) Sequential string. Load regexp code according to encoding.
1986 __ bind(&seq_string);
1987 // subject: sequential subject string (or look-alike, external string)
1988 // r3: original subject string
1989 // Load previous index and check range before r3 is overwritten. We have to
1990 // use r3 instead of subject here because subject might have been only made
1991 // to look like a sequential string when it actually is an external string.
1992 __ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
1993 __ JumpIfNotSmi(r1, &runtime);
1994 __ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
1995 __ cmp(r3, Operand(r1));
1999 STATIC_ASSERT(4 == kOneByteStringTag);
2000 STATIC_ASSERT(kTwoByteStringTag == 0);
2001 __ and_(r0, r0, Operand(kStringEncodingMask));
2002 __ mov(r3, Operand(r0, ASR, 2), SetCC);
2003 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset),
2005 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
2007 // (E) Carry on. String handling is done.
2008 // r6: irregexp code
2009 // Check that the irregexp code has been generated for the actual string
2010 // encoding. If it has, the field contains a code object otherwise it contains
2011 // a smi (code flushing support).
2012 __ JumpIfSmi(r6, &runtime);
2014 // r1: previous index
2015 // r3: encoding of subject string (1 if one_byte, 0 if two_byte);
2017 // subject: Subject string
2018 // regexp_data: RegExp data (FixedArray)
2019 // All checks done. Now push arguments for native regexp code.
2020 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r0, r2);
2022 // Isolates: note we add an additional parameter here (isolate pointer).
2023 const int kRegExpExecuteArguments = 9;
2024 const int kParameterRegisters = 4;
2025 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2027 // Stack pointer now points to cell where return address is to be written.
2028 // Arguments are before that on the stack or in registers.
2030 // Argument 9 (sp[20]): Pass current isolate address.
2031 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2032 __ str(r0, MemOperand(sp, 5 * kPointerSize));
2034 // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
2035 __ mov(r0, Operand(1));
2036 __ str(r0, MemOperand(sp, 4 * kPointerSize));
2038 // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
2039 __ mov(r0, Operand(address_of_regexp_stack_memory_address));
2040 __ ldr(r0, MemOperand(r0, 0));
2041 __ mov(r2, Operand(address_of_regexp_stack_memory_size));
2042 __ ldr(r2, MemOperand(r2, 0));
2043 __ add(r0, r0, Operand(r2));
2044 __ str(r0, MemOperand(sp, 3 * kPointerSize));
2046 // Argument 6: Set the number of capture registers to zero to force global
2047 // regexps to behave as non-global. This does not affect non-global regexps.
2048 __ mov(r0, Operand::Zero());
2049 __ str(r0, MemOperand(sp, 2 * kPointerSize));
2051 // Argument 5 (sp[4]): static offsets vector buffer.
2053 Operand(ExternalReference::address_of_static_offsets_vector(
2055 __ str(r0, MemOperand(sp, 1 * kPointerSize));
2057 // For arguments 4 and 3 get string length, calculate start of string data and
2058 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2059 __ add(r7, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2060 __ eor(r3, r3, Operand(1));
2061 // Load the length from the original subject string from the previous stack
2062 // frame. Therefore we have to use fp, which points exactly to two pointer
2063 // sizes below the previous sp. (Because creating a new stack frame pushes
2064 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2065 __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2066 // If slice offset is not 0, load the length from the original sliced string.
2067 // Argument 4, r3: End of string data
2068 // Argument 3, r2: Start of string data
2069 // Prepare start and end index of the input.
2070 __ add(r9, r7, Operand(r9, LSL, r3));
2071 __ add(r2, r9, Operand(r1, LSL, r3));
2073 __ ldr(r7, FieldMemOperand(subject, String::kLengthOffset));
2075 __ add(r3, r9, Operand(r7, LSL, r3));
2077 // Argument 2 (r1): Previous index.
2080 // Argument 1 (r0): Subject string.
2081 __ mov(r0, subject);
2083 // Locate the code entry and call it.
2084 __ add(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
2085 DirectCEntryStub stub(isolate());
2086 stub.GenerateCall(masm, r6);
2088 __ LeaveExitFrame(false, no_reg, true);
2090 last_match_info_elements = r6;
2093 // subject: subject string (callee saved)
2094 // regexp_data: RegExp data (callee saved)
2095 // last_match_info_elements: Last match info elements (callee saved)
2096 // Check the result.
2098 __ cmp(r0, Operand(1));
2099 // We expect exactly one result since we force the called regexp to behave
2103 __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
2105 __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2106 // If not exception it can only be retry. Handle that in the runtime system.
2108 // Result must now be exception. If there is no pending exception already a
2109 // stack overflow (on the backtrack stack) was detected in RegExp code but
2110 // haven't created the exception yet. Handle that in the runtime system.
2111 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2112 __ mov(r1, Operand(isolate()->factory()->the_hole_value()));
2113 __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2115 __ ldr(r0, MemOperand(r2, 0));
2119 // For exception, throw the exception again.
2120 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2123 // For failure and exception return null.
2124 __ mov(r0, Operand(isolate()->factory()->null_value()));
2125 __ add(sp, sp, Operand(4 * kPointerSize));
2128 // Process the result from the native regexp code.
2131 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2132 // Calculate number of capture registers (number_of_captures + 1) * 2.
2133 // Multiplying by 2 comes for free since r1 is smi-tagged.
2134 STATIC_ASSERT(kSmiTag == 0);
2135 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2136 __ add(r1, r1, Operand(2)); // r1 was a smi.
2138 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2139 __ JumpIfSmi(r0, &runtime);
2140 __ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
2142 // Check that the JSArray is in fast case.
2143 __ ldr(last_match_info_elements,
2144 FieldMemOperand(r0, JSArray::kElementsOffset));
2145 __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2146 __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
2148 // Check that the last match info has space for the capture registers and the
2149 // additional information.
2151 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2152 __ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
2153 __ cmp(r2, Operand::SmiUntag(r0));
2156 // r1: number of capture registers
2157 // r4: subject string
2158 // Store the capture count.
2160 __ str(r2, FieldMemOperand(last_match_info_elements,
2161 RegExpImpl::kLastCaptureCountOffset));
2162 // Store last subject and last input.
2164 FieldMemOperand(last_match_info_elements,
2165 RegExpImpl::kLastSubjectOffset));
2166 __ mov(r2, subject);
2167 __ RecordWriteField(last_match_info_elements,
2168 RegExpImpl::kLastSubjectOffset,
2173 __ mov(subject, r2);
2175 FieldMemOperand(last_match_info_elements,
2176 RegExpImpl::kLastInputOffset));
2177 __ RecordWriteField(last_match_info_elements,
2178 RegExpImpl::kLastInputOffset,
2184 // Get the static offsets vector filled by the native regexp code.
2185 ExternalReference address_of_static_offsets_vector =
2186 ExternalReference::address_of_static_offsets_vector(isolate());
2187 __ mov(r2, Operand(address_of_static_offsets_vector));
2189 // r1: number of capture registers
2190 // r2: offsets vector
2191 Label next_capture, done;
2192 // Capture register counter starts from number of capture registers and
2193 // counts down until wraping after zero.
2195 last_match_info_elements,
2196 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2197 __ bind(&next_capture);
2198 __ sub(r1, r1, Operand(1), SetCC);
2200 // Read the value from the static offsets vector buffer.
2201 __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
2202 // Store the smi value in the last match info.
2204 __ str(r3, MemOperand(r0, kPointerSize, PostIndex));
2205 __ jmp(&next_capture);
2208 // Return last match info.
2209 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2210 __ add(sp, sp, Operand(4 * kPointerSize));
2213 // Do the runtime call to execute the regexp.
2215 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2217 // Deferred code for string handling.
2218 // (6) Not a long external string? If yes, go to (8).
2219 __ bind(¬_seq_nor_cons);
2220 // Compare flags are still set.
2221 __ b(gt, ¬_long_external); // Go to (8).
2223 // (7) External string. Make it, offset-wise, look like a sequential string.
2224 __ bind(&external_string);
2225 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2226 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2227 if (FLAG_debug_code) {
2228 // Assert that we do not have a cons or slice (indirect strings) here.
2229 // Sequential strings have already been ruled out.
2230 __ tst(r0, Operand(kIsIndirectStringMask));
2231 __ Assert(eq, kExternalStringExpectedButNotFound);
2234 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2235 // Move the pointer so that offset-wise, it looks like a sequential string.
2236 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2239 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2240 __ jmp(&seq_string); // Go to (5).
2242 // (8) Short external string or not a string? If yes, bail out to runtime.
2243 __ bind(¬_long_external);
2244 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2245 __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
2248 // (9) Sliced string. Replace subject with parent. Go to (4).
2249 // Load offset into r9 and replace subject string with parent.
2250 __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2252 __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2253 __ jmp(&check_underlying); // Go to (4).
2254 #endif // V8_INTERPRETED_REGEXP
2258 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2260 // r0 : number of arguments to the construct function
2261 // r1 : the function to call
2262 // r2 : feedback vector
2263 // r3 : slot in feedback vector (Smi)
2264 // r4 : original constructor (for IsSuperConstructorCall)
2265 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2267 // Number-of-arguments register must be smi-tagged to call out.
2269 __ Push(r3, r2, r1, r0);
2279 __ Pop(r3, r2, r1, r0);
2284 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2285 // Cache the called function in a feedback vector slot. Cache states
2286 // are uninitialized, monomorphic (indicated by a JSFunction), and
2288 // r0 : number of arguments to the construct function
2289 // r1 : the function to call
2290 // r2 : feedback vector
2291 // r3 : slot in feedback vector (Smi)
2292 // r4 : original constructor (for IsSuperConstructorCall)
2293 Label initialize, done, miss, megamorphic, not_array_function;
2295 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2296 masm->isolate()->heap()->megamorphic_symbol());
2297 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2298 masm->isolate()->heap()->uninitialized_symbol());
2300 // Load the cache state into r5.
2301 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2302 __ ldr(r5, FieldMemOperand(r5, FixedArray::kHeaderSize));
2304 // A monomorphic cache hit or an already megamorphic state: invoke the
2305 // function without changing the state.
2306 // We don't know if r5 is a WeakCell or a Symbol, but it's harmless to read at
2307 // this position in a symbol (see static asserts in type-feedback-vector.h).
2308 Label check_allocation_site;
2309 Register feedback_map = r6;
2310 Register weak_value = r9;
2311 __ ldr(weak_value, FieldMemOperand(r5, WeakCell::kValueOffset));
2312 __ cmp(r1, weak_value);
2314 __ CompareRoot(r5, Heap::kmegamorphic_symbolRootIndex);
2316 __ ldr(feedback_map, FieldMemOperand(r5, HeapObject::kMapOffset));
2317 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2318 __ b(ne, &check_allocation_site);
2320 // If the weak cell is cleared, we have a new chance to become monomorphic.
2321 __ JumpIfSmi(weak_value, &initialize);
2322 __ jmp(&megamorphic);
2324 __ bind(&check_allocation_site);
2325 // If we came here, we need to see if we are the array function.
2326 // If we didn't have a matching function, and we didn't find the megamorph
2327 // sentinel, then we have in the slot either some other function or an
2329 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2332 // Make sure the function is the Array() function
2333 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2335 __ b(ne, &megamorphic);
2340 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2342 __ CompareRoot(r5, Heap::kuninitialized_symbolRootIndex);
2343 __ b(eq, &initialize);
2344 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2345 // write-barrier is needed.
2346 __ bind(&megamorphic);
2347 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2348 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2349 __ str(ip, FieldMemOperand(r5, FixedArray::kHeaderSize));
2352 // An uninitialized cache is patched with the function
2353 __ bind(&initialize);
2355 // Make sure the function is the Array() function
2356 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2358 __ b(ne, ¬_array_function);
2360 // The target function is the Array constructor,
2361 // Create an AllocationSite if we don't already have it, store it in the
2363 CreateAllocationSiteStub create_stub(masm->isolate());
2364 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2367 __ bind(¬_array_function);
2368 CreateWeakCellStub weak_cell_stub(masm->isolate());
2369 CallStubInRecordCallTarget(masm, &weak_cell_stub, is_super);
2374 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2375 // Do not transform the receiver for strict mode functions.
2376 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2377 __ ldr(r4, FieldMemOperand(r3, SharedFunctionInfo::kCompilerHintsOffset));
2378 __ tst(r4, Operand(1 << (SharedFunctionInfo::kStrictModeFunction +
2382 // Do not transform the receiver for native (Compilerhints already in r3).
2383 __ tst(r4, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
2388 static void EmitSlowCase(MacroAssembler* masm, int argc) {
2389 __ mov(r0, Operand(argc));
2390 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2394 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2395 // Wrap the receiver and patch it back onto the stack.
2396 { FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2399 ToObjectStub stub(masm->isolate());
2403 __ str(r0, MemOperand(sp, argc * kPointerSize));
2408 static void CallFunctionNoFeedback(MacroAssembler* masm,
2409 int argc, bool needs_checks,
2410 bool call_as_method) {
2411 // r1 : the function to call
2412 Label slow, wrap, cont;
2415 // Check that the function is really a JavaScript function.
2416 // r1: pushed function (to be verified)
2417 __ JumpIfSmi(r1, &slow);
2419 // Goto slow case if we do not have a function.
2420 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2424 // Fast-case: Invoke the function now.
2425 // r1: pushed function
2426 ParameterCount actual(argc);
2428 if (call_as_method) {
2430 EmitContinueIfStrictOrNative(masm, &cont);
2433 // Compute the receiver in sloppy mode.
2434 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2437 __ JumpIfSmi(r3, &wrap);
2438 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2447 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2450 // Slow-case: Non-function called.
2452 EmitSlowCase(masm, argc);
2455 if (call_as_method) {
2457 EmitWrapCase(masm, argc, &cont);
2462 void CallFunctionStub::Generate(MacroAssembler* masm) {
2463 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2467 void CallConstructStub::Generate(MacroAssembler* masm) {
2468 // r0 : number of arguments
2469 // r1 : the function to call
2470 // r2 : feedback vector
2471 // r3 : slot in feedback vector (Smi, for RecordCallTarget)
2472 // r4 : original constructor (for IsSuperConstructorCall)
2473 Label slow, non_function_call;
2475 // Check that the function is not a smi.
2476 __ JumpIfSmi(r1, &non_function_call);
2477 // Check that the function is a JSFunction.
2478 __ CompareObjectType(r1, r5, r5, JS_FUNCTION_TYPE);
2481 if (RecordCallTarget()) {
2482 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2484 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2485 Label feedback_register_initialized;
2486 // Put the AllocationSite from the feedback vector into r2, or undefined.
2487 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2488 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2489 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2490 __ b(eq, &feedback_register_initialized);
2491 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2492 __ bind(&feedback_register_initialized);
2494 __ AssertUndefinedOrAllocationSite(r2, r5);
2497 // Pass function as original constructor.
2498 if (IsSuperConstructorCall()) {
2504 // Jump to the function-specific construct stub.
2505 Register jmp_reg = r4;
2506 __ ldr(jmp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2507 __ ldr(jmp_reg, FieldMemOperand(jmp_reg,
2508 SharedFunctionInfo::kConstructStubOffset));
2509 __ add(pc, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2511 // r0: number of arguments
2512 // r1: called object
2516 __ cmp(r5, Operand(JS_FUNCTION_PROXY_TYPE));
2517 __ b(ne, &non_function_call);
2518 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies.
2519 __ ldr(r1, FieldMemOperand(r1, JSFunctionProxy::kConstructTrapOffset));
2520 __ Jump(isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2522 __ bind(&non_function_call);
2524 // Determine the delegate for the target (if any).
2525 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2528 __ CallRuntime(Runtime::kGetConstructorDelegate, 1);
2533 // The delegate is always a regular function.
2534 __ AssertFunction(r1);
2535 __ Jump(masm->isolate()->builtins()->CallFunction(),
2536 RelocInfo::CODE_TARGET);
2541 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2542 __ ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2543 __ ldr(vector, FieldMemOperand(vector,
2544 JSFunction::kSharedFunctionInfoOffset));
2545 __ ldr(vector, FieldMemOperand(vector,
2546 SharedFunctionInfo::kFeedbackVectorOffset));
2550 void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
2554 // r4 - allocation site (loaded from vector[slot])
2555 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2559 __ mov(r0, Operand(arg_count()));
2561 // Increment the call count for monomorphic function calls.
2562 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2563 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2564 __ ldr(r3, FieldMemOperand(r2, 0));
2565 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2566 __ str(r3, FieldMemOperand(r2, 0));
2570 ArrayConstructorStub stub(masm->isolate(), arg_count());
2571 __ TailCallStub(&stub);
2575 void CallICStub::Generate(MacroAssembler* masm) {
2577 // r3 - slot id (Smi)
2579 const int with_types_offset =
2580 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2581 const int generic_offset =
2582 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2583 Label extra_checks_or_miss, slow_start;
2584 Label slow, wrap, cont;
2585 Label have_js_function;
2586 int argc = arg_count();
2587 ParameterCount actual(argc);
2589 // The checks. First, does r1 match the recorded monomorphic target?
2590 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2591 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2593 // We don't know that we have a weak cell. We might have a private symbol
2594 // or an AllocationSite, but the memory is safe to examine.
2595 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2597 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2598 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2599 // computed, meaning that it can't appear to be a pointer. If the low bit is
2600 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2602 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2603 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2604 WeakCell::kValueOffset &&
2605 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2607 __ ldr(r5, FieldMemOperand(r4, WeakCell::kValueOffset));
2609 __ b(ne, &extra_checks_or_miss);
2611 // The compare above could have been a SMI/SMI comparison. Guard against this
2612 // convincing us that we have a monomorphic JSFunction.
2613 __ JumpIfSmi(r1, &extra_checks_or_miss);
2615 // Increment the call count for monomorphic function calls.
2616 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2617 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2618 __ ldr(r3, FieldMemOperand(r2, 0));
2619 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2620 __ str(r3, FieldMemOperand(r2, 0));
2622 __ bind(&have_js_function);
2623 if (CallAsMethod()) {
2624 EmitContinueIfStrictOrNative(masm, &cont);
2625 // Compute the receiver in sloppy mode.
2626 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2628 __ JumpIfSmi(r3, &wrap);
2629 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2635 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2638 EmitSlowCase(masm, argc);
2640 if (CallAsMethod()) {
2642 EmitWrapCase(masm, argc, &cont);
2645 __ bind(&extra_checks_or_miss);
2646 Label uninitialized, miss, not_allocation_site;
2648 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2649 __ b(eq, &slow_start);
2651 // Verify that r4 contains an AllocationSite
2652 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2653 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2654 __ b(ne, ¬_allocation_site);
2656 // We have an allocation site.
2657 HandleArrayCase(masm, &miss);
2659 __ bind(¬_allocation_site);
2661 // The following cases attempt to handle MISS cases without going to the
2663 if (FLAG_trace_ic) {
2667 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2668 __ b(eq, &uninitialized);
2670 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2671 // to handle it here. More complex cases are dealt with in the runtime.
2672 __ AssertNotSmi(r4);
2673 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2675 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2676 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2677 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2678 // We have to update statistics for runtime profiling.
2679 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2680 __ sub(r4, r4, Operand(Smi::FromInt(1)));
2681 __ str(r4, FieldMemOperand(r2, with_types_offset));
2682 __ ldr(r4, FieldMemOperand(r2, generic_offset));
2683 __ add(r4, r4, Operand(Smi::FromInt(1)));
2684 __ str(r4, FieldMemOperand(r2, generic_offset));
2685 __ jmp(&slow_start);
2687 __ bind(&uninitialized);
2689 // We are going monomorphic, provided we actually have a JSFunction.
2690 __ JumpIfSmi(r1, &miss);
2692 // Goto miss case if we do not have a function.
2693 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2696 // Make sure the function is not the Array() function, which requires special
2697 // behavior on MISS.
2698 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2703 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2704 __ add(r4, r4, Operand(Smi::FromInt(1)));
2705 __ str(r4, FieldMemOperand(r2, with_types_offset));
2707 // Initialize the call counter.
2708 __ Move(r5, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2709 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2710 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + kPointerSize));
2712 // Store the function. Use a stub since we need a frame for allocation.
2717 FrameScope scope(masm, StackFrame::INTERNAL);
2718 CreateWeakCellStub create_stub(masm->isolate());
2720 __ CallStub(&create_stub);
2724 __ jmp(&have_js_function);
2726 // We are here because tracing is on or we encountered a MISS case we can't
2732 __ bind(&slow_start);
2733 // Check that the function is really a JavaScript function.
2734 // r1: pushed function (to be verified)
2735 __ JumpIfSmi(r1, &slow);
2737 // Goto slow case if we do not have a function.
2738 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2740 __ jmp(&have_js_function);
2744 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2745 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2747 // Push the receiver and the function and feedback info.
2748 __ Push(r1, r2, r3);
2751 __ CallRuntime(Runtime::kCallIC_Miss, 3);
2753 // Move result to edi and exit the internal frame.
2758 // StringCharCodeAtGenerator
2759 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2760 // If the receiver is a smi trigger the non-string case.
2761 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2762 __ JumpIfSmi(object_, receiver_not_string_);
2764 // Fetch the instance type of the receiver into result register.
2765 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2766 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2767 // If the receiver is not a string trigger the non-string case.
2768 __ tst(result_, Operand(kIsNotStringMask));
2769 __ b(ne, receiver_not_string_);
2772 // If the index is non-smi trigger the non-smi case.
2773 __ JumpIfNotSmi(index_, &index_not_smi_);
2774 __ bind(&got_smi_index_);
2776 // Check for index out of range.
2777 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
2778 __ cmp(ip, Operand(index_));
2779 __ b(ls, index_out_of_range_);
2781 __ SmiUntag(index_);
2783 StringCharLoadGenerator::Generate(masm,
2794 void StringCharCodeAtGenerator::GenerateSlow(
2795 MacroAssembler* masm, EmbedMode embed_mode,
2796 const RuntimeCallHelper& call_helper) {
2797 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2799 // Index is not a smi.
2800 __ bind(&index_not_smi_);
2801 // If index is a heap number, try converting it to an integer.
2804 Heap::kHeapNumberMapRootIndex,
2807 call_helper.BeforeCall(masm);
2808 if (embed_mode == PART_OF_IC_HANDLER) {
2809 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2810 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2812 // index_ is consumed by runtime conversion function.
2813 __ Push(object_, index_);
2815 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2816 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2818 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2819 // NumberToSmi discards numbers that are not exact integers.
2820 __ CallRuntime(Runtime::kNumberToSmi, 1);
2822 // Save the conversion result before the pop instructions below
2823 // have a chance to overwrite it.
2824 __ Move(index_, r0);
2825 if (embed_mode == PART_OF_IC_HANDLER) {
2826 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2827 LoadWithVectorDescriptor::SlotRegister(), object_);
2831 // Reload the instance type.
2832 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2833 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2834 call_helper.AfterCall(masm);
2835 // If index is still not a smi, it must be out of range.
2836 __ JumpIfNotSmi(index_, index_out_of_range_);
2837 // Otherwise, return to the fast path.
2838 __ jmp(&got_smi_index_);
2840 // Call runtime. We get here when the receiver is a string and the
2841 // index is a number, but the code of getting the actual character
2842 // is too complex (e.g., when the string needs to be flattened).
2843 __ bind(&call_runtime_);
2844 call_helper.BeforeCall(masm);
2846 __ Push(object_, index_);
2847 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2848 __ Move(result_, r0);
2849 call_helper.AfterCall(masm);
2852 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2856 // -------------------------------------------------------------------------
2857 // StringCharFromCodeGenerator
2859 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2860 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2861 STATIC_ASSERT(kSmiTag == 0);
2862 STATIC_ASSERT(kSmiShiftSize == 0);
2863 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2864 __ tst(code_, Operand(kSmiTagMask |
2865 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
2866 __ b(ne, &slow_case_);
2868 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2869 // At this point code register contains smi tagged one-byte char code.
2870 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
2871 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
2872 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
2873 __ b(eq, &slow_case_);
2878 void StringCharFromCodeGenerator::GenerateSlow(
2879 MacroAssembler* masm,
2880 const RuntimeCallHelper& call_helper) {
2881 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2883 __ bind(&slow_case_);
2884 call_helper.BeforeCall(masm);
2886 __ CallRuntime(Runtime::kCharFromCode, 1);
2887 __ Move(result_, r0);
2888 call_helper.AfterCall(masm);
2891 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2895 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
2898 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2903 String::Encoding encoding) {
2904 if (FLAG_debug_code) {
2905 // Check that destination is word aligned.
2906 __ tst(dest, Operand(kPointerAlignmentMask));
2907 __ Check(eq, kDestinationOfCopyNotAligned);
2910 // Assumes word reads and writes are little endian.
2911 // Nothing to do for zero characters.
2913 if (encoding == String::TWO_BYTE_ENCODING) {
2914 __ add(count, count, Operand(count), SetCC);
2917 Register limit = count; // Read until dest equals this.
2918 __ add(limit, dest, Operand(count));
2920 Label loop_entry, loop;
2921 // Copy bytes from src to dest until dest hits limit.
2924 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
2925 __ strb(scratch, MemOperand(dest, 1, PostIndex));
2926 __ bind(&loop_entry);
2927 __ cmp(dest, Operand(limit));
2934 void SubStringStub::Generate(MacroAssembler* masm) {
2937 // Stack frame on entry.
2938 // lr: return address
2943 // This stub is called from the native-call %_SubString(...), so
2944 // nothing can be assumed about the arguments. It is tested that:
2945 // "string" is a sequential string,
2946 // both "from" and "to" are smis, and
2947 // 0 <= from <= to <= string.length.
2948 // If any of these assumptions fail, we call the runtime system.
2950 const int kToOffset = 0 * kPointerSize;
2951 const int kFromOffset = 1 * kPointerSize;
2952 const int kStringOffset = 2 * kPointerSize;
2954 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
2955 STATIC_ASSERT(kFromOffset == kToOffset + 4);
2956 STATIC_ASSERT(kSmiTag == 0);
2957 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2959 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
2960 // instead because we bail out on non-smi values: ROR and ASR are equivalent
2961 // for smis but they set the flags in a way that's easier to optimize.
2962 __ mov(r2, Operand(r2, ROR, 1), SetCC);
2963 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
2964 // If either to or from had the smi tag bit set, then C is set now, and N
2965 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
2966 // We want to bailout to runtime here if From is negative. In that case, the
2967 // next instruction is not executed and we fall through to bailing out to
2969 // Executed if both r2 and r3 are untagged integers.
2970 __ sub(r2, r2, Operand(r3), SetCC, cc);
2971 // One of the above un-smis or the above SUB could have set N==1.
2972 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
2974 // Make sure first argument is a string.
2975 __ ldr(r0, MemOperand(sp, kStringOffset));
2976 __ JumpIfSmi(r0, &runtime);
2977 Condition is_string = masm->IsObjectStringType(r0, r1);
2978 __ b(NegateCondition(is_string), &runtime);
2981 __ cmp(r2, Operand(1));
2982 __ b(eq, &single_char);
2984 // Short-cut for the case of trivial substring.
2986 // r0: original string
2987 // r2: result string length
2988 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
2989 __ cmp(r2, Operand(r4, ASR, 1));
2990 // Return original string.
2991 __ b(eq, &return_r0);
2992 // Longer than original string's length or negative: unsafe arguments.
2994 // Shorter than original string's length: an actual substring.
2996 // Deal with different string types: update the index if necessary
2997 // and put the underlying string into r5.
2998 // r0: original string
2999 // r1: instance type
3001 // r3: from index (untagged)
3002 Label underlying_unpacked, sliced_string, seq_or_external_string;
3003 // If the string is not indirect, it can only be sequential or external.
3004 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3005 STATIC_ASSERT(kIsIndirectStringMask != 0);
3006 __ tst(r1, Operand(kIsIndirectStringMask));
3007 __ b(eq, &seq_or_external_string);
3009 __ tst(r1, Operand(kSlicedNotConsMask));
3010 __ b(ne, &sliced_string);
3011 // Cons string. Check whether it is flat, then fetch first part.
3012 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
3013 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
3015 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
3016 // Update instance type.
3017 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3018 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3019 __ jmp(&underlying_unpacked);
3021 __ bind(&sliced_string);
3022 // Sliced string. Fetch parent and correct start index by offset.
3023 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3024 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3025 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
3026 // Update instance type.
3027 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3028 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3029 __ jmp(&underlying_unpacked);
3031 __ bind(&seq_or_external_string);
3032 // Sequential or external string. Just move string to the expected register.
3035 __ bind(&underlying_unpacked);
3037 if (FLAG_string_slices) {
3039 // r5: underlying subject string
3040 // r1: instance type of underlying subject string
3042 // r3: adjusted start index (untagged)
3043 __ cmp(r2, Operand(SlicedString::kMinLength));
3044 // Short slice. Copy instead of slicing.
3045 __ b(lt, ©_routine);
3046 // Allocate new sliced string. At this point we do not reload the instance
3047 // type including the string encoding because we simply rely on the info
3048 // provided by the original string. It does not matter if the original
3049 // string's encoding is wrong because we always have to recheck encoding of
3050 // the newly created string's parent anyways due to externalized strings.
3051 Label two_byte_slice, set_slice_header;
3052 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3053 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3054 __ tst(r1, Operand(kStringEncodingMask));
3055 __ b(eq, &two_byte_slice);
3056 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
3057 __ jmp(&set_slice_header);
3058 __ bind(&two_byte_slice);
3059 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
3060 __ bind(&set_slice_header);
3061 __ mov(r3, Operand(r3, LSL, 1));
3062 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3063 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3066 __ bind(©_routine);
3069 // r5: underlying subject string
3070 // r1: instance type of underlying subject string
3072 // r3: adjusted start index (untagged)
3073 Label two_byte_sequential, sequential_string, allocate_result;
3074 STATIC_ASSERT(kExternalStringTag != 0);
3075 STATIC_ASSERT(kSeqStringTag == 0);
3076 __ tst(r1, Operand(kExternalStringTag));
3077 __ b(eq, &sequential_string);
3079 // Handle external string.
3080 // Rule out short external strings.
3081 STATIC_ASSERT(kShortExternalStringTag != 0);
3082 __ tst(r1, Operand(kShortExternalStringTag));
3084 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
3085 // r5 already points to the first character of underlying string.
3086 __ jmp(&allocate_result);
3088 __ bind(&sequential_string);
3089 // Locate first character of underlying subject string.
3090 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3091 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3093 __ bind(&allocate_result);
3094 // Sequential acii string. Allocate the result.
3095 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3096 __ tst(r1, Operand(kStringEncodingMask));
3097 __ b(eq, &two_byte_sequential);
3099 // Allocate and copy the resulting one-byte string.
3100 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
3102 // Locate first character of substring to copy.
3104 // Locate first character of result.
3105 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3107 // r0: result string
3108 // r1: first character of result string
3109 // r2: result string length
3110 // r5: first character of substring to copy
3111 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3112 StringHelper::GenerateCopyCharacters(
3113 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
3116 // Allocate and copy the resulting two-byte string.
3117 __ bind(&two_byte_sequential);
3118 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
3120 // Locate first character of substring to copy.
3121 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3122 __ add(r5, r5, Operand(r3, LSL, 1));
3123 // Locate first character of result.
3124 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3126 // r0: result string.
3127 // r1: first character of result.
3128 // r2: result length.
3129 // r5: first character of substring to copy.
3130 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3131 StringHelper::GenerateCopyCharacters(
3132 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
3134 __ bind(&return_r0);
3135 Counters* counters = isolate()->counters();
3136 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
3140 // Just jump to runtime to create the sub string.
3142 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3144 __ bind(&single_char);
3145 // r0: original string
3146 // r1: instance type
3148 // r3: from index (untagged)
3150 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
3151 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3152 generator.GenerateFast(masm);
3155 generator.SkipSlow(masm, &runtime);
3159 void ToNumberStub::Generate(MacroAssembler* masm) {
3160 // The ToNumber stub takes one argument in r0.
3162 __ JumpIfNotSmi(r0, ¬_smi);
3166 __ CompareObjectType(r0, r1, r1, HEAP_NUMBER_TYPE);
3168 // r1: receiver instance type
3171 Label not_string, slow_string;
3172 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
3173 __ b(hs, ¬_string);
3174 // Check if string has a cached array index.
3175 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
3176 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
3177 __ b(ne, &slow_string);
3178 __ IndexFromHash(r2, r0);
3180 __ bind(&slow_string);
3181 __ push(r0); // Push argument.
3182 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3183 __ bind(¬_string);
3186 __ cmp(r1, Operand(ODDBALL_TYPE));
3187 __ b(ne, ¬_oddball);
3188 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
3190 __ bind(¬_oddball);
3192 __ push(r0); // Push argument.
3193 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3197 void ToStringStub::Generate(MacroAssembler* masm) {
3198 // The ToString stub takes one argument in r0.
3200 __ JumpIfSmi(r0, &is_number);
3202 __ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE);
3204 // r1: receiver instance type
3207 Label not_heap_number;
3208 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
3209 __ b(ne, ¬_heap_number);
3210 __ bind(&is_number);
3211 NumberToStringStub stub(isolate());
3212 __ TailCallStub(&stub);
3213 __ bind(¬_heap_number);
3216 __ cmp(r1, Operand(ODDBALL_TYPE));
3217 __ b(ne, ¬_oddball);
3218 __ ldr(r0, FieldMemOperand(r0, Oddball::kToStringOffset));
3220 __ bind(¬_oddball);
3222 __ push(r0); // Push argument.
3223 __ TailCallRuntime(Runtime::kToString, 1, 1);
3227 void StringHelper::GenerateFlatOneByteStringEquals(
3228 MacroAssembler* masm, Register left, Register right, Register scratch1,
3229 Register scratch2, Register scratch3) {
3230 Register length = scratch1;
3233 Label strings_not_equal, check_zero_length;
3234 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
3235 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3236 __ cmp(length, scratch2);
3237 __ b(eq, &check_zero_length);
3238 __ bind(&strings_not_equal);
3239 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
3242 // Check if the length is zero.
3243 Label compare_chars;
3244 __ bind(&check_zero_length);
3245 STATIC_ASSERT(kSmiTag == 0);
3246 __ cmp(length, Operand::Zero());
3247 __ b(ne, &compare_chars);
3248 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3251 // Compare characters.
3252 __ bind(&compare_chars);
3253 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3254 &strings_not_equal);
3256 // Characters are equal.
3257 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3262 void StringHelper::GenerateCompareFlatOneByteStrings(
3263 MacroAssembler* masm, Register left, Register right, Register scratch1,
3264 Register scratch2, Register scratch3, Register scratch4) {
3265 Label result_not_equal, compare_lengths;
3266 // Find minimum length and length difference.
3267 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3268 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3269 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
3270 Register length_delta = scratch3;
3271 __ mov(scratch1, scratch2, LeaveCC, gt);
3272 Register min_length = scratch1;
3273 STATIC_ASSERT(kSmiTag == 0);
3274 __ cmp(min_length, Operand::Zero());
3275 __ b(eq, &compare_lengths);
3278 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3279 scratch4, &result_not_equal);
3281 // Compare lengths - strings up to min-length are equal.
3282 __ bind(&compare_lengths);
3283 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3284 // Use length_delta as result if it's zero.
3285 __ mov(r0, Operand(length_delta), SetCC);
3286 __ bind(&result_not_equal);
3287 // Conditionally update the result based either on length_delta or
3288 // the last comparion performed in the loop above.
3289 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
3290 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
3295 void StringHelper::GenerateOneByteCharsCompareLoop(
3296 MacroAssembler* masm, Register left, Register right, Register length,
3297 Register scratch1, Register scratch2, Label* chars_not_equal) {
3298 // Change index to run from -length to -1 by adding length to string
3299 // start. This means that loop ends when index reaches zero, which
3300 // doesn't need an additional compare.
3301 __ SmiUntag(length);
3302 __ add(scratch1, length,
3303 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3304 __ add(left, left, Operand(scratch1));
3305 __ add(right, right, Operand(scratch1));
3306 __ rsb(length, length, Operand::Zero());
3307 Register index = length; // index = -length;
3312 __ ldrb(scratch1, MemOperand(left, index));
3313 __ ldrb(scratch2, MemOperand(right, index));
3314 __ cmp(scratch1, scratch2);
3315 __ b(ne, chars_not_equal);
3316 __ add(index, index, Operand(1), SetCC);
3321 void StringCompareStub::Generate(MacroAssembler* masm) {
3322 // ----------- S t a t e -------------
3325 // -- lr : return address
3326 // -----------------------------------
3327 __ AssertString(r1);
3328 __ AssertString(r0);
3332 __ b(ne, ¬_same);
3333 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3334 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r1,
3340 // Check that both objects are sequential one-byte strings.
3342 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
3344 // Compare flat one-byte strings natively.
3345 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
3347 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
3349 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3350 // tagged as a small integer.
3353 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3357 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3358 // ----------- S t a t e -------------
3361 // -- lr : return address
3362 // -----------------------------------
3364 // Load r2 with the allocation site. We stick an undefined dummy value here
3365 // and replace it with the real allocation site later when we instantiate this
3366 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3367 __ Move(r2, handle(isolate()->heap()->undefined_value()));
3369 // Make sure that we actually patched the allocation site.
3370 if (FLAG_debug_code) {
3371 __ tst(r2, Operand(kSmiTagMask));
3372 __ Assert(ne, kExpectedAllocationSite);
3374 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3375 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3378 __ Assert(eq, kExpectedAllocationSite);
3381 // Tail call into the stub that handles binary operations with allocation
3383 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3384 __ TailCallStub(&stub);
3388 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3389 DCHECK(state() == CompareICState::SMI);
3392 __ JumpIfNotSmi(r2, &miss);
3394 if (GetCondition() == eq) {
3395 // For equality we do not care about the sign of the result.
3396 __ sub(r0, r0, r1, SetCC);
3398 // Untag before subtracting to avoid handling overflow.
3400 __ sub(r0, r1, Operand::SmiUntag(r0));
3409 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3410 DCHECK(state() == CompareICState::NUMBER);
3413 Label unordered, maybe_undefined1, maybe_undefined2;
3416 if (left() == CompareICState::SMI) {
3417 __ JumpIfNotSmi(r1, &miss);
3419 if (right() == CompareICState::SMI) {
3420 __ JumpIfNotSmi(r0, &miss);
3423 // Inlining the double comparison and falling back to the general compare
3424 // stub if NaN is involved.
3425 // Load left and right operand.
3426 Label done, left, left_smi, right_smi;
3427 __ JumpIfSmi(r0, &right_smi);
3428 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3430 __ sub(r2, r0, Operand(kHeapObjectTag));
3431 __ vldr(d1, r2, HeapNumber::kValueOffset);
3433 __ bind(&right_smi);
3434 __ SmiToDouble(d1, r0);
3437 __ JumpIfSmi(r1, &left_smi);
3438 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3440 __ sub(r2, r1, Operand(kHeapObjectTag));
3441 __ vldr(d0, r2, HeapNumber::kValueOffset);
3444 __ SmiToDouble(d0, r1);
3447 // Compare operands.
3448 __ VFPCompareAndSetFlags(d0, d1);
3450 // Don't base result on status bits when a NaN is involved.
3451 __ b(vs, &unordered);
3453 // Return a result of -1, 0, or 1, based on status bits.
3454 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
3455 __ mov(r0, Operand(LESS), LeaveCC, lt);
3456 __ mov(r0, Operand(GREATER), LeaveCC, gt);
3459 __ bind(&unordered);
3460 __ bind(&generic_stub);
3461 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3462 CompareICState::GENERIC, CompareICState::GENERIC);
3463 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3465 __ bind(&maybe_undefined1);
3466 if (Token::IsOrderedRelationalCompareOp(op())) {
3467 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3469 __ JumpIfSmi(r1, &unordered);
3470 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3471 __ b(ne, &maybe_undefined2);
3475 __ bind(&maybe_undefined2);
3476 if (Token::IsOrderedRelationalCompareOp(op())) {
3477 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3478 __ b(eq, &unordered);
3486 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3487 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3490 // Registers containing left and right operands respectively.
3492 Register right = r0;
3496 // Check that both operands are heap objects.
3497 __ JumpIfEitherSmi(left, right, &miss);
3499 // Check that both operands are internalized strings.
3500 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3501 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3502 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3503 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3504 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3505 __ orr(tmp1, tmp1, Operand(tmp2));
3506 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3509 // Internalized strings are compared by identity.
3510 __ cmp(left, right);
3511 // Make sure r0 is non-zero. At this point input operands are
3512 // guaranteed to be non-zero.
3513 DCHECK(right.is(r0));
3514 STATIC_ASSERT(EQUAL == 0);
3515 STATIC_ASSERT(kSmiTag == 0);
3516 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3524 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3525 DCHECK(state() == CompareICState::UNIQUE_NAME);
3526 DCHECK(GetCondition() == eq);
3529 // Registers containing left and right operands respectively.
3531 Register right = r0;
3535 // Check that both operands are heap objects.
3536 __ JumpIfEitherSmi(left, right, &miss);
3538 // Check that both operands are unique names. This leaves the instance
3539 // types loaded in tmp1 and tmp2.
3540 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3541 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3542 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3543 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3545 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3546 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3548 // Unique names are compared by identity.
3549 __ cmp(left, right);
3550 // Make sure r0 is non-zero. At this point input operands are
3551 // guaranteed to be non-zero.
3552 DCHECK(right.is(r0));
3553 STATIC_ASSERT(EQUAL == 0);
3554 STATIC_ASSERT(kSmiTag == 0);
3555 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3563 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3564 DCHECK(state() == CompareICState::STRING);
3567 bool equality = Token::IsEqualityOp(op());
3569 // Registers containing left and right operands respectively.
3571 Register right = r0;
3577 // Check that both operands are heap objects.
3578 __ JumpIfEitherSmi(left, right, &miss);
3580 // Check that both operands are strings. This leaves the instance
3581 // types loaded in tmp1 and tmp2.
3582 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3583 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3584 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3585 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3586 STATIC_ASSERT(kNotStringTag != 0);
3587 __ orr(tmp3, tmp1, tmp2);
3588 __ tst(tmp3, Operand(kIsNotStringMask));
3591 // Fast check for identical strings.
3592 __ cmp(left, right);
3593 STATIC_ASSERT(EQUAL == 0);
3594 STATIC_ASSERT(kSmiTag == 0);
3595 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3598 // Handle not identical strings.
3600 // Check that both strings are internalized strings. If they are, we're done
3601 // because we already know they are not identical. We know they are both
3604 DCHECK(GetCondition() == eq);
3605 STATIC_ASSERT(kInternalizedTag == 0);
3606 __ orr(tmp3, tmp1, Operand(tmp2));
3607 __ tst(tmp3, Operand(kIsNotInternalizedMask));
3608 // Make sure r0 is non-zero. At this point input operands are
3609 // guaranteed to be non-zero.
3610 DCHECK(right.is(r0));
3614 // Check that both strings are sequential one-byte.
3616 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3619 // Compare flat one-byte strings. Returns when done.
3621 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3624 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3628 // Handle more complex cases in runtime.
3630 __ Push(left, right);
3632 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3634 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3642 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3643 DCHECK(state() == CompareICState::OBJECT);
3645 __ and_(r2, r1, Operand(r0));
3646 __ JumpIfSmi(r2, &miss);
3648 __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
3650 __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
3653 DCHECK(GetCondition() == eq);
3654 __ sub(r0, r0, Operand(r1));
3662 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3664 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3665 __ and_(r2, r1, Operand(r0));
3666 __ JumpIfSmi(r2, &miss);
3667 __ GetWeakValue(r4, cell);
3668 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3669 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
3675 __ sub(r0, r0, Operand(r1));
3683 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3685 // Call the runtime system in a fresh internal frame.
3686 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3688 __ Push(lr, r1, r0);
3689 __ mov(ip, Operand(Smi::FromInt(op())));
3691 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3692 // Compute the entry point of the rewritten stub.
3693 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3694 // Restore registers.
3703 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3704 // Place the return address on the stack, making the call
3705 // GC safe. The RegExp backend also relies on this.
3706 __ str(lr, MemOperand(sp, 0));
3707 __ blx(ip); // Call the C++ function.
3708 __ VFPEnsureFPSCRState(r2);
3709 __ ldr(pc, MemOperand(sp, 0));
3713 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3716 reinterpret_cast<intptr_t>(GetCode().location());
3717 __ Move(ip, target);
3718 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3719 __ blx(lr); // Call the stub.
3723 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3727 Register properties,
3729 Register scratch0) {
3730 DCHECK(name->IsUniqueName());
3731 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3732 // not equal to the name and kProbes-th slot is not used (its name is the
3733 // undefined value), it guarantees the hash table doesn't contain the
3734 // property. It's true even if some slots represent deleted properties
3735 // (their names are the hole value).
3736 for (int i = 0; i < kInlinedProbes; i++) {
3737 // scratch0 points to properties hash.
3738 // Compute the masked index: (hash + i + i * i) & mask.
3739 Register index = scratch0;
3740 // Capacity is smi 2^n.
3741 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3742 __ sub(index, index, Operand(1));
3743 __ and_(index, index, Operand(
3744 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3746 // Scale the index by multiplying by the entry size.
3747 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3748 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3750 Register entity_name = scratch0;
3751 // Having undefined at this place means the name is not contained.
3752 STATIC_ASSERT(kSmiTagSize == 1);
3753 Register tmp = properties;
3754 __ add(tmp, properties, Operand(index, LSL, 1));
3755 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3757 DCHECK(!tmp.is(entity_name));
3758 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3759 __ cmp(entity_name, tmp);
3762 // Load the hole ready for use below:
3763 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3765 // Stop if found the property.
3766 __ cmp(entity_name, Operand(Handle<Name>(name)));
3770 __ cmp(entity_name, tmp);
3773 // Check if the entry name is not a unique name.
3774 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3775 __ ldrb(entity_name,
3776 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3777 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3780 // Restore the properties.
3782 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3785 const int spill_mask =
3786 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3787 r2.bit() | r1.bit() | r0.bit());
3789 __ stm(db_w, sp, spill_mask);
3790 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3791 __ mov(r1, Operand(Handle<Name>(name)));
3792 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3794 __ cmp(r0, Operand::Zero());
3795 __ ldm(ia_w, sp, spill_mask);
3802 // Probe the name dictionary in the |elements| register. Jump to the
3803 // |done| label if a property with the given name is found. Jump to
3804 // the |miss| label otherwise.
3805 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
3806 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3812 Register scratch2) {
3813 DCHECK(!elements.is(scratch1));
3814 DCHECK(!elements.is(scratch2));
3815 DCHECK(!name.is(scratch1));
3816 DCHECK(!name.is(scratch2));
3818 __ AssertName(name);
3820 // Compute the capacity mask.
3821 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
3822 __ SmiUntag(scratch1);
3823 __ sub(scratch1, scratch1, Operand(1));
3825 // Generate an unrolled loop that performs a few probes before
3826 // giving up. Measurements done on Gmail indicate that 2 probes
3827 // cover ~93% of loads from dictionaries.
3828 for (int i = 0; i < kInlinedProbes; i++) {
3829 // Compute the masked index: (hash + i + i * i) & mask.
3830 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3832 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3833 // the hash in a separate instruction. The value hash + i + i * i is right
3834 // shifted in the following and instruction.
3835 DCHECK(NameDictionary::GetProbeOffset(i) <
3836 1 << (32 - Name::kHashFieldOffset));
3837 __ add(scratch2, scratch2, Operand(
3838 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3840 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
3842 // Scale the index by multiplying by the entry size.
3843 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3844 // scratch2 = scratch2 * 3.
3845 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3847 // Check if the key is identical to the name.
3848 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3849 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3850 __ cmp(name, Operand(ip));
3854 const int spill_mask =
3855 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3856 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3857 ~(scratch1.bit() | scratch2.bit());
3859 __ stm(db_w, sp, spill_mask);
3861 DCHECK(!elements.is(r1));
3863 __ Move(r0, elements);
3865 __ Move(r0, elements);
3868 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
3870 __ cmp(r0, Operand::Zero());
3871 __ mov(scratch2, Operand(r2));
3872 __ ldm(ia_w, sp, spill_mask);
3879 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3880 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3881 // we cannot call anything that could cause a GC from this stub.
3883 // result: NameDictionary to probe
3885 // dictionary: NameDictionary to probe.
3886 // index: will hold an index of entry if lookup is successful.
3887 // might alias with result_.
3889 // result_ is zero if lookup failed, non zero otherwise.
3891 Register result = r0;
3892 Register dictionary = r0;
3894 Register index = r2;
3897 Register undefined = r5;
3898 Register entry_key = r6;
3900 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3902 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
3904 __ sub(mask, mask, Operand(1));
3906 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
3908 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3910 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3911 // Compute the masked index: (hash + i + i * i) & mask.
3912 // Capacity is smi 2^n.
3914 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3915 // the hash in a separate instruction. The value hash + i + i * i is right
3916 // shifted in the following and instruction.
3917 DCHECK(NameDictionary::GetProbeOffset(i) <
3918 1 << (32 - Name::kHashFieldOffset));
3919 __ add(index, hash, Operand(
3920 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3922 __ mov(index, Operand(hash));
3924 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
3926 // Scale the index by multiplying by the entry size.
3927 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3928 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3930 STATIC_ASSERT(kSmiTagSize == 1);
3931 __ add(index, dictionary, Operand(index, LSL, 2));
3932 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
3934 // Having undefined at this place means the name is not contained.
3935 __ cmp(entry_key, Operand(undefined));
3936 __ b(eq, ¬_in_dictionary);
3938 // Stop if found the property.
3939 __ cmp(entry_key, Operand(key));
3940 __ b(eq, &in_dictionary);
3942 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3943 // Check if the entry name is not a unique name.
3944 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3946 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
3947 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
3951 __ bind(&maybe_in_dictionary);
3952 // If we are doing negative lookup then probing failure should be
3953 // treated as a lookup success. For positive lookup probing failure
3954 // should be treated as lookup failure.
3955 if (mode() == POSITIVE_LOOKUP) {
3956 __ mov(result, Operand::Zero());
3960 __ bind(&in_dictionary);
3961 __ mov(result, Operand(1));
3964 __ bind(¬_in_dictionary);
3965 __ mov(result, Operand::Zero());
3970 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3972 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3974 // Hydrogen code stubs need stub2 at snapshot time.
3975 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3980 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
3981 // the value has just been written into the object, now this stub makes sure
3982 // we keep the GC informed. The word in the object where the value has been
3983 // written is in the address register.
3984 void RecordWriteStub::Generate(MacroAssembler* masm) {
3985 Label skip_to_incremental_noncompacting;
3986 Label skip_to_incremental_compacting;
3988 // The first two instructions are generated with labels so as to get the
3989 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3990 // forth between a compare instructions (a nop in this position) and the
3991 // real branch when we start and stop incremental heap marking.
3992 // See RecordWriteStub::Patch for details.
3994 // Block literal pool emission, as the position of these two instructions
3995 // is assumed by the patching code.
3996 Assembler::BlockConstPoolScope block_const_pool(masm);
3997 __ b(&skip_to_incremental_noncompacting);
3998 __ b(&skip_to_incremental_compacting);
4001 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4002 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4003 MacroAssembler::kReturnAtEnd);
4007 __ bind(&skip_to_incremental_noncompacting);
4008 GenerateIncremental(masm, INCREMENTAL);
4010 __ bind(&skip_to_incremental_compacting);
4011 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4013 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4014 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4015 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4016 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
4017 PatchBranchIntoNop(masm, 0);
4018 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4022 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4025 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4026 Label dont_need_remembered_set;
4028 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4029 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4031 &dont_need_remembered_set);
4033 __ CheckPageFlag(regs_.object(),
4035 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4037 &dont_need_remembered_set);
4039 // First notify the incremental marker if necessary, then update the
4041 CheckNeedsToInformIncrementalMarker(
4042 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4043 InformIncrementalMarker(masm);
4044 regs_.Restore(masm);
4045 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4046 MacroAssembler::kReturnAtEnd);
4048 __ bind(&dont_need_remembered_set);
4051 CheckNeedsToInformIncrementalMarker(
4052 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4053 InformIncrementalMarker(masm);
4054 regs_.Restore(masm);
4059 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4060 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4061 int argument_count = 3;
4062 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4064 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4065 DCHECK(!address.is(regs_.object()));
4066 DCHECK(!address.is(r0));
4067 __ Move(address, regs_.address());
4068 __ Move(r0, regs_.object());
4069 __ Move(r1, address);
4070 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4072 AllowExternalCallThatCantCauseGC scope(masm);
4074 ExternalReference::incremental_marking_record_write_function(isolate()),
4076 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4080 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4081 MacroAssembler* masm,
4082 OnNoNeedToInformIncrementalMarker on_no_need,
4085 Label need_incremental;
4086 Label need_incremental_pop_scratch;
4088 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4089 __ ldr(regs_.scratch1(),
4090 MemOperand(regs_.scratch0(),
4091 MemoryChunk::kWriteBarrierCounterOffset));
4092 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4093 __ str(regs_.scratch1(),
4094 MemOperand(regs_.scratch0(),
4095 MemoryChunk::kWriteBarrierCounterOffset));
4096 __ b(mi, &need_incremental);
4098 // Let's look at the color of the object: If it is not black we don't have
4099 // to inform the incremental marker.
4100 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4102 regs_.Restore(masm);
4103 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4104 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4105 MacroAssembler::kReturnAtEnd);
4112 // Get the value from the slot.
4113 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4115 if (mode == INCREMENTAL_COMPACTION) {
4116 Label ensure_not_white;
4118 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4119 regs_.scratch1(), // Scratch.
4120 MemoryChunk::kEvacuationCandidateMask,
4124 __ CheckPageFlag(regs_.object(),
4125 regs_.scratch1(), // Scratch.
4126 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4130 __ bind(&ensure_not_white);
4133 // We need extra registers for this, so we push the object and the address
4134 // register temporarily.
4135 __ Push(regs_.object(), regs_.address());
4136 __ EnsureNotWhite(regs_.scratch0(), // The value.
4137 regs_.scratch1(), // Scratch.
4138 regs_.object(), // Scratch.
4139 regs_.address(), // Scratch.
4140 &need_incremental_pop_scratch);
4141 __ Pop(regs_.object(), regs_.address());
4143 regs_.Restore(masm);
4144 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4145 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4146 MacroAssembler::kReturnAtEnd);
4151 __ bind(&need_incremental_pop_scratch);
4152 __ Pop(regs_.object(), regs_.address());
4154 __ bind(&need_incremental);
4156 // Fall through when we need to inform the incremental marker.
4160 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4161 // ----------- S t a t e -------------
4162 // -- r0 : element value to store
4163 // -- r3 : element index as smi
4164 // -- sp[0] : array literal index in function as smi
4165 // -- sp[4] : array literal
4166 // clobbers r1, r2, r4
4167 // -----------------------------------
4170 Label double_elements;
4172 Label slow_elements;
4173 Label fast_elements;
4175 // Get array literal index, array literal and its map.
4176 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4177 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4178 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4180 __ CheckFastElements(r2, r5, &double_elements);
4181 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4182 __ JumpIfSmi(r0, &smi_element);
4183 __ CheckFastSmiElements(r2, r5, &fast_elements);
4185 // Store into the array literal requires a elements transition. Call into
4187 __ bind(&slow_elements);
4189 __ Push(r1, r3, r0);
4190 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4191 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4193 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4195 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4196 __ bind(&fast_elements);
4197 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4198 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4199 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4200 __ str(r0, MemOperand(r6, 0));
4201 // Update the write barrier for the array store.
4202 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4203 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4206 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4207 // and value is Smi.
4208 __ bind(&smi_element);
4209 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4210 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4211 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4214 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4215 __ bind(&double_elements);
4216 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4217 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
4222 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4223 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4224 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4225 int parameter_count_offset =
4226 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4227 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4228 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4229 __ add(r1, r1, Operand(1));
4231 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4232 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4238 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4239 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4240 LoadICStub stub(isolate(), state());
4241 stub.GenerateForTrampoline(masm);
4245 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4246 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4247 KeyedLoadICStub stub(isolate(), state());
4248 stub.GenerateForTrampoline(masm);
4252 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4253 EmitLoadTypeFeedbackVector(masm, r2);
4254 CallICStub stub(isolate(), state());
4255 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4259 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4262 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4263 GenerateImpl(masm, true);
4267 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4268 Register receiver_map, Register scratch1,
4269 Register scratch2, bool is_polymorphic,
4271 // feedback initially contains the feedback array
4272 Label next_loop, prepare_next;
4273 Label start_polymorphic;
4275 Register cached_map = scratch1;
4278 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4279 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4280 __ cmp(receiver_map, cached_map);
4281 __ b(ne, &start_polymorphic);
4282 // found, now call handler.
4283 Register handler = feedback;
4284 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4285 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4288 Register length = scratch2;
4289 __ bind(&start_polymorphic);
4290 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4291 if (!is_polymorphic) {
4292 // If the IC could be monomorphic we have to make sure we don't go past the
4293 // end of the feedback array.
4294 __ cmp(length, Operand(Smi::FromInt(2)));
4298 Register too_far = length;
4299 Register pointer_reg = feedback;
4301 // +-----+------+------+-----+-----+ ... ----+
4302 // | map | len | wm0 | h0 | wm1 | hN |
4303 // +-----+------+------+-----+-----+ ... ----+
4307 // pointer_reg too_far
4308 // aka feedback scratch2
4309 // also need receiver_map
4310 // use cached_map (scratch1) to look in the weak map values.
4311 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
4312 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4313 __ add(pointer_reg, feedback,
4314 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4316 __ bind(&next_loop);
4317 __ ldr(cached_map, MemOperand(pointer_reg));
4318 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4319 __ cmp(receiver_map, cached_map);
4320 __ b(ne, &prepare_next);
4321 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
4322 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4324 __ bind(&prepare_next);
4325 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4326 __ cmp(pointer_reg, too_far);
4327 __ b(lt, &next_loop);
4329 // We exhausted our array of map handler pairs.
4334 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4335 Register receiver_map, Register feedback,
4336 Register vector, Register slot,
4337 Register scratch, Label* compare_map,
4338 Label* load_smi_map, Label* try_array) {
4339 __ JumpIfSmi(receiver, load_smi_map);
4340 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4341 __ bind(compare_map);
4342 Register cached_map = scratch;
4343 // Move the weak map into the weak_cell register.
4344 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4345 __ cmp(cached_map, receiver_map);
4346 __ b(ne, try_array);
4347 Register handler = feedback;
4348 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
4350 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4351 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4355 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4356 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4357 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
4358 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4359 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4360 Register feedback = r4;
4361 Register receiver_map = r5;
4362 Register scratch1 = r6;
4364 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4365 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4367 // Try to quickly handle the monomorphic case without knowing for sure
4368 // if we have a weak cell in feedback. We do know it's safe to look
4369 // at WeakCell::kValueOffset.
4370 Label try_array, load_smi_map, compare_map;
4371 Label not_array, miss;
4372 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4373 scratch1, &compare_map, &load_smi_map, &try_array);
4375 // Is it a fixed array?
4376 __ bind(&try_array);
4377 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4378 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4379 __ b(ne, ¬_array);
4380 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4382 __ bind(¬_array);
4383 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4385 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4386 Code::ComputeHandlerFlags(Code::LOAD_IC));
4387 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4388 receiver, name, feedback,
4389 receiver_map, scratch1, r9);
4392 LoadIC::GenerateMiss(masm);
4394 __ bind(&load_smi_map);
4395 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4396 __ jmp(&compare_map);
4400 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4401 GenerateImpl(masm, false);
4405 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4406 GenerateImpl(masm, true);
4410 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4411 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4412 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
4413 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4414 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4415 Register feedback = r4;
4416 Register receiver_map = r5;
4417 Register scratch1 = r6;
4419 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4420 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4422 // Try to quickly handle the monomorphic case without knowing for sure
4423 // if we have a weak cell in feedback. We do know it's safe to look
4424 // at WeakCell::kValueOffset.
4425 Label try_array, load_smi_map, compare_map;
4426 Label not_array, miss;
4427 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4428 scratch1, &compare_map, &load_smi_map, &try_array);
4430 __ bind(&try_array);
4431 // Is it a fixed array?
4432 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4433 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4434 __ b(ne, ¬_array);
4436 // We have a polymorphic element handler.
4437 Label polymorphic, try_poly_name;
4438 __ bind(&polymorphic);
4439 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4441 __ bind(¬_array);
4443 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4444 __ b(ne, &try_poly_name);
4445 Handle<Code> megamorphic_stub =
4446 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4447 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4449 __ bind(&try_poly_name);
4450 // We might have a name in feedback, and a fixed array in the next slot.
4451 __ cmp(key, feedback);
4453 // If the name comparison succeeded, we know we have a fixed array with
4454 // at least one map/handler pair.
4455 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4457 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4458 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, false, &miss);
4461 KeyedLoadIC::GenerateMiss(masm);
4463 __ bind(&load_smi_map);
4464 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4465 __ jmp(&compare_map);
4469 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4470 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4471 VectorStoreICStub stub(isolate(), state());
4472 stub.GenerateForTrampoline(masm);
4476 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4477 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4478 VectorKeyedStoreICStub stub(isolate(), state());
4479 stub.GenerateForTrampoline(masm);
4483 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4484 GenerateImpl(masm, false);
4488 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4489 GenerateImpl(masm, true);
4493 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4494 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4495 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4496 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4497 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4498 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4499 Register feedback = r5;
4500 Register receiver_map = r6;
4501 Register scratch1 = r9;
4503 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4504 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4506 // Try to quickly handle the monomorphic case without knowing for sure
4507 // if we have a weak cell in feedback. We do know it's safe to look
4508 // at WeakCell::kValueOffset.
4509 Label try_array, load_smi_map, compare_map;
4510 Label not_array, miss;
4511 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4512 scratch1, &compare_map, &load_smi_map, &try_array);
4514 // Is it a fixed array?
4515 __ bind(&try_array);
4516 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4517 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4518 __ b(ne, ¬_array);
4520 // We are using register r8, which is used for the embedded constant pool
4521 // when FLAG_enable_embedded_constant_pool is true.
4522 DCHECK(!FLAG_enable_embedded_constant_pool);
4523 Register scratch2 = r8;
4524 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4527 __ bind(¬_array);
4528 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4530 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4531 Code::ComputeHandlerFlags(Code::STORE_IC));
4532 masm->isolate()->stub_cache()->GenerateProbe(
4533 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4534 scratch1, scratch2);
4537 StoreIC::GenerateMiss(masm);
4539 __ bind(&load_smi_map);
4540 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4541 __ jmp(&compare_map);
4545 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4546 GenerateImpl(masm, false);
4550 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4551 GenerateImpl(masm, true);
4555 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4556 Register receiver_map, Register scratch1,
4557 Register scratch2, Label* miss) {
4558 // feedback initially contains the feedback array
4559 Label next_loop, prepare_next;
4560 Label start_polymorphic;
4561 Label transition_call;
4563 Register cached_map = scratch1;
4564 Register too_far = scratch2;
4565 Register pointer_reg = feedback;
4566 __ ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4568 // +-----+------+------+-----+-----+-----+ ... ----+
4569 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4570 // +-----+------+------+-----+-----+ ----+ ... ----+
4574 // pointer_reg too_far
4575 // aka feedback scratch2
4576 // also need receiver_map
4577 // use cached_map (scratch1) to look in the weak map values.
4578 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(too_far));
4579 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4580 __ add(pointer_reg, feedback,
4581 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4583 __ bind(&next_loop);
4584 __ ldr(cached_map, MemOperand(pointer_reg));
4585 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4586 __ cmp(receiver_map, cached_map);
4587 __ b(ne, &prepare_next);
4588 // Is it a transitioning store?
4589 __ ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4590 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4591 __ b(ne, &transition_call);
4592 __ ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4593 __ add(pc, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4595 __ bind(&transition_call);
4596 __ ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4597 __ JumpIfSmi(too_far, miss);
4599 __ ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4601 // Load the map into the correct register.
4602 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4603 __ mov(feedback, too_far);
4605 __ add(pc, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4607 __ bind(&prepare_next);
4608 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4609 __ cmp(pointer_reg, too_far);
4610 __ b(lt, &next_loop);
4612 // We exhausted our array of map handler pairs.
4617 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4618 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4619 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4620 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4621 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4622 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4623 Register feedback = r5;
4624 Register receiver_map = r6;
4625 Register scratch1 = r9;
4627 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4628 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4630 // Try to quickly handle the monomorphic case without knowing for sure
4631 // if we have a weak cell in feedback. We do know it's safe to look
4632 // at WeakCell::kValueOffset.
4633 Label try_array, load_smi_map, compare_map;
4634 Label not_array, miss;
4635 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4636 scratch1, &compare_map, &load_smi_map, &try_array);
4638 __ bind(&try_array);
4639 // Is it a fixed array?
4640 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4641 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4642 __ b(ne, ¬_array);
4644 // We have a polymorphic element handler.
4645 Label polymorphic, try_poly_name;
4646 __ bind(&polymorphic);
4648 // We are using register r8, which is used for the embedded constant pool
4649 // when FLAG_enable_embedded_constant_pool is true.
4650 DCHECK(!FLAG_enable_embedded_constant_pool);
4651 Register scratch2 = r8;
4653 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4656 __ bind(¬_array);
4658 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4659 __ b(ne, &try_poly_name);
4660 Handle<Code> megamorphic_stub =
4661 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4662 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4664 __ bind(&try_poly_name);
4665 // We might have a name in feedback, and a fixed array in the next slot.
4666 __ cmp(key, feedback);
4668 // If the name comparison succeeded, we know we have a fixed array with
4669 // at least one map/handler pair.
4670 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4672 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4673 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4677 KeyedStoreIC::GenerateMiss(masm);
4679 __ bind(&load_smi_map);
4680 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4681 __ jmp(&compare_map);
4685 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4686 if (masm->isolate()->function_entry_hook() != NULL) {
4687 ProfileEntryHookStub stub(masm->isolate());
4688 PredictableCodeSizeScope predictable(masm);
4689 predictable.ExpectSize(masm->CallStubSize(&stub) +
4690 2 * Assembler::kInstrSize);
4698 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4699 // The entry hook is a "push lr" instruction, followed by a call.
4700 const int32_t kReturnAddressDistanceFromFunctionStart =
4701 3 * Assembler::kInstrSize;
4703 // This should contain all kCallerSaved registers.
4704 const RegList kSavedRegs =
4711 // We also save lr, so the count here is one higher than the mask indicates.
4712 const int32_t kNumSavedRegs = 7;
4714 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4716 // Save all caller-save registers as this may be called from anywhere.
4717 __ stm(db_w, sp, kSavedRegs | lr.bit());
4719 // Compute the function's address for the first argument.
4720 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4722 // The caller's return address is above the saved temporaries.
4723 // Grab that for the second argument to the hook.
4724 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4726 // Align the stack if necessary.
4727 int frame_alignment = masm->ActivationFrameAlignment();
4728 if (frame_alignment > kPointerSize) {
4730 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4731 __ and_(sp, sp, Operand(-frame_alignment));
4734 #if V8_HOST_ARCH_ARM
4735 int32_t entry_hook =
4736 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4737 __ mov(ip, Operand(entry_hook));
4739 // Under the simulator we need to indirect the entry hook through a
4740 // trampoline function at a known address.
4741 // It additionally takes an isolate as a third parameter
4742 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4744 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4745 __ mov(ip, Operand(ExternalReference(&dispatcher,
4746 ExternalReference::BUILTIN_CALL,
4751 // Restore the stack pointer if needed.
4752 if (frame_alignment > kPointerSize) {
4756 // Also pop pc to get Ret(0).
4757 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4762 static void CreateArrayDispatch(MacroAssembler* masm,
4763 AllocationSiteOverrideMode mode) {
4764 if (mode == DISABLE_ALLOCATION_SITES) {
4765 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4766 __ TailCallStub(&stub);
4767 } else if (mode == DONT_OVERRIDE) {
4768 int last_index = GetSequenceIndexFromFastElementsKind(
4769 TERMINAL_FAST_ELEMENTS_KIND);
4770 for (int i = 0; i <= last_index; ++i) {
4771 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4772 __ cmp(r3, Operand(kind));
4773 T stub(masm->isolate(), kind);
4774 __ TailCallStub(&stub, eq);
4777 // If we reached this point there is a problem.
4778 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4785 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4786 AllocationSiteOverrideMode mode) {
4787 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4788 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4789 // r0 - number of arguments
4790 // r1 - constructor?
4791 // sp[0] - last argument
4792 Label normal_sequence;
4793 if (mode == DONT_OVERRIDE) {
4794 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4795 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4796 STATIC_ASSERT(FAST_ELEMENTS == 2);
4797 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4798 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4799 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4801 // is the low bit set? If so, we are holey and that is good.
4802 __ tst(r3, Operand(1));
4803 __ b(ne, &normal_sequence);
4806 // look at the first argument
4807 __ ldr(r5, MemOperand(sp, 0));
4808 __ cmp(r5, Operand::Zero());
4809 __ b(eq, &normal_sequence);
4811 if (mode == DISABLE_ALLOCATION_SITES) {
4812 ElementsKind initial = GetInitialFastElementsKind();
4813 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4815 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4817 DISABLE_ALLOCATION_SITES);
4818 __ TailCallStub(&stub_holey);
4820 __ bind(&normal_sequence);
4821 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4823 DISABLE_ALLOCATION_SITES);
4824 __ TailCallStub(&stub);
4825 } else if (mode == DONT_OVERRIDE) {
4826 // We are going to create a holey array, but our kind is non-holey.
4827 // Fix kind and retry (only if we have an allocation site in the slot).
4828 __ add(r3, r3, Operand(1));
4830 if (FLAG_debug_code) {
4831 __ ldr(r5, FieldMemOperand(r2, 0));
4832 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4833 __ Assert(eq, kExpectedAllocationSite);
4836 // Save the resulting elements kind in type info. We can't just store r3
4837 // in the AllocationSite::transition_info field because elements kind is
4838 // restricted to a portion of the field...upper bits need to be left alone.
4839 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4840 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4841 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4842 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4844 __ bind(&normal_sequence);
4845 int last_index = GetSequenceIndexFromFastElementsKind(
4846 TERMINAL_FAST_ELEMENTS_KIND);
4847 for (int i = 0; i <= last_index; ++i) {
4848 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4849 __ cmp(r3, Operand(kind));
4850 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4851 __ TailCallStub(&stub, eq);
4854 // If we reached this point there is a problem.
4855 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4863 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4864 int to_index = GetSequenceIndexFromFastElementsKind(
4865 TERMINAL_FAST_ELEMENTS_KIND);
4866 for (int i = 0; i <= to_index; ++i) {
4867 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4868 T stub(isolate, kind);
4870 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4871 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4878 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4879 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4881 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4883 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4888 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4890 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4891 for (int i = 0; i < 2; i++) {
4892 // For internal arrays we only need a few things
4893 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4895 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4897 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4903 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4904 MacroAssembler* masm,
4905 AllocationSiteOverrideMode mode) {
4906 if (argument_count() == ANY) {
4907 Label not_zero_case, not_one_case;
4909 __ b(ne, ¬_zero_case);
4910 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4912 __ bind(¬_zero_case);
4913 __ cmp(r0, Operand(1));
4914 __ b(gt, ¬_one_case);
4915 CreateArrayDispatchOneArgument(masm, mode);
4917 __ bind(¬_one_case);
4918 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4919 } else if (argument_count() == NONE) {
4920 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4921 } else if (argument_count() == ONE) {
4922 CreateArrayDispatchOneArgument(masm, mode);
4923 } else if (argument_count() == MORE_THAN_ONE) {
4924 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4931 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4932 // ----------- S t a t e -------------
4933 // -- r0 : argc (only if argument_count() == ANY)
4934 // -- r1 : constructor
4935 // -- r2 : AllocationSite or undefined
4936 // -- r3 : original constructor
4937 // -- sp[0] : return address
4938 // -- sp[4] : last argument
4939 // -----------------------------------
4941 if (FLAG_debug_code) {
4942 // The array construct code is only set for the global and natives
4943 // builtin Array functions which always have maps.
4945 // Initial map for the builtin Array function should be a map.
4946 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4947 // Will both indicate a NULL and a Smi.
4948 __ tst(r4, Operand(kSmiTagMask));
4949 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4950 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4951 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4953 // We should either have undefined in r2 or a valid AllocationSite
4954 __ AssertUndefinedOrAllocationSite(r2, r4);
4959 __ b(ne, &subclassing);
4962 // Get the elements kind and case on that.
4963 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4966 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4968 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4969 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4970 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4973 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4975 __ bind(&subclassing);
4980 switch (argument_count()) {
4983 __ add(r0, r0, Operand(2));
4986 __ mov(r0, Operand(2));
4989 __ mov(r0, Operand(3));
4993 __ JumpToExternalReference(
4994 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
4998 void InternalArrayConstructorStub::GenerateCase(
4999 MacroAssembler* masm, ElementsKind kind) {
5000 __ cmp(r0, Operand(1));
5002 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5003 __ TailCallStub(&stub0, lo);
5005 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5006 __ TailCallStub(&stubN, hi);
5008 if (IsFastPackedElementsKind(kind)) {
5009 // We might need to create a holey array
5010 // look at the first argument
5011 __ ldr(r3, MemOperand(sp, 0));
5012 __ cmp(r3, Operand::Zero());
5014 InternalArraySingleArgumentConstructorStub
5015 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5016 __ TailCallStub(&stub1_holey, ne);
5019 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5020 __ TailCallStub(&stub1);
5024 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5025 // ----------- S t a t e -------------
5027 // -- r1 : constructor
5028 // -- sp[0] : return address
5029 // -- sp[4] : last argument
5030 // -----------------------------------
5032 if (FLAG_debug_code) {
5033 // The array construct code is only set for the global and natives
5034 // builtin Array functions which always have maps.
5036 // Initial map for the builtin Array function should be a map.
5037 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5038 // Will both indicate a NULL and a Smi.
5039 __ tst(r3, Operand(kSmiTagMask));
5040 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5041 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
5042 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5045 // Figure out the right elements kind
5046 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5047 // Load the map's "bit field 2" into |result|. We only need the first byte,
5048 // but the following bit field extraction takes care of that anyway.
5049 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
5050 // Retrieve elements_kind from bit field 2.
5051 __ DecodeField<Map::ElementsKindBits>(r3);
5053 if (FLAG_debug_code) {
5055 __ cmp(r3, Operand(FAST_ELEMENTS));
5057 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
5059 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5063 Label fast_elements_case;
5064 __ cmp(r3, Operand(FAST_ELEMENTS));
5065 __ b(eq, &fast_elements_case);
5066 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5068 __ bind(&fast_elements_case);
5069 GenerateCase(masm, FAST_ELEMENTS);
5073 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5074 Register context = cp;
5075 Register result = r0;
5078 // Go up the context chain to the script context.
5079 for (int i = 0; i < depth(); ++i) {
5080 __ ldr(result, ContextOperand(context, Context::PREVIOUS_INDEX));
5084 // Load the PropertyCell value at the specified slot.
5085 __ add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5086 __ ldr(result, ContextOperand(result));
5087 __ ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5089 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5090 __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
5093 // Fallback to runtime.
5096 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5100 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5101 Register value = r0;
5105 Register cell_details = r4;
5106 Register cell_value = r5;
5107 Register cell_value_map = r6;
5108 Register scratch = r9;
5110 Register context = cp;
5111 Register context_temp = cell;
5113 Label fast_heapobject_case, fast_smi_case, slow_case;
5115 if (FLAG_debug_code) {
5116 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5117 __ Check(ne, kUnexpectedValue);
5120 // Go up the context chain to the script context.
5121 for (int i = 0; i < depth(); i++) {
5122 __ ldr(context_temp, ContextOperand(context, Context::PREVIOUS_INDEX));
5123 context = context_temp;
5126 // Load the PropertyCell at the specified slot.
5127 __ add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5128 __ ldr(cell, ContextOperand(cell));
5130 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5131 __ ldr(cell_details, FieldMemOperand(cell, PropertyCell::kDetailsOffset));
5132 __ SmiUntag(cell_details);
5133 __ and_(cell_details, cell_details,
5134 Operand(PropertyDetails::PropertyCellTypeField::kMask |
5135 PropertyDetails::KindField::kMask |
5136 PropertyDetails::kAttributesReadOnlyMask));
5138 // Check if PropertyCell holds mutable data.
5139 Label not_mutable_data;
5140 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5141 PropertyCellType::kMutable) |
5142 PropertyDetails::KindField::encode(kData)));
5143 __ b(ne, ¬_mutable_data);
5144 __ JumpIfSmi(value, &fast_smi_case);
5146 __ bind(&fast_heapobject_case);
5147 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5148 // RecordWriteField clobbers the value register, so we copy it before the
5150 __ mov(r4, Operand(value));
5151 __ RecordWriteField(cell, PropertyCell::kValueOffset, r4, scratch,
5152 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5156 __ bind(¬_mutable_data);
5157 // Check if PropertyCell value matches the new value (relevant for Constant,
5158 // ConstantType and Undefined cells).
5159 Label not_same_value;
5160 __ ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5161 __ cmp(cell_value, value);
5162 __ b(ne, ¬_same_value);
5164 // Make sure the PropertyCell is not marked READ_ONLY.
5165 __ tst(cell_details, Operand(PropertyDetails::kAttributesReadOnlyMask));
5166 __ b(ne, &slow_case);
5168 if (FLAG_debug_code) {
5170 // This can only be true for Constant, ConstantType and Undefined cells,
5171 // because we never store the_hole via this stub.
5172 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5173 PropertyCellType::kConstant) |
5174 PropertyDetails::KindField::encode(kData)));
5176 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5177 PropertyCellType::kConstantType) |
5178 PropertyDetails::KindField::encode(kData)));
5180 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5181 PropertyCellType::kUndefined) |
5182 PropertyDetails::KindField::encode(kData)));
5183 __ Check(eq, kUnexpectedValue);
5187 __ bind(¬_same_value);
5189 // Check if PropertyCell contains data with constant type (and is not
5191 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5192 PropertyCellType::kConstantType) |
5193 PropertyDetails::KindField::encode(kData)));
5194 __ b(ne, &slow_case);
5196 // Now either both old and new values must be smis or both must be heap
5197 // objects with same map.
5198 Label value_is_heap_object;
5199 __ JumpIfNotSmi(value, &value_is_heap_object);
5200 __ JumpIfNotSmi(cell_value, &slow_case);
5201 // Old and new values are smis, no need for a write barrier here.
5202 __ bind(&fast_smi_case);
5203 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5206 __ bind(&value_is_heap_object);
5207 __ JumpIfSmi(cell_value, &slow_case);
5209 __ ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5210 __ ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5211 __ cmp(cell_value_map, scratch);
5212 __ b(eq, &fast_heapobject_case);
5214 // Fallback to runtime.
5215 __ bind(&slow_case);
5217 __ Push(slot, value);
5218 __ TailCallRuntime(is_strict(language_mode())
5219 ? Runtime::kStoreGlobalViaContext_Strict
5220 : Runtime::kStoreGlobalViaContext_Sloppy,
5225 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5226 return ref0.address() - ref1.address();
5230 // Calls an API function. Allocates HandleScope, extracts returned value
5231 // from handle and propagates exceptions. Restores context. stack_space
5232 // - space to be unwound on exit (includes the call JS arguments space and
5233 // the additional space allocated for the fast call).
5234 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5235 Register function_address,
5236 ExternalReference thunk_ref,
5238 MemOperand* stack_space_operand,
5239 MemOperand return_value_operand,
5240 MemOperand* context_restore_operand) {
5241 Isolate* isolate = masm->isolate();
5242 ExternalReference next_address =
5243 ExternalReference::handle_scope_next_address(isolate);
5244 const int kNextOffset = 0;
5245 const int kLimitOffset = AddressOffset(
5246 ExternalReference::handle_scope_limit_address(isolate), next_address);
5247 const int kLevelOffset = AddressOffset(
5248 ExternalReference::handle_scope_level_address(isolate), next_address);
5250 DCHECK(function_address.is(r1) || function_address.is(r2));
5252 Label profiler_disabled;
5253 Label end_profiler_check;
5254 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5255 __ ldrb(r9, MemOperand(r9, 0));
5256 __ cmp(r9, Operand(0));
5257 __ b(eq, &profiler_disabled);
5259 // Additional parameter is the address of the actual callback.
5260 __ mov(r3, Operand(thunk_ref));
5261 __ jmp(&end_profiler_check);
5263 __ bind(&profiler_disabled);
5264 __ Move(r3, function_address);
5265 __ bind(&end_profiler_check);
5267 // Allocate HandleScope in callee-save registers.
5268 __ mov(r9, Operand(next_address));
5269 __ ldr(r4, MemOperand(r9, kNextOffset));
5270 __ ldr(r5, MemOperand(r9, kLimitOffset));
5271 __ ldr(r6, MemOperand(r9, kLevelOffset));
5272 __ add(r6, r6, Operand(1));
5273 __ str(r6, MemOperand(r9, kLevelOffset));
5275 if (FLAG_log_timer_events) {
5276 FrameScope frame(masm, StackFrame::MANUAL);
5277 __ PushSafepointRegisters();
5278 __ PrepareCallCFunction(1, r0);
5279 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5280 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5282 __ PopSafepointRegisters();
5285 // Native call returns to the DirectCEntry stub which redirects to the
5286 // return address pushed on stack (could have moved after GC).
5287 // DirectCEntry stub itself is generated early and never moves.
5288 DirectCEntryStub stub(isolate);
5289 stub.GenerateCall(masm, r3);
5291 if (FLAG_log_timer_events) {
5292 FrameScope frame(masm, StackFrame::MANUAL);
5293 __ PushSafepointRegisters();
5294 __ PrepareCallCFunction(1, r0);
5295 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5296 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5298 __ PopSafepointRegisters();
5301 Label promote_scheduled_exception;
5302 Label delete_allocated_handles;
5303 Label leave_exit_frame;
5304 Label return_value_loaded;
5306 // load value from ReturnValue
5307 __ ldr(r0, return_value_operand);
5308 __ bind(&return_value_loaded);
5309 // No more valid handles (the result handle was the last one). Restore
5310 // previous handle scope.
5311 __ str(r4, MemOperand(r9, kNextOffset));
5312 if (__ emit_debug_code()) {
5313 __ ldr(r1, MemOperand(r9, kLevelOffset));
5315 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5317 __ sub(r6, r6, Operand(1));
5318 __ str(r6, MemOperand(r9, kLevelOffset));
5319 __ ldr(ip, MemOperand(r9, kLimitOffset));
5321 __ b(ne, &delete_allocated_handles);
5323 // Leave the API exit frame.
5324 __ bind(&leave_exit_frame);
5325 bool restore_context = context_restore_operand != NULL;
5326 if (restore_context) {
5327 __ ldr(cp, *context_restore_operand);
5329 // LeaveExitFrame expects unwind space to be in a register.
5330 if (stack_space_operand != NULL) {
5331 __ ldr(r4, *stack_space_operand);
5333 __ mov(r4, Operand(stack_space));
5335 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5337 // Check if the function scheduled an exception.
5338 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5339 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5340 __ ldr(r5, MemOperand(ip));
5342 __ b(ne, &promote_scheduled_exception);
5346 // Re-throw by promoting a scheduled exception.
5347 __ bind(&promote_scheduled_exception);
5348 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5350 // HandleScope limit has changed. Delete allocated extensions.
5351 __ bind(&delete_allocated_handles);
5352 __ str(r5, MemOperand(r9, kLimitOffset));
5354 __ PrepareCallCFunction(1, r5);
5355 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5356 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5359 __ jmp(&leave_exit_frame);
5363 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5364 const ParameterCount& argc,
5365 bool return_first_arg,
5366 bool call_data_undefined) {
5367 // ----------- S t a t e -------------
5369 // -- r4 : call_data
5371 // -- r1 : api_function_address
5372 // -- r3 : number of arguments if argc is a register
5375 // -- sp[0] : last argument
5377 // -- sp[(argc - 1)* 4] : first argument
5378 // -- sp[argc * 4] : receiver
5379 // -----------------------------------
5381 Register callee = r0;
5382 Register call_data = r4;
5383 Register holder = r2;
5384 Register api_function_address = r1;
5385 Register context = cp;
5387 typedef FunctionCallbackArguments FCA;
5389 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5390 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5391 STATIC_ASSERT(FCA::kDataIndex == 4);
5392 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5393 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5394 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5395 STATIC_ASSERT(FCA::kHolderIndex == 0);
5396 STATIC_ASSERT(FCA::kArgsLength == 7);
5398 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5402 // load context from callee
5403 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5411 Register scratch = call_data;
5412 if (!call_data_undefined) {
5413 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5417 // return value default
5420 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5425 // Prepare arguments.
5426 __ mov(scratch, sp);
5428 // Allocate the v8::Arguments structure in the arguments' space since
5429 // it's not controlled by GC.
5430 const int kApiStackSpace = 4;
5432 FrameScope frame_scope(masm, StackFrame::MANUAL);
5433 __ EnterExitFrame(false, kApiStackSpace);
5435 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5436 // r0 = FunctionCallbackInfo&
5437 // Arguments is after the return address.
5438 __ add(r0, sp, Operand(1 * kPointerSize));
5439 // FunctionCallbackInfo::implicit_args_
5440 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
5441 if (argc.is_immediate()) {
5442 // FunctionCallbackInfo::values_
5444 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5445 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5446 // FunctionCallbackInfo::length_ = argc
5447 __ mov(ip, Operand(argc.immediate()));
5448 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5449 // FunctionCallbackInfo::is_construct_call_ = 0
5450 __ mov(ip, Operand::Zero());
5451 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5453 // FunctionCallbackInfo::values_
5454 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5455 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5456 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5457 // FunctionCallbackInfo::length_ = argc
5458 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5459 // FunctionCallbackInfo::is_construct_call_
5460 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5461 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5462 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5465 ExternalReference thunk_ref =
5466 ExternalReference::invoke_function_callback(masm->isolate());
5468 AllowExternalCallThatCantCauseGC scope(masm);
5469 MemOperand context_restore_operand(
5470 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5471 // Stores return the first js argument
5472 int return_value_offset = 0;
5473 if (return_first_arg) {
5474 return_value_offset = 2 + FCA::kArgsLength;
5476 return_value_offset = 2 + FCA::kReturnValueOffset;
5478 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5479 int stack_space = 0;
5480 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5481 MemOperand* stack_space_operand = &is_construct_call_operand;
5482 if (argc.is_immediate()) {
5483 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5484 stack_space_operand = NULL;
5486 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5487 stack_space_operand, return_value_operand,
5488 &context_restore_operand);
5492 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5493 bool call_data_undefined = this->call_data_undefined();
5494 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
5495 call_data_undefined);
5499 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5500 bool is_store = this->is_store();
5501 int argc = this->argc();
5502 bool call_data_undefined = this->call_data_undefined();
5503 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5504 call_data_undefined);
5508 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5509 // ----------- S t a t e -------------
5511 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5513 // -- r2 : api_function_address
5514 // -----------------------------------
5516 Register api_function_address = ApiGetterDescriptor::function_address();
5517 DCHECK(api_function_address.is(r2));
5519 __ mov(r0, sp); // r0 = Handle<Name>
5520 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
5522 const int kApiStackSpace = 1;
5523 FrameScope frame_scope(masm, StackFrame::MANUAL);
5524 __ EnterExitFrame(false, kApiStackSpace);
5526 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5527 // r1 (internal::Object** args_) as the data.
5528 __ str(r1, MemOperand(sp, 1 * kPointerSize));
5529 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
5531 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5533 ExternalReference thunk_ref =
5534 ExternalReference::invoke_accessor_getter_callback(isolate());
5535 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5536 kStackUnwindSpace, NULL,
5537 MemOperand(fp, 6 * kPointerSize), NULL);
5543 } // namespace internal
5546 #endif // V8_TARGET_ARCH_ARM