1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "src/base/bits.h"
8 #include "src/bootstrapper.h"
9 #include "src/code-stubs.h"
10 #include "src/codegen.h"
11 #include "src/ic/handler-compiler.h"
12 #include "src/ic/ic.h"
13 #include "src/ic/stub-cache.h"
14 #include "src/isolate.h"
15 #include "src/regexp/jsregexp.h"
16 #include "src/regexp/regexp-macro-assembler.h"
17 #include "src/runtime/runtime.h"
19 #include "src/arm/code-stubs-arm.h"
25 static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
28 Address deopt_handler = Runtime::FunctionForId(
29 Runtime::kArrayConstructor)->entry;
31 if (constant_stack_parameter_count == 0) {
32 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
33 JS_FUNCTION_STUB_MODE);
35 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
36 JS_FUNCTION_STUB_MODE);
41 static void InitializeInternalArrayConstructorDescriptor(
42 Isolate* isolate, CodeStubDescriptor* descriptor,
43 int constant_stack_parameter_count) {
44 Address deopt_handler = Runtime::FunctionForId(
45 Runtime::kInternalArrayConstructor)->entry;
47 if (constant_stack_parameter_count == 0) {
48 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
49 JS_FUNCTION_STUB_MODE);
51 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
52 JS_FUNCTION_STUB_MODE);
57 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
63 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
64 CodeStubDescriptor* descriptor) {
65 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
69 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
70 CodeStubDescriptor* descriptor) {
71 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
75 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
76 CodeStubDescriptor* descriptor) {
77 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
81 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
82 CodeStubDescriptor* descriptor) {
83 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
87 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
88 CodeStubDescriptor* descriptor) {
89 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
93 #define __ ACCESS_MASM(masm)
96 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
97 Condition cond, Strength strength);
98 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
104 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
109 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
110 ExternalReference miss) {
111 // Update the static counter each time a new code stub is generated.
112 isolate()->counters()->code_stubs()->Increment();
114 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
115 int param_count = descriptor.GetRegisterParameterCount();
117 // Call the runtime system in a fresh internal frame.
118 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
119 DCHECK(param_count == 0 ||
120 r0.is(descriptor.GetRegisterParameter(param_count - 1)));
122 for (int i = 0; i < param_count; ++i) {
123 __ push(descriptor.GetRegisterParameter(i));
125 __ CallExternalReference(miss, param_count);
132 void DoubleToIStub::Generate(MacroAssembler* masm) {
133 Label out_of_range, only_low, negate, done;
134 Register input_reg = source();
135 Register result_reg = destination();
136 DCHECK(is_truncating());
138 int double_offset = offset();
139 // Account for saved regs if input is sp.
140 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
142 Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
143 Register scratch_low =
144 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
145 Register scratch_high =
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
147 LowDwVfpRegister double_scratch = kScratchDoubleReg;
149 __ Push(scratch_high, scratch_low, scratch);
151 if (!skip_fastpath()) {
152 // Load double input.
153 __ vldr(double_scratch, MemOperand(input_reg, double_offset));
154 __ vmov(scratch_low, scratch_high, double_scratch);
156 // Do fast-path convert from double to int.
157 __ vcvt_s32_f64(double_scratch.low(), double_scratch);
158 __ vmov(result_reg, double_scratch.low());
160 // If result is not saturated (0x7fffffff or 0x80000000), we are done.
161 __ sub(scratch, result_reg, Operand(1));
162 __ cmp(scratch, Operand(0x7ffffffe));
165 // We've already done MacroAssembler::TryFastTruncatedDoubleToILoad, so we
166 // know exponent > 31, so we can skip the vcvt_s32_f64 which will saturate.
167 if (double_offset == 0) {
168 __ ldm(ia, input_reg, scratch_low.bit() | scratch_high.bit());
170 __ ldr(scratch_low, MemOperand(input_reg, double_offset));
171 __ ldr(scratch_high, MemOperand(input_reg, double_offset + kIntSize));
175 __ Ubfx(scratch, scratch_high,
176 HeapNumber::kExponentShift, HeapNumber::kExponentBits);
177 // Load scratch with exponent - 1. This is faster than loading
178 // with exponent because Bias + 1 = 1024 which is an *ARM* immediate value.
179 STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
180 __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
181 // If exponent is greater than or equal to 84, the 32 less significant
182 // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
184 // Compare exponent with 84 (compare exponent - 1 with 83).
185 __ cmp(scratch, Operand(83));
186 __ b(ge, &out_of_range);
188 // If we reach this code, 31 <= exponent <= 83.
189 // So, we don't have to handle cases where 0 <= exponent <= 20 for
190 // which we would need to shift right the high part of the mantissa.
191 // Scratch contains exponent - 1.
192 // Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
193 __ rsb(scratch, scratch, Operand(51), SetCC);
195 // 21 <= exponent <= 51, shift scratch_low and scratch_high
196 // to generate the result.
197 __ mov(scratch_low, Operand(scratch_low, LSR, scratch));
198 // Scratch contains: 52 - exponent.
199 // We needs: exponent - 20.
200 // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
201 __ rsb(scratch, scratch, Operand(32));
202 __ Ubfx(result_reg, scratch_high,
203 0, HeapNumber::kMantissaBitsInTopWord);
204 // Set the implicit 1 before the mantissa part in scratch_high.
205 __ orr(result_reg, result_reg,
206 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
207 __ orr(result_reg, scratch_low, Operand(result_reg, LSL, scratch));
210 __ bind(&out_of_range);
211 __ mov(result_reg, Operand::Zero());
215 // 52 <= exponent <= 83, shift only scratch_low.
216 // On entry, scratch contains: 52 - exponent.
217 __ rsb(scratch, scratch, Operand::Zero());
218 __ mov(result_reg, Operand(scratch_low, LSL, scratch));
221 // If input was positive, scratch_high ASR 31 equals 0 and
222 // scratch_high LSR 31 equals zero.
223 // New result = (result eor 0) + 0 = result.
224 // If the input was negative, we have to negate the result.
225 // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
226 // New result = (result eor 0xffffffff) + 1 = 0 - result.
227 __ eor(result_reg, result_reg, Operand(scratch_high, ASR, 31));
228 __ add(result_reg, result_reg, Operand(scratch_high, LSR, 31));
232 __ Pop(scratch_high, scratch_low, scratch);
237 // Handle the case where the lhs and rhs are the same object.
238 // Equality is almost reflexive (everything but NaN), so this is a test
239 // for "identity and not NaN".
240 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
241 Condition cond, Strength strength) {
243 Label heap_number, return_equal;
245 __ b(ne, ¬_identical);
247 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
248 // so we do the second best thing - test it ourselves.
249 // They are both equal and they are not both Smis so both of them are not
250 // Smis. If it's not a heap number, then return equal.
251 if (cond == lt || cond == gt) {
252 // Call runtime on identical JSObjects.
253 __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE);
255 // Call runtime on identical symbols since we need to throw a TypeError.
256 __ cmp(r4, Operand(SYMBOL_TYPE));
258 // Call runtime on identical SIMD values since we must throw a TypeError.
259 __ cmp(r4, Operand(SIMD128_VALUE_TYPE));
261 if (is_strong(strength)) {
262 // Call the runtime on anything that is converted in the semantics, since
263 // we need to throw a TypeError. Smis have already been ruled out.
264 __ cmp(r4, Operand(HEAP_NUMBER_TYPE));
265 __ b(eq, &return_equal);
266 __ tst(r4, Operand(kIsNotStringMask));
270 __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE);
271 __ b(eq, &heap_number);
272 // Comparing JS objects with <=, >= is complicated.
274 __ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE));
276 // Call runtime on identical symbols since we need to throw a TypeError.
277 __ cmp(r4, Operand(SYMBOL_TYPE));
279 // Call runtime on identical SIMD values since we must throw a TypeError.
280 __ cmp(r4, Operand(SIMD128_VALUE_TYPE));
282 if (is_strong(strength)) {
283 // Call the runtime on anything that is converted in the semantics,
284 // since we need to throw a TypeError. Smis and heap numbers have
285 // already been ruled out.
286 __ tst(r4, Operand(kIsNotStringMask));
289 // Normally here we fall through to return_equal, but undefined is
290 // special: (undefined == undefined) == true, but
291 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
292 if (cond == le || cond == ge) {
293 __ cmp(r4, Operand(ODDBALL_TYPE));
294 __ b(ne, &return_equal);
295 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
297 __ b(ne, &return_equal);
299 // undefined <= undefined should fail.
300 __ mov(r0, Operand(GREATER));
302 // undefined >= undefined should fail.
303 __ mov(r0, Operand(LESS));
310 __ bind(&return_equal);
312 __ mov(r0, Operand(GREATER)); // Things aren't less than themselves.
313 } else if (cond == gt) {
314 __ mov(r0, Operand(LESS)); // Things aren't greater than themselves.
316 __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
320 // For less and greater we don't have to check for NaN since the result of
321 // x < x is false regardless. For the others here is some code to check
323 if (cond != lt && cond != gt) {
324 __ bind(&heap_number);
325 // It is a heap number, so return non-equal if it's NaN and equal if it's
328 // The representation of NaN values has all exponent bits (52..62) set,
329 // and not all mantissa bits (0..51) clear.
330 // Read top bits of double representation (second word of value).
331 __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
332 // Test that exponent bits are all set.
333 __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits);
334 // NaNs have all-one exponents so they sign extend to -1.
335 __ cmp(r3, Operand(-1));
336 __ b(ne, &return_equal);
338 // Shift out flag and all exponent bits, retaining only mantissa.
339 __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord));
340 // Or with all low-bits of mantissa.
341 __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
342 __ orr(r0, r3, Operand(r2), SetCC);
343 // For equal we already have the right value in r0: Return zero (equal)
344 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
345 // not (it's a NaN). For <= and >= we need to load r0 with the failing
346 // value if it's a NaN.
348 // All-zero means Infinity means equal.
351 __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail.
353 __ mov(r0, Operand(LESS)); // NaN >= NaN should fail.
358 // No fall through here.
360 __ bind(¬_identical);
364 // See comment at call site.
365 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
371 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
372 (lhs.is(r1) && rhs.is(r0)));
375 __ JumpIfSmi(rhs, &rhs_is_smi);
377 // Lhs is a Smi. Check whether the rhs is a heap number.
378 __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE);
380 // If rhs is not a number and lhs is a Smi then strict equality cannot
381 // succeed. Return non-equal
382 // If rhs is r0 then there is already a non zero value in it.
384 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
388 // Smi compared non-strictly with a non-Smi non-heap-number. Call
393 // Lhs is a smi, rhs is a number.
394 // Convert lhs to a double in d7.
395 __ SmiToDouble(d7, lhs);
396 // Load the double from rhs, tagged HeapNumber r0, to d6.
397 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
399 // We now have both loaded as doubles but we can skip the lhs nan check
403 __ bind(&rhs_is_smi);
404 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
405 __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE);
407 // If lhs is not a number and rhs is a smi then strict equality cannot
408 // succeed. Return non-equal.
409 // If lhs is r0 then there is already a non zero value in it.
411 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
415 // Smi compared non-strictly with a non-smi non-heap-number. Call
420 // Rhs is a smi, lhs is a heap number.
421 // Load the double from lhs, tagged HeapNumber r1, to d7.
422 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
423 // Convert rhs to a double in d6 .
424 __ SmiToDouble(d6, rhs);
425 // Fall through to both_loaded_as_doubles.
429 // See comment at call site.
430 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
433 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
434 (lhs.is(r1) && rhs.is(r0)));
436 // If either operand is a JS object or an oddball value, then they are
437 // not equal since their pointers are different.
438 // There is no test for undetectability in strict equality.
439 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
440 Label first_non_object;
441 // Get the type of the first operand into r2 and compare it with
442 // FIRST_SPEC_OBJECT_TYPE.
443 __ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE);
444 __ b(lt, &first_non_object);
446 // Return non-zero (r0 is not zero)
447 Label return_not_equal;
448 __ bind(&return_not_equal);
451 __ bind(&first_non_object);
452 // Check for oddballs: true, false, null, undefined.
453 __ cmp(r2, Operand(ODDBALL_TYPE));
454 __ b(eq, &return_not_equal);
456 __ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE);
457 __ b(ge, &return_not_equal);
459 // Check for oddballs: true, false, null, undefined.
460 __ cmp(r3, Operand(ODDBALL_TYPE));
461 __ b(eq, &return_not_equal);
463 // Now that we have the types we might as well check for
464 // internalized-internalized.
465 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
466 __ orr(r2, r2, Operand(r3));
467 __ tst(r2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
468 __ b(eq, &return_not_equal);
472 // See comment at call site.
473 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
476 Label* both_loaded_as_doubles,
477 Label* not_heap_numbers,
479 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
480 (lhs.is(r1) && rhs.is(r0)));
482 __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE);
483 __ b(ne, not_heap_numbers);
484 __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset));
486 __ b(ne, slow); // First was a heap number, second wasn't. Go slow case.
488 // Both are heap numbers. Load them up then jump to the code we have
490 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
491 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
492 __ jmp(both_loaded_as_doubles);
496 // Fast negative check for internalized-to-internalized equality.
497 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
500 Label* possible_strings,
501 Label* not_both_strings) {
502 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
503 (lhs.is(r1) && rhs.is(r0)));
505 // r2 is object type of rhs.
507 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
508 __ tst(r2, Operand(kIsNotStringMask));
509 __ b(ne, &object_test);
510 __ tst(r2, Operand(kIsNotInternalizedMask));
511 __ b(ne, possible_strings);
512 __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE);
513 __ b(ge, not_both_strings);
514 __ tst(r3, Operand(kIsNotInternalizedMask));
515 __ b(ne, possible_strings);
517 // Both are internalized. We already checked they weren't the same pointer
518 // so they are not equal.
519 __ mov(r0, Operand(NOT_EQUAL));
522 __ bind(&object_test);
523 __ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE));
524 __ b(lt, not_both_strings);
525 __ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE);
526 __ b(lt, not_both_strings);
527 // If both objects are undetectable, they are equal. Otherwise, they
528 // are not equal, since they are different objects and an object is not
529 // equal to undefined.
530 __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset));
531 __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset));
532 __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset));
533 __ and_(r0, r2, Operand(r3));
534 __ and_(r0, r0, Operand(1 << Map::kIsUndetectable));
535 __ eor(r0, r0, Operand(1 << Map::kIsUndetectable));
540 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
542 CompareICState::State expected,
545 if (expected == CompareICState::SMI) {
546 __ JumpIfNotSmi(input, fail);
547 } else if (expected == CompareICState::NUMBER) {
548 __ JumpIfSmi(input, &ok);
549 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
552 // We could be strict about internalized/non-internalized here, but as long as
553 // hydrogen doesn't care, the stub doesn't have to care either.
558 // On entry r1 and r2 are the values to be compared.
559 // On exit r0 is 0, positive or negative to indicate the result of
561 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
564 Condition cc = GetCondition();
567 CompareICStub_CheckInputType(masm, lhs, r2, left(), &miss);
568 CompareICStub_CheckInputType(masm, rhs, r3, right(), &miss);
570 Label slow; // Call builtin.
571 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
573 Label not_two_smis, smi_done;
575 __ JumpIfNotSmi(r2, ¬_two_smis);
576 __ mov(r1, Operand(r1, ASR, 1));
577 __ sub(r0, r1, Operand(r0, ASR, 1));
579 __ bind(¬_two_smis);
581 // NOTICE! This code is only reached after a smi-fast-case check, so
582 // it is certain that at least one operand isn't a smi.
584 // Handle the case where the objects are identical. Either returns the answer
585 // or goes to slow. Only falls through if the objects were not identical.
586 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
588 // If either is a Smi (we know that not both are), then they can only
589 // be strictly equal if the other is a HeapNumber.
590 STATIC_ASSERT(kSmiTag == 0);
591 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
592 __ and_(r2, lhs, Operand(rhs));
593 __ JumpIfNotSmi(r2, ¬_smis);
594 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
595 // 1) Return the answer.
597 // 3) Fall through to both_loaded_as_doubles.
598 // 4) Jump to lhs_not_nan.
599 // In cases 3 and 4 we have found out we were dealing with a number-number
600 // comparison. If VFP3 is supported the double values of the numbers have
601 // been loaded into d7 and d6. Otherwise, the double values have been loaded
602 // into r0, r1, r2, and r3.
603 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
605 __ bind(&both_loaded_as_doubles);
606 // The arguments have been converted to doubles and stored in d6 and d7, if
607 // VFP3 is supported, or in r0, r1, r2, and r3.
608 __ bind(&lhs_not_nan);
610 // ARMv7 VFP3 instructions to implement double precision comparison.
611 __ VFPCompareAndSetFlags(d7, d6);
614 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
615 __ mov(r0, Operand(LESS), LeaveCC, lt);
616 __ mov(r0, Operand(GREATER), LeaveCC, gt);
620 // If one of the sides was a NaN then the v flag is set. Load r0 with
621 // whatever it takes to make the comparison fail, since comparisons with NaN
623 if (cc == lt || cc == le) {
624 __ mov(r0, Operand(GREATER));
626 __ mov(r0, Operand(LESS));
631 // At this point we know we are dealing with two different objects,
632 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
634 // This returns non-equal for some object types, or falls through if it
636 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
639 Label check_for_internalized_strings;
640 Label flat_string_check;
641 // Check for heap-number-heap-number comparison. Can jump to slow case,
642 // or load both doubles into r0, r1, r2, r3 and jump to the code that handles
643 // that case. If the inputs are not doubles then jumps to
644 // check_for_internalized_strings.
645 // In this case r2 will contain the type of rhs_. Never falls through.
646 EmitCheckForTwoHeapNumbers(masm,
649 &both_loaded_as_doubles,
650 &check_for_internalized_strings,
653 __ bind(&check_for_internalized_strings);
654 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
655 // internalized strings.
656 if (cc == eq && !strict()) {
657 // Returns an answer for two internalized strings or two detectable objects.
658 // Otherwise jumps to string case or not both strings case.
659 // Assumes that r2 is the type of rhs_ on entry.
660 EmitCheckForInternalizedStringsOrObjects(
661 masm, lhs, rhs, &flat_string_check, &slow);
664 // Check for both being sequential one-byte strings,
665 // and inline if that is the case.
666 __ bind(&flat_string_check);
668 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r2, r3, &slow);
670 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
673 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r2, r3, r4);
675 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r2, r3, r4,
678 // Never falls through to here.
683 // Figure out which native to call and setup the arguments.
685 __ TailCallRuntime(strict() ? Runtime::kStrictEquals : Runtime::kEquals, 2,
688 int ncr; // NaN compare result
689 if (cc == lt || cc == le) {
692 DCHECK(cc == gt || cc == ge); // remaining cases
695 __ mov(r0, Operand(Smi::FromInt(ncr)));
698 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
699 // tagged as a small integer.
701 is_strong(strength()) ? Runtime::kCompare_Strong : Runtime::kCompare, 3,
710 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
711 // We don't allow a GC during a store buffer overflow so there is no need to
712 // store the registers in any particular way, but we do have to store and
714 __ stm(db_w, sp, kCallerSaved | lr.bit());
716 const Register scratch = r1;
718 if (save_doubles()) {
719 __ SaveFPRegs(sp, scratch);
721 const int argument_count = 1;
722 const int fp_argument_count = 0;
724 AllowExternalCallThatCantCauseGC scope(masm);
725 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
726 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
728 ExternalReference::store_buffer_overflow_function(isolate()),
730 if (save_doubles()) {
731 __ RestoreFPRegs(sp, scratch);
733 __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0).
737 void MathPowStub::Generate(MacroAssembler* masm) {
738 const Register base = r1;
739 const Register exponent = MathPowTaggedDescriptor::exponent();
740 DCHECK(exponent.is(r2));
741 const Register heapnumbermap = r5;
742 const Register heapnumber = r0;
743 const DwVfpRegister double_base = d0;
744 const DwVfpRegister double_exponent = d1;
745 const DwVfpRegister double_result = d2;
746 const DwVfpRegister double_scratch = d3;
747 const SwVfpRegister single_scratch = s6;
748 const Register scratch = r9;
749 const Register scratch2 = r4;
751 Label call_runtime, done, int_exponent;
752 if (exponent_type() == ON_STACK) {
753 Label base_is_smi, unpack_exponent;
754 // The exponent and base are supplied as arguments on the stack.
755 // This can only happen if the stub is called from non-optimized code.
756 // Load input parameters from stack to double registers.
757 __ ldr(base, MemOperand(sp, 1 * kPointerSize));
758 __ ldr(exponent, MemOperand(sp, 0 * kPointerSize));
760 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
762 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
763 __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset));
764 __ cmp(scratch, heapnumbermap);
765 __ b(ne, &call_runtime);
767 __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
768 __ jmp(&unpack_exponent);
770 __ bind(&base_is_smi);
771 __ vmov(single_scratch, scratch);
772 __ vcvt_f64_s32(double_base, single_scratch);
773 __ bind(&unpack_exponent);
775 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
777 __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
778 __ cmp(scratch, heapnumbermap);
779 __ b(ne, &call_runtime);
780 __ vldr(double_exponent,
781 FieldMemOperand(exponent, HeapNumber::kValueOffset));
782 } else if (exponent_type() == TAGGED) {
783 // Base is already in double_base.
784 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
786 __ vldr(double_exponent,
787 FieldMemOperand(exponent, HeapNumber::kValueOffset));
790 if (exponent_type() != INTEGER) {
791 Label int_exponent_convert;
792 // Detect integer exponents stored as double.
793 __ vcvt_u32_f64(single_scratch, double_exponent);
794 // We do not check for NaN or Infinity here because comparing numbers on
795 // ARM correctly distinguishes NaNs. We end up calling the built-in.
796 __ vcvt_f64_u32(double_scratch, single_scratch);
797 __ VFPCompareAndSetFlags(double_scratch, double_exponent);
798 __ b(eq, &int_exponent_convert);
800 if (exponent_type() == ON_STACK) {
801 // Detect square root case. Crankshaft detects constant +/-0.5 at
802 // compile time and uses DoMathPowHalf instead. We then skip this check
803 // for non-constant cases of +/-0.5 as these hardly occur.
807 __ vmov(double_scratch, 0.5, scratch);
808 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
809 __ b(ne, ¬_plus_half);
811 // Calculates square root of base. Check for the special case of
812 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
813 __ vmov(double_scratch, -V8_INFINITY, scratch);
814 __ VFPCompareAndSetFlags(double_base, double_scratch);
815 __ vneg(double_result, double_scratch, eq);
818 // Add +0 to convert -0 to +0.
819 __ vadd(double_scratch, double_base, kDoubleRegZero);
820 __ vsqrt(double_result, double_scratch);
823 __ bind(¬_plus_half);
824 __ vmov(double_scratch, -0.5, scratch);
825 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
826 __ b(ne, &call_runtime);
828 // Calculates square root of base. Check for the special case of
829 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
830 __ vmov(double_scratch, -V8_INFINITY, scratch);
831 __ VFPCompareAndSetFlags(double_base, double_scratch);
832 __ vmov(double_result, kDoubleRegZero, eq);
835 // Add +0 to convert -0 to +0.
836 __ vadd(double_scratch, double_base, kDoubleRegZero);
837 __ vmov(double_result, 1.0, scratch);
838 __ vsqrt(double_scratch, double_scratch);
839 __ vdiv(double_result, double_result, double_scratch);
845 AllowExternalCallThatCantCauseGC scope(masm);
846 __ PrepareCallCFunction(0, 2, scratch);
847 __ MovToFloatParameters(double_base, double_exponent);
849 ExternalReference::power_double_double_function(isolate()),
853 __ MovFromFloatResult(double_result);
856 __ bind(&int_exponent_convert);
857 __ vcvt_u32_f64(single_scratch, double_exponent);
858 __ vmov(scratch, single_scratch);
861 // Calculate power with integer exponent.
862 __ bind(&int_exponent);
864 // Get two copies of exponent in the registers scratch and exponent.
865 if (exponent_type() == INTEGER) {
866 __ mov(scratch, exponent);
868 // Exponent has previously been stored into scratch as untagged integer.
869 __ mov(exponent, scratch);
871 __ vmov(double_scratch, double_base); // Back up base.
872 __ vmov(double_result, 1.0, scratch2);
874 // Get absolute value of exponent.
875 __ cmp(scratch, Operand::Zero());
876 __ mov(scratch2, Operand::Zero(), LeaveCC, mi);
877 __ sub(scratch, scratch2, scratch, LeaveCC, mi);
880 __ bind(&while_true);
881 __ mov(scratch, Operand(scratch, ASR, 1), SetCC);
882 __ vmul(double_result, double_result, double_scratch, cs);
883 __ vmul(double_scratch, double_scratch, double_scratch, ne);
884 __ b(ne, &while_true);
886 __ cmp(exponent, Operand::Zero());
888 __ vmov(double_scratch, 1.0, scratch);
889 __ vdiv(double_result, double_scratch, double_result);
890 // Test whether result is zero. Bail out to check for subnormal result.
891 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
892 __ VFPCompareAndSetFlags(double_result, 0.0);
894 // double_exponent may not containe the exponent value if the input was a
895 // smi. We set it with exponent value before bailing out.
896 __ vmov(single_scratch, exponent);
897 __ vcvt_f64_s32(double_exponent, single_scratch);
899 // Returning or bailing out.
900 Counters* counters = isolate()->counters();
901 if (exponent_type() == ON_STACK) {
902 // The arguments are still on the stack.
903 __ bind(&call_runtime);
904 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
906 // The stub is called from non-optimized code, which expects the result
907 // as heap number in exponent.
909 __ AllocateHeapNumber(
910 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
911 __ vstr(double_result,
912 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
913 DCHECK(heapnumber.is(r0));
914 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
919 AllowExternalCallThatCantCauseGC scope(masm);
920 __ PrepareCallCFunction(0, 2, scratch);
921 __ MovToFloatParameters(double_base, double_exponent);
923 ExternalReference::power_double_double_function(isolate()),
927 __ MovFromFloatResult(double_result);
930 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
936 bool CEntryStub::NeedsImmovableCode() {
941 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
942 CEntryStub::GenerateAheadOfTime(isolate);
943 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
944 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
945 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
946 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
947 CreateWeakCellStub::GenerateAheadOfTime(isolate);
948 BinaryOpICStub::GenerateAheadOfTime(isolate);
949 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
950 StoreFastElementStub::GenerateAheadOfTime(isolate);
951 TypeofStub::GenerateAheadOfTime(isolate);
955 void CodeStub::GenerateFPStubs(Isolate* isolate) {
956 // Generate if not already in cache.
957 SaveFPRegsMode mode = kSaveFPRegs;
958 CEntryStub(isolate, 1, mode).GetCode();
959 StoreBufferOverflowStub(isolate, mode).GetCode();
960 isolate->set_fp_stubs_generated(true);
964 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
965 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
970 void CEntryStub::Generate(MacroAssembler* masm) {
971 // Called from JavaScript; parameters are on stack as if calling JS function.
972 // r0: number of arguments including receiver
973 // r1: pointer to builtin function
974 // fp: frame pointer (restored after C call)
975 // sp: stack pointer (restored as callee's sp after C call)
976 // cp: current context (C callee-saved)
978 ProfileEntryHookStub::MaybeCallEntryHook(masm);
980 __ mov(r5, Operand(r1));
982 // Compute the argv pointer in a callee-saved register.
983 __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2));
984 __ sub(r1, r1, Operand(kPointerSize));
986 // Enter the exit frame that transitions from JavaScript to C++.
987 FrameScope scope(masm, StackFrame::MANUAL);
988 __ EnterExitFrame(save_doubles());
990 // Store a copy of argc in callee-saved registers for later.
991 __ mov(r4, Operand(r0));
993 // r0, r4: number of arguments including receiver (C callee-saved)
994 // r1: pointer to the first argument (C callee-saved)
995 // r5: pointer to builtin function (C callee-saved)
997 // Result returned in r0 or r0+r1 by default.
1000 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
1001 int frame_alignment_mask = frame_alignment - 1;
1002 if (FLAG_debug_code) {
1003 if (frame_alignment > kPointerSize) {
1004 Label alignment_as_expected;
1005 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
1006 __ tst(sp, Operand(frame_alignment_mask));
1007 __ b(eq, &alignment_as_expected);
1008 // Don't use Check here, as it will call Runtime_Abort re-entering here.
1009 __ stop("Unexpected alignment");
1010 __ bind(&alignment_as_expected);
1016 // r0 = argc, r1 = argv
1017 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1019 // To let the GC traverse the return address of the exit frames, we need to
1020 // know where the return address is. The CEntryStub is unmovable, so
1021 // we can store the address on the stack to be able to find it again and
1022 // we never have to restore it, because it will not change.
1023 // Compute the return address in lr to return to after the jump below. Pc is
1024 // already at '+ 8' from the current instruction but return is after three
1025 // instructions so add another 4 to pc to get the return address.
1027 // Prevent literal pool emission before return address.
1028 Assembler::BlockConstPoolScope block_const_pool(masm);
1029 __ add(lr, pc, Operand(4));
1030 __ str(lr, MemOperand(sp, 0));
1034 __ VFPEnsureFPSCRState(r2);
1036 // Check result for exception sentinel.
1037 Label exception_returned;
1038 __ CompareRoot(r0, Heap::kExceptionRootIndex);
1039 __ b(eq, &exception_returned);
1041 // Check that there is no pending exception, otherwise we
1042 // should have returned the exception sentinel.
1043 if (FLAG_debug_code) {
1045 ExternalReference pending_exception_address(
1046 Isolate::kPendingExceptionAddress, isolate());
1047 __ mov(r2, Operand(pending_exception_address));
1048 __ ldr(r2, MemOperand(r2));
1049 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex);
1050 // Cannot use check here as it attempts to generate call into runtime.
1052 __ stop("Unexpected pending exception");
1056 // Exit C frame and return.
1058 // sp: stack pointer
1059 // fp: frame pointer
1060 // Callee-saved register r4 still holds argc.
1061 __ LeaveExitFrame(save_doubles(), r4, true);
1064 // Handling of exception.
1065 __ bind(&exception_returned);
1067 ExternalReference pending_handler_context_address(
1068 Isolate::kPendingHandlerContextAddress, isolate());
1069 ExternalReference pending_handler_code_address(
1070 Isolate::kPendingHandlerCodeAddress, isolate());
1071 ExternalReference pending_handler_offset_address(
1072 Isolate::kPendingHandlerOffsetAddress, isolate());
1073 ExternalReference pending_handler_fp_address(
1074 Isolate::kPendingHandlerFPAddress, isolate());
1075 ExternalReference pending_handler_sp_address(
1076 Isolate::kPendingHandlerSPAddress, isolate());
1078 // Ask the runtime for help to determine the handler. This will set r0 to
1079 // contain the current pending exception, don't clobber it.
1080 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1083 FrameScope scope(masm, StackFrame::MANUAL);
1084 __ PrepareCallCFunction(3, 0, r0);
1085 __ mov(r0, Operand(0));
1086 __ mov(r1, Operand(0));
1087 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1088 __ CallCFunction(find_handler, 3);
1091 // Retrieve the handler context, SP and FP.
1092 __ mov(cp, Operand(pending_handler_context_address));
1093 __ ldr(cp, MemOperand(cp));
1094 __ mov(sp, Operand(pending_handler_sp_address));
1095 __ ldr(sp, MemOperand(sp));
1096 __ mov(fp, Operand(pending_handler_fp_address));
1097 __ ldr(fp, MemOperand(fp));
1099 // If the handler is a JS frame, restore the context to the frame. Note that
1100 // the context will be set to (cp == 0) for non-JS frames.
1101 __ cmp(cp, Operand(0));
1102 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne);
1104 // Compute the handler entry address and jump to it.
1105 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1106 __ mov(r1, Operand(pending_handler_code_address));
1107 __ ldr(r1, MemOperand(r1));
1108 __ mov(r2, Operand(pending_handler_offset_address));
1109 __ ldr(r2, MemOperand(r2));
1110 __ add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1111 if (FLAG_enable_embedded_constant_pool) {
1112 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r1);
1118 void JSEntryStub::Generate(MacroAssembler* masm) {
1125 Label invoke, handler_entry, exit;
1127 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1129 // Called from C, so do not pop argc and args on exit (preserve sp)
1130 // No need to save register-passed args
1131 // Save callee-saved registers (incl. cp and fp), sp, and lr
1132 __ stm(db_w, sp, kCalleeSaved | lr.bit());
1134 // Save callee-saved vfp registers.
1135 __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1136 // Set up the reserved register for 0.0.
1137 __ vmov(kDoubleRegZero, 0.0);
1138 __ VFPEnsureFPSCRState(r4);
1140 // Get address of argv, see stm above.
1146 // Set up argv in r4.
1147 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1148 offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize;
1149 __ ldr(r4, MemOperand(sp, offset_to_argv));
1151 // Push a frame with special values setup to mark it as an entry frame.
1157 int marker = type();
1158 if (FLAG_enable_embedded_constant_pool) {
1159 __ mov(r8, Operand::Zero());
1161 __ mov(r7, Operand(Smi::FromInt(marker)));
1162 __ mov(r6, Operand(Smi::FromInt(marker)));
1164 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1165 __ ldr(r5, MemOperand(r5));
1166 __ mov(ip, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1167 __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() |
1168 (FLAG_enable_embedded_constant_pool ? r8.bit() : 0) |
1171 // Set up frame pointer for the frame to be pushed.
1172 __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1174 // If this is the outermost JS call, set js_entry_sp value.
1175 Label non_outermost_js;
1176 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1177 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1178 __ ldr(r6, MemOperand(r5));
1179 __ cmp(r6, Operand::Zero());
1180 __ b(ne, &non_outermost_js);
1181 __ str(fp, MemOperand(r5));
1182 __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1185 __ bind(&non_outermost_js);
1186 __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1190 // Jump to a faked try block that does the invoke, with a faked catch
1191 // block that sets the pending exception.
1194 // Block literal pool emission whilst taking the position of the handler
1195 // entry. This avoids making the assumption that literal pools are always
1196 // emitted after an instruction is emitted, rather than before.
1198 Assembler::BlockConstPoolScope block_const_pool(masm);
1199 __ bind(&handler_entry);
1200 handler_offset_ = handler_entry.pos();
1201 // Caught exception: Store result (exception) in the pending exception
1202 // field in the JSEnv and return a failure sentinel. Coming in here the
1203 // fp will be invalid because the PushStackHandler below sets it to 0 to
1204 // signal the existence of the JSEntry frame.
1205 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1208 __ str(r0, MemOperand(ip));
1209 __ LoadRoot(r0, Heap::kExceptionRootIndex);
1212 // Invoke: Link this frame into the handler chain.
1214 // Must preserve r0-r4, r5-r6 are available.
1215 __ PushStackHandler();
1216 // If an exception not caught by another handler occurs, this handler
1217 // returns control to the code after the bl(&invoke) above, which
1218 // restores all kCalleeSaved registers (including cp and fp) to their
1219 // saved values before returning a failure to C.
1221 // Clear any pending exceptions.
1222 __ mov(r5, Operand(isolate()->factory()->the_hole_value()));
1223 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1225 __ str(r5, MemOperand(ip));
1227 // Invoke the function by calling through JS entry trampoline builtin.
1228 // Notice that we cannot store a reference to the trampoline code directly in
1229 // this stub, because runtime stubs are not traversed when doing GC.
1231 // Expected registers by Builtins::JSEntryTrampoline
1237 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1238 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1240 __ mov(ip, Operand(construct_entry));
1242 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
1243 __ mov(ip, Operand(entry));
1245 __ ldr(ip, MemOperand(ip)); // deref address
1246 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1248 // Branch and link to JSEntryTrampoline.
1251 // Unlink this frame from the handler chain.
1252 __ PopStackHandler();
1254 __ bind(&exit); // r0 holds result
1255 // Check if the current stack frame is marked as the outermost JS frame.
1256 Label non_outermost_js_2;
1258 __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1259 __ b(ne, &non_outermost_js_2);
1260 __ mov(r6, Operand::Zero());
1261 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1262 __ str(r6, MemOperand(r5));
1263 __ bind(&non_outermost_js_2);
1265 // Restore the top frame descriptors from the stack.
1268 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1269 __ str(r3, MemOperand(ip));
1271 // Reset the stack to the callee saved registers.
1272 __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1274 // Restore callee-saved registers and return.
1276 if (FLAG_debug_code) {
1277 __ mov(lr, Operand(pc));
1281 // Restore callee-saved vfp registers.
1282 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1284 __ ldm(ia_w, sp, kCalleeSaved | pc.bit());
1288 void InstanceOfStub::Generate(MacroAssembler* masm) {
1289 Register const object = r1; // Object (lhs).
1290 Register const function = r0; // Function (rhs).
1291 Register const object_map = r2; // Map of {object}.
1292 Register const function_map = r3; // Map of {function}.
1293 Register const function_prototype = r4; // Prototype of {function}.
1294 Register const scratch = r5;
1296 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1297 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1299 // Check if {object} is a smi.
1300 Label object_is_smi;
1301 __ JumpIfSmi(object, &object_is_smi);
1303 // Lookup the {function} and the {object} map in the global instanceof cache.
1304 // Note: This is safe because we clear the global instanceof cache whenever
1305 // we change the prototype of any object.
1306 Label fast_case, slow_case;
1307 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1308 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1309 __ b(ne, &fast_case);
1310 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1311 __ b(ne, &fast_case);
1312 __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1315 // If {object} is a smi we can safely return false if {function} is a JS
1316 // function, otherwise we have to miss to the runtime and throw an exception.
1317 __ bind(&object_is_smi);
1318 __ JumpIfSmi(function, &slow_case);
1319 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1320 __ b(ne, &slow_case);
1321 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1324 // Fast-case: The {function} must be a valid JSFunction.
1325 __ bind(&fast_case);
1326 __ JumpIfSmi(function, &slow_case);
1327 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1328 __ b(ne, &slow_case);
1330 // Ensure that {function} has an instance prototype.
1331 __ ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1332 __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
1333 __ b(ne, &slow_case);
1335 // Ensure that {function} is not bound.
1336 Register const shared_info = scratch;
1338 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1339 __ ldr(scratch, FieldMemOperand(shared_info,
1340 SharedFunctionInfo::kCompilerHintsOffset));
1342 Operand(Smi::FromInt(1 << SharedFunctionInfo::kBoundFunction)));
1343 __ b(ne, &slow_case);
1345 // Get the "prototype" (or initial map) of the {function}.
1346 __ ldr(function_prototype,
1347 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1348 __ AssertNotSmi(function_prototype);
1350 // Resolve the prototype if the {function} has an initial map. Afterwards the
1351 // {function_prototype} will be either the JSReceiver prototype object or the
1352 // hole value, which means that no instances of the {function} were created so
1353 // far and hence we should return false.
1354 Label function_prototype_valid;
1355 __ CompareObjectType(function_prototype, scratch, scratch, MAP_TYPE);
1356 __ b(ne, &function_prototype_valid);
1357 __ ldr(function_prototype,
1358 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1359 __ bind(&function_prototype_valid);
1360 __ AssertNotSmi(function_prototype);
1362 // Update the global instanceof cache with the current {object} map and
1363 // {function}. The cached answer will be set when it is known below.
1364 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1365 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1367 // Loop through the prototype chain looking for the {function} prototype.
1368 // Assume true, and change to false if not found.
1369 Register const object_prototype = object_map;
1370 Register const null = scratch;
1372 __ LoadRoot(r0, Heap::kTrueValueRootIndex);
1373 __ LoadRoot(null, Heap::kNullValueRootIndex);
1375 __ ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1376 __ cmp(object_prototype, function_prototype);
1378 __ cmp(object_prototype, null);
1379 __ ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1381 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1383 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1386 // Slow-case: Call the runtime function.
1387 __ bind(&slow_case);
1388 __ Push(object, function);
1389 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1393 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1395 Register receiver = LoadDescriptor::ReceiverRegister();
1396 // Ensure that the vector and slot registers won't be clobbered before
1397 // calling the miss handler.
1398 DCHECK(!AreAliased(r4, r5, LoadWithVectorDescriptor::VectorRegister(),
1399 LoadWithVectorDescriptor::SlotRegister()));
1401 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4,
1404 PropertyAccessCompiler::TailCallBuiltin(
1405 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1409 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1410 // Return address is in lr.
1413 Register receiver = LoadDescriptor::ReceiverRegister();
1414 Register index = LoadDescriptor::NameRegister();
1415 Register scratch = r5;
1416 Register result = r0;
1417 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1418 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1419 result.is(LoadWithVectorDescriptor::SlotRegister()));
1421 // StringCharAtGenerator doesn't use the result register until it's passed
1422 // the different miss possibilities. If it did, we would have a conflict
1423 // when FLAG_vector_ics is true.
1424 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1425 &miss, // When not a string.
1426 &miss, // When not a number.
1427 &miss, // When index out of range.
1428 STRING_INDEX_IS_ARRAY_INDEX,
1429 RECEIVER_IS_STRING);
1430 char_at_generator.GenerateFast(masm);
1433 StubRuntimeCallHelper call_helper;
1434 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1437 PropertyAccessCompiler::TailCallBuiltin(
1438 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1442 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1443 // The displacement is the offset of the last parameter (if any)
1444 // relative to the frame pointer.
1445 const int kDisplacement =
1446 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1447 DCHECK(r1.is(ArgumentsAccessReadDescriptor::index()));
1448 DCHECK(r0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1450 // Check that the key is a smi.
1452 __ JumpIfNotSmi(r1, &slow);
1454 // Check if the calling frame is an arguments adaptor frame.
1456 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1457 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1458 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1461 // Check index against formal parameters count limit passed in
1462 // through register r0. Use unsigned comparison to get negative
1467 // Read the argument from the stack and return it.
1469 __ add(r3, fp, Operand::PointerOffsetFromSmiKey(r3));
1470 __ ldr(r0, MemOperand(r3, kDisplacement));
1473 // Arguments adaptor case: Check index against actual arguments
1474 // limit found in the arguments adaptor frame. Use unsigned
1475 // comparison to get negative check for free.
1477 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1481 // Read the argument from the adaptor frame and return it.
1483 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r3));
1484 __ ldr(r0, MemOperand(r3, kDisplacement));
1487 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1488 // by calling the runtime system.
1491 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1495 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1496 // sp[0] : number of parameters
1497 // sp[4] : receiver displacement
1500 // Check if the calling frame is an arguments adaptor frame.
1502 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1503 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1504 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1507 // Patch the arguments.length and the parameters pointer in the current frame.
1508 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1509 __ str(r2, MemOperand(sp, 0 * kPointerSize));
1510 __ add(r3, r3, Operand(r2, LSL, 1));
1511 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1512 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1515 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1519 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1521 // sp[0] : number of parameters (tagged)
1522 // sp[4] : address of receiver argument
1524 // Registers used over whole function:
1525 // r6 : allocated object (tagged)
1526 // r9 : mapped parameter count (tagged)
1528 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1529 // r1 = parameter count (tagged)
1531 // Check if the calling frame is an arguments adaptor frame.
1533 Label adaptor_frame, try_allocate;
1534 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1535 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1536 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1537 __ b(eq, &adaptor_frame);
1539 // No adaptor, parameter count = argument count.
1541 __ b(&try_allocate);
1543 // We have an adaptor frame. Patch the parameters pointer.
1544 __ bind(&adaptor_frame);
1545 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1546 __ add(r3, r3, Operand(r2, LSL, 1));
1547 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1548 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1550 // r1 = parameter count (tagged)
1551 // r2 = argument count (tagged)
1552 // Compute the mapped parameter count = min(r1, r2) in r1.
1553 __ cmp(r1, Operand(r2));
1554 __ mov(r1, Operand(r2), LeaveCC, gt);
1556 __ bind(&try_allocate);
1558 // Compute the sizes of backing store, parameter map, and arguments object.
1559 // 1. Parameter map, has 2 extra words containing context and backing store.
1560 const int kParameterMapHeaderSize =
1561 FixedArray::kHeaderSize + 2 * kPointerSize;
1562 // If there are no mapped parameters, we do not need the parameter_map.
1563 __ cmp(r1, Operand(Smi::FromInt(0)));
1564 __ mov(r9, Operand::Zero(), LeaveCC, eq);
1565 __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne);
1566 __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne);
1568 // 2. Backing store.
1569 __ add(r9, r9, Operand(r2, LSL, 1));
1570 __ add(r9, r9, Operand(FixedArray::kHeaderSize));
1572 // 3. Arguments object.
1573 __ add(r9, r9, Operand(Heap::kSloppyArgumentsObjectSize));
1575 // Do the allocation of all three objects in one go.
1576 __ Allocate(r9, r0, r3, r4, &runtime, TAG_OBJECT);
1578 // r0 = address of new object(s) (tagged)
1579 // r2 = argument count (smi-tagged)
1580 // Get the arguments boilerplate from the current native context into r4.
1581 const int kNormalOffset =
1582 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1583 const int kAliasedOffset =
1584 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1586 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1587 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1588 __ cmp(r1, Operand::Zero());
1589 __ ldr(r4, MemOperand(r4, kNormalOffset), eq);
1590 __ ldr(r4, MemOperand(r4, kAliasedOffset), ne);
1592 // r0 = address of new object (tagged)
1593 // r1 = mapped parameter count (tagged)
1594 // r2 = argument count (smi-tagged)
1595 // r4 = address of arguments map (tagged)
1596 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1597 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1598 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1599 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1601 // Set up the callee in-object property.
1602 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1603 __ ldr(r3, MemOperand(sp, 2 * kPointerSize));
1604 __ AssertNotSmi(r3);
1605 const int kCalleeOffset = JSObject::kHeaderSize +
1606 Heap::kArgumentsCalleeIndex * kPointerSize;
1607 __ str(r3, FieldMemOperand(r0, kCalleeOffset));
1609 // Use the length (smi tagged) and set that as an in-object property too.
1611 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1612 const int kLengthOffset = JSObject::kHeaderSize +
1613 Heap::kArgumentsLengthIndex * kPointerSize;
1614 __ str(r2, FieldMemOperand(r0, kLengthOffset));
1616 // Set up the elements pointer in the allocated arguments object.
1617 // If we allocated a parameter map, r4 will point there, otherwise
1618 // it will point to the backing store.
1619 __ add(r4, r0, Operand(Heap::kSloppyArgumentsObjectSize));
1620 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1622 // r0 = address of new object (tagged)
1623 // r1 = mapped parameter count (tagged)
1624 // r2 = argument count (tagged)
1625 // r4 = address of parameter map or backing store (tagged)
1626 // Initialize parameter map. If there are no mapped arguments, we're done.
1627 Label skip_parameter_map;
1628 __ cmp(r1, Operand(Smi::FromInt(0)));
1629 // Move backing store address to r3, because it is
1630 // expected there when filling in the unmapped arguments.
1631 __ mov(r3, r4, LeaveCC, eq);
1632 __ b(eq, &skip_parameter_map);
1634 __ LoadRoot(r6, Heap::kSloppyArgumentsElementsMapRootIndex);
1635 __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset));
1636 __ add(r6, r1, Operand(Smi::FromInt(2)));
1637 __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset));
1638 __ str(cp, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize));
1639 __ add(r6, r4, Operand(r1, LSL, 1));
1640 __ add(r6, r6, Operand(kParameterMapHeaderSize));
1641 __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize));
1643 // Copy the parameter slots and the holes in the arguments.
1644 // We need to fill in mapped_parameter_count slots. They index the context,
1645 // where parameters are stored in reverse order, at
1646 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1647 // The mapped parameter thus need to get indices
1648 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1649 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1650 // We loop from right to left.
1651 Label parameters_loop, parameters_test;
1653 __ ldr(r9, MemOperand(sp, 0 * kPointerSize));
1654 __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1655 __ sub(r9, r9, Operand(r1));
1656 __ LoadRoot(r5, Heap::kTheHoleValueRootIndex);
1657 __ add(r3, r4, Operand(r6, LSL, 1));
1658 __ add(r3, r3, Operand(kParameterMapHeaderSize));
1660 // r6 = loop variable (tagged)
1661 // r1 = mapping index (tagged)
1662 // r3 = address of backing store (tagged)
1663 // r4 = address of parameter map (tagged), which is also the address of new
1664 // object + Heap::kSloppyArgumentsObjectSize (tagged)
1665 // r0 = temporary scratch (a.o., for address calculation)
1666 // r5 = the hole value
1667 __ jmp(¶meters_test);
1669 __ bind(¶meters_loop);
1670 __ sub(r6, r6, Operand(Smi::FromInt(1)));
1671 __ mov(r0, Operand(r6, LSL, 1));
1672 __ add(r0, r0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1673 __ str(r9, MemOperand(r4, r0));
1674 __ sub(r0, r0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1675 __ str(r5, MemOperand(r3, r0));
1676 __ add(r9, r9, Operand(Smi::FromInt(1)));
1677 __ bind(¶meters_test);
1678 __ cmp(r6, Operand(Smi::FromInt(0)));
1679 __ b(ne, ¶meters_loop);
1681 // Restore r0 = new object (tagged)
1682 __ sub(r0, r4, Operand(Heap::kSloppyArgumentsObjectSize));
1684 __ bind(&skip_parameter_map);
1685 // r0 = address of new object (tagged)
1686 // r2 = argument count (tagged)
1687 // r3 = address of backing store (tagged)
1689 // Copy arguments header and remaining slots (if there are any).
1690 __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex);
1691 __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset));
1692 __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset));
1694 Label arguments_loop, arguments_test;
1696 __ ldr(r4, MemOperand(sp, 1 * kPointerSize));
1697 __ sub(r4, r4, Operand(r9, LSL, 1));
1698 __ jmp(&arguments_test);
1700 __ bind(&arguments_loop);
1701 __ sub(r4, r4, Operand(kPointerSize));
1702 __ ldr(r6, MemOperand(r4, 0));
1703 __ add(r5, r3, Operand(r9, LSL, 1));
1704 __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize));
1705 __ add(r9, r9, Operand(Smi::FromInt(1)));
1707 __ bind(&arguments_test);
1708 __ cmp(r9, Operand(r2));
1709 __ b(lt, &arguments_loop);
1711 // Return and remove the on-stack parameters.
1712 __ add(sp, sp, Operand(3 * kPointerSize));
1715 // Do the runtime call to allocate the arguments object.
1716 // r0 = address of new object (tagged)
1717 // r2 = argument count (tagged)
1719 __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1720 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1724 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1725 // Return address is in lr.
1728 Register receiver = LoadDescriptor::ReceiverRegister();
1729 Register key = LoadDescriptor::NameRegister();
1731 // Check that the key is an array index, that is Uint32.
1732 __ NonNegativeSmiTst(key);
1735 // Everything is fine, call runtime.
1736 __ Push(receiver, key); // Receiver, key.
1738 // Perform tail call to the entry.
1739 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1742 PropertyAccessCompiler::TailCallBuiltin(
1743 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1747 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1748 // sp[0] : number of parameters
1749 // sp[4] : receiver displacement
1751 // Check if the calling frame is an arguments adaptor frame.
1752 Label adaptor_frame, try_allocate, runtime;
1753 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1754 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1755 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1756 __ b(eq, &adaptor_frame);
1758 // Get the length from the frame.
1759 __ ldr(r1, MemOperand(sp, 0));
1760 __ b(&try_allocate);
1762 // Patch the arguments.length and the parameters pointer.
1763 __ bind(&adaptor_frame);
1764 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1765 __ str(r1, MemOperand(sp, 0));
1766 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1767 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1768 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1770 // Try the new space allocation. Start out with computing the size
1771 // of the arguments object and the elements array in words.
1772 Label add_arguments_object;
1773 __ bind(&try_allocate);
1774 __ SmiUntag(r1, SetCC);
1775 __ b(eq, &add_arguments_object);
1776 __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize));
1777 __ bind(&add_arguments_object);
1778 __ add(r1, r1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1780 // Do the allocation of both objects in one go.
1781 __ Allocate(r1, r0, r2, r3, &runtime,
1782 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1784 // Get the arguments boilerplate from the current native context.
1785 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1786 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1787 __ ldr(r4, MemOperand(
1788 r4, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1790 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1791 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1792 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1793 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1795 // Get the length (smi tagged) and set that as an in-object property too.
1796 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1797 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1799 __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize +
1800 Heap::kArgumentsLengthIndex * kPointerSize));
1802 // If there are no actual arguments, we're done.
1804 __ cmp(r1, Operand::Zero());
1807 // Get the parameters pointer from the stack.
1808 __ ldr(r2, MemOperand(sp, 1 * kPointerSize));
1810 // Set up the elements pointer in the allocated arguments object and
1811 // initialize the header in the elements fixed array.
1812 __ add(r4, r0, Operand(Heap::kStrictArgumentsObjectSize));
1813 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1814 __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex);
1815 __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset));
1816 __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset));
1819 // Copy the fixed array slots.
1821 // Set up r4 to point to the first array slot.
1822 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1824 // Pre-decrement r2 with kPointerSize on each iteration.
1825 // Pre-decrement in order to skip receiver.
1826 __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
1827 // Post-increment r4 with kPointerSize on each iteration.
1828 __ str(r3, MemOperand(r4, kPointerSize, PostIndex));
1829 __ sub(r1, r1, Operand(1));
1830 __ cmp(r1, Operand::Zero());
1833 // Return and remove the on-stack parameters.
1835 __ add(sp, sp, Operand(3 * kPointerSize));
1838 // Do the runtime call to allocate the arguments object.
1840 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1844 void RegExpExecStub::Generate(MacroAssembler* masm) {
1845 // Just jump directly to runtime if native RegExp is not selected at compile
1846 // time or if regexp entry in generated code is turned off runtime switch or
1848 #ifdef V8_INTERPRETED_REGEXP
1849 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1850 #else // V8_INTERPRETED_REGEXP
1852 // Stack frame on entry.
1853 // sp[0]: last_match_info (expected JSArray)
1854 // sp[4]: previous index
1855 // sp[8]: subject string
1856 // sp[12]: JSRegExp object
1858 const int kLastMatchInfoOffset = 0 * kPointerSize;
1859 const int kPreviousIndexOffset = 1 * kPointerSize;
1860 const int kSubjectOffset = 2 * kPointerSize;
1861 const int kJSRegExpOffset = 3 * kPointerSize;
1864 // Allocation of registers for this function. These are in callee save
1865 // registers and will be preserved by the call to the native RegExp code, as
1866 // this code is called using the normal C calling convention. When calling
1867 // directly from generated code the native RegExp code will not do a GC and
1868 // therefore the content of these registers are safe to use after the call.
1869 Register subject = r4;
1870 Register regexp_data = r5;
1871 Register last_match_info_elements = no_reg; // will be r6;
1873 // Ensure that a RegExp stack is allocated.
1874 ExternalReference address_of_regexp_stack_memory_address =
1875 ExternalReference::address_of_regexp_stack_memory_address(isolate());
1876 ExternalReference address_of_regexp_stack_memory_size =
1877 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1878 __ mov(r0, Operand(address_of_regexp_stack_memory_size));
1879 __ ldr(r0, MemOperand(r0, 0));
1880 __ cmp(r0, Operand::Zero());
1883 // Check that the first argument is a JSRegExp object.
1884 __ ldr(r0, MemOperand(sp, kJSRegExpOffset));
1885 __ JumpIfSmi(r0, &runtime);
1886 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
1889 // Check that the RegExp has been compiled (data contains a fixed array).
1890 __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
1891 if (FLAG_debug_code) {
1892 __ SmiTst(regexp_data);
1893 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1894 __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
1895 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1898 // regexp_data: RegExp data (FixedArray)
1899 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1900 __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1901 __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
1904 // regexp_data: RegExp data (FixedArray)
1905 // Check that the number of captures fit in the static offsets vector buffer.
1907 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1908 // Check (number_of_captures + 1) * 2 <= offsets vector size
1909 // Or number_of_captures * 2 <= offsets vector size - 2
1910 // Multiplying by 2 comes for free since r2 is smi-tagged.
1911 STATIC_ASSERT(kSmiTag == 0);
1912 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
1913 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1914 __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
1917 // Reset offset for possibly sliced string.
1918 __ mov(r9, Operand::Zero());
1919 __ ldr(subject, MemOperand(sp, kSubjectOffset));
1920 __ JumpIfSmi(subject, &runtime);
1921 __ mov(r3, subject); // Make a copy of the original subject string.
1922 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1923 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
1924 // subject: subject string
1925 // r3: subject string
1926 // r0: subject string instance type
1927 // regexp_data: RegExp data (FixedArray)
1928 // Handle subject string according to its encoding and representation:
1929 // (1) Sequential string? If yes, go to (5).
1930 // (2) Anything but sequential or cons? If yes, go to (6).
1931 // (3) Cons string. If the string is flat, replace subject with first string.
1932 // Otherwise bailout.
1933 // (4) Is subject external? If yes, go to (7).
1934 // (5) Sequential string. Load regexp code according to encoding.
1938 // Deferred code at the end of the stub:
1939 // (6) Not a long external string? If yes, go to (8).
1940 // (7) External string. Make it, offset-wise, look like a sequential string.
1942 // (8) Short external string or not a string? If yes, bail out to runtime.
1943 // (9) Sliced string. Replace subject with parent. Go to (4).
1945 Label seq_string /* 5 */, external_string /* 7 */,
1946 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
1947 not_long_external /* 8 */;
1949 // (1) Sequential string? If yes, go to (5).
1952 Operand(kIsNotStringMask |
1953 kStringRepresentationMask |
1954 kShortExternalStringMask),
1956 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
1957 __ b(eq, &seq_string); // Go to (5).
1959 // (2) Anything but sequential or cons? If yes, go to (6).
1960 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1961 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
1962 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1963 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
1964 __ cmp(r1, Operand(kExternalStringTag));
1965 __ b(ge, ¬_seq_nor_cons); // Go to (6).
1967 // (3) Cons string. Check that it's flat.
1968 // Replace subject with first string and reload instance type.
1969 __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
1970 __ CompareRoot(r0, Heap::kempty_stringRootIndex);
1972 __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
1974 // (4) Is subject external? If yes, go to (7).
1975 __ bind(&check_underlying);
1976 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1977 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
1978 STATIC_ASSERT(kSeqStringTag == 0);
1979 __ tst(r0, Operand(kStringRepresentationMask));
1980 // The underlying external string is never a short external string.
1981 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
1982 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
1983 __ b(ne, &external_string); // Go to (7).
1985 // (5) Sequential string. Load regexp code according to encoding.
1986 __ bind(&seq_string);
1987 // subject: sequential subject string (or look-alike, external string)
1988 // r3: original subject string
1989 // Load previous index and check range before r3 is overwritten. We have to
1990 // use r3 instead of subject here because subject might have been only made
1991 // to look like a sequential string when it actually is an external string.
1992 __ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
1993 __ JumpIfNotSmi(r1, &runtime);
1994 __ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
1995 __ cmp(r3, Operand(r1));
1999 STATIC_ASSERT(4 == kOneByteStringTag);
2000 STATIC_ASSERT(kTwoByteStringTag == 0);
2001 __ and_(r0, r0, Operand(kStringEncodingMask));
2002 __ mov(r3, Operand(r0, ASR, 2), SetCC);
2003 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset),
2005 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
2007 // (E) Carry on. String handling is done.
2008 // r6: irregexp code
2009 // Check that the irregexp code has been generated for the actual string
2010 // encoding. If it has, the field contains a code object otherwise it contains
2011 // a smi (code flushing support).
2012 __ JumpIfSmi(r6, &runtime);
2014 // r1: previous index
2015 // r3: encoding of subject string (1 if one_byte, 0 if two_byte);
2017 // subject: Subject string
2018 // regexp_data: RegExp data (FixedArray)
2019 // All checks done. Now push arguments for native regexp code.
2020 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r0, r2);
2022 // Isolates: note we add an additional parameter here (isolate pointer).
2023 const int kRegExpExecuteArguments = 9;
2024 const int kParameterRegisters = 4;
2025 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2027 // Stack pointer now points to cell where return address is to be written.
2028 // Arguments are before that on the stack or in registers.
2030 // Argument 9 (sp[20]): Pass current isolate address.
2031 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2032 __ str(r0, MemOperand(sp, 5 * kPointerSize));
2034 // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
2035 __ mov(r0, Operand(1));
2036 __ str(r0, MemOperand(sp, 4 * kPointerSize));
2038 // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
2039 __ mov(r0, Operand(address_of_regexp_stack_memory_address));
2040 __ ldr(r0, MemOperand(r0, 0));
2041 __ mov(r2, Operand(address_of_regexp_stack_memory_size));
2042 __ ldr(r2, MemOperand(r2, 0));
2043 __ add(r0, r0, Operand(r2));
2044 __ str(r0, MemOperand(sp, 3 * kPointerSize));
2046 // Argument 6: Set the number of capture registers to zero to force global
2047 // regexps to behave as non-global. This does not affect non-global regexps.
2048 __ mov(r0, Operand::Zero());
2049 __ str(r0, MemOperand(sp, 2 * kPointerSize));
2051 // Argument 5 (sp[4]): static offsets vector buffer.
2053 Operand(ExternalReference::address_of_static_offsets_vector(
2055 __ str(r0, MemOperand(sp, 1 * kPointerSize));
2057 // For arguments 4 and 3 get string length, calculate start of string data and
2058 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2059 __ add(r7, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2060 __ eor(r3, r3, Operand(1));
2061 // Load the length from the original subject string from the previous stack
2062 // frame. Therefore we have to use fp, which points exactly to two pointer
2063 // sizes below the previous sp. (Because creating a new stack frame pushes
2064 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2065 __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2066 // If slice offset is not 0, load the length from the original sliced string.
2067 // Argument 4, r3: End of string data
2068 // Argument 3, r2: Start of string data
2069 // Prepare start and end index of the input.
2070 __ add(r9, r7, Operand(r9, LSL, r3));
2071 __ add(r2, r9, Operand(r1, LSL, r3));
2073 __ ldr(r7, FieldMemOperand(subject, String::kLengthOffset));
2075 __ add(r3, r9, Operand(r7, LSL, r3));
2077 // Argument 2 (r1): Previous index.
2080 // Argument 1 (r0): Subject string.
2081 __ mov(r0, subject);
2083 // Locate the code entry and call it.
2084 __ add(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
2085 DirectCEntryStub stub(isolate());
2086 stub.GenerateCall(masm, r6);
2088 __ LeaveExitFrame(false, no_reg, true);
2090 last_match_info_elements = r6;
2093 // subject: subject string (callee saved)
2094 // regexp_data: RegExp data (callee saved)
2095 // last_match_info_elements: Last match info elements (callee saved)
2096 // Check the result.
2098 __ cmp(r0, Operand(1));
2099 // We expect exactly one result since we force the called regexp to behave
2103 __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
2105 __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2106 // If not exception it can only be retry. Handle that in the runtime system.
2108 // Result must now be exception. If there is no pending exception already a
2109 // stack overflow (on the backtrack stack) was detected in RegExp code but
2110 // haven't created the exception yet. Handle that in the runtime system.
2111 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2112 __ mov(r1, Operand(isolate()->factory()->the_hole_value()));
2113 __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2115 __ ldr(r0, MemOperand(r2, 0));
2119 // For exception, throw the exception again.
2120 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2123 // For failure and exception return null.
2124 __ mov(r0, Operand(isolate()->factory()->null_value()));
2125 __ add(sp, sp, Operand(4 * kPointerSize));
2128 // Process the result from the native regexp code.
2131 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2132 // Calculate number of capture registers (number_of_captures + 1) * 2.
2133 // Multiplying by 2 comes for free since r1 is smi-tagged.
2134 STATIC_ASSERT(kSmiTag == 0);
2135 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2136 __ add(r1, r1, Operand(2)); // r1 was a smi.
2138 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2139 __ JumpIfSmi(r0, &runtime);
2140 __ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
2142 // Check that the JSArray is in fast case.
2143 __ ldr(last_match_info_elements,
2144 FieldMemOperand(r0, JSArray::kElementsOffset));
2145 __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2146 __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
2148 // Check that the last match info has space for the capture registers and the
2149 // additional information.
2151 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2152 __ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
2153 __ cmp(r2, Operand::SmiUntag(r0));
2156 // r1: number of capture registers
2157 // r4: subject string
2158 // Store the capture count.
2160 __ str(r2, FieldMemOperand(last_match_info_elements,
2161 RegExpImpl::kLastCaptureCountOffset));
2162 // Store last subject and last input.
2164 FieldMemOperand(last_match_info_elements,
2165 RegExpImpl::kLastSubjectOffset));
2166 __ mov(r2, subject);
2167 __ RecordWriteField(last_match_info_elements,
2168 RegExpImpl::kLastSubjectOffset,
2173 __ mov(subject, r2);
2175 FieldMemOperand(last_match_info_elements,
2176 RegExpImpl::kLastInputOffset));
2177 __ RecordWriteField(last_match_info_elements,
2178 RegExpImpl::kLastInputOffset,
2184 // Get the static offsets vector filled by the native regexp code.
2185 ExternalReference address_of_static_offsets_vector =
2186 ExternalReference::address_of_static_offsets_vector(isolate());
2187 __ mov(r2, Operand(address_of_static_offsets_vector));
2189 // r1: number of capture registers
2190 // r2: offsets vector
2191 Label next_capture, done;
2192 // Capture register counter starts from number of capture registers and
2193 // counts down until wraping after zero.
2195 last_match_info_elements,
2196 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2197 __ bind(&next_capture);
2198 __ sub(r1, r1, Operand(1), SetCC);
2200 // Read the value from the static offsets vector buffer.
2201 __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
2202 // Store the smi value in the last match info.
2204 __ str(r3, MemOperand(r0, kPointerSize, PostIndex));
2205 __ jmp(&next_capture);
2208 // Return last match info.
2209 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2210 __ add(sp, sp, Operand(4 * kPointerSize));
2213 // Do the runtime call to execute the regexp.
2215 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2217 // Deferred code for string handling.
2218 // (6) Not a long external string? If yes, go to (8).
2219 __ bind(¬_seq_nor_cons);
2220 // Compare flags are still set.
2221 __ b(gt, ¬_long_external); // Go to (8).
2223 // (7) External string. Make it, offset-wise, look like a sequential string.
2224 __ bind(&external_string);
2225 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2226 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2227 if (FLAG_debug_code) {
2228 // Assert that we do not have a cons or slice (indirect strings) here.
2229 // Sequential strings have already been ruled out.
2230 __ tst(r0, Operand(kIsIndirectStringMask));
2231 __ Assert(eq, kExternalStringExpectedButNotFound);
2234 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2235 // Move the pointer so that offset-wise, it looks like a sequential string.
2236 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2239 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2240 __ jmp(&seq_string); // Go to (5).
2242 // (8) Short external string or not a string? If yes, bail out to runtime.
2243 __ bind(¬_long_external);
2244 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2245 __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
2248 // (9) Sliced string. Replace subject with parent. Go to (4).
2249 // Load offset into r9 and replace subject string with parent.
2250 __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2252 __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2253 __ jmp(&check_underlying); // Go to (4).
2254 #endif // V8_INTERPRETED_REGEXP
2258 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2260 // r0 : number of arguments to the construct function
2261 // r1 : the function to call
2262 // r2 : feedback vector
2263 // r3 : slot in feedback vector (Smi)
2264 // r4 : original constructor (for IsSuperConstructorCall)
2265 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2267 // Number-of-arguments register must be smi-tagged to call out.
2269 __ Push(r3, r2, r1, r0);
2279 __ Pop(r3, r2, r1, r0);
2284 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2285 // Cache the called function in a feedback vector slot. Cache states
2286 // are uninitialized, monomorphic (indicated by a JSFunction), and
2288 // r0 : number of arguments to the construct function
2289 // r1 : the function to call
2290 // r2 : feedback vector
2291 // r3 : slot in feedback vector (Smi)
2292 // r4 : original constructor (for IsSuperConstructorCall)
2293 Label initialize, done, miss, megamorphic, not_array_function;
2295 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2296 masm->isolate()->heap()->megamorphic_symbol());
2297 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2298 masm->isolate()->heap()->uninitialized_symbol());
2300 // Load the cache state into r5.
2301 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2302 __ ldr(r5, FieldMemOperand(r5, FixedArray::kHeaderSize));
2304 // A monomorphic cache hit or an already megamorphic state: invoke the
2305 // function without changing the state.
2306 // We don't know if r5 is a WeakCell or a Symbol, but it's harmless to read at
2307 // this position in a symbol (see static asserts in type-feedback-vector.h).
2308 Label check_allocation_site;
2309 Register feedback_map = r6;
2310 Register weak_value = r9;
2311 __ ldr(weak_value, FieldMemOperand(r5, WeakCell::kValueOffset));
2312 __ cmp(r1, weak_value);
2314 __ CompareRoot(r5, Heap::kmegamorphic_symbolRootIndex);
2316 __ ldr(feedback_map, FieldMemOperand(r5, HeapObject::kMapOffset));
2317 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2318 __ b(ne, &check_allocation_site);
2320 // If the weak cell is cleared, we have a new chance to become monomorphic.
2321 __ JumpIfSmi(weak_value, &initialize);
2322 __ jmp(&megamorphic);
2324 __ bind(&check_allocation_site);
2325 // If we came here, we need to see if we are the array function.
2326 // If we didn't have a matching function, and we didn't find the megamorph
2327 // sentinel, then we have in the slot either some other function or an
2329 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2332 // Make sure the function is the Array() function
2333 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2335 __ b(ne, &megamorphic);
2340 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2342 __ CompareRoot(r5, Heap::kuninitialized_symbolRootIndex);
2343 __ b(eq, &initialize);
2344 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2345 // write-barrier is needed.
2346 __ bind(&megamorphic);
2347 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2348 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2349 __ str(ip, FieldMemOperand(r5, FixedArray::kHeaderSize));
2352 // An uninitialized cache is patched with the function
2353 __ bind(&initialize);
2355 // Make sure the function is the Array() function
2356 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2358 __ b(ne, ¬_array_function);
2360 // The target function is the Array constructor,
2361 // Create an AllocationSite if we don't already have it, store it in the
2363 CreateAllocationSiteStub create_stub(masm->isolate());
2364 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2367 __ bind(¬_array_function);
2368 CreateWeakCellStub weak_cell_stub(masm->isolate());
2369 CallStubInRecordCallTarget(masm, &weak_cell_stub, is_super);
2374 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2375 // Do not transform the receiver for strict mode functions.
2376 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2377 __ ldr(r4, FieldMemOperand(r3, SharedFunctionInfo::kCompilerHintsOffset));
2378 __ tst(r4, Operand(1 << (SharedFunctionInfo::kStrictModeFunction +
2382 // Do not transform the receiver for native (Compilerhints already in r3).
2383 __ tst(r4, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
2388 static void EmitSlowCase(MacroAssembler* masm, int argc) {
2389 __ mov(r0, Operand(argc));
2390 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2394 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2395 // Wrap the receiver and patch it back onto the stack.
2396 { FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2399 ToObjectStub stub(masm->isolate());
2403 __ str(r0, MemOperand(sp, argc * kPointerSize));
2408 static void CallFunctionNoFeedback(MacroAssembler* masm,
2409 int argc, bool needs_checks,
2410 bool call_as_method) {
2411 // r1 : the function to call
2412 Label slow, wrap, cont;
2415 // Check that the function is really a JavaScript function.
2416 // r1: pushed function (to be verified)
2417 __ JumpIfSmi(r1, &slow);
2419 // Goto slow case if we do not have a function.
2420 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2424 // Fast-case: Invoke the function now.
2425 // r1: pushed function
2426 ParameterCount actual(argc);
2428 if (call_as_method) {
2430 EmitContinueIfStrictOrNative(masm, &cont);
2433 // Compute the receiver in sloppy mode.
2434 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2437 __ JumpIfSmi(r3, &wrap);
2438 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2447 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2450 // Slow-case: Non-function called.
2452 EmitSlowCase(masm, argc);
2455 if (call_as_method) {
2457 EmitWrapCase(masm, argc, &cont);
2462 void CallFunctionStub::Generate(MacroAssembler* masm) {
2463 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2467 void CallConstructStub::Generate(MacroAssembler* masm) {
2468 // r0 : number of arguments
2469 // r1 : the function to call
2470 // r2 : feedback vector
2471 // r3 : slot in feedback vector (Smi, for RecordCallTarget)
2472 // r4 : original constructor (for IsSuperConstructorCall)
2475 // Check that the function is not a smi.
2476 __ JumpIfSmi(r1, &non_function);
2477 // Check that the function is a JSFunction.
2478 __ CompareObjectType(r1, r5, r5, JS_FUNCTION_TYPE);
2479 __ b(ne, &non_function);
2481 if (RecordCallTarget()) {
2482 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2484 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2485 Label feedback_register_initialized;
2486 // Put the AllocationSite from the feedback vector into r2, or undefined.
2487 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2488 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2489 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2490 __ b(eq, &feedback_register_initialized);
2491 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2492 __ bind(&feedback_register_initialized);
2494 __ AssertUndefinedOrAllocationSite(r2, r5);
2497 // Pass function as original constructor.
2498 if (IsSuperConstructorCall()) {
2504 // Tail call to the function-specific construct stub (still in the caller
2505 // context at this point).
2506 __ ldr(r4, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2507 __ ldr(r4, FieldMemOperand(r4, SharedFunctionInfo::kConstructStubOffset));
2508 __ add(pc, r4, Operand(Code::kHeaderSize - kHeapObjectTag));
2510 __ bind(&non_function);
2512 __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
2516 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2517 __ ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2518 __ ldr(vector, FieldMemOperand(vector,
2519 JSFunction::kSharedFunctionInfoOffset));
2520 __ ldr(vector, FieldMemOperand(vector,
2521 SharedFunctionInfo::kFeedbackVectorOffset));
2525 void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
2529 // r4 - allocation site (loaded from vector[slot])
2530 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2534 __ mov(r0, Operand(arg_count()));
2536 // Increment the call count for monomorphic function calls.
2537 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2538 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2539 __ ldr(r3, FieldMemOperand(r2, 0));
2540 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2541 __ str(r3, FieldMemOperand(r2, 0));
2545 ArrayConstructorStub stub(masm->isolate(), arg_count());
2546 __ TailCallStub(&stub);
2550 void CallICStub::Generate(MacroAssembler* masm) {
2552 // r3 - slot id (Smi)
2554 const int with_types_offset =
2555 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2556 const int generic_offset =
2557 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2558 Label extra_checks_or_miss, slow_start;
2559 Label slow, wrap, cont;
2560 Label have_js_function;
2561 int argc = arg_count();
2562 ParameterCount actual(argc);
2564 // The checks. First, does r1 match the recorded monomorphic target?
2565 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2566 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2568 // We don't know that we have a weak cell. We might have a private symbol
2569 // or an AllocationSite, but the memory is safe to examine.
2570 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2572 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2573 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2574 // computed, meaning that it can't appear to be a pointer. If the low bit is
2575 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2577 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2578 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2579 WeakCell::kValueOffset &&
2580 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2582 __ ldr(r5, FieldMemOperand(r4, WeakCell::kValueOffset));
2584 __ b(ne, &extra_checks_or_miss);
2586 // The compare above could have been a SMI/SMI comparison. Guard against this
2587 // convincing us that we have a monomorphic JSFunction.
2588 __ JumpIfSmi(r1, &extra_checks_or_miss);
2590 // Increment the call count for monomorphic function calls.
2591 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2592 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2593 __ ldr(r3, FieldMemOperand(r2, 0));
2594 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2595 __ str(r3, FieldMemOperand(r2, 0));
2597 __ bind(&have_js_function);
2598 if (CallAsMethod()) {
2599 EmitContinueIfStrictOrNative(masm, &cont);
2600 // Compute the receiver in sloppy mode.
2601 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2603 __ JumpIfSmi(r3, &wrap);
2604 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2610 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2613 EmitSlowCase(masm, argc);
2615 if (CallAsMethod()) {
2617 EmitWrapCase(masm, argc, &cont);
2620 __ bind(&extra_checks_or_miss);
2621 Label uninitialized, miss, not_allocation_site;
2623 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2624 __ b(eq, &slow_start);
2626 // Verify that r4 contains an AllocationSite
2627 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2628 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2629 __ b(ne, ¬_allocation_site);
2631 // We have an allocation site.
2632 HandleArrayCase(masm, &miss);
2634 __ bind(¬_allocation_site);
2636 // The following cases attempt to handle MISS cases without going to the
2638 if (FLAG_trace_ic) {
2642 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2643 __ b(eq, &uninitialized);
2645 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2646 // to handle it here. More complex cases are dealt with in the runtime.
2647 __ AssertNotSmi(r4);
2648 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2650 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2651 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2652 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2653 // We have to update statistics for runtime profiling.
2654 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2655 __ sub(r4, r4, Operand(Smi::FromInt(1)));
2656 __ str(r4, FieldMemOperand(r2, with_types_offset));
2657 __ ldr(r4, FieldMemOperand(r2, generic_offset));
2658 __ add(r4, r4, Operand(Smi::FromInt(1)));
2659 __ str(r4, FieldMemOperand(r2, generic_offset));
2660 __ jmp(&slow_start);
2662 __ bind(&uninitialized);
2664 // We are going monomorphic, provided we actually have a JSFunction.
2665 __ JumpIfSmi(r1, &miss);
2667 // Goto miss case if we do not have a function.
2668 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2671 // Make sure the function is not the Array() function, which requires special
2672 // behavior on MISS.
2673 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2678 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2679 __ add(r4, r4, Operand(Smi::FromInt(1)));
2680 __ str(r4, FieldMemOperand(r2, with_types_offset));
2682 // Initialize the call counter.
2683 __ Move(r5, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2684 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2685 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + kPointerSize));
2687 // Store the function. Use a stub since we need a frame for allocation.
2692 FrameScope scope(masm, StackFrame::INTERNAL);
2693 CreateWeakCellStub create_stub(masm->isolate());
2695 __ CallStub(&create_stub);
2699 __ jmp(&have_js_function);
2701 // We are here because tracing is on or we encountered a MISS case we can't
2707 __ bind(&slow_start);
2708 // Check that the function is really a JavaScript function.
2709 // r1: pushed function (to be verified)
2710 __ JumpIfSmi(r1, &slow);
2712 // Goto slow case if we do not have a function.
2713 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2715 __ jmp(&have_js_function);
2719 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2720 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2722 // Push the receiver and the function and feedback info.
2723 __ Push(r1, r2, r3);
2726 __ CallRuntime(Runtime::kCallIC_Miss, 3);
2728 // Move result to edi and exit the internal frame.
2733 // StringCharCodeAtGenerator
2734 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2735 // If the receiver is a smi trigger the non-string case.
2736 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2737 __ JumpIfSmi(object_, receiver_not_string_);
2739 // Fetch the instance type of the receiver into result register.
2740 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2741 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2742 // If the receiver is not a string trigger the non-string case.
2743 __ tst(result_, Operand(kIsNotStringMask));
2744 __ b(ne, receiver_not_string_);
2747 // If the index is non-smi trigger the non-smi case.
2748 __ JumpIfNotSmi(index_, &index_not_smi_);
2749 __ bind(&got_smi_index_);
2751 // Check for index out of range.
2752 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
2753 __ cmp(ip, Operand(index_));
2754 __ b(ls, index_out_of_range_);
2756 __ SmiUntag(index_);
2758 StringCharLoadGenerator::Generate(masm,
2769 void StringCharCodeAtGenerator::GenerateSlow(
2770 MacroAssembler* masm, EmbedMode embed_mode,
2771 const RuntimeCallHelper& call_helper) {
2772 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2774 // Index is not a smi.
2775 __ bind(&index_not_smi_);
2776 // If index is a heap number, try converting it to an integer.
2779 Heap::kHeapNumberMapRootIndex,
2782 call_helper.BeforeCall(masm);
2783 if (embed_mode == PART_OF_IC_HANDLER) {
2784 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2785 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2787 // index_ is consumed by runtime conversion function.
2788 __ Push(object_, index_);
2790 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2791 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2793 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2794 // NumberToSmi discards numbers that are not exact integers.
2795 __ CallRuntime(Runtime::kNumberToSmi, 1);
2797 // Save the conversion result before the pop instructions below
2798 // have a chance to overwrite it.
2799 __ Move(index_, r0);
2800 if (embed_mode == PART_OF_IC_HANDLER) {
2801 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2802 LoadWithVectorDescriptor::SlotRegister(), object_);
2806 // Reload the instance type.
2807 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2808 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2809 call_helper.AfterCall(masm);
2810 // If index is still not a smi, it must be out of range.
2811 __ JumpIfNotSmi(index_, index_out_of_range_);
2812 // Otherwise, return to the fast path.
2813 __ jmp(&got_smi_index_);
2815 // Call runtime. We get here when the receiver is a string and the
2816 // index is a number, but the code of getting the actual character
2817 // is too complex (e.g., when the string needs to be flattened).
2818 __ bind(&call_runtime_);
2819 call_helper.BeforeCall(masm);
2821 __ Push(object_, index_);
2822 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2823 __ Move(result_, r0);
2824 call_helper.AfterCall(masm);
2827 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2831 // -------------------------------------------------------------------------
2832 // StringCharFromCodeGenerator
2834 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2835 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2836 STATIC_ASSERT(kSmiTag == 0);
2837 STATIC_ASSERT(kSmiShiftSize == 0);
2838 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2839 __ tst(code_, Operand(kSmiTagMask |
2840 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
2841 __ b(ne, &slow_case_);
2843 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2844 // At this point code register contains smi tagged one-byte char code.
2845 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
2846 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
2847 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
2848 __ b(eq, &slow_case_);
2853 void StringCharFromCodeGenerator::GenerateSlow(
2854 MacroAssembler* masm,
2855 const RuntimeCallHelper& call_helper) {
2856 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2858 __ bind(&slow_case_);
2859 call_helper.BeforeCall(masm);
2861 __ CallRuntime(Runtime::kCharFromCode, 1);
2862 __ Move(result_, r0);
2863 call_helper.AfterCall(masm);
2866 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2870 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
2873 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2878 String::Encoding encoding) {
2879 if (FLAG_debug_code) {
2880 // Check that destination is word aligned.
2881 __ tst(dest, Operand(kPointerAlignmentMask));
2882 __ Check(eq, kDestinationOfCopyNotAligned);
2885 // Assumes word reads and writes are little endian.
2886 // Nothing to do for zero characters.
2888 if (encoding == String::TWO_BYTE_ENCODING) {
2889 __ add(count, count, Operand(count), SetCC);
2892 Register limit = count; // Read until dest equals this.
2893 __ add(limit, dest, Operand(count));
2895 Label loop_entry, loop;
2896 // Copy bytes from src to dest until dest hits limit.
2899 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
2900 __ strb(scratch, MemOperand(dest, 1, PostIndex));
2901 __ bind(&loop_entry);
2902 __ cmp(dest, Operand(limit));
2909 void SubStringStub::Generate(MacroAssembler* masm) {
2912 // Stack frame on entry.
2913 // lr: return address
2918 // This stub is called from the native-call %_SubString(...), so
2919 // nothing can be assumed about the arguments. It is tested that:
2920 // "string" is a sequential string,
2921 // both "from" and "to" are smis, and
2922 // 0 <= from <= to <= string.length.
2923 // If any of these assumptions fail, we call the runtime system.
2925 const int kToOffset = 0 * kPointerSize;
2926 const int kFromOffset = 1 * kPointerSize;
2927 const int kStringOffset = 2 * kPointerSize;
2929 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
2930 STATIC_ASSERT(kFromOffset == kToOffset + 4);
2931 STATIC_ASSERT(kSmiTag == 0);
2932 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2934 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
2935 // instead because we bail out on non-smi values: ROR and ASR are equivalent
2936 // for smis but they set the flags in a way that's easier to optimize.
2937 __ mov(r2, Operand(r2, ROR, 1), SetCC);
2938 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
2939 // If either to or from had the smi tag bit set, then C is set now, and N
2940 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
2941 // We want to bailout to runtime here if From is negative. In that case, the
2942 // next instruction is not executed and we fall through to bailing out to
2944 // Executed if both r2 and r3 are untagged integers.
2945 __ sub(r2, r2, Operand(r3), SetCC, cc);
2946 // One of the above un-smis or the above SUB could have set N==1.
2947 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
2949 // Make sure first argument is a string.
2950 __ ldr(r0, MemOperand(sp, kStringOffset));
2951 __ JumpIfSmi(r0, &runtime);
2952 Condition is_string = masm->IsObjectStringType(r0, r1);
2953 __ b(NegateCondition(is_string), &runtime);
2956 __ cmp(r2, Operand(1));
2957 __ b(eq, &single_char);
2959 // Short-cut for the case of trivial substring.
2961 // r0: original string
2962 // r2: result string length
2963 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
2964 __ cmp(r2, Operand(r4, ASR, 1));
2965 // Return original string.
2966 __ b(eq, &return_r0);
2967 // Longer than original string's length or negative: unsafe arguments.
2969 // Shorter than original string's length: an actual substring.
2971 // Deal with different string types: update the index if necessary
2972 // and put the underlying string into r5.
2973 // r0: original string
2974 // r1: instance type
2976 // r3: from index (untagged)
2977 Label underlying_unpacked, sliced_string, seq_or_external_string;
2978 // If the string is not indirect, it can only be sequential or external.
2979 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2980 STATIC_ASSERT(kIsIndirectStringMask != 0);
2981 __ tst(r1, Operand(kIsIndirectStringMask));
2982 __ b(eq, &seq_or_external_string);
2984 __ tst(r1, Operand(kSlicedNotConsMask));
2985 __ b(ne, &sliced_string);
2986 // Cons string. Check whether it is flat, then fetch first part.
2987 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
2988 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
2990 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
2991 // Update instance type.
2992 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
2993 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
2994 __ jmp(&underlying_unpacked);
2996 __ bind(&sliced_string);
2997 // Sliced string. Fetch parent and correct start index by offset.
2998 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
2999 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3000 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
3001 // Update instance type.
3002 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3003 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3004 __ jmp(&underlying_unpacked);
3006 __ bind(&seq_or_external_string);
3007 // Sequential or external string. Just move string to the expected register.
3010 __ bind(&underlying_unpacked);
3012 if (FLAG_string_slices) {
3014 // r5: underlying subject string
3015 // r1: instance type of underlying subject string
3017 // r3: adjusted start index (untagged)
3018 __ cmp(r2, Operand(SlicedString::kMinLength));
3019 // Short slice. Copy instead of slicing.
3020 __ b(lt, ©_routine);
3021 // Allocate new sliced string. At this point we do not reload the instance
3022 // type including the string encoding because we simply rely on the info
3023 // provided by the original string. It does not matter if the original
3024 // string's encoding is wrong because we always have to recheck encoding of
3025 // the newly created string's parent anyways due to externalized strings.
3026 Label two_byte_slice, set_slice_header;
3027 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3028 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3029 __ tst(r1, Operand(kStringEncodingMask));
3030 __ b(eq, &two_byte_slice);
3031 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
3032 __ jmp(&set_slice_header);
3033 __ bind(&two_byte_slice);
3034 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
3035 __ bind(&set_slice_header);
3036 __ mov(r3, Operand(r3, LSL, 1));
3037 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3038 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3041 __ bind(©_routine);
3044 // r5: underlying subject string
3045 // r1: instance type of underlying subject string
3047 // r3: adjusted start index (untagged)
3048 Label two_byte_sequential, sequential_string, allocate_result;
3049 STATIC_ASSERT(kExternalStringTag != 0);
3050 STATIC_ASSERT(kSeqStringTag == 0);
3051 __ tst(r1, Operand(kExternalStringTag));
3052 __ b(eq, &sequential_string);
3054 // Handle external string.
3055 // Rule out short external strings.
3056 STATIC_ASSERT(kShortExternalStringTag != 0);
3057 __ tst(r1, Operand(kShortExternalStringTag));
3059 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
3060 // r5 already points to the first character of underlying string.
3061 __ jmp(&allocate_result);
3063 __ bind(&sequential_string);
3064 // Locate first character of underlying subject string.
3065 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3066 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3068 __ bind(&allocate_result);
3069 // Sequential acii string. Allocate the result.
3070 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3071 __ tst(r1, Operand(kStringEncodingMask));
3072 __ b(eq, &two_byte_sequential);
3074 // Allocate and copy the resulting one-byte string.
3075 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
3077 // Locate first character of substring to copy.
3079 // Locate first character of result.
3080 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3082 // r0: result string
3083 // r1: first character of result string
3084 // r2: result string length
3085 // r5: first character of substring to copy
3086 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3087 StringHelper::GenerateCopyCharacters(
3088 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
3091 // Allocate and copy the resulting two-byte string.
3092 __ bind(&two_byte_sequential);
3093 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
3095 // Locate first character of substring to copy.
3096 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3097 __ add(r5, r5, Operand(r3, LSL, 1));
3098 // Locate first character of result.
3099 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3101 // r0: result string.
3102 // r1: first character of result.
3103 // r2: result length.
3104 // r5: first character of substring to copy.
3105 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3106 StringHelper::GenerateCopyCharacters(
3107 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
3109 __ bind(&return_r0);
3110 Counters* counters = isolate()->counters();
3111 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
3115 // Just jump to runtime to create the sub string.
3117 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3119 __ bind(&single_char);
3120 // r0: original string
3121 // r1: instance type
3123 // r3: from index (untagged)
3125 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
3126 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3127 generator.GenerateFast(masm);
3130 generator.SkipSlow(masm, &runtime);
3134 void ToNumberStub::Generate(MacroAssembler* masm) {
3135 // The ToNumber stub takes one argument in r0.
3137 __ JumpIfNotSmi(r0, ¬_smi);
3141 __ CompareObjectType(r0, r1, r1, HEAP_NUMBER_TYPE);
3143 // r1: receiver instance type
3146 Label not_string, slow_string;
3147 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
3148 __ b(hs, ¬_string);
3149 // Check if string has a cached array index.
3150 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
3151 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
3152 __ b(ne, &slow_string);
3153 __ IndexFromHash(r2, r0);
3155 __ bind(&slow_string);
3156 __ push(r0); // Push argument.
3157 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3158 __ bind(¬_string);
3161 __ cmp(r1, Operand(ODDBALL_TYPE));
3162 __ b(ne, ¬_oddball);
3163 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
3165 __ bind(¬_oddball);
3167 __ push(r0); // Push argument.
3168 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3172 void ToStringStub::Generate(MacroAssembler* masm) {
3173 // The ToString stub takes one argument in r0.
3175 __ JumpIfSmi(r0, &is_number);
3177 __ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE);
3179 // r1: receiver instance type
3182 Label not_heap_number;
3183 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
3184 __ b(ne, ¬_heap_number);
3185 __ bind(&is_number);
3186 NumberToStringStub stub(isolate());
3187 __ TailCallStub(&stub);
3188 __ bind(¬_heap_number);
3191 __ cmp(r1, Operand(ODDBALL_TYPE));
3192 __ b(ne, ¬_oddball);
3193 __ ldr(r0, FieldMemOperand(r0, Oddball::kToStringOffset));
3195 __ bind(¬_oddball);
3197 __ push(r0); // Push argument.
3198 __ TailCallRuntime(Runtime::kToString, 1, 1);
3202 void StringHelper::GenerateFlatOneByteStringEquals(
3203 MacroAssembler* masm, Register left, Register right, Register scratch1,
3204 Register scratch2, Register scratch3) {
3205 Register length = scratch1;
3208 Label strings_not_equal, check_zero_length;
3209 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
3210 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3211 __ cmp(length, scratch2);
3212 __ b(eq, &check_zero_length);
3213 __ bind(&strings_not_equal);
3214 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
3217 // Check if the length is zero.
3218 Label compare_chars;
3219 __ bind(&check_zero_length);
3220 STATIC_ASSERT(kSmiTag == 0);
3221 __ cmp(length, Operand::Zero());
3222 __ b(ne, &compare_chars);
3223 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3226 // Compare characters.
3227 __ bind(&compare_chars);
3228 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3229 &strings_not_equal);
3231 // Characters are equal.
3232 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3237 void StringHelper::GenerateCompareFlatOneByteStrings(
3238 MacroAssembler* masm, Register left, Register right, Register scratch1,
3239 Register scratch2, Register scratch3, Register scratch4) {
3240 Label result_not_equal, compare_lengths;
3241 // Find minimum length and length difference.
3242 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3243 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3244 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
3245 Register length_delta = scratch3;
3246 __ mov(scratch1, scratch2, LeaveCC, gt);
3247 Register min_length = scratch1;
3248 STATIC_ASSERT(kSmiTag == 0);
3249 __ cmp(min_length, Operand::Zero());
3250 __ b(eq, &compare_lengths);
3253 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3254 scratch4, &result_not_equal);
3256 // Compare lengths - strings up to min-length are equal.
3257 __ bind(&compare_lengths);
3258 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3259 // Use length_delta as result if it's zero.
3260 __ mov(r0, Operand(length_delta), SetCC);
3261 __ bind(&result_not_equal);
3262 // Conditionally update the result based either on length_delta or
3263 // the last comparion performed in the loop above.
3264 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
3265 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
3270 void StringHelper::GenerateOneByteCharsCompareLoop(
3271 MacroAssembler* masm, Register left, Register right, Register length,
3272 Register scratch1, Register scratch2, Label* chars_not_equal) {
3273 // Change index to run from -length to -1 by adding length to string
3274 // start. This means that loop ends when index reaches zero, which
3275 // doesn't need an additional compare.
3276 __ SmiUntag(length);
3277 __ add(scratch1, length,
3278 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3279 __ add(left, left, Operand(scratch1));
3280 __ add(right, right, Operand(scratch1));
3281 __ rsb(length, length, Operand::Zero());
3282 Register index = length; // index = -length;
3287 __ ldrb(scratch1, MemOperand(left, index));
3288 __ ldrb(scratch2, MemOperand(right, index));
3289 __ cmp(scratch1, scratch2);
3290 __ b(ne, chars_not_equal);
3291 __ add(index, index, Operand(1), SetCC);
3296 void StringCompareStub::Generate(MacroAssembler* masm) {
3297 // ----------- S t a t e -------------
3300 // -- lr : return address
3301 // -----------------------------------
3302 __ AssertString(r1);
3303 __ AssertString(r0);
3307 __ b(ne, ¬_same);
3308 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3309 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r1,
3315 // Check that both objects are sequential one-byte strings.
3317 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
3319 // Compare flat one-byte strings natively.
3320 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
3322 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
3324 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3325 // tagged as a small integer.
3328 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3332 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3333 // ----------- S t a t e -------------
3336 // -- lr : return address
3337 // -----------------------------------
3339 // Load r2 with the allocation site. We stick an undefined dummy value here
3340 // and replace it with the real allocation site later when we instantiate this
3341 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3342 __ Move(r2, handle(isolate()->heap()->undefined_value()));
3344 // Make sure that we actually patched the allocation site.
3345 if (FLAG_debug_code) {
3346 __ tst(r2, Operand(kSmiTagMask));
3347 __ Assert(ne, kExpectedAllocationSite);
3349 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3350 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3353 __ Assert(eq, kExpectedAllocationSite);
3356 // Tail call into the stub that handles binary operations with allocation
3358 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3359 __ TailCallStub(&stub);
3363 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3364 DCHECK(state() == CompareICState::SMI);
3367 __ JumpIfNotSmi(r2, &miss);
3369 if (GetCondition() == eq) {
3370 // For equality we do not care about the sign of the result.
3371 __ sub(r0, r0, r1, SetCC);
3373 // Untag before subtracting to avoid handling overflow.
3375 __ sub(r0, r1, Operand::SmiUntag(r0));
3384 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3385 DCHECK(state() == CompareICState::NUMBER);
3388 Label unordered, maybe_undefined1, maybe_undefined2;
3391 if (left() == CompareICState::SMI) {
3392 __ JumpIfNotSmi(r1, &miss);
3394 if (right() == CompareICState::SMI) {
3395 __ JumpIfNotSmi(r0, &miss);
3398 // Inlining the double comparison and falling back to the general compare
3399 // stub if NaN is involved.
3400 // Load left and right operand.
3401 Label done, left, left_smi, right_smi;
3402 __ JumpIfSmi(r0, &right_smi);
3403 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3405 __ sub(r2, r0, Operand(kHeapObjectTag));
3406 __ vldr(d1, r2, HeapNumber::kValueOffset);
3408 __ bind(&right_smi);
3409 __ SmiToDouble(d1, r0);
3412 __ JumpIfSmi(r1, &left_smi);
3413 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3415 __ sub(r2, r1, Operand(kHeapObjectTag));
3416 __ vldr(d0, r2, HeapNumber::kValueOffset);
3419 __ SmiToDouble(d0, r1);
3422 // Compare operands.
3423 __ VFPCompareAndSetFlags(d0, d1);
3425 // Don't base result on status bits when a NaN is involved.
3426 __ b(vs, &unordered);
3428 // Return a result of -1, 0, or 1, based on status bits.
3429 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
3430 __ mov(r0, Operand(LESS), LeaveCC, lt);
3431 __ mov(r0, Operand(GREATER), LeaveCC, gt);
3434 __ bind(&unordered);
3435 __ bind(&generic_stub);
3436 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3437 CompareICState::GENERIC, CompareICState::GENERIC);
3438 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3440 __ bind(&maybe_undefined1);
3441 if (Token::IsOrderedRelationalCompareOp(op())) {
3442 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3444 __ JumpIfSmi(r1, &unordered);
3445 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3446 __ b(ne, &maybe_undefined2);
3450 __ bind(&maybe_undefined2);
3451 if (Token::IsOrderedRelationalCompareOp(op())) {
3452 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3453 __ b(eq, &unordered);
3461 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3462 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3465 // Registers containing left and right operands respectively.
3467 Register right = r0;
3471 // Check that both operands are heap objects.
3472 __ JumpIfEitherSmi(left, right, &miss);
3474 // Check that both operands are internalized strings.
3475 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3476 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3477 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3478 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3479 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3480 __ orr(tmp1, tmp1, Operand(tmp2));
3481 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3484 // Internalized strings are compared by identity.
3485 __ cmp(left, right);
3486 // Make sure r0 is non-zero. At this point input operands are
3487 // guaranteed to be non-zero.
3488 DCHECK(right.is(r0));
3489 STATIC_ASSERT(EQUAL == 0);
3490 STATIC_ASSERT(kSmiTag == 0);
3491 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3499 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3500 DCHECK(state() == CompareICState::UNIQUE_NAME);
3501 DCHECK(GetCondition() == eq);
3504 // Registers containing left and right operands respectively.
3506 Register right = r0;
3510 // Check that both operands are heap objects.
3511 __ JumpIfEitherSmi(left, right, &miss);
3513 // Check that both operands are unique names. This leaves the instance
3514 // types loaded in tmp1 and tmp2.
3515 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3516 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3517 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3518 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3520 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3521 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3523 // Unique names are compared by identity.
3524 __ cmp(left, right);
3525 // Make sure r0 is non-zero. At this point input operands are
3526 // guaranteed to be non-zero.
3527 DCHECK(right.is(r0));
3528 STATIC_ASSERT(EQUAL == 0);
3529 STATIC_ASSERT(kSmiTag == 0);
3530 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3538 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3539 DCHECK(state() == CompareICState::STRING);
3542 bool equality = Token::IsEqualityOp(op());
3544 // Registers containing left and right operands respectively.
3546 Register right = r0;
3552 // Check that both operands are heap objects.
3553 __ JumpIfEitherSmi(left, right, &miss);
3555 // Check that both operands are strings. This leaves the instance
3556 // types loaded in tmp1 and tmp2.
3557 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3558 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3559 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3560 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3561 STATIC_ASSERT(kNotStringTag != 0);
3562 __ orr(tmp3, tmp1, tmp2);
3563 __ tst(tmp3, Operand(kIsNotStringMask));
3566 // Fast check for identical strings.
3567 __ cmp(left, right);
3568 STATIC_ASSERT(EQUAL == 0);
3569 STATIC_ASSERT(kSmiTag == 0);
3570 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3573 // Handle not identical strings.
3575 // Check that both strings are internalized strings. If they are, we're done
3576 // because we already know they are not identical. We know they are both
3579 DCHECK(GetCondition() == eq);
3580 STATIC_ASSERT(kInternalizedTag == 0);
3581 __ orr(tmp3, tmp1, Operand(tmp2));
3582 __ tst(tmp3, Operand(kIsNotInternalizedMask));
3583 // Make sure r0 is non-zero. At this point input operands are
3584 // guaranteed to be non-zero.
3585 DCHECK(right.is(r0));
3589 // Check that both strings are sequential one-byte.
3591 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3594 // Compare flat one-byte strings. Returns when done.
3596 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3599 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3603 // Handle more complex cases in runtime.
3605 __ Push(left, right);
3607 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3609 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3617 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3618 DCHECK(state() == CompareICState::OBJECT);
3620 __ and_(r2, r1, Operand(r0));
3621 __ JumpIfSmi(r2, &miss);
3623 __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
3625 __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
3628 DCHECK(GetCondition() == eq);
3629 __ sub(r0, r0, Operand(r1));
3637 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3639 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3640 __ and_(r2, r1, Operand(r0));
3641 __ JumpIfSmi(r2, &miss);
3642 __ GetWeakValue(r4, cell);
3643 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3644 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
3650 if (Token::IsEqualityOp(op())) {
3651 __ sub(r0, r0, Operand(r1));
3653 } else if (is_strong(strength())) {
3654 __ TailCallRuntime(Runtime::kThrowStrongModeImplicitConversion, 0, 1);
3656 if (op() == Token::LT || op() == Token::LTE) {
3657 __ mov(r2, Operand(Smi::FromInt(GREATER)));
3659 __ mov(r2, Operand(Smi::FromInt(LESS)));
3661 __ Push(r1, r0, r2);
3662 __ TailCallRuntime(Runtime::kCompare, 3, 1);
3670 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3672 // Call the runtime system in a fresh internal frame.
3673 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3675 __ Push(lr, r1, r0);
3676 __ mov(ip, Operand(Smi::FromInt(op())));
3678 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3679 // Compute the entry point of the rewritten stub.
3680 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3681 // Restore registers.
3690 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3691 // Place the return address on the stack, making the call
3692 // GC safe. The RegExp backend also relies on this.
3693 __ str(lr, MemOperand(sp, 0));
3694 __ blx(ip); // Call the C++ function.
3695 __ VFPEnsureFPSCRState(r2);
3696 __ ldr(pc, MemOperand(sp, 0));
3700 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3703 reinterpret_cast<intptr_t>(GetCode().location());
3704 __ Move(ip, target);
3705 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3706 __ blx(lr); // Call the stub.
3710 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3714 Register properties,
3716 Register scratch0) {
3717 DCHECK(name->IsUniqueName());
3718 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3719 // not equal to the name and kProbes-th slot is not used (its name is the
3720 // undefined value), it guarantees the hash table doesn't contain the
3721 // property. It's true even if some slots represent deleted properties
3722 // (their names are the hole value).
3723 for (int i = 0; i < kInlinedProbes; i++) {
3724 // scratch0 points to properties hash.
3725 // Compute the masked index: (hash + i + i * i) & mask.
3726 Register index = scratch0;
3727 // Capacity is smi 2^n.
3728 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3729 __ sub(index, index, Operand(1));
3730 __ and_(index, index, Operand(
3731 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3733 // Scale the index by multiplying by the entry size.
3734 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3735 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3737 Register entity_name = scratch0;
3738 // Having undefined at this place means the name is not contained.
3739 STATIC_ASSERT(kSmiTagSize == 1);
3740 Register tmp = properties;
3741 __ add(tmp, properties, Operand(index, LSL, 1));
3742 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3744 DCHECK(!tmp.is(entity_name));
3745 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3746 __ cmp(entity_name, tmp);
3749 // Load the hole ready for use below:
3750 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3752 // Stop if found the property.
3753 __ cmp(entity_name, Operand(Handle<Name>(name)));
3757 __ cmp(entity_name, tmp);
3760 // Check if the entry name is not a unique name.
3761 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3762 __ ldrb(entity_name,
3763 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3764 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3767 // Restore the properties.
3769 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3772 const int spill_mask =
3773 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3774 r2.bit() | r1.bit() | r0.bit());
3776 __ stm(db_w, sp, spill_mask);
3777 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3778 __ mov(r1, Operand(Handle<Name>(name)));
3779 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3781 __ cmp(r0, Operand::Zero());
3782 __ ldm(ia_w, sp, spill_mask);
3789 // Probe the name dictionary in the |elements| register. Jump to the
3790 // |done| label if a property with the given name is found. Jump to
3791 // the |miss| label otherwise.
3792 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
3793 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3799 Register scratch2) {
3800 DCHECK(!elements.is(scratch1));
3801 DCHECK(!elements.is(scratch2));
3802 DCHECK(!name.is(scratch1));
3803 DCHECK(!name.is(scratch2));
3805 __ AssertName(name);
3807 // Compute the capacity mask.
3808 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
3809 __ SmiUntag(scratch1);
3810 __ sub(scratch1, scratch1, Operand(1));
3812 // Generate an unrolled loop that performs a few probes before
3813 // giving up. Measurements done on Gmail indicate that 2 probes
3814 // cover ~93% of loads from dictionaries.
3815 for (int i = 0; i < kInlinedProbes; i++) {
3816 // Compute the masked index: (hash + i + i * i) & mask.
3817 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3819 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3820 // the hash in a separate instruction. The value hash + i + i * i is right
3821 // shifted in the following and instruction.
3822 DCHECK(NameDictionary::GetProbeOffset(i) <
3823 1 << (32 - Name::kHashFieldOffset));
3824 __ add(scratch2, scratch2, Operand(
3825 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3827 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
3829 // Scale the index by multiplying by the entry size.
3830 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3831 // scratch2 = scratch2 * 3.
3832 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3834 // Check if the key is identical to the name.
3835 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3836 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3837 __ cmp(name, Operand(ip));
3841 const int spill_mask =
3842 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3843 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3844 ~(scratch1.bit() | scratch2.bit());
3846 __ stm(db_w, sp, spill_mask);
3848 DCHECK(!elements.is(r1));
3850 __ Move(r0, elements);
3852 __ Move(r0, elements);
3855 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
3857 __ cmp(r0, Operand::Zero());
3858 __ mov(scratch2, Operand(r2));
3859 __ ldm(ia_w, sp, spill_mask);
3866 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3867 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3868 // we cannot call anything that could cause a GC from this stub.
3870 // result: NameDictionary to probe
3872 // dictionary: NameDictionary to probe.
3873 // index: will hold an index of entry if lookup is successful.
3874 // might alias with result_.
3876 // result_ is zero if lookup failed, non zero otherwise.
3878 Register result = r0;
3879 Register dictionary = r0;
3881 Register index = r2;
3884 Register undefined = r5;
3885 Register entry_key = r6;
3887 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3889 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
3891 __ sub(mask, mask, Operand(1));
3893 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
3895 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3897 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3898 // Compute the masked index: (hash + i + i * i) & mask.
3899 // Capacity is smi 2^n.
3901 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3902 // the hash in a separate instruction. The value hash + i + i * i is right
3903 // shifted in the following and instruction.
3904 DCHECK(NameDictionary::GetProbeOffset(i) <
3905 1 << (32 - Name::kHashFieldOffset));
3906 __ add(index, hash, Operand(
3907 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3909 __ mov(index, Operand(hash));
3911 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
3913 // Scale the index by multiplying by the entry size.
3914 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3915 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3917 STATIC_ASSERT(kSmiTagSize == 1);
3918 __ add(index, dictionary, Operand(index, LSL, 2));
3919 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
3921 // Having undefined at this place means the name is not contained.
3922 __ cmp(entry_key, Operand(undefined));
3923 __ b(eq, ¬_in_dictionary);
3925 // Stop if found the property.
3926 __ cmp(entry_key, Operand(key));
3927 __ b(eq, &in_dictionary);
3929 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3930 // Check if the entry name is not a unique name.
3931 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3933 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
3934 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
3938 __ bind(&maybe_in_dictionary);
3939 // If we are doing negative lookup then probing failure should be
3940 // treated as a lookup success. For positive lookup probing failure
3941 // should be treated as lookup failure.
3942 if (mode() == POSITIVE_LOOKUP) {
3943 __ mov(result, Operand::Zero());
3947 __ bind(&in_dictionary);
3948 __ mov(result, Operand(1));
3951 __ bind(¬_in_dictionary);
3952 __ mov(result, Operand::Zero());
3957 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3959 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3961 // Hydrogen code stubs need stub2 at snapshot time.
3962 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3967 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
3968 // the value has just been written into the object, now this stub makes sure
3969 // we keep the GC informed. The word in the object where the value has been
3970 // written is in the address register.
3971 void RecordWriteStub::Generate(MacroAssembler* masm) {
3972 Label skip_to_incremental_noncompacting;
3973 Label skip_to_incremental_compacting;
3975 // The first two instructions are generated with labels so as to get the
3976 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3977 // forth between a compare instructions (a nop in this position) and the
3978 // real branch when we start and stop incremental heap marking.
3979 // See RecordWriteStub::Patch for details.
3981 // Block literal pool emission, as the position of these two instructions
3982 // is assumed by the patching code.
3983 Assembler::BlockConstPoolScope block_const_pool(masm);
3984 __ b(&skip_to_incremental_noncompacting);
3985 __ b(&skip_to_incremental_compacting);
3988 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3989 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3990 MacroAssembler::kReturnAtEnd);
3994 __ bind(&skip_to_incremental_noncompacting);
3995 GenerateIncremental(masm, INCREMENTAL);
3997 __ bind(&skip_to_incremental_compacting);
3998 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4000 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4001 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4002 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4003 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
4004 PatchBranchIntoNop(masm, 0);
4005 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4009 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4012 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4013 Label dont_need_remembered_set;
4015 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4016 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4018 &dont_need_remembered_set);
4020 __ CheckPageFlag(regs_.object(),
4022 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4024 &dont_need_remembered_set);
4026 // First notify the incremental marker if necessary, then update the
4028 CheckNeedsToInformIncrementalMarker(
4029 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4030 InformIncrementalMarker(masm);
4031 regs_.Restore(masm);
4032 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4033 MacroAssembler::kReturnAtEnd);
4035 __ bind(&dont_need_remembered_set);
4038 CheckNeedsToInformIncrementalMarker(
4039 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4040 InformIncrementalMarker(masm);
4041 regs_.Restore(masm);
4046 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4047 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4048 int argument_count = 3;
4049 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4051 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4052 DCHECK(!address.is(regs_.object()));
4053 DCHECK(!address.is(r0));
4054 __ Move(address, regs_.address());
4055 __ Move(r0, regs_.object());
4056 __ Move(r1, address);
4057 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4059 AllowExternalCallThatCantCauseGC scope(masm);
4061 ExternalReference::incremental_marking_record_write_function(isolate()),
4063 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4067 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4068 MacroAssembler* masm,
4069 OnNoNeedToInformIncrementalMarker on_no_need,
4072 Label need_incremental;
4073 Label need_incremental_pop_scratch;
4075 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4076 __ ldr(regs_.scratch1(),
4077 MemOperand(regs_.scratch0(),
4078 MemoryChunk::kWriteBarrierCounterOffset));
4079 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4080 __ str(regs_.scratch1(),
4081 MemOperand(regs_.scratch0(),
4082 MemoryChunk::kWriteBarrierCounterOffset));
4083 __ b(mi, &need_incremental);
4085 // Let's look at the color of the object: If it is not black we don't have
4086 // to inform the incremental marker.
4087 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4089 regs_.Restore(masm);
4090 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4091 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4092 MacroAssembler::kReturnAtEnd);
4099 // Get the value from the slot.
4100 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4102 if (mode == INCREMENTAL_COMPACTION) {
4103 Label ensure_not_white;
4105 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4106 regs_.scratch1(), // Scratch.
4107 MemoryChunk::kEvacuationCandidateMask,
4111 __ CheckPageFlag(regs_.object(),
4112 regs_.scratch1(), // Scratch.
4113 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4117 __ bind(&ensure_not_white);
4120 // We need extra registers for this, so we push the object and the address
4121 // register temporarily.
4122 __ Push(regs_.object(), regs_.address());
4123 __ EnsureNotWhite(regs_.scratch0(), // The value.
4124 regs_.scratch1(), // Scratch.
4125 regs_.object(), // Scratch.
4126 regs_.address(), // Scratch.
4127 &need_incremental_pop_scratch);
4128 __ Pop(regs_.object(), regs_.address());
4130 regs_.Restore(masm);
4131 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4132 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4133 MacroAssembler::kReturnAtEnd);
4138 __ bind(&need_incremental_pop_scratch);
4139 __ Pop(regs_.object(), regs_.address());
4141 __ bind(&need_incremental);
4143 // Fall through when we need to inform the incremental marker.
4147 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4148 // ----------- S t a t e -------------
4149 // -- r0 : element value to store
4150 // -- r3 : element index as smi
4151 // -- sp[0] : array literal index in function as smi
4152 // -- sp[4] : array literal
4153 // clobbers r1, r2, r4
4154 // -----------------------------------
4157 Label double_elements;
4159 Label slow_elements;
4160 Label fast_elements;
4162 // Get array literal index, array literal and its map.
4163 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4164 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4165 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4167 __ CheckFastElements(r2, r5, &double_elements);
4168 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4169 __ JumpIfSmi(r0, &smi_element);
4170 __ CheckFastSmiElements(r2, r5, &fast_elements);
4172 // Store into the array literal requires a elements transition. Call into
4174 __ bind(&slow_elements);
4176 __ Push(r1, r3, r0);
4177 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4178 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4180 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4182 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4183 __ bind(&fast_elements);
4184 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4185 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4186 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4187 __ str(r0, MemOperand(r6, 0));
4188 // Update the write barrier for the array store.
4189 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4190 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4193 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4194 // and value is Smi.
4195 __ bind(&smi_element);
4196 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4197 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4198 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4201 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4202 __ bind(&double_elements);
4203 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4204 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
4209 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4210 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4211 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4212 int parameter_count_offset =
4213 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4214 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4215 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4216 __ add(r1, r1, Operand(1));
4218 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4219 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4225 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4226 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4227 LoadICStub stub(isolate(), state());
4228 stub.GenerateForTrampoline(masm);
4232 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4233 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4234 KeyedLoadICStub stub(isolate(), state());
4235 stub.GenerateForTrampoline(masm);
4239 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4240 EmitLoadTypeFeedbackVector(masm, r2);
4241 CallICStub stub(isolate(), state());
4242 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4246 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4249 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4250 GenerateImpl(masm, true);
4254 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4255 Register receiver_map, Register scratch1,
4256 Register scratch2, bool is_polymorphic,
4258 // feedback initially contains the feedback array
4259 Label next_loop, prepare_next;
4260 Label start_polymorphic;
4262 Register cached_map = scratch1;
4265 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4266 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4267 __ cmp(receiver_map, cached_map);
4268 __ b(ne, &start_polymorphic);
4269 // found, now call handler.
4270 Register handler = feedback;
4271 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4272 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4275 Register length = scratch2;
4276 __ bind(&start_polymorphic);
4277 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4278 if (!is_polymorphic) {
4279 // If the IC could be monomorphic we have to make sure we don't go past the
4280 // end of the feedback array.
4281 __ cmp(length, Operand(Smi::FromInt(2)));
4285 Register too_far = length;
4286 Register pointer_reg = feedback;
4288 // +-----+------+------+-----+-----+ ... ----+
4289 // | map | len | wm0 | h0 | wm1 | hN |
4290 // +-----+------+------+-----+-----+ ... ----+
4294 // pointer_reg too_far
4295 // aka feedback scratch2
4296 // also need receiver_map
4297 // use cached_map (scratch1) to look in the weak map values.
4298 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
4299 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4300 __ add(pointer_reg, feedback,
4301 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4303 __ bind(&next_loop);
4304 __ ldr(cached_map, MemOperand(pointer_reg));
4305 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4306 __ cmp(receiver_map, cached_map);
4307 __ b(ne, &prepare_next);
4308 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
4309 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4311 __ bind(&prepare_next);
4312 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4313 __ cmp(pointer_reg, too_far);
4314 __ b(lt, &next_loop);
4316 // We exhausted our array of map handler pairs.
4321 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4322 Register receiver_map, Register feedback,
4323 Register vector, Register slot,
4324 Register scratch, Label* compare_map,
4325 Label* load_smi_map, Label* try_array) {
4326 __ JumpIfSmi(receiver, load_smi_map);
4327 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4328 __ bind(compare_map);
4329 Register cached_map = scratch;
4330 // Move the weak map into the weak_cell register.
4331 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4332 __ cmp(cached_map, receiver_map);
4333 __ b(ne, try_array);
4334 Register handler = feedback;
4335 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
4337 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4338 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4342 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4343 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4344 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
4345 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4346 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4347 Register feedback = r4;
4348 Register receiver_map = r5;
4349 Register scratch1 = r6;
4351 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4352 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4354 // Try to quickly handle the monomorphic case without knowing for sure
4355 // if we have a weak cell in feedback. We do know it's safe to look
4356 // at WeakCell::kValueOffset.
4357 Label try_array, load_smi_map, compare_map;
4358 Label not_array, miss;
4359 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4360 scratch1, &compare_map, &load_smi_map, &try_array);
4362 // Is it a fixed array?
4363 __ bind(&try_array);
4364 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4365 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4366 __ b(ne, ¬_array);
4367 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4369 __ bind(¬_array);
4370 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4372 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4373 Code::ComputeHandlerFlags(Code::LOAD_IC));
4374 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4375 receiver, name, feedback,
4376 receiver_map, scratch1, r9);
4379 LoadIC::GenerateMiss(masm);
4381 __ bind(&load_smi_map);
4382 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4383 __ jmp(&compare_map);
4387 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4388 GenerateImpl(masm, false);
4392 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4393 GenerateImpl(masm, true);
4397 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4398 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4399 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
4400 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4401 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4402 Register feedback = r4;
4403 Register receiver_map = r5;
4404 Register scratch1 = r6;
4406 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4407 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4409 // Try to quickly handle the monomorphic case without knowing for sure
4410 // if we have a weak cell in feedback. We do know it's safe to look
4411 // at WeakCell::kValueOffset.
4412 Label try_array, load_smi_map, compare_map;
4413 Label not_array, miss;
4414 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4415 scratch1, &compare_map, &load_smi_map, &try_array);
4417 __ bind(&try_array);
4418 // Is it a fixed array?
4419 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4420 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4421 __ b(ne, ¬_array);
4423 // We have a polymorphic element handler.
4424 Label polymorphic, try_poly_name;
4425 __ bind(&polymorphic);
4426 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
4428 __ bind(¬_array);
4430 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4431 __ b(ne, &try_poly_name);
4432 Handle<Code> megamorphic_stub =
4433 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4434 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4436 __ bind(&try_poly_name);
4437 // We might have a name in feedback, and a fixed array in the next slot.
4438 __ cmp(key, feedback);
4440 // If the name comparison succeeded, we know we have a fixed array with
4441 // at least one map/handler pair.
4442 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4444 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4445 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, false, &miss);
4448 KeyedLoadIC::GenerateMiss(masm);
4450 __ bind(&load_smi_map);
4451 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4452 __ jmp(&compare_map);
4456 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4457 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4458 VectorStoreICStub stub(isolate(), state());
4459 stub.GenerateForTrampoline(masm);
4463 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4464 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4465 VectorKeyedStoreICStub stub(isolate(), state());
4466 stub.GenerateForTrampoline(masm);
4470 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4471 GenerateImpl(masm, false);
4475 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4476 GenerateImpl(masm, true);
4480 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4481 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4482 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4483 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4484 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4485 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4486 Register feedback = r5;
4487 Register receiver_map = r6;
4488 Register scratch1 = r9;
4490 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4491 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4493 // Try to quickly handle the monomorphic case without knowing for sure
4494 // if we have a weak cell in feedback. We do know it's safe to look
4495 // at WeakCell::kValueOffset.
4496 Label try_array, load_smi_map, compare_map;
4497 Label not_array, miss;
4498 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4499 scratch1, &compare_map, &load_smi_map, &try_array);
4501 // Is it a fixed array?
4502 __ bind(&try_array);
4503 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4504 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4505 __ b(ne, ¬_array);
4507 // We are using register r8, which is used for the embedded constant pool
4508 // when FLAG_enable_embedded_constant_pool is true.
4509 DCHECK(!FLAG_enable_embedded_constant_pool);
4510 Register scratch2 = r8;
4511 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4514 __ bind(¬_array);
4515 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4517 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4518 Code::ComputeHandlerFlags(Code::STORE_IC));
4519 masm->isolate()->stub_cache()->GenerateProbe(
4520 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4521 scratch1, scratch2);
4524 StoreIC::GenerateMiss(masm);
4526 __ bind(&load_smi_map);
4527 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4528 __ jmp(&compare_map);
4532 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4533 GenerateImpl(masm, false);
4537 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4538 GenerateImpl(masm, true);
4542 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4543 Register receiver_map, Register scratch1,
4544 Register scratch2, Label* miss) {
4545 // feedback initially contains the feedback array
4546 Label next_loop, prepare_next;
4547 Label start_polymorphic;
4548 Label transition_call;
4550 Register cached_map = scratch1;
4551 Register too_far = scratch2;
4552 Register pointer_reg = feedback;
4553 __ ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4555 // +-----+------+------+-----+-----+-----+ ... ----+
4556 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4557 // +-----+------+------+-----+-----+ ----+ ... ----+
4561 // pointer_reg too_far
4562 // aka feedback scratch2
4563 // also need receiver_map
4564 // use cached_map (scratch1) to look in the weak map values.
4565 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(too_far));
4566 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4567 __ add(pointer_reg, feedback,
4568 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4570 __ bind(&next_loop);
4571 __ ldr(cached_map, MemOperand(pointer_reg));
4572 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4573 __ cmp(receiver_map, cached_map);
4574 __ b(ne, &prepare_next);
4575 // Is it a transitioning store?
4576 __ ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4577 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4578 __ b(ne, &transition_call);
4579 __ ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4580 __ add(pc, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4582 __ bind(&transition_call);
4583 __ ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4584 __ JumpIfSmi(too_far, miss);
4586 __ ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4588 // Load the map into the correct register.
4589 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4590 __ mov(feedback, too_far);
4592 __ add(pc, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4594 __ bind(&prepare_next);
4595 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4596 __ cmp(pointer_reg, too_far);
4597 __ b(lt, &next_loop);
4599 // We exhausted our array of map handler pairs.
4604 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4605 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4606 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4607 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4608 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4609 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4610 Register feedback = r5;
4611 Register receiver_map = r6;
4612 Register scratch1 = r9;
4614 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4615 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4617 // Try to quickly handle the monomorphic case without knowing for sure
4618 // if we have a weak cell in feedback. We do know it's safe to look
4619 // at WeakCell::kValueOffset.
4620 Label try_array, load_smi_map, compare_map;
4621 Label not_array, miss;
4622 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4623 scratch1, &compare_map, &load_smi_map, &try_array);
4625 __ bind(&try_array);
4626 // Is it a fixed array?
4627 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4628 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4629 __ b(ne, ¬_array);
4631 // We have a polymorphic element handler.
4632 Label polymorphic, try_poly_name;
4633 __ bind(&polymorphic);
4635 // We are using register r8, which is used for the embedded constant pool
4636 // when FLAG_enable_embedded_constant_pool is true.
4637 DCHECK(!FLAG_enable_embedded_constant_pool);
4638 Register scratch2 = r8;
4640 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4643 __ bind(¬_array);
4645 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4646 __ b(ne, &try_poly_name);
4647 Handle<Code> megamorphic_stub =
4648 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4649 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4651 __ bind(&try_poly_name);
4652 // We might have a name in feedback, and a fixed array in the next slot.
4653 __ cmp(key, feedback);
4655 // If the name comparison succeeded, we know we have a fixed array with
4656 // at least one map/handler pair.
4657 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4659 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4660 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4664 KeyedStoreIC::GenerateMiss(masm);
4666 __ bind(&load_smi_map);
4667 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4668 __ jmp(&compare_map);
4672 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4673 if (masm->isolate()->function_entry_hook() != NULL) {
4674 ProfileEntryHookStub stub(masm->isolate());
4675 PredictableCodeSizeScope predictable(masm);
4676 predictable.ExpectSize(masm->CallStubSize(&stub) +
4677 2 * Assembler::kInstrSize);
4685 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4686 // The entry hook is a "push lr" instruction, followed by a call.
4687 const int32_t kReturnAddressDistanceFromFunctionStart =
4688 3 * Assembler::kInstrSize;
4690 // This should contain all kCallerSaved registers.
4691 const RegList kSavedRegs =
4698 // We also save lr, so the count here is one higher than the mask indicates.
4699 const int32_t kNumSavedRegs = 7;
4701 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4703 // Save all caller-save registers as this may be called from anywhere.
4704 __ stm(db_w, sp, kSavedRegs | lr.bit());
4706 // Compute the function's address for the first argument.
4707 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4709 // The caller's return address is above the saved temporaries.
4710 // Grab that for the second argument to the hook.
4711 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4713 // Align the stack if necessary.
4714 int frame_alignment = masm->ActivationFrameAlignment();
4715 if (frame_alignment > kPointerSize) {
4717 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4718 __ and_(sp, sp, Operand(-frame_alignment));
4721 #if V8_HOST_ARCH_ARM
4722 int32_t entry_hook =
4723 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4724 __ mov(ip, Operand(entry_hook));
4726 // Under the simulator we need to indirect the entry hook through a
4727 // trampoline function at a known address.
4728 // It additionally takes an isolate as a third parameter
4729 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4731 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4732 __ mov(ip, Operand(ExternalReference(&dispatcher,
4733 ExternalReference::BUILTIN_CALL,
4738 // Restore the stack pointer if needed.
4739 if (frame_alignment > kPointerSize) {
4743 // Also pop pc to get Ret(0).
4744 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4749 static void CreateArrayDispatch(MacroAssembler* masm,
4750 AllocationSiteOverrideMode mode) {
4751 if (mode == DISABLE_ALLOCATION_SITES) {
4752 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4753 __ TailCallStub(&stub);
4754 } else if (mode == DONT_OVERRIDE) {
4755 int last_index = GetSequenceIndexFromFastElementsKind(
4756 TERMINAL_FAST_ELEMENTS_KIND);
4757 for (int i = 0; i <= last_index; ++i) {
4758 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4759 __ cmp(r3, Operand(kind));
4760 T stub(masm->isolate(), kind);
4761 __ TailCallStub(&stub, eq);
4764 // If we reached this point there is a problem.
4765 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4772 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4773 AllocationSiteOverrideMode mode) {
4774 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4775 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4776 // r0 - number of arguments
4777 // r1 - constructor?
4778 // sp[0] - last argument
4779 Label normal_sequence;
4780 if (mode == DONT_OVERRIDE) {
4781 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4782 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4783 STATIC_ASSERT(FAST_ELEMENTS == 2);
4784 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4785 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4786 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4788 // is the low bit set? If so, we are holey and that is good.
4789 __ tst(r3, Operand(1));
4790 __ b(ne, &normal_sequence);
4793 // look at the first argument
4794 __ ldr(r5, MemOperand(sp, 0));
4795 __ cmp(r5, Operand::Zero());
4796 __ b(eq, &normal_sequence);
4798 if (mode == DISABLE_ALLOCATION_SITES) {
4799 ElementsKind initial = GetInitialFastElementsKind();
4800 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4802 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4804 DISABLE_ALLOCATION_SITES);
4805 __ TailCallStub(&stub_holey);
4807 __ bind(&normal_sequence);
4808 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4810 DISABLE_ALLOCATION_SITES);
4811 __ TailCallStub(&stub);
4812 } else if (mode == DONT_OVERRIDE) {
4813 // We are going to create a holey array, but our kind is non-holey.
4814 // Fix kind and retry (only if we have an allocation site in the slot).
4815 __ add(r3, r3, Operand(1));
4817 if (FLAG_debug_code) {
4818 __ ldr(r5, FieldMemOperand(r2, 0));
4819 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4820 __ Assert(eq, kExpectedAllocationSite);
4823 // Save the resulting elements kind in type info. We can't just store r3
4824 // in the AllocationSite::transition_info field because elements kind is
4825 // restricted to a portion of the field...upper bits need to be left alone.
4826 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4827 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4828 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4829 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4831 __ bind(&normal_sequence);
4832 int last_index = GetSequenceIndexFromFastElementsKind(
4833 TERMINAL_FAST_ELEMENTS_KIND);
4834 for (int i = 0; i <= last_index; ++i) {
4835 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4836 __ cmp(r3, Operand(kind));
4837 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4838 __ TailCallStub(&stub, eq);
4841 // If we reached this point there is a problem.
4842 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4850 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4851 int to_index = GetSequenceIndexFromFastElementsKind(
4852 TERMINAL_FAST_ELEMENTS_KIND);
4853 for (int i = 0; i <= to_index; ++i) {
4854 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4855 T stub(isolate, kind);
4857 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4858 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4865 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4866 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4868 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4870 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4875 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4877 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4878 for (int i = 0; i < 2; i++) {
4879 // For internal arrays we only need a few things
4880 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4882 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4884 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4890 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4891 MacroAssembler* masm,
4892 AllocationSiteOverrideMode mode) {
4893 if (argument_count() == ANY) {
4894 Label not_zero_case, not_one_case;
4896 __ b(ne, ¬_zero_case);
4897 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4899 __ bind(¬_zero_case);
4900 __ cmp(r0, Operand(1));
4901 __ b(gt, ¬_one_case);
4902 CreateArrayDispatchOneArgument(masm, mode);
4904 __ bind(¬_one_case);
4905 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4906 } else if (argument_count() == NONE) {
4907 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4908 } else if (argument_count() == ONE) {
4909 CreateArrayDispatchOneArgument(masm, mode);
4910 } else if (argument_count() == MORE_THAN_ONE) {
4911 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4918 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4919 // ----------- S t a t e -------------
4920 // -- r0 : argc (only if argument_count() == ANY)
4921 // -- r1 : constructor
4922 // -- r2 : AllocationSite or undefined
4923 // -- r3 : original constructor
4924 // -- sp[0] : return address
4925 // -- sp[4] : last argument
4926 // -----------------------------------
4928 if (FLAG_debug_code) {
4929 // The array construct code is only set for the global and natives
4930 // builtin Array functions which always have maps.
4932 // Initial map for the builtin Array function should be a map.
4933 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4934 // Will both indicate a NULL and a Smi.
4935 __ tst(r4, Operand(kSmiTagMask));
4936 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4937 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4938 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4940 // We should either have undefined in r2 or a valid AllocationSite
4941 __ AssertUndefinedOrAllocationSite(r2, r4);
4946 __ b(ne, &subclassing);
4949 // Get the elements kind and case on that.
4950 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4953 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4955 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4956 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4957 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4960 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4962 __ bind(&subclassing);
4967 switch (argument_count()) {
4970 __ add(r0, r0, Operand(2));
4973 __ mov(r0, Operand(2));
4976 __ mov(r0, Operand(3));
4980 __ JumpToExternalReference(
4981 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
4985 void InternalArrayConstructorStub::GenerateCase(
4986 MacroAssembler* masm, ElementsKind kind) {
4987 __ cmp(r0, Operand(1));
4989 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4990 __ TailCallStub(&stub0, lo);
4992 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4993 __ TailCallStub(&stubN, hi);
4995 if (IsFastPackedElementsKind(kind)) {
4996 // We might need to create a holey array
4997 // look at the first argument
4998 __ ldr(r3, MemOperand(sp, 0));
4999 __ cmp(r3, Operand::Zero());
5001 InternalArraySingleArgumentConstructorStub
5002 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5003 __ TailCallStub(&stub1_holey, ne);
5006 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5007 __ TailCallStub(&stub1);
5011 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5012 // ----------- S t a t e -------------
5014 // -- r1 : constructor
5015 // -- sp[0] : return address
5016 // -- sp[4] : last argument
5017 // -----------------------------------
5019 if (FLAG_debug_code) {
5020 // The array construct code is only set for the global and natives
5021 // builtin Array functions which always have maps.
5023 // Initial map for the builtin Array function should be a map.
5024 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5025 // Will both indicate a NULL and a Smi.
5026 __ tst(r3, Operand(kSmiTagMask));
5027 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5028 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
5029 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5032 // Figure out the right elements kind
5033 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5034 // Load the map's "bit field 2" into |result|. We only need the first byte,
5035 // but the following bit field extraction takes care of that anyway.
5036 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
5037 // Retrieve elements_kind from bit field 2.
5038 __ DecodeField<Map::ElementsKindBits>(r3);
5040 if (FLAG_debug_code) {
5042 __ cmp(r3, Operand(FAST_ELEMENTS));
5044 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
5046 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5050 Label fast_elements_case;
5051 __ cmp(r3, Operand(FAST_ELEMENTS));
5052 __ b(eq, &fast_elements_case);
5053 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5055 __ bind(&fast_elements_case);
5056 GenerateCase(masm, FAST_ELEMENTS);
5060 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5061 Register context = cp;
5062 Register result = r0;
5065 // Go up the context chain to the script context.
5066 for (int i = 0; i < depth(); ++i) {
5067 __ ldr(result, ContextOperand(context, Context::PREVIOUS_INDEX));
5071 // Load the PropertyCell value at the specified slot.
5072 __ add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5073 __ ldr(result, ContextOperand(result));
5074 __ ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5076 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5077 __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
5080 // Fallback to runtime.
5083 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5087 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5088 Register value = r0;
5092 Register cell_details = r4;
5093 Register cell_value = r5;
5094 Register cell_value_map = r6;
5095 Register scratch = r9;
5097 Register context = cp;
5098 Register context_temp = cell;
5100 Label fast_heapobject_case, fast_smi_case, slow_case;
5102 if (FLAG_debug_code) {
5103 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5104 __ Check(ne, kUnexpectedValue);
5107 // Go up the context chain to the script context.
5108 for (int i = 0; i < depth(); i++) {
5109 __ ldr(context_temp, ContextOperand(context, Context::PREVIOUS_INDEX));
5110 context = context_temp;
5113 // Load the PropertyCell at the specified slot.
5114 __ add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5115 __ ldr(cell, ContextOperand(cell));
5117 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5118 __ ldr(cell_details, FieldMemOperand(cell, PropertyCell::kDetailsOffset));
5119 __ SmiUntag(cell_details);
5120 __ and_(cell_details, cell_details,
5121 Operand(PropertyDetails::PropertyCellTypeField::kMask |
5122 PropertyDetails::KindField::kMask |
5123 PropertyDetails::kAttributesReadOnlyMask));
5125 // Check if PropertyCell holds mutable data.
5126 Label not_mutable_data;
5127 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5128 PropertyCellType::kMutable) |
5129 PropertyDetails::KindField::encode(kData)));
5130 __ b(ne, ¬_mutable_data);
5131 __ JumpIfSmi(value, &fast_smi_case);
5133 __ bind(&fast_heapobject_case);
5134 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5135 // RecordWriteField clobbers the value register, so we copy it before the
5137 __ mov(r4, Operand(value));
5138 __ RecordWriteField(cell, PropertyCell::kValueOffset, r4, scratch,
5139 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5143 __ bind(¬_mutable_data);
5144 // Check if PropertyCell value matches the new value (relevant for Constant,
5145 // ConstantType and Undefined cells).
5146 Label not_same_value;
5147 __ ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5148 __ cmp(cell_value, value);
5149 __ b(ne, ¬_same_value);
5151 // Make sure the PropertyCell is not marked READ_ONLY.
5152 __ tst(cell_details, Operand(PropertyDetails::kAttributesReadOnlyMask));
5153 __ b(ne, &slow_case);
5155 if (FLAG_debug_code) {
5157 // This can only be true for Constant, ConstantType and Undefined cells,
5158 // because we never store the_hole via this stub.
5159 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5160 PropertyCellType::kConstant) |
5161 PropertyDetails::KindField::encode(kData)));
5163 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5164 PropertyCellType::kConstantType) |
5165 PropertyDetails::KindField::encode(kData)));
5167 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5168 PropertyCellType::kUndefined) |
5169 PropertyDetails::KindField::encode(kData)));
5170 __ Check(eq, kUnexpectedValue);
5174 __ bind(¬_same_value);
5176 // Check if PropertyCell contains data with constant type (and is not
5178 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5179 PropertyCellType::kConstantType) |
5180 PropertyDetails::KindField::encode(kData)));
5181 __ b(ne, &slow_case);
5183 // Now either both old and new values must be smis or both must be heap
5184 // objects with same map.
5185 Label value_is_heap_object;
5186 __ JumpIfNotSmi(value, &value_is_heap_object);
5187 __ JumpIfNotSmi(cell_value, &slow_case);
5188 // Old and new values are smis, no need for a write barrier here.
5189 __ bind(&fast_smi_case);
5190 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5193 __ bind(&value_is_heap_object);
5194 __ JumpIfSmi(cell_value, &slow_case);
5196 __ ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5197 __ ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5198 __ cmp(cell_value_map, scratch);
5199 __ b(eq, &fast_heapobject_case);
5201 // Fallback to runtime.
5202 __ bind(&slow_case);
5204 __ Push(slot, value);
5205 __ TailCallRuntime(is_strict(language_mode())
5206 ? Runtime::kStoreGlobalViaContext_Strict
5207 : Runtime::kStoreGlobalViaContext_Sloppy,
5212 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5213 return ref0.address() - ref1.address();
5217 // Calls an API function. Allocates HandleScope, extracts returned value
5218 // from handle and propagates exceptions. Restores context. stack_space
5219 // - space to be unwound on exit (includes the call JS arguments space and
5220 // the additional space allocated for the fast call).
5221 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5222 Register function_address,
5223 ExternalReference thunk_ref,
5225 MemOperand* stack_space_operand,
5226 MemOperand return_value_operand,
5227 MemOperand* context_restore_operand) {
5228 Isolate* isolate = masm->isolate();
5229 ExternalReference next_address =
5230 ExternalReference::handle_scope_next_address(isolate);
5231 const int kNextOffset = 0;
5232 const int kLimitOffset = AddressOffset(
5233 ExternalReference::handle_scope_limit_address(isolate), next_address);
5234 const int kLevelOffset = AddressOffset(
5235 ExternalReference::handle_scope_level_address(isolate), next_address);
5237 DCHECK(function_address.is(r1) || function_address.is(r2));
5239 Label profiler_disabled;
5240 Label end_profiler_check;
5241 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5242 __ ldrb(r9, MemOperand(r9, 0));
5243 __ cmp(r9, Operand(0));
5244 __ b(eq, &profiler_disabled);
5246 // Additional parameter is the address of the actual callback.
5247 __ mov(r3, Operand(thunk_ref));
5248 __ jmp(&end_profiler_check);
5250 __ bind(&profiler_disabled);
5251 __ Move(r3, function_address);
5252 __ bind(&end_profiler_check);
5254 // Allocate HandleScope in callee-save registers.
5255 __ mov(r9, Operand(next_address));
5256 __ ldr(r4, MemOperand(r9, kNextOffset));
5257 __ ldr(r5, MemOperand(r9, kLimitOffset));
5258 __ ldr(r6, MemOperand(r9, kLevelOffset));
5259 __ add(r6, r6, Operand(1));
5260 __ str(r6, MemOperand(r9, kLevelOffset));
5262 if (FLAG_log_timer_events) {
5263 FrameScope frame(masm, StackFrame::MANUAL);
5264 __ PushSafepointRegisters();
5265 __ PrepareCallCFunction(1, r0);
5266 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5267 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5269 __ PopSafepointRegisters();
5272 // Native call returns to the DirectCEntry stub which redirects to the
5273 // return address pushed on stack (could have moved after GC).
5274 // DirectCEntry stub itself is generated early and never moves.
5275 DirectCEntryStub stub(isolate);
5276 stub.GenerateCall(masm, r3);
5278 if (FLAG_log_timer_events) {
5279 FrameScope frame(masm, StackFrame::MANUAL);
5280 __ PushSafepointRegisters();
5281 __ PrepareCallCFunction(1, r0);
5282 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5283 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5285 __ PopSafepointRegisters();
5288 Label promote_scheduled_exception;
5289 Label delete_allocated_handles;
5290 Label leave_exit_frame;
5291 Label return_value_loaded;
5293 // load value from ReturnValue
5294 __ ldr(r0, return_value_operand);
5295 __ bind(&return_value_loaded);
5296 // No more valid handles (the result handle was the last one). Restore
5297 // previous handle scope.
5298 __ str(r4, MemOperand(r9, kNextOffset));
5299 if (__ emit_debug_code()) {
5300 __ ldr(r1, MemOperand(r9, kLevelOffset));
5302 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5304 __ sub(r6, r6, Operand(1));
5305 __ str(r6, MemOperand(r9, kLevelOffset));
5306 __ ldr(ip, MemOperand(r9, kLimitOffset));
5308 __ b(ne, &delete_allocated_handles);
5310 // Leave the API exit frame.
5311 __ bind(&leave_exit_frame);
5312 bool restore_context = context_restore_operand != NULL;
5313 if (restore_context) {
5314 __ ldr(cp, *context_restore_operand);
5316 // LeaveExitFrame expects unwind space to be in a register.
5317 if (stack_space_operand != NULL) {
5318 __ ldr(r4, *stack_space_operand);
5320 __ mov(r4, Operand(stack_space));
5322 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5324 // Check if the function scheduled an exception.
5325 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5326 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5327 __ ldr(r5, MemOperand(ip));
5329 __ b(ne, &promote_scheduled_exception);
5333 // Re-throw by promoting a scheduled exception.
5334 __ bind(&promote_scheduled_exception);
5335 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5337 // HandleScope limit has changed. Delete allocated extensions.
5338 __ bind(&delete_allocated_handles);
5339 __ str(r5, MemOperand(r9, kLimitOffset));
5341 __ PrepareCallCFunction(1, r5);
5342 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5343 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5346 __ jmp(&leave_exit_frame);
5350 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5351 const ParameterCount& argc,
5352 bool return_first_arg,
5353 bool call_data_undefined) {
5354 // ----------- S t a t e -------------
5356 // -- r4 : call_data
5358 // -- r1 : api_function_address
5359 // -- r3 : number of arguments if argc is a register
5362 // -- sp[0] : last argument
5364 // -- sp[(argc - 1)* 4] : first argument
5365 // -- sp[argc * 4] : receiver
5366 // -----------------------------------
5368 Register callee = r0;
5369 Register call_data = r4;
5370 Register holder = r2;
5371 Register api_function_address = r1;
5372 Register context = cp;
5374 typedef FunctionCallbackArguments FCA;
5376 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5377 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5378 STATIC_ASSERT(FCA::kDataIndex == 4);
5379 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5380 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5381 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5382 STATIC_ASSERT(FCA::kHolderIndex == 0);
5383 STATIC_ASSERT(FCA::kArgsLength == 7);
5385 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5389 // load context from callee
5390 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5398 Register scratch = call_data;
5399 if (!call_data_undefined) {
5400 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5404 // return value default
5407 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5412 // Prepare arguments.
5413 __ mov(scratch, sp);
5415 // Allocate the v8::Arguments structure in the arguments' space since
5416 // it's not controlled by GC.
5417 const int kApiStackSpace = 4;
5419 FrameScope frame_scope(masm, StackFrame::MANUAL);
5420 __ EnterExitFrame(false, kApiStackSpace);
5422 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5423 // r0 = FunctionCallbackInfo&
5424 // Arguments is after the return address.
5425 __ add(r0, sp, Operand(1 * kPointerSize));
5426 // FunctionCallbackInfo::implicit_args_
5427 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
5428 if (argc.is_immediate()) {
5429 // FunctionCallbackInfo::values_
5431 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5432 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5433 // FunctionCallbackInfo::length_ = argc
5434 __ mov(ip, Operand(argc.immediate()));
5435 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5436 // FunctionCallbackInfo::is_construct_call_ = 0
5437 __ mov(ip, Operand::Zero());
5438 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5440 // FunctionCallbackInfo::values_
5441 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5442 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5443 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5444 // FunctionCallbackInfo::length_ = argc
5445 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5446 // FunctionCallbackInfo::is_construct_call_
5447 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5448 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5449 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5452 ExternalReference thunk_ref =
5453 ExternalReference::invoke_function_callback(masm->isolate());
5455 AllowExternalCallThatCantCauseGC scope(masm);
5456 MemOperand context_restore_operand(
5457 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5458 // Stores return the first js argument
5459 int return_value_offset = 0;
5460 if (return_first_arg) {
5461 return_value_offset = 2 + FCA::kArgsLength;
5463 return_value_offset = 2 + FCA::kReturnValueOffset;
5465 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5466 int stack_space = 0;
5467 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5468 MemOperand* stack_space_operand = &is_construct_call_operand;
5469 if (argc.is_immediate()) {
5470 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5471 stack_space_operand = NULL;
5473 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5474 stack_space_operand, return_value_operand,
5475 &context_restore_operand);
5479 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5480 bool call_data_undefined = this->call_data_undefined();
5481 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
5482 call_data_undefined);
5486 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5487 bool is_store = this->is_store();
5488 int argc = this->argc();
5489 bool call_data_undefined = this->call_data_undefined();
5490 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5491 call_data_undefined);
5495 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5496 // ----------- S t a t e -------------
5498 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5500 // -- r2 : api_function_address
5501 // -----------------------------------
5503 Register api_function_address = ApiGetterDescriptor::function_address();
5504 DCHECK(api_function_address.is(r2));
5506 __ mov(r0, sp); // r0 = Handle<Name>
5507 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
5509 const int kApiStackSpace = 1;
5510 FrameScope frame_scope(masm, StackFrame::MANUAL);
5511 __ EnterExitFrame(false, kApiStackSpace);
5513 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5514 // r1 (internal::Object** args_) as the data.
5515 __ str(r1, MemOperand(sp, 1 * kPointerSize));
5516 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
5518 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5520 ExternalReference thunk_ref =
5521 ExternalReference::invoke_accessor_getter_callback(isolate());
5522 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5523 kStackUnwindSpace, NULL,
5524 MemOperand(fp, 6 * kPointerSize), NULL);
5530 } // namespace internal
5533 #endif // V8_TARGET_ARCH_ARM