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.
684 if (cc == eq && strict()) {
685 __ TailCallRuntime(Runtime::kStrictEquals, 2, 1);
689 context_index = Context::EQUALS_BUILTIN_INDEX;
691 context_index = is_strong(strength())
692 ? Context::COMPARE_STRONG_BUILTIN_INDEX
693 : Context::COMPARE_BUILTIN_INDEX;
694 int ncr; // NaN compare result
695 if (cc == lt || cc == le) {
698 DCHECK(cc == gt || cc == ge); // remaining cases
701 __ mov(r0, Operand(Smi::FromInt(ncr)));
705 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
706 // tagged as a small integer.
707 __ InvokeBuiltin(context_index, JUMP_FUNCTION);
715 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
716 // We don't allow a GC during a store buffer overflow so there is no need to
717 // store the registers in any particular way, but we do have to store and
719 __ stm(db_w, sp, kCallerSaved | lr.bit());
721 const Register scratch = r1;
723 if (save_doubles()) {
724 __ SaveFPRegs(sp, scratch);
726 const int argument_count = 1;
727 const int fp_argument_count = 0;
729 AllowExternalCallThatCantCauseGC scope(masm);
730 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
731 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
733 ExternalReference::store_buffer_overflow_function(isolate()),
735 if (save_doubles()) {
736 __ RestoreFPRegs(sp, scratch);
738 __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0).
742 void MathPowStub::Generate(MacroAssembler* masm) {
743 const Register base = r1;
744 const Register exponent = MathPowTaggedDescriptor::exponent();
745 DCHECK(exponent.is(r2));
746 const Register heapnumbermap = r5;
747 const Register heapnumber = r0;
748 const DwVfpRegister double_base = d0;
749 const DwVfpRegister double_exponent = d1;
750 const DwVfpRegister double_result = d2;
751 const DwVfpRegister double_scratch = d3;
752 const SwVfpRegister single_scratch = s6;
753 const Register scratch = r9;
754 const Register scratch2 = r4;
756 Label call_runtime, done, int_exponent;
757 if (exponent_type() == ON_STACK) {
758 Label base_is_smi, unpack_exponent;
759 // The exponent and base are supplied as arguments on the stack.
760 // This can only happen if the stub is called from non-optimized code.
761 // Load input parameters from stack to double registers.
762 __ ldr(base, MemOperand(sp, 1 * kPointerSize));
763 __ ldr(exponent, MemOperand(sp, 0 * kPointerSize));
765 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
767 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
768 __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset));
769 __ cmp(scratch, heapnumbermap);
770 __ b(ne, &call_runtime);
772 __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
773 __ jmp(&unpack_exponent);
775 __ bind(&base_is_smi);
776 __ vmov(single_scratch, scratch);
777 __ vcvt_f64_s32(double_base, single_scratch);
778 __ bind(&unpack_exponent);
780 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
782 __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
783 __ cmp(scratch, heapnumbermap);
784 __ b(ne, &call_runtime);
785 __ vldr(double_exponent,
786 FieldMemOperand(exponent, HeapNumber::kValueOffset));
787 } else if (exponent_type() == TAGGED) {
788 // Base is already in double_base.
789 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
791 __ vldr(double_exponent,
792 FieldMemOperand(exponent, HeapNumber::kValueOffset));
795 if (exponent_type() != INTEGER) {
796 Label int_exponent_convert;
797 // Detect integer exponents stored as double.
798 __ vcvt_u32_f64(single_scratch, double_exponent);
799 // We do not check for NaN or Infinity here because comparing numbers on
800 // ARM correctly distinguishes NaNs. We end up calling the built-in.
801 __ vcvt_f64_u32(double_scratch, single_scratch);
802 __ VFPCompareAndSetFlags(double_scratch, double_exponent);
803 __ b(eq, &int_exponent_convert);
805 if (exponent_type() == ON_STACK) {
806 // Detect square root case. Crankshaft detects constant +/-0.5 at
807 // compile time and uses DoMathPowHalf instead. We then skip this check
808 // for non-constant cases of +/-0.5 as these hardly occur.
812 __ vmov(double_scratch, 0.5, scratch);
813 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
814 __ b(ne, ¬_plus_half);
816 // Calculates square root of base. Check for the special case of
817 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
818 __ vmov(double_scratch, -V8_INFINITY, scratch);
819 __ VFPCompareAndSetFlags(double_base, double_scratch);
820 __ vneg(double_result, double_scratch, eq);
823 // Add +0 to convert -0 to +0.
824 __ vadd(double_scratch, double_base, kDoubleRegZero);
825 __ vsqrt(double_result, double_scratch);
828 __ bind(¬_plus_half);
829 __ vmov(double_scratch, -0.5, scratch);
830 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
831 __ b(ne, &call_runtime);
833 // Calculates square root of base. Check for the special case of
834 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
835 __ vmov(double_scratch, -V8_INFINITY, scratch);
836 __ VFPCompareAndSetFlags(double_base, double_scratch);
837 __ vmov(double_result, kDoubleRegZero, eq);
840 // Add +0 to convert -0 to +0.
841 __ vadd(double_scratch, double_base, kDoubleRegZero);
842 __ vmov(double_result, 1.0, scratch);
843 __ vsqrt(double_scratch, double_scratch);
844 __ vdiv(double_result, double_result, double_scratch);
850 AllowExternalCallThatCantCauseGC scope(masm);
851 __ PrepareCallCFunction(0, 2, scratch);
852 __ MovToFloatParameters(double_base, double_exponent);
854 ExternalReference::power_double_double_function(isolate()),
858 __ MovFromFloatResult(double_result);
861 __ bind(&int_exponent_convert);
862 __ vcvt_u32_f64(single_scratch, double_exponent);
863 __ vmov(scratch, single_scratch);
866 // Calculate power with integer exponent.
867 __ bind(&int_exponent);
869 // Get two copies of exponent in the registers scratch and exponent.
870 if (exponent_type() == INTEGER) {
871 __ mov(scratch, exponent);
873 // Exponent has previously been stored into scratch as untagged integer.
874 __ mov(exponent, scratch);
876 __ vmov(double_scratch, double_base); // Back up base.
877 __ vmov(double_result, 1.0, scratch2);
879 // Get absolute value of exponent.
880 __ cmp(scratch, Operand::Zero());
881 __ mov(scratch2, Operand::Zero(), LeaveCC, mi);
882 __ sub(scratch, scratch2, scratch, LeaveCC, mi);
885 __ bind(&while_true);
886 __ mov(scratch, Operand(scratch, ASR, 1), SetCC);
887 __ vmul(double_result, double_result, double_scratch, cs);
888 __ vmul(double_scratch, double_scratch, double_scratch, ne);
889 __ b(ne, &while_true);
891 __ cmp(exponent, Operand::Zero());
893 __ vmov(double_scratch, 1.0, scratch);
894 __ vdiv(double_result, double_scratch, double_result);
895 // Test whether result is zero. Bail out to check for subnormal result.
896 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
897 __ VFPCompareAndSetFlags(double_result, 0.0);
899 // double_exponent may not containe the exponent value if the input was a
900 // smi. We set it with exponent value before bailing out.
901 __ vmov(single_scratch, exponent);
902 __ vcvt_f64_s32(double_exponent, single_scratch);
904 // Returning or bailing out.
905 Counters* counters = isolate()->counters();
906 if (exponent_type() == ON_STACK) {
907 // The arguments are still on the stack.
908 __ bind(&call_runtime);
909 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
911 // The stub is called from non-optimized code, which expects the result
912 // as heap number in exponent.
914 __ AllocateHeapNumber(
915 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
916 __ vstr(double_result,
917 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
918 DCHECK(heapnumber.is(r0));
919 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
924 AllowExternalCallThatCantCauseGC scope(masm);
925 __ PrepareCallCFunction(0, 2, scratch);
926 __ MovToFloatParameters(double_base, double_exponent);
928 ExternalReference::power_double_double_function(isolate()),
932 __ MovFromFloatResult(double_result);
935 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
941 bool CEntryStub::NeedsImmovableCode() {
946 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
947 CEntryStub::GenerateAheadOfTime(isolate);
948 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
949 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
950 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
951 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
952 CreateWeakCellStub::GenerateAheadOfTime(isolate);
953 BinaryOpICStub::GenerateAheadOfTime(isolate);
954 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
955 StoreFastElementStub::GenerateAheadOfTime(isolate);
956 TypeofStub::GenerateAheadOfTime(isolate);
960 void CodeStub::GenerateFPStubs(Isolate* isolate) {
961 // Generate if not already in cache.
962 SaveFPRegsMode mode = kSaveFPRegs;
963 CEntryStub(isolate, 1, mode).GetCode();
964 StoreBufferOverflowStub(isolate, mode).GetCode();
965 isolate->set_fp_stubs_generated(true);
969 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
970 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
975 void CEntryStub::Generate(MacroAssembler* masm) {
976 // Called from JavaScript; parameters are on stack as if calling JS function.
977 // r0: number of arguments including receiver
978 // r1: pointer to builtin function
979 // fp: frame pointer (restored after C call)
980 // sp: stack pointer (restored as callee's sp after C call)
981 // cp: current context (C callee-saved)
983 ProfileEntryHookStub::MaybeCallEntryHook(masm);
985 __ mov(r5, Operand(r1));
987 // Compute the argv pointer in a callee-saved register.
988 __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2));
989 __ sub(r1, r1, Operand(kPointerSize));
991 // Enter the exit frame that transitions from JavaScript to C++.
992 FrameScope scope(masm, StackFrame::MANUAL);
993 __ EnterExitFrame(save_doubles());
995 // Store a copy of argc in callee-saved registers for later.
996 __ mov(r4, Operand(r0));
998 // r0, r4: number of arguments including receiver (C callee-saved)
999 // r1: pointer to the first argument (C callee-saved)
1000 // r5: pointer to builtin function (C callee-saved)
1002 // Result returned in r0 or r0+r1 by default.
1004 #if V8_HOST_ARCH_ARM
1005 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
1006 int frame_alignment_mask = frame_alignment - 1;
1007 if (FLAG_debug_code) {
1008 if (frame_alignment > kPointerSize) {
1009 Label alignment_as_expected;
1010 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
1011 __ tst(sp, Operand(frame_alignment_mask));
1012 __ b(eq, &alignment_as_expected);
1013 // Don't use Check here, as it will call Runtime_Abort re-entering here.
1014 __ stop("Unexpected alignment");
1015 __ bind(&alignment_as_expected);
1021 // r0 = argc, r1 = argv
1022 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1024 // To let the GC traverse the return address of the exit frames, we need to
1025 // know where the return address is. The CEntryStub is unmovable, so
1026 // we can store the address on the stack to be able to find it again and
1027 // we never have to restore it, because it will not change.
1028 // Compute the return address in lr to return to after the jump below. Pc is
1029 // already at '+ 8' from the current instruction but return is after three
1030 // instructions so add another 4 to pc to get the return address.
1032 // Prevent literal pool emission before return address.
1033 Assembler::BlockConstPoolScope block_const_pool(masm);
1034 __ add(lr, pc, Operand(4));
1035 __ str(lr, MemOperand(sp, 0));
1039 __ VFPEnsureFPSCRState(r2);
1041 // Check result for exception sentinel.
1042 Label exception_returned;
1043 __ CompareRoot(r0, Heap::kExceptionRootIndex);
1044 __ b(eq, &exception_returned);
1046 // Check that there is no pending exception, otherwise we
1047 // should have returned the exception sentinel.
1048 if (FLAG_debug_code) {
1050 ExternalReference pending_exception_address(
1051 Isolate::kPendingExceptionAddress, isolate());
1052 __ mov(r2, Operand(pending_exception_address));
1053 __ ldr(r2, MemOperand(r2));
1054 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex);
1055 // Cannot use check here as it attempts to generate call into runtime.
1057 __ stop("Unexpected pending exception");
1061 // Exit C frame and return.
1063 // sp: stack pointer
1064 // fp: frame pointer
1065 // Callee-saved register r4 still holds argc.
1066 __ LeaveExitFrame(save_doubles(), r4, true);
1069 // Handling of exception.
1070 __ bind(&exception_returned);
1072 ExternalReference pending_handler_context_address(
1073 Isolate::kPendingHandlerContextAddress, isolate());
1074 ExternalReference pending_handler_code_address(
1075 Isolate::kPendingHandlerCodeAddress, isolate());
1076 ExternalReference pending_handler_offset_address(
1077 Isolate::kPendingHandlerOffsetAddress, isolate());
1078 ExternalReference pending_handler_fp_address(
1079 Isolate::kPendingHandlerFPAddress, isolate());
1080 ExternalReference pending_handler_sp_address(
1081 Isolate::kPendingHandlerSPAddress, isolate());
1083 // Ask the runtime for help to determine the handler. This will set r0 to
1084 // contain the current pending exception, don't clobber it.
1085 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1088 FrameScope scope(masm, StackFrame::MANUAL);
1089 __ PrepareCallCFunction(3, 0, r0);
1090 __ mov(r0, Operand(0));
1091 __ mov(r1, Operand(0));
1092 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1093 __ CallCFunction(find_handler, 3);
1096 // Retrieve the handler context, SP and FP.
1097 __ mov(cp, Operand(pending_handler_context_address));
1098 __ ldr(cp, MemOperand(cp));
1099 __ mov(sp, Operand(pending_handler_sp_address));
1100 __ ldr(sp, MemOperand(sp));
1101 __ mov(fp, Operand(pending_handler_fp_address));
1102 __ ldr(fp, MemOperand(fp));
1104 // If the handler is a JS frame, restore the context to the frame. Note that
1105 // the context will be set to (cp == 0) for non-JS frames.
1106 __ cmp(cp, Operand(0));
1107 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne);
1109 // Compute the handler entry address and jump to it.
1110 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1111 __ mov(r1, Operand(pending_handler_code_address));
1112 __ ldr(r1, MemOperand(r1));
1113 __ mov(r2, Operand(pending_handler_offset_address));
1114 __ ldr(r2, MemOperand(r2));
1115 __ add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1116 if (FLAG_enable_embedded_constant_pool) {
1117 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r1);
1123 void JSEntryStub::Generate(MacroAssembler* masm) {
1130 Label invoke, handler_entry, exit;
1132 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1134 // Called from C, so do not pop argc and args on exit (preserve sp)
1135 // No need to save register-passed args
1136 // Save callee-saved registers (incl. cp and fp), sp, and lr
1137 __ stm(db_w, sp, kCalleeSaved | lr.bit());
1139 // Save callee-saved vfp registers.
1140 __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1141 // Set up the reserved register for 0.0.
1142 __ vmov(kDoubleRegZero, 0.0);
1143 __ VFPEnsureFPSCRState(r4);
1145 // Get address of argv, see stm above.
1151 // Set up argv in r4.
1152 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1153 offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize;
1154 __ ldr(r4, MemOperand(sp, offset_to_argv));
1156 // Push a frame with special values setup to mark it as an entry frame.
1162 int marker = type();
1163 if (FLAG_enable_embedded_constant_pool) {
1164 __ mov(r8, Operand::Zero());
1166 __ mov(r7, Operand(Smi::FromInt(marker)));
1167 __ mov(r6, Operand(Smi::FromInt(marker)));
1169 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1170 __ ldr(r5, MemOperand(r5));
1171 __ mov(ip, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1172 __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() |
1173 (FLAG_enable_embedded_constant_pool ? r8.bit() : 0) |
1176 // Set up frame pointer for the frame to be pushed.
1177 __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1179 // If this is the outermost JS call, set js_entry_sp value.
1180 Label non_outermost_js;
1181 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1182 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1183 __ ldr(r6, MemOperand(r5));
1184 __ cmp(r6, Operand::Zero());
1185 __ b(ne, &non_outermost_js);
1186 __ str(fp, MemOperand(r5));
1187 __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1190 __ bind(&non_outermost_js);
1191 __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1195 // Jump to a faked try block that does the invoke, with a faked catch
1196 // block that sets the pending exception.
1199 // Block literal pool emission whilst taking the position of the handler
1200 // entry. This avoids making the assumption that literal pools are always
1201 // emitted after an instruction is emitted, rather than before.
1203 Assembler::BlockConstPoolScope block_const_pool(masm);
1204 __ bind(&handler_entry);
1205 handler_offset_ = handler_entry.pos();
1206 // Caught exception: Store result (exception) in the pending exception
1207 // field in the JSEnv and return a failure sentinel. Coming in here the
1208 // fp will be invalid because the PushStackHandler below sets it to 0 to
1209 // signal the existence of the JSEntry frame.
1210 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1213 __ str(r0, MemOperand(ip));
1214 __ LoadRoot(r0, Heap::kExceptionRootIndex);
1217 // Invoke: Link this frame into the handler chain.
1219 // Must preserve r0-r4, r5-r6 are available.
1220 __ PushStackHandler();
1221 // If an exception not caught by another handler occurs, this handler
1222 // returns control to the code after the bl(&invoke) above, which
1223 // restores all kCalleeSaved registers (including cp and fp) to their
1224 // saved values before returning a failure to C.
1226 // Clear any pending exceptions.
1227 __ mov(r5, Operand(isolate()->factory()->the_hole_value()));
1228 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1230 __ str(r5, MemOperand(ip));
1232 // Invoke the function by calling through JS entry trampoline builtin.
1233 // Notice that we cannot store a reference to the trampoline code directly in
1234 // this stub, because runtime stubs are not traversed when doing GC.
1236 // Expected registers by Builtins::JSEntryTrampoline
1242 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1243 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1245 __ mov(ip, Operand(construct_entry));
1247 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
1248 __ mov(ip, Operand(entry));
1250 __ ldr(ip, MemOperand(ip)); // deref address
1251 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1253 // Branch and link to JSEntryTrampoline.
1256 // Unlink this frame from the handler chain.
1257 __ PopStackHandler();
1259 __ bind(&exit); // r0 holds result
1260 // Check if the current stack frame is marked as the outermost JS frame.
1261 Label non_outermost_js_2;
1263 __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1264 __ b(ne, &non_outermost_js_2);
1265 __ mov(r6, Operand::Zero());
1266 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1267 __ str(r6, MemOperand(r5));
1268 __ bind(&non_outermost_js_2);
1270 // Restore the top frame descriptors from the stack.
1273 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1274 __ str(r3, MemOperand(ip));
1276 // Reset the stack to the callee saved registers.
1277 __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1279 // Restore callee-saved registers and return.
1281 if (FLAG_debug_code) {
1282 __ mov(lr, Operand(pc));
1286 // Restore callee-saved vfp registers.
1287 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1289 __ ldm(ia_w, sp, kCalleeSaved | pc.bit());
1293 void InstanceOfStub::Generate(MacroAssembler* masm) {
1294 Register const object = r1; // Object (lhs).
1295 Register const function = r0; // Function (rhs).
1296 Register const object_map = r2; // Map of {object}.
1297 Register const function_map = r3; // Map of {function}.
1298 Register const function_prototype = r4; // Prototype of {function}.
1299 Register const scratch = r5;
1301 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1302 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1304 // Check if {object} is a smi.
1305 Label object_is_smi;
1306 __ JumpIfSmi(object, &object_is_smi);
1308 // Lookup the {function} and the {object} map in the global instanceof cache.
1309 // Note: This is safe because we clear the global instanceof cache whenever
1310 // we change the prototype of any object.
1311 Label fast_case, slow_case;
1312 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1313 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1314 __ b(ne, &fast_case);
1315 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1316 __ b(ne, &fast_case);
1317 __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1320 // If {object} is a smi we can safely return false if {function} is a JS
1321 // function, otherwise we have to miss to the runtime and throw an exception.
1322 __ bind(&object_is_smi);
1323 __ JumpIfSmi(function, &slow_case);
1324 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1325 __ b(ne, &slow_case);
1326 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1329 // Fast-case: The {function} must be a valid JSFunction.
1330 __ bind(&fast_case);
1331 __ JumpIfSmi(function, &slow_case);
1332 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1333 __ b(ne, &slow_case);
1335 // Ensure that {function} has an instance prototype.
1336 __ ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1337 __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
1338 __ b(ne, &slow_case);
1340 // Ensure that {function} is not bound.
1341 Register const shared_info = scratch;
1343 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1344 __ ldr(scratch, FieldMemOperand(shared_info,
1345 SharedFunctionInfo::kCompilerHintsOffset));
1347 Operand(Smi::FromInt(1 << SharedFunctionInfo::kBoundFunction)));
1348 __ b(ne, &slow_case);
1350 // Get the "prototype" (or initial map) of the {function}.
1351 __ ldr(function_prototype,
1352 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1353 __ AssertNotSmi(function_prototype);
1355 // Resolve the prototype if the {function} has an initial map. Afterwards the
1356 // {function_prototype} will be either the JSReceiver prototype object or the
1357 // hole value, which means that no instances of the {function} were created so
1358 // far and hence we should return false.
1359 Label function_prototype_valid;
1360 __ CompareObjectType(function_prototype, scratch, scratch, MAP_TYPE);
1361 __ b(ne, &function_prototype_valid);
1362 __ ldr(function_prototype,
1363 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1364 __ bind(&function_prototype_valid);
1365 __ AssertNotSmi(function_prototype);
1367 // Update the global instanceof cache with the current {object} map and
1368 // {function}. The cached answer will be set when it is known below.
1369 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1370 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1372 // Loop through the prototype chain looking for the {function} prototype.
1373 // Assume true, and change to false if not found.
1374 Register const object_prototype = object_map;
1375 Register const null = scratch;
1377 __ LoadRoot(r0, Heap::kTrueValueRootIndex);
1378 __ LoadRoot(null, Heap::kNullValueRootIndex);
1380 __ ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1381 __ cmp(object_prototype, function_prototype);
1383 __ cmp(object_prototype, null);
1384 __ ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1386 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1388 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1391 // Slow-case: Call the runtime function.
1392 __ bind(&slow_case);
1393 __ Push(object, function);
1394 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1398 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1400 Register receiver = LoadDescriptor::ReceiverRegister();
1401 // Ensure that the vector and slot registers won't be clobbered before
1402 // calling the miss handler.
1403 DCHECK(!AreAliased(r4, r5, LoadWithVectorDescriptor::VectorRegister(),
1404 LoadWithVectorDescriptor::SlotRegister()));
1406 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4,
1409 PropertyAccessCompiler::TailCallBuiltin(
1410 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1414 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1415 // Return address is in lr.
1418 Register receiver = LoadDescriptor::ReceiverRegister();
1419 Register index = LoadDescriptor::NameRegister();
1420 Register scratch = r5;
1421 Register result = r0;
1422 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1423 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1424 result.is(LoadWithVectorDescriptor::SlotRegister()));
1426 // StringCharAtGenerator doesn't use the result register until it's passed
1427 // the different miss possibilities. If it did, we would have a conflict
1428 // when FLAG_vector_ics is true.
1429 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1430 &miss, // When not a string.
1431 &miss, // When not a number.
1432 &miss, // When index out of range.
1433 STRING_INDEX_IS_ARRAY_INDEX,
1434 RECEIVER_IS_STRING);
1435 char_at_generator.GenerateFast(masm);
1438 StubRuntimeCallHelper call_helper;
1439 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1442 PropertyAccessCompiler::TailCallBuiltin(
1443 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1447 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1448 // The displacement is the offset of the last parameter (if any)
1449 // relative to the frame pointer.
1450 const int kDisplacement =
1451 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1452 DCHECK(r1.is(ArgumentsAccessReadDescriptor::index()));
1453 DCHECK(r0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1455 // Check that the key is a smi.
1457 __ JumpIfNotSmi(r1, &slow);
1459 // Check if the calling frame is an arguments adaptor frame.
1461 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1462 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1463 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1466 // Check index against formal parameters count limit passed in
1467 // through register r0. Use unsigned comparison to get negative
1472 // Read the argument from the stack and return it.
1474 __ add(r3, fp, Operand::PointerOffsetFromSmiKey(r3));
1475 __ ldr(r0, MemOperand(r3, kDisplacement));
1478 // Arguments adaptor case: Check index against actual arguments
1479 // limit found in the arguments adaptor frame. Use unsigned
1480 // comparison to get negative check for free.
1482 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1486 // Read the argument from the adaptor frame and return it.
1488 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r3));
1489 __ ldr(r0, MemOperand(r3, kDisplacement));
1492 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1493 // by calling the runtime system.
1496 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1500 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1501 // sp[0] : number of parameters
1502 // sp[4] : receiver displacement
1505 // Check if the calling frame is an arguments adaptor frame.
1507 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1508 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1509 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1512 // Patch the arguments.length and the parameters pointer in the current frame.
1513 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1514 __ str(r2, MemOperand(sp, 0 * kPointerSize));
1515 __ add(r3, r3, Operand(r2, LSL, 1));
1516 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1517 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1520 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1524 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1526 // sp[0] : number of parameters (tagged)
1527 // sp[4] : address of receiver argument
1529 // Registers used over whole function:
1530 // r6 : allocated object (tagged)
1531 // r9 : mapped parameter count (tagged)
1533 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1534 // r1 = parameter count (tagged)
1536 // Check if the calling frame is an arguments adaptor frame.
1538 Label adaptor_frame, try_allocate;
1539 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1540 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1541 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1542 __ b(eq, &adaptor_frame);
1544 // No adaptor, parameter count = argument count.
1546 __ b(&try_allocate);
1548 // We have an adaptor frame. Patch the parameters pointer.
1549 __ bind(&adaptor_frame);
1550 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1551 __ add(r3, r3, Operand(r2, LSL, 1));
1552 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1553 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1555 // r1 = parameter count (tagged)
1556 // r2 = argument count (tagged)
1557 // Compute the mapped parameter count = min(r1, r2) in r1.
1558 __ cmp(r1, Operand(r2));
1559 __ mov(r1, Operand(r2), LeaveCC, gt);
1561 __ bind(&try_allocate);
1563 // Compute the sizes of backing store, parameter map, and arguments object.
1564 // 1. Parameter map, has 2 extra words containing context and backing store.
1565 const int kParameterMapHeaderSize =
1566 FixedArray::kHeaderSize + 2 * kPointerSize;
1567 // If there are no mapped parameters, we do not need the parameter_map.
1568 __ cmp(r1, Operand(Smi::FromInt(0)));
1569 __ mov(r9, Operand::Zero(), LeaveCC, eq);
1570 __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne);
1571 __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne);
1573 // 2. Backing store.
1574 __ add(r9, r9, Operand(r2, LSL, 1));
1575 __ add(r9, r9, Operand(FixedArray::kHeaderSize));
1577 // 3. Arguments object.
1578 __ add(r9, r9, Operand(Heap::kSloppyArgumentsObjectSize));
1580 // Do the allocation of all three objects in one go.
1581 __ Allocate(r9, r0, r3, r4, &runtime, TAG_OBJECT);
1583 // r0 = address of new object(s) (tagged)
1584 // r2 = argument count (smi-tagged)
1585 // Get the arguments boilerplate from the current native context into r4.
1586 const int kNormalOffset =
1587 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1588 const int kAliasedOffset =
1589 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1591 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1592 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1593 __ cmp(r1, Operand::Zero());
1594 __ ldr(r4, MemOperand(r4, kNormalOffset), eq);
1595 __ ldr(r4, MemOperand(r4, kAliasedOffset), ne);
1597 // r0 = address of new object (tagged)
1598 // r1 = mapped parameter count (tagged)
1599 // r2 = argument count (smi-tagged)
1600 // r4 = address of arguments map (tagged)
1601 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1602 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1603 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1604 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1606 // Set up the callee in-object property.
1607 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1608 __ ldr(r3, MemOperand(sp, 2 * kPointerSize));
1609 __ AssertNotSmi(r3);
1610 const int kCalleeOffset = JSObject::kHeaderSize +
1611 Heap::kArgumentsCalleeIndex * kPointerSize;
1612 __ str(r3, FieldMemOperand(r0, kCalleeOffset));
1614 // Use the length (smi tagged) and set that as an in-object property too.
1616 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1617 const int kLengthOffset = JSObject::kHeaderSize +
1618 Heap::kArgumentsLengthIndex * kPointerSize;
1619 __ str(r2, FieldMemOperand(r0, kLengthOffset));
1621 // Set up the elements pointer in the allocated arguments object.
1622 // If we allocated a parameter map, r4 will point there, otherwise
1623 // it will point to the backing store.
1624 __ add(r4, r0, Operand(Heap::kSloppyArgumentsObjectSize));
1625 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1627 // r0 = address of new object (tagged)
1628 // r1 = mapped parameter count (tagged)
1629 // r2 = argument count (tagged)
1630 // r4 = address of parameter map or backing store (tagged)
1631 // Initialize parameter map. If there are no mapped arguments, we're done.
1632 Label skip_parameter_map;
1633 __ cmp(r1, Operand(Smi::FromInt(0)));
1634 // Move backing store address to r3, because it is
1635 // expected there when filling in the unmapped arguments.
1636 __ mov(r3, r4, LeaveCC, eq);
1637 __ b(eq, &skip_parameter_map);
1639 __ LoadRoot(r6, Heap::kSloppyArgumentsElementsMapRootIndex);
1640 __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset));
1641 __ add(r6, r1, Operand(Smi::FromInt(2)));
1642 __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset));
1643 __ str(cp, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize));
1644 __ add(r6, r4, Operand(r1, LSL, 1));
1645 __ add(r6, r6, Operand(kParameterMapHeaderSize));
1646 __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize));
1648 // Copy the parameter slots and the holes in the arguments.
1649 // We need to fill in mapped_parameter_count slots. They index the context,
1650 // where parameters are stored in reverse order, at
1651 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1652 // The mapped parameter thus need to get indices
1653 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1654 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1655 // We loop from right to left.
1656 Label parameters_loop, parameters_test;
1658 __ ldr(r9, MemOperand(sp, 0 * kPointerSize));
1659 __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1660 __ sub(r9, r9, Operand(r1));
1661 __ LoadRoot(r5, Heap::kTheHoleValueRootIndex);
1662 __ add(r3, r4, Operand(r6, LSL, 1));
1663 __ add(r3, r3, Operand(kParameterMapHeaderSize));
1665 // r6 = loop variable (tagged)
1666 // r1 = mapping index (tagged)
1667 // r3 = address of backing store (tagged)
1668 // r4 = address of parameter map (tagged), which is also the address of new
1669 // object + Heap::kSloppyArgumentsObjectSize (tagged)
1670 // r0 = temporary scratch (a.o., for address calculation)
1671 // r5 = the hole value
1672 __ jmp(¶meters_test);
1674 __ bind(¶meters_loop);
1675 __ sub(r6, r6, Operand(Smi::FromInt(1)));
1676 __ mov(r0, Operand(r6, LSL, 1));
1677 __ add(r0, r0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1678 __ str(r9, MemOperand(r4, r0));
1679 __ sub(r0, r0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1680 __ str(r5, MemOperand(r3, r0));
1681 __ add(r9, r9, Operand(Smi::FromInt(1)));
1682 __ bind(¶meters_test);
1683 __ cmp(r6, Operand(Smi::FromInt(0)));
1684 __ b(ne, ¶meters_loop);
1686 // Restore r0 = new object (tagged)
1687 __ sub(r0, r4, Operand(Heap::kSloppyArgumentsObjectSize));
1689 __ bind(&skip_parameter_map);
1690 // r0 = address of new object (tagged)
1691 // r2 = argument count (tagged)
1692 // r3 = address of backing store (tagged)
1694 // Copy arguments header and remaining slots (if there are any).
1695 __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex);
1696 __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset));
1697 __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset));
1699 Label arguments_loop, arguments_test;
1701 __ ldr(r4, MemOperand(sp, 1 * kPointerSize));
1702 __ sub(r4, r4, Operand(r9, LSL, 1));
1703 __ jmp(&arguments_test);
1705 __ bind(&arguments_loop);
1706 __ sub(r4, r4, Operand(kPointerSize));
1707 __ ldr(r6, MemOperand(r4, 0));
1708 __ add(r5, r3, Operand(r9, LSL, 1));
1709 __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize));
1710 __ add(r9, r9, Operand(Smi::FromInt(1)));
1712 __ bind(&arguments_test);
1713 __ cmp(r9, Operand(r2));
1714 __ b(lt, &arguments_loop);
1716 // Return and remove the on-stack parameters.
1717 __ add(sp, sp, Operand(3 * kPointerSize));
1720 // Do the runtime call to allocate the arguments object.
1721 // r0 = address of new object (tagged)
1722 // r2 = argument count (tagged)
1724 __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1725 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1729 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1730 // Return address is in lr.
1733 Register receiver = LoadDescriptor::ReceiverRegister();
1734 Register key = LoadDescriptor::NameRegister();
1736 // Check that the key is an array index, that is Uint32.
1737 __ NonNegativeSmiTst(key);
1740 // Everything is fine, call runtime.
1741 __ Push(receiver, key); // Receiver, key.
1743 // Perform tail call to the entry.
1744 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1747 PropertyAccessCompiler::TailCallBuiltin(
1748 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1752 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1753 // sp[0] : number of parameters
1754 // sp[4] : receiver displacement
1756 // Check if the calling frame is an arguments adaptor frame.
1757 Label adaptor_frame, try_allocate, runtime;
1758 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1759 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1760 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1761 __ b(eq, &adaptor_frame);
1763 // Get the length from the frame.
1764 __ ldr(r1, MemOperand(sp, 0));
1765 __ b(&try_allocate);
1767 // Patch the arguments.length and the parameters pointer.
1768 __ bind(&adaptor_frame);
1769 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1770 __ str(r1, MemOperand(sp, 0));
1771 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1772 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1773 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1775 // Try the new space allocation. Start out with computing the size
1776 // of the arguments object and the elements array in words.
1777 Label add_arguments_object;
1778 __ bind(&try_allocate);
1779 __ SmiUntag(r1, SetCC);
1780 __ b(eq, &add_arguments_object);
1781 __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize));
1782 __ bind(&add_arguments_object);
1783 __ add(r1, r1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1785 // Do the allocation of both objects in one go.
1786 __ Allocate(r1, r0, r2, r3, &runtime,
1787 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1789 // Get the arguments boilerplate from the current native context.
1790 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1791 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1792 __ ldr(r4, MemOperand(
1793 r4, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1795 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1796 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1797 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1798 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1800 // Get the length (smi tagged) and set that as an in-object property too.
1801 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1802 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1804 __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize +
1805 Heap::kArgumentsLengthIndex * kPointerSize));
1807 // If there are no actual arguments, we're done.
1809 __ cmp(r1, Operand::Zero());
1812 // Get the parameters pointer from the stack.
1813 __ ldr(r2, MemOperand(sp, 1 * kPointerSize));
1815 // Set up the elements pointer in the allocated arguments object and
1816 // initialize the header in the elements fixed array.
1817 __ add(r4, r0, Operand(Heap::kStrictArgumentsObjectSize));
1818 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1819 __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex);
1820 __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset));
1821 __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset));
1824 // Copy the fixed array slots.
1826 // Set up r4 to point to the first array slot.
1827 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1829 // Pre-decrement r2 with kPointerSize on each iteration.
1830 // Pre-decrement in order to skip receiver.
1831 __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
1832 // Post-increment r4 with kPointerSize on each iteration.
1833 __ str(r3, MemOperand(r4, kPointerSize, PostIndex));
1834 __ sub(r1, r1, Operand(1));
1835 __ cmp(r1, Operand::Zero());
1838 // Return and remove the on-stack parameters.
1840 __ add(sp, sp, Operand(3 * kPointerSize));
1843 // Do the runtime call to allocate the arguments object.
1845 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1849 void RegExpExecStub::Generate(MacroAssembler* masm) {
1850 // Just jump directly to runtime if native RegExp is not selected at compile
1851 // time or if regexp entry in generated code is turned off runtime switch or
1853 #ifdef V8_INTERPRETED_REGEXP
1854 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1855 #else // V8_INTERPRETED_REGEXP
1857 // Stack frame on entry.
1858 // sp[0]: last_match_info (expected JSArray)
1859 // sp[4]: previous index
1860 // sp[8]: subject string
1861 // sp[12]: JSRegExp object
1863 const int kLastMatchInfoOffset = 0 * kPointerSize;
1864 const int kPreviousIndexOffset = 1 * kPointerSize;
1865 const int kSubjectOffset = 2 * kPointerSize;
1866 const int kJSRegExpOffset = 3 * kPointerSize;
1869 // Allocation of registers for this function. These are in callee save
1870 // registers and will be preserved by the call to the native RegExp code, as
1871 // this code is called using the normal C calling convention. When calling
1872 // directly from generated code the native RegExp code will not do a GC and
1873 // therefore the content of these registers are safe to use after the call.
1874 Register subject = r4;
1875 Register regexp_data = r5;
1876 Register last_match_info_elements = no_reg; // will be r6;
1878 // Ensure that a RegExp stack is allocated.
1879 ExternalReference address_of_regexp_stack_memory_address =
1880 ExternalReference::address_of_regexp_stack_memory_address(isolate());
1881 ExternalReference address_of_regexp_stack_memory_size =
1882 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1883 __ mov(r0, Operand(address_of_regexp_stack_memory_size));
1884 __ ldr(r0, MemOperand(r0, 0));
1885 __ cmp(r0, Operand::Zero());
1888 // Check that the first argument is a JSRegExp object.
1889 __ ldr(r0, MemOperand(sp, kJSRegExpOffset));
1890 __ JumpIfSmi(r0, &runtime);
1891 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
1894 // Check that the RegExp has been compiled (data contains a fixed array).
1895 __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
1896 if (FLAG_debug_code) {
1897 __ SmiTst(regexp_data);
1898 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1899 __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
1900 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1903 // regexp_data: RegExp data (FixedArray)
1904 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1905 __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1906 __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
1909 // regexp_data: RegExp data (FixedArray)
1910 // Check that the number of captures fit in the static offsets vector buffer.
1912 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1913 // Check (number_of_captures + 1) * 2 <= offsets vector size
1914 // Or number_of_captures * 2 <= offsets vector size - 2
1915 // Multiplying by 2 comes for free since r2 is smi-tagged.
1916 STATIC_ASSERT(kSmiTag == 0);
1917 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
1918 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1919 __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
1922 // Reset offset for possibly sliced string.
1923 __ mov(r9, Operand::Zero());
1924 __ ldr(subject, MemOperand(sp, kSubjectOffset));
1925 __ JumpIfSmi(subject, &runtime);
1926 __ mov(r3, subject); // Make a copy of the original subject string.
1927 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1928 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
1929 // subject: subject string
1930 // r3: subject string
1931 // r0: subject string instance type
1932 // regexp_data: RegExp data (FixedArray)
1933 // Handle subject string according to its encoding and representation:
1934 // (1) Sequential string? If yes, go to (5).
1935 // (2) Anything but sequential or cons? If yes, go to (6).
1936 // (3) Cons string. If the string is flat, replace subject with first string.
1937 // Otherwise bailout.
1938 // (4) Is subject external? If yes, go to (7).
1939 // (5) Sequential string. Load regexp code according to encoding.
1943 // Deferred code at the end of the stub:
1944 // (6) Not a long external string? If yes, go to (8).
1945 // (7) External string. Make it, offset-wise, look like a sequential string.
1947 // (8) Short external string or not a string? If yes, bail out to runtime.
1948 // (9) Sliced string. Replace subject with parent. Go to (4).
1950 Label seq_string /* 5 */, external_string /* 7 */,
1951 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
1952 not_long_external /* 8 */;
1954 // (1) Sequential string? If yes, go to (5).
1957 Operand(kIsNotStringMask |
1958 kStringRepresentationMask |
1959 kShortExternalStringMask),
1961 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
1962 __ b(eq, &seq_string); // Go to (5).
1964 // (2) Anything but sequential or cons? If yes, go to (6).
1965 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1966 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
1967 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1968 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
1969 __ cmp(r1, Operand(kExternalStringTag));
1970 __ b(ge, ¬_seq_nor_cons); // Go to (6).
1972 // (3) Cons string. Check that it's flat.
1973 // Replace subject with first string and reload instance type.
1974 __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
1975 __ CompareRoot(r0, Heap::kempty_stringRootIndex);
1977 __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
1979 // (4) Is subject external? If yes, go to (7).
1980 __ bind(&check_underlying);
1981 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1982 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
1983 STATIC_ASSERT(kSeqStringTag == 0);
1984 __ tst(r0, Operand(kStringRepresentationMask));
1985 // The underlying external string is never a short external string.
1986 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
1987 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
1988 __ b(ne, &external_string); // Go to (7).
1990 // (5) Sequential string. Load regexp code according to encoding.
1991 __ bind(&seq_string);
1992 // subject: sequential subject string (or look-alike, external string)
1993 // r3: original subject string
1994 // Load previous index and check range before r3 is overwritten. We have to
1995 // use r3 instead of subject here because subject might have been only made
1996 // to look like a sequential string when it actually is an external string.
1997 __ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
1998 __ JumpIfNotSmi(r1, &runtime);
1999 __ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
2000 __ cmp(r3, Operand(r1));
2004 STATIC_ASSERT(4 == kOneByteStringTag);
2005 STATIC_ASSERT(kTwoByteStringTag == 0);
2006 __ and_(r0, r0, Operand(kStringEncodingMask));
2007 __ mov(r3, Operand(r0, ASR, 2), SetCC);
2008 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset),
2010 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
2012 // (E) Carry on. String handling is done.
2013 // r6: irregexp code
2014 // Check that the irregexp code has been generated for the actual string
2015 // encoding. If it has, the field contains a code object otherwise it contains
2016 // a smi (code flushing support).
2017 __ JumpIfSmi(r6, &runtime);
2019 // r1: previous index
2020 // r3: encoding of subject string (1 if one_byte, 0 if two_byte);
2022 // subject: Subject string
2023 // regexp_data: RegExp data (FixedArray)
2024 // All checks done. Now push arguments for native regexp code.
2025 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r0, r2);
2027 // Isolates: note we add an additional parameter here (isolate pointer).
2028 const int kRegExpExecuteArguments = 9;
2029 const int kParameterRegisters = 4;
2030 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2032 // Stack pointer now points to cell where return address is to be written.
2033 // Arguments are before that on the stack or in registers.
2035 // Argument 9 (sp[20]): Pass current isolate address.
2036 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2037 __ str(r0, MemOperand(sp, 5 * kPointerSize));
2039 // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
2040 __ mov(r0, Operand(1));
2041 __ str(r0, MemOperand(sp, 4 * kPointerSize));
2043 // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
2044 __ mov(r0, Operand(address_of_regexp_stack_memory_address));
2045 __ ldr(r0, MemOperand(r0, 0));
2046 __ mov(r2, Operand(address_of_regexp_stack_memory_size));
2047 __ ldr(r2, MemOperand(r2, 0));
2048 __ add(r0, r0, Operand(r2));
2049 __ str(r0, MemOperand(sp, 3 * kPointerSize));
2051 // Argument 6: Set the number of capture registers to zero to force global
2052 // regexps to behave as non-global. This does not affect non-global regexps.
2053 __ mov(r0, Operand::Zero());
2054 __ str(r0, MemOperand(sp, 2 * kPointerSize));
2056 // Argument 5 (sp[4]): static offsets vector buffer.
2058 Operand(ExternalReference::address_of_static_offsets_vector(
2060 __ str(r0, MemOperand(sp, 1 * kPointerSize));
2062 // For arguments 4 and 3 get string length, calculate start of string data and
2063 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2064 __ add(r7, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2065 __ eor(r3, r3, Operand(1));
2066 // Load the length from the original subject string from the previous stack
2067 // frame. Therefore we have to use fp, which points exactly to two pointer
2068 // sizes below the previous sp. (Because creating a new stack frame pushes
2069 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2070 __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2071 // If slice offset is not 0, load the length from the original sliced string.
2072 // Argument 4, r3: End of string data
2073 // Argument 3, r2: Start of string data
2074 // Prepare start and end index of the input.
2075 __ add(r9, r7, Operand(r9, LSL, r3));
2076 __ add(r2, r9, Operand(r1, LSL, r3));
2078 __ ldr(r7, FieldMemOperand(subject, String::kLengthOffset));
2080 __ add(r3, r9, Operand(r7, LSL, r3));
2082 // Argument 2 (r1): Previous index.
2085 // Argument 1 (r0): Subject string.
2086 __ mov(r0, subject);
2088 // Locate the code entry and call it.
2089 __ add(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
2090 DirectCEntryStub stub(isolate());
2091 stub.GenerateCall(masm, r6);
2093 __ LeaveExitFrame(false, no_reg, true);
2095 last_match_info_elements = r6;
2098 // subject: subject string (callee saved)
2099 // regexp_data: RegExp data (callee saved)
2100 // last_match_info_elements: Last match info elements (callee saved)
2101 // Check the result.
2103 __ cmp(r0, Operand(1));
2104 // We expect exactly one result since we force the called regexp to behave
2108 __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
2110 __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2111 // If not exception it can only be retry. Handle that in the runtime system.
2113 // Result must now be exception. If there is no pending exception already a
2114 // stack overflow (on the backtrack stack) was detected in RegExp code but
2115 // haven't created the exception yet. Handle that in the runtime system.
2116 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2117 __ mov(r1, Operand(isolate()->factory()->the_hole_value()));
2118 __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2120 __ ldr(r0, MemOperand(r2, 0));
2124 // For exception, throw the exception again.
2125 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2128 // For failure and exception return null.
2129 __ mov(r0, Operand(isolate()->factory()->null_value()));
2130 __ add(sp, sp, Operand(4 * kPointerSize));
2133 // Process the result from the native regexp code.
2136 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2137 // Calculate number of capture registers (number_of_captures + 1) * 2.
2138 // Multiplying by 2 comes for free since r1 is smi-tagged.
2139 STATIC_ASSERT(kSmiTag == 0);
2140 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2141 __ add(r1, r1, Operand(2)); // r1 was a smi.
2143 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2144 __ JumpIfSmi(r0, &runtime);
2145 __ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
2147 // Check that the JSArray is in fast case.
2148 __ ldr(last_match_info_elements,
2149 FieldMemOperand(r0, JSArray::kElementsOffset));
2150 __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2151 __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
2153 // Check that the last match info has space for the capture registers and the
2154 // additional information.
2156 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2157 __ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
2158 __ cmp(r2, Operand::SmiUntag(r0));
2161 // r1: number of capture registers
2162 // r4: subject string
2163 // Store the capture count.
2165 __ str(r2, FieldMemOperand(last_match_info_elements,
2166 RegExpImpl::kLastCaptureCountOffset));
2167 // Store last subject and last input.
2169 FieldMemOperand(last_match_info_elements,
2170 RegExpImpl::kLastSubjectOffset));
2171 __ mov(r2, subject);
2172 __ RecordWriteField(last_match_info_elements,
2173 RegExpImpl::kLastSubjectOffset,
2178 __ mov(subject, r2);
2180 FieldMemOperand(last_match_info_elements,
2181 RegExpImpl::kLastInputOffset));
2182 __ RecordWriteField(last_match_info_elements,
2183 RegExpImpl::kLastInputOffset,
2189 // Get the static offsets vector filled by the native regexp code.
2190 ExternalReference address_of_static_offsets_vector =
2191 ExternalReference::address_of_static_offsets_vector(isolate());
2192 __ mov(r2, Operand(address_of_static_offsets_vector));
2194 // r1: number of capture registers
2195 // r2: offsets vector
2196 Label next_capture, done;
2197 // Capture register counter starts from number of capture registers and
2198 // counts down until wraping after zero.
2200 last_match_info_elements,
2201 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2202 __ bind(&next_capture);
2203 __ sub(r1, r1, Operand(1), SetCC);
2205 // Read the value from the static offsets vector buffer.
2206 __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
2207 // Store the smi value in the last match info.
2209 __ str(r3, MemOperand(r0, kPointerSize, PostIndex));
2210 __ jmp(&next_capture);
2213 // Return last match info.
2214 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2215 __ add(sp, sp, Operand(4 * kPointerSize));
2218 // Do the runtime call to execute the regexp.
2220 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2222 // Deferred code for string handling.
2223 // (6) Not a long external string? If yes, go to (8).
2224 __ bind(¬_seq_nor_cons);
2225 // Compare flags are still set.
2226 __ b(gt, ¬_long_external); // Go to (8).
2228 // (7) External string. Make it, offset-wise, look like a sequential string.
2229 __ bind(&external_string);
2230 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2231 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2232 if (FLAG_debug_code) {
2233 // Assert that we do not have a cons or slice (indirect strings) here.
2234 // Sequential strings have already been ruled out.
2235 __ tst(r0, Operand(kIsIndirectStringMask));
2236 __ Assert(eq, kExternalStringExpectedButNotFound);
2239 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2240 // Move the pointer so that offset-wise, it looks like a sequential string.
2241 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2244 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2245 __ jmp(&seq_string); // Go to (5).
2247 // (8) Short external string or not a string? If yes, bail out to runtime.
2248 __ bind(¬_long_external);
2249 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2250 __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
2253 // (9) Sliced string. Replace subject with parent. Go to (4).
2254 // Load offset into r9 and replace subject string with parent.
2255 __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2257 __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2258 __ jmp(&check_underlying); // Go to (4).
2259 #endif // V8_INTERPRETED_REGEXP
2263 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2265 // r0 : number of arguments to the construct function
2266 // r1 : the function to call
2267 // r2 : feedback vector
2268 // r3 : slot in feedback vector (Smi)
2269 // r4 : original constructor (for IsSuperConstructorCall)
2270 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2272 // Number-of-arguments register must be smi-tagged to call out.
2274 __ Push(r3, r2, r1, r0);
2284 __ Pop(r3, r2, r1, r0);
2289 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2290 // Cache the called function in a feedback vector slot. Cache states
2291 // are uninitialized, monomorphic (indicated by a JSFunction), and
2293 // r0 : number of arguments to the construct function
2294 // r1 : the function to call
2295 // r2 : feedback vector
2296 // r3 : slot in feedback vector (Smi)
2297 // r4 : original constructor (for IsSuperConstructorCall)
2298 Label initialize, done, miss, megamorphic, not_array_function;
2300 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2301 masm->isolate()->heap()->megamorphic_symbol());
2302 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2303 masm->isolate()->heap()->uninitialized_symbol());
2305 // Load the cache state into r5.
2306 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2307 __ ldr(r5, FieldMemOperand(r5, FixedArray::kHeaderSize));
2309 // A monomorphic cache hit or an already megamorphic state: invoke the
2310 // function without changing the state.
2311 // We don't know if r5 is a WeakCell or a Symbol, but it's harmless to read at
2312 // this position in a symbol (see static asserts in type-feedback-vector.h).
2313 Label check_allocation_site;
2314 Register feedback_map = r6;
2315 Register weak_value = r9;
2316 __ ldr(weak_value, FieldMemOperand(r5, WeakCell::kValueOffset));
2317 __ cmp(r1, weak_value);
2319 __ CompareRoot(r5, Heap::kmegamorphic_symbolRootIndex);
2321 __ ldr(feedback_map, FieldMemOperand(r5, HeapObject::kMapOffset));
2322 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2323 __ b(ne, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2325 // If the weak cell is cleared, we have a new chance to become monomorphic.
2326 __ JumpIfSmi(weak_value, &initialize);
2327 __ jmp(&megamorphic);
2329 if (!FLAG_pretenuring_call_new) {
2330 __ bind(&check_allocation_site);
2331 // If we came here, we need to see if we are the array function.
2332 // If we didn't have a matching function, and we didn't find the megamorph
2333 // sentinel, then we have in the slot either some other function or an
2335 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2338 // Make sure the function is the Array() function
2339 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2341 __ b(ne, &megamorphic);
2347 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2349 __ CompareRoot(r5, Heap::kuninitialized_symbolRootIndex);
2350 __ b(eq, &initialize);
2351 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2352 // write-barrier is needed.
2353 __ bind(&megamorphic);
2354 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2355 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2356 __ str(ip, FieldMemOperand(r5, FixedArray::kHeaderSize));
2359 // An uninitialized cache is patched with the function
2360 __ bind(&initialize);
2362 if (!FLAG_pretenuring_call_new) {
2363 // Make sure the function is the Array() function
2364 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2366 __ b(ne, ¬_array_function);
2368 // The target function is the Array constructor,
2369 // Create an AllocationSite if we don't already have it, store it in the
2371 CreateAllocationSiteStub create_stub(masm->isolate());
2372 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2375 __ bind(¬_array_function);
2378 CreateWeakCellStub create_stub(masm->isolate());
2379 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2384 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2385 // Do not transform the receiver for strict mode functions.
2386 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2387 __ ldr(r4, FieldMemOperand(r3, SharedFunctionInfo::kCompilerHintsOffset));
2388 __ tst(r4, Operand(1 << (SharedFunctionInfo::kStrictModeFunction +
2392 // Do not transform the receiver for native (Compilerhints already in r3).
2393 __ tst(r4, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
2398 static void EmitSlowCase(MacroAssembler* masm, int argc) {
2399 __ mov(r0, Operand(argc));
2400 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2404 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2405 // Wrap the receiver and patch it back onto the stack.
2406 { FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2409 ToObjectStub stub(masm->isolate());
2413 __ str(r0, MemOperand(sp, argc * kPointerSize));
2418 static void CallFunctionNoFeedback(MacroAssembler* masm,
2419 int argc, bool needs_checks,
2420 bool call_as_method) {
2421 // r1 : the function to call
2422 Label slow, wrap, cont;
2425 // Check that the function is really a JavaScript function.
2426 // r1: pushed function (to be verified)
2427 __ JumpIfSmi(r1, &slow);
2429 // Goto slow case if we do not have a function.
2430 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2434 // Fast-case: Invoke the function now.
2435 // r1: pushed function
2436 ParameterCount actual(argc);
2438 if (call_as_method) {
2440 EmitContinueIfStrictOrNative(masm, &cont);
2443 // Compute the receiver in sloppy mode.
2444 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2447 __ JumpIfSmi(r3, &wrap);
2448 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2457 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2460 // Slow-case: Non-function called.
2462 EmitSlowCase(masm, argc);
2465 if (call_as_method) {
2467 EmitWrapCase(masm, argc, &cont);
2472 void CallFunctionStub::Generate(MacroAssembler* masm) {
2473 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2477 void CallConstructStub::Generate(MacroAssembler* masm) {
2478 // r0 : number of arguments
2479 // r1 : the function to call
2480 // r2 : feedback vector
2481 // r3 : slot in feedback vector (Smi, for RecordCallTarget)
2482 // r4 : original constructor (for IsSuperConstructorCall)
2483 Label slow, non_function_call;
2485 // Check that the function is not a smi.
2486 __ JumpIfSmi(r1, &non_function_call);
2487 // Check that the function is a JSFunction.
2488 __ CompareObjectType(r1, r5, r5, JS_FUNCTION_TYPE);
2491 if (RecordCallTarget()) {
2492 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2494 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2495 if (FLAG_pretenuring_call_new) {
2496 // Put the AllocationSite from the feedback vector into r2.
2497 // By adding kPointerSize we encode that we know the AllocationSite
2498 // entry is at the feedback vector slot given by r3 + 1.
2499 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize + kPointerSize));
2501 Label feedback_register_initialized;
2502 // Put the AllocationSite from the feedback vector into r2, or undefined.
2503 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2504 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2505 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2506 __ b(eq, &feedback_register_initialized);
2507 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2508 __ bind(&feedback_register_initialized);
2511 __ AssertUndefinedOrAllocationSite(r2, r5);
2514 // Pass function as original constructor.
2515 if (IsSuperConstructorCall()) {
2521 // Jump to the function-specific construct stub.
2522 Register jmp_reg = r4;
2523 __ ldr(jmp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2524 __ ldr(jmp_reg, FieldMemOperand(jmp_reg,
2525 SharedFunctionInfo::kConstructStubOffset));
2526 __ add(pc, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2528 // r0: number of arguments
2529 // r1: called object
2533 __ cmp(r5, Operand(JS_FUNCTION_PROXY_TYPE));
2534 __ b(ne, &non_function_call);
2535 __ GetBuiltinFunction(
2536 r1, Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2539 __ bind(&non_function_call);
2540 __ GetBuiltinFunction(
2541 r1, Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2543 // Set expected number of arguments to zero (not changing r0).
2544 __ mov(r2, Operand::Zero());
2545 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2546 RelocInfo::CODE_TARGET);
2550 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2551 __ ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2552 __ ldr(vector, FieldMemOperand(vector,
2553 JSFunction::kSharedFunctionInfoOffset));
2554 __ ldr(vector, FieldMemOperand(vector,
2555 SharedFunctionInfo::kFeedbackVectorOffset));
2559 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2564 int argc = arg_count();
2565 ParameterCount actual(argc);
2567 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2571 __ mov(r0, Operand(arg_count()));
2572 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2573 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2575 // Verify that r4 contains an AllocationSite
2576 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2577 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2580 // Increment the call count for monomorphic function calls.
2581 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2582 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2583 __ ldr(r3, FieldMemOperand(r2, 0));
2584 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2585 __ str(r3, FieldMemOperand(r2, 0));
2589 ArrayConstructorStub stub(masm->isolate(), arg_count());
2590 __ TailCallStub(&stub);
2595 // The slow case, we need this no matter what to complete a call after a miss.
2596 __ mov(r0, Operand(arg_count()));
2597 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2601 void CallICStub::Generate(MacroAssembler* masm) {
2603 // r3 - slot id (Smi)
2605 const int with_types_offset =
2606 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2607 const int generic_offset =
2608 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2609 Label extra_checks_or_miss, slow_start;
2610 Label slow, wrap, cont;
2611 Label have_js_function;
2612 int argc = arg_count();
2613 ParameterCount actual(argc);
2615 // The checks. First, does r1 match the recorded monomorphic target?
2616 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2617 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2619 // We don't know that we have a weak cell. We might have a private symbol
2620 // or an AllocationSite, but the memory is safe to examine.
2621 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2623 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2624 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2625 // computed, meaning that it can't appear to be a pointer. If the low bit is
2626 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2628 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2629 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2630 WeakCell::kValueOffset &&
2631 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2633 __ ldr(r5, FieldMemOperand(r4, WeakCell::kValueOffset));
2635 __ b(ne, &extra_checks_or_miss);
2637 // The compare above could have been a SMI/SMI comparison. Guard against this
2638 // convincing us that we have a monomorphic JSFunction.
2639 __ JumpIfSmi(r1, &extra_checks_or_miss);
2641 // Increment the call count for monomorphic function calls.
2642 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2643 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2644 __ ldr(r3, FieldMemOperand(r2, 0));
2645 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2646 __ str(r3, FieldMemOperand(r2, 0));
2648 __ bind(&have_js_function);
2649 if (CallAsMethod()) {
2650 EmitContinueIfStrictOrNative(masm, &cont);
2651 // Compute the receiver in sloppy mode.
2652 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2654 __ JumpIfSmi(r3, &wrap);
2655 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2661 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2664 EmitSlowCase(masm, argc);
2666 if (CallAsMethod()) {
2668 EmitWrapCase(masm, argc, &cont);
2671 __ bind(&extra_checks_or_miss);
2672 Label uninitialized, miss;
2674 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2675 __ b(eq, &slow_start);
2677 // The following cases attempt to handle MISS cases without going to the
2679 if (FLAG_trace_ic) {
2683 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2684 __ b(eq, &uninitialized);
2686 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2687 // to handle it here. More complex cases are dealt with in the runtime.
2688 __ AssertNotSmi(r4);
2689 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2691 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2692 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2693 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2694 // We have to update statistics for runtime profiling.
2695 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2696 __ sub(r4, r4, Operand(Smi::FromInt(1)));
2697 __ str(r4, FieldMemOperand(r2, with_types_offset));
2698 __ ldr(r4, FieldMemOperand(r2, generic_offset));
2699 __ add(r4, r4, Operand(Smi::FromInt(1)));
2700 __ str(r4, FieldMemOperand(r2, generic_offset));
2701 __ jmp(&slow_start);
2703 __ bind(&uninitialized);
2705 // We are going monomorphic, provided we actually have a JSFunction.
2706 __ JumpIfSmi(r1, &miss);
2708 // Goto miss case if we do not have a function.
2709 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2712 // Make sure the function is not the Array() function, which requires special
2713 // behavior on MISS.
2714 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2719 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2720 __ add(r4, r4, Operand(Smi::FromInt(1)));
2721 __ str(r4, FieldMemOperand(r2, with_types_offset));
2723 // Initialize the call counter.
2724 __ Move(r5, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2725 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2726 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + kPointerSize));
2728 // Store the function. Use a stub since we need a frame for allocation.
2733 FrameScope scope(masm, StackFrame::INTERNAL);
2734 CreateWeakCellStub create_stub(masm->isolate());
2736 __ CallStub(&create_stub);
2740 __ jmp(&have_js_function);
2742 // We are here because tracing is on or we encountered a MISS case we can't
2748 __ bind(&slow_start);
2749 // Check that the function is really a JavaScript function.
2750 // r1: pushed function (to be verified)
2751 __ JumpIfSmi(r1, &slow);
2753 // Goto slow case if we do not have a function.
2754 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2756 __ jmp(&have_js_function);
2760 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2761 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2763 // Push the receiver and the function and feedback info.
2764 __ Push(r1, r2, r3);
2767 Runtime::FunctionId id = GetICState() == DEFAULT
2768 ? Runtime::kCallIC_Miss
2769 : Runtime::kCallIC_Customization_Miss;
2770 __ CallRuntime(id, 3);
2772 // Move result to edi and exit the internal frame.
2777 // StringCharCodeAtGenerator
2778 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2779 // If the receiver is a smi trigger the non-string case.
2780 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2781 __ JumpIfSmi(object_, receiver_not_string_);
2783 // Fetch the instance type of the receiver into result register.
2784 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2785 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2786 // If the receiver is not a string trigger the non-string case.
2787 __ tst(result_, Operand(kIsNotStringMask));
2788 __ b(ne, receiver_not_string_);
2791 // If the index is non-smi trigger the non-smi case.
2792 __ JumpIfNotSmi(index_, &index_not_smi_);
2793 __ bind(&got_smi_index_);
2795 // Check for index out of range.
2796 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
2797 __ cmp(ip, Operand(index_));
2798 __ b(ls, index_out_of_range_);
2800 __ SmiUntag(index_);
2802 StringCharLoadGenerator::Generate(masm,
2813 void StringCharCodeAtGenerator::GenerateSlow(
2814 MacroAssembler* masm, EmbedMode embed_mode,
2815 const RuntimeCallHelper& call_helper) {
2816 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2818 // Index is not a smi.
2819 __ bind(&index_not_smi_);
2820 // If index is a heap number, try converting it to an integer.
2823 Heap::kHeapNumberMapRootIndex,
2826 call_helper.BeforeCall(masm);
2827 if (embed_mode == PART_OF_IC_HANDLER) {
2828 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2829 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2831 // index_ is consumed by runtime conversion function.
2832 __ Push(object_, index_);
2834 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2835 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2837 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2838 // NumberToSmi discards numbers that are not exact integers.
2839 __ CallRuntime(Runtime::kNumberToSmi, 1);
2841 // Save the conversion result before the pop instructions below
2842 // have a chance to overwrite it.
2843 __ Move(index_, r0);
2844 if (embed_mode == PART_OF_IC_HANDLER) {
2845 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2846 LoadWithVectorDescriptor::SlotRegister(), object_);
2850 // Reload the instance type.
2851 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2852 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2853 call_helper.AfterCall(masm);
2854 // If index is still not a smi, it must be out of range.
2855 __ JumpIfNotSmi(index_, index_out_of_range_);
2856 // Otherwise, return to the fast path.
2857 __ jmp(&got_smi_index_);
2859 // Call runtime. We get here when the receiver is a string and the
2860 // index is a number, but the code of getting the actual character
2861 // is too complex (e.g., when the string needs to be flattened).
2862 __ bind(&call_runtime_);
2863 call_helper.BeforeCall(masm);
2865 __ Push(object_, index_);
2866 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2867 __ Move(result_, r0);
2868 call_helper.AfterCall(masm);
2871 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2875 // -------------------------------------------------------------------------
2876 // StringCharFromCodeGenerator
2878 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2879 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2880 STATIC_ASSERT(kSmiTag == 0);
2881 STATIC_ASSERT(kSmiShiftSize == 0);
2882 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2883 __ tst(code_, Operand(kSmiTagMask |
2884 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
2885 __ b(ne, &slow_case_);
2887 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2888 // At this point code register contains smi tagged one-byte char code.
2889 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
2890 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
2891 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
2892 __ b(eq, &slow_case_);
2897 void StringCharFromCodeGenerator::GenerateSlow(
2898 MacroAssembler* masm,
2899 const RuntimeCallHelper& call_helper) {
2900 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2902 __ bind(&slow_case_);
2903 call_helper.BeforeCall(masm);
2905 __ CallRuntime(Runtime::kCharFromCode, 1);
2906 __ Move(result_, r0);
2907 call_helper.AfterCall(masm);
2910 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2914 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
2917 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2922 String::Encoding encoding) {
2923 if (FLAG_debug_code) {
2924 // Check that destination is word aligned.
2925 __ tst(dest, Operand(kPointerAlignmentMask));
2926 __ Check(eq, kDestinationOfCopyNotAligned);
2929 // Assumes word reads and writes are little endian.
2930 // Nothing to do for zero characters.
2932 if (encoding == String::TWO_BYTE_ENCODING) {
2933 __ add(count, count, Operand(count), SetCC);
2936 Register limit = count; // Read until dest equals this.
2937 __ add(limit, dest, Operand(count));
2939 Label loop_entry, loop;
2940 // Copy bytes from src to dest until dest hits limit.
2943 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
2944 __ strb(scratch, MemOperand(dest, 1, PostIndex));
2945 __ bind(&loop_entry);
2946 __ cmp(dest, Operand(limit));
2953 void SubStringStub::Generate(MacroAssembler* masm) {
2956 // Stack frame on entry.
2957 // lr: return address
2962 // This stub is called from the native-call %_SubString(...), so
2963 // nothing can be assumed about the arguments. It is tested that:
2964 // "string" is a sequential string,
2965 // both "from" and "to" are smis, and
2966 // 0 <= from <= to <= string.length.
2967 // If any of these assumptions fail, we call the runtime system.
2969 const int kToOffset = 0 * kPointerSize;
2970 const int kFromOffset = 1 * kPointerSize;
2971 const int kStringOffset = 2 * kPointerSize;
2973 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
2974 STATIC_ASSERT(kFromOffset == kToOffset + 4);
2975 STATIC_ASSERT(kSmiTag == 0);
2976 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2978 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
2979 // instead because we bail out on non-smi values: ROR and ASR are equivalent
2980 // for smis but they set the flags in a way that's easier to optimize.
2981 __ mov(r2, Operand(r2, ROR, 1), SetCC);
2982 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
2983 // If either to or from had the smi tag bit set, then C is set now, and N
2984 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
2985 // We want to bailout to runtime here if From is negative. In that case, the
2986 // next instruction is not executed and we fall through to bailing out to
2988 // Executed if both r2 and r3 are untagged integers.
2989 __ sub(r2, r2, Operand(r3), SetCC, cc);
2990 // One of the above un-smis or the above SUB could have set N==1.
2991 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
2993 // Make sure first argument is a string.
2994 __ ldr(r0, MemOperand(sp, kStringOffset));
2995 __ JumpIfSmi(r0, &runtime);
2996 Condition is_string = masm->IsObjectStringType(r0, r1);
2997 __ b(NegateCondition(is_string), &runtime);
3000 __ cmp(r2, Operand(1));
3001 __ b(eq, &single_char);
3003 // Short-cut for the case of trivial substring.
3005 // r0: original string
3006 // r2: result string length
3007 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
3008 __ cmp(r2, Operand(r4, ASR, 1));
3009 // Return original string.
3010 __ b(eq, &return_r0);
3011 // Longer than original string's length or negative: unsafe arguments.
3013 // Shorter than original string's length: an actual substring.
3015 // Deal with different string types: update the index if necessary
3016 // and put the underlying string into r5.
3017 // r0: original string
3018 // r1: instance type
3020 // r3: from index (untagged)
3021 Label underlying_unpacked, sliced_string, seq_or_external_string;
3022 // If the string is not indirect, it can only be sequential or external.
3023 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3024 STATIC_ASSERT(kIsIndirectStringMask != 0);
3025 __ tst(r1, Operand(kIsIndirectStringMask));
3026 __ b(eq, &seq_or_external_string);
3028 __ tst(r1, Operand(kSlicedNotConsMask));
3029 __ b(ne, &sliced_string);
3030 // Cons string. Check whether it is flat, then fetch first part.
3031 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
3032 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
3034 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
3035 // Update instance type.
3036 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3037 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3038 __ jmp(&underlying_unpacked);
3040 __ bind(&sliced_string);
3041 // Sliced string. Fetch parent and correct start index by offset.
3042 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3043 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3044 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
3045 // Update instance type.
3046 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3047 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3048 __ jmp(&underlying_unpacked);
3050 __ bind(&seq_or_external_string);
3051 // Sequential or external string. Just move string to the expected register.
3054 __ bind(&underlying_unpacked);
3056 if (FLAG_string_slices) {
3058 // r5: underlying subject string
3059 // r1: instance type of underlying subject string
3061 // r3: adjusted start index (untagged)
3062 __ cmp(r2, Operand(SlicedString::kMinLength));
3063 // Short slice. Copy instead of slicing.
3064 __ b(lt, ©_routine);
3065 // Allocate new sliced string. At this point we do not reload the instance
3066 // type including the string encoding because we simply rely on the info
3067 // provided by the original string. It does not matter if the original
3068 // string's encoding is wrong because we always have to recheck encoding of
3069 // the newly created string's parent anyways due to externalized strings.
3070 Label two_byte_slice, set_slice_header;
3071 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3072 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3073 __ tst(r1, Operand(kStringEncodingMask));
3074 __ b(eq, &two_byte_slice);
3075 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
3076 __ jmp(&set_slice_header);
3077 __ bind(&two_byte_slice);
3078 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
3079 __ bind(&set_slice_header);
3080 __ mov(r3, Operand(r3, LSL, 1));
3081 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3082 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3085 __ bind(©_routine);
3088 // r5: underlying subject string
3089 // r1: instance type of underlying subject string
3091 // r3: adjusted start index (untagged)
3092 Label two_byte_sequential, sequential_string, allocate_result;
3093 STATIC_ASSERT(kExternalStringTag != 0);
3094 STATIC_ASSERT(kSeqStringTag == 0);
3095 __ tst(r1, Operand(kExternalStringTag));
3096 __ b(eq, &sequential_string);
3098 // Handle external string.
3099 // Rule out short external strings.
3100 STATIC_ASSERT(kShortExternalStringTag != 0);
3101 __ tst(r1, Operand(kShortExternalStringTag));
3103 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
3104 // r5 already points to the first character of underlying string.
3105 __ jmp(&allocate_result);
3107 __ bind(&sequential_string);
3108 // Locate first character of underlying subject string.
3109 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3110 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3112 __ bind(&allocate_result);
3113 // Sequential acii string. Allocate the result.
3114 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3115 __ tst(r1, Operand(kStringEncodingMask));
3116 __ b(eq, &two_byte_sequential);
3118 // Allocate and copy the resulting one-byte string.
3119 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
3121 // Locate first character of substring to copy.
3123 // Locate first character of result.
3124 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3126 // r0: result string
3127 // r1: first character of result string
3128 // r2: result string length
3129 // r5: first character of substring to copy
3130 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3131 StringHelper::GenerateCopyCharacters(
3132 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
3135 // Allocate and copy the resulting two-byte string.
3136 __ bind(&two_byte_sequential);
3137 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
3139 // Locate first character of substring to copy.
3140 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3141 __ add(r5, r5, Operand(r3, LSL, 1));
3142 // Locate first character of result.
3143 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3145 // r0: result string.
3146 // r1: first character of result.
3147 // r2: result length.
3148 // r5: first character of substring to copy.
3149 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3150 StringHelper::GenerateCopyCharacters(
3151 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
3153 __ bind(&return_r0);
3154 Counters* counters = isolate()->counters();
3155 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
3159 // Just jump to runtime to create the sub string.
3161 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3163 __ bind(&single_char);
3164 // r0: original string
3165 // r1: instance type
3167 // r3: from index (untagged)
3169 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
3170 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3171 generator.GenerateFast(masm);
3174 generator.SkipSlow(masm, &runtime);
3178 void ToNumberStub::Generate(MacroAssembler* masm) {
3179 // The ToNumber stub takes one argument in r0.
3181 __ JumpIfNotSmi(r0, ¬_smi);
3185 __ CompareObjectType(r0, r1, r1, HEAP_NUMBER_TYPE);
3187 // r1: receiver instance type
3190 Label not_string, slow_string;
3191 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
3192 __ b(hs, ¬_string);
3193 // Check if string has a cached array index.
3194 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
3195 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
3196 __ b(ne, &slow_string);
3197 __ IndexFromHash(r2, r0);
3199 __ bind(&slow_string);
3200 __ push(r0); // Push argument.
3201 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3202 __ bind(¬_string);
3205 __ cmp(r1, Operand(ODDBALL_TYPE));
3206 __ b(ne, ¬_oddball);
3207 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
3209 __ bind(¬_oddball);
3211 __ push(r0); // Push argument.
3212 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3216 void ToStringStub::Generate(MacroAssembler* masm) {
3217 // The ToString stub takes one argument in r0.
3219 __ JumpIfSmi(r0, &is_number);
3221 __ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE);
3223 // r1: receiver instance type
3226 Label not_heap_number;
3227 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
3228 __ b(ne, ¬_heap_number);
3229 __ bind(&is_number);
3230 NumberToStringStub stub(isolate());
3231 __ TailCallStub(&stub);
3232 __ bind(¬_heap_number);
3235 __ cmp(r1, Operand(ODDBALL_TYPE));
3236 __ b(ne, ¬_oddball);
3237 __ ldr(r0, FieldMemOperand(r0, Oddball::kToStringOffset));
3239 __ bind(¬_oddball);
3241 __ push(r0); // Push argument.
3242 __ TailCallRuntime(Runtime::kToString, 1, 1);
3246 void StringHelper::GenerateFlatOneByteStringEquals(
3247 MacroAssembler* masm, Register left, Register right, Register scratch1,
3248 Register scratch2, Register scratch3) {
3249 Register length = scratch1;
3252 Label strings_not_equal, check_zero_length;
3253 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
3254 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3255 __ cmp(length, scratch2);
3256 __ b(eq, &check_zero_length);
3257 __ bind(&strings_not_equal);
3258 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
3261 // Check if the length is zero.
3262 Label compare_chars;
3263 __ bind(&check_zero_length);
3264 STATIC_ASSERT(kSmiTag == 0);
3265 __ cmp(length, Operand::Zero());
3266 __ b(ne, &compare_chars);
3267 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3270 // Compare characters.
3271 __ bind(&compare_chars);
3272 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3273 &strings_not_equal);
3275 // Characters are equal.
3276 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3281 void StringHelper::GenerateCompareFlatOneByteStrings(
3282 MacroAssembler* masm, Register left, Register right, Register scratch1,
3283 Register scratch2, Register scratch3, Register scratch4) {
3284 Label result_not_equal, compare_lengths;
3285 // Find minimum length and length difference.
3286 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3287 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3288 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
3289 Register length_delta = scratch3;
3290 __ mov(scratch1, scratch2, LeaveCC, gt);
3291 Register min_length = scratch1;
3292 STATIC_ASSERT(kSmiTag == 0);
3293 __ cmp(min_length, Operand::Zero());
3294 __ b(eq, &compare_lengths);
3297 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3298 scratch4, &result_not_equal);
3300 // Compare lengths - strings up to min-length are equal.
3301 __ bind(&compare_lengths);
3302 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3303 // Use length_delta as result if it's zero.
3304 __ mov(r0, Operand(length_delta), SetCC);
3305 __ bind(&result_not_equal);
3306 // Conditionally update the result based either on length_delta or
3307 // the last comparion performed in the loop above.
3308 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
3309 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
3314 void StringHelper::GenerateOneByteCharsCompareLoop(
3315 MacroAssembler* masm, Register left, Register right, Register length,
3316 Register scratch1, Register scratch2, Label* chars_not_equal) {
3317 // Change index to run from -length to -1 by adding length to string
3318 // start. This means that loop ends when index reaches zero, which
3319 // doesn't need an additional compare.
3320 __ SmiUntag(length);
3321 __ add(scratch1, length,
3322 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3323 __ add(left, left, Operand(scratch1));
3324 __ add(right, right, Operand(scratch1));
3325 __ rsb(length, length, Operand::Zero());
3326 Register index = length; // index = -length;
3331 __ ldrb(scratch1, MemOperand(left, index));
3332 __ ldrb(scratch2, MemOperand(right, index));
3333 __ cmp(scratch1, scratch2);
3334 __ b(ne, chars_not_equal);
3335 __ add(index, index, Operand(1), SetCC);
3340 void StringCompareStub::Generate(MacroAssembler* masm) {
3343 Counters* counters = isolate()->counters();
3345 // Stack frame on entry.
3346 // sp[0]: right string
3347 // sp[4]: left string
3348 __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1.
3352 __ b(ne, ¬_same);
3353 STATIC_ASSERT(EQUAL == 0);
3354 STATIC_ASSERT(kSmiTag == 0);
3355 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3356 __ IncrementCounter(counters->string_compare_native(), 1, r1, r2);
3357 __ add(sp, sp, Operand(2 * kPointerSize));
3362 // Check that both objects are sequential one-byte strings.
3363 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
3365 // Compare flat one-byte strings natively. Remove arguments from stack first.
3366 __ IncrementCounter(counters->string_compare_native(), 1, r2, r3);
3367 __ add(sp, sp, Operand(2 * kPointerSize));
3368 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
3370 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3371 // tagged as a small integer.
3373 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3377 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3378 // ----------- S t a t e -------------
3381 // -- lr : return address
3382 // -----------------------------------
3384 // Load r2 with the allocation site. We stick an undefined dummy value here
3385 // and replace it with the real allocation site later when we instantiate this
3386 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3387 __ Move(r2, handle(isolate()->heap()->undefined_value()));
3389 // Make sure that we actually patched the allocation site.
3390 if (FLAG_debug_code) {
3391 __ tst(r2, Operand(kSmiTagMask));
3392 __ Assert(ne, kExpectedAllocationSite);
3394 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3395 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3398 __ Assert(eq, kExpectedAllocationSite);
3401 // Tail call into the stub that handles binary operations with allocation
3403 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3404 __ TailCallStub(&stub);
3408 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3409 DCHECK(state() == CompareICState::SMI);
3412 __ JumpIfNotSmi(r2, &miss);
3414 if (GetCondition() == eq) {
3415 // For equality we do not care about the sign of the result.
3416 __ sub(r0, r0, r1, SetCC);
3418 // Untag before subtracting to avoid handling overflow.
3420 __ sub(r0, r1, Operand::SmiUntag(r0));
3429 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3430 DCHECK(state() == CompareICState::NUMBER);
3433 Label unordered, maybe_undefined1, maybe_undefined2;
3436 if (left() == CompareICState::SMI) {
3437 __ JumpIfNotSmi(r1, &miss);
3439 if (right() == CompareICState::SMI) {
3440 __ JumpIfNotSmi(r0, &miss);
3443 // Inlining the double comparison and falling back to the general compare
3444 // stub if NaN is involved.
3445 // Load left and right operand.
3446 Label done, left, left_smi, right_smi;
3447 __ JumpIfSmi(r0, &right_smi);
3448 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3450 __ sub(r2, r0, Operand(kHeapObjectTag));
3451 __ vldr(d1, r2, HeapNumber::kValueOffset);
3453 __ bind(&right_smi);
3454 __ SmiToDouble(d1, r0);
3457 __ JumpIfSmi(r1, &left_smi);
3458 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3460 __ sub(r2, r1, Operand(kHeapObjectTag));
3461 __ vldr(d0, r2, HeapNumber::kValueOffset);
3464 __ SmiToDouble(d0, r1);
3467 // Compare operands.
3468 __ VFPCompareAndSetFlags(d0, d1);
3470 // Don't base result on status bits when a NaN is involved.
3471 __ b(vs, &unordered);
3473 // Return a result of -1, 0, or 1, based on status bits.
3474 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
3475 __ mov(r0, Operand(LESS), LeaveCC, lt);
3476 __ mov(r0, Operand(GREATER), LeaveCC, gt);
3479 __ bind(&unordered);
3480 __ bind(&generic_stub);
3481 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3482 CompareICState::GENERIC, CompareICState::GENERIC);
3483 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3485 __ bind(&maybe_undefined1);
3486 if (Token::IsOrderedRelationalCompareOp(op())) {
3487 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3489 __ JumpIfSmi(r1, &unordered);
3490 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3491 __ b(ne, &maybe_undefined2);
3495 __ bind(&maybe_undefined2);
3496 if (Token::IsOrderedRelationalCompareOp(op())) {
3497 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3498 __ b(eq, &unordered);
3506 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3507 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3510 // Registers containing left and right operands respectively.
3512 Register right = r0;
3516 // Check that both operands are heap objects.
3517 __ JumpIfEitherSmi(left, right, &miss);
3519 // Check that both operands are internalized strings.
3520 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3521 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3522 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3523 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3524 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3525 __ orr(tmp1, tmp1, Operand(tmp2));
3526 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3529 // Internalized strings are compared by identity.
3530 __ cmp(left, right);
3531 // Make sure r0 is non-zero. At this point input operands are
3532 // guaranteed to be non-zero.
3533 DCHECK(right.is(r0));
3534 STATIC_ASSERT(EQUAL == 0);
3535 STATIC_ASSERT(kSmiTag == 0);
3536 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3544 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3545 DCHECK(state() == CompareICState::UNIQUE_NAME);
3546 DCHECK(GetCondition() == eq);
3549 // Registers containing left and right operands respectively.
3551 Register right = r0;
3555 // Check that both operands are heap objects.
3556 __ JumpIfEitherSmi(left, right, &miss);
3558 // Check that both operands are unique names. This leaves the instance
3559 // types loaded in tmp1 and tmp2.
3560 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3561 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3562 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3563 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3565 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3566 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3568 // Unique names are compared by identity.
3569 __ cmp(left, right);
3570 // Make sure r0 is non-zero. At this point input operands are
3571 // guaranteed to be non-zero.
3572 DCHECK(right.is(r0));
3573 STATIC_ASSERT(EQUAL == 0);
3574 STATIC_ASSERT(kSmiTag == 0);
3575 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3583 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3584 DCHECK(state() == CompareICState::STRING);
3587 bool equality = Token::IsEqualityOp(op());
3589 // Registers containing left and right operands respectively.
3591 Register right = r0;
3597 // Check that both operands are heap objects.
3598 __ JumpIfEitherSmi(left, right, &miss);
3600 // Check that both operands are strings. This leaves the instance
3601 // types loaded in tmp1 and tmp2.
3602 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3603 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3604 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3605 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3606 STATIC_ASSERT(kNotStringTag != 0);
3607 __ orr(tmp3, tmp1, tmp2);
3608 __ tst(tmp3, Operand(kIsNotStringMask));
3611 // Fast check for identical strings.
3612 __ cmp(left, right);
3613 STATIC_ASSERT(EQUAL == 0);
3614 STATIC_ASSERT(kSmiTag == 0);
3615 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3618 // Handle not identical strings.
3620 // Check that both strings are internalized strings. If they are, we're done
3621 // because we already know they are not identical. We know they are both
3624 DCHECK(GetCondition() == eq);
3625 STATIC_ASSERT(kInternalizedTag == 0);
3626 __ orr(tmp3, tmp1, Operand(tmp2));
3627 __ tst(tmp3, Operand(kIsNotInternalizedMask));
3628 // Make sure r0 is non-zero. At this point input operands are
3629 // guaranteed to be non-zero.
3630 DCHECK(right.is(r0));
3634 // Check that both strings are sequential one-byte.
3636 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3639 // Compare flat one-byte strings. Returns when done.
3641 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3644 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3648 // Handle more complex cases in runtime.
3650 __ Push(left, right);
3652 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3654 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3662 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3663 DCHECK(state() == CompareICState::OBJECT);
3665 __ and_(r2, r1, Operand(r0));
3666 __ JumpIfSmi(r2, &miss);
3668 __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
3670 __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
3673 DCHECK(GetCondition() == eq);
3674 __ sub(r0, r0, Operand(r1));
3682 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3684 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3685 __ and_(r2, r1, Operand(r0));
3686 __ JumpIfSmi(r2, &miss);
3687 __ GetWeakValue(r4, cell);
3688 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3689 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
3695 __ sub(r0, r0, Operand(r1));
3703 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3705 // Call the runtime system in a fresh internal frame.
3706 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3708 __ Push(lr, r1, r0);
3709 __ mov(ip, Operand(Smi::FromInt(op())));
3711 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3712 // Compute the entry point of the rewritten stub.
3713 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3714 // Restore registers.
3723 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3724 // Place the return address on the stack, making the call
3725 // GC safe. The RegExp backend also relies on this.
3726 __ str(lr, MemOperand(sp, 0));
3727 __ blx(ip); // Call the C++ function.
3728 __ VFPEnsureFPSCRState(r2);
3729 __ ldr(pc, MemOperand(sp, 0));
3733 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3736 reinterpret_cast<intptr_t>(GetCode().location());
3737 __ Move(ip, target);
3738 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3739 __ blx(lr); // Call the stub.
3743 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3747 Register properties,
3749 Register scratch0) {
3750 DCHECK(name->IsUniqueName());
3751 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3752 // not equal to the name and kProbes-th slot is not used (its name is the
3753 // undefined value), it guarantees the hash table doesn't contain the
3754 // property. It's true even if some slots represent deleted properties
3755 // (their names are the hole value).
3756 for (int i = 0; i < kInlinedProbes; i++) {
3757 // scratch0 points to properties hash.
3758 // Compute the masked index: (hash + i + i * i) & mask.
3759 Register index = scratch0;
3760 // Capacity is smi 2^n.
3761 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3762 __ sub(index, index, Operand(1));
3763 __ and_(index, index, Operand(
3764 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3766 // Scale the index by multiplying by the entry size.
3767 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3768 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3770 Register entity_name = scratch0;
3771 // Having undefined at this place means the name is not contained.
3772 STATIC_ASSERT(kSmiTagSize == 1);
3773 Register tmp = properties;
3774 __ add(tmp, properties, Operand(index, LSL, 1));
3775 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3777 DCHECK(!tmp.is(entity_name));
3778 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3779 __ cmp(entity_name, tmp);
3782 // Load the hole ready for use below:
3783 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3785 // Stop if found the property.
3786 __ cmp(entity_name, Operand(Handle<Name>(name)));
3790 __ cmp(entity_name, tmp);
3793 // Check if the entry name is not a unique name.
3794 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3795 __ ldrb(entity_name,
3796 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3797 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3800 // Restore the properties.
3802 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3805 const int spill_mask =
3806 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3807 r2.bit() | r1.bit() | r0.bit());
3809 __ stm(db_w, sp, spill_mask);
3810 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3811 __ mov(r1, Operand(Handle<Name>(name)));
3812 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3814 __ cmp(r0, Operand::Zero());
3815 __ ldm(ia_w, sp, spill_mask);
3822 // Probe the name dictionary in the |elements| register. Jump to the
3823 // |done| label if a property with the given name is found. Jump to
3824 // the |miss| label otherwise.
3825 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
3826 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3832 Register scratch2) {
3833 DCHECK(!elements.is(scratch1));
3834 DCHECK(!elements.is(scratch2));
3835 DCHECK(!name.is(scratch1));
3836 DCHECK(!name.is(scratch2));
3838 __ AssertName(name);
3840 // Compute the capacity mask.
3841 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
3842 __ SmiUntag(scratch1);
3843 __ sub(scratch1, scratch1, Operand(1));
3845 // Generate an unrolled loop that performs a few probes before
3846 // giving up. Measurements done on Gmail indicate that 2 probes
3847 // cover ~93% of loads from dictionaries.
3848 for (int i = 0; i < kInlinedProbes; i++) {
3849 // Compute the masked index: (hash + i + i * i) & mask.
3850 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3852 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3853 // the hash in a separate instruction. The value hash + i + i * i is right
3854 // shifted in the following and instruction.
3855 DCHECK(NameDictionary::GetProbeOffset(i) <
3856 1 << (32 - Name::kHashFieldOffset));
3857 __ add(scratch2, scratch2, Operand(
3858 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3860 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
3862 // Scale the index by multiplying by the entry size.
3863 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3864 // scratch2 = scratch2 * 3.
3865 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3867 // Check if the key is identical to the name.
3868 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3869 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3870 __ cmp(name, Operand(ip));
3874 const int spill_mask =
3875 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3876 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3877 ~(scratch1.bit() | scratch2.bit());
3879 __ stm(db_w, sp, spill_mask);
3881 DCHECK(!elements.is(r1));
3883 __ Move(r0, elements);
3885 __ Move(r0, elements);
3888 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
3890 __ cmp(r0, Operand::Zero());
3891 __ mov(scratch2, Operand(r2));
3892 __ ldm(ia_w, sp, spill_mask);
3899 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3900 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3901 // we cannot call anything that could cause a GC from this stub.
3903 // result: NameDictionary to probe
3905 // dictionary: NameDictionary to probe.
3906 // index: will hold an index of entry if lookup is successful.
3907 // might alias with result_.
3909 // result_ is zero if lookup failed, non zero otherwise.
3911 Register result = r0;
3912 Register dictionary = r0;
3914 Register index = r2;
3917 Register undefined = r5;
3918 Register entry_key = r6;
3920 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3922 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
3924 __ sub(mask, mask, Operand(1));
3926 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
3928 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3930 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3931 // Compute the masked index: (hash + i + i * i) & mask.
3932 // Capacity is smi 2^n.
3934 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3935 // the hash in a separate instruction. The value hash + i + i * i is right
3936 // shifted in the following and instruction.
3937 DCHECK(NameDictionary::GetProbeOffset(i) <
3938 1 << (32 - Name::kHashFieldOffset));
3939 __ add(index, hash, Operand(
3940 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3942 __ mov(index, Operand(hash));
3944 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
3946 // Scale the index by multiplying by the entry size.
3947 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3948 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3950 STATIC_ASSERT(kSmiTagSize == 1);
3951 __ add(index, dictionary, Operand(index, LSL, 2));
3952 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
3954 // Having undefined at this place means the name is not contained.
3955 __ cmp(entry_key, Operand(undefined));
3956 __ b(eq, ¬_in_dictionary);
3958 // Stop if found the property.
3959 __ cmp(entry_key, Operand(key));
3960 __ b(eq, &in_dictionary);
3962 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3963 // Check if the entry name is not a unique name.
3964 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3966 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
3967 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
3971 __ bind(&maybe_in_dictionary);
3972 // If we are doing negative lookup then probing failure should be
3973 // treated as a lookup success. For positive lookup probing failure
3974 // should be treated as lookup failure.
3975 if (mode() == POSITIVE_LOOKUP) {
3976 __ mov(result, Operand::Zero());
3980 __ bind(&in_dictionary);
3981 __ mov(result, Operand(1));
3984 __ bind(¬_in_dictionary);
3985 __ mov(result, Operand::Zero());
3990 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3992 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3994 // Hydrogen code stubs need stub2 at snapshot time.
3995 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4000 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4001 // the value has just been written into the object, now this stub makes sure
4002 // we keep the GC informed. The word in the object where the value has been
4003 // written is in the address register.
4004 void RecordWriteStub::Generate(MacroAssembler* masm) {
4005 Label skip_to_incremental_noncompacting;
4006 Label skip_to_incremental_compacting;
4008 // The first two instructions are generated with labels so as to get the
4009 // offset fixed up correctly by the bind(Label*) call. We patch it back and
4010 // forth between a compare instructions (a nop in this position) and the
4011 // real branch when we start and stop incremental heap marking.
4012 // See RecordWriteStub::Patch for details.
4014 // Block literal pool emission, as the position of these two instructions
4015 // is assumed by the patching code.
4016 Assembler::BlockConstPoolScope block_const_pool(masm);
4017 __ b(&skip_to_incremental_noncompacting);
4018 __ b(&skip_to_incremental_compacting);
4021 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4022 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4023 MacroAssembler::kReturnAtEnd);
4027 __ bind(&skip_to_incremental_noncompacting);
4028 GenerateIncremental(masm, INCREMENTAL);
4030 __ bind(&skip_to_incremental_compacting);
4031 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4033 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4034 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4035 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4036 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
4037 PatchBranchIntoNop(masm, 0);
4038 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4042 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4045 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4046 Label dont_need_remembered_set;
4048 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4049 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4051 &dont_need_remembered_set);
4053 __ CheckPageFlag(regs_.object(),
4055 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4057 &dont_need_remembered_set);
4059 // First notify the incremental marker if necessary, then update the
4061 CheckNeedsToInformIncrementalMarker(
4062 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4063 InformIncrementalMarker(masm);
4064 regs_.Restore(masm);
4065 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4066 MacroAssembler::kReturnAtEnd);
4068 __ bind(&dont_need_remembered_set);
4071 CheckNeedsToInformIncrementalMarker(
4072 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4073 InformIncrementalMarker(masm);
4074 regs_.Restore(masm);
4079 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4080 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4081 int argument_count = 3;
4082 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4084 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4085 DCHECK(!address.is(regs_.object()));
4086 DCHECK(!address.is(r0));
4087 __ Move(address, regs_.address());
4088 __ Move(r0, regs_.object());
4089 __ Move(r1, address);
4090 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4092 AllowExternalCallThatCantCauseGC scope(masm);
4094 ExternalReference::incremental_marking_record_write_function(isolate()),
4096 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4100 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4101 MacroAssembler* masm,
4102 OnNoNeedToInformIncrementalMarker on_no_need,
4105 Label need_incremental;
4106 Label need_incremental_pop_scratch;
4108 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4109 __ ldr(regs_.scratch1(),
4110 MemOperand(regs_.scratch0(),
4111 MemoryChunk::kWriteBarrierCounterOffset));
4112 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4113 __ str(regs_.scratch1(),
4114 MemOperand(regs_.scratch0(),
4115 MemoryChunk::kWriteBarrierCounterOffset));
4116 __ b(mi, &need_incremental);
4118 // Let's look at the color of the object: If it is not black we don't have
4119 // to inform the incremental marker.
4120 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4122 regs_.Restore(masm);
4123 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4124 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4125 MacroAssembler::kReturnAtEnd);
4132 // Get the value from the slot.
4133 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4135 if (mode == INCREMENTAL_COMPACTION) {
4136 Label ensure_not_white;
4138 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4139 regs_.scratch1(), // Scratch.
4140 MemoryChunk::kEvacuationCandidateMask,
4144 __ CheckPageFlag(regs_.object(),
4145 regs_.scratch1(), // Scratch.
4146 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4150 __ bind(&ensure_not_white);
4153 // We need extra registers for this, so we push the object and the address
4154 // register temporarily.
4155 __ Push(regs_.object(), regs_.address());
4156 __ EnsureNotWhite(regs_.scratch0(), // The value.
4157 regs_.scratch1(), // Scratch.
4158 regs_.object(), // Scratch.
4159 regs_.address(), // Scratch.
4160 &need_incremental_pop_scratch);
4161 __ Pop(regs_.object(), regs_.address());
4163 regs_.Restore(masm);
4164 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4165 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4166 MacroAssembler::kReturnAtEnd);
4171 __ bind(&need_incremental_pop_scratch);
4172 __ Pop(regs_.object(), regs_.address());
4174 __ bind(&need_incremental);
4176 // Fall through when we need to inform the incremental marker.
4180 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4181 // ----------- S t a t e -------------
4182 // -- r0 : element value to store
4183 // -- r3 : element index as smi
4184 // -- sp[0] : array literal index in function as smi
4185 // -- sp[4] : array literal
4186 // clobbers r1, r2, r4
4187 // -----------------------------------
4190 Label double_elements;
4192 Label slow_elements;
4193 Label fast_elements;
4195 // Get array literal index, array literal and its map.
4196 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4197 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4198 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4200 __ CheckFastElements(r2, r5, &double_elements);
4201 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4202 __ JumpIfSmi(r0, &smi_element);
4203 __ CheckFastSmiElements(r2, r5, &fast_elements);
4205 // Store into the array literal requires a elements transition. Call into
4207 __ bind(&slow_elements);
4209 __ Push(r1, r3, r0);
4210 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4211 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4213 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4215 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4216 __ bind(&fast_elements);
4217 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4218 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4219 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4220 __ str(r0, MemOperand(r6, 0));
4221 // Update the write barrier for the array store.
4222 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4223 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4226 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4227 // and value is Smi.
4228 __ bind(&smi_element);
4229 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4230 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4231 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4234 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4235 __ bind(&double_elements);
4236 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4237 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
4242 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4243 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4244 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4245 int parameter_count_offset =
4246 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4247 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4248 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4249 __ add(r1, r1, Operand(1));
4251 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4252 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4258 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4259 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4260 LoadICStub stub(isolate(), state());
4261 stub.GenerateForTrampoline(masm);
4265 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4266 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4267 KeyedLoadICStub stub(isolate(), state());
4268 stub.GenerateForTrampoline(masm);
4272 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4273 EmitLoadTypeFeedbackVector(masm, r2);
4274 CallICStub stub(isolate(), state());
4275 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4279 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4280 EmitLoadTypeFeedbackVector(masm, r2);
4281 CallIC_ArrayStub stub(isolate(), state());
4282 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4286 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4289 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4290 GenerateImpl(masm, true);
4294 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4295 Register receiver_map, Register scratch1,
4296 Register scratch2, bool is_polymorphic,
4298 // feedback initially contains the feedback array
4299 Label next_loop, prepare_next;
4300 Label start_polymorphic;
4302 Register cached_map = scratch1;
4305 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4306 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4307 __ cmp(receiver_map, cached_map);
4308 __ b(ne, &start_polymorphic);
4309 // found, now call handler.
4310 Register handler = feedback;
4311 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4312 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4315 Register length = scratch2;
4316 __ bind(&start_polymorphic);
4317 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4318 if (!is_polymorphic) {
4319 // If the IC could be monomorphic we have to make sure we don't go past the
4320 // end of the feedback array.
4321 __ cmp(length, Operand(Smi::FromInt(2)));
4325 Register too_far = length;
4326 Register pointer_reg = feedback;
4328 // +-----+------+------+-----+-----+ ... ----+
4329 // | map | len | wm0 | h0 | wm1 | hN |
4330 // +-----+------+------+-----+-----+ ... ----+
4334 // pointer_reg too_far
4335 // aka feedback scratch2
4336 // also need receiver_map
4337 // use cached_map (scratch1) to look in the weak map values.
4338 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
4339 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4340 __ add(pointer_reg, feedback,
4341 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4343 __ bind(&next_loop);
4344 __ ldr(cached_map, MemOperand(pointer_reg));
4345 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4346 __ cmp(receiver_map, cached_map);
4347 __ b(ne, &prepare_next);
4348 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
4349 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4351 __ bind(&prepare_next);
4352 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4353 __ cmp(pointer_reg, too_far);
4354 __ b(lt, &next_loop);
4356 // We exhausted our array of map handler pairs.
4361 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4362 Register receiver_map, Register feedback,
4363 Register vector, Register slot,
4364 Register scratch, Label* compare_map,
4365 Label* load_smi_map, Label* try_array) {
4366 __ JumpIfSmi(receiver, load_smi_map);
4367 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4368 __ bind(compare_map);
4369 Register cached_map = scratch;
4370 // Move the weak map into the weak_cell register.
4371 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4372 __ cmp(cached_map, receiver_map);
4373 __ b(ne, try_array);
4374 Register handler = feedback;
4375 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
4377 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4378 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4382 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4383 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4384 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
4385 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4386 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4387 Register feedback = r4;
4388 Register receiver_map = r5;
4389 Register scratch1 = r6;
4391 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4392 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4394 // Try to quickly handle the monomorphic case without knowing for sure
4395 // if we have a weak cell in feedback. We do know it's safe to look
4396 // at WeakCell::kValueOffset.
4397 Label try_array, load_smi_map, compare_map;
4398 Label not_array, miss;
4399 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4400 scratch1, &compare_map, &load_smi_map, &try_array);
4402 // Is it a fixed array?
4403 __ bind(&try_array);
4404 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4405 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4406 __ b(ne, ¬_array);
4407 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4409 __ bind(¬_array);
4410 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4412 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4413 Code::ComputeHandlerFlags(Code::LOAD_IC));
4414 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4415 receiver, name, feedback,
4416 receiver_map, scratch1, r9);
4419 LoadIC::GenerateMiss(masm);
4421 __ bind(&load_smi_map);
4422 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4423 __ jmp(&compare_map);
4427 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4428 GenerateImpl(masm, false);
4432 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4433 GenerateImpl(masm, true);
4437 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4438 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4439 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
4440 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4441 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4442 Register feedback = r4;
4443 Register receiver_map = r5;
4444 Register scratch1 = r6;
4446 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4447 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4449 // Try to quickly handle the monomorphic case without knowing for sure
4450 // if we have a weak cell in feedback. We do know it's safe to look
4451 // at WeakCell::kValueOffset.
4452 Label try_array, load_smi_map, compare_map;
4453 Label not_array, miss;
4454 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4455 scratch1, &compare_map, &load_smi_map, &try_array);
4457 __ bind(&try_array);
4458 // Is it a fixed array?
4459 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4460 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4461 __ b(ne, ¬_array);
4463 // We have a polymorphic element handler.
4464 Label polymorphic, try_poly_name;
4465 __ bind(&polymorphic);
4466 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4468 __ bind(¬_array);
4470 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4471 __ b(ne, &try_poly_name);
4472 Handle<Code> megamorphic_stub =
4473 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4474 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4476 __ bind(&try_poly_name);
4477 // We might have a name in feedback, and a fixed array in the next slot.
4478 __ cmp(key, feedback);
4480 // If the name comparison succeeded, we know we have a fixed array with
4481 // at least one map/handler pair.
4482 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4484 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4485 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, false, &miss);
4488 KeyedLoadIC::GenerateMiss(masm);
4490 __ bind(&load_smi_map);
4491 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4492 __ jmp(&compare_map);
4496 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4497 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4498 VectorStoreICStub stub(isolate(), state());
4499 stub.GenerateForTrampoline(masm);
4503 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4504 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4505 VectorKeyedStoreICStub stub(isolate(), state());
4506 stub.GenerateForTrampoline(masm);
4510 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4511 GenerateImpl(masm, false);
4515 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4516 GenerateImpl(masm, true);
4520 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4521 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4522 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4523 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4524 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4525 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4526 Register feedback = r5;
4527 Register receiver_map = r6;
4528 Register scratch1 = r9;
4530 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4531 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4533 // Try to quickly handle the monomorphic case without knowing for sure
4534 // if we have a weak cell in feedback. We do know it's safe to look
4535 // at WeakCell::kValueOffset.
4536 Label try_array, load_smi_map, compare_map;
4537 Label not_array, miss;
4538 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4539 scratch1, &compare_map, &load_smi_map, &try_array);
4541 // Is it a fixed array?
4542 __ bind(&try_array);
4543 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4544 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4545 __ b(ne, ¬_array);
4547 // We are using register r8, which is used for the embedded constant pool
4548 // when FLAG_enable_embedded_constant_pool is true.
4549 DCHECK(!FLAG_enable_embedded_constant_pool);
4550 Register scratch2 = r8;
4551 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4554 __ bind(¬_array);
4555 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4557 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4558 Code::ComputeHandlerFlags(Code::STORE_IC));
4559 masm->isolate()->stub_cache()->GenerateProbe(
4560 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4561 scratch1, scratch2);
4564 StoreIC::GenerateMiss(masm);
4566 __ bind(&load_smi_map);
4567 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4568 __ jmp(&compare_map);
4572 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4573 GenerateImpl(masm, false);
4577 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4578 GenerateImpl(masm, true);
4582 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4583 Register receiver_map, Register scratch1,
4584 Register scratch2, Label* miss) {
4585 // feedback initially contains the feedback array
4586 Label next_loop, prepare_next;
4587 Label start_polymorphic;
4588 Label transition_call;
4590 Register cached_map = scratch1;
4591 Register too_far = scratch2;
4592 Register pointer_reg = feedback;
4593 __ ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4595 // +-----+------+------+-----+-----+-----+ ... ----+
4596 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4597 // +-----+------+------+-----+-----+ ----+ ... ----+
4601 // pointer_reg too_far
4602 // aka feedback scratch2
4603 // also need receiver_map
4604 // use cached_map (scratch1) to look in the weak map values.
4605 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(too_far));
4606 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4607 __ add(pointer_reg, feedback,
4608 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4610 __ bind(&next_loop);
4611 __ ldr(cached_map, MemOperand(pointer_reg));
4612 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4613 __ cmp(receiver_map, cached_map);
4614 __ b(ne, &prepare_next);
4615 // Is it a transitioning store?
4616 __ ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4617 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4618 __ b(ne, &transition_call);
4619 __ ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4620 __ add(pc, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4622 __ bind(&transition_call);
4623 __ ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4624 __ JumpIfSmi(too_far, miss);
4626 __ ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4628 // Load the map into the correct register.
4629 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4630 __ mov(feedback, too_far);
4632 __ add(pc, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4634 __ bind(&prepare_next);
4635 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4636 __ cmp(pointer_reg, too_far);
4637 __ b(lt, &next_loop);
4639 // We exhausted our array of map handler pairs.
4644 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4645 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4646 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4647 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4648 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4649 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4650 Register feedback = r5;
4651 Register receiver_map = r6;
4652 Register scratch1 = r9;
4654 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4655 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4657 // Try to quickly handle the monomorphic case without knowing for sure
4658 // if we have a weak cell in feedback. We do know it's safe to look
4659 // at WeakCell::kValueOffset.
4660 Label try_array, load_smi_map, compare_map;
4661 Label not_array, miss;
4662 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4663 scratch1, &compare_map, &load_smi_map, &try_array);
4665 __ bind(&try_array);
4666 // Is it a fixed array?
4667 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4668 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4669 __ b(ne, ¬_array);
4671 // We have a polymorphic element handler.
4672 Label polymorphic, try_poly_name;
4673 __ bind(&polymorphic);
4675 // We are using register r8, which is used for the embedded constant pool
4676 // when FLAG_enable_embedded_constant_pool is true.
4677 DCHECK(!FLAG_enable_embedded_constant_pool);
4678 Register scratch2 = r8;
4680 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4683 __ bind(¬_array);
4685 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4686 __ b(ne, &try_poly_name);
4687 Handle<Code> megamorphic_stub =
4688 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4689 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4691 __ bind(&try_poly_name);
4692 // We might have a name in feedback, and a fixed array in the next slot.
4693 __ cmp(key, feedback);
4695 // If the name comparison succeeded, we know we have a fixed array with
4696 // at least one map/handler pair.
4697 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4699 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4700 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4704 KeyedStoreIC::GenerateMiss(masm);
4706 __ bind(&load_smi_map);
4707 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4708 __ jmp(&compare_map);
4712 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4713 if (masm->isolate()->function_entry_hook() != NULL) {
4714 ProfileEntryHookStub stub(masm->isolate());
4715 PredictableCodeSizeScope predictable(masm);
4716 predictable.ExpectSize(masm->CallStubSize(&stub) +
4717 2 * Assembler::kInstrSize);
4725 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4726 // The entry hook is a "push lr" instruction, followed by a call.
4727 const int32_t kReturnAddressDistanceFromFunctionStart =
4728 3 * Assembler::kInstrSize;
4730 // This should contain all kCallerSaved registers.
4731 const RegList kSavedRegs =
4738 // We also save lr, so the count here is one higher than the mask indicates.
4739 const int32_t kNumSavedRegs = 7;
4741 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4743 // Save all caller-save registers as this may be called from anywhere.
4744 __ stm(db_w, sp, kSavedRegs | lr.bit());
4746 // Compute the function's address for the first argument.
4747 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4749 // The caller's return address is above the saved temporaries.
4750 // Grab that for the second argument to the hook.
4751 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4753 // Align the stack if necessary.
4754 int frame_alignment = masm->ActivationFrameAlignment();
4755 if (frame_alignment > kPointerSize) {
4757 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4758 __ and_(sp, sp, Operand(-frame_alignment));
4761 #if V8_HOST_ARCH_ARM
4762 int32_t entry_hook =
4763 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4764 __ mov(ip, Operand(entry_hook));
4766 // Under the simulator we need to indirect the entry hook through a
4767 // trampoline function at a known address.
4768 // It additionally takes an isolate as a third parameter
4769 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4771 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4772 __ mov(ip, Operand(ExternalReference(&dispatcher,
4773 ExternalReference::BUILTIN_CALL,
4778 // Restore the stack pointer if needed.
4779 if (frame_alignment > kPointerSize) {
4783 // Also pop pc to get Ret(0).
4784 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4789 static void CreateArrayDispatch(MacroAssembler* masm,
4790 AllocationSiteOverrideMode mode) {
4791 if (mode == DISABLE_ALLOCATION_SITES) {
4792 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4793 __ TailCallStub(&stub);
4794 } else if (mode == DONT_OVERRIDE) {
4795 int last_index = GetSequenceIndexFromFastElementsKind(
4796 TERMINAL_FAST_ELEMENTS_KIND);
4797 for (int i = 0; i <= last_index; ++i) {
4798 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4799 __ cmp(r3, Operand(kind));
4800 T stub(masm->isolate(), kind);
4801 __ TailCallStub(&stub, eq);
4804 // If we reached this point there is a problem.
4805 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4812 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4813 AllocationSiteOverrideMode mode) {
4814 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4815 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4816 // r0 - number of arguments
4817 // r1 - constructor?
4818 // sp[0] - last argument
4819 Label normal_sequence;
4820 if (mode == DONT_OVERRIDE) {
4821 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4822 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4823 STATIC_ASSERT(FAST_ELEMENTS == 2);
4824 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4825 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4826 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4828 // is the low bit set? If so, we are holey and that is good.
4829 __ tst(r3, Operand(1));
4830 __ b(ne, &normal_sequence);
4833 // look at the first argument
4834 __ ldr(r5, MemOperand(sp, 0));
4835 __ cmp(r5, Operand::Zero());
4836 __ b(eq, &normal_sequence);
4838 if (mode == DISABLE_ALLOCATION_SITES) {
4839 ElementsKind initial = GetInitialFastElementsKind();
4840 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4842 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4844 DISABLE_ALLOCATION_SITES);
4845 __ TailCallStub(&stub_holey);
4847 __ bind(&normal_sequence);
4848 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4850 DISABLE_ALLOCATION_SITES);
4851 __ TailCallStub(&stub);
4852 } else if (mode == DONT_OVERRIDE) {
4853 // We are going to create a holey array, but our kind is non-holey.
4854 // Fix kind and retry (only if we have an allocation site in the slot).
4855 __ add(r3, r3, Operand(1));
4857 if (FLAG_debug_code) {
4858 __ ldr(r5, FieldMemOperand(r2, 0));
4859 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4860 __ Assert(eq, kExpectedAllocationSite);
4863 // Save the resulting elements kind in type info. We can't just store r3
4864 // in the AllocationSite::transition_info field because elements kind is
4865 // restricted to a portion of the field...upper bits need to be left alone.
4866 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4867 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4868 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4869 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4871 __ bind(&normal_sequence);
4872 int last_index = GetSequenceIndexFromFastElementsKind(
4873 TERMINAL_FAST_ELEMENTS_KIND);
4874 for (int i = 0; i <= last_index; ++i) {
4875 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4876 __ cmp(r3, Operand(kind));
4877 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4878 __ TailCallStub(&stub, eq);
4881 // If we reached this point there is a problem.
4882 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4890 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4891 int to_index = GetSequenceIndexFromFastElementsKind(
4892 TERMINAL_FAST_ELEMENTS_KIND);
4893 for (int i = 0; i <= to_index; ++i) {
4894 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4895 T stub(isolate, kind);
4897 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4898 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4905 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4906 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4908 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4910 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4915 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4917 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4918 for (int i = 0; i < 2; i++) {
4919 // For internal arrays we only need a few things
4920 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4922 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4924 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4930 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4931 MacroAssembler* masm,
4932 AllocationSiteOverrideMode mode) {
4933 if (argument_count() == ANY) {
4934 Label not_zero_case, not_one_case;
4936 __ b(ne, ¬_zero_case);
4937 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4939 __ bind(¬_zero_case);
4940 __ cmp(r0, Operand(1));
4941 __ b(gt, ¬_one_case);
4942 CreateArrayDispatchOneArgument(masm, mode);
4944 __ bind(¬_one_case);
4945 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4946 } else if (argument_count() == NONE) {
4947 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4948 } else if (argument_count() == ONE) {
4949 CreateArrayDispatchOneArgument(masm, mode);
4950 } else if (argument_count() == MORE_THAN_ONE) {
4951 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4958 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4959 // ----------- S t a t e -------------
4960 // -- r0 : argc (only if argument_count() == ANY)
4961 // -- r1 : constructor
4962 // -- r2 : AllocationSite or undefined
4963 // -- r3 : original constructor
4964 // -- sp[0] : return address
4965 // -- sp[4] : last argument
4966 // -----------------------------------
4968 if (FLAG_debug_code) {
4969 // The array construct code is only set for the global and natives
4970 // builtin Array functions which always have maps.
4972 // Initial map for the builtin Array function should be a map.
4973 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4974 // Will both indicate a NULL and a Smi.
4975 __ tst(r4, Operand(kSmiTagMask));
4976 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4977 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4978 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4980 // We should either have undefined in r2 or a valid AllocationSite
4981 __ AssertUndefinedOrAllocationSite(r2, r4);
4986 __ b(ne, &subclassing);
4989 // Get the elements kind and case on that.
4990 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4993 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4995 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4996 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4997 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5000 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5002 __ bind(&subclassing);
5007 switch (argument_count()) {
5010 __ add(r0, r0, Operand(2));
5013 __ mov(r0, Operand(2));
5016 __ mov(r0, Operand(3));
5020 __ JumpToExternalReference(
5021 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5025 void InternalArrayConstructorStub::GenerateCase(
5026 MacroAssembler* masm, ElementsKind kind) {
5027 __ cmp(r0, Operand(1));
5029 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5030 __ TailCallStub(&stub0, lo);
5032 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5033 __ TailCallStub(&stubN, hi);
5035 if (IsFastPackedElementsKind(kind)) {
5036 // We might need to create a holey array
5037 // look at the first argument
5038 __ ldr(r3, MemOperand(sp, 0));
5039 __ cmp(r3, Operand::Zero());
5041 InternalArraySingleArgumentConstructorStub
5042 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5043 __ TailCallStub(&stub1_holey, ne);
5046 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5047 __ TailCallStub(&stub1);
5051 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5052 // ----------- S t a t e -------------
5054 // -- r1 : constructor
5055 // -- sp[0] : return address
5056 // -- sp[4] : last argument
5057 // -----------------------------------
5059 if (FLAG_debug_code) {
5060 // The array construct code is only set for the global and natives
5061 // builtin Array functions which always have maps.
5063 // Initial map for the builtin Array function should be a map.
5064 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5065 // Will both indicate a NULL and a Smi.
5066 __ tst(r3, Operand(kSmiTagMask));
5067 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5068 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
5069 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5072 // Figure out the right elements kind
5073 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5074 // Load the map's "bit field 2" into |result|. We only need the first byte,
5075 // but the following bit field extraction takes care of that anyway.
5076 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
5077 // Retrieve elements_kind from bit field 2.
5078 __ DecodeField<Map::ElementsKindBits>(r3);
5080 if (FLAG_debug_code) {
5082 __ cmp(r3, Operand(FAST_ELEMENTS));
5084 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
5086 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5090 Label fast_elements_case;
5091 __ cmp(r3, Operand(FAST_ELEMENTS));
5092 __ b(eq, &fast_elements_case);
5093 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5095 __ bind(&fast_elements_case);
5096 GenerateCase(masm, FAST_ELEMENTS);
5100 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5101 Register context = cp;
5102 Register result = r0;
5105 // Go up the context chain to the script context.
5106 for (int i = 0; i < depth(); ++i) {
5107 __ ldr(result, ContextOperand(context, Context::PREVIOUS_INDEX));
5111 // Load the PropertyCell value at the specified slot.
5112 __ add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5113 __ ldr(result, ContextOperand(result));
5114 __ ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5116 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5117 __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
5120 // Fallback to runtime.
5123 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5127 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5128 Register value = r0;
5132 Register cell_details = r4;
5133 Register cell_value = r5;
5134 Register cell_value_map = r6;
5135 Register scratch = r9;
5137 Register context = cp;
5138 Register context_temp = cell;
5140 Label fast_heapobject_case, fast_smi_case, slow_case;
5142 if (FLAG_debug_code) {
5143 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5144 __ Check(ne, kUnexpectedValue);
5147 // Go up the context chain to the script context.
5148 for (int i = 0; i < depth(); i++) {
5149 __ ldr(context_temp, ContextOperand(context, Context::PREVIOUS_INDEX));
5150 context = context_temp;
5153 // Load the PropertyCell at the specified slot.
5154 __ add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5155 __ ldr(cell, ContextOperand(cell));
5157 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5158 __ ldr(cell_details, FieldMemOperand(cell, PropertyCell::kDetailsOffset));
5159 __ SmiUntag(cell_details);
5160 __ and_(cell_details, cell_details,
5161 Operand(PropertyDetails::PropertyCellTypeField::kMask |
5162 PropertyDetails::KindField::kMask |
5163 PropertyDetails::kAttributesReadOnlyMask));
5165 // Check if PropertyCell holds mutable data.
5166 Label not_mutable_data;
5167 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5168 PropertyCellType::kMutable) |
5169 PropertyDetails::KindField::encode(kData)));
5170 __ b(ne, ¬_mutable_data);
5171 __ JumpIfSmi(value, &fast_smi_case);
5173 __ bind(&fast_heapobject_case);
5174 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5175 // RecordWriteField clobbers the value register, so we copy it before the
5177 __ mov(r4, Operand(value));
5178 __ RecordWriteField(cell, PropertyCell::kValueOffset, r4, scratch,
5179 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5183 __ bind(¬_mutable_data);
5184 // Check if PropertyCell value matches the new value (relevant for Constant,
5185 // ConstantType and Undefined cells).
5186 Label not_same_value;
5187 __ ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5188 __ cmp(cell_value, value);
5189 __ b(ne, ¬_same_value);
5191 // Make sure the PropertyCell is not marked READ_ONLY.
5192 __ tst(cell_details, Operand(PropertyDetails::kAttributesReadOnlyMask));
5193 __ b(ne, &slow_case);
5195 if (FLAG_debug_code) {
5197 // This can only be true for Constant, ConstantType and Undefined cells,
5198 // because we never store the_hole via this stub.
5199 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5200 PropertyCellType::kConstant) |
5201 PropertyDetails::KindField::encode(kData)));
5203 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5204 PropertyCellType::kConstantType) |
5205 PropertyDetails::KindField::encode(kData)));
5207 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5208 PropertyCellType::kUndefined) |
5209 PropertyDetails::KindField::encode(kData)));
5210 __ Check(eq, kUnexpectedValue);
5214 __ bind(¬_same_value);
5216 // Check if PropertyCell contains data with constant type (and is not
5218 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5219 PropertyCellType::kConstantType) |
5220 PropertyDetails::KindField::encode(kData)));
5221 __ b(ne, &slow_case);
5223 // Now either both old and new values must be smis or both must be heap
5224 // objects with same map.
5225 Label value_is_heap_object;
5226 __ JumpIfNotSmi(value, &value_is_heap_object);
5227 __ JumpIfNotSmi(cell_value, &slow_case);
5228 // Old and new values are smis, no need for a write barrier here.
5229 __ bind(&fast_smi_case);
5230 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5233 __ bind(&value_is_heap_object);
5234 __ JumpIfSmi(cell_value, &slow_case);
5236 __ ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5237 __ ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5238 __ cmp(cell_value_map, scratch);
5239 __ b(eq, &fast_heapobject_case);
5241 // Fallback to runtime.
5242 __ bind(&slow_case);
5244 __ Push(slot, value);
5245 __ TailCallRuntime(is_strict(language_mode())
5246 ? Runtime::kStoreGlobalViaContext_Strict
5247 : Runtime::kStoreGlobalViaContext_Sloppy,
5252 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5253 return ref0.address() - ref1.address();
5257 // Calls an API function. Allocates HandleScope, extracts returned value
5258 // from handle and propagates exceptions. Restores context. stack_space
5259 // - space to be unwound on exit (includes the call JS arguments space and
5260 // the additional space allocated for the fast call).
5261 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5262 Register function_address,
5263 ExternalReference thunk_ref,
5265 MemOperand* stack_space_operand,
5266 MemOperand return_value_operand,
5267 MemOperand* context_restore_operand) {
5268 Isolate* isolate = masm->isolate();
5269 ExternalReference next_address =
5270 ExternalReference::handle_scope_next_address(isolate);
5271 const int kNextOffset = 0;
5272 const int kLimitOffset = AddressOffset(
5273 ExternalReference::handle_scope_limit_address(isolate), next_address);
5274 const int kLevelOffset = AddressOffset(
5275 ExternalReference::handle_scope_level_address(isolate), next_address);
5277 DCHECK(function_address.is(r1) || function_address.is(r2));
5279 Label profiler_disabled;
5280 Label end_profiler_check;
5281 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5282 __ ldrb(r9, MemOperand(r9, 0));
5283 __ cmp(r9, Operand(0));
5284 __ b(eq, &profiler_disabled);
5286 // Additional parameter is the address of the actual callback.
5287 __ mov(r3, Operand(thunk_ref));
5288 __ jmp(&end_profiler_check);
5290 __ bind(&profiler_disabled);
5291 __ Move(r3, function_address);
5292 __ bind(&end_profiler_check);
5294 // Allocate HandleScope in callee-save registers.
5295 __ mov(r9, Operand(next_address));
5296 __ ldr(r4, MemOperand(r9, kNextOffset));
5297 __ ldr(r5, MemOperand(r9, kLimitOffset));
5298 __ ldr(r6, MemOperand(r9, kLevelOffset));
5299 __ add(r6, r6, Operand(1));
5300 __ str(r6, MemOperand(r9, kLevelOffset));
5302 if (FLAG_log_timer_events) {
5303 FrameScope frame(masm, StackFrame::MANUAL);
5304 __ PushSafepointRegisters();
5305 __ PrepareCallCFunction(1, r0);
5306 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5307 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5309 __ PopSafepointRegisters();
5312 // Native call returns to the DirectCEntry stub which redirects to the
5313 // return address pushed on stack (could have moved after GC).
5314 // DirectCEntry stub itself is generated early and never moves.
5315 DirectCEntryStub stub(isolate);
5316 stub.GenerateCall(masm, r3);
5318 if (FLAG_log_timer_events) {
5319 FrameScope frame(masm, StackFrame::MANUAL);
5320 __ PushSafepointRegisters();
5321 __ PrepareCallCFunction(1, r0);
5322 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5323 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5325 __ PopSafepointRegisters();
5328 Label promote_scheduled_exception;
5329 Label delete_allocated_handles;
5330 Label leave_exit_frame;
5331 Label return_value_loaded;
5333 // load value from ReturnValue
5334 __ ldr(r0, return_value_operand);
5335 __ bind(&return_value_loaded);
5336 // No more valid handles (the result handle was the last one). Restore
5337 // previous handle scope.
5338 __ str(r4, MemOperand(r9, kNextOffset));
5339 if (__ emit_debug_code()) {
5340 __ ldr(r1, MemOperand(r9, kLevelOffset));
5342 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5344 __ sub(r6, r6, Operand(1));
5345 __ str(r6, MemOperand(r9, kLevelOffset));
5346 __ ldr(ip, MemOperand(r9, kLimitOffset));
5348 __ b(ne, &delete_allocated_handles);
5350 // Leave the API exit frame.
5351 __ bind(&leave_exit_frame);
5352 bool restore_context = context_restore_operand != NULL;
5353 if (restore_context) {
5354 __ ldr(cp, *context_restore_operand);
5356 // LeaveExitFrame expects unwind space to be in a register.
5357 if (stack_space_operand != NULL) {
5358 __ ldr(r4, *stack_space_operand);
5360 __ mov(r4, Operand(stack_space));
5362 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5364 // Check if the function scheduled an exception.
5365 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5366 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5367 __ ldr(r5, MemOperand(ip));
5369 __ b(ne, &promote_scheduled_exception);
5373 // Re-throw by promoting a scheduled exception.
5374 __ bind(&promote_scheduled_exception);
5375 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5377 // HandleScope limit has changed. Delete allocated extensions.
5378 __ bind(&delete_allocated_handles);
5379 __ str(r5, MemOperand(r9, kLimitOffset));
5381 __ PrepareCallCFunction(1, r5);
5382 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5383 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5386 __ jmp(&leave_exit_frame);
5390 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5391 const ParameterCount& argc,
5392 bool return_first_arg,
5393 bool call_data_undefined) {
5394 // ----------- S t a t e -------------
5396 // -- r4 : call_data
5398 // -- r1 : api_function_address
5399 // -- r3 : number of arguments if argc is a register
5402 // -- sp[0] : last argument
5404 // -- sp[(argc - 1)* 4] : first argument
5405 // -- sp[argc * 4] : receiver
5406 // -----------------------------------
5408 Register callee = r0;
5409 Register call_data = r4;
5410 Register holder = r2;
5411 Register api_function_address = r1;
5412 Register context = cp;
5414 typedef FunctionCallbackArguments FCA;
5416 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5417 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5418 STATIC_ASSERT(FCA::kDataIndex == 4);
5419 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5420 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5421 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5422 STATIC_ASSERT(FCA::kHolderIndex == 0);
5423 STATIC_ASSERT(FCA::kArgsLength == 7);
5425 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5429 // load context from callee
5430 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5438 Register scratch = call_data;
5439 if (!call_data_undefined) {
5440 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5444 // return value default
5447 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5452 // Prepare arguments.
5453 __ mov(scratch, sp);
5455 // Allocate the v8::Arguments structure in the arguments' space since
5456 // it's not controlled by GC.
5457 const int kApiStackSpace = 4;
5459 FrameScope frame_scope(masm, StackFrame::MANUAL);
5460 __ EnterExitFrame(false, kApiStackSpace);
5462 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5463 // r0 = FunctionCallbackInfo&
5464 // Arguments is after the return address.
5465 __ add(r0, sp, Operand(1 * kPointerSize));
5466 // FunctionCallbackInfo::implicit_args_
5467 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
5468 if (argc.is_immediate()) {
5469 // FunctionCallbackInfo::values_
5471 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5472 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5473 // FunctionCallbackInfo::length_ = argc
5474 __ mov(ip, Operand(argc.immediate()));
5475 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5476 // FunctionCallbackInfo::is_construct_call_ = 0
5477 __ mov(ip, Operand::Zero());
5478 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5480 // FunctionCallbackInfo::values_
5481 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5482 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5483 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5484 // FunctionCallbackInfo::length_ = argc
5485 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5486 // FunctionCallbackInfo::is_construct_call_
5487 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5488 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5489 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5492 ExternalReference thunk_ref =
5493 ExternalReference::invoke_function_callback(masm->isolate());
5495 AllowExternalCallThatCantCauseGC scope(masm);
5496 MemOperand context_restore_operand(
5497 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5498 // Stores return the first js argument
5499 int return_value_offset = 0;
5500 if (return_first_arg) {
5501 return_value_offset = 2 + FCA::kArgsLength;
5503 return_value_offset = 2 + FCA::kReturnValueOffset;
5505 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5506 int stack_space = 0;
5507 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5508 MemOperand* stack_space_operand = &is_construct_call_operand;
5509 if (argc.is_immediate()) {
5510 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5511 stack_space_operand = NULL;
5513 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5514 stack_space_operand, return_value_operand,
5515 &context_restore_operand);
5519 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5520 bool call_data_undefined = this->call_data_undefined();
5521 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
5522 call_data_undefined);
5526 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5527 bool is_store = this->is_store();
5528 int argc = this->argc();
5529 bool call_data_undefined = this->call_data_undefined();
5530 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5531 call_data_undefined);
5535 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5536 // ----------- S t a t e -------------
5538 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5540 // -- r2 : api_function_address
5541 // -----------------------------------
5543 Register api_function_address = ApiGetterDescriptor::function_address();
5544 DCHECK(api_function_address.is(r2));
5546 __ mov(r0, sp); // r0 = Handle<Name>
5547 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
5549 const int kApiStackSpace = 1;
5550 FrameScope frame_scope(masm, StackFrame::MANUAL);
5551 __ EnterExitFrame(false, kApiStackSpace);
5553 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5554 // r1 (internal::Object** args_) as the data.
5555 __ str(r1, MemOperand(sp, 1 * kPointerSize));
5556 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
5558 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5560 ExternalReference thunk_ref =
5561 ExternalReference::invoke_accessor_getter_callback(isolate());
5562 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5563 kStackUnwindSpace, NULL,
5564 MemOperand(fp, 6 * kPointerSize), NULL);
5570 } // namespace internal
5573 #endif // V8_TARGET_ARCH_ARM