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,
2400 Label* non_function) {
2401 // Check for function proxy.
2402 __ cmp(r4, Operand(JS_FUNCTION_PROXY_TYPE));
2403 __ b(ne, non_function);
2404 __ push(r1); // put proxy as additional argument
2405 __ mov(r0, Operand(argc + 1, RelocInfo::NONE32));
2406 __ mov(r2, Operand::Zero());
2407 __ GetBuiltinFunction(r1, Context::CALL_FUNCTION_PROXY_BUILTIN_INDEX);
2409 Handle<Code> adaptor =
2410 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2411 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2414 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2415 // of the original receiver from the call site).
2416 __ bind(non_function);
2417 __ str(r1, MemOperand(sp, argc * kPointerSize));
2418 __ mov(r0, Operand(argc)); // Set up the number of arguments.
2419 __ mov(r2, Operand::Zero());
2420 __ GetBuiltinFunction(r1, Context::CALL_NON_FUNCTION_BUILTIN_INDEX);
2421 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2422 RelocInfo::CODE_TARGET);
2426 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2427 // Wrap the receiver and patch it back onto the stack.
2428 { FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2431 ToObjectStub stub(masm->isolate());
2435 __ str(r0, MemOperand(sp, argc * kPointerSize));
2440 static void CallFunctionNoFeedback(MacroAssembler* masm,
2441 int argc, bool needs_checks,
2442 bool call_as_method) {
2443 // r1 : the function to call
2444 Label slow, non_function, wrap, cont;
2447 // Check that the function is really a JavaScript function.
2448 // r1: pushed function (to be verified)
2449 __ JumpIfSmi(r1, &non_function);
2451 // Goto slow case if we do not have a function.
2452 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2456 // Fast-case: Invoke the function now.
2457 // r1: pushed function
2458 ParameterCount actual(argc);
2460 if (call_as_method) {
2462 EmitContinueIfStrictOrNative(masm, &cont);
2465 // Compute the receiver in sloppy mode.
2466 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2469 __ JumpIfSmi(r3, &wrap);
2470 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2479 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2482 // Slow-case: Non-function called.
2484 EmitSlowCase(masm, argc, &non_function);
2487 if (call_as_method) {
2489 EmitWrapCase(masm, argc, &cont);
2494 void CallFunctionStub::Generate(MacroAssembler* masm) {
2495 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2499 void CallConstructStub::Generate(MacroAssembler* masm) {
2500 // r0 : number of arguments
2501 // r1 : the function to call
2502 // r2 : feedback vector
2503 // r3 : slot in feedback vector (Smi, for RecordCallTarget)
2504 // r4 : original constructor (for IsSuperConstructorCall)
2505 Label slow, non_function_call;
2507 // Check that the function is not a smi.
2508 __ JumpIfSmi(r1, &non_function_call);
2509 // Check that the function is a JSFunction.
2510 __ CompareObjectType(r1, r5, r5, JS_FUNCTION_TYPE);
2513 if (RecordCallTarget()) {
2514 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2516 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2517 if (FLAG_pretenuring_call_new) {
2518 // Put the AllocationSite from the feedback vector into r2.
2519 // By adding kPointerSize we encode that we know the AllocationSite
2520 // entry is at the feedback vector slot given by r3 + 1.
2521 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize + kPointerSize));
2523 Label feedback_register_initialized;
2524 // Put the AllocationSite from the feedback vector into r2, or undefined.
2525 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2526 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2527 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2528 __ b(eq, &feedback_register_initialized);
2529 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2530 __ bind(&feedback_register_initialized);
2533 __ AssertUndefinedOrAllocationSite(r2, r5);
2536 // Pass function as original constructor.
2537 if (IsSuperConstructorCall()) {
2543 // Jump to the function-specific construct stub.
2544 Register jmp_reg = r4;
2545 __ ldr(jmp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2546 __ ldr(jmp_reg, FieldMemOperand(jmp_reg,
2547 SharedFunctionInfo::kConstructStubOffset));
2548 __ add(pc, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2550 // r0: number of arguments
2551 // r1: called object
2555 __ cmp(r5, Operand(JS_FUNCTION_PROXY_TYPE));
2556 __ b(ne, &non_function_call);
2557 __ GetBuiltinFunction(
2558 r1, Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2561 __ bind(&non_function_call);
2562 __ GetBuiltinFunction(
2563 r1, Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2565 // Set expected number of arguments to zero (not changing r0).
2566 __ mov(r2, Operand::Zero());
2567 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2568 RelocInfo::CODE_TARGET);
2572 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2573 __ ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2574 __ ldr(vector, FieldMemOperand(vector,
2575 JSFunction::kSharedFunctionInfoOffset));
2576 __ ldr(vector, FieldMemOperand(vector,
2577 SharedFunctionInfo::kFeedbackVectorOffset));
2581 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2586 int argc = arg_count();
2587 ParameterCount actual(argc);
2589 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2593 __ mov(r0, Operand(arg_count()));
2594 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2595 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2597 // Verify that r4 contains an AllocationSite
2598 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2599 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2602 // Increment the call count for monomorphic function calls.
2603 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2604 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2605 __ ldr(r3, FieldMemOperand(r2, 0));
2606 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2607 __ str(r3, FieldMemOperand(r2, 0));
2611 ArrayConstructorStub stub(masm->isolate(), arg_count());
2612 __ TailCallStub(&stub);
2617 // The slow case, we need this no matter what to complete a call after a miss.
2618 CallFunctionNoFeedback(masm,
2624 __ stop("Unexpected code address");
2628 void CallICStub::Generate(MacroAssembler* masm) {
2630 // r3 - slot id (Smi)
2632 const int with_types_offset =
2633 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2634 const int generic_offset =
2635 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2636 Label extra_checks_or_miss, slow_start;
2637 Label slow, non_function, wrap, cont;
2638 Label have_js_function;
2639 int argc = arg_count();
2640 ParameterCount actual(argc);
2642 // The checks. First, does r1 match the recorded monomorphic target?
2643 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2644 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2646 // We don't know that we have a weak cell. We might have a private symbol
2647 // or an AllocationSite, but the memory is safe to examine.
2648 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2650 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2651 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2652 // computed, meaning that it can't appear to be a pointer. If the low bit is
2653 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2655 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2656 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2657 WeakCell::kValueOffset &&
2658 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2660 __ ldr(r5, FieldMemOperand(r4, WeakCell::kValueOffset));
2662 __ b(ne, &extra_checks_or_miss);
2664 // The compare above could have been a SMI/SMI comparison. Guard against this
2665 // convincing us that we have a monomorphic JSFunction.
2666 __ JumpIfSmi(r1, &extra_checks_or_miss);
2668 // Increment the call count for monomorphic function calls.
2669 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2670 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2671 __ ldr(r3, FieldMemOperand(r2, 0));
2672 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2673 __ str(r3, FieldMemOperand(r2, 0));
2675 __ bind(&have_js_function);
2676 if (CallAsMethod()) {
2677 EmitContinueIfStrictOrNative(masm, &cont);
2678 // Compute the receiver in sloppy mode.
2679 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2681 __ JumpIfSmi(r3, &wrap);
2682 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2688 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2691 EmitSlowCase(masm, argc, &non_function);
2693 if (CallAsMethod()) {
2695 EmitWrapCase(masm, argc, &cont);
2698 __ bind(&extra_checks_or_miss);
2699 Label uninitialized, miss;
2701 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2702 __ b(eq, &slow_start);
2704 // The following cases attempt to handle MISS cases without going to the
2706 if (FLAG_trace_ic) {
2710 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2711 __ b(eq, &uninitialized);
2713 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2714 // to handle it here. More complex cases are dealt with in the runtime.
2715 __ AssertNotSmi(r4);
2716 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2718 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2719 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2720 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2721 // We have to update statistics for runtime profiling.
2722 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2723 __ sub(r4, r4, Operand(Smi::FromInt(1)));
2724 __ str(r4, FieldMemOperand(r2, with_types_offset));
2725 __ ldr(r4, FieldMemOperand(r2, generic_offset));
2726 __ add(r4, r4, Operand(Smi::FromInt(1)));
2727 __ str(r4, FieldMemOperand(r2, generic_offset));
2728 __ jmp(&slow_start);
2730 __ bind(&uninitialized);
2732 // We are going monomorphic, provided we actually have a JSFunction.
2733 __ JumpIfSmi(r1, &miss);
2735 // Goto miss case if we do not have a function.
2736 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2739 // Make sure the function is not the Array() function, which requires special
2740 // behavior on MISS.
2741 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2746 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2747 __ add(r4, r4, Operand(Smi::FromInt(1)));
2748 __ str(r4, FieldMemOperand(r2, with_types_offset));
2750 // Initialize the call counter.
2751 __ Move(r5, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2752 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2753 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + kPointerSize));
2755 // Store the function. Use a stub since we need a frame for allocation.
2760 FrameScope scope(masm, StackFrame::INTERNAL);
2761 CreateWeakCellStub create_stub(masm->isolate());
2763 __ CallStub(&create_stub);
2767 __ jmp(&have_js_function);
2769 // We are here because tracing is on or we encountered a MISS case we can't
2775 __ bind(&slow_start);
2776 // Check that the function is really a JavaScript function.
2777 // r1: pushed function (to be verified)
2778 __ JumpIfSmi(r1, &non_function);
2780 // Goto slow case if we do not have a function.
2781 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2783 __ jmp(&have_js_function);
2787 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2788 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2790 // Push the receiver and the function and feedback info.
2791 __ Push(r1, r2, r3);
2794 Runtime::FunctionId id = GetICState() == DEFAULT
2795 ? Runtime::kCallIC_Miss
2796 : Runtime::kCallIC_Customization_Miss;
2797 __ CallRuntime(id, 3);
2799 // Move result to edi and exit the internal frame.
2804 // StringCharCodeAtGenerator
2805 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2806 // If the receiver is a smi trigger the non-string case.
2807 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2808 __ JumpIfSmi(object_, receiver_not_string_);
2810 // Fetch the instance type of the receiver into result register.
2811 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2812 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2813 // If the receiver is not a string trigger the non-string case.
2814 __ tst(result_, Operand(kIsNotStringMask));
2815 __ b(ne, receiver_not_string_);
2818 // If the index is non-smi trigger the non-smi case.
2819 __ JumpIfNotSmi(index_, &index_not_smi_);
2820 __ bind(&got_smi_index_);
2822 // Check for index out of range.
2823 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
2824 __ cmp(ip, Operand(index_));
2825 __ b(ls, index_out_of_range_);
2827 __ SmiUntag(index_);
2829 StringCharLoadGenerator::Generate(masm,
2840 void StringCharCodeAtGenerator::GenerateSlow(
2841 MacroAssembler* masm, EmbedMode embed_mode,
2842 const RuntimeCallHelper& call_helper) {
2843 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2845 // Index is not a smi.
2846 __ bind(&index_not_smi_);
2847 // If index is a heap number, try converting it to an integer.
2850 Heap::kHeapNumberMapRootIndex,
2853 call_helper.BeforeCall(masm);
2854 if (embed_mode == PART_OF_IC_HANDLER) {
2855 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2856 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2858 // index_ is consumed by runtime conversion function.
2859 __ Push(object_, index_);
2861 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2862 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2864 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2865 // NumberToSmi discards numbers that are not exact integers.
2866 __ CallRuntime(Runtime::kNumberToSmi, 1);
2868 // Save the conversion result before the pop instructions below
2869 // have a chance to overwrite it.
2870 __ Move(index_, r0);
2871 if (embed_mode == PART_OF_IC_HANDLER) {
2872 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2873 LoadWithVectorDescriptor::SlotRegister(), object_);
2877 // Reload the instance type.
2878 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2879 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2880 call_helper.AfterCall(masm);
2881 // If index is still not a smi, it must be out of range.
2882 __ JumpIfNotSmi(index_, index_out_of_range_);
2883 // Otherwise, return to the fast path.
2884 __ jmp(&got_smi_index_);
2886 // Call runtime. We get here when the receiver is a string and the
2887 // index is a number, but the code of getting the actual character
2888 // is too complex (e.g., when the string needs to be flattened).
2889 __ bind(&call_runtime_);
2890 call_helper.BeforeCall(masm);
2892 __ Push(object_, index_);
2893 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2894 __ Move(result_, r0);
2895 call_helper.AfterCall(masm);
2898 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2902 // -------------------------------------------------------------------------
2903 // StringCharFromCodeGenerator
2905 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2906 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2907 STATIC_ASSERT(kSmiTag == 0);
2908 STATIC_ASSERT(kSmiShiftSize == 0);
2909 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2910 __ tst(code_, Operand(kSmiTagMask |
2911 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
2912 __ b(ne, &slow_case_);
2914 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2915 // At this point code register contains smi tagged one-byte char code.
2916 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
2917 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
2918 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
2919 __ b(eq, &slow_case_);
2924 void StringCharFromCodeGenerator::GenerateSlow(
2925 MacroAssembler* masm,
2926 const RuntimeCallHelper& call_helper) {
2927 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2929 __ bind(&slow_case_);
2930 call_helper.BeforeCall(masm);
2932 __ CallRuntime(Runtime::kCharFromCode, 1);
2933 __ Move(result_, r0);
2934 call_helper.AfterCall(masm);
2937 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2941 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
2944 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2949 String::Encoding encoding) {
2950 if (FLAG_debug_code) {
2951 // Check that destination is word aligned.
2952 __ tst(dest, Operand(kPointerAlignmentMask));
2953 __ Check(eq, kDestinationOfCopyNotAligned);
2956 // Assumes word reads and writes are little endian.
2957 // Nothing to do for zero characters.
2959 if (encoding == String::TWO_BYTE_ENCODING) {
2960 __ add(count, count, Operand(count), SetCC);
2963 Register limit = count; // Read until dest equals this.
2964 __ add(limit, dest, Operand(count));
2966 Label loop_entry, loop;
2967 // Copy bytes from src to dest until dest hits limit.
2970 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
2971 __ strb(scratch, MemOperand(dest, 1, PostIndex));
2972 __ bind(&loop_entry);
2973 __ cmp(dest, Operand(limit));
2980 void SubStringStub::Generate(MacroAssembler* masm) {
2983 // Stack frame on entry.
2984 // lr: return address
2989 // This stub is called from the native-call %_SubString(...), so
2990 // nothing can be assumed about the arguments. It is tested that:
2991 // "string" is a sequential string,
2992 // both "from" and "to" are smis, and
2993 // 0 <= from <= to <= string.length.
2994 // If any of these assumptions fail, we call the runtime system.
2996 const int kToOffset = 0 * kPointerSize;
2997 const int kFromOffset = 1 * kPointerSize;
2998 const int kStringOffset = 2 * kPointerSize;
3000 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
3001 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3002 STATIC_ASSERT(kSmiTag == 0);
3003 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3005 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
3006 // instead because we bail out on non-smi values: ROR and ASR are equivalent
3007 // for smis but they set the flags in a way that's easier to optimize.
3008 __ mov(r2, Operand(r2, ROR, 1), SetCC);
3009 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
3010 // If either to or from had the smi tag bit set, then C is set now, and N
3011 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
3012 // We want to bailout to runtime here if From is negative. In that case, the
3013 // next instruction is not executed and we fall through to bailing out to
3015 // Executed if both r2 and r3 are untagged integers.
3016 __ sub(r2, r2, Operand(r3), SetCC, cc);
3017 // One of the above un-smis or the above SUB could have set N==1.
3018 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
3020 // Make sure first argument is a string.
3021 __ ldr(r0, MemOperand(sp, kStringOffset));
3022 __ JumpIfSmi(r0, &runtime);
3023 Condition is_string = masm->IsObjectStringType(r0, r1);
3024 __ b(NegateCondition(is_string), &runtime);
3027 __ cmp(r2, Operand(1));
3028 __ b(eq, &single_char);
3030 // Short-cut for the case of trivial substring.
3032 // r0: original string
3033 // r2: result string length
3034 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
3035 __ cmp(r2, Operand(r4, ASR, 1));
3036 // Return original string.
3037 __ b(eq, &return_r0);
3038 // Longer than original string's length or negative: unsafe arguments.
3040 // Shorter than original string's length: an actual substring.
3042 // Deal with different string types: update the index if necessary
3043 // and put the underlying string into r5.
3044 // r0: original string
3045 // r1: instance type
3047 // r3: from index (untagged)
3048 Label underlying_unpacked, sliced_string, seq_or_external_string;
3049 // If the string is not indirect, it can only be sequential or external.
3050 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3051 STATIC_ASSERT(kIsIndirectStringMask != 0);
3052 __ tst(r1, Operand(kIsIndirectStringMask));
3053 __ b(eq, &seq_or_external_string);
3055 __ tst(r1, Operand(kSlicedNotConsMask));
3056 __ b(ne, &sliced_string);
3057 // Cons string. Check whether it is flat, then fetch first part.
3058 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
3059 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
3061 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
3062 // Update instance type.
3063 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3064 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3065 __ jmp(&underlying_unpacked);
3067 __ bind(&sliced_string);
3068 // Sliced string. Fetch parent and correct start index by offset.
3069 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3070 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3071 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
3072 // Update instance type.
3073 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3074 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3075 __ jmp(&underlying_unpacked);
3077 __ bind(&seq_or_external_string);
3078 // Sequential or external string. Just move string to the expected register.
3081 __ bind(&underlying_unpacked);
3083 if (FLAG_string_slices) {
3085 // r5: underlying subject string
3086 // r1: instance type of underlying subject string
3088 // r3: adjusted start index (untagged)
3089 __ cmp(r2, Operand(SlicedString::kMinLength));
3090 // Short slice. Copy instead of slicing.
3091 __ b(lt, ©_routine);
3092 // Allocate new sliced string. At this point we do not reload the instance
3093 // type including the string encoding because we simply rely on the info
3094 // provided by the original string. It does not matter if the original
3095 // string's encoding is wrong because we always have to recheck encoding of
3096 // the newly created string's parent anyways due to externalized strings.
3097 Label two_byte_slice, set_slice_header;
3098 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3099 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3100 __ tst(r1, Operand(kStringEncodingMask));
3101 __ b(eq, &two_byte_slice);
3102 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
3103 __ jmp(&set_slice_header);
3104 __ bind(&two_byte_slice);
3105 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
3106 __ bind(&set_slice_header);
3107 __ mov(r3, Operand(r3, LSL, 1));
3108 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3109 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3112 __ bind(©_routine);
3115 // r5: underlying subject string
3116 // r1: instance type of underlying subject string
3118 // r3: adjusted start index (untagged)
3119 Label two_byte_sequential, sequential_string, allocate_result;
3120 STATIC_ASSERT(kExternalStringTag != 0);
3121 STATIC_ASSERT(kSeqStringTag == 0);
3122 __ tst(r1, Operand(kExternalStringTag));
3123 __ b(eq, &sequential_string);
3125 // Handle external string.
3126 // Rule out short external strings.
3127 STATIC_ASSERT(kShortExternalStringTag != 0);
3128 __ tst(r1, Operand(kShortExternalStringTag));
3130 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
3131 // r5 already points to the first character of underlying string.
3132 __ jmp(&allocate_result);
3134 __ bind(&sequential_string);
3135 // Locate first character of underlying subject string.
3136 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3137 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3139 __ bind(&allocate_result);
3140 // Sequential acii string. Allocate the result.
3141 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3142 __ tst(r1, Operand(kStringEncodingMask));
3143 __ b(eq, &two_byte_sequential);
3145 // Allocate and copy the resulting one-byte string.
3146 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
3148 // Locate first character of substring to copy.
3150 // Locate first character of result.
3151 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3153 // r0: result string
3154 // r1: first character of result string
3155 // r2: result string length
3156 // r5: first character of substring to copy
3157 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3158 StringHelper::GenerateCopyCharacters(
3159 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
3162 // Allocate and copy the resulting two-byte string.
3163 __ bind(&two_byte_sequential);
3164 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
3166 // Locate first character of substring to copy.
3167 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3168 __ add(r5, r5, Operand(r3, LSL, 1));
3169 // Locate first character of result.
3170 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3172 // r0: result string.
3173 // r1: first character of result.
3174 // r2: result length.
3175 // r5: first character of substring to copy.
3176 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3177 StringHelper::GenerateCopyCharacters(
3178 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
3180 __ bind(&return_r0);
3181 Counters* counters = isolate()->counters();
3182 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
3186 // Just jump to runtime to create the sub string.
3188 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3190 __ bind(&single_char);
3191 // r0: original string
3192 // r1: instance type
3194 // r3: from index (untagged)
3196 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
3197 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3198 generator.GenerateFast(masm);
3201 generator.SkipSlow(masm, &runtime);
3205 void ToNumberStub::Generate(MacroAssembler* masm) {
3206 // The ToNumber stub takes one argument in r0.
3208 __ JumpIfNotSmi(r0, ¬_smi);
3212 __ CompareObjectType(r0, r1, r1, HEAP_NUMBER_TYPE);
3214 // r1: receiver instance type
3217 Label not_string, slow_string;
3218 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
3219 __ b(hs, ¬_string);
3220 // Check if string has a cached array index.
3221 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
3222 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
3223 __ b(ne, &slow_string);
3224 __ IndexFromHash(r2, r0);
3226 __ bind(&slow_string);
3227 __ push(r0); // Push argument.
3228 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3229 __ bind(¬_string);
3232 __ cmp(r1, Operand(ODDBALL_TYPE));
3233 __ b(ne, ¬_oddball);
3234 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
3236 __ bind(¬_oddball);
3238 __ push(r0); // Push argument.
3239 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3243 void ToStringStub::Generate(MacroAssembler* masm) {
3244 // The ToString stub takes one argument in r0.
3246 __ JumpIfSmi(r0, &is_number);
3248 __ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE);
3250 // r1: receiver instance type
3253 Label not_heap_number;
3254 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
3255 __ b(ne, ¬_heap_number);
3256 __ bind(&is_number);
3257 NumberToStringStub stub(isolate());
3258 __ TailCallStub(&stub);
3259 __ bind(¬_heap_number);
3262 __ cmp(r1, Operand(ODDBALL_TYPE));
3263 __ b(ne, ¬_oddball);
3264 __ ldr(r0, FieldMemOperand(r0, Oddball::kToStringOffset));
3266 __ bind(¬_oddball);
3268 __ push(r0); // Push argument.
3269 __ TailCallRuntime(Runtime::kToString, 1, 1);
3273 void StringHelper::GenerateFlatOneByteStringEquals(
3274 MacroAssembler* masm, Register left, Register right, Register scratch1,
3275 Register scratch2, Register scratch3) {
3276 Register length = scratch1;
3279 Label strings_not_equal, check_zero_length;
3280 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
3281 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3282 __ cmp(length, scratch2);
3283 __ b(eq, &check_zero_length);
3284 __ bind(&strings_not_equal);
3285 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
3288 // Check if the length is zero.
3289 Label compare_chars;
3290 __ bind(&check_zero_length);
3291 STATIC_ASSERT(kSmiTag == 0);
3292 __ cmp(length, Operand::Zero());
3293 __ b(ne, &compare_chars);
3294 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3297 // Compare characters.
3298 __ bind(&compare_chars);
3299 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3300 &strings_not_equal);
3302 // Characters are equal.
3303 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3308 void StringHelper::GenerateCompareFlatOneByteStrings(
3309 MacroAssembler* masm, Register left, Register right, Register scratch1,
3310 Register scratch2, Register scratch3, Register scratch4) {
3311 Label result_not_equal, compare_lengths;
3312 // Find minimum length and length difference.
3313 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3314 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3315 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
3316 Register length_delta = scratch3;
3317 __ mov(scratch1, scratch2, LeaveCC, gt);
3318 Register min_length = scratch1;
3319 STATIC_ASSERT(kSmiTag == 0);
3320 __ cmp(min_length, Operand::Zero());
3321 __ b(eq, &compare_lengths);
3324 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3325 scratch4, &result_not_equal);
3327 // Compare lengths - strings up to min-length are equal.
3328 __ bind(&compare_lengths);
3329 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3330 // Use length_delta as result if it's zero.
3331 __ mov(r0, Operand(length_delta), SetCC);
3332 __ bind(&result_not_equal);
3333 // Conditionally update the result based either on length_delta or
3334 // the last comparion performed in the loop above.
3335 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
3336 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
3341 void StringHelper::GenerateOneByteCharsCompareLoop(
3342 MacroAssembler* masm, Register left, Register right, Register length,
3343 Register scratch1, Register scratch2, Label* chars_not_equal) {
3344 // Change index to run from -length to -1 by adding length to string
3345 // start. This means that loop ends when index reaches zero, which
3346 // doesn't need an additional compare.
3347 __ SmiUntag(length);
3348 __ add(scratch1, length,
3349 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3350 __ add(left, left, Operand(scratch1));
3351 __ add(right, right, Operand(scratch1));
3352 __ rsb(length, length, Operand::Zero());
3353 Register index = length; // index = -length;
3358 __ ldrb(scratch1, MemOperand(left, index));
3359 __ ldrb(scratch2, MemOperand(right, index));
3360 __ cmp(scratch1, scratch2);
3361 __ b(ne, chars_not_equal);
3362 __ add(index, index, Operand(1), SetCC);
3367 void StringCompareStub::Generate(MacroAssembler* masm) {
3370 Counters* counters = isolate()->counters();
3372 // Stack frame on entry.
3373 // sp[0]: right string
3374 // sp[4]: left string
3375 __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1.
3379 __ b(ne, ¬_same);
3380 STATIC_ASSERT(EQUAL == 0);
3381 STATIC_ASSERT(kSmiTag == 0);
3382 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3383 __ IncrementCounter(counters->string_compare_native(), 1, r1, r2);
3384 __ add(sp, sp, Operand(2 * kPointerSize));
3389 // Check that both objects are sequential one-byte strings.
3390 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
3392 // Compare flat one-byte strings natively. Remove arguments from stack first.
3393 __ IncrementCounter(counters->string_compare_native(), 1, r2, r3);
3394 __ add(sp, sp, Operand(2 * kPointerSize));
3395 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
3397 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3398 // tagged as a small integer.
3400 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3404 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3405 // ----------- S t a t e -------------
3408 // -- lr : return address
3409 // -----------------------------------
3411 // Load r2 with the allocation site. We stick an undefined dummy value here
3412 // and replace it with the real allocation site later when we instantiate this
3413 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3414 __ Move(r2, handle(isolate()->heap()->undefined_value()));
3416 // Make sure that we actually patched the allocation site.
3417 if (FLAG_debug_code) {
3418 __ tst(r2, Operand(kSmiTagMask));
3419 __ Assert(ne, kExpectedAllocationSite);
3421 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3422 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3425 __ Assert(eq, kExpectedAllocationSite);
3428 // Tail call into the stub that handles binary operations with allocation
3430 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3431 __ TailCallStub(&stub);
3435 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3436 DCHECK(state() == CompareICState::SMI);
3439 __ JumpIfNotSmi(r2, &miss);
3441 if (GetCondition() == eq) {
3442 // For equality we do not care about the sign of the result.
3443 __ sub(r0, r0, r1, SetCC);
3445 // Untag before subtracting to avoid handling overflow.
3447 __ sub(r0, r1, Operand::SmiUntag(r0));
3456 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3457 DCHECK(state() == CompareICState::NUMBER);
3460 Label unordered, maybe_undefined1, maybe_undefined2;
3463 if (left() == CompareICState::SMI) {
3464 __ JumpIfNotSmi(r1, &miss);
3466 if (right() == CompareICState::SMI) {
3467 __ JumpIfNotSmi(r0, &miss);
3470 // Inlining the double comparison and falling back to the general compare
3471 // stub if NaN is involved.
3472 // Load left and right operand.
3473 Label done, left, left_smi, right_smi;
3474 __ JumpIfSmi(r0, &right_smi);
3475 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3477 __ sub(r2, r0, Operand(kHeapObjectTag));
3478 __ vldr(d1, r2, HeapNumber::kValueOffset);
3480 __ bind(&right_smi);
3481 __ SmiToDouble(d1, r0);
3484 __ JumpIfSmi(r1, &left_smi);
3485 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3487 __ sub(r2, r1, Operand(kHeapObjectTag));
3488 __ vldr(d0, r2, HeapNumber::kValueOffset);
3491 __ SmiToDouble(d0, r1);
3494 // Compare operands.
3495 __ VFPCompareAndSetFlags(d0, d1);
3497 // Don't base result on status bits when a NaN is involved.
3498 __ b(vs, &unordered);
3500 // Return a result of -1, 0, or 1, based on status bits.
3501 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
3502 __ mov(r0, Operand(LESS), LeaveCC, lt);
3503 __ mov(r0, Operand(GREATER), LeaveCC, gt);
3506 __ bind(&unordered);
3507 __ bind(&generic_stub);
3508 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3509 CompareICState::GENERIC, CompareICState::GENERIC);
3510 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3512 __ bind(&maybe_undefined1);
3513 if (Token::IsOrderedRelationalCompareOp(op())) {
3514 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3516 __ JumpIfSmi(r1, &unordered);
3517 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3518 __ b(ne, &maybe_undefined2);
3522 __ bind(&maybe_undefined2);
3523 if (Token::IsOrderedRelationalCompareOp(op())) {
3524 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3525 __ b(eq, &unordered);
3533 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3534 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3537 // Registers containing left and right operands respectively.
3539 Register right = r0;
3543 // Check that both operands are heap objects.
3544 __ JumpIfEitherSmi(left, right, &miss);
3546 // Check that both operands are internalized strings.
3547 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3548 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3549 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3550 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3551 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3552 __ orr(tmp1, tmp1, Operand(tmp2));
3553 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3556 // Internalized strings are compared by identity.
3557 __ cmp(left, right);
3558 // Make sure r0 is non-zero. At this point input operands are
3559 // guaranteed to be non-zero.
3560 DCHECK(right.is(r0));
3561 STATIC_ASSERT(EQUAL == 0);
3562 STATIC_ASSERT(kSmiTag == 0);
3563 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3571 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3572 DCHECK(state() == CompareICState::UNIQUE_NAME);
3573 DCHECK(GetCondition() == eq);
3576 // Registers containing left and right operands respectively.
3578 Register right = r0;
3582 // Check that both operands are heap objects.
3583 __ JumpIfEitherSmi(left, right, &miss);
3585 // Check that both operands are unique names. This leaves the instance
3586 // types loaded in tmp1 and tmp2.
3587 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3588 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3589 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3590 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3592 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3593 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3595 // Unique names are compared by identity.
3596 __ cmp(left, right);
3597 // Make sure r0 is non-zero. At this point input operands are
3598 // guaranteed to be non-zero.
3599 DCHECK(right.is(r0));
3600 STATIC_ASSERT(EQUAL == 0);
3601 STATIC_ASSERT(kSmiTag == 0);
3602 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3610 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3611 DCHECK(state() == CompareICState::STRING);
3614 bool equality = Token::IsEqualityOp(op());
3616 // Registers containing left and right operands respectively.
3618 Register right = r0;
3624 // Check that both operands are heap objects.
3625 __ JumpIfEitherSmi(left, right, &miss);
3627 // Check that both operands are strings. This leaves the instance
3628 // types loaded in tmp1 and tmp2.
3629 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3630 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3631 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3632 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3633 STATIC_ASSERT(kNotStringTag != 0);
3634 __ orr(tmp3, tmp1, tmp2);
3635 __ tst(tmp3, Operand(kIsNotStringMask));
3638 // Fast check for identical strings.
3639 __ cmp(left, right);
3640 STATIC_ASSERT(EQUAL == 0);
3641 STATIC_ASSERT(kSmiTag == 0);
3642 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3645 // Handle not identical strings.
3647 // Check that both strings are internalized strings. If they are, we're done
3648 // because we already know they are not identical. We know they are both
3651 DCHECK(GetCondition() == eq);
3652 STATIC_ASSERT(kInternalizedTag == 0);
3653 __ orr(tmp3, tmp1, Operand(tmp2));
3654 __ tst(tmp3, Operand(kIsNotInternalizedMask));
3655 // Make sure r0 is non-zero. At this point input operands are
3656 // guaranteed to be non-zero.
3657 DCHECK(right.is(r0));
3661 // Check that both strings are sequential one-byte.
3663 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3666 // Compare flat one-byte strings. Returns when done.
3668 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3671 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3675 // Handle more complex cases in runtime.
3677 __ Push(left, right);
3679 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3681 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3689 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3690 DCHECK(state() == CompareICState::OBJECT);
3692 __ and_(r2, r1, Operand(r0));
3693 __ JumpIfSmi(r2, &miss);
3695 __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
3697 __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
3700 DCHECK(GetCondition() == eq);
3701 __ sub(r0, r0, Operand(r1));
3709 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3711 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3712 __ and_(r2, r1, Operand(r0));
3713 __ JumpIfSmi(r2, &miss);
3714 __ GetWeakValue(r4, cell);
3715 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3716 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
3722 __ sub(r0, r0, Operand(r1));
3730 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3732 // Call the runtime system in a fresh internal frame.
3733 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3735 __ Push(lr, r1, r0);
3736 __ mov(ip, Operand(Smi::FromInt(op())));
3738 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3739 // Compute the entry point of the rewritten stub.
3740 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3741 // Restore registers.
3750 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3751 // Place the return address on the stack, making the call
3752 // GC safe. The RegExp backend also relies on this.
3753 __ str(lr, MemOperand(sp, 0));
3754 __ blx(ip); // Call the C++ function.
3755 __ VFPEnsureFPSCRState(r2);
3756 __ ldr(pc, MemOperand(sp, 0));
3760 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3763 reinterpret_cast<intptr_t>(GetCode().location());
3764 __ Move(ip, target);
3765 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3766 __ blx(lr); // Call the stub.
3770 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3774 Register properties,
3776 Register scratch0) {
3777 DCHECK(name->IsUniqueName());
3778 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3779 // not equal to the name and kProbes-th slot is not used (its name is the
3780 // undefined value), it guarantees the hash table doesn't contain the
3781 // property. It's true even if some slots represent deleted properties
3782 // (their names are the hole value).
3783 for (int i = 0; i < kInlinedProbes; i++) {
3784 // scratch0 points to properties hash.
3785 // Compute the masked index: (hash + i + i * i) & mask.
3786 Register index = scratch0;
3787 // Capacity is smi 2^n.
3788 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3789 __ sub(index, index, Operand(1));
3790 __ and_(index, index, Operand(
3791 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3793 // Scale the index by multiplying by the entry size.
3794 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3795 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3797 Register entity_name = scratch0;
3798 // Having undefined at this place means the name is not contained.
3799 STATIC_ASSERT(kSmiTagSize == 1);
3800 Register tmp = properties;
3801 __ add(tmp, properties, Operand(index, LSL, 1));
3802 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3804 DCHECK(!tmp.is(entity_name));
3805 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3806 __ cmp(entity_name, tmp);
3809 // Load the hole ready for use below:
3810 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3812 // Stop if found the property.
3813 __ cmp(entity_name, Operand(Handle<Name>(name)));
3817 __ cmp(entity_name, tmp);
3820 // Check if the entry name is not a unique name.
3821 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3822 __ ldrb(entity_name,
3823 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3824 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3827 // Restore the properties.
3829 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3832 const int spill_mask =
3833 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3834 r2.bit() | r1.bit() | r0.bit());
3836 __ stm(db_w, sp, spill_mask);
3837 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3838 __ mov(r1, Operand(Handle<Name>(name)));
3839 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3841 __ cmp(r0, Operand::Zero());
3842 __ ldm(ia_w, sp, spill_mask);
3849 // Probe the name dictionary in the |elements| register. Jump to the
3850 // |done| label if a property with the given name is found. Jump to
3851 // the |miss| label otherwise.
3852 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
3853 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3859 Register scratch2) {
3860 DCHECK(!elements.is(scratch1));
3861 DCHECK(!elements.is(scratch2));
3862 DCHECK(!name.is(scratch1));
3863 DCHECK(!name.is(scratch2));
3865 __ AssertName(name);
3867 // Compute the capacity mask.
3868 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
3869 __ SmiUntag(scratch1);
3870 __ sub(scratch1, scratch1, Operand(1));
3872 // Generate an unrolled loop that performs a few probes before
3873 // giving up. Measurements done on Gmail indicate that 2 probes
3874 // cover ~93% of loads from dictionaries.
3875 for (int i = 0; i < kInlinedProbes; i++) {
3876 // Compute the masked index: (hash + i + i * i) & mask.
3877 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3879 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3880 // the hash in a separate instruction. The value hash + i + i * i is right
3881 // shifted in the following and instruction.
3882 DCHECK(NameDictionary::GetProbeOffset(i) <
3883 1 << (32 - Name::kHashFieldOffset));
3884 __ add(scratch2, scratch2, Operand(
3885 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3887 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
3889 // Scale the index by multiplying by the entry size.
3890 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3891 // scratch2 = scratch2 * 3.
3892 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3894 // Check if the key is identical to the name.
3895 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3896 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3897 __ cmp(name, Operand(ip));
3901 const int spill_mask =
3902 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3903 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3904 ~(scratch1.bit() | scratch2.bit());
3906 __ stm(db_w, sp, spill_mask);
3908 DCHECK(!elements.is(r1));
3910 __ Move(r0, elements);
3912 __ Move(r0, elements);
3915 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
3917 __ cmp(r0, Operand::Zero());
3918 __ mov(scratch2, Operand(r2));
3919 __ ldm(ia_w, sp, spill_mask);
3926 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3927 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3928 // we cannot call anything that could cause a GC from this stub.
3930 // result: NameDictionary to probe
3932 // dictionary: NameDictionary to probe.
3933 // index: will hold an index of entry if lookup is successful.
3934 // might alias with result_.
3936 // result_ is zero if lookup failed, non zero otherwise.
3938 Register result = r0;
3939 Register dictionary = r0;
3941 Register index = r2;
3944 Register undefined = r5;
3945 Register entry_key = r6;
3947 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3949 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
3951 __ sub(mask, mask, Operand(1));
3953 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
3955 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3957 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3958 // Compute the masked index: (hash + i + i * i) & mask.
3959 // Capacity is smi 2^n.
3961 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3962 // the hash in a separate instruction. The value hash + i + i * i is right
3963 // shifted in the following and instruction.
3964 DCHECK(NameDictionary::GetProbeOffset(i) <
3965 1 << (32 - Name::kHashFieldOffset));
3966 __ add(index, hash, Operand(
3967 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3969 __ mov(index, Operand(hash));
3971 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
3973 // Scale the index by multiplying by the entry size.
3974 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3975 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3977 STATIC_ASSERT(kSmiTagSize == 1);
3978 __ add(index, dictionary, Operand(index, LSL, 2));
3979 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
3981 // Having undefined at this place means the name is not contained.
3982 __ cmp(entry_key, Operand(undefined));
3983 __ b(eq, ¬_in_dictionary);
3985 // Stop if found the property.
3986 __ cmp(entry_key, Operand(key));
3987 __ b(eq, &in_dictionary);
3989 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3990 // Check if the entry name is not a unique name.
3991 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3993 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
3994 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
3998 __ bind(&maybe_in_dictionary);
3999 // If we are doing negative lookup then probing failure should be
4000 // treated as a lookup success. For positive lookup probing failure
4001 // should be treated as lookup failure.
4002 if (mode() == POSITIVE_LOOKUP) {
4003 __ mov(result, Operand::Zero());
4007 __ bind(&in_dictionary);
4008 __ mov(result, Operand(1));
4011 __ bind(¬_in_dictionary);
4012 __ mov(result, Operand::Zero());
4017 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4019 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4021 // Hydrogen code stubs need stub2 at snapshot time.
4022 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4027 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4028 // the value has just been written into the object, now this stub makes sure
4029 // we keep the GC informed. The word in the object where the value has been
4030 // written is in the address register.
4031 void RecordWriteStub::Generate(MacroAssembler* masm) {
4032 Label skip_to_incremental_noncompacting;
4033 Label skip_to_incremental_compacting;
4035 // The first two instructions are generated with labels so as to get the
4036 // offset fixed up correctly by the bind(Label*) call. We patch it back and
4037 // forth between a compare instructions (a nop in this position) and the
4038 // real branch when we start and stop incremental heap marking.
4039 // See RecordWriteStub::Patch for details.
4041 // Block literal pool emission, as the position of these two instructions
4042 // is assumed by the patching code.
4043 Assembler::BlockConstPoolScope block_const_pool(masm);
4044 __ b(&skip_to_incremental_noncompacting);
4045 __ b(&skip_to_incremental_compacting);
4048 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4049 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4050 MacroAssembler::kReturnAtEnd);
4054 __ bind(&skip_to_incremental_noncompacting);
4055 GenerateIncremental(masm, INCREMENTAL);
4057 __ bind(&skip_to_incremental_compacting);
4058 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4060 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4061 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4062 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4063 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
4064 PatchBranchIntoNop(masm, 0);
4065 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4069 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4072 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4073 Label dont_need_remembered_set;
4075 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4076 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4078 &dont_need_remembered_set);
4080 __ CheckPageFlag(regs_.object(),
4082 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4084 &dont_need_remembered_set);
4086 // First notify the incremental marker if necessary, then update the
4088 CheckNeedsToInformIncrementalMarker(
4089 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4090 InformIncrementalMarker(masm);
4091 regs_.Restore(masm);
4092 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4093 MacroAssembler::kReturnAtEnd);
4095 __ bind(&dont_need_remembered_set);
4098 CheckNeedsToInformIncrementalMarker(
4099 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4100 InformIncrementalMarker(masm);
4101 regs_.Restore(masm);
4106 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4107 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4108 int argument_count = 3;
4109 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4111 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4112 DCHECK(!address.is(regs_.object()));
4113 DCHECK(!address.is(r0));
4114 __ Move(address, regs_.address());
4115 __ Move(r0, regs_.object());
4116 __ Move(r1, address);
4117 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4119 AllowExternalCallThatCantCauseGC scope(masm);
4121 ExternalReference::incremental_marking_record_write_function(isolate()),
4123 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4127 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4128 MacroAssembler* masm,
4129 OnNoNeedToInformIncrementalMarker on_no_need,
4132 Label need_incremental;
4133 Label need_incremental_pop_scratch;
4135 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4136 __ ldr(regs_.scratch1(),
4137 MemOperand(regs_.scratch0(),
4138 MemoryChunk::kWriteBarrierCounterOffset));
4139 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4140 __ str(regs_.scratch1(),
4141 MemOperand(regs_.scratch0(),
4142 MemoryChunk::kWriteBarrierCounterOffset));
4143 __ b(mi, &need_incremental);
4145 // Let's look at the color of the object: If it is not black we don't have
4146 // to inform the incremental marker.
4147 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4149 regs_.Restore(masm);
4150 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4151 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4152 MacroAssembler::kReturnAtEnd);
4159 // Get the value from the slot.
4160 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4162 if (mode == INCREMENTAL_COMPACTION) {
4163 Label ensure_not_white;
4165 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4166 regs_.scratch1(), // Scratch.
4167 MemoryChunk::kEvacuationCandidateMask,
4171 __ CheckPageFlag(regs_.object(),
4172 regs_.scratch1(), // Scratch.
4173 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4177 __ bind(&ensure_not_white);
4180 // We need extra registers for this, so we push the object and the address
4181 // register temporarily.
4182 __ Push(regs_.object(), regs_.address());
4183 __ EnsureNotWhite(regs_.scratch0(), // The value.
4184 regs_.scratch1(), // Scratch.
4185 regs_.object(), // Scratch.
4186 regs_.address(), // Scratch.
4187 &need_incremental_pop_scratch);
4188 __ Pop(regs_.object(), regs_.address());
4190 regs_.Restore(masm);
4191 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4192 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4193 MacroAssembler::kReturnAtEnd);
4198 __ bind(&need_incremental_pop_scratch);
4199 __ Pop(regs_.object(), regs_.address());
4201 __ bind(&need_incremental);
4203 // Fall through when we need to inform the incremental marker.
4207 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4208 // ----------- S t a t e -------------
4209 // -- r0 : element value to store
4210 // -- r3 : element index as smi
4211 // -- sp[0] : array literal index in function as smi
4212 // -- sp[4] : array literal
4213 // clobbers r1, r2, r4
4214 // -----------------------------------
4217 Label double_elements;
4219 Label slow_elements;
4220 Label fast_elements;
4222 // Get array literal index, array literal and its map.
4223 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4224 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4225 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4227 __ CheckFastElements(r2, r5, &double_elements);
4228 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4229 __ JumpIfSmi(r0, &smi_element);
4230 __ CheckFastSmiElements(r2, r5, &fast_elements);
4232 // Store into the array literal requires a elements transition. Call into
4234 __ bind(&slow_elements);
4236 __ Push(r1, r3, r0);
4237 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4238 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4240 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4242 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4243 __ bind(&fast_elements);
4244 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4245 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4246 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4247 __ str(r0, MemOperand(r6, 0));
4248 // Update the write barrier for the array store.
4249 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4250 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4253 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4254 // and value is Smi.
4255 __ bind(&smi_element);
4256 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4257 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4258 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4261 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4262 __ bind(&double_elements);
4263 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4264 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
4269 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4270 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4271 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4272 int parameter_count_offset =
4273 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4274 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4275 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4276 __ add(r1, r1, Operand(1));
4278 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4279 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4285 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4286 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4287 LoadICStub stub(isolate(), state());
4288 stub.GenerateForTrampoline(masm);
4292 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4293 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4294 KeyedLoadICStub stub(isolate(), state());
4295 stub.GenerateForTrampoline(masm);
4299 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4300 EmitLoadTypeFeedbackVector(masm, r2);
4301 CallICStub stub(isolate(), state());
4302 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4306 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4307 EmitLoadTypeFeedbackVector(masm, r2);
4308 CallIC_ArrayStub stub(isolate(), state());
4309 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4313 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4316 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4317 GenerateImpl(masm, true);
4321 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4322 Register receiver_map, Register scratch1,
4323 Register scratch2, bool is_polymorphic,
4325 // feedback initially contains the feedback array
4326 Label next_loop, prepare_next;
4327 Label start_polymorphic;
4329 Register cached_map = scratch1;
4332 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4333 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4334 __ cmp(receiver_map, cached_map);
4335 __ b(ne, &start_polymorphic);
4336 // found, now call handler.
4337 Register handler = feedback;
4338 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4339 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4342 Register length = scratch2;
4343 __ bind(&start_polymorphic);
4344 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4345 if (!is_polymorphic) {
4346 // If the IC could be monomorphic we have to make sure we don't go past the
4347 // end of the feedback array.
4348 __ cmp(length, Operand(Smi::FromInt(2)));
4352 Register too_far = length;
4353 Register pointer_reg = feedback;
4355 // +-----+------+------+-----+-----+ ... ----+
4356 // | map | len | wm0 | h0 | wm1 | hN |
4357 // +-----+------+------+-----+-----+ ... ----+
4361 // pointer_reg too_far
4362 // aka feedback scratch2
4363 // also need receiver_map
4364 // use cached_map (scratch1) to look in the weak map values.
4365 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
4366 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4367 __ add(pointer_reg, feedback,
4368 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4370 __ bind(&next_loop);
4371 __ ldr(cached_map, MemOperand(pointer_reg));
4372 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4373 __ cmp(receiver_map, cached_map);
4374 __ b(ne, &prepare_next);
4375 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
4376 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4378 __ bind(&prepare_next);
4379 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4380 __ cmp(pointer_reg, too_far);
4381 __ b(lt, &next_loop);
4383 // We exhausted our array of map handler pairs.
4388 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4389 Register receiver_map, Register feedback,
4390 Register vector, Register slot,
4391 Register scratch, Label* compare_map,
4392 Label* load_smi_map, Label* try_array) {
4393 __ JumpIfSmi(receiver, load_smi_map);
4394 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4395 __ bind(compare_map);
4396 Register cached_map = scratch;
4397 // Move the weak map into the weak_cell register.
4398 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4399 __ cmp(cached_map, receiver_map);
4400 __ b(ne, try_array);
4401 Register handler = feedback;
4402 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
4404 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4405 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4409 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4410 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4411 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
4412 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4413 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4414 Register feedback = r4;
4415 Register receiver_map = r5;
4416 Register scratch1 = r6;
4418 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4419 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4421 // Try to quickly handle the monomorphic case without knowing for sure
4422 // if we have a weak cell in feedback. We do know it's safe to look
4423 // at WeakCell::kValueOffset.
4424 Label try_array, load_smi_map, compare_map;
4425 Label not_array, miss;
4426 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4427 scratch1, &compare_map, &load_smi_map, &try_array);
4429 // Is it a fixed array?
4430 __ bind(&try_array);
4431 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4432 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4433 __ b(ne, ¬_array);
4434 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4436 __ bind(¬_array);
4437 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4439 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4440 Code::ComputeHandlerFlags(Code::LOAD_IC));
4441 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4442 receiver, name, feedback,
4443 receiver_map, scratch1, r9);
4446 LoadIC::GenerateMiss(masm);
4448 __ bind(&load_smi_map);
4449 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4450 __ jmp(&compare_map);
4454 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4455 GenerateImpl(masm, false);
4459 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4460 GenerateImpl(masm, true);
4464 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4465 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4466 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
4467 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4468 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4469 Register feedback = r4;
4470 Register receiver_map = r5;
4471 Register scratch1 = r6;
4473 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4474 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4476 // Try to quickly handle the monomorphic case without knowing for sure
4477 // if we have a weak cell in feedback. We do know it's safe to look
4478 // at WeakCell::kValueOffset.
4479 Label try_array, load_smi_map, compare_map;
4480 Label not_array, miss;
4481 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4482 scratch1, &compare_map, &load_smi_map, &try_array);
4484 __ bind(&try_array);
4485 // Is it a fixed array?
4486 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4487 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4488 __ b(ne, ¬_array);
4490 // We have a polymorphic element handler.
4491 Label polymorphic, try_poly_name;
4492 __ bind(&polymorphic);
4493 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4495 __ bind(¬_array);
4497 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4498 __ b(ne, &try_poly_name);
4499 Handle<Code> megamorphic_stub =
4500 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4501 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4503 __ bind(&try_poly_name);
4504 // We might have a name in feedback, and a fixed array in the next slot.
4505 __ cmp(key, feedback);
4507 // If the name comparison succeeded, we know we have a fixed array with
4508 // at least one map/handler pair.
4509 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4511 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4512 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, false, &miss);
4515 KeyedLoadIC::GenerateMiss(masm);
4517 __ bind(&load_smi_map);
4518 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4519 __ jmp(&compare_map);
4523 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4524 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4525 VectorStoreICStub stub(isolate(), state());
4526 stub.GenerateForTrampoline(masm);
4530 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4531 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4532 VectorKeyedStoreICStub stub(isolate(), state());
4533 stub.GenerateForTrampoline(masm);
4537 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4538 GenerateImpl(masm, false);
4542 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4543 GenerateImpl(masm, true);
4547 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4548 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4549 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4550 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4551 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4552 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4553 Register feedback = r5;
4554 Register receiver_map = r6;
4555 Register scratch1 = r9;
4557 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4558 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4560 // Try to quickly handle the monomorphic case without knowing for sure
4561 // if we have a weak cell in feedback. We do know it's safe to look
4562 // at WeakCell::kValueOffset.
4563 Label try_array, load_smi_map, compare_map;
4564 Label not_array, miss;
4565 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4566 scratch1, &compare_map, &load_smi_map, &try_array);
4568 // Is it a fixed array?
4569 __ bind(&try_array);
4570 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4571 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4572 __ b(ne, ¬_array);
4574 // We are using register r8, which is used for the embedded constant pool
4575 // when FLAG_enable_embedded_constant_pool is true.
4576 DCHECK(!FLAG_enable_embedded_constant_pool);
4577 Register scratch2 = r8;
4578 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4581 __ bind(¬_array);
4582 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4584 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4585 Code::ComputeHandlerFlags(Code::STORE_IC));
4586 masm->isolate()->stub_cache()->GenerateProbe(
4587 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4588 scratch1, scratch2);
4591 StoreIC::GenerateMiss(masm);
4593 __ bind(&load_smi_map);
4594 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4595 __ jmp(&compare_map);
4599 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4600 GenerateImpl(masm, false);
4604 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4605 GenerateImpl(masm, true);
4609 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4610 Register receiver_map, Register scratch1,
4611 Register scratch2, Label* miss) {
4612 // feedback initially contains the feedback array
4613 Label next_loop, prepare_next;
4614 Label start_polymorphic;
4615 Label transition_call;
4617 Register cached_map = scratch1;
4618 Register too_far = scratch2;
4619 Register pointer_reg = feedback;
4620 __ ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4622 // +-----+------+------+-----+-----+-----+ ... ----+
4623 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4624 // +-----+------+------+-----+-----+ ----+ ... ----+
4628 // pointer_reg too_far
4629 // aka feedback scratch2
4630 // also need receiver_map
4631 // use cached_map (scratch1) to look in the weak map values.
4632 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(too_far));
4633 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4634 __ add(pointer_reg, feedback,
4635 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4637 __ bind(&next_loop);
4638 __ ldr(cached_map, MemOperand(pointer_reg));
4639 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4640 __ cmp(receiver_map, cached_map);
4641 __ b(ne, &prepare_next);
4642 // Is it a transitioning store?
4643 __ ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4644 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4645 __ b(ne, &transition_call);
4646 __ ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4647 __ add(pc, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4649 __ bind(&transition_call);
4650 __ ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4651 __ JumpIfSmi(too_far, miss);
4653 __ ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4655 // Load the map into the correct register.
4656 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4657 __ mov(feedback, too_far);
4659 __ add(pc, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4661 __ bind(&prepare_next);
4662 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4663 __ cmp(pointer_reg, too_far);
4664 __ b(lt, &next_loop);
4666 // We exhausted our array of map handler pairs.
4671 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4672 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4673 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4674 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4675 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4676 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4677 Register feedback = r5;
4678 Register receiver_map = r6;
4679 Register scratch1 = r9;
4681 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4682 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4684 // Try to quickly handle the monomorphic case without knowing for sure
4685 // if we have a weak cell in feedback. We do know it's safe to look
4686 // at WeakCell::kValueOffset.
4687 Label try_array, load_smi_map, compare_map;
4688 Label not_array, miss;
4689 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4690 scratch1, &compare_map, &load_smi_map, &try_array);
4692 __ bind(&try_array);
4693 // Is it a fixed array?
4694 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4695 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4696 __ b(ne, ¬_array);
4698 // We have a polymorphic element handler.
4699 Label polymorphic, try_poly_name;
4700 __ bind(&polymorphic);
4702 // We are using register r8, which is used for the embedded constant pool
4703 // when FLAG_enable_embedded_constant_pool is true.
4704 DCHECK(!FLAG_enable_embedded_constant_pool);
4705 Register scratch2 = r8;
4707 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4710 __ bind(¬_array);
4712 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4713 __ b(ne, &try_poly_name);
4714 Handle<Code> megamorphic_stub =
4715 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4716 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4718 __ bind(&try_poly_name);
4719 // We might have a name in feedback, and a fixed array in the next slot.
4720 __ cmp(key, feedback);
4722 // If the name comparison succeeded, we know we have a fixed array with
4723 // at least one map/handler pair.
4724 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4726 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4727 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4731 KeyedStoreIC::GenerateMiss(masm);
4733 __ bind(&load_smi_map);
4734 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4735 __ jmp(&compare_map);
4739 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4740 if (masm->isolate()->function_entry_hook() != NULL) {
4741 ProfileEntryHookStub stub(masm->isolate());
4742 PredictableCodeSizeScope predictable(masm);
4743 predictable.ExpectSize(masm->CallStubSize(&stub) +
4744 2 * Assembler::kInstrSize);
4752 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4753 // The entry hook is a "push lr" instruction, followed by a call.
4754 const int32_t kReturnAddressDistanceFromFunctionStart =
4755 3 * Assembler::kInstrSize;
4757 // This should contain all kCallerSaved registers.
4758 const RegList kSavedRegs =
4765 // We also save lr, so the count here is one higher than the mask indicates.
4766 const int32_t kNumSavedRegs = 7;
4768 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4770 // Save all caller-save registers as this may be called from anywhere.
4771 __ stm(db_w, sp, kSavedRegs | lr.bit());
4773 // Compute the function's address for the first argument.
4774 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4776 // The caller's return address is above the saved temporaries.
4777 // Grab that for the second argument to the hook.
4778 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4780 // Align the stack if necessary.
4781 int frame_alignment = masm->ActivationFrameAlignment();
4782 if (frame_alignment > kPointerSize) {
4784 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4785 __ and_(sp, sp, Operand(-frame_alignment));
4788 #if V8_HOST_ARCH_ARM
4789 int32_t entry_hook =
4790 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4791 __ mov(ip, Operand(entry_hook));
4793 // Under the simulator we need to indirect the entry hook through a
4794 // trampoline function at a known address.
4795 // It additionally takes an isolate as a third parameter
4796 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4798 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4799 __ mov(ip, Operand(ExternalReference(&dispatcher,
4800 ExternalReference::BUILTIN_CALL,
4805 // Restore the stack pointer if needed.
4806 if (frame_alignment > kPointerSize) {
4810 // Also pop pc to get Ret(0).
4811 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4816 static void CreateArrayDispatch(MacroAssembler* masm,
4817 AllocationSiteOverrideMode mode) {
4818 if (mode == DISABLE_ALLOCATION_SITES) {
4819 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4820 __ TailCallStub(&stub);
4821 } else if (mode == DONT_OVERRIDE) {
4822 int last_index = GetSequenceIndexFromFastElementsKind(
4823 TERMINAL_FAST_ELEMENTS_KIND);
4824 for (int i = 0; i <= last_index; ++i) {
4825 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4826 __ cmp(r3, Operand(kind));
4827 T stub(masm->isolate(), kind);
4828 __ TailCallStub(&stub, eq);
4831 // If we reached this point there is a problem.
4832 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4839 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4840 AllocationSiteOverrideMode mode) {
4841 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4842 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4843 // r0 - number of arguments
4844 // r1 - constructor?
4845 // sp[0] - last argument
4846 Label normal_sequence;
4847 if (mode == DONT_OVERRIDE) {
4848 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4849 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4850 STATIC_ASSERT(FAST_ELEMENTS == 2);
4851 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4852 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4853 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4855 // is the low bit set? If so, we are holey and that is good.
4856 __ tst(r3, Operand(1));
4857 __ b(ne, &normal_sequence);
4860 // look at the first argument
4861 __ ldr(r5, MemOperand(sp, 0));
4862 __ cmp(r5, Operand::Zero());
4863 __ b(eq, &normal_sequence);
4865 if (mode == DISABLE_ALLOCATION_SITES) {
4866 ElementsKind initial = GetInitialFastElementsKind();
4867 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4869 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4871 DISABLE_ALLOCATION_SITES);
4872 __ TailCallStub(&stub_holey);
4874 __ bind(&normal_sequence);
4875 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4877 DISABLE_ALLOCATION_SITES);
4878 __ TailCallStub(&stub);
4879 } else if (mode == DONT_OVERRIDE) {
4880 // We are going to create a holey array, but our kind is non-holey.
4881 // Fix kind and retry (only if we have an allocation site in the slot).
4882 __ add(r3, r3, Operand(1));
4884 if (FLAG_debug_code) {
4885 __ ldr(r5, FieldMemOperand(r2, 0));
4886 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4887 __ Assert(eq, kExpectedAllocationSite);
4890 // Save the resulting elements kind in type info. We can't just store r3
4891 // in the AllocationSite::transition_info field because elements kind is
4892 // restricted to a portion of the field...upper bits need to be left alone.
4893 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4894 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4895 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4896 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4898 __ bind(&normal_sequence);
4899 int last_index = GetSequenceIndexFromFastElementsKind(
4900 TERMINAL_FAST_ELEMENTS_KIND);
4901 for (int i = 0; i <= last_index; ++i) {
4902 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4903 __ cmp(r3, Operand(kind));
4904 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4905 __ TailCallStub(&stub, eq);
4908 // If we reached this point there is a problem.
4909 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4917 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4918 int to_index = GetSequenceIndexFromFastElementsKind(
4919 TERMINAL_FAST_ELEMENTS_KIND);
4920 for (int i = 0; i <= to_index; ++i) {
4921 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4922 T stub(isolate, kind);
4924 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4925 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4932 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4933 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4935 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4937 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4942 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4944 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4945 for (int i = 0; i < 2; i++) {
4946 // For internal arrays we only need a few things
4947 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4949 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4951 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4957 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4958 MacroAssembler* masm,
4959 AllocationSiteOverrideMode mode) {
4960 if (argument_count() == ANY) {
4961 Label not_zero_case, not_one_case;
4963 __ b(ne, ¬_zero_case);
4964 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4966 __ bind(¬_zero_case);
4967 __ cmp(r0, Operand(1));
4968 __ b(gt, ¬_one_case);
4969 CreateArrayDispatchOneArgument(masm, mode);
4971 __ bind(¬_one_case);
4972 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4973 } else if (argument_count() == NONE) {
4974 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4975 } else if (argument_count() == ONE) {
4976 CreateArrayDispatchOneArgument(masm, mode);
4977 } else if (argument_count() == MORE_THAN_ONE) {
4978 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4985 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4986 // ----------- S t a t e -------------
4987 // -- r0 : argc (only if argument_count() == ANY)
4988 // -- r1 : constructor
4989 // -- r2 : AllocationSite or undefined
4990 // -- r3 : original constructor
4991 // -- sp[0] : return address
4992 // -- sp[4] : last argument
4993 // -----------------------------------
4995 if (FLAG_debug_code) {
4996 // The array construct code is only set for the global and natives
4997 // builtin Array functions which always have maps.
4999 // Initial map for the builtin Array function should be a map.
5000 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5001 // Will both indicate a NULL and a Smi.
5002 __ tst(r4, Operand(kSmiTagMask));
5003 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5004 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
5005 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5007 // We should either have undefined in r2 or a valid AllocationSite
5008 __ AssertUndefinedOrAllocationSite(r2, r4);
5013 __ b(ne, &subclassing);
5016 // Get the elements kind and case on that.
5017 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
5020 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
5022 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5023 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
5024 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5027 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5029 __ bind(&subclassing);
5034 switch (argument_count()) {
5037 __ add(r0, r0, Operand(2));
5040 __ mov(r0, Operand(2));
5043 __ mov(r0, Operand(3));
5047 __ JumpToExternalReference(
5048 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5052 void InternalArrayConstructorStub::GenerateCase(
5053 MacroAssembler* masm, ElementsKind kind) {
5054 __ cmp(r0, Operand(1));
5056 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5057 __ TailCallStub(&stub0, lo);
5059 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5060 __ TailCallStub(&stubN, hi);
5062 if (IsFastPackedElementsKind(kind)) {
5063 // We might need to create a holey array
5064 // look at the first argument
5065 __ ldr(r3, MemOperand(sp, 0));
5066 __ cmp(r3, Operand::Zero());
5068 InternalArraySingleArgumentConstructorStub
5069 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5070 __ TailCallStub(&stub1_holey, ne);
5073 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5074 __ TailCallStub(&stub1);
5078 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5079 // ----------- S t a t e -------------
5081 // -- r1 : constructor
5082 // -- sp[0] : return address
5083 // -- sp[4] : last argument
5084 // -----------------------------------
5086 if (FLAG_debug_code) {
5087 // The array construct code is only set for the global and natives
5088 // builtin Array functions which always have maps.
5090 // Initial map for the builtin Array function should be a map.
5091 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5092 // Will both indicate a NULL and a Smi.
5093 __ tst(r3, Operand(kSmiTagMask));
5094 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5095 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
5096 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5099 // Figure out the right elements kind
5100 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5101 // Load the map's "bit field 2" into |result|. We only need the first byte,
5102 // but the following bit field extraction takes care of that anyway.
5103 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
5104 // Retrieve elements_kind from bit field 2.
5105 __ DecodeField<Map::ElementsKindBits>(r3);
5107 if (FLAG_debug_code) {
5109 __ cmp(r3, Operand(FAST_ELEMENTS));
5111 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
5113 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5117 Label fast_elements_case;
5118 __ cmp(r3, Operand(FAST_ELEMENTS));
5119 __ b(eq, &fast_elements_case);
5120 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5122 __ bind(&fast_elements_case);
5123 GenerateCase(masm, FAST_ELEMENTS);
5127 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5128 Register context = cp;
5129 Register result = r0;
5132 // Go up the context chain to the script context.
5133 for (int i = 0; i < depth(); ++i) {
5134 __ ldr(result, ContextOperand(context, Context::PREVIOUS_INDEX));
5138 // Load the PropertyCell value at the specified slot.
5139 __ add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5140 __ ldr(result, ContextOperand(result));
5141 __ ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5143 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5144 __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
5147 // Fallback to runtime.
5150 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5154 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5155 Register value = r0;
5159 Register cell_details = r4;
5160 Register cell_value = r5;
5161 Register cell_value_map = r6;
5162 Register scratch = r9;
5164 Register context = cp;
5165 Register context_temp = cell;
5167 Label fast_heapobject_case, fast_smi_case, slow_case;
5169 if (FLAG_debug_code) {
5170 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5171 __ Check(ne, kUnexpectedValue);
5174 // Go up the context chain to the script context.
5175 for (int i = 0; i < depth(); i++) {
5176 __ ldr(context_temp, ContextOperand(context, Context::PREVIOUS_INDEX));
5177 context = context_temp;
5180 // Load the PropertyCell at the specified slot.
5181 __ add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5182 __ ldr(cell, ContextOperand(cell));
5184 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5185 __ ldr(cell_details, FieldMemOperand(cell, PropertyCell::kDetailsOffset));
5186 __ SmiUntag(cell_details);
5187 __ and_(cell_details, cell_details,
5188 Operand(PropertyDetails::PropertyCellTypeField::kMask |
5189 PropertyDetails::KindField::kMask |
5190 PropertyDetails::kAttributesReadOnlyMask));
5192 // Check if PropertyCell holds mutable data.
5193 Label not_mutable_data;
5194 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5195 PropertyCellType::kMutable) |
5196 PropertyDetails::KindField::encode(kData)));
5197 __ b(ne, ¬_mutable_data);
5198 __ JumpIfSmi(value, &fast_smi_case);
5200 __ bind(&fast_heapobject_case);
5201 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5202 // RecordWriteField clobbers the value register, so we copy it before the
5204 __ mov(r4, Operand(value));
5205 __ RecordWriteField(cell, PropertyCell::kValueOffset, r4, scratch,
5206 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5210 __ bind(¬_mutable_data);
5211 // Check if PropertyCell value matches the new value (relevant for Constant,
5212 // ConstantType and Undefined cells).
5213 Label not_same_value;
5214 __ ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5215 __ cmp(cell_value, value);
5216 __ b(ne, ¬_same_value);
5218 // Make sure the PropertyCell is not marked READ_ONLY.
5219 __ tst(cell_details, Operand(PropertyDetails::kAttributesReadOnlyMask));
5220 __ b(ne, &slow_case);
5222 if (FLAG_debug_code) {
5224 // This can only be true for Constant, ConstantType and Undefined cells,
5225 // because we never store the_hole via this stub.
5226 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5227 PropertyCellType::kConstant) |
5228 PropertyDetails::KindField::encode(kData)));
5230 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5231 PropertyCellType::kConstantType) |
5232 PropertyDetails::KindField::encode(kData)));
5234 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5235 PropertyCellType::kUndefined) |
5236 PropertyDetails::KindField::encode(kData)));
5237 __ Check(eq, kUnexpectedValue);
5241 __ bind(¬_same_value);
5243 // Check if PropertyCell contains data with constant type (and is not
5245 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5246 PropertyCellType::kConstantType) |
5247 PropertyDetails::KindField::encode(kData)));
5248 __ b(ne, &slow_case);
5250 // Now either both old and new values must be smis or both must be heap
5251 // objects with same map.
5252 Label value_is_heap_object;
5253 __ JumpIfNotSmi(value, &value_is_heap_object);
5254 __ JumpIfNotSmi(cell_value, &slow_case);
5255 // Old and new values are smis, no need for a write barrier here.
5256 __ bind(&fast_smi_case);
5257 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5260 __ bind(&value_is_heap_object);
5261 __ JumpIfSmi(cell_value, &slow_case);
5263 __ ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5264 __ ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5265 __ cmp(cell_value_map, scratch);
5266 __ b(eq, &fast_heapobject_case);
5268 // Fallback to runtime.
5269 __ bind(&slow_case);
5271 __ Push(slot, value);
5272 __ TailCallRuntime(is_strict(language_mode())
5273 ? Runtime::kStoreGlobalViaContext_Strict
5274 : Runtime::kStoreGlobalViaContext_Sloppy,
5279 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5280 return ref0.address() - ref1.address();
5284 // Calls an API function. Allocates HandleScope, extracts returned value
5285 // from handle and propagates exceptions. Restores context. stack_space
5286 // - space to be unwound on exit (includes the call JS arguments space and
5287 // the additional space allocated for the fast call).
5288 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5289 Register function_address,
5290 ExternalReference thunk_ref,
5292 MemOperand* stack_space_operand,
5293 MemOperand return_value_operand,
5294 MemOperand* context_restore_operand) {
5295 Isolate* isolate = masm->isolate();
5296 ExternalReference next_address =
5297 ExternalReference::handle_scope_next_address(isolate);
5298 const int kNextOffset = 0;
5299 const int kLimitOffset = AddressOffset(
5300 ExternalReference::handle_scope_limit_address(isolate), next_address);
5301 const int kLevelOffset = AddressOffset(
5302 ExternalReference::handle_scope_level_address(isolate), next_address);
5304 DCHECK(function_address.is(r1) || function_address.is(r2));
5306 Label profiler_disabled;
5307 Label end_profiler_check;
5308 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5309 __ ldrb(r9, MemOperand(r9, 0));
5310 __ cmp(r9, Operand(0));
5311 __ b(eq, &profiler_disabled);
5313 // Additional parameter is the address of the actual callback.
5314 __ mov(r3, Operand(thunk_ref));
5315 __ jmp(&end_profiler_check);
5317 __ bind(&profiler_disabled);
5318 __ Move(r3, function_address);
5319 __ bind(&end_profiler_check);
5321 // Allocate HandleScope in callee-save registers.
5322 __ mov(r9, Operand(next_address));
5323 __ ldr(r4, MemOperand(r9, kNextOffset));
5324 __ ldr(r5, MemOperand(r9, kLimitOffset));
5325 __ ldr(r6, MemOperand(r9, kLevelOffset));
5326 __ add(r6, r6, Operand(1));
5327 __ str(r6, MemOperand(r9, kLevelOffset));
5329 if (FLAG_log_timer_events) {
5330 FrameScope frame(masm, StackFrame::MANUAL);
5331 __ PushSafepointRegisters();
5332 __ PrepareCallCFunction(1, r0);
5333 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5334 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5336 __ PopSafepointRegisters();
5339 // Native call returns to the DirectCEntry stub which redirects to the
5340 // return address pushed on stack (could have moved after GC).
5341 // DirectCEntry stub itself is generated early and never moves.
5342 DirectCEntryStub stub(isolate);
5343 stub.GenerateCall(masm, r3);
5345 if (FLAG_log_timer_events) {
5346 FrameScope frame(masm, StackFrame::MANUAL);
5347 __ PushSafepointRegisters();
5348 __ PrepareCallCFunction(1, r0);
5349 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5350 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5352 __ PopSafepointRegisters();
5355 Label promote_scheduled_exception;
5356 Label delete_allocated_handles;
5357 Label leave_exit_frame;
5358 Label return_value_loaded;
5360 // load value from ReturnValue
5361 __ ldr(r0, return_value_operand);
5362 __ bind(&return_value_loaded);
5363 // No more valid handles (the result handle was the last one). Restore
5364 // previous handle scope.
5365 __ str(r4, MemOperand(r9, kNextOffset));
5366 if (__ emit_debug_code()) {
5367 __ ldr(r1, MemOperand(r9, kLevelOffset));
5369 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5371 __ sub(r6, r6, Operand(1));
5372 __ str(r6, MemOperand(r9, kLevelOffset));
5373 __ ldr(ip, MemOperand(r9, kLimitOffset));
5375 __ b(ne, &delete_allocated_handles);
5377 // Leave the API exit frame.
5378 __ bind(&leave_exit_frame);
5379 bool restore_context = context_restore_operand != NULL;
5380 if (restore_context) {
5381 __ ldr(cp, *context_restore_operand);
5383 // LeaveExitFrame expects unwind space to be in a register.
5384 if (stack_space_operand != NULL) {
5385 __ ldr(r4, *stack_space_operand);
5387 __ mov(r4, Operand(stack_space));
5389 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5391 // Check if the function scheduled an exception.
5392 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5393 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5394 __ ldr(r5, MemOperand(ip));
5396 __ b(ne, &promote_scheduled_exception);
5400 // Re-throw by promoting a scheduled exception.
5401 __ bind(&promote_scheduled_exception);
5402 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5404 // HandleScope limit has changed. Delete allocated extensions.
5405 __ bind(&delete_allocated_handles);
5406 __ str(r5, MemOperand(r9, kLimitOffset));
5408 __ PrepareCallCFunction(1, r5);
5409 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5410 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5413 __ jmp(&leave_exit_frame);
5417 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5418 const ParameterCount& argc,
5419 bool return_first_arg,
5420 bool call_data_undefined) {
5421 // ----------- S t a t e -------------
5423 // -- r4 : call_data
5425 // -- r1 : api_function_address
5426 // -- r3 : number of arguments if argc is a register
5429 // -- sp[0] : last argument
5431 // -- sp[(argc - 1)* 4] : first argument
5432 // -- sp[argc * 4] : receiver
5433 // -----------------------------------
5435 Register callee = r0;
5436 Register call_data = r4;
5437 Register holder = r2;
5438 Register api_function_address = r1;
5439 Register context = cp;
5441 typedef FunctionCallbackArguments FCA;
5443 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5444 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5445 STATIC_ASSERT(FCA::kDataIndex == 4);
5446 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5447 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5448 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5449 STATIC_ASSERT(FCA::kHolderIndex == 0);
5450 STATIC_ASSERT(FCA::kArgsLength == 7);
5452 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5456 // load context from callee
5457 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5465 Register scratch = call_data;
5466 if (!call_data_undefined) {
5467 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5471 // return value default
5474 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5479 // Prepare arguments.
5480 __ mov(scratch, sp);
5482 // Allocate the v8::Arguments structure in the arguments' space since
5483 // it's not controlled by GC.
5484 const int kApiStackSpace = 4;
5486 FrameScope frame_scope(masm, StackFrame::MANUAL);
5487 __ EnterExitFrame(false, kApiStackSpace);
5489 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5490 // r0 = FunctionCallbackInfo&
5491 // Arguments is after the return address.
5492 __ add(r0, sp, Operand(1 * kPointerSize));
5493 // FunctionCallbackInfo::implicit_args_
5494 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
5495 if (argc.is_immediate()) {
5496 // FunctionCallbackInfo::values_
5498 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5499 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5500 // FunctionCallbackInfo::length_ = argc
5501 __ mov(ip, Operand(argc.immediate()));
5502 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5503 // FunctionCallbackInfo::is_construct_call_ = 0
5504 __ mov(ip, Operand::Zero());
5505 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5507 // FunctionCallbackInfo::values_
5508 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5509 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5510 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5511 // FunctionCallbackInfo::length_ = argc
5512 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5513 // FunctionCallbackInfo::is_construct_call_
5514 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5515 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5516 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5519 ExternalReference thunk_ref =
5520 ExternalReference::invoke_function_callback(masm->isolate());
5522 AllowExternalCallThatCantCauseGC scope(masm);
5523 MemOperand context_restore_operand(
5524 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5525 // Stores return the first js argument
5526 int return_value_offset = 0;
5527 if (return_first_arg) {
5528 return_value_offset = 2 + FCA::kArgsLength;
5530 return_value_offset = 2 + FCA::kReturnValueOffset;
5532 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5533 int stack_space = 0;
5534 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5535 MemOperand* stack_space_operand = &is_construct_call_operand;
5536 if (argc.is_immediate()) {
5537 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5538 stack_space_operand = NULL;
5540 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5541 stack_space_operand, return_value_operand,
5542 &context_restore_operand);
5546 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5547 bool call_data_undefined = this->call_data_undefined();
5548 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
5549 call_data_undefined);
5553 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5554 bool is_store = this->is_store();
5555 int argc = this->argc();
5556 bool call_data_undefined = this->call_data_undefined();
5557 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5558 call_data_undefined);
5562 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5563 // ----------- S t a t e -------------
5565 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5567 // -- r2 : api_function_address
5568 // -----------------------------------
5570 Register api_function_address = ApiGetterDescriptor::function_address();
5571 DCHECK(api_function_address.is(r2));
5573 __ mov(r0, sp); // r0 = Handle<Name>
5574 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
5576 const int kApiStackSpace = 1;
5577 FrameScope frame_scope(masm, StackFrame::MANUAL);
5578 __ EnterExitFrame(false, kApiStackSpace);
5580 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5581 // r1 (internal::Object** args_) as the data.
5582 __ str(r1, MemOperand(sp, 1 * kPointerSize));
5583 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
5585 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5587 ExternalReference thunk_ref =
5588 ExternalReference::invoke_accessor_getter_callback(isolate());
5589 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5590 kStackUnwindSpace, NULL,
5591 MemOperand(fp, 6 * kPointerSize), NULL);
5597 } // namespace internal
5600 #endif // V8_TARGET_ARCH_ARM