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 if (Token::IsEqualityOp(op())) {
3676 __ sub(r0, r0, Operand(r1));
3678 } else if (is_strong(strength())) {
3679 __ TailCallRuntime(Runtime::kThrowStrongModeImplicitConversion, 0, 1);
3681 if (op() == Token::LT || op() == Token::LTE) {
3682 __ mov(r2, Operand(Smi::FromInt(GREATER)));
3684 __ mov(r2, Operand(Smi::FromInt(LESS)));
3686 __ Push(r1, r0, r2);
3687 __ TailCallRuntime(Runtime::kCompare, 3, 1);
3695 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3697 // Call the runtime system in a fresh internal frame.
3698 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3700 __ Push(lr, r1, r0);
3701 __ mov(ip, Operand(Smi::FromInt(op())));
3703 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3704 // Compute the entry point of the rewritten stub.
3705 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3706 // Restore registers.
3715 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3716 // Place the return address on the stack, making the call
3717 // GC safe. The RegExp backend also relies on this.
3718 __ str(lr, MemOperand(sp, 0));
3719 __ blx(ip); // Call the C++ function.
3720 __ VFPEnsureFPSCRState(r2);
3721 __ ldr(pc, MemOperand(sp, 0));
3725 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3728 reinterpret_cast<intptr_t>(GetCode().location());
3729 __ Move(ip, target);
3730 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3731 __ blx(lr); // Call the stub.
3735 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3739 Register properties,
3741 Register scratch0) {
3742 DCHECK(name->IsUniqueName());
3743 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3744 // not equal to the name and kProbes-th slot is not used (its name is the
3745 // undefined value), it guarantees the hash table doesn't contain the
3746 // property. It's true even if some slots represent deleted properties
3747 // (their names are the hole value).
3748 for (int i = 0; i < kInlinedProbes; i++) {
3749 // scratch0 points to properties hash.
3750 // Compute the masked index: (hash + i + i * i) & mask.
3751 Register index = scratch0;
3752 // Capacity is smi 2^n.
3753 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3754 __ sub(index, index, Operand(1));
3755 __ and_(index, index, Operand(
3756 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3758 // Scale the index by multiplying by the entry size.
3759 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3760 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3762 Register entity_name = scratch0;
3763 // Having undefined at this place means the name is not contained.
3764 STATIC_ASSERT(kSmiTagSize == 1);
3765 Register tmp = properties;
3766 __ add(tmp, properties, Operand(index, LSL, 1));
3767 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3769 DCHECK(!tmp.is(entity_name));
3770 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3771 __ cmp(entity_name, tmp);
3774 // Load the hole ready for use below:
3775 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3777 // Stop if found the property.
3778 __ cmp(entity_name, Operand(Handle<Name>(name)));
3782 __ cmp(entity_name, tmp);
3785 // Check if the entry name is not a unique name.
3786 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3787 __ ldrb(entity_name,
3788 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3789 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3792 // Restore the properties.
3794 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3797 const int spill_mask =
3798 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3799 r2.bit() | r1.bit() | r0.bit());
3801 __ stm(db_w, sp, spill_mask);
3802 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3803 __ mov(r1, Operand(Handle<Name>(name)));
3804 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3806 __ cmp(r0, Operand::Zero());
3807 __ ldm(ia_w, sp, spill_mask);
3814 // Probe the name dictionary in the |elements| register. Jump to the
3815 // |done| label if a property with the given name is found. Jump to
3816 // the |miss| label otherwise.
3817 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
3818 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3824 Register scratch2) {
3825 DCHECK(!elements.is(scratch1));
3826 DCHECK(!elements.is(scratch2));
3827 DCHECK(!name.is(scratch1));
3828 DCHECK(!name.is(scratch2));
3830 __ AssertName(name);
3832 // Compute the capacity mask.
3833 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
3834 __ SmiUntag(scratch1);
3835 __ sub(scratch1, scratch1, Operand(1));
3837 // Generate an unrolled loop that performs a few probes before
3838 // giving up. Measurements done on Gmail indicate that 2 probes
3839 // cover ~93% of loads from dictionaries.
3840 for (int i = 0; i < kInlinedProbes; i++) {
3841 // Compute the masked index: (hash + i + i * i) & mask.
3842 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3844 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3845 // the hash in a separate instruction. The value hash + i + i * i is right
3846 // shifted in the following and instruction.
3847 DCHECK(NameDictionary::GetProbeOffset(i) <
3848 1 << (32 - Name::kHashFieldOffset));
3849 __ add(scratch2, scratch2, Operand(
3850 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3852 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
3854 // Scale the index by multiplying by the entry size.
3855 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3856 // scratch2 = scratch2 * 3.
3857 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3859 // Check if the key is identical to the name.
3860 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3861 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3862 __ cmp(name, Operand(ip));
3866 const int spill_mask =
3867 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3868 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3869 ~(scratch1.bit() | scratch2.bit());
3871 __ stm(db_w, sp, spill_mask);
3873 DCHECK(!elements.is(r1));
3875 __ Move(r0, elements);
3877 __ Move(r0, elements);
3880 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
3882 __ cmp(r0, Operand::Zero());
3883 __ mov(scratch2, Operand(r2));
3884 __ ldm(ia_w, sp, spill_mask);
3891 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3892 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3893 // we cannot call anything that could cause a GC from this stub.
3895 // result: NameDictionary to probe
3897 // dictionary: NameDictionary to probe.
3898 // index: will hold an index of entry if lookup is successful.
3899 // might alias with result_.
3901 // result_ is zero if lookup failed, non zero otherwise.
3903 Register result = r0;
3904 Register dictionary = r0;
3906 Register index = r2;
3909 Register undefined = r5;
3910 Register entry_key = r6;
3912 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3914 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
3916 __ sub(mask, mask, Operand(1));
3918 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
3920 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3922 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3923 // Compute the masked index: (hash + i + i * i) & mask.
3924 // Capacity is smi 2^n.
3926 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3927 // the hash in a separate instruction. The value hash + i + i * i is right
3928 // shifted in the following and instruction.
3929 DCHECK(NameDictionary::GetProbeOffset(i) <
3930 1 << (32 - Name::kHashFieldOffset));
3931 __ add(index, hash, Operand(
3932 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3934 __ mov(index, Operand(hash));
3936 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
3938 // Scale the index by multiplying by the entry size.
3939 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3940 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3942 STATIC_ASSERT(kSmiTagSize == 1);
3943 __ add(index, dictionary, Operand(index, LSL, 2));
3944 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
3946 // Having undefined at this place means the name is not contained.
3947 __ cmp(entry_key, Operand(undefined));
3948 __ b(eq, ¬_in_dictionary);
3950 // Stop if found the property.
3951 __ cmp(entry_key, Operand(key));
3952 __ b(eq, &in_dictionary);
3954 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3955 // Check if the entry name is not a unique name.
3956 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3958 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
3959 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
3963 __ bind(&maybe_in_dictionary);
3964 // If we are doing negative lookup then probing failure should be
3965 // treated as a lookup success. For positive lookup probing failure
3966 // should be treated as lookup failure.
3967 if (mode() == POSITIVE_LOOKUP) {
3968 __ mov(result, Operand::Zero());
3972 __ bind(&in_dictionary);
3973 __ mov(result, Operand(1));
3976 __ bind(¬_in_dictionary);
3977 __ mov(result, Operand::Zero());
3982 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3984 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3986 // Hydrogen code stubs need stub2 at snapshot time.
3987 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3992 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
3993 // the value has just been written into the object, now this stub makes sure
3994 // we keep the GC informed. The word in the object where the value has been
3995 // written is in the address register.
3996 void RecordWriteStub::Generate(MacroAssembler* masm) {
3997 Label skip_to_incremental_noncompacting;
3998 Label skip_to_incremental_compacting;
4000 // The first two instructions are generated with labels so as to get the
4001 // offset fixed up correctly by the bind(Label*) call. We patch it back and
4002 // forth between a compare instructions (a nop in this position) and the
4003 // real branch when we start and stop incremental heap marking.
4004 // See RecordWriteStub::Patch for details.
4006 // Block literal pool emission, as the position of these two instructions
4007 // is assumed by the patching code.
4008 Assembler::BlockConstPoolScope block_const_pool(masm);
4009 __ b(&skip_to_incremental_noncompacting);
4010 __ b(&skip_to_incremental_compacting);
4013 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4014 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4015 MacroAssembler::kReturnAtEnd);
4019 __ bind(&skip_to_incremental_noncompacting);
4020 GenerateIncremental(masm, INCREMENTAL);
4022 __ bind(&skip_to_incremental_compacting);
4023 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4025 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4026 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4027 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4028 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
4029 PatchBranchIntoNop(masm, 0);
4030 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4034 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4037 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4038 Label dont_need_remembered_set;
4040 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4041 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4043 &dont_need_remembered_set);
4045 __ CheckPageFlag(regs_.object(),
4047 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4049 &dont_need_remembered_set);
4051 // First notify the incremental marker if necessary, then update the
4053 CheckNeedsToInformIncrementalMarker(
4054 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4055 InformIncrementalMarker(masm);
4056 regs_.Restore(masm);
4057 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4058 MacroAssembler::kReturnAtEnd);
4060 __ bind(&dont_need_remembered_set);
4063 CheckNeedsToInformIncrementalMarker(
4064 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4065 InformIncrementalMarker(masm);
4066 regs_.Restore(masm);
4071 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4072 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4073 int argument_count = 3;
4074 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4076 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4077 DCHECK(!address.is(regs_.object()));
4078 DCHECK(!address.is(r0));
4079 __ Move(address, regs_.address());
4080 __ Move(r0, regs_.object());
4081 __ Move(r1, address);
4082 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4084 AllowExternalCallThatCantCauseGC scope(masm);
4086 ExternalReference::incremental_marking_record_write_function(isolate()),
4088 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4092 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4093 MacroAssembler* masm,
4094 OnNoNeedToInformIncrementalMarker on_no_need,
4097 Label need_incremental;
4098 Label need_incremental_pop_scratch;
4100 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4101 __ ldr(regs_.scratch1(),
4102 MemOperand(regs_.scratch0(),
4103 MemoryChunk::kWriteBarrierCounterOffset));
4104 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4105 __ str(regs_.scratch1(),
4106 MemOperand(regs_.scratch0(),
4107 MemoryChunk::kWriteBarrierCounterOffset));
4108 __ b(mi, &need_incremental);
4110 // Let's look at the color of the object: If it is not black we don't have
4111 // to inform the incremental marker.
4112 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4114 regs_.Restore(masm);
4115 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4116 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4117 MacroAssembler::kReturnAtEnd);
4124 // Get the value from the slot.
4125 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4127 if (mode == INCREMENTAL_COMPACTION) {
4128 Label ensure_not_white;
4130 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4131 regs_.scratch1(), // Scratch.
4132 MemoryChunk::kEvacuationCandidateMask,
4136 __ CheckPageFlag(regs_.object(),
4137 regs_.scratch1(), // Scratch.
4138 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4142 __ bind(&ensure_not_white);
4145 // We need extra registers for this, so we push the object and the address
4146 // register temporarily.
4147 __ Push(regs_.object(), regs_.address());
4148 __ EnsureNotWhite(regs_.scratch0(), // The value.
4149 regs_.scratch1(), // Scratch.
4150 regs_.object(), // Scratch.
4151 regs_.address(), // Scratch.
4152 &need_incremental_pop_scratch);
4153 __ Pop(regs_.object(), regs_.address());
4155 regs_.Restore(masm);
4156 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4157 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4158 MacroAssembler::kReturnAtEnd);
4163 __ bind(&need_incremental_pop_scratch);
4164 __ Pop(regs_.object(), regs_.address());
4166 __ bind(&need_incremental);
4168 // Fall through when we need to inform the incremental marker.
4172 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4173 // ----------- S t a t e -------------
4174 // -- r0 : element value to store
4175 // -- r3 : element index as smi
4176 // -- sp[0] : array literal index in function as smi
4177 // -- sp[4] : array literal
4178 // clobbers r1, r2, r4
4179 // -----------------------------------
4182 Label double_elements;
4184 Label slow_elements;
4185 Label fast_elements;
4187 // Get array literal index, array literal and its map.
4188 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4189 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4190 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4192 __ CheckFastElements(r2, r5, &double_elements);
4193 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4194 __ JumpIfSmi(r0, &smi_element);
4195 __ CheckFastSmiElements(r2, r5, &fast_elements);
4197 // Store into the array literal requires a elements transition. Call into
4199 __ bind(&slow_elements);
4201 __ Push(r1, r3, r0);
4202 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4203 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4205 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4207 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4208 __ bind(&fast_elements);
4209 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4210 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4211 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4212 __ str(r0, MemOperand(r6, 0));
4213 // Update the write barrier for the array store.
4214 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4215 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4218 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4219 // and value is Smi.
4220 __ bind(&smi_element);
4221 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4222 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4223 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4226 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4227 __ bind(&double_elements);
4228 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4229 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
4234 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4235 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4236 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4237 int parameter_count_offset =
4238 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4239 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4240 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4241 __ add(r1, r1, Operand(1));
4243 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4244 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4250 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4251 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4252 LoadICStub stub(isolate(), state());
4253 stub.GenerateForTrampoline(masm);
4257 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4258 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4259 KeyedLoadICStub stub(isolate(), state());
4260 stub.GenerateForTrampoline(masm);
4264 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4265 EmitLoadTypeFeedbackVector(masm, r2);
4266 CallICStub stub(isolate(), state());
4267 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4271 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4274 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4275 GenerateImpl(masm, true);
4279 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4280 Register receiver_map, Register scratch1,
4281 Register scratch2, bool is_polymorphic,
4283 // feedback initially contains the feedback array
4284 Label next_loop, prepare_next;
4285 Label start_polymorphic;
4287 Register cached_map = scratch1;
4290 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4291 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4292 __ cmp(receiver_map, cached_map);
4293 __ b(ne, &start_polymorphic);
4294 // found, now call handler.
4295 Register handler = feedback;
4296 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4297 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4300 Register length = scratch2;
4301 __ bind(&start_polymorphic);
4302 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4303 if (!is_polymorphic) {
4304 // If the IC could be monomorphic we have to make sure we don't go past the
4305 // end of the feedback array.
4306 __ cmp(length, Operand(Smi::FromInt(2)));
4310 Register too_far = length;
4311 Register pointer_reg = feedback;
4313 // +-----+------+------+-----+-----+ ... ----+
4314 // | map | len | wm0 | h0 | wm1 | hN |
4315 // +-----+------+------+-----+-----+ ... ----+
4319 // pointer_reg too_far
4320 // aka feedback scratch2
4321 // also need receiver_map
4322 // use cached_map (scratch1) to look in the weak map values.
4323 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
4324 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4325 __ add(pointer_reg, feedback,
4326 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4328 __ bind(&next_loop);
4329 __ ldr(cached_map, MemOperand(pointer_reg));
4330 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4331 __ cmp(receiver_map, cached_map);
4332 __ b(ne, &prepare_next);
4333 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
4334 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4336 __ bind(&prepare_next);
4337 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4338 __ cmp(pointer_reg, too_far);
4339 __ b(lt, &next_loop);
4341 // We exhausted our array of map handler pairs.
4346 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4347 Register receiver_map, Register feedback,
4348 Register vector, Register slot,
4349 Register scratch, Label* compare_map,
4350 Label* load_smi_map, Label* try_array) {
4351 __ JumpIfSmi(receiver, load_smi_map);
4352 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4353 __ bind(compare_map);
4354 Register cached_map = scratch;
4355 // Move the weak map into the weak_cell register.
4356 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4357 __ cmp(cached_map, receiver_map);
4358 __ b(ne, try_array);
4359 Register handler = feedback;
4360 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
4362 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4363 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4367 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4368 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4369 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
4370 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4371 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4372 Register feedback = r4;
4373 Register receiver_map = r5;
4374 Register scratch1 = r6;
4376 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4377 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4379 // Try to quickly handle the monomorphic case without knowing for sure
4380 // if we have a weak cell in feedback. We do know it's safe to look
4381 // at WeakCell::kValueOffset.
4382 Label try_array, load_smi_map, compare_map;
4383 Label not_array, miss;
4384 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4385 scratch1, &compare_map, &load_smi_map, &try_array);
4387 // Is it a fixed array?
4388 __ bind(&try_array);
4389 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4390 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4391 __ b(ne, ¬_array);
4392 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4394 __ bind(¬_array);
4395 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4397 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4398 Code::ComputeHandlerFlags(Code::LOAD_IC));
4399 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4400 receiver, name, feedback,
4401 receiver_map, scratch1, r9);
4404 LoadIC::GenerateMiss(masm);
4406 __ bind(&load_smi_map);
4407 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4408 __ jmp(&compare_map);
4412 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4413 GenerateImpl(masm, false);
4417 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4418 GenerateImpl(masm, true);
4422 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4423 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4424 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
4425 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4426 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4427 Register feedback = r4;
4428 Register receiver_map = r5;
4429 Register scratch1 = r6;
4431 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4432 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4434 // Try to quickly handle the monomorphic case without knowing for sure
4435 // if we have a weak cell in feedback. We do know it's safe to look
4436 // at WeakCell::kValueOffset.
4437 Label try_array, load_smi_map, compare_map;
4438 Label not_array, miss;
4439 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4440 scratch1, &compare_map, &load_smi_map, &try_array);
4442 __ bind(&try_array);
4443 // Is it a fixed array?
4444 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4445 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4446 __ b(ne, ¬_array);
4448 // We have a polymorphic element handler.
4449 Label polymorphic, try_poly_name;
4450 __ bind(&polymorphic);
4451 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4453 __ bind(¬_array);
4455 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4456 __ b(ne, &try_poly_name);
4457 Handle<Code> megamorphic_stub =
4458 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4459 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4461 __ bind(&try_poly_name);
4462 // We might have a name in feedback, and a fixed array in the next slot.
4463 __ cmp(key, feedback);
4465 // If the name comparison succeeded, we know we have a fixed array with
4466 // at least one map/handler pair.
4467 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4469 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4470 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, false, &miss);
4473 KeyedLoadIC::GenerateMiss(masm);
4475 __ bind(&load_smi_map);
4476 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4477 __ jmp(&compare_map);
4481 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4482 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4483 VectorStoreICStub stub(isolate(), state());
4484 stub.GenerateForTrampoline(masm);
4488 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4489 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4490 VectorKeyedStoreICStub stub(isolate(), state());
4491 stub.GenerateForTrampoline(masm);
4495 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4496 GenerateImpl(masm, false);
4500 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4501 GenerateImpl(masm, true);
4505 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4506 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4507 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4508 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4509 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4510 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4511 Register feedback = r5;
4512 Register receiver_map = r6;
4513 Register scratch1 = r9;
4515 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4516 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4518 // Try to quickly handle the monomorphic case without knowing for sure
4519 // if we have a weak cell in feedback. We do know it's safe to look
4520 // at WeakCell::kValueOffset.
4521 Label try_array, load_smi_map, compare_map;
4522 Label not_array, miss;
4523 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4524 scratch1, &compare_map, &load_smi_map, &try_array);
4526 // Is it a fixed array?
4527 __ bind(&try_array);
4528 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4529 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4530 __ b(ne, ¬_array);
4532 // We are using register r8, which is used for the embedded constant pool
4533 // when FLAG_enable_embedded_constant_pool is true.
4534 DCHECK(!FLAG_enable_embedded_constant_pool);
4535 Register scratch2 = r8;
4536 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4539 __ bind(¬_array);
4540 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4542 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4543 Code::ComputeHandlerFlags(Code::STORE_IC));
4544 masm->isolate()->stub_cache()->GenerateProbe(
4545 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4546 scratch1, scratch2);
4549 StoreIC::GenerateMiss(masm);
4551 __ bind(&load_smi_map);
4552 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4553 __ jmp(&compare_map);
4557 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4558 GenerateImpl(masm, false);
4562 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4563 GenerateImpl(masm, true);
4567 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4568 Register receiver_map, Register scratch1,
4569 Register scratch2, Label* miss) {
4570 // feedback initially contains the feedback array
4571 Label next_loop, prepare_next;
4572 Label start_polymorphic;
4573 Label transition_call;
4575 Register cached_map = scratch1;
4576 Register too_far = scratch2;
4577 Register pointer_reg = feedback;
4578 __ ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4580 // +-----+------+------+-----+-----+-----+ ... ----+
4581 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4582 // +-----+------+------+-----+-----+ ----+ ... ----+
4586 // pointer_reg too_far
4587 // aka feedback scratch2
4588 // also need receiver_map
4589 // use cached_map (scratch1) to look in the weak map values.
4590 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(too_far));
4591 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4592 __ add(pointer_reg, feedback,
4593 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4595 __ bind(&next_loop);
4596 __ ldr(cached_map, MemOperand(pointer_reg));
4597 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4598 __ cmp(receiver_map, cached_map);
4599 __ b(ne, &prepare_next);
4600 // Is it a transitioning store?
4601 __ ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4602 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4603 __ b(ne, &transition_call);
4604 __ ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4605 __ add(pc, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4607 __ bind(&transition_call);
4608 __ ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4609 __ JumpIfSmi(too_far, miss);
4611 __ ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4613 // Load the map into the correct register.
4614 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4615 __ mov(feedback, too_far);
4617 __ add(pc, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4619 __ bind(&prepare_next);
4620 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4621 __ cmp(pointer_reg, too_far);
4622 __ b(lt, &next_loop);
4624 // We exhausted our array of map handler pairs.
4629 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4630 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4631 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4632 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4633 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4634 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4635 Register feedback = r5;
4636 Register receiver_map = r6;
4637 Register scratch1 = r9;
4639 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4640 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4642 // Try to quickly handle the monomorphic case without knowing for sure
4643 // if we have a weak cell in feedback. We do know it's safe to look
4644 // at WeakCell::kValueOffset.
4645 Label try_array, load_smi_map, compare_map;
4646 Label not_array, miss;
4647 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4648 scratch1, &compare_map, &load_smi_map, &try_array);
4650 __ bind(&try_array);
4651 // Is it a fixed array?
4652 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4653 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4654 __ b(ne, ¬_array);
4656 // We have a polymorphic element handler.
4657 Label polymorphic, try_poly_name;
4658 __ bind(&polymorphic);
4660 // We are using register r8, which is used for the embedded constant pool
4661 // when FLAG_enable_embedded_constant_pool is true.
4662 DCHECK(!FLAG_enable_embedded_constant_pool);
4663 Register scratch2 = r8;
4665 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4668 __ bind(¬_array);
4670 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4671 __ b(ne, &try_poly_name);
4672 Handle<Code> megamorphic_stub =
4673 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4674 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4676 __ bind(&try_poly_name);
4677 // We might have a name in feedback, and a fixed array in the next slot.
4678 __ cmp(key, feedback);
4680 // If the name comparison succeeded, we know we have a fixed array with
4681 // at least one map/handler pair.
4682 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4684 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4685 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4689 KeyedStoreIC::GenerateMiss(masm);
4691 __ bind(&load_smi_map);
4692 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4693 __ jmp(&compare_map);
4697 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4698 if (masm->isolate()->function_entry_hook() != NULL) {
4699 ProfileEntryHookStub stub(masm->isolate());
4700 PredictableCodeSizeScope predictable(masm);
4701 predictable.ExpectSize(masm->CallStubSize(&stub) +
4702 2 * Assembler::kInstrSize);
4710 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4711 // The entry hook is a "push lr" instruction, followed by a call.
4712 const int32_t kReturnAddressDistanceFromFunctionStart =
4713 3 * Assembler::kInstrSize;
4715 // This should contain all kCallerSaved registers.
4716 const RegList kSavedRegs =
4723 // We also save lr, so the count here is one higher than the mask indicates.
4724 const int32_t kNumSavedRegs = 7;
4726 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4728 // Save all caller-save registers as this may be called from anywhere.
4729 __ stm(db_w, sp, kSavedRegs | lr.bit());
4731 // Compute the function's address for the first argument.
4732 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4734 // The caller's return address is above the saved temporaries.
4735 // Grab that for the second argument to the hook.
4736 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4738 // Align the stack if necessary.
4739 int frame_alignment = masm->ActivationFrameAlignment();
4740 if (frame_alignment > kPointerSize) {
4742 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4743 __ and_(sp, sp, Operand(-frame_alignment));
4746 #if V8_HOST_ARCH_ARM
4747 int32_t entry_hook =
4748 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4749 __ mov(ip, Operand(entry_hook));
4751 // Under the simulator we need to indirect the entry hook through a
4752 // trampoline function at a known address.
4753 // It additionally takes an isolate as a third parameter
4754 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4756 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4757 __ mov(ip, Operand(ExternalReference(&dispatcher,
4758 ExternalReference::BUILTIN_CALL,
4763 // Restore the stack pointer if needed.
4764 if (frame_alignment > kPointerSize) {
4768 // Also pop pc to get Ret(0).
4769 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4774 static void CreateArrayDispatch(MacroAssembler* masm,
4775 AllocationSiteOverrideMode mode) {
4776 if (mode == DISABLE_ALLOCATION_SITES) {
4777 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4778 __ TailCallStub(&stub);
4779 } else if (mode == DONT_OVERRIDE) {
4780 int last_index = GetSequenceIndexFromFastElementsKind(
4781 TERMINAL_FAST_ELEMENTS_KIND);
4782 for (int i = 0; i <= last_index; ++i) {
4783 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4784 __ cmp(r3, Operand(kind));
4785 T stub(masm->isolate(), kind);
4786 __ TailCallStub(&stub, eq);
4789 // If we reached this point there is a problem.
4790 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4797 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4798 AllocationSiteOverrideMode mode) {
4799 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4800 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4801 // r0 - number of arguments
4802 // r1 - constructor?
4803 // sp[0] - last argument
4804 Label normal_sequence;
4805 if (mode == DONT_OVERRIDE) {
4806 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4807 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4808 STATIC_ASSERT(FAST_ELEMENTS == 2);
4809 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4810 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4811 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4813 // is the low bit set? If so, we are holey and that is good.
4814 __ tst(r3, Operand(1));
4815 __ b(ne, &normal_sequence);
4818 // look at the first argument
4819 __ ldr(r5, MemOperand(sp, 0));
4820 __ cmp(r5, Operand::Zero());
4821 __ b(eq, &normal_sequence);
4823 if (mode == DISABLE_ALLOCATION_SITES) {
4824 ElementsKind initial = GetInitialFastElementsKind();
4825 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4827 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4829 DISABLE_ALLOCATION_SITES);
4830 __ TailCallStub(&stub_holey);
4832 __ bind(&normal_sequence);
4833 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4835 DISABLE_ALLOCATION_SITES);
4836 __ TailCallStub(&stub);
4837 } else if (mode == DONT_OVERRIDE) {
4838 // We are going to create a holey array, but our kind is non-holey.
4839 // Fix kind and retry (only if we have an allocation site in the slot).
4840 __ add(r3, r3, Operand(1));
4842 if (FLAG_debug_code) {
4843 __ ldr(r5, FieldMemOperand(r2, 0));
4844 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4845 __ Assert(eq, kExpectedAllocationSite);
4848 // Save the resulting elements kind in type info. We can't just store r3
4849 // in the AllocationSite::transition_info field because elements kind is
4850 // restricted to a portion of the field...upper bits need to be left alone.
4851 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4852 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4853 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4854 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4856 __ bind(&normal_sequence);
4857 int last_index = GetSequenceIndexFromFastElementsKind(
4858 TERMINAL_FAST_ELEMENTS_KIND);
4859 for (int i = 0; i <= last_index; ++i) {
4860 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4861 __ cmp(r3, Operand(kind));
4862 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4863 __ TailCallStub(&stub, eq);
4866 // If we reached this point there is a problem.
4867 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4875 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4876 int to_index = GetSequenceIndexFromFastElementsKind(
4877 TERMINAL_FAST_ELEMENTS_KIND);
4878 for (int i = 0; i <= to_index; ++i) {
4879 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4880 T stub(isolate, kind);
4882 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4883 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4890 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4891 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4893 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4895 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4900 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4902 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4903 for (int i = 0; i < 2; i++) {
4904 // For internal arrays we only need a few things
4905 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4907 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4909 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4915 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4916 MacroAssembler* masm,
4917 AllocationSiteOverrideMode mode) {
4918 if (argument_count() == ANY) {
4919 Label not_zero_case, not_one_case;
4921 __ b(ne, ¬_zero_case);
4922 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4924 __ bind(¬_zero_case);
4925 __ cmp(r0, Operand(1));
4926 __ b(gt, ¬_one_case);
4927 CreateArrayDispatchOneArgument(masm, mode);
4929 __ bind(¬_one_case);
4930 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4931 } else if (argument_count() == NONE) {
4932 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4933 } else if (argument_count() == ONE) {
4934 CreateArrayDispatchOneArgument(masm, mode);
4935 } else if (argument_count() == MORE_THAN_ONE) {
4936 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4943 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4944 // ----------- S t a t e -------------
4945 // -- r0 : argc (only if argument_count() == ANY)
4946 // -- r1 : constructor
4947 // -- r2 : AllocationSite or undefined
4948 // -- r3 : original constructor
4949 // -- sp[0] : return address
4950 // -- sp[4] : last argument
4951 // -----------------------------------
4953 if (FLAG_debug_code) {
4954 // The array construct code is only set for the global and natives
4955 // builtin Array functions which always have maps.
4957 // Initial map for the builtin Array function should be a map.
4958 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4959 // Will both indicate a NULL and a Smi.
4960 __ tst(r4, Operand(kSmiTagMask));
4961 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4962 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4963 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4965 // We should either have undefined in r2 or a valid AllocationSite
4966 __ AssertUndefinedOrAllocationSite(r2, r4);
4971 __ b(ne, &subclassing);
4974 // Get the elements kind and case on that.
4975 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4978 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4980 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4981 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4982 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4985 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4987 __ bind(&subclassing);
4992 switch (argument_count()) {
4995 __ add(r0, r0, Operand(2));
4998 __ mov(r0, Operand(2));
5001 __ mov(r0, Operand(3));
5005 __ JumpToExternalReference(
5006 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5010 void InternalArrayConstructorStub::GenerateCase(
5011 MacroAssembler* masm, ElementsKind kind) {
5012 __ cmp(r0, Operand(1));
5014 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5015 __ TailCallStub(&stub0, lo);
5017 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5018 __ TailCallStub(&stubN, hi);
5020 if (IsFastPackedElementsKind(kind)) {
5021 // We might need to create a holey array
5022 // look at the first argument
5023 __ ldr(r3, MemOperand(sp, 0));
5024 __ cmp(r3, Operand::Zero());
5026 InternalArraySingleArgumentConstructorStub
5027 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5028 __ TailCallStub(&stub1_holey, ne);
5031 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5032 __ TailCallStub(&stub1);
5036 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5037 // ----------- S t a t e -------------
5039 // -- r1 : constructor
5040 // -- sp[0] : return address
5041 // -- sp[4] : last argument
5042 // -----------------------------------
5044 if (FLAG_debug_code) {
5045 // The array construct code is only set for the global and natives
5046 // builtin Array functions which always have maps.
5048 // Initial map for the builtin Array function should be a map.
5049 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5050 // Will both indicate a NULL and a Smi.
5051 __ tst(r3, Operand(kSmiTagMask));
5052 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5053 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
5054 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5057 // Figure out the right elements kind
5058 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5059 // Load the map's "bit field 2" into |result|. We only need the first byte,
5060 // but the following bit field extraction takes care of that anyway.
5061 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
5062 // Retrieve elements_kind from bit field 2.
5063 __ DecodeField<Map::ElementsKindBits>(r3);
5065 if (FLAG_debug_code) {
5067 __ cmp(r3, Operand(FAST_ELEMENTS));
5069 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
5071 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5075 Label fast_elements_case;
5076 __ cmp(r3, Operand(FAST_ELEMENTS));
5077 __ b(eq, &fast_elements_case);
5078 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5080 __ bind(&fast_elements_case);
5081 GenerateCase(masm, FAST_ELEMENTS);
5085 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5086 Register context = cp;
5087 Register result = r0;
5090 // Go up the context chain to the script context.
5091 for (int i = 0; i < depth(); ++i) {
5092 __ ldr(result, ContextOperand(context, Context::PREVIOUS_INDEX));
5096 // Load the PropertyCell value at the specified slot.
5097 __ add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5098 __ ldr(result, ContextOperand(result));
5099 __ ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5101 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5102 __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
5105 // Fallback to runtime.
5108 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5112 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5113 Register value = r0;
5117 Register cell_details = r4;
5118 Register cell_value = r5;
5119 Register cell_value_map = r6;
5120 Register scratch = r9;
5122 Register context = cp;
5123 Register context_temp = cell;
5125 Label fast_heapobject_case, fast_smi_case, slow_case;
5127 if (FLAG_debug_code) {
5128 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5129 __ Check(ne, kUnexpectedValue);
5132 // Go up the context chain to the script context.
5133 for (int i = 0; i < depth(); i++) {
5134 __ ldr(context_temp, ContextOperand(context, Context::PREVIOUS_INDEX));
5135 context = context_temp;
5138 // Load the PropertyCell at the specified slot.
5139 __ add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5140 __ ldr(cell, ContextOperand(cell));
5142 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5143 __ ldr(cell_details, FieldMemOperand(cell, PropertyCell::kDetailsOffset));
5144 __ SmiUntag(cell_details);
5145 __ and_(cell_details, cell_details,
5146 Operand(PropertyDetails::PropertyCellTypeField::kMask |
5147 PropertyDetails::KindField::kMask |
5148 PropertyDetails::kAttributesReadOnlyMask));
5150 // Check if PropertyCell holds mutable data.
5151 Label not_mutable_data;
5152 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5153 PropertyCellType::kMutable) |
5154 PropertyDetails::KindField::encode(kData)));
5155 __ b(ne, ¬_mutable_data);
5156 __ JumpIfSmi(value, &fast_smi_case);
5158 __ bind(&fast_heapobject_case);
5159 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5160 // RecordWriteField clobbers the value register, so we copy it before the
5162 __ mov(r4, Operand(value));
5163 __ RecordWriteField(cell, PropertyCell::kValueOffset, r4, scratch,
5164 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5168 __ bind(¬_mutable_data);
5169 // Check if PropertyCell value matches the new value (relevant for Constant,
5170 // ConstantType and Undefined cells).
5171 Label not_same_value;
5172 __ ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5173 __ cmp(cell_value, value);
5174 __ b(ne, ¬_same_value);
5176 // Make sure the PropertyCell is not marked READ_ONLY.
5177 __ tst(cell_details, Operand(PropertyDetails::kAttributesReadOnlyMask));
5178 __ b(ne, &slow_case);
5180 if (FLAG_debug_code) {
5182 // This can only be true for Constant, ConstantType and Undefined cells,
5183 // because we never store the_hole via this stub.
5184 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5185 PropertyCellType::kConstant) |
5186 PropertyDetails::KindField::encode(kData)));
5188 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5189 PropertyCellType::kConstantType) |
5190 PropertyDetails::KindField::encode(kData)));
5192 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5193 PropertyCellType::kUndefined) |
5194 PropertyDetails::KindField::encode(kData)));
5195 __ Check(eq, kUnexpectedValue);
5199 __ bind(¬_same_value);
5201 // Check if PropertyCell contains data with constant type (and is not
5203 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5204 PropertyCellType::kConstantType) |
5205 PropertyDetails::KindField::encode(kData)));
5206 __ b(ne, &slow_case);
5208 // Now either both old and new values must be smis or both must be heap
5209 // objects with same map.
5210 Label value_is_heap_object;
5211 __ JumpIfNotSmi(value, &value_is_heap_object);
5212 __ JumpIfNotSmi(cell_value, &slow_case);
5213 // Old and new values are smis, no need for a write barrier here.
5214 __ bind(&fast_smi_case);
5215 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5218 __ bind(&value_is_heap_object);
5219 __ JumpIfSmi(cell_value, &slow_case);
5221 __ ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5222 __ ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5223 __ cmp(cell_value_map, scratch);
5224 __ b(eq, &fast_heapobject_case);
5226 // Fallback to runtime.
5227 __ bind(&slow_case);
5229 __ Push(slot, value);
5230 __ TailCallRuntime(is_strict(language_mode())
5231 ? Runtime::kStoreGlobalViaContext_Strict
5232 : Runtime::kStoreGlobalViaContext_Sloppy,
5237 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5238 return ref0.address() - ref1.address();
5242 // Calls an API function. Allocates HandleScope, extracts returned value
5243 // from handle and propagates exceptions. Restores context. stack_space
5244 // - space to be unwound on exit (includes the call JS arguments space and
5245 // the additional space allocated for the fast call).
5246 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5247 Register function_address,
5248 ExternalReference thunk_ref,
5250 MemOperand* stack_space_operand,
5251 MemOperand return_value_operand,
5252 MemOperand* context_restore_operand) {
5253 Isolate* isolate = masm->isolate();
5254 ExternalReference next_address =
5255 ExternalReference::handle_scope_next_address(isolate);
5256 const int kNextOffset = 0;
5257 const int kLimitOffset = AddressOffset(
5258 ExternalReference::handle_scope_limit_address(isolate), next_address);
5259 const int kLevelOffset = AddressOffset(
5260 ExternalReference::handle_scope_level_address(isolate), next_address);
5262 DCHECK(function_address.is(r1) || function_address.is(r2));
5264 Label profiler_disabled;
5265 Label end_profiler_check;
5266 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5267 __ ldrb(r9, MemOperand(r9, 0));
5268 __ cmp(r9, Operand(0));
5269 __ b(eq, &profiler_disabled);
5271 // Additional parameter is the address of the actual callback.
5272 __ mov(r3, Operand(thunk_ref));
5273 __ jmp(&end_profiler_check);
5275 __ bind(&profiler_disabled);
5276 __ Move(r3, function_address);
5277 __ bind(&end_profiler_check);
5279 // Allocate HandleScope in callee-save registers.
5280 __ mov(r9, Operand(next_address));
5281 __ ldr(r4, MemOperand(r9, kNextOffset));
5282 __ ldr(r5, MemOperand(r9, kLimitOffset));
5283 __ ldr(r6, MemOperand(r9, kLevelOffset));
5284 __ add(r6, r6, Operand(1));
5285 __ str(r6, MemOperand(r9, kLevelOffset));
5287 if (FLAG_log_timer_events) {
5288 FrameScope frame(masm, StackFrame::MANUAL);
5289 __ PushSafepointRegisters();
5290 __ PrepareCallCFunction(1, r0);
5291 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5292 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5294 __ PopSafepointRegisters();
5297 // Native call returns to the DirectCEntry stub which redirects to the
5298 // return address pushed on stack (could have moved after GC).
5299 // DirectCEntry stub itself is generated early and never moves.
5300 DirectCEntryStub stub(isolate);
5301 stub.GenerateCall(masm, r3);
5303 if (FLAG_log_timer_events) {
5304 FrameScope frame(masm, StackFrame::MANUAL);
5305 __ PushSafepointRegisters();
5306 __ PrepareCallCFunction(1, r0);
5307 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5308 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5310 __ PopSafepointRegisters();
5313 Label promote_scheduled_exception;
5314 Label delete_allocated_handles;
5315 Label leave_exit_frame;
5316 Label return_value_loaded;
5318 // load value from ReturnValue
5319 __ ldr(r0, return_value_operand);
5320 __ bind(&return_value_loaded);
5321 // No more valid handles (the result handle was the last one). Restore
5322 // previous handle scope.
5323 __ str(r4, MemOperand(r9, kNextOffset));
5324 if (__ emit_debug_code()) {
5325 __ ldr(r1, MemOperand(r9, kLevelOffset));
5327 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5329 __ sub(r6, r6, Operand(1));
5330 __ str(r6, MemOperand(r9, kLevelOffset));
5331 __ ldr(ip, MemOperand(r9, kLimitOffset));
5333 __ b(ne, &delete_allocated_handles);
5335 // Leave the API exit frame.
5336 __ bind(&leave_exit_frame);
5337 bool restore_context = context_restore_operand != NULL;
5338 if (restore_context) {
5339 __ ldr(cp, *context_restore_operand);
5341 // LeaveExitFrame expects unwind space to be in a register.
5342 if (stack_space_operand != NULL) {
5343 __ ldr(r4, *stack_space_operand);
5345 __ mov(r4, Operand(stack_space));
5347 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5349 // Check if the function scheduled an exception.
5350 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5351 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5352 __ ldr(r5, MemOperand(ip));
5354 __ b(ne, &promote_scheduled_exception);
5358 // Re-throw by promoting a scheduled exception.
5359 __ bind(&promote_scheduled_exception);
5360 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5362 // HandleScope limit has changed. Delete allocated extensions.
5363 __ bind(&delete_allocated_handles);
5364 __ str(r5, MemOperand(r9, kLimitOffset));
5366 __ PrepareCallCFunction(1, r5);
5367 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5368 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5371 __ jmp(&leave_exit_frame);
5375 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5376 const ParameterCount& argc,
5377 bool return_first_arg,
5378 bool call_data_undefined) {
5379 // ----------- S t a t e -------------
5381 // -- r4 : call_data
5383 // -- r1 : api_function_address
5384 // -- r3 : number of arguments if argc is a register
5387 // -- sp[0] : last argument
5389 // -- sp[(argc - 1)* 4] : first argument
5390 // -- sp[argc * 4] : receiver
5391 // -----------------------------------
5393 Register callee = r0;
5394 Register call_data = r4;
5395 Register holder = r2;
5396 Register api_function_address = r1;
5397 Register context = cp;
5399 typedef FunctionCallbackArguments FCA;
5401 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5402 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5403 STATIC_ASSERT(FCA::kDataIndex == 4);
5404 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5405 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5406 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5407 STATIC_ASSERT(FCA::kHolderIndex == 0);
5408 STATIC_ASSERT(FCA::kArgsLength == 7);
5410 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5414 // load context from callee
5415 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5423 Register scratch = call_data;
5424 if (!call_data_undefined) {
5425 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5429 // return value default
5432 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5437 // Prepare arguments.
5438 __ mov(scratch, sp);
5440 // Allocate the v8::Arguments structure in the arguments' space since
5441 // it's not controlled by GC.
5442 const int kApiStackSpace = 4;
5444 FrameScope frame_scope(masm, StackFrame::MANUAL);
5445 __ EnterExitFrame(false, kApiStackSpace);
5447 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5448 // r0 = FunctionCallbackInfo&
5449 // Arguments is after the return address.
5450 __ add(r0, sp, Operand(1 * kPointerSize));
5451 // FunctionCallbackInfo::implicit_args_
5452 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
5453 if (argc.is_immediate()) {
5454 // FunctionCallbackInfo::values_
5456 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5457 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5458 // FunctionCallbackInfo::length_ = argc
5459 __ mov(ip, Operand(argc.immediate()));
5460 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5461 // FunctionCallbackInfo::is_construct_call_ = 0
5462 __ mov(ip, Operand::Zero());
5463 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5465 // FunctionCallbackInfo::values_
5466 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5467 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5468 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5469 // FunctionCallbackInfo::length_ = argc
5470 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5471 // FunctionCallbackInfo::is_construct_call_
5472 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5473 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5474 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5477 ExternalReference thunk_ref =
5478 ExternalReference::invoke_function_callback(masm->isolate());
5480 AllowExternalCallThatCantCauseGC scope(masm);
5481 MemOperand context_restore_operand(
5482 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5483 // Stores return the first js argument
5484 int return_value_offset = 0;
5485 if (return_first_arg) {
5486 return_value_offset = 2 + FCA::kArgsLength;
5488 return_value_offset = 2 + FCA::kReturnValueOffset;
5490 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5491 int stack_space = 0;
5492 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5493 MemOperand* stack_space_operand = &is_construct_call_operand;
5494 if (argc.is_immediate()) {
5495 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5496 stack_space_operand = NULL;
5498 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5499 stack_space_operand, return_value_operand,
5500 &context_restore_operand);
5504 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5505 bool call_data_undefined = this->call_data_undefined();
5506 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
5507 call_data_undefined);
5511 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5512 bool is_store = this->is_store();
5513 int argc = this->argc();
5514 bool call_data_undefined = this->call_data_undefined();
5515 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5516 call_data_undefined);
5520 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5521 // ----------- S t a t e -------------
5523 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5525 // -- r2 : api_function_address
5526 // -----------------------------------
5528 Register api_function_address = ApiGetterDescriptor::function_address();
5529 DCHECK(api_function_address.is(r2));
5531 __ mov(r0, sp); // r0 = Handle<Name>
5532 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
5534 const int kApiStackSpace = 1;
5535 FrameScope frame_scope(masm, StackFrame::MANUAL);
5536 __ EnterExitFrame(false, kApiStackSpace);
5538 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5539 // r1 (internal::Object** args_) as the data.
5540 __ str(r1, MemOperand(sp, 1 * kPointerSize));
5541 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
5543 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5545 ExternalReference thunk_ref =
5546 ExternalReference::invoke_accessor_getter_callback(isolate());
5547 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5548 kStackUnwindSpace, NULL,
5549 MemOperand(fp, 6 * kPointerSize), NULL);
5555 } // namespace internal
5558 #endif // V8_TARGET_ARCH_ARM