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.
9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h"
11 #include "src/code-stubs.h"
12 #include "src/codegen.h"
13 #include "src/ic/handler-compiler.h"
14 #include "src/ic/ic.h"
15 #include "src/ic/stub-cache.h"
16 #include "src/isolate.h"
17 #include "src/jsregexp.h"
18 #include "src/regexp-macro-assembler.h"
19 #include "src/runtime/runtime.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, PASS_ARGUMENTS);
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, PASS_ARGUMENTS);
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 if (is_strong(strength)) {
259 // Call the runtime on anything that is converted in the semantics, since
260 // we need to throw a TypeError. Smis have already been ruled out.
261 __ cmp(r4, Operand(HEAP_NUMBER_TYPE));
262 __ b(eq, &return_equal);
263 __ tst(r4, Operand(kIsNotStringMask));
267 __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE);
268 __ b(eq, &heap_number);
269 // Comparing JS objects with <=, >= is complicated.
271 __ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE));
273 // Call runtime on identical symbols since we need to throw a TypeError.
274 __ cmp(r4, Operand(SYMBOL_TYPE));
276 if (is_strong(strength)) {
277 // Call the runtime on anything that is converted in the semantics,
278 // since we need to throw a TypeError. Smis and heap numbers have
279 // already been ruled out.
280 __ tst(r4, Operand(kIsNotStringMask));
283 // Normally here we fall through to return_equal, but undefined is
284 // special: (undefined == undefined) == true, but
285 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
286 if (cond == le || cond == ge) {
287 __ cmp(r4, Operand(ODDBALL_TYPE));
288 __ b(ne, &return_equal);
289 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
291 __ b(ne, &return_equal);
293 // undefined <= undefined should fail.
294 __ mov(r0, Operand(GREATER));
296 // undefined >= undefined should fail.
297 __ mov(r0, Operand(LESS));
304 __ bind(&return_equal);
306 __ mov(r0, Operand(GREATER)); // Things aren't less than themselves.
307 } else if (cond == gt) {
308 __ mov(r0, Operand(LESS)); // Things aren't greater than themselves.
310 __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
314 // For less and greater we don't have to check for NaN since the result of
315 // x < x is false regardless. For the others here is some code to check
317 if (cond != lt && cond != gt) {
318 __ bind(&heap_number);
319 // It is a heap number, so return non-equal if it's NaN and equal if it's
322 // The representation of NaN values has all exponent bits (52..62) set,
323 // and not all mantissa bits (0..51) clear.
324 // Read top bits of double representation (second word of value).
325 __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
326 // Test that exponent bits are all set.
327 __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits);
328 // NaNs have all-one exponents so they sign extend to -1.
329 __ cmp(r3, Operand(-1));
330 __ b(ne, &return_equal);
332 // Shift out flag and all exponent bits, retaining only mantissa.
333 __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord));
334 // Or with all low-bits of mantissa.
335 __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
336 __ orr(r0, r3, Operand(r2), SetCC);
337 // For equal we already have the right value in r0: Return zero (equal)
338 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
339 // not (it's a NaN). For <= and >= we need to load r0 with the failing
340 // value if it's a NaN.
342 // All-zero means Infinity means equal.
345 __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail.
347 __ mov(r0, Operand(LESS)); // NaN >= NaN should fail.
352 // No fall through here.
354 __ bind(¬_identical);
358 // See comment at call site.
359 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
365 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
366 (lhs.is(r1) && rhs.is(r0)));
369 __ JumpIfSmi(rhs, &rhs_is_smi);
371 // Lhs is a Smi. Check whether the rhs is a heap number.
372 __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE);
374 // If rhs is not a number and lhs is a Smi then strict equality cannot
375 // succeed. Return non-equal
376 // If rhs is r0 then there is already a non zero value in it.
378 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
382 // Smi compared non-strictly with a non-Smi non-heap-number. Call
387 // Lhs is a smi, rhs is a number.
388 // Convert lhs to a double in d7.
389 __ SmiToDouble(d7, lhs);
390 // Load the double from rhs, tagged HeapNumber r0, to d6.
391 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
393 // We now have both loaded as doubles but we can skip the lhs nan check
397 __ bind(&rhs_is_smi);
398 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
399 __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE);
401 // If lhs is not a number and rhs is a smi then strict equality cannot
402 // succeed. Return non-equal.
403 // If lhs is r0 then there is already a non zero value in it.
405 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
409 // Smi compared non-strictly with a non-smi non-heap-number. Call
414 // Rhs is a smi, lhs is a heap number.
415 // Load the double from lhs, tagged HeapNumber r1, to d7.
416 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
417 // Convert rhs to a double in d6 .
418 __ SmiToDouble(d6, rhs);
419 // Fall through to both_loaded_as_doubles.
423 // See comment at call site.
424 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
427 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
428 (lhs.is(r1) && rhs.is(r0)));
430 // If either operand is a JS object or an oddball value, then they are
431 // not equal since their pointers are different.
432 // There is no test for undetectability in strict equality.
433 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
434 Label first_non_object;
435 // Get the type of the first operand into r2 and compare it with
436 // FIRST_SPEC_OBJECT_TYPE.
437 __ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE);
438 __ b(lt, &first_non_object);
440 // Return non-zero (r0 is not zero)
441 Label return_not_equal;
442 __ bind(&return_not_equal);
445 __ bind(&first_non_object);
446 // Check for oddballs: true, false, null, undefined.
447 __ cmp(r2, Operand(ODDBALL_TYPE));
448 __ b(eq, &return_not_equal);
450 __ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE);
451 __ b(ge, &return_not_equal);
453 // Check for oddballs: true, false, null, undefined.
454 __ cmp(r3, Operand(ODDBALL_TYPE));
455 __ b(eq, &return_not_equal);
457 // Now that we have the types we might as well check for
458 // internalized-internalized.
459 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
460 __ orr(r2, r2, Operand(r3));
461 __ tst(r2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
462 __ b(eq, &return_not_equal);
466 // See comment at call site.
467 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
470 Label* both_loaded_as_doubles,
471 Label* not_heap_numbers,
473 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
474 (lhs.is(r1) && rhs.is(r0)));
476 __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE);
477 __ b(ne, not_heap_numbers);
478 __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset));
480 __ b(ne, slow); // First was a heap number, second wasn't. Go slow case.
482 // Both are heap numbers. Load them up then jump to the code we have
484 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
485 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
486 __ jmp(both_loaded_as_doubles);
490 // Fast negative check for internalized-to-internalized equality.
491 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
494 Label* possible_strings,
495 Label* not_both_strings) {
496 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
497 (lhs.is(r1) && rhs.is(r0)));
499 // r2 is object type of rhs.
501 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
502 __ tst(r2, Operand(kIsNotStringMask));
503 __ b(ne, &object_test);
504 __ tst(r2, Operand(kIsNotInternalizedMask));
505 __ b(ne, possible_strings);
506 __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE);
507 __ b(ge, not_both_strings);
508 __ tst(r3, Operand(kIsNotInternalizedMask));
509 __ b(ne, possible_strings);
511 // Both are internalized. We already checked they weren't the same pointer
512 // so they are not equal.
513 __ mov(r0, Operand(NOT_EQUAL));
516 __ bind(&object_test);
517 __ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE));
518 __ b(lt, not_both_strings);
519 __ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE);
520 __ b(lt, not_both_strings);
521 // If both objects are undetectable, they are equal. Otherwise, they
522 // are not equal, since they are different objects and an object is not
523 // equal to undefined.
524 __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset));
525 __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset));
526 __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset));
527 __ and_(r0, r2, Operand(r3));
528 __ and_(r0, r0, Operand(1 << Map::kIsUndetectable));
529 __ eor(r0, r0, Operand(1 << Map::kIsUndetectable));
534 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
536 CompareICState::State expected,
539 if (expected == CompareICState::SMI) {
540 __ JumpIfNotSmi(input, fail);
541 } else if (expected == CompareICState::NUMBER) {
542 __ JumpIfSmi(input, &ok);
543 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
546 // We could be strict about internalized/non-internalized here, but as long as
547 // hydrogen doesn't care, the stub doesn't have to care either.
552 // On entry r1 and r2 are the values to be compared.
553 // On exit r0 is 0, positive or negative to indicate the result of
555 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
558 Condition cc = GetCondition();
561 CompareICStub_CheckInputType(masm, lhs, r2, left(), &miss);
562 CompareICStub_CheckInputType(masm, rhs, r3, right(), &miss);
564 Label slow; // Call builtin.
565 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
567 Label not_two_smis, smi_done;
569 __ JumpIfNotSmi(r2, ¬_two_smis);
570 __ mov(r1, Operand(r1, ASR, 1));
571 __ sub(r0, r1, Operand(r0, ASR, 1));
573 __ bind(¬_two_smis);
575 // NOTICE! This code is only reached after a smi-fast-case check, so
576 // it is certain that at least one operand isn't a smi.
578 // Handle the case where the objects are identical. Either returns the answer
579 // or goes to slow. Only falls through if the objects were not identical.
580 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
582 // If either is a Smi (we know that not both are), then they can only
583 // be strictly equal if the other is a HeapNumber.
584 STATIC_ASSERT(kSmiTag == 0);
585 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
586 __ and_(r2, lhs, Operand(rhs));
587 __ JumpIfNotSmi(r2, ¬_smis);
588 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
589 // 1) Return the answer.
591 // 3) Fall through to both_loaded_as_doubles.
592 // 4) Jump to lhs_not_nan.
593 // In cases 3 and 4 we have found out we were dealing with a number-number
594 // comparison. If VFP3 is supported the double values of the numbers have
595 // been loaded into d7 and d6. Otherwise, the double values have been loaded
596 // into r0, r1, r2, and r3.
597 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
599 __ bind(&both_loaded_as_doubles);
600 // The arguments have been converted to doubles and stored in d6 and d7, if
601 // VFP3 is supported, or in r0, r1, r2, and r3.
602 __ bind(&lhs_not_nan);
604 // ARMv7 VFP3 instructions to implement double precision comparison.
605 __ VFPCompareAndSetFlags(d7, d6);
608 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
609 __ mov(r0, Operand(LESS), LeaveCC, lt);
610 __ mov(r0, Operand(GREATER), LeaveCC, gt);
614 // If one of the sides was a NaN then the v flag is set. Load r0 with
615 // whatever it takes to make the comparison fail, since comparisons with NaN
617 if (cc == lt || cc == le) {
618 __ mov(r0, Operand(GREATER));
620 __ mov(r0, Operand(LESS));
625 // At this point we know we are dealing with two different objects,
626 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
628 // This returns non-equal for some object types, or falls through if it
630 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
633 Label check_for_internalized_strings;
634 Label flat_string_check;
635 // Check for heap-number-heap-number comparison. Can jump to slow case,
636 // or load both doubles into r0, r1, r2, r3 and jump to the code that handles
637 // that case. If the inputs are not doubles then jumps to
638 // check_for_internalized_strings.
639 // In this case r2 will contain the type of rhs_. Never falls through.
640 EmitCheckForTwoHeapNumbers(masm,
643 &both_loaded_as_doubles,
644 &check_for_internalized_strings,
647 __ bind(&check_for_internalized_strings);
648 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
649 // internalized strings.
650 if (cc == eq && !strict()) {
651 // Returns an answer for two internalized strings or two detectable objects.
652 // Otherwise jumps to string case or not both strings case.
653 // Assumes that r2 is the type of rhs_ on entry.
654 EmitCheckForInternalizedStringsOrObjects(
655 masm, lhs, rhs, &flat_string_check, &slow);
658 // Check for both being sequential one-byte strings,
659 // and inline if that is the case.
660 __ bind(&flat_string_check);
662 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r2, r3, &slow);
664 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
667 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r2, r3, r4);
669 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r2, r3, r4,
672 // Never falls through to here.
677 // Figure out which native to call and setup the arguments.
678 Builtins::JavaScript native;
680 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
683 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
684 int ncr; // NaN compare result
685 if (cc == lt || cc == le) {
688 DCHECK(cc == gt || cc == ge); // remaining cases
691 __ mov(r0, Operand(Smi::FromInt(ncr)));
695 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
696 // tagged as a small integer.
697 __ InvokeBuiltin(native, JUMP_FUNCTION);
704 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
705 // We don't allow a GC during a store buffer overflow so there is no need to
706 // store the registers in any particular way, but we do have to store and
708 __ stm(db_w, sp, kCallerSaved | lr.bit());
710 const Register scratch = r1;
712 if (save_doubles()) {
713 __ SaveFPRegs(sp, scratch);
715 const int argument_count = 1;
716 const int fp_argument_count = 0;
718 AllowExternalCallThatCantCauseGC scope(masm);
719 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
720 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
722 ExternalReference::store_buffer_overflow_function(isolate()),
724 if (save_doubles()) {
725 __ RestoreFPRegs(sp, scratch);
727 __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0).
731 void MathPowStub::Generate(MacroAssembler* masm) {
732 const Register base = r1;
733 const Register exponent = MathPowTaggedDescriptor::exponent();
734 DCHECK(exponent.is(r2));
735 const Register heapnumbermap = r5;
736 const Register heapnumber = r0;
737 const DwVfpRegister double_base = d0;
738 const DwVfpRegister double_exponent = d1;
739 const DwVfpRegister double_result = d2;
740 const DwVfpRegister double_scratch = d3;
741 const SwVfpRegister single_scratch = s6;
742 const Register scratch = r9;
743 const Register scratch2 = r4;
745 Label call_runtime, done, int_exponent;
746 if (exponent_type() == ON_STACK) {
747 Label base_is_smi, unpack_exponent;
748 // The exponent and base are supplied as arguments on the stack.
749 // This can only happen if the stub is called from non-optimized code.
750 // Load input parameters from stack to double registers.
751 __ ldr(base, MemOperand(sp, 1 * kPointerSize));
752 __ ldr(exponent, MemOperand(sp, 0 * kPointerSize));
754 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
756 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
757 __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset));
758 __ cmp(scratch, heapnumbermap);
759 __ b(ne, &call_runtime);
761 __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
762 __ jmp(&unpack_exponent);
764 __ bind(&base_is_smi);
765 __ vmov(single_scratch, scratch);
766 __ vcvt_f64_s32(double_base, single_scratch);
767 __ bind(&unpack_exponent);
769 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
771 __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
772 __ cmp(scratch, heapnumbermap);
773 __ b(ne, &call_runtime);
774 __ vldr(double_exponent,
775 FieldMemOperand(exponent, HeapNumber::kValueOffset));
776 } else if (exponent_type() == TAGGED) {
777 // Base is already in double_base.
778 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
780 __ vldr(double_exponent,
781 FieldMemOperand(exponent, HeapNumber::kValueOffset));
784 if (exponent_type() != INTEGER) {
785 Label int_exponent_convert;
786 // Detect integer exponents stored as double.
787 __ vcvt_u32_f64(single_scratch, double_exponent);
788 // We do not check for NaN or Infinity here because comparing numbers on
789 // ARM correctly distinguishes NaNs. We end up calling the built-in.
790 __ vcvt_f64_u32(double_scratch, single_scratch);
791 __ VFPCompareAndSetFlags(double_scratch, double_exponent);
792 __ b(eq, &int_exponent_convert);
794 if (exponent_type() == ON_STACK) {
795 // Detect square root case. Crankshaft detects constant +/-0.5 at
796 // compile time and uses DoMathPowHalf instead. We then skip this check
797 // for non-constant cases of +/-0.5 as these hardly occur.
801 __ vmov(double_scratch, 0.5, scratch);
802 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
803 __ b(ne, ¬_plus_half);
805 // Calculates square root of base. Check for the special case of
806 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
807 __ vmov(double_scratch, -V8_INFINITY, scratch);
808 __ VFPCompareAndSetFlags(double_base, double_scratch);
809 __ vneg(double_result, double_scratch, eq);
812 // Add +0 to convert -0 to +0.
813 __ vadd(double_scratch, double_base, kDoubleRegZero);
814 __ vsqrt(double_result, double_scratch);
817 __ bind(¬_plus_half);
818 __ vmov(double_scratch, -0.5, scratch);
819 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
820 __ b(ne, &call_runtime);
822 // Calculates square root of base. Check for the special case of
823 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
824 __ vmov(double_scratch, -V8_INFINITY, scratch);
825 __ VFPCompareAndSetFlags(double_base, double_scratch);
826 __ vmov(double_result, kDoubleRegZero, eq);
829 // Add +0 to convert -0 to +0.
830 __ vadd(double_scratch, double_base, kDoubleRegZero);
831 __ vmov(double_result, 1.0, scratch);
832 __ vsqrt(double_scratch, double_scratch);
833 __ vdiv(double_result, double_result, double_scratch);
839 AllowExternalCallThatCantCauseGC scope(masm);
840 __ PrepareCallCFunction(0, 2, scratch);
841 __ MovToFloatParameters(double_base, double_exponent);
843 ExternalReference::power_double_double_function(isolate()),
847 __ MovFromFloatResult(double_result);
850 __ bind(&int_exponent_convert);
851 __ vcvt_u32_f64(single_scratch, double_exponent);
852 __ vmov(scratch, single_scratch);
855 // Calculate power with integer exponent.
856 __ bind(&int_exponent);
858 // Get two copies of exponent in the registers scratch and exponent.
859 if (exponent_type() == INTEGER) {
860 __ mov(scratch, exponent);
862 // Exponent has previously been stored into scratch as untagged integer.
863 __ mov(exponent, scratch);
865 __ vmov(double_scratch, double_base); // Back up base.
866 __ vmov(double_result, 1.0, scratch2);
868 // Get absolute value of exponent.
869 __ cmp(scratch, Operand::Zero());
870 __ mov(scratch2, Operand::Zero(), LeaveCC, mi);
871 __ sub(scratch, scratch2, scratch, LeaveCC, mi);
874 __ bind(&while_true);
875 __ mov(scratch, Operand(scratch, ASR, 1), SetCC);
876 __ vmul(double_result, double_result, double_scratch, cs);
877 __ vmul(double_scratch, double_scratch, double_scratch, ne);
878 __ b(ne, &while_true);
880 __ cmp(exponent, Operand::Zero());
882 __ vmov(double_scratch, 1.0, scratch);
883 __ vdiv(double_result, double_scratch, double_result);
884 // Test whether result is zero. Bail out to check for subnormal result.
885 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
886 __ VFPCompareAndSetFlags(double_result, 0.0);
888 // double_exponent may not containe the exponent value if the input was a
889 // smi. We set it with exponent value before bailing out.
890 __ vmov(single_scratch, exponent);
891 __ vcvt_f64_s32(double_exponent, single_scratch);
893 // Returning or bailing out.
894 Counters* counters = isolate()->counters();
895 if (exponent_type() == ON_STACK) {
896 // The arguments are still on the stack.
897 __ bind(&call_runtime);
898 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
900 // The stub is called from non-optimized code, which expects the result
901 // as heap number in exponent.
903 __ AllocateHeapNumber(
904 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
905 __ vstr(double_result,
906 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
907 DCHECK(heapnumber.is(r0));
908 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
913 AllowExternalCallThatCantCauseGC scope(masm);
914 __ PrepareCallCFunction(0, 2, scratch);
915 __ MovToFloatParameters(double_base, double_exponent);
917 ExternalReference::power_double_double_function(isolate()),
921 __ MovFromFloatResult(double_result);
924 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
930 bool CEntryStub::NeedsImmovableCode() {
935 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
936 CEntryStub::GenerateAheadOfTime(isolate);
937 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
938 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
939 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
940 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
941 CreateWeakCellStub::GenerateAheadOfTime(isolate);
942 BinaryOpICStub::GenerateAheadOfTime(isolate);
943 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
944 StoreFastElementStub::GenerateAheadOfTime(isolate);
945 TypeofStub::GenerateAheadOfTime(isolate);
949 void CodeStub::GenerateFPStubs(Isolate* isolate) {
950 // Generate if not already in cache.
951 SaveFPRegsMode mode = kSaveFPRegs;
952 CEntryStub(isolate, 1, mode).GetCode();
953 StoreBufferOverflowStub(isolate, mode).GetCode();
954 isolate->set_fp_stubs_generated(true);
958 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
959 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
964 void CEntryStub::Generate(MacroAssembler* masm) {
965 // Called from JavaScript; parameters are on stack as if calling JS function.
966 // r0: number of arguments including receiver
967 // r1: pointer to builtin function
968 // fp: frame pointer (restored after C call)
969 // sp: stack pointer (restored as callee's sp after C call)
970 // cp: current context (C callee-saved)
972 ProfileEntryHookStub::MaybeCallEntryHook(masm);
974 __ mov(r5, Operand(r1));
976 // Compute the argv pointer in a callee-saved register.
977 __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2));
978 __ sub(r1, r1, Operand(kPointerSize));
980 // Enter the exit frame that transitions from JavaScript to C++.
981 FrameScope scope(masm, StackFrame::MANUAL);
982 __ EnterExitFrame(save_doubles());
984 // Store a copy of argc in callee-saved registers for later.
985 __ mov(r4, Operand(r0));
987 // r0, r4: number of arguments including receiver (C callee-saved)
988 // r1: pointer to the first argument (C callee-saved)
989 // r5: pointer to builtin function (C callee-saved)
991 // Result returned in r0 or r0+r1 by default.
994 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
995 int frame_alignment_mask = frame_alignment - 1;
996 if (FLAG_debug_code) {
997 if (frame_alignment > kPointerSize) {
998 Label alignment_as_expected;
999 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
1000 __ tst(sp, Operand(frame_alignment_mask));
1001 __ b(eq, &alignment_as_expected);
1002 // Don't use Check here, as it will call Runtime_Abort re-entering here.
1003 __ stop("Unexpected alignment");
1004 __ bind(&alignment_as_expected);
1010 // r0 = argc, r1 = argv
1011 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1013 // To let the GC traverse the return address of the exit frames, we need to
1014 // know where the return address is. The CEntryStub is unmovable, so
1015 // we can store the address on the stack to be able to find it again and
1016 // we never have to restore it, because it will not change.
1017 // Compute the return address in lr to return to after the jump below. Pc is
1018 // already at '+ 8' from the current instruction but return is after three
1019 // instructions so add another 4 to pc to get the return address.
1021 // Prevent literal pool emission before return address.
1022 Assembler::BlockConstPoolScope block_const_pool(masm);
1023 __ add(lr, pc, Operand(4));
1024 __ str(lr, MemOperand(sp, 0));
1028 __ VFPEnsureFPSCRState(r2);
1030 // Check result for exception sentinel.
1031 Label exception_returned;
1032 __ CompareRoot(r0, Heap::kExceptionRootIndex);
1033 __ b(eq, &exception_returned);
1035 // Check that there is no pending exception, otherwise we
1036 // should have returned the exception sentinel.
1037 if (FLAG_debug_code) {
1039 ExternalReference pending_exception_address(
1040 Isolate::kPendingExceptionAddress, isolate());
1041 __ mov(r2, Operand(pending_exception_address));
1042 __ ldr(r2, MemOperand(r2));
1043 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex);
1044 // Cannot use check here as it attempts to generate call into runtime.
1046 __ stop("Unexpected pending exception");
1050 // Exit C frame and return.
1052 // sp: stack pointer
1053 // fp: frame pointer
1054 // Callee-saved register r4 still holds argc.
1055 __ LeaveExitFrame(save_doubles(), r4, true);
1058 // Handling of exception.
1059 __ bind(&exception_returned);
1061 ExternalReference pending_handler_context_address(
1062 Isolate::kPendingHandlerContextAddress, isolate());
1063 ExternalReference pending_handler_code_address(
1064 Isolate::kPendingHandlerCodeAddress, isolate());
1065 ExternalReference pending_handler_offset_address(
1066 Isolate::kPendingHandlerOffsetAddress, isolate());
1067 ExternalReference pending_handler_fp_address(
1068 Isolate::kPendingHandlerFPAddress, isolate());
1069 ExternalReference pending_handler_sp_address(
1070 Isolate::kPendingHandlerSPAddress, isolate());
1072 // Ask the runtime for help to determine the handler. This will set r0 to
1073 // contain the current pending exception, don't clobber it.
1074 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1077 FrameScope scope(masm, StackFrame::MANUAL);
1078 __ PrepareCallCFunction(3, 0, r0);
1079 __ mov(r0, Operand(0));
1080 __ mov(r1, Operand(0));
1081 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1082 __ CallCFunction(find_handler, 3);
1085 // Retrieve the handler context, SP and FP.
1086 __ mov(cp, Operand(pending_handler_context_address));
1087 __ ldr(cp, MemOperand(cp));
1088 __ mov(sp, Operand(pending_handler_sp_address));
1089 __ ldr(sp, MemOperand(sp));
1090 __ mov(fp, Operand(pending_handler_fp_address));
1091 __ ldr(fp, MemOperand(fp));
1093 // If the handler is a JS frame, restore the context to the frame. Note that
1094 // the context will be set to (cp == 0) for non-JS frames.
1095 __ cmp(cp, Operand(0));
1096 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne);
1098 // Compute the handler entry address and jump to it.
1099 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1100 __ mov(r1, Operand(pending_handler_code_address));
1101 __ ldr(r1, MemOperand(r1));
1102 __ mov(r2, Operand(pending_handler_offset_address));
1103 __ ldr(r2, MemOperand(r2));
1104 __ add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1105 if (FLAG_enable_embedded_constant_pool) {
1106 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r1);
1112 void JSEntryStub::Generate(MacroAssembler* masm) {
1119 Label invoke, handler_entry, exit;
1121 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1123 // Called from C, so do not pop argc and args on exit (preserve sp)
1124 // No need to save register-passed args
1125 // Save callee-saved registers (incl. cp and fp), sp, and lr
1126 __ stm(db_w, sp, kCalleeSaved | lr.bit());
1128 // Save callee-saved vfp registers.
1129 __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1130 // Set up the reserved register for 0.0.
1131 __ vmov(kDoubleRegZero, 0.0);
1132 __ VFPEnsureFPSCRState(r4);
1134 // Get address of argv, see stm above.
1140 // Set up argv in r4.
1141 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1142 offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize;
1143 __ ldr(r4, MemOperand(sp, offset_to_argv));
1145 // Push a frame with special values setup to mark it as an entry frame.
1151 int marker = type();
1152 if (FLAG_enable_embedded_constant_pool) {
1153 __ mov(r8, Operand::Zero());
1155 __ mov(r7, Operand(Smi::FromInt(marker)));
1156 __ mov(r6, Operand(Smi::FromInt(marker)));
1158 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1159 __ ldr(r5, MemOperand(r5));
1160 __ mov(ip, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1161 __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() |
1162 (FLAG_enable_embedded_constant_pool ? r8.bit() : 0) |
1165 // Set up frame pointer for the frame to be pushed.
1166 __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1168 // If this is the outermost JS call, set js_entry_sp value.
1169 Label non_outermost_js;
1170 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1171 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1172 __ ldr(r6, MemOperand(r5));
1173 __ cmp(r6, Operand::Zero());
1174 __ b(ne, &non_outermost_js);
1175 __ str(fp, MemOperand(r5));
1176 __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1179 __ bind(&non_outermost_js);
1180 __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1184 // Jump to a faked try block that does the invoke, with a faked catch
1185 // block that sets the pending exception.
1188 // Block literal pool emission whilst taking the position of the handler
1189 // entry. This avoids making the assumption that literal pools are always
1190 // emitted after an instruction is emitted, rather than before.
1192 Assembler::BlockConstPoolScope block_const_pool(masm);
1193 __ bind(&handler_entry);
1194 handler_offset_ = handler_entry.pos();
1195 // Caught exception: Store result (exception) in the pending exception
1196 // field in the JSEnv and return a failure sentinel. Coming in here the
1197 // fp will be invalid because the PushStackHandler below sets it to 0 to
1198 // signal the existence of the JSEntry frame.
1199 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1202 __ str(r0, MemOperand(ip));
1203 __ LoadRoot(r0, Heap::kExceptionRootIndex);
1206 // Invoke: Link this frame into the handler chain.
1208 // Must preserve r0-r4, r5-r6 are available.
1209 __ PushStackHandler();
1210 // If an exception not caught by another handler occurs, this handler
1211 // returns control to the code after the bl(&invoke) above, which
1212 // restores all kCalleeSaved registers (including cp and fp) to their
1213 // saved values before returning a failure to C.
1215 // Clear any pending exceptions.
1216 __ mov(r5, Operand(isolate()->factory()->the_hole_value()));
1217 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1219 __ str(r5, MemOperand(ip));
1221 // Invoke the function by calling through JS entry trampoline builtin.
1222 // Notice that we cannot store a reference to the trampoline code directly in
1223 // this stub, because runtime stubs are not traversed when doing GC.
1225 // Expected registers by Builtins::JSEntryTrampoline
1231 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1232 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1234 __ mov(ip, Operand(construct_entry));
1236 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
1237 __ mov(ip, Operand(entry));
1239 __ ldr(ip, MemOperand(ip)); // deref address
1240 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1242 // Branch and link to JSEntryTrampoline.
1245 // Unlink this frame from the handler chain.
1246 __ PopStackHandler();
1248 __ bind(&exit); // r0 holds result
1249 // Check if the current stack frame is marked as the outermost JS frame.
1250 Label non_outermost_js_2;
1252 __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1253 __ b(ne, &non_outermost_js_2);
1254 __ mov(r6, Operand::Zero());
1255 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1256 __ str(r6, MemOperand(r5));
1257 __ bind(&non_outermost_js_2);
1259 // Restore the top frame descriptors from the stack.
1262 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1263 __ str(r3, MemOperand(ip));
1265 // Reset the stack to the callee saved registers.
1266 __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1268 // Restore callee-saved registers and return.
1270 if (FLAG_debug_code) {
1271 __ mov(lr, Operand(pc));
1275 // Restore callee-saved vfp registers.
1276 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1278 __ ldm(ia_w, sp, kCalleeSaved | pc.bit());
1282 // Uses registers r0 to r4.
1283 // Expected input (depending on whether args are in registers or on the stack):
1284 // * object: r0 or at sp + 1 * kPointerSize.
1285 // * function: r1 or at sp.
1287 // An inlined call site may have been generated before calling this stub.
1288 // In this case the offset to the inline sites to patch are passed in r5 and r6.
1289 // (See LCodeGen::DoInstanceOfKnownGlobal)
1290 void InstanceofStub::Generate(MacroAssembler* masm) {
1291 // Call site inlining and patching implies arguments in registers.
1292 DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck());
1294 // Fixed register usage throughout the stub:
1295 const Register object = r0; // Object (lhs).
1296 Register map = r3; // Map of the object.
1297 const Register function = r1; // Function (rhs).
1298 const Register prototype = r4; // Prototype of the function.
1299 const Register scratch = r2;
1301 Label slow, loop, is_instance, is_not_instance, not_js_object;
1303 if (!HasArgsInRegisters()) {
1304 __ ldr(object, MemOperand(sp, 1 * kPointerSize));
1305 __ ldr(function, MemOperand(sp, 0));
1308 // Check that the left hand is a JS object and load map.
1309 __ JumpIfSmi(object, ¬_js_object);
1310 __ IsObjectJSObjectType(object, map, scratch, ¬_js_object);
1312 // If there is a call site cache don't look in the global cache, but do the
1313 // real lookup and update the call site cache.
1314 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
1316 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1318 __ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex);
1320 __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1321 __ Ret(HasArgsInRegisters() ? 0 : 2);
1326 // Get the prototype of the function.
1327 __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
1329 // Check that the function prototype is a JS object.
1330 __ JumpIfSmi(prototype, &slow);
1331 __ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
1333 // Update the global instanceof or call site inlined cache with the current
1334 // map and function. The cached answer will be set when it is known below.
1335 if (!HasCallSiteInlineCheck()) {
1336 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1337 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1339 DCHECK(HasArgsInRegisters());
1340 // Patch the (relocated) inlined map check.
1342 // The map_load_offset was stored in r5
1343 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1344 const Register map_load_offset = r5;
1345 __ sub(r9, lr, map_load_offset);
1346 // Get the map location in r5 and patch it.
1347 __ GetRelocatedValueLocation(r9, map_load_offset, scratch);
1348 __ ldr(map_load_offset, MemOperand(map_load_offset));
1349 __ str(map, FieldMemOperand(map_load_offset, Cell::kValueOffset));
1351 __ mov(scratch, map);
1352 // |map_load_offset| points at the beginning of the cell. Calculate the
1353 // field containing the map.
1354 __ add(function, map_load_offset, Operand(Cell::kValueOffset - 1));
1355 __ RecordWriteField(map_load_offset, Cell::kValueOffset, scratch, function,
1356 kLRHasNotBeenSaved, kDontSaveFPRegs,
1357 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
1360 // Register mapping: r3 is object map and r4 is function prototype.
1361 // Get prototype of object into r2.
1362 __ ldr(scratch, FieldMemOperand(map, Map::kPrototypeOffset));
1364 // We don't need map any more. Use it as a scratch register.
1365 Register scratch2 = map;
1368 // Loop through the prototype chain looking for the function prototype.
1369 __ LoadRoot(scratch2, Heap::kNullValueRootIndex);
1371 __ cmp(scratch, Operand(prototype));
1372 __ b(eq, &is_instance);
1373 __ cmp(scratch, scratch2);
1374 __ b(eq, &is_not_instance);
1375 __ ldr(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
1376 __ ldr(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset));
1378 Factory* factory = isolate()->factory();
1380 __ bind(&is_instance);
1381 if (!HasCallSiteInlineCheck()) {
1382 __ mov(r0, Operand(Smi::FromInt(0)));
1383 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1384 if (ReturnTrueFalseObject()) {
1385 __ Move(r0, factory->true_value());
1388 // Patch the call site to return true.
1389 __ LoadRoot(r0, Heap::kTrueValueRootIndex);
1390 // The bool_load_offset was stored in r6
1391 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1392 const Register bool_load_offset = r6;
1393 __ sub(r9, lr, bool_load_offset);
1394 // Get the boolean result location in scratch and patch it.
1395 __ GetRelocatedValueLocation(r9, scratch, scratch2);
1396 __ str(r0, MemOperand(scratch));
1398 if (!ReturnTrueFalseObject()) {
1399 __ mov(r0, Operand(Smi::FromInt(0)));
1402 __ Ret(HasArgsInRegisters() ? 0 : 2);
1404 __ bind(&is_not_instance);
1405 if (!HasCallSiteInlineCheck()) {
1406 __ mov(r0, Operand(Smi::FromInt(1)));
1407 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1408 if (ReturnTrueFalseObject()) {
1409 __ Move(r0, factory->false_value());
1412 // Patch the call site to return false.
1413 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1414 // The bool_load_offset was stored in r6
1415 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1416 const Register bool_load_offset = r6;
1417 __ sub(r9, lr, bool_load_offset);
1419 // Get the boolean result location in scratch and patch it.
1420 __ GetRelocatedValueLocation(r9, scratch, scratch2);
1421 __ str(r0, MemOperand(scratch));
1423 if (!ReturnTrueFalseObject()) {
1424 __ mov(r0, Operand(Smi::FromInt(1)));
1427 __ Ret(HasArgsInRegisters() ? 0 : 2);
1429 Label object_not_null, object_not_null_or_smi;
1430 __ bind(¬_js_object);
1431 // Before null, smi and string value checks, check that the rhs is a function
1432 // as for a non-function rhs an exception needs to be thrown.
1433 __ JumpIfSmi(function, &slow);
1434 __ CompareObjectType(function, scratch2, scratch, JS_FUNCTION_TYPE);
1437 // Null is not instance of anything.
1438 __ cmp(object, Operand(isolate()->factory()->null_value()));
1439 __ b(ne, &object_not_null);
1440 if (ReturnTrueFalseObject()) {
1441 __ Move(r0, factory->false_value());
1443 __ mov(r0, Operand(Smi::FromInt(1)));
1445 __ Ret(HasArgsInRegisters() ? 0 : 2);
1447 __ bind(&object_not_null);
1448 // Smi values are not instances of anything.
1449 __ JumpIfNotSmi(object, &object_not_null_or_smi);
1450 if (ReturnTrueFalseObject()) {
1451 __ Move(r0, factory->false_value());
1453 __ mov(r0, Operand(Smi::FromInt(1)));
1455 __ Ret(HasArgsInRegisters() ? 0 : 2);
1457 __ bind(&object_not_null_or_smi);
1458 // String values are not instances of anything.
1459 __ IsObjectJSStringType(object, scratch, &slow);
1460 if (ReturnTrueFalseObject()) {
1461 __ Move(r0, factory->false_value());
1463 __ mov(r0, Operand(Smi::FromInt(1)));
1465 __ Ret(HasArgsInRegisters() ? 0 : 2);
1467 // Slow-case. Tail call builtin.
1469 if (!ReturnTrueFalseObject()) {
1470 if (HasArgsInRegisters()) {
1473 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
1476 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
1478 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1480 __ cmp(r0, Operand::Zero());
1481 __ LoadRoot(r0, Heap::kTrueValueRootIndex, eq);
1482 __ LoadRoot(r0, Heap::kFalseValueRootIndex, ne);
1483 __ Ret(HasArgsInRegisters() ? 0 : 2);
1488 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1490 Register receiver = LoadDescriptor::ReceiverRegister();
1491 // Ensure that the vector and slot registers won't be clobbered before
1492 // calling the miss handler.
1493 DCHECK(!AreAliased(r4, r5, LoadWithVectorDescriptor::VectorRegister(),
1494 LoadWithVectorDescriptor::SlotRegister()));
1496 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4,
1499 PropertyAccessCompiler::TailCallBuiltin(
1500 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1504 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1505 // Return address is in lr.
1508 Register receiver = LoadDescriptor::ReceiverRegister();
1509 Register index = LoadDescriptor::NameRegister();
1510 Register scratch = r5;
1511 Register result = r0;
1512 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1513 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1514 result.is(LoadWithVectorDescriptor::SlotRegister()));
1516 // StringCharAtGenerator doesn't use the result register until it's passed
1517 // the different miss possibilities. If it did, we would have a conflict
1518 // when FLAG_vector_ics is true.
1519 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1520 &miss, // When not a string.
1521 &miss, // When not a number.
1522 &miss, // When index out of range.
1523 STRING_INDEX_IS_ARRAY_INDEX,
1524 RECEIVER_IS_STRING);
1525 char_at_generator.GenerateFast(masm);
1528 StubRuntimeCallHelper call_helper;
1529 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1532 PropertyAccessCompiler::TailCallBuiltin(
1533 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1537 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1538 // The displacement is the offset of the last parameter (if any)
1539 // relative to the frame pointer.
1540 const int kDisplacement =
1541 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1542 DCHECK(r1.is(ArgumentsAccessReadDescriptor::index()));
1543 DCHECK(r0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1545 // Check that the key is a smi.
1547 __ JumpIfNotSmi(r1, &slow);
1549 // Check if the calling frame is an arguments adaptor frame.
1551 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1552 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1553 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1556 // Check index against formal parameters count limit passed in
1557 // through register r0. Use unsigned comparison to get negative
1562 // Read the argument from the stack and return it.
1564 __ add(r3, fp, Operand::PointerOffsetFromSmiKey(r3));
1565 __ ldr(r0, MemOperand(r3, kDisplacement));
1568 // Arguments adaptor case: Check index against actual arguments
1569 // limit found in the arguments adaptor frame. Use unsigned
1570 // comparison to get negative check for free.
1572 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1576 // Read the argument from the adaptor frame and return it.
1578 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r3));
1579 __ ldr(r0, MemOperand(r3, kDisplacement));
1582 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1583 // by calling the runtime system.
1586 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1590 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1591 // sp[0] : number of parameters
1592 // sp[4] : receiver displacement
1595 // Check if the calling frame is an arguments adaptor frame.
1597 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1598 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1599 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1602 // Patch the arguments.length and the parameters pointer in the current frame.
1603 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1604 __ str(r2, MemOperand(sp, 0 * kPointerSize));
1605 __ add(r3, r3, Operand(r2, LSL, 1));
1606 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1607 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1610 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1614 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1616 // sp[0] : number of parameters (tagged)
1617 // sp[4] : address of receiver argument
1619 // Registers used over whole function:
1620 // r6 : allocated object (tagged)
1621 // r9 : mapped parameter count (tagged)
1623 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1624 // r1 = parameter count (tagged)
1626 // Check if the calling frame is an arguments adaptor frame.
1628 Label adaptor_frame, try_allocate;
1629 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1630 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1631 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1632 __ b(eq, &adaptor_frame);
1634 // No adaptor, parameter count = argument count.
1636 __ b(&try_allocate);
1638 // We have an adaptor frame. Patch the parameters pointer.
1639 __ bind(&adaptor_frame);
1640 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1641 __ add(r3, r3, Operand(r2, LSL, 1));
1642 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1643 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1645 // r1 = parameter count (tagged)
1646 // r2 = argument count (tagged)
1647 // Compute the mapped parameter count = min(r1, r2) in r1.
1648 __ cmp(r1, Operand(r2));
1649 __ mov(r1, Operand(r2), LeaveCC, gt);
1651 __ bind(&try_allocate);
1653 // Compute the sizes of backing store, parameter map, and arguments object.
1654 // 1. Parameter map, has 2 extra words containing context and backing store.
1655 const int kParameterMapHeaderSize =
1656 FixedArray::kHeaderSize + 2 * kPointerSize;
1657 // If there are no mapped parameters, we do not need the parameter_map.
1658 __ cmp(r1, Operand(Smi::FromInt(0)));
1659 __ mov(r9, Operand::Zero(), LeaveCC, eq);
1660 __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne);
1661 __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne);
1663 // 2. Backing store.
1664 __ add(r9, r9, Operand(r2, LSL, 1));
1665 __ add(r9, r9, Operand(FixedArray::kHeaderSize));
1667 // 3. Arguments object.
1668 __ add(r9, r9, Operand(Heap::kSloppyArgumentsObjectSize));
1670 // Do the allocation of all three objects in one go.
1671 __ Allocate(r9, r0, r3, r4, &runtime, TAG_OBJECT);
1673 // r0 = address of new object(s) (tagged)
1674 // r2 = argument count (smi-tagged)
1675 // Get the arguments boilerplate from the current native context into r4.
1676 const int kNormalOffset =
1677 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1678 const int kAliasedOffset =
1679 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1681 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1682 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1683 __ cmp(r1, Operand::Zero());
1684 __ ldr(r4, MemOperand(r4, kNormalOffset), eq);
1685 __ ldr(r4, MemOperand(r4, kAliasedOffset), ne);
1687 // r0 = address of new object (tagged)
1688 // r1 = mapped parameter count (tagged)
1689 // r2 = argument count (smi-tagged)
1690 // r4 = address of arguments map (tagged)
1691 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1692 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1693 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1694 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1696 // Set up the callee in-object property.
1697 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1698 __ ldr(r3, MemOperand(sp, 2 * kPointerSize));
1699 __ AssertNotSmi(r3);
1700 const int kCalleeOffset = JSObject::kHeaderSize +
1701 Heap::kArgumentsCalleeIndex * kPointerSize;
1702 __ str(r3, FieldMemOperand(r0, kCalleeOffset));
1704 // Use the length (smi tagged) and set that as an in-object property too.
1706 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1707 const int kLengthOffset = JSObject::kHeaderSize +
1708 Heap::kArgumentsLengthIndex * kPointerSize;
1709 __ str(r2, FieldMemOperand(r0, kLengthOffset));
1711 // Set up the elements pointer in the allocated arguments object.
1712 // If we allocated a parameter map, r4 will point there, otherwise
1713 // it will point to the backing store.
1714 __ add(r4, r0, Operand(Heap::kSloppyArgumentsObjectSize));
1715 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1717 // r0 = address of new object (tagged)
1718 // r1 = mapped parameter count (tagged)
1719 // r2 = argument count (tagged)
1720 // r4 = address of parameter map or backing store (tagged)
1721 // Initialize parameter map. If there are no mapped arguments, we're done.
1722 Label skip_parameter_map;
1723 __ cmp(r1, Operand(Smi::FromInt(0)));
1724 // Move backing store address to r3, because it is
1725 // expected there when filling in the unmapped arguments.
1726 __ mov(r3, r4, LeaveCC, eq);
1727 __ b(eq, &skip_parameter_map);
1729 __ LoadRoot(r6, Heap::kSloppyArgumentsElementsMapRootIndex);
1730 __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset));
1731 __ add(r6, r1, Operand(Smi::FromInt(2)));
1732 __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset));
1733 __ str(cp, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize));
1734 __ add(r6, r4, Operand(r1, LSL, 1));
1735 __ add(r6, r6, Operand(kParameterMapHeaderSize));
1736 __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize));
1738 // Copy the parameter slots and the holes in the arguments.
1739 // We need to fill in mapped_parameter_count slots. They index the context,
1740 // where parameters are stored in reverse order, at
1741 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1742 // The mapped parameter thus need to get indices
1743 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1744 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1745 // We loop from right to left.
1746 Label parameters_loop, parameters_test;
1748 __ ldr(r9, MemOperand(sp, 0 * kPointerSize));
1749 __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1750 __ sub(r9, r9, Operand(r1));
1751 __ LoadRoot(r5, Heap::kTheHoleValueRootIndex);
1752 __ add(r3, r4, Operand(r6, LSL, 1));
1753 __ add(r3, r3, Operand(kParameterMapHeaderSize));
1755 // r6 = loop variable (tagged)
1756 // r1 = mapping index (tagged)
1757 // r3 = address of backing store (tagged)
1758 // r4 = address of parameter map (tagged), which is also the address of new
1759 // object + Heap::kSloppyArgumentsObjectSize (tagged)
1760 // r0 = temporary scratch (a.o., for address calculation)
1761 // r5 = the hole value
1762 __ jmp(¶meters_test);
1764 __ bind(¶meters_loop);
1765 __ sub(r6, r6, Operand(Smi::FromInt(1)));
1766 __ mov(r0, Operand(r6, LSL, 1));
1767 __ add(r0, r0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1768 __ str(r9, MemOperand(r4, r0));
1769 __ sub(r0, r0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1770 __ str(r5, MemOperand(r3, r0));
1771 __ add(r9, r9, Operand(Smi::FromInt(1)));
1772 __ bind(¶meters_test);
1773 __ cmp(r6, Operand(Smi::FromInt(0)));
1774 __ b(ne, ¶meters_loop);
1776 // Restore r0 = new object (tagged)
1777 __ sub(r0, r4, Operand(Heap::kSloppyArgumentsObjectSize));
1779 __ bind(&skip_parameter_map);
1780 // r0 = address of new object (tagged)
1781 // r2 = argument count (tagged)
1782 // r3 = address of backing store (tagged)
1784 // Copy arguments header and remaining slots (if there are any).
1785 __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex);
1786 __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset));
1787 __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset));
1789 Label arguments_loop, arguments_test;
1791 __ ldr(r4, MemOperand(sp, 1 * kPointerSize));
1792 __ sub(r4, r4, Operand(r9, LSL, 1));
1793 __ jmp(&arguments_test);
1795 __ bind(&arguments_loop);
1796 __ sub(r4, r4, Operand(kPointerSize));
1797 __ ldr(r6, MemOperand(r4, 0));
1798 __ add(r5, r3, Operand(r9, LSL, 1));
1799 __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize));
1800 __ add(r9, r9, Operand(Smi::FromInt(1)));
1802 __ bind(&arguments_test);
1803 __ cmp(r9, Operand(r2));
1804 __ b(lt, &arguments_loop);
1806 // Return and remove the on-stack parameters.
1807 __ add(sp, sp, Operand(3 * kPointerSize));
1810 // Do the runtime call to allocate the arguments object.
1811 // r0 = address of new object (tagged)
1812 // r2 = argument count (tagged)
1814 __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1815 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1819 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1820 // Return address is in lr.
1823 Register receiver = LoadDescriptor::ReceiverRegister();
1824 Register key = LoadDescriptor::NameRegister();
1826 // Check that the key is an array index, that is Uint32.
1827 __ NonNegativeSmiTst(key);
1830 // Everything is fine, call runtime.
1831 __ Push(receiver, key); // Receiver, key.
1833 // Perform tail call to the entry.
1834 __ TailCallExternalReference(
1835 ExternalReference(IC_Utility(IC::kLoadElementWithInterceptor),
1840 PropertyAccessCompiler::TailCallBuiltin(
1841 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1845 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1846 // sp[0] : number of parameters
1847 // sp[4] : receiver displacement
1849 // Check if the calling frame is an arguments adaptor frame.
1850 Label adaptor_frame, try_allocate, runtime;
1851 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1852 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1853 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1854 __ b(eq, &adaptor_frame);
1856 // Get the length from the frame.
1857 __ ldr(r1, MemOperand(sp, 0));
1858 __ b(&try_allocate);
1860 // Patch the arguments.length and the parameters pointer.
1861 __ bind(&adaptor_frame);
1862 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1863 __ str(r1, MemOperand(sp, 0));
1864 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1865 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1866 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1868 // Try the new space allocation. Start out with computing the size
1869 // of the arguments object and the elements array in words.
1870 Label add_arguments_object;
1871 __ bind(&try_allocate);
1872 __ SmiUntag(r1, SetCC);
1873 __ b(eq, &add_arguments_object);
1874 __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize));
1875 __ bind(&add_arguments_object);
1876 __ add(r1, r1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1878 // Do the allocation of both objects in one go.
1879 __ Allocate(r1, r0, r2, r3, &runtime,
1880 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1882 // Get the arguments boilerplate from the current native context.
1883 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1884 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1885 __ ldr(r4, MemOperand(
1886 r4, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1888 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1889 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1890 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1891 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1893 // Get the length (smi tagged) and set that as an in-object property too.
1894 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1895 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1897 __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize +
1898 Heap::kArgumentsLengthIndex * kPointerSize));
1900 // If there are no actual arguments, we're done.
1902 __ cmp(r1, Operand::Zero());
1905 // Get the parameters pointer from the stack.
1906 __ ldr(r2, MemOperand(sp, 1 * kPointerSize));
1908 // Set up the elements pointer in the allocated arguments object and
1909 // initialize the header in the elements fixed array.
1910 __ add(r4, r0, Operand(Heap::kStrictArgumentsObjectSize));
1911 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1912 __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex);
1913 __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset));
1914 __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset));
1917 // Copy the fixed array slots.
1919 // Set up r4 to point to the first array slot.
1920 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1922 // Pre-decrement r2 with kPointerSize on each iteration.
1923 // Pre-decrement in order to skip receiver.
1924 __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
1925 // Post-increment r4 with kPointerSize on each iteration.
1926 __ str(r3, MemOperand(r4, kPointerSize, PostIndex));
1927 __ sub(r1, r1, Operand(1));
1928 __ cmp(r1, Operand::Zero());
1931 // Return and remove the on-stack parameters.
1933 __ add(sp, sp, Operand(3 * kPointerSize));
1936 // Do the runtime call to allocate the arguments object.
1938 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1942 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
1943 // Stack layout on entry.
1944 // sp[0] : language mode
1945 // sp[4] : index of rest parameter
1946 // sp[8] : number of parameters
1947 // sp[12] : receiver displacement
1950 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1951 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1952 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1955 // Patch the arguments.length and the parameters pointer.
1956 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1957 __ str(r1, MemOperand(sp, 2 * kPointerSize));
1958 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1959 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1960 __ str(r3, MemOperand(sp, 3 * kPointerSize));
1963 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
1967 void RegExpExecStub::Generate(MacroAssembler* masm) {
1968 // Just jump directly to runtime if native RegExp is not selected at compile
1969 // time or if regexp entry in generated code is turned off runtime switch or
1971 #ifdef V8_INTERPRETED_REGEXP
1972 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1973 #else // V8_INTERPRETED_REGEXP
1975 // Stack frame on entry.
1976 // sp[0]: last_match_info (expected JSArray)
1977 // sp[4]: previous index
1978 // sp[8]: subject string
1979 // sp[12]: JSRegExp object
1981 const int kLastMatchInfoOffset = 0 * kPointerSize;
1982 const int kPreviousIndexOffset = 1 * kPointerSize;
1983 const int kSubjectOffset = 2 * kPointerSize;
1984 const int kJSRegExpOffset = 3 * kPointerSize;
1987 // Allocation of registers for this function. These are in callee save
1988 // registers and will be preserved by the call to the native RegExp code, as
1989 // this code is called using the normal C calling convention. When calling
1990 // directly from generated code the native RegExp code will not do a GC and
1991 // therefore the content of these registers are safe to use after the call.
1992 Register subject = r4;
1993 Register regexp_data = r5;
1994 Register last_match_info_elements = no_reg; // will be r6;
1996 // Ensure that a RegExp stack is allocated.
1997 ExternalReference address_of_regexp_stack_memory_address =
1998 ExternalReference::address_of_regexp_stack_memory_address(isolate());
1999 ExternalReference address_of_regexp_stack_memory_size =
2000 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2001 __ mov(r0, Operand(address_of_regexp_stack_memory_size));
2002 __ ldr(r0, MemOperand(r0, 0));
2003 __ cmp(r0, Operand::Zero());
2006 // Check that the first argument is a JSRegExp object.
2007 __ ldr(r0, MemOperand(sp, kJSRegExpOffset));
2008 __ JumpIfSmi(r0, &runtime);
2009 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
2012 // Check that the RegExp has been compiled (data contains a fixed array).
2013 __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
2014 if (FLAG_debug_code) {
2015 __ SmiTst(regexp_data);
2016 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2017 __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
2018 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2021 // regexp_data: RegExp data (FixedArray)
2022 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2023 __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2024 __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2027 // regexp_data: RegExp data (FixedArray)
2028 // Check that the number of captures fit in the static offsets vector buffer.
2030 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2031 // Check (number_of_captures + 1) * 2 <= offsets vector size
2032 // Or number_of_captures * 2 <= offsets vector size - 2
2033 // Multiplying by 2 comes for free since r2 is smi-tagged.
2034 STATIC_ASSERT(kSmiTag == 0);
2035 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2036 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2037 __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2040 // Reset offset for possibly sliced string.
2041 __ mov(r9, Operand::Zero());
2042 __ ldr(subject, MemOperand(sp, kSubjectOffset));
2043 __ JumpIfSmi(subject, &runtime);
2044 __ mov(r3, subject); // Make a copy of the original subject string.
2045 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2046 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2047 // subject: subject string
2048 // r3: subject string
2049 // r0: subject string instance type
2050 // regexp_data: RegExp data (FixedArray)
2051 // Handle subject string according to its encoding and representation:
2052 // (1) Sequential string? If yes, go to (5).
2053 // (2) Anything but sequential or cons? If yes, go to (6).
2054 // (3) Cons string. If the string is flat, replace subject with first string.
2055 // Otherwise bailout.
2056 // (4) Is subject external? If yes, go to (7).
2057 // (5) Sequential string. Load regexp code according to encoding.
2061 // Deferred code at the end of the stub:
2062 // (6) Not a long external string? If yes, go to (8).
2063 // (7) External string. Make it, offset-wise, look like a sequential string.
2065 // (8) Short external string or not a string? If yes, bail out to runtime.
2066 // (9) Sliced string. Replace subject with parent. Go to (4).
2068 Label seq_string /* 5 */, external_string /* 7 */,
2069 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2070 not_long_external /* 8 */;
2072 // (1) Sequential string? If yes, go to (5).
2075 Operand(kIsNotStringMask |
2076 kStringRepresentationMask |
2077 kShortExternalStringMask),
2079 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2080 __ b(eq, &seq_string); // Go to (5).
2082 // (2) Anything but sequential or cons? If yes, go to (6).
2083 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2084 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2085 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2086 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2087 __ cmp(r1, Operand(kExternalStringTag));
2088 __ b(ge, ¬_seq_nor_cons); // Go to (6).
2090 // (3) Cons string. Check that it's flat.
2091 // Replace subject with first string and reload instance type.
2092 __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
2093 __ CompareRoot(r0, Heap::kempty_stringRootIndex);
2095 __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2097 // (4) Is subject external? If yes, go to (7).
2098 __ bind(&check_underlying);
2099 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2100 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2101 STATIC_ASSERT(kSeqStringTag == 0);
2102 __ tst(r0, Operand(kStringRepresentationMask));
2103 // The underlying external string is never a short external string.
2104 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2105 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2106 __ b(ne, &external_string); // Go to (7).
2108 // (5) Sequential string. Load regexp code according to encoding.
2109 __ bind(&seq_string);
2110 // subject: sequential subject string (or look-alike, external string)
2111 // r3: original subject string
2112 // Load previous index and check range before r3 is overwritten. We have to
2113 // use r3 instead of subject here because subject might have been only made
2114 // to look like a sequential string when it actually is an external string.
2115 __ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
2116 __ JumpIfNotSmi(r1, &runtime);
2117 __ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
2118 __ cmp(r3, Operand(r1));
2122 STATIC_ASSERT(4 == kOneByteStringTag);
2123 STATIC_ASSERT(kTwoByteStringTag == 0);
2124 __ and_(r0, r0, Operand(kStringEncodingMask));
2125 __ mov(r3, Operand(r0, ASR, 2), SetCC);
2126 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset),
2128 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
2130 // (E) Carry on. String handling is done.
2131 // r6: irregexp code
2132 // Check that the irregexp code has been generated for the actual string
2133 // encoding. If it has, the field contains a code object otherwise it contains
2134 // a smi (code flushing support).
2135 __ JumpIfSmi(r6, &runtime);
2137 // r1: previous index
2138 // r3: encoding of subject string (1 if one_byte, 0 if two_byte);
2140 // subject: Subject string
2141 // regexp_data: RegExp data (FixedArray)
2142 // All checks done. Now push arguments for native regexp code.
2143 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r0, r2);
2145 // Isolates: note we add an additional parameter here (isolate pointer).
2146 const int kRegExpExecuteArguments = 9;
2147 const int kParameterRegisters = 4;
2148 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2150 // Stack pointer now points to cell where return address is to be written.
2151 // Arguments are before that on the stack or in registers.
2153 // Argument 9 (sp[20]): Pass current isolate address.
2154 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2155 __ str(r0, MemOperand(sp, 5 * kPointerSize));
2157 // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
2158 __ mov(r0, Operand(1));
2159 __ str(r0, MemOperand(sp, 4 * kPointerSize));
2161 // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
2162 __ mov(r0, Operand(address_of_regexp_stack_memory_address));
2163 __ ldr(r0, MemOperand(r0, 0));
2164 __ mov(r2, Operand(address_of_regexp_stack_memory_size));
2165 __ ldr(r2, MemOperand(r2, 0));
2166 __ add(r0, r0, Operand(r2));
2167 __ str(r0, MemOperand(sp, 3 * kPointerSize));
2169 // Argument 6: Set the number of capture registers to zero to force global
2170 // regexps to behave as non-global. This does not affect non-global regexps.
2171 __ mov(r0, Operand::Zero());
2172 __ str(r0, MemOperand(sp, 2 * kPointerSize));
2174 // Argument 5 (sp[4]): static offsets vector buffer.
2176 Operand(ExternalReference::address_of_static_offsets_vector(
2178 __ str(r0, MemOperand(sp, 1 * kPointerSize));
2180 // For arguments 4 and 3 get string length, calculate start of string data and
2181 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2182 __ add(r7, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2183 __ eor(r3, r3, Operand(1));
2184 // Load the length from the original subject string from the previous stack
2185 // frame. Therefore we have to use fp, which points exactly to two pointer
2186 // sizes below the previous sp. (Because creating a new stack frame pushes
2187 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2188 __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2189 // If slice offset is not 0, load the length from the original sliced string.
2190 // Argument 4, r3: End of string data
2191 // Argument 3, r2: Start of string data
2192 // Prepare start and end index of the input.
2193 __ add(r9, r7, Operand(r9, LSL, r3));
2194 __ add(r2, r9, Operand(r1, LSL, r3));
2196 __ ldr(r7, FieldMemOperand(subject, String::kLengthOffset));
2198 __ add(r3, r9, Operand(r7, LSL, r3));
2200 // Argument 2 (r1): Previous index.
2203 // Argument 1 (r0): Subject string.
2204 __ mov(r0, subject);
2206 // Locate the code entry and call it.
2207 __ add(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
2208 DirectCEntryStub stub(isolate());
2209 stub.GenerateCall(masm, r6);
2211 __ LeaveExitFrame(false, no_reg, true);
2213 last_match_info_elements = r6;
2216 // subject: subject string (callee saved)
2217 // regexp_data: RegExp data (callee saved)
2218 // last_match_info_elements: Last match info elements (callee saved)
2219 // Check the result.
2221 __ cmp(r0, Operand(1));
2222 // We expect exactly one result since we force the called regexp to behave
2226 __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
2228 __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2229 // If not exception it can only be retry. Handle that in the runtime system.
2231 // Result must now be exception. If there is no pending exception already a
2232 // stack overflow (on the backtrack stack) was detected in RegExp code but
2233 // haven't created the exception yet. Handle that in the runtime system.
2234 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2235 __ mov(r1, Operand(isolate()->factory()->the_hole_value()));
2236 __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2238 __ ldr(r0, MemOperand(r2, 0));
2242 // For exception, throw the exception again.
2243 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2246 // For failure and exception return null.
2247 __ mov(r0, Operand(isolate()->factory()->null_value()));
2248 __ add(sp, sp, Operand(4 * kPointerSize));
2251 // Process the result from the native regexp code.
2254 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2255 // Calculate number of capture registers (number_of_captures + 1) * 2.
2256 // Multiplying by 2 comes for free since r1 is smi-tagged.
2257 STATIC_ASSERT(kSmiTag == 0);
2258 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2259 __ add(r1, r1, Operand(2)); // r1 was a smi.
2261 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2262 __ JumpIfSmi(r0, &runtime);
2263 __ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
2265 // Check that the JSArray is in fast case.
2266 __ ldr(last_match_info_elements,
2267 FieldMemOperand(r0, JSArray::kElementsOffset));
2268 __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2269 __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
2271 // Check that the last match info has space for the capture registers and the
2272 // additional information.
2274 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2275 __ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
2276 __ cmp(r2, Operand::SmiUntag(r0));
2279 // r1: number of capture registers
2280 // r4: subject string
2281 // Store the capture count.
2283 __ str(r2, FieldMemOperand(last_match_info_elements,
2284 RegExpImpl::kLastCaptureCountOffset));
2285 // Store last subject and last input.
2287 FieldMemOperand(last_match_info_elements,
2288 RegExpImpl::kLastSubjectOffset));
2289 __ mov(r2, subject);
2290 __ RecordWriteField(last_match_info_elements,
2291 RegExpImpl::kLastSubjectOffset,
2296 __ mov(subject, r2);
2298 FieldMemOperand(last_match_info_elements,
2299 RegExpImpl::kLastInputOffset));
2300 __ RecordWriteField(last_match_info_elements,
2301 RegExpImpl::kLastInputOffset,
2307 // Get the static offsets vector filled by the native regexp code.
2308 ExternalReference address_of_static_offsets_vector =
2309 ExternalReference::address_of_static_offsets_vector(isolate());
2310 __ mov(r2, Operand(address_of_static_offsets_vector));
2312 // r1: number of capture registers
2313 // r2: offsets vector
2314 Label next_capture, done;
2315 // Capture register counter starts from number of capture registers and
2316 // counts down until wraping after zero.
2318 last_match_info_elements,
2319 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2320 __ bind(&next_capture);
2321 __ sub(r1, r1, Operand(1), SetCC);
2323 // Read the value from the static offsets vector buffer.
2324 __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
2325 // Store the smi value in the last match info.
2327 __ str(r3, MemOperand(r0, kPointerSize, PostIndex));
2328 __ jmp(&next_capture);
2331 // Return last match info.
2332 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2333 __ add(sp, sp, Operand(4 * kPointerSize));
2336 // Do the runtime call to execute the regexp.
2338 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2340 // Deferred code for string handling.
2341 // (6) Not a long external string? If yes, go to (8).
2342 __ bind(¬_seq_nor_cons);
2343 // Compare flags are still set.
2344 __ b(gt, ¬_long_external); // Go to (8).
2346 // (7) External string. Make it, offset-wise, look like a sequential string.
2347 __ bind(&external_string);
2348 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2349 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2350 if (FLAG_debug_code) {
2351 // Assert that we do not have a cons or slice (indirect strings) here.
2352 // Sequential strings have already been ruled out.
2353 __ tst(r0, Operand(kIsIndirectStringMask));
2354 __ Assert(eq, kExternalStringExpectedButNotFound);
2357 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2358 // Move the pointer so that offset-wise, it looks like a sequential string.
2359 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2362 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2363 __ jmp(&seq_string); // Go to (5).
2365 // (8) Short external string or not a string? If yes, bail out to runtime.
2366 __ bind(¬_long_external);
2367 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2368 __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
2371 // (9) Sliced string. Replace subject with parent. Go to (4).
2372 // Load offset into r9 and replace subject string with parent.
2373 __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2375 __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2376 __ jmp(&check_underlying); // Go to (4).
2377 #endif // V8_INTERPRETED_REGEXP
2381 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
2382 // r0 : number of arguments to the construct function
2383 // r2 : Feedback vector
2384 // r3 : slot in feedback vector (Smi)
2385 // r1 : the function to call
2386 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2388 // Number-of-arguments register must be smi-tagged to call out.
2390 __ Push(r3, r2, r1, r0);
2394 __ Pop(r3, r2, r1, r0);
2399 static void GenerateRecordCallTarget(MacroAssembler* masm) {
2400 // Cache the called function in a feedback vector slot. Cache states
2401 // are uninitialized, monomorphic (indicated by a JSFunction), and
2403 // r0 : number of arguments to the construct function
2404 // r1 : the function to call
2405 // r2 : Feedback vector
2406 // r3 : slot in feedback vector (Smi)
2407 Label initialize, done, miss, megamorphic, not_array_function;
2409 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2410 masm->isolate()->heap()->megamorphic_symbol());
2411 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2412 masm->isolate()->heap()->uninitialized_symbol());
2414 // Load the cache state into r4.
2415 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2416 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2418 // A monomorphic cache hit or an already megamorphic state: invoke the
2419 // function without changing the state.
2420 // We don't know if r4 is a WeakCell or a Symbol, but it's harmless to read at
2421 // this position in a symbol (see static asserts in type-feedback-vector.h).
2422 Label check_allocation_site;
2423 Register feedback_map = r5;
2424 Register weak_value = r6;
2425 __ ldr(weak_value, FieldMemOperand(r4, WeakCell::kValueOffset));
2426 __ cmp(r1, weak_value);
2428 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2430 __ ldr(feedback_map, FieldMemOperand(r4, HeapObject::kMapOffset));
2431 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2432 __ b(ne, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2434 // If the weak cell is cleared, we have a new chance to become monomorphic.
2435 __ JumpIfSmi(weak_value, &initialize);
2436 __ jmp(&megamorphic);
2438 if (!FLAG_pretenuring_call_new) {
2439 __ bind(&check_allocation_site);
2440 // If we came here, we need to see if we are the array function.
2441 // If we didn't have a matching function, and we didn't find the megamorph
2442 // sentinel, then we have in the slot either some other function or an
2444 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2447 // Make sure the function is the Array() function
2448 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2450 __ b(ne, &megamorphic);
2456 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2458 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2459 __ b(eq, &initialize);
2460 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2461 // write-barrier is needed.
2462 __ bind(&megamorphic);
2463 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2464 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2465 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2468 // An uninitialized cache is patched with the function
2469 __ bind(&initialize);
2471 if (!FLAG_pretenuring_call_new) {
2472 // Make sure the function is the Array() function
2473 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2475 __ b(ne, ¬_array_function);
2477 // The target function is the Array constructor,
2478 // Create an AllocationSite if we don't already have it, store it in the
2480 CreateAllocationSiteStub create_stub(masm->isolate());
2481 CallStubInRecordCallTarget(masm, &create_stub);
2484 __ bind(¬_array_function);
2487 CreateWeakCellStub create_stub(masm->isolate());
2488 CallStubInRecordCallTarget(masm, &create_stub);
2493 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2494 // Do not transform the receiver for strict mode functions.
2495 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2496 __ ldr(r4, FieldMemOperand(r3, SharedFunctionInfo::kCompilerHintsOffset));
2497 __ tst(r4, Operand(1 << (SharedFunctionInfo::kStrictModeFunction +
2501 // Do not transform the receiver for native (Compilerhints already in r3).
2502 __ tst(r4, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
2507 static void EmitSlowCase(MacroAssembler* masm,
2509 Label* non_function) {
2510 // Check for function proxy.
2511 __ cmp(r4, Operand(JS_FUNCTION_PROXY_TYPE));
2512 __ b(ne, non_function);
2513 __ push(r1); // put proxy as additional argument
2514 __ mov(r0, Operand(argc + 1, RelocInfo::NONE32));
2515 __ mov(r2, Operand::Zero());
2516 __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY);
2518 Handle<Code> adaptor =
2519 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2520 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2523 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2524 // of the original receiver from the call site).
2525 __ bind(non_function);
2526 __ str(r1, MemOperand(sp, argc * kPointerSize));
2527 __ mov(r0, Operand(argc)); // Set up the number of arguments.
2528 __ mov(r2, Operand::Zero());
2529 __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION);
2530 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2531 RelocInfo::CODE_TARGET);
2535 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2536 // Wrap the receiver and patch it back onto the stack.
2537 { FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2539 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2542 __ str(r0, MemOperand(sp, argc * kPointerSize));
2547 static void CallFunctionNoFeedback(MacroAssembler* masm,
2548 int argc, bool needs_checks,
2549 bool call_as_method) {
2550 // r1 : the function to call
2551 Label slow, non_function, wrap, cont;
2554 // Check that the function is really a JavaScript function.
2555 // r1: pushed function (to be verified)
2556 __ JumpIfSmi(r1, &non_function);
2558 // Goto slow case if we do not have a function.
2559 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2563 // Fast-case: Invoke the function now.
2564 // r1: pushed function
2565 ParameterCount actual(argc);
2567 if (call_as_method) {
2569 EmitContinueIfStrictOrNative(masm, &cont);
2572 // Compute the receiver in sloppy mode.
2573 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2576 __ JumpIfSmi(r3, &wrap);
2577 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2586 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2589 // Slow-case: Non-function called.
2591 EmitSlowCase(masm, argc, &non_function);
2594 if (call_as_method) {
2596 EmitWrapCase(masm, argc, &cont);
2601 void CallFunctionStub::Generate(MacroAssembler* masm) {
2602 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2606 void CallConstructStub::Generate(MacroAssembler* masm) {
2607 // r0 : number of arguments
2608 // r1 : the function to call
2609 // r2 : feedback vector
2610 // r3 : slot in feedback vector (Smi, for RecordCallTarget)
2611 // r4 : original constructor (for IsSuperConstructorCall)
2612 Label slow, non_function_call;
2614 // Check that the function is not a smi.
2615 __ JumpIfSmi(r1, &non_function_call);
2616 // Check that the function is a JSFunction.
2617 __ CompareObjectType(r1, r5, r5, JS_FUNCTION_TYPE);
2620 if (RecordCallTarget()) {
2621 if (IsSuperConstructorCall()) {
2624 // TODO(mstarzinger): Consider tweaking target recording to avoid push/pop.
2625 GenerateRecordCallTarget(masm);
2626 if (IsSuperConstructorCall()) {
2630 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2631 if (FLAG_pretenuring_call_new) {
2632 // Put the AllocationSite from the feedback vector into r2.
2633 // By adding kPointerSize we encode that we know the AllocationSite
2634 // entry is at the feedback vector slot given by r3 + 1.
2635 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize + kPointerSize));
2637 Label feedback_register_initialized;
2638 // Put the AllocationSite from the feedback vector into r2, or undefined.
2639 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2640 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2641 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2642 __ b(eq, &feedback_register_initialized);
2643 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2644 __ bind(&feedback_register_initialized);
2647 __ AssertUndefinedOrAllocationSite(r2, r5);
2650 // Pass function as original constructor.
2651 if (IsSuperConstructorCall()) {
2657 // Jump to the function-specific construct stub.
2658 Register jmp_reg = r4;
2659 __ ldr(jmp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2660 __ ldr(jmp_reg, FieldMemOperand(jmp_reg,
2661 SharedFunctionInfo::kConstructStubOffset));
2662 __ add(pc, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2664 // r0: number of arguments
2665 // r1: called object
2669 __ cmp(r5, Operand(JS_FUNCTION_PROXY_TYPE));
2670 __ b(ne, &non_function_call);
2671 __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2674 __ bind(&non_function_call);
2675 __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2677 // Set expected number of arguments to zero (not changing r0).
2678 __ mov(r2, Operand::Zero());
2679 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2680 RelocInfo::CODE_TARGET);
2684 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2685 __ ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2686 __ ldr(vector, FieldMemOperand(vector,
2687 JSFunction::kSharedFunctionInfoOffset));
2688 __ ldr(vector, FieldMemOperand(vector,
2689 SharedFunctionInfo::kFeedbackVectorOffset));
2693 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2698 int argc = arg_count();
2699 ParameterCount actual(argc);
2701 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2705 __ mov(r0, Operand(arg_count()));
2706 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2707 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2709 // Verify that r4 contains an AllocationSite
2710 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2711 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2714 // Increment the call count for monomorphic function calls.
2715 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2716 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2717 __ ldr(r3, FieldMemOperand(r2, 0));
2718 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2719 __ str(r3, FieldMemOperand(r2, 0));
2723 ArrayConstructorStub stub(masm->isolate(), arg_count());
2724 __ TailCallStub(&stub);
2729 // The slow case, we need this no matter what to complete a call after a miss.
2730 CallFunctionNoFeedback(masm,
2736 __ stop("Unexpected code address");
2740 void CallICStub::Generate(MacroAssembler* masm) {
2742 // r3 - slot id (Smi)
2744 const int with_types_offset =
2745 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2746 const int generic_offset =
2747 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2748 Label extra_checks_or_miss, slow_start;
2749 Label slow, non_function, wrap, cont;
2750 Label have_js_function;
2751 int argc = arg_count();
2752 ParameterCount actual(argc);
2754 // The checks. First, does r1 match the recorded monomorphic target?
2755 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2756 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2758 // We don't know that we have a weak cell. We might have a private symbol
2759 // or an AllocationSite, but the memory is safe to examine.
2760 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2762 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2763 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2764 // computed, meaning that it can't appear to be a pointer. If the low bit is
2765 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2767 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2768 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2769 WeakCell::kValueOffset &&
2770 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2772 __ ldr(r5, FieldMemOperand(r4, WeakCell::kValueOffset));
2774 __ b(ne, &extra_checks_or_miss);
2776 // The compare above could have been a SMI/SMI comparison. Guard against this
2777 // convincing us that we have a monomorphic JSFunction.
2778 __ JumpIfSmi(r1, &extra_checks_or_miss);
2780 // Increment the call count for monomorphic function calls.
2781 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2782 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2783 __ ldr(r3, FieldMemOperand(r2, 0));
2784 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2785 __ str(r3, FieldMemOperand(r2, 0));
2787 __ bind(&have_js_function);
2788 if (CallAsMethod()) {
2789 EmitContinueIfStrictOrNative(masm, &cont);
2790 // Compute the receiver in sloppy mode.
2791 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2793 __ JumpIfSmi(r3, &wrap);
2794 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2800 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2803 EmitSlowCase(masm, argc, &non_function);
2805 if (CallAsMethod()) {
2807 EmitWrapCase(masm, argc, &cont);
2810 __ bind(&extra_checks_or_miss);
2811 Label uninitialized, miss;
2813 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2814 __ b(eq, &slow_start);
2816 // The following cases attempt to handle MISS cases without going to the
2818 if (FLAG_trace_ic) {
2822 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2823 __ b(eq, &uninitialized);
2825 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2826 // to handle it here. More complex cases are dealt with in the runtime.
2827 __ AssertNotSmi(r4);
2828 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2830 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2831 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2832 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2833 // We have to update statistics for runtime profiling.
2834 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2835 __ sub(r4, r4, Operand(Smi::FromInt(1)));
2836 __ str(r4, FieldMemOperand(r2, with_types_offset));
2837 __ ldr(r4, FieldMemOperand(r2, generic_offset));
2838 __ add(r4, r4, Operand(Smi::FromInt(1)));
2839 __ str(r4, FieldMemOperand(r2, generic_offset));
2840 __ jmp(&slow_start);
2842 __ bind(&uninitialized);
2844 // We are going monomorphic, provided we actually have a JSFunction.
2845 __ JumpIfSmi(r1, &miss);
2847 // Goto miss case if we do not have a function.
2848 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2851 // Make sure the function is not the Array() function, which requires special
2852 // behavior on MISS.
2853 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2858 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2859 __ add(r4, r4, Operand(Smi::FromInt(1)));
2860 __ str(r4, FieldMemOperand(r2, with_types_offset));
2862 // Initialize the call counter.
2863 __ Move(r5, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2864 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2865 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + kPointerSize));
2867 // Store the function. Use a stub since we need a frame for allocation.
2872 FrameScope scope(masm, StackFrame::INTERNAL);
2873 CreateWeakCellStub create_stub(masm->isolate());
2875 __ CallStub(&create_stub);
2879 __ jmp(&have_js_function);
2881 // We are here because tracing is on or we encountered a MISS case we can't
2887 __ bind(&slow_start);
2888 // Check that the function is really a JavaScript function.
2889 // r1: pushed function (to be verified)
2890 __ JumpIfSmi(r1, &non_function);
2892 // Goto slow case if we do not have a function.
2893 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2895 __ jmp(&have_js_function);
2899 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2900 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2902 // Push the receiver and the function and feedback info.
2903 __ Push(r1, r2, r3);
2906 IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
2907 : IC::kCallIC_Customization_Miss;
2909 ExternalReference miss = ExternalReference(IC_Utility(id), masm->isolate());
2910 __ CallExternalReference(miss, 3);
2912 // Move result to edi and exit the internal frame.
2917 // StringCharCodeAtGenerator
2918 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2919 // If the receiver is a smi trigger the non-string case.
2920 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2921 __ JumpIfSmi(object_, receiver_not_string_);
2923 // Fetch the instance type of the receiver into result register.
2924 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2925 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2926 // If the receiver is not a string trigger the non-string case.
2927 __ tst(result_, Operand(kIsNotStringMask));
2928 __ b(ne, receiver_not_string_);
2931 // If the index is non-smi trigger the non-smi case.
2932 __ JumpIfNotSmi(index_, &index_not_smi_);
2933 __ bind(&got_smi_index_);
2935 // Check for index out of range.
2936 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
2937 __ cmp(ip, Operand(index_));
2938 __ b(ls, index_out_of_range_);
2940 __ SmiUntag(index_);
2942 StringCharLoadGenerator::Generate(masm,
2953 void StringCharCodeAtGenerator::GenerateSlow(
2954 MacroAssembler* masm, EmbedMode embed_mode,
2955 const RuntimeCallHelper& call_helper) {
2956 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2958 // Index is not a smi.
2959 __ bind(&index_not_smi_);
2960 // If index is a heap number, try converting it to an integer.
2963 Heap::kHeapNumberMapRootIndex,
2966 call_helper.BeforeCall(masm);
2967 if (embed_mode == PART_OF_IC_HANDLER) {
2968 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2969 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2971 // index_ is consumed by runtime conversion function.
2972 __ Push(object_, index_);
2974 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2975 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2977 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2978 // NumberToSmi discards numbers that are not exact integers.
2979 __ CallRuntime(Runtime::kNumberToSmi, 1);
2981 // Save the conversion result before the pop instructions below
2982 // have a chance to overwrite it.
2983 __ Move(index_, r0);
2984 if (embed_mode == PART_OF_IC_HANDLER) {
2985 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2986 LoadWithVectorDescriptor::SlotRegister(), object_);
2990 // Reload the instance type.
2991 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2992 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2993 call_helper.AfterCall(masm);
2994 // If index is still not a smi, it must be out of range.
2995 __ JumpIfNotSmi(index_, index_out_of_range_);
2996 // Otherwise, return to the fast path.
2997 __ jmp(&got_smi_index_);
2999 // Call runtime. We get here when the receiver is a string and the
3000 // index is a number, but the code of getting the actual character
3001 // is too complex (e.g., when the string needs to be flattened).
3002 __ bind(&call_runtime_);
3003 call_helper.BeforeCall(masm);
3005 __ Push(object_, index_);
3006 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3007 __ Move(result_, r0);
3008 call_helper.AfterCall(masm);
3011 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3015 // -------------------------------------------------------------------------
3016 // StringCharFromCodeGenerator
3018 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3019 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3020 STATIC_ASSERT(kSmiTag == 0);
3021 STATIC_ASSERT(kSmiShiftSize == 0);
3022 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3023 __ tst(code_, Operand(kSmiTagMask |
3024 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3025 __ b(ne, &slow_case_);
3027 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3028 // At this point code register contains smi tagged one-byte char code.
3029 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
3030 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3031 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
3032 __ b(eq, &slow_case_);
3037 void StringCharFromCodeGenerator::GenerateSlow(
3038 MacroAssembler* masm,
3039 const RuntimeCallHelper& call_helper) {
3040 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3042 __ bind(&slow_case_);
3043 call_helper.BeforeCall(masm);
3045 __ CallRuntime(Runtime::kCharFromCode, 1);
3046 __ Move(result_, r0);
3047 call_helper.AfterCall(masm);
3050 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3054 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3057 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3062 String::Encoding encoding) {
3063 if (FLAG_debug_code) {
3064 // Check that destination is word aligned.
3065 __ tst(dest, Operand(kPointerAlignmentMask));
3066 __ Check(eq, kDestinationOfCopyNotAligned);
3069 // Assumes word reads and writes are little endian.
3070 // Nothing to do for zero characters.
3072 if (encoding == String::TWO_BYTE_ENCODING) {
3073 __ add(count, count, Operand(count), SetCC);
3076 Register limit = count; // Read until dest equals this.
3077 __ add(limit, dest, Operand(count));
3079 Label loop_entry, loop;
3080 // Copy bytes from src to dest until dest hits limit.
3083 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
3084 __ strb(scratch, MemOperand(dest, 1, PostIndex));
3085 __ bind(&loop_entry);
3086 __ cmp(dest, Operand(limit));
3093 void SubStringStub::Generate(MacroAssembler* masm) {
3096 // Stack frame on entry.
3097 // lr: return address
3102 // This stub is called from the native-call %_SubString(...), so
3103 // nothing can be assumed about the arguments. It is tested that:
3104 // "string" is a sequential string,
3105 // both "from" and "to" are smis, and
3106 // 0 <= from <= to <= string.length.
3107 // If any of these assumptions fail, we call the runtime system.
3109 const int kToOffset = 0 * kPointerSize;
3110 const int kFromOffset = 1 * kPointerSize;
3111 const int kStringOffset = 2 * kPointerSize;
3113 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
3114 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3115 STATIC_ASSERT(kSmiTag == 0);
3116 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3118 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
3119 // instead because we bail out on non-smi values: ROR and ASR are equivalent
3120 // for smis but they set the flags in a way that's easier to optimize.
3121 __ mov(r2, Operand(r2, ROR, 1), SetCC);
3122 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
3123 // If either to or from had the smi tag bit set, then C is set now, and N
3124 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
3125 // We want to bailout to runtime here if From is negative. In that case, the
3126 // next instruction is not executed and we fall through to bailing out to
3128 // Executed if both r2 and r3 are untagged integers.
3129 __ sub(r2, r2, Operand(r3), SetCC, cc);
3130 // One of the above un-smis or the above SUB could have set N==1.
3131 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
3133 // Make sure first argument is a string.
3134 __ ldr(r0, MemOperand(sp, kStringOffset));
3135 __ JumpIfSmi(r0, &runtime);
3136 Condition is_string = masm->IsObjectStringType(r0, r1);
3137 __ b(NegateCondition(is_string), &runtime);
3140 __ cmp(r2, Operand(1));
3141 __ b(eq, &single_char);
3143 // Short-cut for the case of trivial substring.
3145 // r0: original string
3146 // r2: result string length
3147 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
3148 __ cmp(r2, Operand(r4, ASR, 1));
3149 // Return original string.
3150 __ b(eq, &return_r0);
3151 // Longer than original string's length or negative: unsafe arguments.
3153 // Shorter than original string's length: an actual substring.
3155 // Deal with different string types: update the index if necessary
3156 // and put the underlying string into r5.
3157 // r0: original string
3158 // r1: instance type
3160 // r3: from index (untagged)
3161 Label underlying_unpacked, sliced_string, seq_or_external_string;
3162 // If the string is not indirect, it can only be sequential or external.
3163 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3164 STATIC_ASSERT(kIsIndirectStringMask != 0);
3165 __ tst(r1, Operand(kIsIndirectStringMask));
3166 __ b(eq, &seq_or_external_string);
3168 __ tst(r1, Operand(kSlicedNotConsMask));
3169 __ b(ne, &sliced_string);
3170 // Cons string. Check whether it is flat, then fetch first part.
3171 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
3172 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
3174 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
3175 // Update instance type.
3176 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3177 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3178 __ jmp(&underlying_unpacked);
3180 __ bind(&sliced_string);
3181 // Sliced string. Fetch parent and correct start index by offset.
3182 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3183 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3184 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
3185 // Update instance type.
3186 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3187 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3188 __ jmp(&underlying_unpacked);
3190 __ bind(&seq_or_external_string);
3191 // Sequential or external string. Just move string to the expected register.
3194 __ bind(&underlying_unpacked);
3196 if (FLAG_string_slices) {
3198 // r5: underlying subject string
3199 // r1: instance type of underlying subject string
3201 // r3: adjusted start index (untagged)
3202 __ cmp(r2, Operand(SlicedString::kMinLength));
3203 // Short slice. Copy instead of slicing.
3204 __ b(lt, ©_routine);
3205 // Allocate new sliced string. At this point we do not reload the instance
3206 // type including the string encoding because we simply rely on the info
3207 // provided by the original string. It does not matter if the original
3208 // string's encoding is wrong because we always have to recheck encoding of
3209 // the newly created string's parent anyways due to externalized strings.
3210 Label two_byte_slice, set_slice_header;
3211 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3212 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3213 __ tst(r1, Operand(kStringEncodingMask));
3214 __ b(eq, &two_byte_slice);
3215 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
3216 __ jmp(&set_slice_header);
3217 __ bind(&two_byte_slice);
3218 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
3219 __ bind(&set_slice_header);
3220 __ mov(r3, Operand(r3, LSL, 1));
3221 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3222 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3225 __ bind(©_routine);
3228 // r5: underlying subject string
3229 // r1: instance type of underlying subject string
3231 // r3: adjusted start index (untagged)
3232 Label two_byte_sequential, sequential_string, allocate_result;
3233 STATIC_ASSERT(kExternalStringTag != 0);
3234 STATIC_ASSERT(kSeqStringTag == 0);
3235 __ tst(r1, Operand(kExternalStringTag));
3236 __ b(eq, &sequential_string);
3238 // Handle external string.
3239 // Rule out short external strings.
3240 STATIC_ASSERT(kShortExternalStringTag != 0);
3241 __ tst(r1, Operand(kShortExternalStringTag));
3243 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
3244 // r5 already points to the first character of underlying string.
3245 __ jmp(&allocate_result);
3247 __ bind(&sequential_string);
3248 // Locate first character of underlying subject string.
3249 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3250 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3252 __ bind(&allocate_result);
3253 // Sequential acii string. Allocate the result.
3254 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3255 __ tst(r1, Operand(kStringEncodingMask));
3256 __ b(eq, &two_byte_sequential);
3258 // Allocate and copy the resulting one-byte string.
3259 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
3261 // Locate first character of substring to copy.
3263 // Locate first character of result.
3264 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3266 // r0: result string
3267 // r1: first character of result string
3268 // r2: result string length
3269 // r5: first character of substring to copy
3270 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3271 StringHelper::GenerateCopyCharacters(
3272 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
3275 // Allocate and copy the resulting two-byte string.
3276 __ bind(&two_byte_sequential);
3277 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
3279 // Locate first character of substring to copy.
3280 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3281 __ add(r5, r5, Operand(r3, LSL, 1));
3282 // Locate first character of result.
3283 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3285 // r0: result string.
3286 // r1: first character of result.
3287 // r2: result length.
3288 // r5: first character of substring to copy.
3289 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3290 StringHelper::GenerateCopyCharacters(
3291 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
3293 __ bind(&return_r0);
3294 Counters* counters = isolate()->counters();
3295 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
3299 // Just jump to runtime to create the sub string.
3301 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3303 __ bind(&single_char);
3304 // r0: original string
3305 // r1: instance type
3307 // r3: from index (untagged)
3309 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
3310 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3311 generator.GenerateFast(masm);
3314 generator.SkipSlow(masm, &runtime);
3318 void ToNumberStub::Generate(MacroAssembler* masm) {
3319 // The ToNumber stub takes one argument in r0.
3321 __ JumpIfNotSmi(r0, ¬_smi);
3325 Label not_heap_number;
3326 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
3327 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3329 // r1: instance type.
3330 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
3331 __ b(ne, ¬_heap_number);
3333 __ bind(¬_heap_number);
3335 Label not_string, slow_string;
3336 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
3337 __ b(hs, ¬_string);
3338 // Check if string has a cached array index.
3339 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
3340 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
3341 __ b(ne, &slow_string);
3342 __ IndexFromHash(r2, r0);
3344 __ bind(&slow_string);
3345 __ push(r0); // Push argument.
3346 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3347 __ bind(¬_string);
3350 __ cmp(r1, Operand(ODDBALL_TYPE));
3351 __ b(ne, ¬_oddball);
3352 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
3354 __ bind(¬_oddball);
3356 __ push(r0); // Push argument.
3357 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3361 void StringHelper::GenerateFlatOneByteStringEquals(
3362 MacroAssembler* masm, Register left, Register right, Register scratch1,
3363 Register scratch2, Register scratch3) {
3364 Register length = scratch1;
3367 Label strings_not_equal, check_zero_length;
3368 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
3369 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3370 __ cmp(length, scratch2);
3371 __ b(eq, &check_zero_length);
3372 __ bind(&strings_not_equal);
3373 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
3376 // Check if the length is zero.
3377 Label compare_chars;
3378 __ bind(&check_zero_length);
3379 STATIC_ASSERT(kSmiTag == 0);
3380 __ cmp(length, Operand::Zero());
3381 __ b(ne, &compare_chars);
3382 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3385 // Compare characters.
3386 __ bind(&compare_chars);
3387 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3388 &strings_not_equal);
3390 // Characters are equal.
3391 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3396 void StringHelper::GenerateCompareFlatOneByteStrings(
3397 MacroAssembler* masm, Register left, Register right, Register scratch1,
3398 Register scratch2, Register scratch3, Register scratch4) {
3399 Label result_not_equal, compare_lengths;
3400 // Find minimum length and length difference.
3401 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3402 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3403 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
3404 Register length_delta = scratch3;
3405 __ mov(scratch1, scratch2, LeaveCC, gt);
3406 Register min_length = scratch1;
3407 STATIC_ASSERT(kSmiTag == 0);
3408 __ cmp(min_length, Operand::Zero());
3409 __ b(eq, &compare_lengths);
3412 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3413 scratch4, &result_not_equal);
3415 // Compare lengths - strings up to min-length are equal.
3416 __ bind(&compare_lengths);
3417 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3418 // Use length_delta as result if it's zero.
3419 __ mov(r0, Operand(length_delta), SetCC);
3420 __ bind(&result_not_equal);
3421 // Conditionally update the result based either on length_delta or
3422 // the last comparion performed in the loop above.
3423 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
3424 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
3429 void StringHelper::GenerateOneByteCharsCompareLoop(
3430 MacroAssembler* masm, Register left, Register right, Register length,
3431 Register scratch1, Register scratch2, Label* chars_not_equal) {
3432 // Change index to run from -length to -1 by adding length to string
3433 // start. This means that loop ends when index reaches zero, which
3434 // doesn't need an additional compare.
3435 __ SmiUntag(length);
3436 __ add(scratch1, length,
3437 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3438 __ add(left, left, Operand(scratch1));
3439 __ add(right, right, Operand(scratch1));
3440 __ rsb(length, length, Operand::Zero());
3441 Register index = length; // index = -length;
3446 __ ldrb(scratch1, MemOperand(left, index));
3447 __ ldrb(scratch2, MemOperand(right, index));
3448 __ cmp(scratch1, scratch2);
3449 __ b(ne, chars_not_equal);
3450 __ add(index, index, Operand(1), SetCC);
3455 void StringCompareStub::Generate(MacroAssembler* masm) {
3458 Counters* counters = isolate()->counters();
3460 // Stack frame on entry.
3461 // sp[0]: right string
3462 // sp[4]: left string
3463 __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1.
3467 __ b(ne, ¬_same);
3468 STATIC_ASSERT(EQUAL == 0);
3469 STATIC_ASSERT(kSmiTag == 0);
3470 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3471 __ IncrementCounter(counters->string_compare_native(), 1, r1, r2);
3472 __ add(sp, sp, Operand(2 * kPointerSize));
3477 // Check that both objects are sequential one-byte strings.
3478 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
3480 // Compare flat one-byte strings natively. Remove arguments from stack first.
3481 __ IncrementCounter(counters->string_compare_native(), 1, r2, r3);
3482 __ add(sp, sp, Operand(2 * kPointerSize));
3483 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
3485 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3486 // tagged as a small integer.
3488 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3492 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3493 // ----------- S t a t e -------------
3496 // -- lr : return address
3497 // -----------------------------------
3499 // Load r2 with the allocation site. We stick an undefined dummy value here
3500 // and replace it with the real allocation site later when we instantiate this
3501 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3502 __ Move(r2, handle(isolate()->heap()->undefined_value()));
3504 // Make sure that we actually patched the allocation site.
3505 if (FLAG_debug_code) {
3506 __ tst(r2, Operand(kSmiTagMask));
3507 __ Assert(ne, kExpectedAllocationSite);
3509 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3510 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3513 __ Assert(eq, kExpectedAllocationSite);
3516 // Tail call into the stub that handles binary operations with allocation
3518 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3519 __ TailCallStub(&stub);
3523 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3524 DCHECK(state() == CompareICState::SMI);
3527 __ JumpIfNotSmi(r2, &miss);
3529 if (GetCondition() == eq) {
3530 // For equality we do not care about the sign of the result.
3531 __ sub(r0, r0, r1, SetCC);
3533 // Untag before subtracting to avoid handling overflow.
3535 __ sub(r0, r1, Operand::SmiUntag(r0));
3544 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3545 DCHECK(state() == CompareICState::NUMBER);
3548 Label unordered, maybe_undefined1, maybe_undefined2;
3551 if (left() == CompareICState::SMI) {
3552 __ JumpIfNotSmi(r1, &miss);
3554 if (right() == CompareICState::SMI) {
3555 __ JumpIfNotSmi(r0, &miss);
3558 // Inlining the double comparison and falling back to the general compare
3559 // stub if NaN is involved.
3560 // Load left and right operand.
3561 Label done, left, left_smi, right_smi;
3562 __ JumpIfSmi(r0, &right_smi);
3563 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3565 __ sub(r2, r0, Operand(kHeapObjectTag));
3566 __ vldr(d1, r2, HeapNumber::kValueOffset);
3568 __ bind(&right_smi);
3569 __ SmiToDouble(d1, r0);
3572 __ JumpIfSmi(r1, &left_smi);
3573 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3575 __ sub(r2, r1, Operand(kHeapObjectTag));
3576 __ vldr(d0, r2, HeapNumber::kValueOffset);
3579 __ SmiToDouble(d0, r1);
3582 // Compare operands.
3583 __ VFPCompareAndSetFlags(d0, d1);
3585 // Don't base result on status bits when a NaN is involved.
3586 __ b(vs, &unordered);
3588 // Return a result of -1, 0, or 1, based on status bits.
3589 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
3590 __ mov(r0, Operand(LESS), LeaveCC, lt);
3591 __ mov(r0, Operand(GREATER), LeaveCC, gt);
3594 __ bind(&unordered);
3595 __ bind(&generic_stub);
3596 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3597 CompareICState::GENERIC, CompareICState::GENERIC);
3598 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3600 __ bind(&maybe_undefined1);
3601 if (Token::IsOrderedRelationalCompareOp(op())) {
3602 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3604 __ JumpIfSmi(r1, &unordered);
3605 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3606 __ b(ne, &maybe_undefined2);
3610 __ bind(&maybe_undefined2);
3611 if (Token::IsOrderedRelationalCompareOp(op())) {
3612 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3613 __ b(eq, &unordered);
3621 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3622 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3625 // Registers containing left and right operands respectively.
3627 Register right = r0;
3631 // Check that both operands are heap objects.
3632 __ JumpIfEitherSmi(left, right, &miss);
3634 // Check that both operands are internalized strings.
3635 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3636 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3637 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3638 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3639 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3640 __ orr(tmp1, tmp1, Operand(tmp2));
3641 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3644 // Internalized strings are compared by identity.
3645 __ cmp(left, right);
3646 // Make sure r0 is non-zero. At this point input operands are
3647 // guaranteed to be non-zero.
3648 DCHECK(right.is(r0));
3649 STATIC_ASSERT(EQUAL == 0);
3650 STATIC_ASSERT(kSmiTag == 0);
3651 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3659 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3660 DCHECK(state() == CompareICState::UNIQUE_NAME);
3661 DCHECK(GetCondition() == eq);
3664 // Registers containing left and right operands respectively.
3666 Register right = r0;
3670 // Check that both operands are heap objects.
3671 __ JumpIfEitherSmi(left, right, &miss);
3673 // Check that both operands are unique names. This leaves the instance
3674 // types loaded in tmp1 and tmp2.
3675 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3676 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3677 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3678 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3680 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3681 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3683 // Unique names are compared by identity.
3684 __ cmp(left, right);
3685 // Make sure r0 is non-zero. At this point input operands are
3686 // guaranteed to be non-zero.
3687 DCHECK(right.is(r0));
3688 STATIC_ASSERT(EQUAL == 0);
3689 STATIC_ASSERT(kSmiTag == 0);
3690 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3698 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3699 DCHECK(state() == CompareICState::STRING);
3702 bool equality = Token::IsEqualityOp(op());
3704 // Registers containing left and right operands respectively.
3706 Register right = r0;
3712 // Check that both operands are heap objects.
3713 __ JumpIfEitherSmi(left, right, &miss);
3715 // Check that both operands are strings. This leaves the instance
3716 // types loaded in tmp1 and tmp2.
3717 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3718 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3719 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3720 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3721 STATIC_ASSERT(kNotStringTag != 0);
3722 __ orr(tmp3, tmp1, tmp2);
3723 __ tst(tmp3, Operand(kIsNotStringMask));
3726 // Fast check for identical strings.
3727 __ cmp(left, right);
3728 STATIC_ASSERT(EQUAL == 0);
3729 STATIC_ASSERT(kSmiTag == 0);
3730 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3733 // Handle not identical strings.
3735 // Check that both strings are internalized strings. If they are, we're done
3736 // because we already know they are not identical. We know they are both
3739 DCHECK(GetCondition() == eq);
3740 STATIC_ASSERT(kInternalizedTag == 0);
3741 __ orr(tmp3, tmp1, Operand(tmp2));
3742 __ tst(tmp3, Operand(kIsNotInternalizedMask));
3743 // Make sure r0 is non-zero. At this point input operands are
3744 // guaranteed to be non-zero.
3745 DCHECK(right.is(r0));
3749 // Check that both strings are sequential one-byte.
3751 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3754 // Compare flat one-byte strings. Returns when done.
3756 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3759 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3763 // Handle more complex cases in runtime.
3765 __ Push(left, right);
3767 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3769 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3777 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3778 DCHECK(state() == CompareICState::OBJECT);
3780 __ and_(r2, r1, Operand(r0));
3781 __ JumpIfSmi(r2, &miss);
3783 __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
3785 __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
3788 DCHECK(GetCondition() == eq);
3789 __ sub(r0, r0, Operand(r1));
3797 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3799 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3800 __ and_(r2, r1, Operand(r0));
3801 __ JumpIfSmi(r2, &miss);
3802 __ GetWeakValue(r4, cell);
3803 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3804 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
3810 __ sub(r0, r0, Operand(r1));
3818 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3820 // Call the runtime system in a fresh internal frame.
3821 ExternalReference miss =
3822 ExternalReference(IC_Utility(IC::kCompareIC_Miss), isolate());
3824 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3826 __ Push(lr, r1, r0);
3827 __ mov(ip, Operand(Smi::FromInt(op())));
3829 __ CallExternalReference(miss, 3);
3830 // Compute the entry point of the rewritten stub.
3831 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3832 // Restore registers.
3841 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3842 // Place the return address on the stack, making the call
3843 // GC safe. The RegExp backend also relies on this.
3844 __ str(lr, MemOperand(sp, 0));
3845 __ blx(ip); // Call the C++ function.
3846 __ VFPEnsureFPSCRState(r2);
3847 __ ldr(pc, MemOperand(sp, 0));
3851 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3854 reinterpret_cast<intptr_t>(GetCode().location());
3855 __ Move(ip, target);
3856 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3857 __ blx(lr); // Call the stub.
3861 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3865 Register properties,
3867 Register scratch0) {
3868 DCHECK(name->IsUniqueName());
3869 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3870 // not equal to the name and kProbes-th slot is not used (its name is the
3871 // undefined value), it guarantees the hash table doesn't contain the
3872 // property. It's true even if some slots represent deleted properties
3873 // (their names are the hole value).
3874 for (int i = 0; i < kInlinedProbes; i++) {
3875 // scratch0 points to properties hash.
3876 // Compute the masked index: (hash + i + i * i) & mask.
3877 Register index = scratch0;
3878 // Capacity is smi 2^n.
3879 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3880 __ sub(index, index, Operand(1));
3881 __ and_(index, index, Operand(
3882 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3884 // Scale the index by multiplying by the entry size.
3885 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3886 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3888 Register entity_name = scratch0;
3889 // Having undefined at this place means the name is not contained.
3890 DCHECK_EQ(kSmiTagSize, 1);
3891 Register tmp = properties;
3892 __ add(tmp, properties, Operand(index, LSL, 1));
3893 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3895 DCHECK(!tmp.is(entity_name));
3896 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3897 __ cmp(entity_name, tmp);
3900 // Load the hole ready for use below:
3901 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3903 // Stop if found the property.
3904 __ cmp(entity_name, Operand(Handle<Name>(name)));
3908 __ cmp(entity_name, tmp);
3911 // Check if the entry name is not a unique name.
3912 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3913 __ ldrb(entity_name,
3914 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3915 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3918 // Restore the properties.
3920 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3923 const int spill_mask =
3924 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3925 r2.bit() | r1.bit() | r0.bit());
3927 __ stm(db_w, sp, spill_mask);
3928 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3929 __ mov(r1, Operand(Handle<Name>(name)));
3930 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3932 __ cmp(r0, Operand::Zero());
3933 __ ldm(ia_w, sp, spill_mask);
3940 // Probe the name dictionary in the |elements| register. Jump to the
3941 // |done| label if a property with the given name is found. Jump to
3942 // the |miss| label otherwise.
3943 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
3944 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3950 Register scratch2) {
3951 DCHECK(!elements.is(scratch1));
3952 DCHECK(!elements.is(scratch2));
3953 DCHECK(!name.is(scratch1));
3954 DCHECK(!name.is(scratch2));
3956 __ AssertName(name);
3958 // Compute the capacity mask.
3959 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
3960 __ SmiUntag(scratch1);
3961 __ sub(scratch1, scratch1, Operand(1));
3963 // Generate an unrolled loop that performs a few probes before
3964 // giving up. Measurements done on Gmail indicate that 2 probes
3965 // cover ~93% of loads from dictionaries.
3966 for (int i = 0; i < kInlinedProbes; i++) {
3967 // Compute the masked index: (hash + i + i * i) & mask.
3968 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3970 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3971 // the hash in a separate instruction. The value hash + i + i * i is right
3972 // shifted in the following and instruction.
3973 DCHECK(NameDictionary::GetProbeOffset(i) <
3974 1 << (32 - Name::kHashFieldOffset));
3975 __ add(scratch2, scratch2, Operand(
3976 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3978 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
3980 // Scale the index by multiplying by the element size.
3981 DCHECK(NameDictionary::kEntrySize == 3);
3982 // scratch2 = scratch2 * 3.
3983 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3985 // Check if the key is identical to the name.
3986 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3987 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3988 __ cmp(name, Operand(ip));
3992 const int spill_mask =
3993 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3994 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3995 ~(scratch1.bit() | scratch2.bit());
3997 __ stm(db_w, sp, spill_mask);
3999 DCHECK(!elements.is(r1));
4001 __ Move(r0, elements);
4003 __ Move(r0, elements);
4006 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4008 __ cmp(r0, Operand::Zero());
4009 __ mov(scratch2, Operand(r2));
4010 __ ldm(ia_w, sp, spill_mask);
4017 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4018 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4019 // we cannot call anything that could cause a GC from this stub.
4021 // result: NameDictionary to probe
4023 // dictionary: NameDictionary to probe.
4024 // index: will hold an index of entry if lookup is successful.
4025 // might alias with result_.
4027 // result_ is zero if lookup failed, non zero otherwise.
4029 Register result = r0;
4030 Register dictionary = r0;
4032 Register index = r2;
4035 Register undefined = r5;
4036 Register entry_key = r6;
4038 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4040 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
4042 __ sub(mask, mask, Operand(1));
4044 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4046 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4048 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4049 // Compute the masked index: (hash + i + i * i) & mask.
4050 // Capacity is smi 2^n.
4052 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4053 // the hash in a separate instruction. The value hash + i + i * i is right
4054 // shifted in the following and instruction.
4055 DCHECK(NameDictionary::GetProbeOffset(i) <
4056 1 << (32 - Name::kHashFieldOffset));
4057 __ add(index, hash, Operand(
4058 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4060 __ mov(index, Operand(hash));
4062 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
4064 // Scale the index by multiplying by the entry size.
4065 DCHECK(NameDictionary::kEntrySize == 3);
4066 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
4068 DCHECK_EQ(kSmiTagSize, 1);
4069 __ add(index, dictionary, Operand(index, LSL, 2));
4070 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
4072 // Having undefined at this place means the name is not contained.
4073 __ cmp(entry_key, Operand(undefined));
4074 __ b(eq, ¬_in_dictionary);
4076 // Stop if found the property.
4077 __ cmp(entry_key, Operand(key));
4078 __ b(eq, &in_dictionary);
4080 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4081 // Check if the entry name is not a unique name.
4082 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4084 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4085 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4089 __ bind(&maybe_in_dictionary);
4090 // If we are doing negative lookup then probing failure should be
4091 // treated as a lookup success. For positive lookup probing failure
4092 // should be treated as lookup failure.
4093 if (mode() == POSITIVE_LOOKUP) {
4094 __ mov(result, Operand::Zero());
4098 __ bind(&in_dictionary);
4099 __ mov(result, Operand(1));
4102 __ bind(¬_in_dictionary);
4103 __ mov(result, Operand::Zero());
4108 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4110 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4112 // Hydrogen code stubs need stub2 at snapshot time.
4113 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4118 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4119 // the value has just been written into the object, now this stub makes sure
4120 // we keep the GC informed. The word in the object where the value has been
4121 // written is in the address register.
4122 void RecordWriteStub::Generate(MacroAssembler* masm) {
4123 Label skip_to_incremental_noncompacting;
4124 Label skip_to_incremental_compacting;
4126 // The first two instructions are generated with labels so as to get the
4127 // offset fixed up correctly by the bind(Label*) call. We patch it back and
4128 // forth between a compare instructions (a nop in this position) and the
4129 // real branch when we start and stop incremental heap marking.
4130 // See RecordWriteStub::Patch for details.
4132 // Block literal pool emission, as the position of these two instructions
4133 // is assumed by the patching code.
4134 Assembler::BlockConstPoolScope block_const_pool(masm);
4135 __ b(&skip_to_incremental_noncompacting);
4136 __ b(&skip_to_incremental_compacting);
4139 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4140 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4141 MacroAssembler::kReturnAtEnd);
4145 __ bind(&skip_to_incremental_noncompacting);
4146 GenerateIncremental(masm, INCREMENTAL);
4148 __ bind(&skip_to_incremental_compacting);
4149 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4151 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4152 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4153 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4154 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
4155 PatchBranchIntoNop(masm, 0);
4156 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4160 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4163 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4164 Label dont_need_remembered_set;
4166 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4167 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4169 &dont_need_remembered_set);
4171 __ CheckPageFlag(regs_.object(),
4173 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4175 &dont_need_remembered_set);
4177 // First notify the incremental marker if necessary, then update the
4179 CheckNeedsToInformIncrementalMarker(
4180 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4181 InformIncrementalMarker(masm);
4182 regs_.Restore(masm);
4183 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4184 MacroAssembler::kReturnAtEnd);
4186 __ bind(&dont_need_remembered_set);
4189 CheckNeedsToInformIncrementalMarker(
4190 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4191 InformIncrementalMarker(masm);
4192 regs_.Restore(masm);
4197 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4198 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4199 int argument_count = 3;
4200 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4202 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4203 DCHECK(!address.is(regs_.object()));
4204 DCHECK(!address.is(r0));
4205 __ Move(address, regs_.address());
4206 __ Move(r0, regs_.object());
4207 __ Move(r1, address);
4208 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4210 AllowExternalCallThatCantCauseGC scope(masm);
4212 ExternalReference::incremental_marking_record_write_function(isolate()),
4214 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4218 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4219 MacroAssembler* masm,
4220 OnNoNeedToInformIncrementalMarker on_no_need,
4223 Label need_incremental;
4224 Label need_incremental_pop_scratch;
4226 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4227 __ ldr(regs_.scratch1(),
4228 MemOperand(regs_.scratch0(),
4229 MemoryChunk::kWriteBarrierCounterOffset));
4230 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4231 __ str(regs_.scratch1(),
4232 MemOperand(regs_.scratch0(),
4233 MemoryChunk::kWriteBarrierCounterOffset));
4234 __ b(mi, &need_incremental);
4236 // Let's look at the color of the object: If it is not black we don't have
4237 // to inform the incremental marker.
4238 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4240 regs_.Restore(masm);
4241 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4242 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4243 MacroAssembler::kReturnAtEnd);
4250 // Get the value from the slot.
4251 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4253 if (mode == INCREMENTAL_COMPACTION) {
4254 Label ensure_not_white;
4256 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4257 regs_.scratch1(), // Scratch.
4258 MemoryChunk::kEvacuationCandidateMask,
4262 __ CheckPageFlag(regs_.object(),
4263 regs_.scratch1(), // Scratch.
4264 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4268 __ bind(&ensure_not_white);
4271 // We need extra registers for this, so we push the object and the address
4272 // register temporarily.
4273 __ Push(regs_.object(), regs_.address());
4274 __ EnsureNotWhite(regs_.scratch0(), // The value.
4275 regs_.scratch1(), // Scratch.
4276 regs_.object(), // Scratch.
4277 regs_.address(), // Scratch.
4278 &need_incremental_pop_scratch);
4279 __ Pop(regs_.object(), regs_.address());
4281 regs_.Restore(masm);
4282 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4283 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4284 MacroAssembler::kReturnAtEnd);
4289 __ bind(&need_incremental_pop_scratch);
4290 __ Pop(regs_.object(), regs_.address());
4292 __ bind(&need_incremental);
4294 // Fall through when we need to inform the incremental marker.
4298 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4299 // ----------- S t a t e -------------
4300 // -- r0 : element value to store
4301 // -- r3 : element index as smi
4302 // -- sp[0] : array literal index in function as smi
4303 // -- sp[4] : array literal
4304 // clobbers r1, r2, r4
4305 // -----------------------------------
4308 Label double_elements;
4310 Label slow_elements;
4311 Label fast_elements;
4313 // Get array literal index, array literal and its map.
4314 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4315 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4316 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4318 __ CheckFastElements(r2, r5, &double_elements);
4319 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4320 __ JumpIfSmi(r0, &smi_element);
4321 __ CheckFastSmiElements(r2, r5, &fast_elements);
4323 // Store into the array literal requires a elements transition. Call into
4325 __ bind(&slow_elements);
4327 __ Push(r1, r3, r0);
4328 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4329 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4331 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4333 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4334 __ bind(&fast_elements);
4335 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4336 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4337 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4338 __ str(r0, MemOperand(r6, 0));
4339 // Update the write barrier for the array store.
4340 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4341 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4344 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4345 // and value is Smi.
4346 __ bind(&smi_element);
4347 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4348 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4349 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4352 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4353 __ bind(&double_elements);
4354 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4355 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
4360 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4361 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4362 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4363 int parameter_count_offset =
4364 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4365 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4366 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4367 __ add(r1, r1, Operand(1));
4369 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4370 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4376 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4377 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4378 LoadICStub stub(isolate(), state());
4379 stub.GenerateForTrampoline(masm);
4383 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4384 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4385 KeyedLoadICStub stub(isolate(), state());
4386 stub.GenerateForTrampoline(masm);
4390 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4391 EmitLoadTypeFeedbackVector(masm, r2);
4392 CallICStub stub(isolate(), state());
4393 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4397 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4398 EmitLoadTypeFeedbackVector(masm, r2);
4399 CallIC_ArrayStub stub(isolate(), state());
4400 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4404 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4407 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4408 GenerateImpl(masm, true);
4412 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4413 Register key, Register vector, Register slot,
4414 Register feedback, Register receiver_map,
4415 Register scratch1, Register scratch2,
4416 bool is_polymorphic, Label* miss) {
4417 // feedback initially contains the feedback array
4418 Label next_loop, prepare_next;
4419 Label start_polymorphic;
4421 Register cached_map = scratch1;
4424 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4425 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4426 __ cmp(receiver_map, cached_map);
4427 __ b(ne, &start_polymorphic);
4428 // found, now call handler.
4429 Register handler = feedback;
4430 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4431 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4434 Register length = scratch2;
4435 __ bind(&start_polymorphic);
4436 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4437 if (!is_polymorphic) {
4438 // If the IC could be monomorphic we have to make sure we don't go past the
4439 // end of the feedback array.
4440 __ cmp(length, Operand(Smi::FromInt(2)));
4444 Register too_far = length;
4445 Register pointer_reg = feedback;
4447 // +-----+------+------+-----+-----+ ... ----+
4448 // | map | len | wm0 | h0 | wm1 | hN |
4449 // +-----+------+------+-----+-----+ ... ----+
4453 // pointer_reg too_far
4454 // aka feedback scratch2
4455 // also need receiver_map
4456 // use cached_map (scratch1) to look in the weak map values.
4457 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
4458 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4459 __ add(pointer_reg, feedback,
4460 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4462 __ bind(&next_loop);
4463 __ ldr(cached_map, MemOperand(pointer_reg));
4464 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4465 __ cmp(receiver_map, cached_map);
4466 __ b(ne, &prepare_next);
4467 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
4468 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4470 __ bind(&prepare_next);
4471 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4472 __ cmp(pointer_reg, too_far);
4473 __ b(lt, &next_loop);
4475 // We exhausted our array of map handler pairs.
4480 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4481 Register receiver_map, Register feedback,
4482 Register vector, Register slot,
4483 Register scratch, Label* compare_map,
4484 Label* load_smi_map, Label* try_array) {
4485 __ JumpIfSmi(receiver, load_smi_map);
4486 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4487 __ bind(compare_map);
4488 Register cached_map = scratch;
4489 // Move the weak map into the weak_cell register.
4490 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4491 __ cmp(cached_map, receiver_map);
4492 __ b(ne, try_array);
4493 Register handler = feedback;
4494 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
4496 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4497 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4501 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4502 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4503 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
4504 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4505 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4506 Register feedback = r4;
4507 Register receiver_map = r5;
4508 Register scratch1 = r6;
4510 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4511 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4513 // Try to quickly handle the monomorphic case without knowing for sure
4514 // if we have a weak cell in feedback. We do know it's safe to look
4515 // at WeakCell::kValueOffset.
4516 Label try_array, load_smi_map, compare_map;
4517 Label not_array, miss;
4518 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4519 scratch1, &compare_map, &load_smi_map, &try_array);
4521 // Is it a fixed array?
4522 __ bind(&try_array);
4523 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4524 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4525 __ b(ne, ¬_array);
4526 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4527 scratch1, r9, true, &miss);
4529 __ bind(¬_array);
4530 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4532 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4533 Code::ComputeHandlerFlags(Code::LOAD_IC));
4534 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4535 false, receiver, name, feedback,
4536 receiver_map, scratch1, r9);
4539 LoadIC::GenerateMiss(masm);
4542 __ bind(&load_smi_map);
4543 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4544 __ jmp(&compare_map);
4548 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4549 GenerateImpl(masm, false);
4553 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4554 GenerateImpl(masm, true);
4558 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4559 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4560 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
4561 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4562 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4563 Register feedback = r4;
4564 Register receiver_map = r5;
4565 Register scratch1 = r6;
4567 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4568 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4570 // Try to quickly handle the monomorphic case without knowing for sure
4571 // if we have a weak cell in feedback. We do know it's safe to look
4572 // at WeakCell::kValueOffset.
4573 Label try_array, load_smi_map, compare_map;
4574 Label not_array, miss;
4575 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4576 scratch1, &compare_map, &load_smi_map, &try_array);
4578 __ bind(&try_array);
4579 // Is it a fixed array?
4580 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4581 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4582 __ b(ne, ¬_array);
4584 // We have a polymorphic element handler.
4585 Label polymorphic, try_poly_name;
4586 __ bind(&polymorphic);
4587 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4588 scratch1, r9, true, &miss);
4590 __ bind(¬_array);
4592 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4593 __ b(ne, &try_poly_name);
4594 Handle<Code> megamorphic_stub =
4595 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4596 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4598 __ bind(&try_poly_name);
4599 // We might have a name in feedback, and a fixed array in the next slot.
4600 __ cmp(key, feedback);
4602 // If the name comparison succeeded, we know we have a fixed array with
4603 // at least one map/handler pair.
4604 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4606 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4607 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4608 scratch1, r9, false, &miss);
4611 KeyedLoadIC::GenerateMiss(masm);
4613 __ bind(&load_smi_map);
4614 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4615 __ jmp(&compare_map);
4619 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4620 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4621 VectorStoreICStub stub(isolate(), state());
4622 stub.GenerateForTrampoline(masm);
4626 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4627 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4628 VectorKeyedStoreICStub stub(isolate(), state());
4629 stub.GenerateForTrampoline(masm);
4633 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4634 GenerateImpl(masm, false);
4638 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4639 GenerateImpl(masm, true);
4643 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4646 // TODO(mvstanton): Implement.
4648 StoreIC::GenerateMiss(masm);
4652 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4653 GenerateImpl(masm, false);
4657 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4658 GenerateImpl(masm, true);
4662 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4665 // TODO(mvstanton): Implement.
4667 KeyedStoreIC::GenerateMiss(masm);
4671 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4672 if (masm->isolate()->function_entry_hook() != NULL) {
4673 ProfileEntryHookStub stub(masm->isolate());
4674 int code_size = masm->CallStubSize(&stub) + 2 * Assembler::kInstrSize;
4675 PredictableCodeSizeScope predictable(masm, code_size);
4683 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4684 // The entry hook is a "push lr" instruction, followed by a call.
4685 const int32_t kReturnAddressDistanceFromFunctionStart =
4686 3 * Assembler::kInstrSize;
4688 // This should contain all kCallerSaved registers.
4689 const RegList kSavedRegs =
4696 // We also save lr, so the count here is one higher than the mask indicates.
4697 const int32_t kNumSavedRegs = 7;
4699 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4701 // Save all caller-save registers as this may be called from anywhere.
4702 __ stm(db_w, sp, kSavedRegs | lr.bit());
4704 // Compute the function's address for the first argument.
4705 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4707 // The caller's return address is above the saved temporaries.
4708 // Grab that for the second argument to the hook.
4709 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4711 // Align the stack if necessary.
4712 int frame_alignment = masm->ActivationFrameAlignment();
4713 if (frame_alignment > kPointerSize) {
4715 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4716 __ and_(sp, sp, Operand(-frame_alignment));
4719 #if V8_HOST_ARCH_ARM
4720 int32_t entry_hook =
4721 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4722 __ mov(ip, Operand(entry_hook));
4724 // Under the simulator we need to indirect the entry hook through a
4725 // trampoline function at a known address.
4726 // It additionally takes an isolate as a third parameter
4727 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4729 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4730 __ mov(ip, Operand(ExternalReference(&dispatcher,
4731 ExternalReference::BUILTIN_CALL,
4736 // Restore the stack pointer if needed.
4737 if (frame_alignment > kPointerSize) {
4741 // Also pop pc to get Ret(0).
4742 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4747 static void CreateArrayDispatch(MacroAssembler* masm,
4748 AllocationSiteOverrideMode mode) {
4749 if (mode == DISABLE_ALLOCATION_SITES) {
4750 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4751 __ TailCallStub(&stub);
4752 } else if (mode == DONT_OVERRIDE) {
4753 int last_index = GetSequenceIndexFromFastElementsKind(
4754 TERMINAL_FAST_ELEMENTS_KIND);
4755 for (int i = 0; i <= last_index; ++i) {
4756 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4757 __ cmp(r3, Operand(kind));
4758 T stub(masm->isolate(), kind);
4759 __ TailCallStub(&stub, eq);
4762 // If we reached this point there is a problem.
4763 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4770 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4771 AllocationSiteOverrideMode mode) {
4772 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4773 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4774 // r0 - number of arguments
4775 // r1 - constructor?
4776 // sp[0] - last argument
4777 Label normal_sequence;
4778 if (mode == DONT_OVERRIDE) {
4779 DCHECK(FAST_SMI_ELEMENTS == 0);
4780 DCHECK(FAST_HOLEY_SMI_ELEMENTS == 1);
4781 DCHECK(FAST_ELEMENTS == 2);
4782 DCHECK(FAST_HOLEY_ELEMENTS == 3);
4783 DCHECK(FAST_DOUBLE_ELEMENTS == 4);
4784 DCHECK(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4786 // is the low bit set? If so, we are holey and that is good.
4787 __ tst(r3, Operand(1));
4788 __ b(ne, &normal_sequence);
4791 // look at the first argument
4792 __ ldr(r5, MemOperand(sp, 0));
4793 __ cmp(r5, Operand::Zero());
4794 __ b(eq, &normal_sequence);
4796 if (mode == DISABLE_ALLOCATION_SITES) {
4797 ElementsKind initial = GetInitialFastElementsKind();
4798 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4800 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4802 DISABLE_ALLOCATION_SITES);
4803 __ TailCallStub(&stub_holey);
4805 __ bind(&normal_sequence);
4806 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4808 DISABLE_ALLOCATION_SITES);
4809 __ TailCallStub(&stub);
4810 } else if (mode == DONT_OVERRIDE) {
4811 // We are going to create a holey array, but our kind is non-holey.
4812 // Fix kind and retry (only if we have an allocation site in the slot).
4813 __ add(r3, r3, Operand(1));
4815 if (FLAG_debug_code) {
4816 __ ldr(r5, FieldMemOperand(r2, 0));
4817 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4818 __ Assert(eq, kExpectedAllocationSite);
4821 // Save the resulting elements kind in type info. We can't just store r3
4822 // in the AllocationSite::transition_info field because elements kind is
4823 // restricted to a portion of the field...upper bits need to be left alone.
4824 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4825 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4826 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4827 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4829 __ bind(&normal_sequence);
4830 int last_index = GetSequenceIndexFromFastElementsKind(
4831 TERMINAL_FAST_ELEMENTS_KIND);
4832 for (int i = 0; i <= last_index; ++i) {
4833 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4834 __ cmp(r3, Operand(kind));
4835 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4836 __ TailCallStub(&stub, eq);
4839 // If we reached this point there is a problem.
4840 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4848 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4849 int to_index = GetSequenceIndexFromFastElementsKind(
4850 TERMINAL_FAST_ELEMENTS_KIND);
4851 for (int i = 0; i <= to_index; ++i) {
4852 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4853 T stub(isolate, kind);
4855 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4856 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4863 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4864 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4866 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4868 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4873 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4875 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4876 for (int i = 0; i < 2; i++) {
4877 // For internal arrays we only need a few things
4878 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4880 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4882 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4888 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4889 MacroAssembler* masm,
4890 AllocationSiteOverrideMode mode) {
4891 if (argument_count() == ANY) {
4892 Label not_zero_case, not_one_case;
4894 __ b(ne, ¬_zero_case);
4895 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4897 __ bind(¬_zero_case);
4898 __ cmp(r0, Operand(1));
4899 __ b(gt, ¬_one_case);
4900 CreateArrayDispatchOneArgument(masm, mode);
4902 __ bind(¬_one_case);
4903 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4904 } else if (argument_count() == NONE) {
4905 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4906 } else if (argument_count() == ONE) {
4907 CreateArrayDispatchOneArgument(masm, mode);
4908 } else if (argument_count() == MORE_THAN_ONE) {
4909 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4916 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4917 // ----------- S t a t e -------------
4918 // -- r0 : argc (only if argument_count() == ANY)
4919 // -- r1 : constructor
4920 // -- r2 : AllocationSite or undefined
4921 // -- r3 : original constructor
4922 // -- sp[0] : return address
4923 // -- sp[4] : last argument
4924 // -----------------------------------
4926 if (FLAG_debug_code) {
4927 // The array construct code is only set for the global and natives
4928 // builtin Array functions which always have maps.
4930 // Initial map for the builtin Array function should be a map.
4931 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4932 // Will both indicate a NULL and a Smi.
4933 __ tst(r4, Operand(kSmiTagMask));
4934 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4935 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4936 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4938 // We should either have undefined in r2 or a valid AllocationSite
4939 __ AssertUndefinedOrAllocationSite(r2, r4);
4944 __ b(ne, &subclassing);
4947 // Get the elements kind and case on that.
4948 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4951 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4953 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4954 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4955 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4958 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4960 __ bind(&subclassing);
4965 switch (argument_count()) {
4968 __ add(r0, r0, Operand(2));
4971 __ mov(r0, Operand(2));
4974 __ mov(r0, Operand(3));
4978 __ JumpToExternalReference(
4979 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
4983 void InternalArrayConstructorStub::GenerateCase(
4984 MacroAssembler* masm, ElementsKind kind) {
4985 __ cmp(r0, Operand(1));
4987 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4988 __ TailCallStub(&stub0, lo);
4990 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4991 __ TailCallStub(&stubN, hi);
4993 if (IsFastPackedElementsKind(kind)) {
4994 // We might need to create a holey array
4995 // look at the first argument
4996 __ ldr(r3, MemOperand(sp, 0));
4997 __ cmp(r3, Operand::Zero());
4999 InternalArraySingleArgumentConstructorStub
5000 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5001 __ TailCallStub(&stub1_holey, ne);
5004 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5005 __ TailCallStub(&stub1);
5009 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5010 // ----------- S t a t e -------------
5012 // -- r1 : constructor
5013 // -- sp[0] : return address
5014 // -- sp[4] : last argument
5015 // -----------------------------------
5017 if (FLAG_debug_code) {
5018 // The array construct code is only set for the global and natives
5019 // builtin Array functions which always have maps.
5021 // Initial map for the builtin Array function should be a map.
5022 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5023 // Will both indicate a NULL and a Smi.
5024 __ tst(r3, Operand(kSmiTagMask));
5025 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5026 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
5027 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5030 // Figure out the right elements kind
5031 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5032 // Load the map's "bit field 2" into |result|. We only need the first byte,
5033 // but the following bit field extraction takes care of that anyway.
5034 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
5035 // Retrieve elements_kind from bit field 2.
5036 __ DecodeField<Map::ElementsKindBits>(r3);
5038 if (FLAG_debug_code) {
5040 __ cmp(r3, Operand(FAST_ELEMENTS));
5042 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
5044 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5048 Label fast_elements_case;
5049 __ cmp(r3, Operand(FAST_ELEMENTS));
5050 __ b(eq, &fast_elements_case);
5051 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5053 __ bind(&fast_elements_case);
5054 GenerateCase(masm, FAST_ELEMENTS);
5058 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5059 return ref0.address() - ref1.address();
5063 // Calls an API function. Allocates HandleScope, extracts returned value
5064 // from handle and propagates exceptions. Restores context. stack_space
5065 // - space to be unwound on exit (includes the call JS arguments space and
5066 // the additional space allocated for the fast call).
5067 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5068 Register function_address,
5069 ExternalReference thunk_ref,
5071 MemOperand* stack_space_operand,
5072 MemOperand return_value_operand,
5073 MemOperand* context_restore_operand) {
5074 Isolate* isolate = masm->isolate();
5075 ExternalReference next_address =
5076 ExternalReference::handle_scope_next_address(isolate);
5077 const int kNextOffset = 0;
5078 const int kLimitOffset = AddressOffset(
5079 ExternalReference::handle_scope_limit_address(isolate), next_address);
5080 const int kLevelOffset = AddressOffset(
5081 ExternalReference::handle_scope_level_address(isolate), next_address);
5083 DCHECK(function_address.is(r1) || function_address.is(r2));
5085 Label profiler_disabled;
5086 Label end_profiler_check;
5087 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5088 __ ldrb(r9, MemOperand(r9, 0));
5089 __ cmp(r9, Operand(0));
5090 __ b(eq, &profiler_disabled);
5092 // Additional parameter is the address of the actual callback.
5093 __ mov(r3, Operand(thunk_ref));
5094 __ jmp(&end_profiler_check);
5096 __ bind(&profiler_disabled);
5097 __ Move(r3, function_address);
5098 __ bind(&end_profiler_check);
5100 // Allocate HandleScope in callee-save registers.
5101 __ mov(r9, Operand(next_address));
5102 __ ldr(r4, MemOperand(r9, kNextOffset));
5103 __ ldr(r5, MemOperand(r9, kLimitOffset));
5104 __ ldr(r6, MemOperand(r9, kLevelOffset));
5105 __ add(r6, r6, Operand(1));
5106 __ str(r6, MemOperand(r9, kLevelOffset));
5108 if (FLAG_log_timer_events) {
5109 FrameScope frame(masm, StackFrame::MANUAL);
5110 __ PushSafepointRegisters();
5111 __ PrepareCallCFunction(1, r0);
5112 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5113 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5115 __ PopSafepointRegisters();
5118 // Native call returns to the DirectCEntry stub which redirects to the
5119 // return address pushed on stack (could have moved after GC).
5120 // DirectCEntry stub itself is generated early and never moves.
5121 DirectCEntryStub stub(isolate);
5122 stub.GenerateCall(masm, r3);
5124 if (FLAG_log_timer_events) {
5125 FrameScope frame(masm, StackFrame::MANUAL);
5126 __ PushSafepointRegisters();
5127 __ PrepareCallCFunction(1, r0);
5128 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5129 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5131 __ PopSafepointRegisters();
5134 Label promote_scheduled_exception;
5135 Label delete_allocated_handles;
5136 Label leave_exit_frame;
5137 Label return_value_loaded;
5139 // load value from ReturnValue
5140 __ ldr(r0, return_value_operand);
5141 __ bind(&return_value_loaded);
5142 // No more valid handles (the result handle was the last one). Restore
5143 // previous handle scope.
5144 __ str(r4, MemOperand(r9, kNextOffset));
5145 if (__ emit_debug_code()) {
5146 __ ldr(r1, MemOperand(r9, kLevelOffset));
5148 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5150 __ sub(r6, r6, Operand(1));
5151 __ str(r6, MemOperand(r9, kLevelOffset));
5152 __ ldr(ip, MemOperand(r9, kLimitOffset));
5154 __ b(ne, &delete_allocated_handles);
5156 // Leave the API exit frame.
5157 __ bind(&leave_exit_frame);
5158 bool restore_context = context_restore_operand != NULL;
5159 if (restore_context) {
5160 __ ldr(cp, *context_restore_operand);
5162 // LeaveExitFrame expects unwind space to be in a register.
5163 if (stack_space_operand != NULL) {
5164 __ ldr(r4, *stack_space_operand);
5166 __ mov(r4, Operand(stack_space));
5168 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5170 // Check if the function scheduled an exception.
5171 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5172 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5173 __ ldr(r5, MemOperand(ip));
5175 __ b(ne, &promote_scheduled_exception);
5179 // Re-throw by promoting a scheduled exception.
5180 __ bind(&promote_scheduled_exception);
5181 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5183 // HandleScope limit has changed. Delete allocated extensions.
5184 __ bind(&delete_allocated_handles);
5185 __ str(r5, MemOperand(r9, kLimitOffset));
5187 __ PrepareCallCFunction(1, r5);
5188 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5189 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5192 __ jmp(&leave_exit_frame);
5196 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5197 const ParameterCount& argc,
5198 bool return_first_arg,
5199 bool call_data_undefined) {
5200 // ----------- S t a t e -------------
5202 // -- r4 : call_data
5204 // -- r1 : api_function_address
5205 // -- r3 : number of arguments if argc is a register
5208 // -- sp[0] : last argument
5210 // -- sp[(argc - 1)* 4] : first argument
5211 // -- sp[argc * 4] : receiver
5212 // -----------------------------------
5214 Register callee = r0;
5215 Register call_data = r4;
5216 Register holder = r2;
5217 Register api_function_address = r1;
5218 Register context = cp;
5220 typedef FunctionCallbackArguments FCA;
5222 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5223 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5224 STATIC_ASSERT(FCA::kDataIndex == 4);
5225 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5226 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5227 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5228 STATIC_ASSERT(FCA::kHolderIndex == 0);
5229 STATIC_ASSERT(FCA::kArgsLength == 7);
5231 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5235 // load context from callee
5236 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5244 Register scratch = call_data;
5245 if (!call_data_undefined) {
5246 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5250 // return value default
5253 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5258 // Prepare arguments.
5259 __ mov(scratch, sp);
5261 // Allocate the v8::Arguments structure in the arguments' space since
5262 // it's not controlled by GC.
5263 const int kApiStackSpace = 4;
5265 FrameScope frame_scope(masm, StackFrame::MANUAL);
5266 __ EnterExitFrame(false, kApiStackSpace);
5268 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5269 // r0 = FunctionCallbackInfo&
5270 // Arguments is after the return address.
5271 __ add(r0, sp, Operand(1 * kPointerSize));
5272 // FunctionCallbackInfo::implicit_args_
5273 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
5274 if (argc.is_immediate()) {
5275 // FunctionCallbackInfo::values_
5277 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5278 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5279 // FunctionCallbackInfo::length_ = argc
5280 __ mov(ip, Operand(argc.immediate()));
5281 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5282 // FunctionCallbackInfo::is_construct_call_ = 0
5283 __ mov(ip, Operand::Zero());
5284 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5286 // FunctionCallbackInfo::values_
5287 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5288 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5289 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5290 // FunctionCallbackInfo::length_ = argc
5291 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5292 // FunctionCallbackInfo::is_construct_call_
5293 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5294 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5295 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5298 ExternalReference thunk_ref =
5299 ExternalReference::invoke_function_callback(masm->isolate());
5301 AllowExternalCallThatCantCauseGC scope(masm);
5302 MemOperand context_restore_operand(
5303 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5304 // Stores return the first js argument
5305 int return_value_offset = 0;
5306 if (return_first_arg) {
5307 return_value_offset = 2 + FCA::kArgsLength;
5309 return_value_offset = 2 + FCA::kReturnValueOffset;
5311 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5312 int stack_space = 0;
5313 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5314 MemOperand* stack_space_operand = &is_construct_call_operand;
5315 if (argc.is_immediate()) {
5316 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5317 stack_space_operand = NULL;
5319 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5320 stack_space_operand, return_value_operand,
5321 &context_restore_operand);
5325 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5326 bool call_data_undefined = this->call_data_undefined();
5327 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
5328 call_data_undefined);
5332 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5333 bool is_store = this->is_store();
5334 int argc = this->argc();
5335 bool call_data_undefined = this->call_data_undefined();
5336 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5337 call_data_undefined);
5341 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5342 // ----------- S t a t e -------------
5344 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5346 // -- r2 : api_function_address
5347 // -----------------------------------
5349 Register api_function_address = ApiGetterDescriptor::function_address();
5350 DCHECK(api_function_address.is(r2));
5352 __ mov(r0, sp); // r0 = Handle<Name>
5353 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
5355 const int kApiStackSpace = 1;
5356 FrameScope frame_scope(masm, StackFrame::MANUAL);
5357 __ EnterExitFrame(false, kApiStackSpace);
5359 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5360 // r1 (internal::Object** args_) as the data.
5361 __ str(r1, MemOperand(sp, 1 * kPointerSize));
5362 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
5364 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5366 ExternalReference thunk_ref =
5367 ExternalReference::invoke_accessor_getter_callback(isolate());
5368 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5369 kStackUnwindSpace, NULL,
5370 MemOperand(fp, 6 * kPointerSize), NULL);
5376 } // namespace internal
5379 #endif // V8_TARGET_ARCH_ARM