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);
41 static void InitializeInternalArrayConstructorDescriptor(
42 Isolate* isolate, CodeStubDescriptor* descriptor,
43 int constant_stack_parameter_count) {
44 Address deopt_handler = Runtime::FunctionForId(
45 Runtime::kInternalArrayConstructor)->entry;
47 if (constant_stack_parameter_count == 0) {
48 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
49 JS_FUNCTION_STUB_MODE);
51 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
52 JS_FUNCTION_STUB_MODE);
57 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
63 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
64 CodeStubDescriptor* descriptor) {
65 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
69 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
70 CodeStubDescriptor* descriptor) {
71 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
75 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
76 CodeStubDescriptor* descriptor) {
77 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
81 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
82 CodeStubDescriptor* descriptor) {
83 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
87 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
88 CodeStubDescriptor* descriptor) {
89 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
93 #define __ ACCESS_MASM(masm)
96 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
97 Condition cond, Strength strength);
98 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
104 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
109 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
110 ExternalReference miss) {
111 // Update the static counter each time a new code stub is generated.
112 isolate()->counters()->code_stubs()->Increment();
114 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
115 int param_count = descriptor.GetRegisterParameterCount();
117 // Call the runtime system in a fresh internal frame.
118 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
119 DCHECK(param_count == 0 ||
120 r0.is(descriptor.GetRegisterParameter(param_count - 1)));
122 for (int i = 0; i < param_count; ++i) {
123 __ push(descriptor.GetRegisterParameter(i));
125 __ CallExternalReference(miss, param_count);
132 void DoubleToIStub::Generate(MacroAssembler* masm) {
133 Label out_of_range, only_low, negate, done;
134 Register input_reg = source();
135 Register result_reg = destination();
136 DCHECK(is_truncating());
138 int double_offset = offset();
139 // Account for saved regs if input is sp.
140 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
142 Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
143 Register scratch_low =
144 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
145 Register scratch_high =
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
147 LowDwVfpRegister double_scratch = kScratchDoubleReg;
149 __ Push(scratch_high, scratch_low, scratch);
151 if (!skip_fastpath()) {
152 // Load double input.
153 __ vldr(double_scratch, MemOperand(input_reg, double_offset));
154 __ vmov(scratch_low, scratch_high, double_scratch);
156 // Do fast-path convert from double to int.
157 __ vcvt_s32_f64(double_scratch.low(), double_scratch);
158 __ vmov(result_reg, double_scratch.low());
160 // If result is not saturated (0x7fffffff or 0x80000000), we are done.
161 __ sub(scratch, result_reg, Operand(1));
162 __ cmp(scratch, Operand(0x7ffffffe));
165 // We've already done MacroAssembler::TryFastTruncatedDoubleToILoad, so we
166 // know exponent > 31, so we can skip the vcvt_s32_f64 which will saturate.
167 if (double_offset == 0) {
168 __ ldm(ia, input_reg, scratch_low.bit() | scratch_high.bit());
170 __ ldr(scratch_low, MemOperand(input_reg, double_offset));
171 __ ldr(scratch_high, MemOperand(input_reg, double_offset + kIntSize));
175 __ Ubfx(scratch, scratch_high,
176 HeapNumber::kExponentShift, HeapNumber::kExponentBits);
177 // Load scratch with exponent - 1. This is faster than loading
178 // with exponent because Bias + 1 = 1024 which is an *ARM* immediate value.
179 STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
180 __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
181 // If exponent is greater than or equal to 84, the 32 less significant
182 // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
184 // Compare exponent with 84 (compare exponent - 1 with 83).
185 __ cmp(scratch, Operand(83));
186 __ b(ge, &out_of_range);
188 // If we reach this code, 31 <= exponent <= 83.
189 // So, we don't have to handle cases where 0 <= exponent <= 20 for
190 // which we would need to shift right the high part of the mantissa.
191 // Scratch contains exponent - 1.
192 // Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
193 __ rsb(scratch, scratch, Operand(51), SetCC);
195 // 21 <= exponent <= 51, shift scratch_low and scratch_high
196 // to generate the result.
197 __ mov(scratch_low, Operand(scratch_low, LSR, scratch));
198 // Scratch contains: 52 - exponent.
199 // We needs: exponent - 20.
200 // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
201 __ rsb(scratch, scratch, Operand(32));
202 __ Ubfx(result_reg, scratch_high,
203 0, HeapNumber::kMantissaBitsInTopWord);
204 // Set the implicit 1 before the mantissa part in scratch_high.
205 __ orr(result_reg, result_reg,
206 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
207 __ orr(result_reg, scratch_low, Operand(result_reg, LSL, scratch));
210 __ bind(&out_of_range);
211 __ mov(result_reg, Operand::Zero());
215 // 52 <= exponent <= 83, shift only scratch_low.
216 // On entry, scratch contains: 52 - exponent.
217 __ rsb(scratch, scratch, Operand::Zero());
218 __ mov(result_reg, Operand(scratch_low, LSL, scratch));
221 // If input was positive, scratch_high ASR 31 equals 0 and
222 // scratch_high LSR 31 equals zero.
223 // New result = (result eor 0) + 0 = result.
224 // If the input was negative, we have to negate the result.
225 // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
226 // New result = (result eor 0xffffffff) + 1 = 0 - result.
227 __ eor(result_reg, result_reg, Operand(scratch_high, ASR, 31));
228 __ add(result_reg, result_reg, Operand(scratch_high, LSR, 31));
232 __ Pop(scratch_high, scratch_low, scratch);
237 // Handle the case where the lhs and rhs are the same object.
238 // Equality is almost reflexive (everything but NaN), so this is a test
239 // for "identity and not NaN".
240 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
241 Condition cond, Strength strength) {
243 Label heap_number, return_equal;
245 __ b(ne, ¬_identical);
247 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
248 // so we do the second best thing - test it ourselves.
249 // They are both equal and they are not both Smis so both of them are not
250 // Smis. If it's not a heap number, then return equal.
251 if (cond == lt || cond == gt) {
252 // Call runtime on identical JSObjects.
253 __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE);
255 // Call runtime on identical symbols since we need to throw a TypeError.
256 __ cmp(r4, Operand(SYMBOL_TYPE));
258 // Call runtime on identical SIMD values since we must throw a TypeError.
259 __ cmp(r4, Operand(FLOAT32X4_TYPE));
261 if (is_strong(strength)) {
262 // Call the runtime on anything that is converted in the semantics, since
263 // we need to throw a TypeError. Smis have already been ruled out.
264 __ cmp(r4, Operand(HEAP_NUMBER_TYPE));
265 __ b(eq, &return_equal);
266 __ tst(r4, Operand(kIsNotStringMask));
270 __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE);
271 __ b(eq, &heap_number);
272 // Comparing JS objects with <=, >= is complicated.
274 __ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE));
276 // Call runtime on identical symbols since we need to throw a TypeError.
277 __ cmp(r4, Operand(SYMBOL_TYPE));
279 // Call runtime on identical SIMD values since we must throw a TypeError.
280 __ cmp(r4, Operand(FLOAT32X4_TYPE));
282 if (is_strong(strength)) {
283 // Call the runtime on anything that is converted in the semantics,
284 // since we need to throw a TypeError. Smis and heap numbers have
285 // already been ruled out.
286 __ tst(r4, Operand(kIsNotStringMask));
289 // Normally here we fall through to return_equal, but undefined is
290 // special: (undefined == undefined) == true, but
291 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
292 if (cond == le || cond == ge) {
293 __ cmp(r4, Operand(ODDBALL_TYPE));
294 __ b(ne, &return_equal);
295 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
297 __ b(ne, &return_equal);
299 // undefined <= undefined should fail.
300 __ mov(r0, Operand(GREATER));
302 // undefined >= undefined should fail.
303 __ mov(r0, Operand(LESS));
310 __ bind(&return_equal);
312 __ mov(r0, Operand(GREATER)); // Things aren't less than themselves.
313 } else if (cond == gt) {
314 __ mov(r0, Operand(LESS)); // Things aren't greater than themselves.
316 __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
320 // For less and greater we don't have to check for NaN since the result of
321 // x < x is false regardless. For the others here is some code to check
323 if (cond != lt && cond != gt) {
324 __ bind(&heap_number);
325 // It is a heap number, so return non-equal if it's NaN and equal if it's
328 // The representation of NaN values has all exponent bits (52..62) set,
329 // and not all mantissa bits (0..51) clear.
330 // Read top bits of double representation (second word of value).
331 __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
332 // Test that exponent bits are all set.
333 __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits);
334 // NaNs have all-one exponents so they sign extend to -1.
335 __ cmp(r3, Operand(-1));
336 __ b(ne, &return_equal);
338 // Shift out flag and all exponent bits, retaining only mantissa.
339 __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord));
340 // Or with all low-bits of mantissa.
341 __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
342 __ orr(r0, r3, Operand(r2), SetCC);
343 // For equal we already have the right value in r0: Return zero (equal)
344 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
345 // not (it's a NaN). For <= and >= we need to load r0 with the failing
346 // value if it's a NaN.
348 // All-zero means Infinity means equal.
351 __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail.
353 __ mov(r0, Operand(LESS)); // NaN >= NaN should fail.
358 // No fall through here.
360 __ bind(¬_identical);
364 // See comment at call site.
365 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
371 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
372 (lhs.is(r1) && rhs.is(r0)));
375 __ JumpIfSmi(rhs, &rhs_is_smi);
377 // Lhs is a Smi. Check whether the rhs is a heap number.
378 __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE);
380 // If rhs is not a number and lhs is a Smi then strict equality cannot
381 // succeed. Return non-equal
382 // If rhs is r0 then there is already a non zero value in it.
384 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
388 // Smi compared non-strictly with a non-Smi non-heap-number. Call
393 // Lhs is a smi, rhs is a number.
394 // Convert lhs to a double in d7.
395 __ SmiToDouble(d7, lhs);
396 // Load the double from rhs, tagged HeapNumber r0, to d6.
397 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
399 // We now have both loaded as doubles but we can skip the lhs nan check
403 __ bind(&rhs_is_smi);
404 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
405 __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE);
407 // If lhs is not a number and rhs is a smi then strict equality cannot
408 // succeed. Return non-equal.
409 // If lhs is r0 then there is already a non zero value in it.
411 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
415 // Smi compared non-strictly with a non-smi non-heap-number. Call
420 // Rhs is a smi, lhs is a heap number.
421 // Load the double from lhs, tagged HeapNumber r1, to d7.
422 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
423 // Convert rhs to a double in d6 .
424 __ SmiToDouble(d6, rhs);
425 // Fall through to both_loaded_as_doubles.
429 // See comment at call site.
430 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
433 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
434 (lhs.is(r1) && rhs.is(r0)));
436 // If either operand is a JS object or an oddball value, then they are
437 // not equal since their pointers are different.
438 // There is no test for undetectability in strict equality.
439 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
440 Label first_non_object;
441 // Get the type of the first operand into r2 and compare it with
442 // FIRST_SPEC_OBJECT_TYPE.
443 __ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE);
444 __ b(lt, &first_non_object);
446 // Return non-zero (r0 is not zero)
447 Label return_not_equal;
448 __ bind(&return_not_equal);
451 __ bind(&first_non_object);
452 // Check for oddballs: true, false, null, undefined.
453 __ cmp(r2, Operand(ODDBALL_TYPE));
454 __ b(eq, &return_not_equal);
456 __ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE);
457 __ b(ge, &return_not_equal);
459 // Check for oddballs: true, false, null, undefined.
460 __ cmp(r3, Operand(ODDBALL_TYPE));
461 __ b(eq, &return_not_equal);
463 // Now that we have the types we might as well check for
464 // internalized-internalized.
465 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
466 __ orr(r2, r2, Operand(r3));
467 __ tst(r2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
468 __ b(eq, &return_not_equal);
472 // See comment at call site.
473 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
476 Label* both_loaded_as_doubles,
477 Label* not_heap_numbers,
479 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
480 (lhs.is(r1) && rhs.is(r0)));
482 __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE);
483 __ b(ne, not_heap_numbers);
484 __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset));
486 __ b(ne, slow); // First was a heap number, second wasn't. Go slow case.
488 // Both are heap numbers. Load them up then jump to the code we have
490 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
491 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
492 __ jmp(both_loaded_as_doubles);
496 // Fast negative check for internalized-to-internalized equality.
497 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
500 Label* possible_strings,
501 Label* not_both_strings) {
502 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
503 (lhs.is(r1) && rhs.is(r0)));
505 // r2 is object type of rhs.
507 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
508 __ tst(r2, Operand(kIsNotStringMask));
509 __ b(ne, &object_test);
510 __ tst(r2, Operand(kIsNotInternalizedMask));
511 __ b(ne, possible_strings);
512 __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE);
513 __ b(ge, not_both_strings);
514 __ tst(r3, Operand(kIsNotInternalizedMask));
515 __ b(ne, possible_strings);
517 // Both are internalized. We already checked they weren't the same pointer
518 // so they are not equal.
519 __ mov(r0, Operand(NOT_EQUAL));
522 __ bind(&object_test);
523 __ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE));
524 __ b(lt, not_both_strings);
525 __ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE);
526 __ b(lt, not_both_strings);
527 // If both objects are undetectable, they are equal. Otherwise, they
528 // are not equal, since they are different objects and an object is not
529 // equal to undefined.
530 __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset));
531 __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset));
532 __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset));
533 __ and_(r0, r2, Operand(r3));
534 __ and_(r0, r0, Operand(1 << Map::kIsUndetectable));
535 __ eor(r0, r0, Operand(1 << Map::kIsUndetectable));
540 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
542 CompareICState::State expected,
545 if (expected == CompareICState::SMI) {
546 __ JumpIfNotSmi(input, fail);
547 } else if (expected == CompareICState::NUMBER) {
548 __ JumpIfSmi(input, &ok);
549 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
552 // We could be strict about internalized/non-internalized here, but as long as
553 // hydrogen doesn't care, the stub doesn't have to care either.
558 // On entry r1 and r2 are the values to be compared.
559 // On exit r0 is 0, positive or negative to indicate the result of
561 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
564 Condition cc = GetCondition();
567 CompareICStub_CheckInputType(masm, lhs, r2, left(), &miss);
568 CompareICStub_CheckInputType(masm, rhs, r3, right(), &miss);
570 Label slow; // Call builtin.
571 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
573 Label not_two_smis, smi_done;
575 __ JumpIfNotSmi(r2, ¬_two_smis);
576 __ mov(r1, Operand(r1, ASR, 1));
577 __ sub(r0, r1, Operand(r0, ASR, 1));
579 __ bind(¬_two_smis);
581 // NOTICE! This code is only reached after a smi-fast-case check, so
582 // it is certain that at least one operand isn't a smi.
584 // Handle the case where the objects are identical. Either returns the answer
585 // or goes to slow. Only falls through if the objects were not identical.
586 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
588 // If either is a Smi (we know that not both are), then they can only
589 // be strictly equal if the other is a HeapNumber.
590 STATIC_ASSERT(kSmiTag == 0);
591 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
592 __ and_(r2, lhs, Operand(rhs));
593 __ JumpIfNotSmi(r2, ¬_smis);
594 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
595 // 1) Return the answer.
597 // 3) Fall through to both_loaded_as_doubles.
598 // 4) Jump to lhs_not_nan.
599 // In cases 3 and 4 we have found out we were dealing with a number-number
600 // comparison. If VFP3 is supported the double values of the numbers have
601 // been loaded into d7 and d6. Otherwise, the double values have been loaded
602 // into r0, r1, r2, and r3.
603 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
605 __ bind(&both_loaded_as_doubles);
606 // The arguments have been converted to doubles and stored in d6 and d7, if
607 // VFP3 is supported, or in r0, r1, r2, and r3.
608 __ bind(&lhs_not_nan);
610 // ARMv7 VFP3 instructions to implement double precision comparison.
611 __ VFPCompareAndSetFlags(d7, d6);
614 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
615 __ mov(r0, Operand(LESS), LeaveCC, lt);
616 __ mov(r0, Operand(GREATER), LeaveCC, gt);
620 // If one of the sides was a NaN then the v flag is set. Load r0 with
621 // whatever it takes to make the comparison fail, since comparisons with NaN
623 if (cc == lt || cc == le) {
624 __ mov(r0, Operand(GREATER));
626 __ mov(r0, Operand(LESS));
631 // At this point we know we are dealing with two different objects,
632 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
634 // This returns non-equal for some object types, or falls through if it
636 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
639 Label check_for_internalized_strings;
640 Label flat_string_check;
641 // Check for heap-number-heap-number comparison. Can jump to slow case,
642 // or load both doubles into r0, r1, r2, r3 and jump to the code that handles
643 // that case. If the inputs are not doubles then jumps to
644 // check_for_internalized_strings.
645 // In this case r2 will contain the type of rhs_. Never falls through.
646 EmitCheckForTwoHeapNumbers(masm,
649 &both_loaded_as_doubles,
650 &check_for_internalized_strings,
653 __ bind(&check_for_internalized_strings);
654 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
655 // internalized strings.
656 if (cc == eq && !strict()) {
657 // Returns an answer for two internalized strings or two detectable objects.
658 // Otherwise jumps to string case or not both strings case.
659 // Assumes that r2 is the type of rhs_ on entry.
660 EmitCheckForInternalizedStringsOrObjects(
661 masm, lhs, rhs, &flat_string_check, &slow);
664 // Check for both being sequential one-byte strings,
665 // and inline if that is the case.
666 __ bind(&flat_string_check);
668 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r2, r3, &slow);
670 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
673 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r2, r3, r4);
675 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r2, r3, r4,
678 // Never falls through to here.
683 // Figure out which native to call and setup the arguments.
684 Builtins::JavaScript native;
686 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
689 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
690 int ncr; // NaN compare result
691 if (cc == lt || cc == le) {
694 DCHECK(cc == gt || cc == ge); // remaining cases
697 __ mov(r0, Operand(Smi::FromInt(ncr)));
701 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
702 // tagged as a small integer.
703 __ InvokeBuiltin(native, JUMP_FUNCTION);
710 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
711 // We don't allow a GC during a store buffer overflow so there is no need to
712 // store the registers in any particular way, but we do have to store and
714 __ stm(db_w, sp, kCallerSaved | lr.bit());
716 const Register scratch = r1;
718 if (save_doubles()) {
719 __ SaveFPRegs(sp, scratch);
721 const int argument_count = 1;
722 const int fp_argument_count = 0;
724 AllowExternalCallThatCantCauseGC scope(masm);
725 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
726 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
728 ExternalReference::store_buffer_overflow_function(isolate()),
730 if (save_doubles()) {
731 __ RestoreFPRegs(sp, scratch);
733 __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0).
737 void MathPowStub::Generate(MacroAssembler* masm) {
738 const Register base = r1;
739 const Register exponent = MathPowTaggedDescriptor::exponent();
740 DCHECK(exponent.is(r2));
741 const Register heapnumbermap = r5;
742 const Register heapnumber = r0;
743 const DwVfpRegister double_base = d0;
744 const DwVfpRegister double_exponent = d1;
745 const DwVfpRegister double_result = d2;
746 const DwVfpRegister double_scratch = d3;
747 const SwVfpRegister single_scratch = s6;
748 const Register scratch = r9;
749 const Register scratch2 = r4;
751 Label call_runtime, done, int_exponent;
752 if (exponent_type() == ON_STACK) {
753 Label base_is_smi, unpack_exponent;
754 // The exponent and base are supplied as arguments on the stack.
755 // This can only happen if the stub is called from non-optimized code.
756 // Load input parameters from stack to double registers.
757 __ ldr(base, MemOperand(sp, 1 * kPointerSize));
758 __ ldr(exponent, MemOperand(sp, 0 * kPointerSize));
760 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
762 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
763 __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset));
764 __ cmp(scratch, heapnumbermap);
765 __ b(ne, &call_runtime);
767 __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
768 __ jmp(&unpack_exponent);
770 __ bind(&base_is_smi);
771 __ vmov(single_scratch, scratch);
772 __ vcvt_f64_s32(double_base, single_scratch);
773 __ bind(&unpack_exponent);
775 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
777 __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
778 __ cmp(scratch, heapnumbermap);
779 __ b(ne, &call_runtime);
780 __ vldr(double_exponent,
781 FieldMemOperand(exponent, HeapNumber::kValueOffset));
782 } else if (exponent_type() == TAGGED) {
783 // Base is already in double_base.
784 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
786 __ vldr(double_exponent,
787 FieldMemOperand(exponent, HeapNumber::kValueOffset));
790 if (exponent_type() != INTEGER) {
791 Label int_exponent_convert;
792 // Detect integer exponents stored as double.
793 __ vcvt_u32_f64(single_scratch, double_exponent);
794 // We do not check for NaN or Infinity here because comparing numbers on
795 // ARM correctly distinguishes NaNs. We end up calling the built-in.
796 __ vcvt_f64_u32(double_scratch, single_scratch);
797 __ VFPCompareAndSetFlags(double_scratch, double_exponent);
798 __ b(eq, &int_exponent_convert);
800 if (exponent_type() == ON_STACK) {
801 // Detect square root case. Crankshaft detects constant +/-0.5 at
802 // compile time and uses DoMathPowHalf instead. We then skip this check
803 // for non-constant cases of +/-0.5 as these hardly occur.
807 __ vmov(double_scratch, 0.5, scratch);
808 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
809 __ b(ne, ¬_plus_half);
811 // Calculates square root of base. Check for the special case of
812 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
813 __ vmov(double_scratch, -V8_INFINITY, scratch);
814 __ VFPCompareAndSetFlags(double_base, double_scratch);
815 __ vneg(double_result, double_scratch, eq);
818 // Add +0 to convert -0 to +0.
819 __ vadd(double_scratch, double_base, kDoubleRegZero);
820 __ vsqrt(double_result, double_scratch);
823 __ bind(¬_plus_half);
824 __ vmov(double_scratch, -0.5, scratch);
825 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
826 __ b(ne, &call_runtime);
828 // Calculates square root of base. Check for the special case of
829 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
830 __ vmov(double_scratch, -V8_INFINITY, scratch);
831 __ VFPCompareAndSetFlags(double_base, double_scratch);
832 __ vmov(double_result, kDoubleRegZero, eq);
835 // Add +0 to convert -0 to +0.
836 __ vadd(double_scratch, double_base, kDoubleRegZero);
837 __ vmov(double_result, 1.0, scratch);
838 __ vsqrt(double_scratch, double_scratch);
839 __ vdiv(double_result, double_result, double_scratch);
845 AllowExternalCallThatCantCauseGC scope(masm);
846 __ PrepareCallCFunction(0, 2, scratch);
847 __ MovToFloatParameters(double_base, double_exponent);
849 ExternalReference::power_double_double_function(isolate()),
853 __ MovFromFloatResult(double_result);
856 __ bind(&int_exponent_convert);
857 __ vcvt_u32_f64(single_scratch, double_exponent);
858 __ vmov(scratch, single_scratch);
861 // Calculate power with integer exponent.
862 __ bind(&int_exponent);
864 // Get two copies of exponent in the registers scratch and exponent.
865 if (exponent_type() == INTEGER) {
866 __ mov(scratch, exponent);
868 // Exponent has previously been stored into scratch as untagged integer.
869 __ mov(exponent, scratch);
871 __ vmov(double_scratch, double_base); // Back up base.
872 __ vmov(double_result, 1.0, scratch2);
874 // Get absolute value of exponent.
875 __ cmp(scratch, Operand::Zero());
876 __ mov(scratch2, Operand::Zero(), LeaveCC, mi);
877 __ sub(scratch, scratch2, scratch, LeaveCC, mi);
880 __ bind(&while_true);
881 __ mov(scratch, Operand(scratch, ASR, 1), SetCC);
882 __ vmul(double_result, double_result, double_scratch, cs);
883 __ vmul(double_scratch, double_scratch, double_scratch, ne);
884 __ b(ne, &while_true);
886 __ cmp(exponent, Operand::Zero());
888 __ vmov(double_scratch, 1.0, scratch);
889 __ vdiv(double_result, double_scratch, double_result);
890 // Test whether result is zero. Bail out to check for subnormal result.
891 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
892 __ VFPCompareAndSetFlags(double_result, 0.0);
894 // double_exponent may not containe the exponent value if the input was a
895 // smi. We set it with exponent value before bailing out.
896 __ vmov(single_scratch, exponent);
897 __ vcvt_f64_s32(double_exponent, single_scratch);
899 // Returning or bailing out.
900 Counters* counters = isolate()->counters();
901 if (exponent_type() == ON_STACK) {
902 // The arguments are still on the stack.
903 __ bind(&call_runtime);
904 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
906 // The stub is called from non-optimized code, which expects the result
907 // as heap number in exponent.
909 __ AllocateHeapNumber(
910 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
911 __ vstr(double_result,
912 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
913 DCHECK(heapnumber.is(r0));
914 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
919 AllowExternalCallThatCantCauseGC scope(masm);
920 __ PrepareCallCFunction(0, 2, scratch);
921 __ MovToFloatParameters(double_base, double_exponent);
923 ExternalReference::power_double_double_function(isolate()),
927 __ MovFromFloatResult(double_result);
930 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
936 bool CEntryStub::NeedsImmovableCode() {
941 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
942 CEntryStub::GenerateAheadOfTime(isolate);
943 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
944 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
945 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
946 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
947 CreateWeakCellStub::GenerateAheadOfTime(isolate);
948 BinaryOpICStub::GenerateAheadOfTime(isolate);
949 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
950 StoreFastElementStub::GenerateAheadOfTime(isolate);
951 TypeofStub::GenerateAheadOfTime(isolate);
955 void CodeStub::GenerateFPStubs(Isolate* isolate) {
956 // Generate if not already in cache.
957 SaveFPRegsMode mode = kSaveFPRegs;
958 CEntryStub(isolate, 1, mode).GetCode();
959 StoreBufferOverflowStub(isolate, mode).GetCode();
960 isolate->set_fp_stubs_generated(true);
964 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
965 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
970 void CEntryStub::Generate(MacroAssembler* masm) {
971 // Called from JavaScript; parameters are on stack as if calling JS function.
972 // r0: number of arguments including receiver
973 // r1: pointer to builtin function
974 // fp: frame pointer (restored after C call)
975 // sp: stack pointer (restored as callee's sp after C call)
976 // cp: current context (C callee-saved)
978 ProfileEntryHookStub::MaybeCallEntryHook(masm);
980 __ mov(r5, Operand(r1));
982 // Compute the argv pointer in a callee-saved register.
983 __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2));
984 __ sub(r1, r1, Operand(kPointerSize));
986 // Enter the exit frame that transitions from JavaScript to C++.
987 FrameScope scope(masm, StackFrame::MANUAL);
988 __ EnterExitFrame(save_doubles());
990 // Store a copy of argc in callee-saved registers for later.
991 __ mov(r4, Operand(r0));
993 // r0, r4: number of arguments including receiver (C callee-saved)
994 // r1: pointer to the first argument (C callee-saved)
995 // r5: pointer to builtin function (C callee-saved)
997 // Result returned in r0 or r0+r1 by default.
1000 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
1001 int frame_alignment_mask = frame_alignment - 1;
1002 if (FLAG_debug_code) {
1003 if (frame_alignment > kPointerSize) {
1004 Label alignment_as_expected;
1005 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
1006 __ tst(sp, Operand(frame_alignment_mask));
1007 __ b(eq, &alignment_as_expected);
1008 // Don't use Check here, as it will call Runtime_Abort re-entering here.
1009 __ stop("Unexpected alignment");
1010 __ bind(&alignment_as_expected);
1016 // r0 = argc, r1 = argv
1017 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1019 // To let the GC traverse the return address of the exit frames, we need to
1020 // know where the return address is. The CEntryStub is unmovable, so
1021 // we can store the address on the stack to be able to find it again and
1022 // we never have to restore it, because it will not change.
1023 // Compute the return address in lr to return to after the jump below. Pc is
1024 // already at '+ 8' from the current instruction but return is after three
1025 // instructions so add another 4 to pc to get the return address.
1027 // Prevent literal pool emission before return address.
1028 Assembler::BlockConstPoolScope block_const_pool(masm);
1029 __ add(lr, pc, Operand(4));
1030 __ str(lr, MemOperand(sp, 0));
1034 __ VFPEnsureFPSCRState(r2);
1036 // Check result for exception sentinel.
1037 Label exception_returned;
1038 __ CompareRoot(r0, Heap::kExceptionRootIndex);
1039 __ b(eq, &exception_returned);
1041 // Check that there is no pending exception, otherwise we
1042 // should have returned the exception sentinel.
1043 if (FLAG_debug_code) {
1045 ExternalReference pending_exception_address(
1046 Isolate::kPendingExceptionAddress, isolate());
1047 __ mov(r2, Operand(pending_exception_address));
1048 __ ldr(r2, MemOperand(r2));
1049 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex);
1050 // Cannot use check here as it attempts to generate call into runtime.
1052 __ stop("Unexpected pending exception");
1056 // Exit C frame and return.
1058 // sp: stack pointer
1059 // fp: frame pointer
1060 // Callee-saved register r4 still holds argc.
1061 __ LeaveExitFrame(save_doubles(), r4, true);
1064 // Handling of exception.
1065 __ bind(&exception_returned);
1067 ExternalReference pending_handler_context_address(
1068 Isolate::kPendingHandlerContextAddress, isolate());
1069 ExternalReference pending_handler_code_address(
1070 Isolate::kPendingHandlerCodeAddress, isolate());
1071 ExternalReference pending_handler_offset_address(
1072 Isolate::kPendingHandlerOffsetAddress, isolate());
1073 ExternalReference pending_handler_fp_address(
1074 Isolate::kPendingHandlerFPAddress, isolate());
1075 ExternalReference pending_handler_sp_address(
1076 Isolate::kPendingHandlerSPAddress, isolate());
1078 // Ask the runtime for help to determine the handler. This will set r0 to
1079 // contain the current pending exception, don't clobber it.
1080 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1083 FrameScope scope(masm, StackFrame::MANUAL);
1084 __ PrepareCallCFunction(3, 0, r0);
1085 __ mov(r0, Operand(0));
1086 __ mov(r1, Operand(0));
1087 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1088 __ CallCFunction(find_handler, 3);
1091 // Retrieve the handler context, SP and FP.
1092 __ mov(cp, Operand(pending_handler_context_address));
1093 __ ldr(cp, MemOperand(cp));
1094 __ mov(sp, Operand(pending_handler_sp_address));
1095 __ ldr(sp, MemOperand(sp));
1096 __ mov(fp, Operand(pending_handler_fp_address));
1097 __ ldr(fp, MemOperand(fp));
1099 // If the handler is a JS frame, restore the context to the frame. Note that
1100 // the context will be set to (cp == 0) for non-JS frames.
1101 __ cmp(cp, Operand(0));
1102 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne);
1104 // Compute the handler entry address and jump to it.
1105 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1106 __ mov(r1, Operand(pending_handler_code_address));
1107 __ ldr(r1, MemOperand(r1));
1108 __ mov(r2, Operand(pending_handler_offset_address));
1109 __ ldr(r2, MemOperand(r2));
1110 __ add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1111 if (FLAG_enable_embedded_constant_pool) {
1112 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r1);
1118 void JSEntryStub::Generate(MacroAssembler* masm) {
1125 Label invoke, handler_entry, exit;
1127 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1129 // Called from C, so do not pop argc and args on exit (preserve sp)
1130 // No need to save register-passed args
1131 // Save callee-saved registers (incl. cp and fp), sp, and lr
1132 __ stm(db_w, sp, kCalleeSaved | lr.bit());
1134 // Save callee-saved vfp registers.
1135 __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1136 // Set up the reserved register for 0.0.
1137 __ vmov(kDoubleRegZero, 0.0);
1138 __ VFPEnsureFPSCRState(r4);
1140 // Get address of argv, see stm above.
1146 // Set up argv in r4.
1147 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1148 offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize;
1149 __ ldr(r4, MemOperand(sp, offset_to_argv));
1151 // Push a frame with special values setup to mark it as an entry frame.
1157 int marker = type();
1158 if (FLAG_enable_embedded_constant_pool) {
1159 __ mov(r8, Operand::Zero());
1161 __ mov(r7, Operand(Smi::FromInt(marker)));
1162 __ mov(r6, Operand(Smi::FromInt(marker)));
1164 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1165 __ ldr(r5, MemOperand(r5));
1166 __ mov(ip, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1167 __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() |
1168 (FLAG_enable_embedded_constant_pool ? r8.bit() : 0) |
1171 // Set up frame pointer for the frame to be pushed.
1172 __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1174 // If this is the outermost JS call, set js_entry_sp value.
1175 Label non_outermost_js;
1176 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1177 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1178 __ ldr(r6, MemOperand(r5));
1179 __ cmp(r6, Operand::Zero());
1180 __ b(ne, &non_outermost_js);
1181 __ str(fp, MemOperand(r5));
1182 __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1185 __ bind(&non_outermost_js);
1186 __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1190 // Jump to a faked try block that does the invoke, with a faked catch
1191 // block that sets the pending exception.
1194 // Block literal pool emission whilst taking the position of the handler
1195 // entry. This avoids making the assumption that literal pools are always
1196 // emitted after an instruction is emitted, rather than before.
1198 Assembler::BlockConstPoolScope block_const_pool(masm);
1199 __ bind(&handler_entry);
1200 handler_offset_ = handler_entry.pos();
1201 // Caught exception: Store result (exception) in the pending exception
1202 // field in the JSEnv and return a failure sentinel. Coming in here the
1203 // fp will be invalid because the PushStackHandler below sets it to 0 to
1204 // signal the existence of the JSEntry frame.
1205 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1208 __ str(r0, MemOperand(ip));
1209 __ LoadRoot(r0, Heap::kExceptionRootIndex);
1212 // Invoke: Link this frame into the handler chain.
1214 // Must preserve r0-r4, r5-r6 are available.
1215 __ PushStackHandler();
1216 // If an exception not caught by another handler occurs, this handler
1217 // returns control to the code after the bl(&invoke) above, which
1218 // restores all kCalleeSaved registers (including cp and fp) to their
1219 // saved values before returning a failure to C.
1221 // Clear any pending exceptions.
1222 __ mov(r5, Operand(isolate()->factory()->the_hole_value()));
1223 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1225 __ str(r5, MemOperand(ip));
1227 // Invoke the function by calling through JS entry trampoline builtin.
1228 // Notice that we cannot store a reference to the trampoline code directly in
1229 // this stub, because runtime stubs are not traversed when doing GC.
1231 // Expected registers by Builtins::JSEntryTrampoline
1237 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1238 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1240 __ mov(ip, Operand(construct_entry));
1242 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
1243 __ mov(ip, Operand(entry));
1245 __ ldr(ip, MemOperand(ip)); // deref address
1246 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1248 // Branch and link to JSEntryTrampoline.
1251 // Unlink this frame from the handler chain.
1252 __ PopStackHandler();
1254 __ bind(&exit); // r0 holds result
1255 // Check if the current stack frame is marked as the outermost JS frame.
1256 Label non_outermost_js_2;
1258 __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1259 __ b(ne, &non_outermost_js_2);
1260 __ mov(r6, Operand::Zero());
1261 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1262 __ str(r6, MemOperand(r5));
1263 __ bind(&non_outermost_js_2);
1265 // Restore the top frame descriptors from the stack.
1268 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1269 __ str(r3, MemOperand(ip));
1271 // Reset the stack to the callee saved registers.
1272 __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1274 // Restore callee-saved registers and return.
1276 if (FLAG_debug_code) {
1277 __ mov(lr, Operand(pc));
1281 // Restore callee-saved vfp registers.
1282 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1284 __ ldm(ia_w, sp, kCalleeSaved | pc.bit());
1288 // Uses registers r0 to r4.
1289 // Expected input (depending on whether args are in registers or on the stack):
1290 // * object: r0 or at sp + 1 * kPointerSize.
1291 // * function: r1 or at sp.
1293 // An inlined call site may have been generated before calling this stub.
1294 // In this case the offset to the inline sites to patch are passed in r5 and r6.
1295 // (See LCodeGen::DoInstanceOfKnownGlobal)
1296 void InstanceofStub::Generate(MacroAssembler* masm) {
1297 // Call site inlining and patching implies arguments in registers.
1298 DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck());
1300 // Fixed register usage throughout the stub:
1301 const Register object = r0; // Object (lhs).
1302 Register map = r3; // Map of the object.
1303 const Register function = r1; // Function (rhs).
1304 const Register prototype = r4; // Prototype of the function.
1305 const Register scratch = r2;
1307 Label slow, loop, is_instance, is_not_instance, not_js_object;
1309 if (!HasArgsInRegisters()) {
1310 __ ldr(object, MemOperand(sp, 1 * kPointerSize));
1311 __ ldr(function, MemOperand(sp, 0));
1314 // Check that the left hand is a JS object and load map.
1315 __ JumpIfSmi(object, ¬_js_object);
1316 __ IsObjectJSObjectType(object, map, scratch, ¬_js_object);
1318 // If there is a call site cache don't look in the global cache, but do the
1319 // real lookup and update the call site cache.
1320 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
1322 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1324 __ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex);
1326 __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1327 __ Ret(HasArgsInRegisters() ? 0 : 2);
1332 // Get the prototype of the function.
1333 __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
1335 // Check that the function prototype is a JS object.
1336 __ JumpIfSmi(prototype, &slow);
1337 __ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
1339 // Update the global instanceof or call site inlined cache with the current
1340 // map and function. The cached answer will be set when it is known below.
1341 if (!HasCallSiteInlineCheck()) {
1342 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1343 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1345 DCHECK(HasArgsInRegisters());
1346 // Patch the (relocated) inlined map check.
1348 // The map_load_offset was stored in r5
1349 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1350 const Register map_load_offset = r5;
1351 __ sub(r9, lr, map_load_offset);
1352 // Get the map location in r5 and patch it.
1353 __ GetRelocatedValueLocation(r9, map_load_offset, scratch);
1354 __ ldr(map_load_offset, MemOperand(map_load_offset));
1355 __ str(map, FieldMemOperand(map_load_offset, Cell::kValueOffset));
1357 __ mov(scratch, map);
1358 // |map_load_offset| points at the beginning of the cell. Calculate the
1359 // field containing the map.
1360 __ add(function, map_load_offset, Operand(Cell::kValueOffset - 1));
1361 __ RecordWriteField(map_load_offset, Cell::kValueOffset, scratch, function,
1362 kLRHasNotBeenSaved, kDontSaveFPRegs,
1363 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
1366 // Register mapping: r3 is object map and r4 is function prototype.
1367 // Get prototype of object into r2.
1368 __ ldr(scratch, FieldMemOperand(map, Map::kPrototypeOffset));
1370 // We don't need map any more. Use it as a scratch register.
1371 Register scratch2 = map;
1374 // Loop through the prototype chain looking for the function prototype.
1375 __ LoadRoot(scratch2, Heap::kNullValueRootIndex);
1377 __ cmp(scratch, Operand(prototype));
1378 __ b(eq, &is_instance);
1379 __ cmp(scratch, scratch2);
1380 __ b(eq, &is_not_instance);
1381 __ ldr(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
1382 __ ldr(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset));
1384 Factory* factory = isolate()->factory();
1386 __ bind(&is_instance);
1387 if (!HasCallSiteInlineCheck()) {
1388 __ mov(r0, Operand(Smi::FromInt(0)));
1389 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1390 if (ReturnTrueFalseObject()) {
1391 __ Move(r0, factory->true_value());
1394 // Patch the call site to return true.
1395 __ LoadRoot(r0, Heap::kTrueValueRootIndex);
1396 // The bool_load_offset was stored in r6
1397 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1398 const Register bool_load_offset = r6;
1399 __ sub(r9, lr, bool_load_offset);
1400 // Get the boolean result location in scratch and patch it.
1401 __ GetRelocatedValueLocation(r9, scratch, scratch2);
1402 __ str(r0, MemOperand(scratch));
1404 if (!ReturnTrueFalseObject()) {
1405 __ mov(r0, Operand(Smi::FromInt(0)));
1408 __ Ret(HasArgsInRegisters() ? 0 : 2);
1410 __ bind(&is_not_instance);
1411 if (!HasCallSiteInlineCheck()) {
1412 __ mov(r0, Operand(Smi::FromInt(1)));
1413 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1414 if (ReturnTrueFalseObject()) {
1415 __ Move(r0, factory->false_value());
1418 // Patch the call site to return false.
1419 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1420 // The bool_load_offset was stored in r6
1421 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1422 const Register bool_load_offset = r6;
1423 __ sub(r9, lr, bool_load_offset);
1425 // Get the boolean result location in scratch and patch it.
1426 __ GetRelocatedValueLocation(r9, scratch, scratch2);
1427 __ str(r0, MemOperand(scratch));
1429 if (!ReturnTrueFalseObject()) {
1430 __ mov(r0, Operand(Smi::FromInt(1)));
1433 __ Ret(HasArgsInRegisters() ? 0 : 2);
1435 Label object_not_null, object_not_null_or_smi;
1436 __ bind(¬_js_object);
1437 // Before null, smi and string value checks, check that the rhs is a function
1438 // as for a non-function rhs an exception needs to be thrown.
1439 __ JumpIfSmi(function, &slow);
1440 __ CompareObjectType(function, scratch2, scratch, JS_FUNCTION_TYPE);
1443 // Null is not instance of anything.
1444 __ cmp(object, Operand(isolate()->factory()->null_value()));
1445 __ b(ne, &object_not_null);
1446 if (ReturnTrueFalseObject()) {
1447 __ Move(r0, factory->false_value());
1449 __ mov(r0, Operand(Smi::FromInt(1)));
1451 __ Ret(HasArgsInRegisters() ? 0 : 2);
1453 __ bind(&object_not_null);
1454 // Smi values are not instances of anything.
1455 __ JumpIfNotSmi(object, &object_not_null_or_smi);
1456 if (ReturnTrueFalseObject()) {
1457 __ Move(r0, factory->false_value());
1459 __ mov(r0, Operand(Smi::FromInt(1)));
1461 __ Ret(HasArgsInRegisters() ? 0 : 2);
1463 __ bind(&object_not_null_or_smi);
1464 // String values are not instances of anything.
1465 __ IsObjectJSStringType(object, scratch, &slow);
1466 if (ReturnTrueFalseObject()) {
1467 __ Move(r0, factory->false_value());
1469 __ mov(r0, Operand(Smi::FromInt(1)));
1471 __ Ret(HasArgsInRegisters() ? 0 : 2);
1473 // Slow-case. Tail call builtin.
1475 if (!ReturnTrueFalseObject()) {
1476 if (HasArgsInRegisters()) {
1479 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
1482 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
1484 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1486 __ cmp(r0, Operand::Zero());
1487 __ LoadRoot(r0, Heap::kTrueValueRootIndex, eq);
1488 __ LoadRoot(r0, Heap::kFalseValueRootIndex, ne);
1489 __ Ret(HasArgsInRegisters() ? 0 : 2);
1494 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1496 Register receiver = LoadDescriptor::ReceiverRegister();
1497 // Ensure that the vector and slot registers won't be clobbered before
1498 // calling the miss handler.
1499 DCHECK(!AreAliased(r4, r5, LoadWithVectorDescriptor::VectorRegister(),
1500 LoadWithVectorDescriptor::SlotRegister()));
1502 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4,
1505 PropertyAccessCompiler::TailCallBuiltin(
1506 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1510 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1511 // Return address is in lr.
1514 Register receiver = LoadDescriptor::ReceiverRegister();
1515 Register index = LoadDescriptor::NameRegister();
1516 Register scratch = r5;
1517 Register result = r0;
1518 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1519 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1520 result.is(LoadWithVectorDescriptor::SlotRegister()));
1522 // StringCharAtGenerator doesn't use the result register until it's passed
1523 // the different miss possibilities. If it did, we would have a conflict
1524 // when FLAG_vector_ics is true.
1525 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1526 &miss, // When not a string.
1527 &miss, // When not a number.
1528 &miss, // When index out of range.
1529 STRING_INDEX_IS_ARRAY_INDEX,
1530 RECEIVER_IS_STRING);
1531 char_at_generator.GenerateFast(masm);
1534 StubRuntimeCallHelper call_helper;
1535 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1538 PropertyAccessCompiler::TailCallBuiltin(
1539 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1543 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1544 // The displacement is the offset of the last parameter (if any)
1545 // relative to the frame pointer.
1546 const int kDisplacement =
1547 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1548 DCHECK(r1.is(ArgumentsAccessReadDescriptor::index()));
1549 DCHECK(r0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1551 // Check that the key is a smi.
1553 __ JumpIfNotSmi(r1, &slow);
1555 // Check if the calling frame is an arguments adaptor frame.
1557 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1558 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1559 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1562 // Check index against formal parameters count limit passed in
1563 // through register r0. Use unsigned comparison to get negative
1568 // Read the argument from the stack and return it.
1570 __ add(r3, fp, Operand::PointerOffsetFromSmiKey(r3));
1571 __ ldr(r0, MemOperand(r3, kDisplacement));
1574 // Arguments adaptor case: Check index against actual arguments
1575 // limit found in the arguments adaptor frame. Use unsigned
1576 // comparison to get negative check for free.
1578 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1582 // Read the argument from the adaptor frame and return it.
1584 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r3));
1585 __ ldr(r0, MemOperand(r3, kDisplacement));
1588 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1589 // by calling the runtime system.
1592 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1596 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1597 // sp[0] : number of parameters
1598 // sp[4] : receiver displacement
1601 // Check if the calling frame is an arguments adaptor frame.
1603 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1604 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1605 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1608 // Patch the arguments.length and the parameters pointer in the current frame.
1609 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1610 __ str(r2, MemOperand(sp, 0 * kPointerSize));
1611 __ add(r3, r3, Operand(r2, LSL, 1));
1612 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1613 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1616 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1620 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1622 // sp[0] : number of parameters (tagged)
1623 // sp[4] : address of receiver argument
1625 // Registers used over whole function:
1626 // r6 : allocated object (tagged)
1627 // r9 : mapped parameter count (tagged)
1629 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1630 // r1 = parameter count (tagged)
1632 // Check if the calling frame is an arguments adaptor frame.
1634 Label adaptor_frame, try_allocate;
1635 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1636 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1637 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1638 __ b(eq, &adaptor_frame);
1640 // No adaptor, parameter count = argument count.
1642 __ b(&try_allocate);
1644 // We have an adaptor frame. Patch the parameters pointer.
1645 __ bind(&adaptor_frame);
1646 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1647 __ add(r3, r3, Operand(r2, LSL, 1));
1648 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1649 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1651 // r1 = parameter count (tagged)
1652 // r2 = argument count (tagged)
1653 // Compute the mapped parameter count = min(r1, r2) in r1.
1654 __ cmp(r1, Operand(r2));
1655 __ mov(r1, Operand(r2), LeaveCC, gt);
1657 __ bind(&try_allocate);
1659 // Compute the sizes of backing store, parameter map, and arguments object.
1660 // 1. Parameter map, has 2 extra words containing context and backing store.
1661 const int kParameterMapHeaderSize =
1662 FixedArray::kHeaderSize + 2 * kPointerSize;
1663 // If there are no mapped parameters, we do not need the parameter_map.
1664 __ cmp(r1, Operand(Smi::FromInt(0)));
1665 __ mov(r9, Operand::Zero(), LeaveCC, eq);
1666 __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne);
1667 __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne);
1669 // 2. Backing store.
1670 __ add(r9, r9, Operand(r2, LSL, 1));
1671 __ add(r9, r9, Operand(FixedArray::kHeaderSize));
1673 // 3. Arguments object.
1674 __ add(r9, r9, Operand(Heap::kSloppyArgumentsObjectSize));
1676 // Do the allocation of all three objects in one go.
1677 __ Allocate(r9, r0, r3, r4, &runtime, TAG_OBJECT);
1679 // r0 = address of new object(s) (tagged)
1680 // r2 = argument count (smi-tagged)
1681 // Get the arguments boilerplate from the current native context into r4.
1682 const int kNormalOffset =
1683 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1684 const int kAliasedOffset =
1685 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1687 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1688 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1689 __ cmp(r1, Operand::Zero());
1690 __ ldr(r4, MemOperand(r4, kNormalOffset), eq);
1691 __ ldr(r4, MemOperand(r4, kAliasedOffset), ne);
1693 // r0 = address of new object (tagged)
1694 // r1 = mapped parameter count (tagged)
1695 // r2 = argument count (smi-tagged)
1696 // r4 = address of arguments map (tagged)
1697 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1698 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1699 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1700 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1702 // Set up the callee in-object property.
1703 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1704 __ ldr(r3, MemOperand(sp, 2 * kPointerSize));
1705 __ AssertNotSmi(r3);
1706 const int kCalleeOffset = JSObject::kHeaderSize +
1707 Heap::kArgumentsCalleeIndex * kPointerSize;
1708 __ str(r3, FieldMemOperand(r0, kCalleeOffset));
1710 // Use the length (smi tagged) and set that as an in-object property too.
1712 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1713 const int kLengthOffset = JSObject::kHeaderSize +
1714 Heap::kArgumentsLengthIndex * kPointerSize;
1715 __ str(r2, FieldMemOperand(r0, kLengthOffset));
1717 // Set up the elements pointer in the allocated arguments object.
1718 // If we allocated a parameter map, r4 will point there, otherwise
1719 // it will point to the backing store.
1720 __ add(r4, r0, Operand(Heap::kSloppyArgumentsObjectSize));
1721 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1723 // r0 = address of new object (tagged)
1724 // r1 = mapped parameter count (tagged)
1725 // r2 = argument count (tagged)
1726 // r4 = address of parameter map or backing store (tagged)
1727 // Initialize parameter map. If there are no mapped arguments, we're done.
1728 Label skip_parameter_map;
1729 __ cmp(r1, Operand(Smi::FromInt(0)));
1730 // Move backing store address to r3, because it is
1731 // expected there when filling in the unmapped arguments.
1732 __ mov(r3, r4, LeaveCC, eq);
1733 __ b(eq, &skip_parameter_map);
1735 __ LoadRoot(r6, Heap::kSloppyArgumentsElementsMapRootIndex);
1736 __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset));
1737 __ add(r6, r1, Operand(Smi::FromInt(2)));
1738 __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset));
1739 __ str(cp, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize));
1740 __ add(r6, r4, Operand(r1, LSL, 1));
1741 __ add(r6, r6, Operand(kParameterMapHeaderSize));
1742 __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize));
1744 // Copy the parameter slots and the holes in the arguments.
1745 // We need to fill in mapped_parameter_count slots. They index the context,
1746 // where parameters are stored in reverse order, at
1747 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1748 // The mapped parameter thus need to get indices
1749 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1750 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1751 // We loop from right to left.
1752 Label parameters_loop, parameters_test;
1754 __ ldr(r9, MemOperand(sp, 0 * kPointerSize));
1755 __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1756 __ sub(r9, r9, Operand(r1));
1757 __ LoadRoot(r5, Heap::kTheHoleValueRootIndex);
1758 __ add(r3, r4, Operand(r6, LSL, 1));
1759 __ add(r3, r3, Operand(kParameterMapHeaderSize));
1761 // r6 = loop variable (tagged)
1762 // r1 = mapping index (tagged)
1763 // r3 = address of backing store (tagged)
1764 // r4 = address of parameter map (tagged), which is also the address of new
1765 // object + Heap::kSloppyArgumentsObjectSize (tagged)
1766 // r0 = temporary scratch (a.o., for address calculation)
1767 // r5 = the hole value
1768 __ jmp(¶meters_test);
1770 __ bind(¶meters_loop);
1771 __ sub(r6, r6, Operand(Smi::FromInt(1)));
1772 __ mov(r0, Operand(r6, LSL, 1));
1773 __ add(r0, r0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1774 __ str(r9, MemOperand(r4, r0));
1775 __ sub(r0, r0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1776 __ str(r5, MemOperand(r3, r0));
1777 __ add(r9, r9, Operand(Smi::FromInt(1)));
1778 __ bind(¶meters_test);
1779 __ cmp(r6, Operand(Smi::FromInt(0)));
1780 __ b(ne, ¶meters_loop);
1782 // Restore r0 = new object (tagged)
1783 __ sub(r0, r4, Operand(Heap::kSloppyArgumentsObjectSize));
1785 __ bind(&skip_parameter_map);
1786 // r0 = address of new object (tagged)
1787 // r2 = argument count (tagged)
1788 // r3 = address of backing store (tagged)
1790 // Copy arguments header and remaining slots (if there are any).
1791 __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex);
1792 __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset));
1793 __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset));
1795 Label arguments_loop, arguments_test;
1797 __ ldr(r4, MemOperand(sp, 1 * kPointerSize));
1798 __ sub(r4, r4, Operand(r9, LSL, 1));
1799 __ jmp(&arguments_test);
1801 __ bind(&arguments_loop);
1802 __ sub(r4, r4, Operand(kPointerSize));
1803 __ ldr(r6, MemOperand(r4, 0));
1804 __ add(r5, r3, Operand(r9, LSL, 1));
1805 __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize));
1806 __ add(r9, r9, Operand(Smi::FromInt(1)));
1808 __ bind(&arguments_test);
1809 __ cmp(r9, Operand(r2));
1810 __ b(lt, &arguments_loop);
1812 // Return and remove the on-stack parameters.
1813 __ add(sp, sp, Operand(3 * kPointerSize));
1816 // Do the runtime call to allocate the arguments object.
1817 // r0 = address of new object (tagged)
1818 // r2 = argument count (tagged)
1820 __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1821 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1825 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1826 // Return address is in lr.
1829 Register receiver = LoadDescriptor::ReceiverRegister();
1830 Register key = LoadDescriptor::NameRegister();
1832 // Check that the key is an array index, that is Uint32.
1833 __ NonNegativeSmiTst(key);
1836 // Everything is fine, call runtime.
1837 __ Push(receiver, key); // Receiver, key.
1839 // Perform tail call to the entry.
1840 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1843 PropertyAccessCompiler::TailCallBuiltin(
1844 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1848 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1849 // sp[0] : number of parameters
1850 // sp[4] : receiver displacement
1852 // Check if the calling frame is an arguments adaptor frame.
1853 Label adaptor_frame, try_allocate, runtime;
1854 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1855 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1856 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1857 __ b(eq, &adaptor_frame);
1859 // Get the length from the frame.
1860 __ ldr(r1, MemOperand(sp, 0));
1861 __ b(&try_allocate);
1863 // Patch the arguments.length and the parameters pointer.
1864 __ bind(&adaptor_frame);
1865 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1866 __ str(r1, MemOperand(sp, 0));
1867 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1868 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1869 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1871 // Try the new space allocation. Start out with computing the size
1872 // of the arguments object and the elements array in words.
1873 Label add_arguments_object;
1874 __ bind(&try_allocate);
1875 __ SmiUntag(r1, SetCC);
1876 __ b(eq, &add_arguments_object);
1877 __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize));
1878 __ bind(&add_arguments_object);
1879 __ add(r1, r1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1881 // Do the allocation of both objects in one go.
1882 __ Allocate(r1, r0, r2, r3, &runtime,
1883 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1885 // Get the arguments boilerplate from the current native context.
1886 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1887 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1888 __ ldr(r4, MemOperand(
1889 r4, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1891 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1892 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1893 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1894 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1896 // Get the length (smi tagged) and set that as an in-object property too.
1897 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1898 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1900 __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize +
1901 Heap::kArgumentsLengthIndex * kPointerSize));
1903 // If there are no actual arguments, we're done.
1905 __ cmp(r1, Operand::Zero());
1908 // Get the parameters pointer from the stack.
1909 __ ldr(r2, MemOperand(sp, 1 * kPointerSize));
1911 // Set up the elements pointer in the allocated arguments object and
1912 // initialize the header in the elements fixed array.
1913 __ add(r4, r0, Operand(Heap::kStrictArgumentsObjectSize));
1914 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1915 __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex);
1916 __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset));
1917 __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset));
1920 // Copy the fixed array slots.
1922 // Set up r4 to point to the first array slot.
1923 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1925 // Pre-decrement r2 with kPointerSize on each iteration.
1926 // Pre-decrement in order to skip receiver.
1927 __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
1928 // Post-increment r4 with kPointerSize on each iteration.
1929 __ str(r3, MemOperand(r4, kPointerSize, PostIndex));
1930 __ sub(r1, r1, Operand(1));
1931 __ cmp(r1, Operand::Zero());
1934 // Return and remove the on-stack parameters.
1936 __ add(sp, sp, Operand(3 * kPointerSize));
1939 // Do the runtime call to allocate the arguments object.
1941 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1945 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
1946 // Stack layout on entry.
1947 // sp[0] : language mode
1948 // sp[4] : index of rest parameter
1949 // sp[8] : number of parameters
1950 // sp[12] : receiver displacement
1953 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1954 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1955 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1958 // Patch the arguments.length and the parameters pointer.
1959 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1960 __ str(r1, MemOperand(sp, 2 * kPointerSize));
1961 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1962 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1963 __ str(r3, MemOperand(sp, 3 * kPointerSize));
1966 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
1970 void RegExpExecStub::Generate(MacroAssembler* masm) {
1971 // Just jump directly to runtime if native RegExp is not selected at compile
1972 // time or if regexp entry in generated code is turned off runtime switch or
1974 #ifdef V8_INTERPRETED_REGEXP
1975 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1976 #else // V8_INTERPRETED_REGEXP
1978 // Stack frame on entry.
1979 // sp[0]: last_match_info (expected JSArray)
1980 // sp[4]: previous index
1981 // sp[8]: subject string
1982 // sp[12]: JSRegExp object
1984 const int kLastMatchInfoOffset = 0 * kPointerSize;
1985 const int kPreviousIndexOffset = 1 * kPointerSize;
1986 const int kSubjectOffset = 2 * kPointerSize;
1987 const int kJSRegExpOffset = 3 * kPointerSize;
1990 // Allocation of registers for this function. These are in callee save
1991 // registers and will be preserved by the call to the native RegExp code, as
1992 // this code is called using the normal C calling convention. When calling
1993 // directly from generated code the native RegExp code will not do a GC and
1994 // therefore the content of these registers are safe to use after the call.
1995 Register subject = r4;
1996 Register regexp_data = r5;
1997 Register last_match_info_elements = no_reg; // will be r6;
1999 // Ensure that a RegExp stack is allocated.
2000 ExternalReference address_of_regexp_stack_memory_address =
2001 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2002 ExternalReference address_of_regexp_stack_memory_size =
2003 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2004 __ mov(r0, Operand(address_of_regexp_stack_memory_size));
2005 __ ldr(r0, MemOperand(r0, 0));
2006 __ cmp(r0, Operand::Zero());
2009 // Check that the first argument is a JSRegExp object.
2010 __ ldr(r0, MemOperand(sp, kJSRegExpOffset));
2011 __ JumpIfSmi(r0, &runtime);
2012 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
2015 // Check that the RegExp has been compiled (data contains a fixed array).
2016 __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
2017 if (FLAG_debug_code) {
2018 __ SmiTst(regexp_data);
2019 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2020 __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
2021 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2024 // regexp_data: RegExp data (FixedArray)
2025 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2026 __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2027 __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2030 // regexp_data: RegExp data (FixedArray)
2031 // Check that the number of captures fit in the static offsets vector buffer.
2033 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2034 // Check (number_of_captures + 1) * 2 <= offsets vector size
2035 // Or number_of_captures * 2 <= offsets vector size - 2
2036 // Multiplying by 2 comes for free since r2 is smi-tagged.
2037 STATIC_ASSERT(kSmiTag == 0);
2038 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2039 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2040 __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2043 // Reset offset for possibly sliced string.
2044 __ mov(r9, Operand::Zero());
2045 __ ldr(subject, MemOperand(sp, kSubjectOffset));
2046 __ JumpIfSmi(subject, &runtime);
2047 __ mov(r3, subject); // Make a copy of the original subject string.
2048 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2049 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2050 // subject: subject string
2051 // r3: subject string
2052 // r0: subject string instance type
2053 // regexp_data: RegExp data (FixedArray)
2054 // Handle subject string according to its encoding and representation:
2055 // (1) Sequential string? If yes, go to (5).
2056 // (2) Anything but sequential or cons? If yes, go to (6).
2057 // (3) Cons string. If the string is flat, replace subject with first string.
2058 // Otherwise bailout.
2059 // (4) Is subject external? If yes, go to (7).
2060 // (5) Sequential string. Load regexp code according to encoding.
2064 // Deferred code at the end of the stub:
2065 // (6) Not a long external string? If yes, go to (8).
2066 // (7) External string. Make it, offset-wise, look like a sequential string.
2068 // (8) Short external string or not a string? If yes, bail out to runtime.
2069 // (9) Sliced string. Replace subject with parent. Go to (4).
2071 Label seq_string /* 5 */, external_string /* 7 */,
2072 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2073 not_long_external /* 8 */;
2075 // (1) Sequential string? If yes, go to (5).
2078 Operand(kIsNotStringMask |
2079 kStringRepresentationMask |
2080 kShortExternalStringMask),
2082 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2083 __ b(eq, &seq_string); // Go to (5).
2085 // (2) Anything but sequential or cons? If yes, go to (6).
2086 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2087 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2088 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2089 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2090 __ cmp(r1, Operand(kExternalStringTag));
2091 __ b(ge, ¬_seq_nor_cons); // Go to (6).
2093 // (3) Cons string. Check that it's flat.
2094 // Replace subject with first string and reload instance type.
2095 __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
2096 __ CompareRoot(r0, Heap::kempty_stringRootIndex);
2098 __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2100 // (4) Is subject external? If yes, go to (7).
2101 __ bind(&check_underlying);
2102 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2103 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2104 STATIC_ASSERT(kSeqStringTag == 0);
2105 __ tst(r0, Operand(kStringRepresentationMask));
2106 // The underlying external string is never a short external string.
2107 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2108 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2109 __ b(ne, &external_string); // Go to (7).
2111 // (5) Sequential string. Load regexp code according to encoding.
2112 __ bind(&seq_string);
2113 // subject: sequential subject string (or look-alike, external string)
2114 // r3: original subject string
2115 // Load previous index and check range before r3 is overwritten. We have to
2116 // use r3 instead of subject here because subject might have been only made
2117 // to look like a sequential string when it actually is an external string.
2118 __ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
2119 __ JumpIfNotSmi(r1, &runtime);
2120 __ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
2121 __ cmp(r3, Operand(r1));
2125 STATIC_ASSERT(4 == kOneByteStringTag);
2126 STATIC_ASSERT(kTwoByteStringTag == 0);
2127 __ and_(r0, r0, Operand(kStringEncodingMask));
2128 __ mov(r3, Operand(r0, ASR, 2), SetCC);
2129 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset),
2131 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
2133 // (E) Carry on. String handling is done.
2134 // r6: irregexp code
2135 // Check that the irregexp code has been generated for the actual string
2136 // encoding. If it has, the field contains a code object otherwise it contains
2137 // a smi (code flushing support).
2138 __ JumpIfSmi(r6, &runtime);
2140 // r1: previous index
2141 // r3: encoding of subject string (1 if one_byte, 0 if two_byte);
2143 // subject: Subject string
2144 // regexp_data: RegExp data (FixedArray)
2145 // All checks done. Now push arguments for native regexp code.
2146 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r0, r2);
2148 // Isolates: note we add an additional parameter here (isolate pointer).
2149 const int kRegExpExecuteArguments = 9;
2150 const int kParameterRegisters = 4;
2151 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2153 // Stack pointer now points to cell where return address is to be written.
2154 // Arguments are before that on the stack or in registers.
2156 // Argument 9 (sp[20]): Pass current isolate address.
2157 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2158 __ str(r0, MemOperand(sp, 5 * kPointerSize));
2160 // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
2161 __ mov(r0, Operand(1));
2162 __ str(r0, MemOperand(sp, 4 * kPointerSize));
2164 // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
2165 __ mov(r0, Operand(address_of_regexp_stack_memory_address));
2166 __ ldr(r0, MemOperand(r0, 0));
2167 __ mov(r2, Operand(address_of_regexp_stack_memory_size));
2168 __ ldr(r2, MemOperand(r2, 0));
2169 __ add(r0, r0, Operand(r2));
2170 __ str(r0, MemOperand(sp, 3 * kPointerSize));
2172 // Argument 6: Set the number of capture registers to zero to force global
2173 // regexps to behave as non-global. This does not affect non-global regexps.
2174 __ mov(r0, Operand::Zero());
2175 __ str(r0, MemOperand(sp, 2 * kPointerSize));
2177 // Argument 5 (sp[4]): static offsets vector buffer.
2179 Operand(ExternalReference::address_of_static_offsets_vector(
2181 __ str(r0, MemOperand(sp, 1 * kPointerSize));
2183 // For arguments 4 and 3 get string length, calculate start of string data and
2184 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2185 __ add(r7, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2186 __ eor(r3, r3, Operand(1));
2187 // Load the length from the original subject string from the previous stack
2188 // frame. Therefore we have to use fp, which points exactly to two pointer
2189 // sizes below the previous sp. (Because creating a new stack frame pushes
2190 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2191 __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2192 // If slice offset is not 0, load the length from the original sliced string.
2193 // Argument 4, r3: End of string data
2194 // Argument 3, r2: Start of string data
2195 // Prepare start and end index of the input.
2196 __ add(r9, r7, Operand(r9, LSL, r3));
2197 __ add(r2, r9, Operand(r1, LSL, r3));
2199 __ ldr(r7, FieldMemOperand(subject, String::kLengthOffset));
2201 __ add(r3, r9, Operand(r7, LSL, r3));
2203 // Argument 2 (r1): Previous index.
2206 // Argument 1 (r0): Subject string.
2207 __ mov(r0, subject);
2209 // Locate the code entry and call it.
2210 __ add(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
2211 DirectCEntryStub stub(isolate());
2212 stub.GenerateCall(masm, r6);
2214 __ LeaveExitFrame(false, no_reg, true);
2216 last_match_info_elements = r6;
2219 // subject: subject string (callee saved)
2220 // regexp_data: RegExp data (callee saved)
2221 // last_match_info_elements: Last match info elements (callee saved)
2222 // Check the result.
2224 __ cmp(r0, Operand(1));
2225 // We expect exactly one result since we force the called regexp to behave
2229 __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
2231 __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2232 // If not exception it can only be retry. Handle that in the runtime system.
2234 // Result must now be exception. If there is no pending exception already a
2235 // stack overflow (on the backtrack stack) was detected in RegExp code but
2236 // haven't created the exception yet. Handle that in the runtime system.
2237 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2238 __ mov(r1, Operand(isolate()->factory()->the_hole_value()));
2239 __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2241 __ ldr(r0, MemOperand(r2, 0));
2245 // For exception, throw the exception again.
2246 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2249 // For failure and exception return null.
2250 __ mov(r0, Operand(isolate()->factory()->null_value()));
2251 __ add(sp, sp, Operand(4 * kPointerSize));
2254 // Process the result from the native regexp code.
2257 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2258 // Calculate number of capture registers (number_of_captures + 1) * 2.
2259 // Multiplying by 2 comes for free since r1 is smi-tagged.
2260 STATIC_ASSERT(kSmiTag == 0);
2261 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2262 __ add(r1, r1, Operand(2)); // r1 was a smi.
2264 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2265 __ JumpIfSmi(r0, &runtime);
2266 __ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
2268 // Check that the JSArray is in fast case.
2269 __ ldr(last_match_info_elements,
2270 FieldMemOperand(r0, JSArray::kElementsOffset));
2271 __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2272 __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
2274 // Check that the last match info has space for the capture registers and the
2275 // additional information.
2277 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2278 __ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
2279 __ cmp(r2, Operand::SmiUntag(r0));
2282 // r1: number of capture registers
2283 // r4: subject string
2284 // Store the capture count.
2286 __ str(r2, FieldMemOperand(last_match_info_elements,
2287 RegExpImpl::kLastCaptureCountOffset));
2288 // Store last subject and last input.
2290 FieldMemOperand(last_match_info_elements,
2291 RegExpImpl::kLastSubjectOffset));
2292 __ mov(r2, subject);
2293 __ RecordWriteField(last_match_info_elements,
2294 RegExpImpl::kLastSubjectOffset,
2299 __ mov(subject, r2);
2301 FieldMemOperand(last_match_info_elements,
2302 RegExpImpl::kLastInputOffset));
2303 __ RecordWriteField(last_match_info_elements,
2304 RegExpImpl::kLastInputOffset,
2310 // Get the static offsets vector filled by the native regexp code.
2311 ExternalReference address_of_static_offsets_vector =
2312 ExternalReference::address_of_static_offsets_vector(isolate());
2313 __ mov(r2, Operand(address_of_static_offsets_vector));
2315 // r1: number of capture registers
2316 // r2: offsets vector
2317 Label next_capture, done;
2318 // Capture register counter starts from number of capture registers and
2319 // counts down until wraping after zero.
2321 last_match_info_elements,
2322 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2323 __ bind(&next_capture);
2324 __ sub(r1, r1, Operand(1), SetCC);
2326 // Read the value from the static offsets vector buffer.
2327 __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
2328 // Store the smi value in the last match info.
2330 __ str(r3, MemOperand(r0, kPointerSize, PostIndex));
2331 __ jmp(&next_capture);
2334 // Return last match info.
2335 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2336 __ add(sp, sp, Operand(4 * kPointerSize));
2339 // Do the runtime call to execute the regexp.
2341 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2343 // Deferred code for string handling.
2344 // (6) Not a long external string? If yes, go to (8).
2345 __ bind(¬_seq_nor_cons);
2346 // Compare flags are still set.
2347 __ b(gt, ¬_long_external); // Go to (8).
2349 // (7) External string. Make it, offset-wise, look like a sequential string.
2350 __ bind(&external_string);
2351 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2352 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2353 if (FLAG_debug_code) {
2354 // Assert that we do not have a cons or slice (indirect strings) here.
2355 // Sequential strings have already been ruled out.
2356 __ tst(r0, Operand(kIsIndirectStringMask));
2357 __ Assert(eq, kExternalStringExpectedButNotFound);
2360 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2361 // Move the pointer so that offset-wise, it looks like a sequential string.
2362 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2365 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2366 __ jmp(&seq_string); // Go to (5).
2368 // (8) Short external string or not a string? If yes, bail out to runtime.
2369 __ bind(¬_long_external);
2370 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2371 __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
2374 // (9) Sliced string. Replace subject with parent. Go to (4).
2375 // Load offset into r9 and replace subject string with parent.
2376 __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2378 __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2379 __ jmp(&check_underlying); // Go to (4).
2380 #endif // V8_INTERPRETED_REGEXP
2384 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2386 // r0 : number of arguments to the construct function
2387 // r1 : the function to call
2388 // r2 : feedback vector
2389 // r3 : slot in feedback vector (Smi)
2390 // r4 : original constructor (for IsSuperConstructorCall)
2391 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2393 // Number-of-arguments register must be smi-tagged to call out.
2395 __ Push(r3, r2, r1, r0);
2405 __ Pop(r3, r2, r1, r0);
2410 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2411 // Cache the called function in a feedback vector slot. Cache states
2412 // are uninitialized, monomorphic (indicated by a JSFunction), and
2414 // r0 : number of arguments to the construct function
2415 // r1 : the function to call
2416 // r2 : feedback vector
2417 // r3 : slot in feedback vector (Smi)
2418 // r4 : original constructor (for IsSuperConstructorCall)
2419 Label initialize, done, miss, megamorphic, not_array_function;
2421 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2422 masm->isolate()->heap()->megamorphic_symbol());
2423 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2424 masm->isolate()->heap()->uninitialized_symbol());
2426 // Load the cache state into r5.
2427 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2428 __ ldr(r5, FieldMemOperand(r5, FixedArray::kHeaderSize));
2430 // A monomorphic cache hit or an already megamorphic state: invoke the
2431 // function without changing the state.
2432 // We don't know if r5 is a WeakCell or a Symbol, but it's harmless to read at
2433 // this position in a symbol (see static asserts in type-feedback-vector.h).
2434 Label check_allocation_site;
2435 Register feedback_map = r6;
2436 Register weak_value = r9;
2437 __ ldr(weak_value, FieldMemOperand(r5, WeakCell::kValueOffset));
2438 __ cmp(r1, weak_value);
2440 __ CompareRoot(r5, Heap::kmegamorphic_symbolRootIndex);
2442 __ ldr(feedback_map, FieldMemOperand(r5, HeapObject::kMapOffset));
2443 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2444 __ b(ne, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2446 // If the weak cell is cleared, we have a new chance to become monomorphic.
2447 __ JumpIfSmi(weak_value, &initialize);
2448 __ jmp(&megamorphic);
2450 if (!FLAG_pretenuring_call_new) {
2451 __ bind(&check_allocation_site);
2452 // If we came here, we need to see if we are the array function.
2453 // If we didn't have a matching function, and we didn't find the megamorph
2454 // sentinel, then we have in the slot either some other function or an
2456 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2459 // Make sure the function is the Array() function
2460 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2462 __ b(ne, &megamorphic);
2468 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2470 __ CompareRoot(r5, Heap::kuninitialized_symbolRootIndex);
2471 __ b(eq, &initialize);
2472 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2473 // write-barrier is needed.
2474 __ bind(&megamorphic);
2475 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2476 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2477 __ str(ip, FieldMemOperand(r5, FixedArray::kHeaderSize));
2480 // An uninitialized cache is patched with the function
2481 __ bind(&initialize);
2483 if (!FLAG_pretenuring_call_new) {
2484 // Make sure the function is the Array() function
2485 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r5);
2487 __ b(ne, ¬_array_function);
2489 // The target function is the Array constructor,
2490 // Create an AllocationSite if we don't already have it, store it in the
2492 CreateAllocationSiteStub create_stub(masm->isolate());
2493 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2496 __ bind(¬_array_function);
2499 CreateWeakCellStub create_stub(masm->isolate());
2500 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2505 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2506 // Do not transform the receiver for strict mode functions.
2507 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2508 __ ldr(r4, FieldMemOperand(r3, SharedFunctionInfo::kCompilerHintsOffset));
2509 __ tst(r4, Operand(1 << (SharedFunctionInfo::kStrictModeFunction +
2513 // Do not transform the receiver for native (Compilerhints already in r3).
2514 __ tst(r4, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
2519 static void EmitSlowCase(MacroAssembler* masm,
2521 Label* non_function) {
2522 // Check for function proxy.
2523 __ cmp(r4, Operand(JS_FUNCTION_PROXY_TYPE));
2524 __ b(ne, non_function);
2525 __ push(r1); // put proxy as additional argument
2526 __ mov(r0, Operand(argc + 1, RelocInfo::NONE32));
2527 __ mov(r2, Operand::Zero());
2528 __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY);
2530 Handle<Code> adaptor =
2531 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2532 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2535 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2536 // of the original receiver from the call site).
2537 __ bind(non_function);
2538 __ str(r1, MemOperand(sp, argc * kPointerSize));
2539 __ mov(r0, Operand(argc)); // Set up the number of arguments.
2540 __ mov(r2, Operand::Zero());
2541 __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION);
2542 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2543 RelocInfo::CODE_TARGET);
2547 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2548 // Wrap the receiver and patch it back onto the stack.
2549 { FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2551 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2554 __ str(r0, MemOperand(sp, argc * kPointerSize));
2559 static void CallFunctionNoFeedback(MacroAssembler* masm,
2560 int argc, bool needs_checks,
2561 bool call_as_method) {
2562 // r1 : the function to call
2563 Label slow, non_function, wrap, cont;
2566 // Check that the function is really a JavaScript function.
2567 // r1: pushed function (to be verified)
2568 __ JumpIfSmi(r1, &non_function);
2570 // Goto slow case if we do not have a function.
2571 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2575 // Fast-case: Invoke the function now.
2576 // r1: pushed function
2577 ParameterCount actual(argc);
2579 if (call_as_method) {
2581 EmitContinueIfStrictOrNative(masm, &cont);
2584 // Compute the receiver in sloppy mode.
2585 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2588 __ JumpIfSmi(r3, &wrap);
2589 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2598 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2601 // Slow-case: Non-function called.
2603 EmitSlowCase(masm, argc, &non_function);
2606 if (call_as_method) {
2608 EmitWrapCase(masm, argc, &cont);
2613 void CallFunctionStub::Generate(MacroAssembler* masm) {
2614 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2618 void CallConstructStub::Generate(MacroAssembler* masm) {
2619 // r0 : number of arguments
2620 // r1 : the function to call
2621 // r2 : feedback vector
2622 // r3 : slot in feedback vector (Smi, for RecordCallTarget)
2623 // r4 : original constructor (for IsSuperConstructorCall)
2624 Label slow, non_function_call;
2626 // Check that the function is not a smi.
2627 __ JumpIfSmi(r1, &non_function_call);
2628 // Check that the function is a JSFunction.
2629 __ CompareObjectType(r1, r5, r5, JS_FUNCTION_TYPE);
2632 if (RecordCallTarget()) {
2633 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2635 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2636 if (FLAG_pretenuring_call_new) {
2637 // Put the AllocationSite from the feedback vector into r2.
2638 // By adding kPointerSize we encode that we know the AllocationSite
2639 // entry is at the feedback vector slot given by r3 + 1.
2640 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize + kPointerSize));
2642 Label feedback_register_initialized;
2643 // Put the AllocationSite from the feedback vector into r2, or undefined.
2644 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2645 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2646 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2647 __ b(eq, &feedback_register_initialized);
2648 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2649 __ bind(&feedback_register_initialized);
2652 __ AssertUndefinedOrAllocationSite(r2, r5);
2655 // Pass function as original constructor.
2656 if (IsSuperConstructorCall()) {
2662 // Jump to the function-specific construct stub.
2663 Register jmp_reg = r4;
2664 __ ldr(jmp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2665 __ ldr(jmp_reg, FieldMemOperand(jmp_reg,
2666 SharedFunctionInfo::kConstructStubOffset));
2667 __ add(pc, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2669 // r0: number of arguments
2670 // r1: called object
2674 __ cmp(r5, Operand(JS_FUNCTION_PROXY_TYPE));
2675 __ b(ne, &non_function_call);
2676 __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2679 __ bind(&non_function_call);
2680 __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2682 // Set expected number of arguments to zero (not changing r0).
2683 __ mov(r2, Operand::Zero());
2684 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2685 RelocInfo::CODE_TARGET);
2689 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2690 __ ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2691 __ ldr(vector, FieldMemOperand(vector,
2692 JSFunction::kSharedFunctionInfoOffset));
2693 __ ldr(vector, FieldMemOperand(vector,
2694 SharedFunctionInfo::kFeedbackVectorOffset));
2698 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2703 int argc = arg_count();
2704 ParameterCount actual(argc);
2706 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2710 __ mov(r0, Operand(arg_count()));
2711 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2712 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2714 // Verify that r4 contains an AllocationSite
2715 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2716 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2719 // Increment the call count for monomorphic function calls.
2720 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2721 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2722 __ ldr(r3, FieldMemOperand(r2, 0));
2723 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2724 __ str(r3, FieldMemOperand(r2, 0));
2728 ArrayConstructorStub stub(masm->isolate(), arg_count());
2729 __ TailCallStub(&stub);
2734 // The slow case, we need this no matter what to complete a call after a miss.
2735 CallFunctionNoFeedback(masm,
2741 __ stop("Unexpected code address");
2745 void CallICStub::Generate(MacroAssembler* masm) {
2747 // r3 - slot id (Smi)
2749 const int with_types_offset =
2750 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2751 const int generic_offset =
2752 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2753 Label extra_checks_or_miss, slow_start;
2754 Label slow, non_function, wrap, cont;
2755 Label have_js_function;
2756 int argc = arg_count();
2757 ParameterCount actual(argc);
2759 // The checks. First, does r1 match the recorded monomorphic target?
2760 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2761 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2763 // We don't know that we have a weak cell. We might have a private symbol
2764 // or an AllocationSite, but the memory is safe to examine.
2765 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2767 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2768 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2769 // computed, meaning that it can't appear to be a pointer. If the low bit is
2770 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2772 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2773 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2774 WeakCell::kValueOffset &&
2775 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2777 __ ldr(r5, FieldMemOperand(r4, WeakCell::kValueOffset));
2779 __ b(ne, &extra_checks_or_miss);
2781 // The compare above could have been a SMI/SMI comparison. Guard against this
2782 // convincing us that we have a monomorphic JSFunction.
2783 __ JumpIfSmi(r1, &extra_checks_or_miss);
2785 // Increment the call count for monomorphic function calls.
2786 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2787 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2788 __ ldr(r3, FieldMemOperand(r2, 0));
2789 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2790 __ str(r3, FieldMemOperand(r2, 0));
2792 __ bind(&have_js_function);
2793 if (CallAsMethod()) {
2794 EmitContinueIfStrictOrNative(masm, &cont);
2795 // Compute the receiver in sloppy mode.
2796 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2798 __ JumpIfSmi(r3, &wrap);
2799 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2805 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2808 EmitSlowCase(masm, argc, &non_function);
2810 if (CallAsMethod()) {
2812 EmitWrapCase(masm, argc, &cont);
2815 __ bind(&extra_checks_or_miss);
2816 Label uninitialized, miss;
2818 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2819 __ b(eq, &slow_start);
2821 // The following cases attempt to handle MISS cases without going to the
2823 if (FLAG_trace_ic) {
2827 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2828 __ b(eq, &uninitialized);
2830 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2831 // to handle it here. More complex cases are dealt with in the runtime.
2832 __ AssertNotSmi(r4);
2833 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2835 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2836 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2837 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2838 // We have to update statistics for runtime profiling.
2839 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2840 __ sub(r4, r4, Operand(Smi::FromInt(1)));
2841 __ str(r4, FieldMemOperand(r2, with_types_offset));
2842 __ ldr(r4, FieldMemOperand(r2, generic_offset));
2843 __ add(r4, r4, Operand(Smi::FromInt(1)));
2844 __ str(r4, FieldMemOperand(r2, generic_offset));
2845 __ jmp(&slow_start);
2847 __ bind(&uninitialized);
2849 // We are going monomorphic, provided we actually have a JSFunction.
2850 __ JumpIfSmi(r1, &miss);
2852 // Goto miss case if we do not have a function.
2853 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2856 // Make sure the function is not the Array() function, which requires special
2857 // behavior on MISS.
2858 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2863 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2864 __ add(r4, r4, Operand(Smi::FromInt(1)));
2865 __ str(r4, FieldMemOperand(r2, with_types_offset));
2867 // Initialize the call counter.
2868 __ Move(r5, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2869 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2870 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + kPointerSize));
2872 // Store the function. Use a stub since we need a frame for allocation.
2877 FrameScope scope(masm, StackFrame::INTERNAL);
2878 CreateWeakCellStub create_stub(masm->isolate());
2880 __ CallStub(&create_stub);
2884 __ jmp(&have_js_function);
2886 // We are here because tracing is on or we encountered a MISS case we can't
2892 __ bind(&slow_start);
2893 // Check that the function is really a JavaScript function.
2894 // r1: pushed function (to be verified)
2895 __ JumpIfSmi(r1, &non_function);
2897 // Goto slow case if we do not have a function.
2898 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2900 __ jmp(&have_js_function);
2904 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2905 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2907 // Push the receiver and the function and feedback info.
2908 __ Push(r1, r2, r3);
2911 Runtime::FunctionId id = GetICState() == DEFAULT
2912 ? Runtime::kCallIC_Miss
2913 : Runtime::kCallIC_Customization_Miss;
2914 __ CallRuntime(id, 3);
2916 // Move result to edi and exit the internal frame.
2921 // StringCharCodeAtGenerator
2922 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2923 // If the receiver is a smi trigger the non-string case.
2924 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2925 __ JumpIfSmi(object_, receiver_not_string_);
2927 // Fetch the instance type of the receiver into result register.
2928 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2929 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2930 // If the receiver is not a string trigger the non-string case.
2931 __ tst(result_, Operand(kIsNotStringMask));
2932 __ b(ne, receiver_not_string_);
2935 // If the index is non-smi trigger the non-smi case.
2936 __ JumpIfNotSmi(index_, &index_not_smi_);
2937 __ bind(&got_smi_index_);
2939 // Check for index out of range.
2940 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
2941 __ cmp(ip, Operand(index_));
2942 __ b(ls, index_out_of_range_);
2944 __ SmiUntag(index_);
2946 StringCharLoadGenerator::Generate(masm,
2957 void StringCharCodeAtGenerator::GenerateSlow(
2958 MacroAssembler* masm, EmbedMode embed_mode,
2959 const RuntimeCallHelper& call_helper) {
2960 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2962 // Index is not a smi.
2963 __ bind(&index_not_smi_);
2964 // If index is a heap number, try converting it to an integer.
2967 Heap::kHeapNumberMapRootIndex,
2970 call_helper.BeforeCall(masm);
2971 if (embed_mode == PART_OF_IC_HANDLER) {
2972 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2973 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2975 // index_ is consumed by runtime conversion function.
2976 __ Push(object_, index_);
2978 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2979 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2981 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2982 // NumberToSmi discards numbers that are not exact integers.
2983 __ CallRuntime(Runtime::kNumberToSmi, 1);
2985 // Save the conversion result before the pop instructions below
2986 // have a chance to overwrite it.
2987 __ Move(index_, r0);
2988 if (embed_mode == PART_OF_IC_HANDLER) {
2989 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2990 LoadWithVectorDescriptor::SlotRegister(), object_);
2994 // Reload the instance type.
2995 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2996 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2997 call_helper.AfterCall(masm);
2998 // If index is still not a smi, it must be out of range.
2999 __ JumpIfNotSmi(index_, index_out_of_range_);
3000 // Otherwise, return to the fast path.
3001 __ jmp(&got_smi_index_);
3003 // Call runtime. We get here when the receiver is a string and the
3004 // index is a number, but the code of getting the actual character
3005 // is too complex (e.g., when the string needs to be flattened).
3006 __ bind(&call_runtime_);
3007 call_helper.BeforeCall(masm);
3009 __ Push(object_, index_);
3010 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3011 __ Move(result_, r0);
3012 call_helper.AfterCall(masm);
3015 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3019 // -------------------------------------------------------------------------
3020 // StringCharFromCodeGenerator
3022 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3023 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3024 STATIC_ASSERT(kSmiTag == 0);
3025 STATIC_ASSERT(kSmiShiftSize == 0);
3026 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3027 __ tst(code_, Operand(kSmiTagMask |
3028 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3029 __ b(ne, &slow_case_);
3031 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3032 // At this point code register contains smi tagged one-byte char code.
3033 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
3034 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3035 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
3036 __ b(eq, &slow_case_);
3041 void StringCharFromCodeGenerator::GenerateSlow(
3042 MacroAssembler* masm,
3043 const RuntimeCallHelper& call_helper) {
3044 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3046 __ bind(&slow_case_);
3047 call_helper.BeforeCall(masm);
3049 __ CallRuntime(Runtime::kCharFromCode, 1);
3050 __ Move(result_, r0);
3051 call_helper.AfterCall(masm);
3054 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3058 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3061 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3066 String::Encoding encoding) {
3067 if (FLAG_debug_code) {
3068 // Check that destination is word aligned.
3069 __ tst(dest, Operand(kPointerAlignmentMask));
3070 __ Check(eq, kDestinationOfCopyNotAligned);
3073 // Assumes word reads and writes are little endian.
3074 // Nothing to do for zero characters.
3076 if (encoding == String::TWO_BYTE_ENCODING) {
3077 __ add(count, count, Operand(count), SetCC);
3080 Register limit = count; // Read until dest equals this.
3081 __ add(limit, dest, Operand(count));
3083 Label loop_entry, loop;
3084 // Copy bytes from src to dest until dest hits limit.
3087 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
3088 __ strb(scratch, MemOperand(dest, 1, PostIndex));
3089 __ bind(&loop_entry);
3090 __ cmp(dest, Operand(limit));
3097 void SubStringStub::Generate(MacroAssembler* masm) {
3100 // Stack frame on entry.
3101 // lr: return address
3106 // This stub is called from the native-call %_SubString(...), so
3107 // nothing can be assumed about the arguments. It is tested that:
3108 // "string" is a sequential string,
3109 // both "from" and "to" are smis, and
3110 // 0 <= from <= to <= string.length.
3111 // If any of these assumptions fail, we call the runtime system.
3113 const int kToOffset = 0 * kPointerSize;
3114 const int kFromOffset = 1 * kPointerSize;
3115 const int kStringOffset = 2 * kPointerSize;
3117 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
3118 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3119 STATIC_ASSERT(kSmiTag == 0);
3120 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3122 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
3123 // instead because we bail out on non-smi values: ROR and ASR are equivalent
3124 // for smis but they set the flags in a way that's easier to optimize.
3125 __ mov(r2, Operand(r2, ROR, 1), SetCC);
3126 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
3127 // If either to or from had the smi tag bit set, then C is set now, and N
3128 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
3129 // We want to bailout to runtime here if From is negative. In that case, the
3130 // next instruction is not executed and we fall through to bailing out to
3132 // Executed if both r2 and r3 are untagged integers.
3133 __ sub(r2, r2, Operand(r3), SetCC, cc);
3134 // One of the above un-smis or the above SUB could have set N==1.
3135 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
3137 // Make sure first argument is a string.
3138 __ ldr(r0, MemOperand(sp, kStringOffset));
3139 __ JumpIfSmi(r0, &runtime);
3140 Condition is_string = masm->IsObjectStringType(r0, r1);
3141 __ b(NegateCondition(is_string), &runtime);
3144 __ cmp(r2, Operand(1));
3145 __ b(eq, &single_char);
3147 // Short-cut for the case of trivial substring.
3149 // r0: original string
3150 // r2: result string length
3151 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
3152 __ cmp(r2, Operand(r4, ASR, 1));
3153 // Return original string.
3154 __ b(eq, &return_r0);
3155 // Longer than original string's length or negative: unsafe arguments.
3157 // Shorter than original string's length: an actual substring.
3159 // Deal with different string types: update the index if necessary
3160 // and put the underlying string into r5.
3161 // r0: original string
3162 // r1: instance type
3164 // r3: from index (untagged)
3165 Label underlying_unpacked, sliced_string, seq_or_external_string;
3166 // If the string is not indirect, it can only be sequential or external.
3167 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3168 STATIC_ASSERT(kIsIndirectStringMask != 0);
3169 __ tst(r1, Operand(kIsIndirectStringMask));
3170 __ b(eq, &seq_or_external_string);
3172 __ tst(r1, Operand(kSlicedNotConsMask));
3173 __ b(ne, &sliced_string);
3174 // Cons string. Check whether it is flat, then fetch first part.
3175 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
3176 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
3178 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
3179 // Update instance type.
3180 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3181 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3182 __ jmp(&underlying_unpacked);
3184 __ bind(&sliced_string);
3185 // Sliced string. Fetch parent and correct start index by offset.
3186 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3187 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3188 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
3189 // Update instance type.
3190 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3191 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3192 __ jmp(&underlying_unpacked);
3194 __ bind(&seq_or_external_string);
3195 // Sequential or external string. Just move string to the expected register.
3198 __ bind(&underlying_unpacked);
3200 if (FLAG_string_slices) {
3202 // r5: underlying subject string
3203 // r1: instance type of underlying subject string
3205 // r3: adjusted start index (untagged)
3206 __ cmp(r2, Operand(SlicedString::kMinLength));
3207 // Short slice. Copy instead of slicing.
3208 __ b(lt, ©_routine);
3209 // Allocate new sliced string. At this point we do not reload the instance
3210 // type including the string encoding because we simply rely on the info
3211 // provided by the original string. It does not matter if the original
3212 // string's encoding is wrong because we always have to recheck encoding of
3213 // the newly created string's parent anyways due to externalized strings.
3214 Label two_byte_slice, set_slice_header;
3215 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3216 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3217 __ tst(r1, Operand(kStringEncodingMask));
3218 __ b(eq, &two_byte_slice);
3219 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
3220 __ jmp(&set_slice_header);
3221 __ bind(&two_byte_slice);
3222 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
3223 __ bind(&set_slice_header);
3224 __ mov(r3, Operand(r3, LSL, 1));
3225 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3226 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3229 __ bind(©_routine);
3232 // r5: underlying subject string
3233 // r1: instance type of underlying subject string
3235 // r3: adjusted start index (untagged)
3236 Label two_byte_sequential, sequential_string, allocate_result;
3237 STATIC_ASSERT(kExternalStringTag != 0);
3238 STATIC_ASSERT(kSeqStringTag == 0);
3239 __ tst(r1, Operand(kExternalStringTag));
3240 __ b(eq, &sequential_string);
3242 // Handle external string.
3243 // Rule out short external strings.
3244 STATIC_ASSERT(kShortExternalStringTag != 0);
3245 __ tst(r1, Operand(kShortExternalStringTag));
3247 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
3248 // r5 already points to the first character of underlying string.
3249 __ jmp(&allocate_result);
3251 __ bind(&sequential_string);
3252 // Locate first character of underlying subject string.
3253 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3254 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3256 __ bind(&allocate_result);
3257 // Sequential acii string. Allocate the result.
3258 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3259 __ tst(r1, Operand(kStringEncodingMask));
3260 __ b(eq, &two_byte_sequential);
3262 // Allocate and copy the resulting one-byte string.
3263 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
3265 // Locate first character of substring to copy.
3267 // Locate first character of result.
3268 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3270 // r0: result string
3271 // r1: first character of result string
3272 // r2: result string length
3273 // r5: first character of substring to copy
3274 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3275 StringHelper::GenerateCopyCharacters(
3276 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
3279 // Allocate and copy the resulting two-byte string.
3280 __ bind(&two_byte_sequential);
3281 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
3283 // Locate first character of substring to copy.
3284 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3285 __ add(r5, r5, Operand(r3, LSL, 1));
3286 // Locate first character of result.
3287 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3289 // r0: result string.
3290 // r1: first character of result.
3291 // r2: result length.
3292 // r5: first character of substring to copy.
3293 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3294 StringHelper::GenerateCopyCharacters(
3295 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
3297 __ bind(&return_r0);
3298 Counters* counters = isolate()->counters();
3299 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
3303 // Just jump to runtime to create the sub string.
3305 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3307 __ bind(&single_char);
3308 // r0: original string
3309 // r1: instance type
3311 // r3: from index (untagged)
3313 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
3314 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3315 generator.GenerateFast(masm);
3318 generator.SkipSlow(masm, &runtime);
3322 void ToNumberStub::Generate(MacroAssembler* masm) {
3323 // The ToNumber stub takes one argument in r0.
3325 __ JumpIfNotSmi(r0, ¬_smi);
3329 Label not_heap_number;
3330 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
3331 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3333 // r1: instance type.
3334 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
3335 __ b(ne, ¬_heap_number);
3337 __ bind(¬_heap_number);
3339 Label not_string, slow_string;
3340 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
3341 __ b(hs, ¬_string);
3342 // Check if string has a cached array index.
3343 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
3344 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
3345 __ b(ne, &slow_string);
3346 __ IndexFromHash(r2, r0);
3348 __ bind(&slow_string);
3349 __ push(r0); // Push argument.
3350 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3351 __ bind(¬_string);
3354 __ cmp(r1, Operand(ODDBALL_TYPE));
3355 __ b(ne, ¬_oddball);
3356 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
3358 __ bind(¬_oddball);
3360 __ push(r0); // Push argument.
3361 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3365 void StringHelper::GenerateFlatOneByteStringEquals(
3366 MacroAssembler* masm, Register left, Register right, Register scratch1,
3367 Register scratch2, Register scratch3) {
3368 Register length = scratch1;
3371 Label strings_not_equal, check_zero_length;
3372 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
3373 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3374 __ cmp(length, scratch2);
3375 __ b(eq, &check_zero_length);
3376 __ bind(&strings_not_equal);
3377 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
3380 // Check if the length is zero.
3381 Label compare_chars;
3382 __ bind(&check_zero_length);
3383 STATIC_ASSERT(kSmiTag == 0);
3384 __ cmp(length, Operand::Zero());
3385 __ b(ne, &compare_chars);
3386 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3389 // Compare characters.
3390 __ bind(&compare_chars);
3391 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3392 &strings_not_equal);
3394 // Characters are equal.
3395 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3400 void StringHelper::GenerateCompareFlatOneByteStrings(
3401 MacroAssembler* masm, Register left, Register right, Register scratch1,
3402 Register scratch2, Register scratch3, Register scratch4) {
3403 Label result_not_equal, compare_lengths;
3404 // Find minimum length and length difference.
3405 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3406 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3407 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
3408 Register length_delta = scratch3;
3409 __ mov(scratch1, scratch2, LeaveCC, gt);
3410 Register min_length = scratch1;
3411 STATIC_ASSERT(kSmiTag == 0);
3412 __ cmp(min_length, Operand::Zero());
3413 __ b(eq, &compare_lengths);
3416 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3417 scratch4, &result_not_equal);
3419 // Compare lengths - strings up to min-length are equal.
3420 __ bind(&compare_lengths);
3421 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3422 // Use length_delta as result if it's zero.
3423 __ mov(r0, Operand(length_delta), SetCC);
3424 __ bind(&result_not_equal);
3425 // Conditionally update the result based either on length_delta or
3426 // the last comparion performed in the loop above.
3427 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
3428 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
3433 void StringHelper::GenerateOneByteCharsCompareLoop(
3434 MacroAssembler* masm, Register left, Register right, Register length,
3435 Register scratch1, Register scratch2, Label* chars_not_equal) {
3436 // Change index to run from -length to -1 by adding length to string
3437 // start. This means that loop ends when index reaches zero, which
3438 // doesn't need an additional compare.
3439 __ SmiUntag(length);
3440 __ add(scratch1, length,
3441 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3442 __ add(left, left, Operand(scratch1));
3443 __ add(right, right, Operand(scratch1));
3444 __ rsb(length, length, Operand::Zero());
3445 Register index = length; // index = -length;
3450 __ ldrb(scratch1, MemOperand(left, index));
3451 __ ldrb(scratch2, MemOperand(right, index));
3452 __ cmp(scratch1, scratch2);
3453 __ b(ne, chars_not_equal);
3454 __ add(index, index, Operand(1), SetCC);
3459 void StringCompareStub::Generate(MacroAssembler* masm) {
3462 Counters* counters = isolate()->counters();
3464 // Stack frame on entry.
3465 // sp[0]: right string
3466 // sp[4]: left string
3467 __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1.
3471 __ b(ne, ¬_same);
3472 STATIC_ASSERT(EQUAL == 0);
3473 STATIC_ASSERT(kSmiTag == 0);
3474 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3475 __ IncrementCounter(counters->string_compare_native(), 1, r1, r2);
3476 __ add(sp, sp, Operand(2 * kPointerSize));
3481 // Check that both objects are sequential one-byte strings.
3482 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
3484 // Compare flat one-byte strings natively. Remove arguments from stack first.
3485 __ IncrementCounter(counters->string_compare_native(), 1, r2, r3);
3486 __ add(sp, sp, Operand(2 * kPointerSize));
3487 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
3489 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3490 // tagged as a small integer.
3492 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3496 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3497 // ----------- S t a t e -------------
3500 // -- lr : return address
3501 // -----------------------------------
3503 // Load r2 with the allocation site. We stick an undefined dummy value here
3504 // and replace it with the real allocation site later when we instantiate this
3505 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3506 __ Move(r2, handle(isolate()->heap()->undefined_value()));
3508 // Make sure that we actually patched the allocation site.
3509 if (FLAG_debug_code) {
3510 __ tst(r2, Operand(kSmiTagMask));
3511 __ Assert(ne, kExpectedAllocationSite);
3513 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3514 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3517 __ Assert(eq, kExpectedAllocationSite);
3520 // Tail call into the stub that handles binary operations with allocation
3522 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3523 __ TailCallStub(&stub);
3527 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3528 DCHECK(state() == CompareICState::SMI);
3531 __ JumpIfNotSmi(r2, &miss);
3533 if (GetCondition() == eq) {
3534 // For equality we do not care about the sign of the result.
3535 __ sub(r0, r0, r1, SetCC);
3537 // Untag before subtracting to avoid handling overflow.
3539 __ sub(r0, r1, Operand::SmiUntag(r0));
3548 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3549 DCHECK(state() == CompareICState::NUMBER);
3552 Label unordered, maybe_undefined1, maybe_undefined2;
3555 if (left() == CompareICState::SMI) {
3556 __ JumpIfNotSmi(r1, &miss);
3558 if (right() == CompareICState::SMI) {
3559 __ JumpIfNotSmi(r0, &miss);
3562 // Inlining the double comparison and falling back to the general compare
3563 // stub if NaN is involved.
3564 // Load left and right operand.
3565 Label done, left, left_smi, right_smi;
3566 __ JumpIfSmi(r0, &right_smi);
3567 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3569 __ sub(r2, r0, Operand(kHeapObjectTag));
3570 __ vldr(d1, r2, HeapNumber::kValueOffset);
3572 __ bind(&right_smi);
3573 __ SmiToDouble(d1, r0);
3576 __ JumpIfSmi(r1, &left_smi);
3577 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3579 __ sub(r2, r1, Operand(kHeapObjectTag));
3580 __ vldr(d0, r2, HeapNumber::kValueOffset);
3583 __ SmiToDouble(d0, r1);
3586 // Compare operands.
3587 __ VFPCompareAndSetFlags(d0, d1);
3589 // Don't base result on status bits when a NaN is involved.
3590 __ b(vs, &unordered);
3592 // Return a result of -1, 0, or 1, based on status bits.
3593 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
3594 __ mov(r0, Operand(LESS), LeaveCC, lt);
3595 __ mov(r0, Operand(GREATER), LeaveCC, gt);
3598 __ bind(&unordered);
3599 __ bind(&generic_stub);
3600 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3601 CompareICState::GENERIC, CompareICState::GENERIC);
3602 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3604 __ bind(&maybe_undefined1);
3605 if (Token::IsOrderedRelationalCompareOp(op())) {
3606 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3608 __ JumpIfSmi(r1, &unordered);
3609 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3610 __ b(ne, &maybe_undefined2);
3614 __ bind(&maybe_undefined2);
3615 if (Token::IsOrderedRelationalCompareOp(op())) {
3616 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3617 __ b(eq, &unordered);
3625 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3626 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3629 // Registers containing left and right operands respectively.
3631 Register right = r0;
3635 // Check that both operands are heap objects.
3636 __ JumpIfEitherSmi(left, right, &miss);
3638 // Check that both operands are internalized strings.
3639 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3640 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3641 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3642 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3643 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3644 __ orr(tmp1, tmp1, Operand(tmp2));
3645 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3648 // Internalized strings are compared by identity.
3649 __ cmp(left, right);
3650 // Make sure r0 is non-zero. At this point input operands are
3651 // guaranteed to be non-zero.
3652 DCHECK(right.is(r0));
3653 STATIC_ASSERT(EQUAL == 0);
3654 STATIC_ASSERT(kSmiTag == 0);
3655 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3663 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3664 DCHECK(state() == CompareICState::UNIQUE_NAME);
3665 DCHECK(GetCondition() == eq);
3668 // Registers containing left and right operands respectively.
3670 Register right = r0;
3674 // Check that both operands are heap objects.
3675 __ JumpIfEitherSmi(left, right, &miss);
3677 // Check that both operands are unique names. This leaves the instance
3678 // types loaded in tmp1 and tmp2.
3679 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3680 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3681 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3682 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3684 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3685 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3687 // Unique names are compared by identity.
3688 __ cmp(left, right);
3689 // Make sure r0 is non-zero. At this point input operands are
3690 // guaranteed to be non-zero.
3691 DCHECK(right.is(r0));
3692 STATIC_ASSERT(EQUAL == 0);
3693 STATIC_ASSERT(kSmiTag == 0);
3694 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3702 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3703 DCHECK(state() == CompareICState::STRING);
3706 bool equality = Token::IsEqualityOp(op());
3708 // Registers containing left and right operands respectively.
3710 Register right = r0;
3716 // Check that both operands are heap objects.
3717 __ JumpIfEitherSmi(left, right, &miss);
3719 // Check that both operands are strings. This leaves the instance
3720 // types loaded in tmp1 and tmp2.
3721 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3722 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3723 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3724 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3725 STATIC_ASSERT(kNotStringTag != 0);
3726 __ orr(tmp3, tmp1, tmp2);
3727 __ tst(tmp3, Operand(kIsNotStringMask));
3730 // Fast check for identical strings.
3731 __ cmp(left, right);
3732 STATIC_ASSERT(EQUAL == 0);
3733 STATIC_ASSERT(kSmiTag == 0);
3734 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3737 // Handle not identical strings.
3739 // Check that both strings are internalized strings. If they are, we're done
3740 // because we already know they are not identical. We know they are both
3743 DCHECK(GetCondition() == eq);
3744 STATIC_ASSERT(kInternalizedTag == 0);
3745 __ orr(tmp3, tmp1, Operand(tmp2));
3746 __ tst(tmp3, Operand(kIsNotInternalizedMask));
3747 // Make sure r0 is non-zero. At this point input operands are
3748 // guaranteed to be non-zero.
3749 DCHECK(right.is(r0));
3753 // Check that both strings are sequential one-byte.
3755 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3758 // Compare flat one-byte strings. Returns when done.
3760 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3763 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3767 // Handle more complex cases in runtime.
3769 __ Push(left, right);
3771 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3773 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3781 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3782 DCHECK(state() == CompareICState::OBJECT);
3784 __ and_(r2, r1, Operand(r0));
3785 __ JumpIfSmi(r2, &miss);
3787 __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
3789 __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
3792 DCHECK(GetCondition() == eq);
3793 __ sub(r0, r0, Operand(r1));
3801 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3803 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3804 __ and_(r2, r1, Operand(r0));
3805 __ JumpIfSmi(r2, &miss);
3806 __ GetWeakValue(r4, cell);
3807 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3808 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
3814 __ sub(r0, r0, Operand(r1));
3822 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3824 // Call the runtime system in a fresh internal frame.
3825 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3827 __ Push(lr, r1, r0);
3828 __ mov(ip, Operand(Smi::FromInt(op())));
3830 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3831 // Compute the entry point of the rewritten stub.
3832 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3833 // Restore registers.
3842 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3843 // Place the return address on the stack, making the call
3844 // GC safe. The RegExp backend also relies on this.
3845 __ str(lr, MemOperand(sp, 0));
3846 __ blx(ip); // Call the C++ function.
3847 __ VFPEnsureFPSCRState(r2);
3848 __ ldr(pc, MemOperand(sp, 0));
3852 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3855 reinterpret_cast<intptr_t>(GetCode().location());
3856 __ Move(ip, target);
3857 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3858 __ blx(lr); // Call the stub.
3862 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3866 Register properties,
3868 Register scratch0) {
3869 DCHECK(name->IsUniqueName());
3870 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3871 // not equal to the name and kProbes-th slot is not used (its name is the
3872 // undefined value), it guarantees the hash table doesn't contain the
3873 // property. It's true even if some slots represent deleted properties
3874 // (their names are the hole value).
3875 for (int i = 0; i < kInlinedProbes; i++) {
3876 // scratch0 points to properties hash.
3877 // Compute the masked index: (hash + i + i * i) & mask.
3878 Register index = scratch0;
3879 // Capacity is smi 2^n.
3880 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3881 __ sub(index, index, Operand(1));
3882 __ and_(index, index, Operand(
3883 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3885 // Scale the index by multiplying by the entry size.
3886 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3887 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3889 Register entity_name = scratch0;
3890 // Having undefined at this place means the name is not contained.
3891 STATIC_ASSERT(kSmiTagSize == 1);
3892 Register tmp = properties;
3893 __ add(tmp, properties, Operand(index, LSL, 1));
3894 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3896 DCHECK(!tmp.is(entity_name));
3897 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3898 __ cmp(entity_name, tmp);
3901 // Load the hole ready for use below:
3902 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3904 // Stop if found the property.
3905 __ cmp(entity_name, Operand(Handle<Name>(name)));
3909 __ cmp(entity_name, tmp);
3912 // Check if the entry name is not a unique name.
3913 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3914 __ ldrb(entity_name,
3915 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3916 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3919 // Restore the properties.
3921 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3924 const int spill_mask =
3925 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3926 r2.bit() | r1.bit() | r0.bit());
3928 __ stm(db_w, sp, spill_mask);
3929 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3930 __ mov(r1, Operand(Handle<Name>(name)));
3931 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3933 __ cmp(r0, Operand::Zero());
3934 __ ldm(ia_w, sp, spill_mask);
3941 // Probe the name dictionary in the |elements| register. Jump to the
3942 // |done| label if a property with the given name is found. Jump to
3943 // the |miss| label otherwise.
3944 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
3945 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3951 Register scratch2) {
3952 DCHECK(!elements.is(scratch1));
3953 DCHECK(!elements.is(scratch2));
3954 DCHECK(!name.is(scratch1));
3955 DCHECK(!name.is(scratch2));
3957 __ AssertName(name);
3959 // Compute the capacity mask.
3960 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
3961 __ SmiUntag(scratch1);
3962 __ sub(scratch1, scratch1, Operand(1));
3964 // Generate an unrolled loop that performs a few probes before
3965 // giving up. Measurements done on Gmail indicate that 2 probes
3966 // cover ~93% of loads from dictionaries.
3967 for (int i = 0; i < kInlinedProbes; i++) {
3968 // Compute the masked index: (hash + i + i * i) & mask.
3969 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3971 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3972 // the hash in a separate instruction. The value hash + i + i * i is right
3973 // shifted in the following and instruction.
3974 DCHECK(NameDictionary::GetProbeOffset(i) <
3975 1 << (32 - Name::kHashFieldOffset));
3976 __ add(scratch2, scratch2, Operand(
3977 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3979 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
3981 // Scale the index by multiplying by the entry size.
3982 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3983 // scratch2 = scratch2 * 3.
3984 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3986 // Check if the key is identical to the name.
3987 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3988 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3989 __ cmp(name, Operand(ip));
3993 const int spill_mask =
3994 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3995 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3996 ~(scratch1.bit() | scratch2.bit());
3998 __ stm(db_w, sp, spill_mask);
4000 DCHECK(!elements.is(r1));
4002 __ Move(r0, elements);
4004 __ Move(r0, elements);
4007 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4009 __ cmp(r0, Operand::Zero());
4010 __ mov(scratch2, Operand(r2));
4011 __ ldm(ia_w, sp, spill_mask);
4018 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4019 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4020 // we cannot call anything that could cause a GC from this stub.
4022 // result: NameDictionary to probe
4024 // dictionary: NameDictionary to probe.
4025 // index: will hold an index of entry if lookup is successful.
4026 // might alias with result_.
4028 // result_ is zero if lookup failed, non zero otherwise.
4030 Register result = r0;
4031 Register dictionary = r0;
4033 Register index = r2;
4036 Register undefined = r5;
4037 Register entry_key = r6;
4039 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4041 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
4043 __ sub(mask, mask, Operand(1));
4045 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4047 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4049 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4050 // Compute the masked index: (hash + i + i * i) & mask.
4051 // Capacity is smi 2^n.
4053 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4054 // the hash in a separate instruction. The value hash + i + i * i is right
4055 // shifted in the following and instruction.
4056 DCHECK(NameDictionary::GetProbeOffset(i) <
4057 1 << (32 - Name::kHashFieldOffset));
4058 __ add(index, hash, Operand(
4059 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4061 __ mov(index, Operand(hash));
4063 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
4065 // Scale the index by multiplying by the entry size.
4066 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4067 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
4069 STATIC_ASSERT(kSmiTagSize == 1);
4070 __ add(index, dictionary, Operand(index, LSL, 2));
4071 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
4073 // Having undefined at this place means the name is not contained.
4074 __ cmp(entry_key, Operand(undefined));
4075 __ b(eq, ¬_in_dictionary);
4077 // Stop if found the property.
4078 __ cmp(entry_key, Operand(key));
4079 __ b(eq, &in_dictionary);
4081 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4082 // Check if the entry name is not a unique name.
4083 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4085 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4086 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4090 __ bind(&maybe_in_dictionary);
4091 // If we are doing negative lookup then probing failure should be
4092 // treated as a lookup success. For positive lookup probing failure
4093 // should be treated as lookup failure.
4094 if (mode() == POSITIVE_LOOKUP) {
4095 __ mov(result, Operand::Zero());
4099 __ bind(&in_dictionary);
4100 __ mov(result, Operand(1));
4103 __ bind(¬_in_dictionary);
4104 __ mov(result, Operand::Zero());
4109 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4111 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4113 // Hydrogen code stubs need stub2 at snapshot time.
4114 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4119 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4120 // the value has just been written into the object, now this stub makes sure
4121 // we keep the GC informed. The word in the object where the value has been
4122 // written is in the address register.
4123 void RecordWriteStub::Generate(MacroAssembler* masm) {
4124 Label skip_to_incremental_noncompacting;
4125 Label skip_to_incremental_compacting;
4127 // The first two instructions are generated with labels so as to get the
4128 // offset fixed up correctly by the bind(Label*) call. We patch it back and
4129 // forth between a compare instructions (a nop in this position) and the
4130 // real branch when we start and stop incremental heap marking.
4131 // See RecordWriteStub::Patch for details.
4133 // Block literal pool emission, as the position of these two instructions
4134 // is assumed by the patching code.
4135 Assembler::BlockConstPoolScope block_const_pool(masm);
4136 __ b(&skip_to_incremental_noncompacting);
4137 __ b(&skip_to_incremental_compacting);
4140 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4141 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4142 MacroAssembler::kReturnAtEnd);
4146 __ bind(&skip_to_incremental_noncompacting);
4147 GenerateIncremental(masm, INCREMENTAL);
4149 __ bind(&skip_to_incremental_compacting);
4150 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4152 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4153 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4154 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4155 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
4156 PatchBranchIntoNop(masm, 0);
4157 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4161 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4164 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4165 Label dont_need_remembered_set;
4167 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4168 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4170 &dont_need_remembered_set);
4172 __ CheckPageFlag(regs_.object(),
4174 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4176 &dont_need_remembered_set);
4178 // First notify the incremental marker if necessary, then update the
4180 CheckNeedsToInformIncrementalMarker(
4181 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4182 InformIncrementalMarker(masm);
4183 regs_.Restore(masm);
4184 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4185 MacroAssembler::kReturnAtEnd);
4187 __ bind(&dont_need_remembered_set);
4190 CheckNeedsToInformIncrementalMarker(
4191 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4192 InformIncrementalMarker(masm);
4193 regs_.Restore(masm);
4198 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4199 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4200 int argument_count = 3;
4201 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4203 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4204 DCHECK(!address.is(regs_.object()));
4205 DCHECK(!address.is(r0));
4206 __ Move(address, regs_.address());
4207 __ Move(r0, regs_.object());
4208 __ Move(r1, address);
4209 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4211 AllowExternalCallThatCantCauseGC scope(masm);
4213 ExternalReference::incremental_marking_record_write_function(isolate()),
4215 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4219 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4220 MacroAssembler* masm,
4221 OnNoNeedToInformIncrementalMarker on_no_need,
4224 Label need_incremental;
4225 Label need_incremental_pop_scratch;
4227 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4228 __ ldr(regs_.scratch1(),
4229 MemOperand(regs_.scratch0(),
4230 MemoryChunk::kWriteBarrierCounterOffset));
4231 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4232 __ str(regs_.scratch1(),
4233 MemOperand(regs_.scratch0(),
4234 MemoryChunk::kWriteBarrierCounterOffset));
4235 __ b(mi, &need_incremental);
4237 // Let's look at the color of the object: If it is not black we don't have
4238 // to inform the incremental marker.
4239 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4241 regs_.Restore(masm);
4242 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4243 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4244 MacroAssembler::kReturnAtEnd);
4251 // Get the value from the slot.
4252 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4254 if (mode == INCREMENTAL_COMPACTION) {
4255 Label ensure_not_white;
4257 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4258 regs_.scratch1(), // Scratch.
4259 MemoryChunk::kEvacuationCandidateMask,
4263 __ CheckPageFlag(regs_.object(),
4264 regs_.scratch1(), // Scratch.
4265 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4269 __ bind(&ensure_not_white);
4272 // We need extra registers for this, so we push the object and the address
4273 // register temporarily.
4274 __ Push(regs_.object(), regs_.address());
4275 __ EnsureNotWhite(regs_.scratch0(), // The value.
4276 regs_.scratch1(), // Scratch.
4277 regs_.object(), // Scratch.
4278 regs_.address(), // Scratch.
4279 &need_incremental_pop_scratch);
4280 __ Pop(regs_.object(), regs_.address());
4282 regs_.Restore(masm);
4283 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4284 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4285 MacroAssembler::kReturnAtEnd);
4290 __ bind(&need_incremental_pop_scratch);
4291 __ Pop(regs_.object(), regs_.address());
4293 __ bind(&need_incremental);
4295 // Fall through when we need to inform the incremental marker.
4299 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4300 // ----------- S t a t e -------------
4301 // -- r0 : element value to store
4302 // -- r3 : element index as smi
4303 // -- sp[0] : array literal index in function as smi
4304 // -- sp[4] : array literal
4305 // clobbers r1, r2, r4
4306 // -----------------------------------
4309 Label double_elements;
4311 Label slow_elements;
4312 Label fast_elements;
4314 // Get array literal index, array literal and its map.
4315 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4316 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4317 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4319 __ CheckFastElements(r2, r5, &double_elements);
4320 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4321 __ JumpIfSmi(r0, &smi_element);
4322 __ CheckFastSmiElements(r2, r5, &fast_elements);
4324 // Store into the array literal requires a elements transition. Call into
4326 __ bind(&slow_elements);
4328 __ Push(r1, r3, r0);
4329 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4330 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4332 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4334 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4335 __ bind(&fast_elements);
4336 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4337 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4338 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4339 __ str(r0, MemOperand(r6, 0));
4340 // Update the write barrier for the array store.
4341 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4342 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4345 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4346 // and value is Smi.
4347 __ bind(&smi_element);
4348 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4349 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4350 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4353 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4354 __ bind(&double_elements);
4355 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4356 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
4361 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4362 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4363 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4364 int parameter_count_offset =
4365 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4366 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4367 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4368 __ add(r1, r1, Operand(1));
4370 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4371 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4377 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4378 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4379 LoadICStub stub(isolate(), state());
4380 stub.GenerateForTrampoline(masm);
4384 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4385 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4386 KeyedLoadICStub stub(isolate(), state());
4387 stub.GenerateForTrampoline(masm);
4391 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4392 EmitLoadTypeFeedbackVector(masm, r2);
4393 CallICStub stub(isolate(), state());
4394 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4398 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4399 EmitLoadTypeFeedbackVector(masm, r2);
4400 CallIC_ArrayStub stub(isolate(), state());
4401 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4405 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4408 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4409 GenerateImpl(masm, true);
4413 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4414 Register key, Register vector, Register slot,
4415 Register feedback, Register receiver_map,
4416 Register scratch1, Register scratch2,
4417 bool is_polymorphic, Label* miss) {
4418 // feedback initially contains the feedback array
4419 Label next_loop, prepare_next;
4420 Label start_polymorphic;
4422 Register cached_map = scratch1;
4425 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4426 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4427 __ cmp(receiver_map, cached_map);
4428 __ b(ne, &start_polymorphic);
4429 // found, now call handler.
4430 Register handler = feedback;
4431 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4432 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4435 Register length = scratch2;
4436 __ bind(&start_polymorphic);
4437 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4438 if (!is_polymorphic) {
4439 // If the IC could be monomorphic we have to make sure we don't go past the
4440 // end of the feedback array.
4441 __ cmp(length, Operand(Smi::FromInt(2)));
4445 Register too_far = length;
4446 Register pointer_reg = feedback;
4448 // +-----+------+------+-----+-----+ ... ----+
4449 // | map | len | wm0 | h0 | wm1 | hN |
4450 // +-----+------+------+-----+-----+ ... ----+
4454 // pointer_reg too_far
4455 // aka feedback scratch2
4456 // also need receiver_map
4457 // use cached_map (scratch1) to look in the weak map values.
4458 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
4459 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4460 __ add(pointer_reg, feedback,
4461 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4463 __ bind(&next_loop);
4464 __ ldr(cached_map, MemOperand(pointer_reg));
4465 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4466 __ cmp(receiver_map, cached_map);
4467 __ b(ne, &prepare_next);
4468 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
4469 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4471 __ bind(&prepare_next);
4472 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4473 __ cmp(pointer_reg, too_far);
4474 __ b(lt, &next_loop);
4476 // We exhausted our array of map handler pairs.
4481 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4482 Register receiver_map, Register feedback,
4483 Register vector, Register slot,
4484 Register scratch, Label* compare_map,
4485 Label* load_smi_map, Label* try_array) {
4486 __ JumpIfSmi(receiver, load_smi_map);
4487 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4488 __ bind(compare_map);
4489 Register cached_map = scratch;
4490 // Move the weak map into the weak_cell register.
4491 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4492 __ cmp(cached_map, receiver_map);
4493 __ b(ne, try_array);
4494 Register handler = feedback;
4495 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
4497 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4498 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4502 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4503 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4504 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
4505 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4506 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4507 Register feedback = r4;
4508 Register receiver_map = r5;
4509 Register scratch1 = r6;
4511 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4512 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4514 // Try to quickly handle the monomorphic case without knowing for sure
4515 // if we have a weak cell in feedback. We do know it's safe to look
4516 // at WeakCell::kValueOffset.
4517 Label try_array, load_smi_map, compare_map;
4518 Label not_array, miss;
4519 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4520 scratch1, &compare_map, &load_smi_map, &try_array);
4522 // Is it a fixed array?
4523 __ bind(&try_array);
4524 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4525 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4526 __ b(ne, ¬_array);
4527 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4528 scratch1, r9, true, &miss);
4530 __ bind(¬_array);
4531 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4533 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4534 Code::ComputeHandlerFlags(Code::LOAD_IC));
4535 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4536 false, receiver, name, feedback,
4537 receiver_map, scratch1, r9);
4540 LoadIC::GenerateMiss(masm);
4543 __ bind(&load_smi_map);
4544 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4545 __ jmp(&compare_map);
4549 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4550 GenerateImpl(masm, false);
4554 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4555 GenerateImpl(masm, true);
4559 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4560 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4561 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
4562 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4563 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4564 Register feedback = r4;
4565 Register receiver_map = r5;
4566 Register scratch1 = r6;
4568 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4569 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4571 // Try to quickly handle the monomorphic case without knowing for sure
4572 // if we have a weak cell in feedback. We do know it's safe to look
4573 // at WeakCell::kValueOffset.
4574 Label try_array, load_smi_map, compare_map;
4575 Label not_array, miss;
4576 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4577 scratch1, &compare_map, &load_smi_map, &try_array);
4579 __ bind(&try_array);
4580 // Is it a fixed array?
4581 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4582 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4583 __ b(ne, ¬_array);
4585 // We have a polymorphic element handler.
4586 Label polymorphic, try_poly_name;
4587 __ bind(&polymorphic);
4588 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4589 scratch1, r9, true, &miss);
4591 __ bind(¬_array);
4593 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4594 __ b(ne, &try_poly_name);
4595 Handle<Code> megamorphic_stub =
4596 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4597 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4599 __ bind(&try_poly_name);
4600 // We might have a name in feedback, and a fixed array in the next slot.
4601 __ cmp(key, feedback);
4603 // If the name comparison succeeded, we know we have a fixed array with
4604 // at least one map/handler pair.
4605 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4607 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4608 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4609 scratch1, r9, false, &miss);
4612 KeyedLoadIC::GenerateMiss(masm);
4614 __ bind(&load_smi_map);
4615 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4616 __ jmp(&compare_map);
4620 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4621 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4622 VectorStoreICStub stub(isolate(), state());
4623 stub.GenerateForTrampoline(masm);
4627 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4628 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4629 VectorKeyedStoreICStub stub(isolate(), state());
4630 stub.GenerateForTrampoline(masm);
4634 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4635 GenerateImpl(masm, false);
4639 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4640 GenerateImpl(masm, true);
4644 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4647 // TODO(mvstanton): Implement.
4649 StoreIC::GenerateMiss(masm);
4653 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4654 GenerateImpl(masm, false);
4658 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4659 GenerateImpl(masm, true);
4663 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4666 // TODO(mvstanton): Implement.
4668 KeyedStoreIC::GenerateMiss(masm);
4672 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4673 if (masm->isolate()->function_entry_hook() != NULL) {
4674 ProfileEntryHookStub stub(masm->isolate());
4675 PredictableCodeSizeScope predictable(masm);
4676 predictable.ExpectSize(masm->CallStubSize(&stub) +
4677 2 * Assembler::kInstrSize);
4685 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4686 // The entry hook is a "push lr" instruction, followed by a call.
4687 const int32_t kReturnAddressDistanceFromFunctionStart =
4688 3 * Assembler::kInstrSize;
4690 // This should contain all kCallerSaved registers.
4691 const RegList kSavedRegs =
4698 // We also save lr, so the count here is one higher than the mask indicates.
4699 const int32_t kNumSavedRegs = 7;
4701 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4703 // Save all caller-save registers as this may be called from anywhere.
4704 __ stm(db_w, sp, kSavedRegs | lr.bit());
4706 // Compute the function's address for the first argument.
4707 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4709 // The caller's return address is above the saved temporaries.
4710 // Grab that for the second argument to the hook.
4711 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4713 // Align the stack if necessary.
4714 int frame_alignment = masm->ActivationFrameAlignment();
4715 if (frame_alignment > kPointerSize) {
4717 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4718 __ and_(sp, sp, Operand(-frame_alignment));
4721 #if V8_HOST_ARCH_ARM
4722 int32_t entry_hook =
4723 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4724 __ mov(ip, Operand(entry_hook));
4726 // Under the simulator we need to indirect the entry hook through a
4727 // trampoline function at a known address.
4728 // It additionally takes an isolate as a third parameter
4729 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4731 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4732 __ mov(ip, Operand(ExternalReference(&dispatcher,
4733 ExternalReference::BUILTIN_CALL,
4738 // Restore the stack pointer if needed.
4739 if (frame_alignment > kPointerSize) {
4743 // Also pop pc to get Ret(0).
4744 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4749 static void CreateArrayDispatch(MacroAssembler* masm,
4750 AllocationSiteOverrideMode mode) {
4751 if (mode == DISABLE_ALLOCATION_SITES) {
4752 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4753 __ TailCallStub(&stub);
4754 } else if (mode == DONT_OVERRIDE) {
4755 int last_index = GetSequenceIndexFromFastElementsKind(
4756 TERMINAL_FAST_ELEMENTS_KIND);
4757 for (int i = 0; i <= last_index; ++i) {
4758 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4759 __ cmp(r3, Operand(kind));
4760 T stub(masm->isolate(), kind);
4761 __ TailCallStub(&stub, eq);
4764 // If we reached this point there is a problem.
4765 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4772 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4773 AllocationSiteOverrideMode mode) {
4774 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4775 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4776 // r0 - number of arguments
4777 // r1 - constructor?
4778 // sp[0] - last argument
4779 Label normal_sequence;
4780 if (mode == DONT_OVERRIDE) {
4781 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4782 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4783 STATIC_ASSERT(FAST_ELEMENTS == 2);
4784 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4785 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4786 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4788 // is the low bit set? If so, we are holey and that is good.
4789 __ tst(r3, Operand(1));
4790 __ b(ne, &normal_sequence);
4793 // look at the first argument
4794 __ ldr(r5, MemOperand(sp, 0));
4795 __ cmp(r5, Operand::Zero());
4796 __ b(eq, &normal_sequence);
4798 if (mode == DISABLE_ALLOCATION_SITES) {
4799 ElementsKind initial = GetInitialFastElementsKind();
4800 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4802 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4804 DISABLE_ALLOCATION_SITES);
4805 __ TailCallStub(&stub_holey);
4807 __ bind(&normal_sequence);
4808 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4810 DISABLE_ALLOCATION_SITES);
4811 __ TailCallStub(&stub);
4812 } else if (mode == DONT_OVERRIDE) {
4813 // We are going to create a holey array, but our kind is non-holey.
4814 // Fix kind and retry (only if we have an allocation site in the slot).
4815 __ add(r3, r3, Operand(1));
4817 if (FLAG_debug_code) {
4818 __ ldr(r5, FieldMemOperand(r2, 0));
4819 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4820 __ Assert(eq, kExpectedAllocationSite);
4823 // Save the resulting elements kind in type info. We can't just store r3
4824 // in the AllocationSite::transition_info field because elements kind is
4825 // restricted to a portion of the field...upper bits need to be left alone.
4826 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4827 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4828 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4829 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4831 __ bind(&normal_sequence);
4832 int last_index = GetSequenceIndexFromFastElementsKind(
4833 TERMINAL_FAST_ELEMENTS_KIND);
4834 for (int i = 0; i <= last_index; ++i) {
4835 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4836 __ cmp(r3, Operand(kind));
4837 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4838 __ TailCallStub(&stub, eq);
4841 // If we reached this point there is a problem.
4842 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4850 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4851 int to_index = GetSequenceIndexFromFastElementsKind(
4852 TERMINAL_FAST_ELEMENTS_KIND);
4853 for (int i = 0; i <= to_index; ++i) {
4854 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4855 T stub(isolate, kind);
4857 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4858 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4865 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4866 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4868 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4870 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4875 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4877 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4878 for (int i = 0; i < 2; i++) {
4879 // For internal arrays we only need a few things
4880 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4882 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4884 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4890 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4891 MacroAssembler* masm,
4892 AllocationSiteOverrideMode mode) {
4893 if (argument_count() == ANY) {
4894 Label not_zero_case, not_one_case;
4896 __ b(ne, ¬_zero_case);
4897 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4899 __ bind(¬_zero_case);
4900 __ cmp(r0, Operand(1));
4901 __ b(gt, ¬_one_case);
4902 CreateArrayDispatchOneArgument(masm, mode);
4904 __ bind(¬_one_case);
4905 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4906 } else if (argument_count() == NONE) {
4907 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4908 } else if (argument_count() == ONE) {
4909 CreateArrayDispatchOneArgument(masm, mode);
4910 } else if (argument_count() == MORE_THAN_ONE) {
4911 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4918 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4919 // ----------- S t a t e -------------
4920 // -- r0 : argc (only if argument_count() == ANY)
4921 // -- r1 : constructor
4922 // -- r2 : AllocationSite or undefined
4923 // -- r3 : original constructor
4924 // -- sp[0] : return address
4925 // -- sp[4] : last argument
4926 // -----------------------------------
4928 if (FLAG_debug_code) {
4929 // The array construct code is only set for the global and natives
4930 // builtin Array functions which always have maps.
4932 // Initial map for the builtin Array function should be a map.
4933 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4934 // Will both indicate a NULL and a Smi.
4935 __ tst(r4, Operand(kSmiTagMask));
4936 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4937 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4938 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4940 // We should either have undefined in r2 or a valid AllocationSite
4941 __ AssertUndefinedOrAllocationSite(r2, r4);
4946 __ b(ne, &subclassing);
4949 // Get the elements kind and case on that.
4950 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4953 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4955 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4956 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4957 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4960 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4962 __ bind(&subclassing);
4967 switch (argument_count()) {
4970 __ add(r0, r0, Operand(2));
4973 __ mov(r0, Operand(2));
4976 __ mov(r0, Operand(3));
4980 __ JumpToExternalReference(
4981 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
4985 void InternalArrayConstructorStub::GenerateCase(
4986 MacroAssembler* masm, ElementsKind kind) {
4987 __ cmp(r0, Operand(1));
4989 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4990 __ TailCallStub(&stub0, lo);
4992 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4993 __ TailCallStub(&stubN, hi);
4995 if (IsFastPackedElementsKind(kind)) {
4996 // We might need to create a holey array
4997 // look at the first argument
4998 __ ldr(r3, MemOperand(sp, 0));
4999 __ cmp(r3, Operand::Zero());
5001 InternalArraySingleArgumentConstructorStub
5002 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5003 __ TailCallStub(&stub1_holey, ne);
5006 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5007 __ TailCallStub(&stub1);
5011 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5012 // ----------- S t a t e -------------
5014 // -- r1 : constructor
5015 // -- sp[0] : return address
5016 // -- sp[4] : last argument
5017 // -----------------------------------
5019 if (FLAG_debug_code) {
5020 // The array construct code is only set for the global and natives
5021 // builtin Array functions which always have maps.
5023 // Initial map for the builtin Array function should be a map.
5024 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5025 // Will both indicate a NULL and a Smi.
5026 __ tst(r3, Operand(kSmiTagMask));
5027 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5028 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
5029 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5032 // Figure out the right elements kind
5033 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5034 // Load the map's "bit field 2" into |result|. We only need the first byte,
5035 // but the following bit field extraction takes care of that anyway.
5036 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
5037 // Retrieve elements_kind from bit field 2.
5038 __ DecodeField<Map::ElementsKindBits>(r3);
5040 if (FLAG_debug_code) {
5042 __ cmp(r3, Operand(FAST_ELEMENTS));
5044 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
5046 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5050 Label fast_elements_case;
5051 __ cmp(r3, Operand(FAST_ELEMENTS));
5052 __ b(eq, &fast_elements_case);
5053 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5055 __ bind(&fast_elements_case);
5056 GenerateCase(masm, FAST_ELEMENTS);
5060 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5061 return ref0.address() - ref1.address();
5065 // Calls an API function. Allocates HandleScope, extracts returned value
5066 // from handle and propagates exceptions. Restores context. stack_space
5067 // - space to be unwound on exit (includes the call JS arguments space and
5068 // the additional space allocated for the fast call).
5069 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5070 Register function_address,
5071 ExternalReference thunk_ref,
5073 MemOperand* stack_space_operand,
5074 MemOperand return_value_operand,
5075 MemOperand* context_restore_operand) {
5076 Isolate* isolate = masm->isolate();
5077 ExternalReference next_address =
5078 ExternalReference::handle_scope_next_address(isolate);
5079 const int kNextOffset = 0;
5080 const int kLimitOffset = AddressOffset(
5081 ExternalReference::handle_scope_limit_address(isolate), next_address);
5082 const int kLevelOffset = AddressOffset(
5083 ExternalReference::handle_scope_level_address(isolate), next_address);
5085 DCHECK(function_address.is(r1) || function_address.is(r2));
5087 Label profiler_disabled;
5088 Label end_profiler_check;
5089 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5090 __ ldrb(r9, MemOperand(r9, 0));
5091 __ cmp(r9, Operand(0));
5092 __ b(eq, &profiler_disabled);
5094 // Additional parameter is the address of the actual callback.
5095 __ mov(r3, Operand(thunk_ref));
5096 __ jmp(&end_profiler_check);
5098 __ bind(&profiler_disabled);
5099 __ Move(r3, function_address);
5100 __ bind(&end_profiler_check);
5102 // Allocate HandleScope in callee-save registers.
5103 __ mov(r9, Operand(next_address));
5104 __ ldr(r4, MemOperand(r9, kNextOffset));
5105 __ ldr(r5, MemOperand(r9, kLimitOffset));
5106 __ ldr(r6, MemOperand(r9, kLevelOffset));
5107 __ add(r6, r6, Operand(1));
5108 __ str(r6, MemOperand(r9, kLevelOffset));
5110 if (FLAG_log_timer_events) {
5111 FrameScope frame(masm, StackFrame::MANUAL);
5112 __ PushSafepointRegisters();
5113 __ PrepareCallCFunction(1, r0);
5114 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5115 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5117 __ PopSafepointRegisters();
5120 // Native call returns to the DirectCEntry stub which redirects to the
5121 // return address pushed on stack (could have moved after GC).
5122 // DirectCEntry stub itself is generated early and never moves.
5123 DirectCEntryStub stub(isolate);
5124 stub.GenerateCall(masm, r3);
5126 if (FLAG_log_timer_events) {
5127 FrameScope frame(masm, StackFrame::MANUAL);
5128 __ PushSafepointRegisters();
5129 __ PrepareCallCFunction(1, r0);
5130 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5131 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5133 __ PopSafepointRegisters();
5136 Label promote_scheduled_exception;
5137 Label delete_allocated_handles;
5138 Label leave_exit_frame;
5139 Label return_value_loaded;
5141 // load value from ReturnValue
5142 __ ldr(r0, return_value_operand);
5143 __ bind(&return_value_loaded);
5144 // No more valid handles (the result handle was the last one). Restore
5145 // previous handle scope.
5146 __ str(r4, MemOperand(r9, kNextOffset));
5147 if (__ emit_debug_code()) {
5148 __ ldr(r1, MemOperand(r9, kLevelOffset));
5150 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5152 __ sub(r6, r6, Operand(1));
5153 __ str(r6, MemOperand(r9, kLevelOffset));
5154 __ ldr(ip, MemOperand(r9, kLimitOffset));
5156 __ b(ne, &delete_allocated_handles);
5158 // Leave the API exit frame.
5159 __ bind(&leave_exit_frame);
5160 bool restore_context = context_restore_operand != NULL;
5161 if (restore_context) {
5162 __ ldr(cp, *context_restore_operand);
5164 // LeaveExitFrame expects unwind space to be in a register.
5165 if (stack_space_operand != NULL) {
5166 __ ldr(r4, *stack_space_operand);
5168 __ mov(r4, Operand(stack_space));
5170 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5172 // Check if the function scheduled an exception.
5173 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5174 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5175 __ ldr(r5, MemOperand(ip));
5177 __ b(ne, &promote_scheduled_exception);
5181 // Re-throw by promoting a scheduled exception.
5182 __ bind(&promote_scheduled_exception);
5183 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5185 // HandleScope limit has changed. Delete allocated extensions.
5186 __ bind(&delete_allocated_handles);
5187 __ str(r5, MemOperand(r9, kLimitOffset));
5189 __ PrepareCallCFunction(1, r5);
5190 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5191 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5194 __ jmp(&leave_exit_frame);
5198 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5199 const ParameterCount& argc,
5200 bool return_first_arg,
5201 bool call_data_undefined) {
5202 // ----------- S t a t e -------------
5204 // -- r4 : call_data
5206 // -- r1 : api_function_address
5207 // -- r3 : number of arguments if argc is a register
5210 // -- sp[0] : last argument
5212 // -- sp[(argc - 1)* 4] : first argument
5213 // -- sp[argc * 4] : receiver
5214 // -----------------------------------
5216 Register callee = r0;
5217 Register call_data = r4;
5218 Register holder = r2;
5219 Register api_function_address = r1;
5220 Register context = cp;
5222 typedef FunctionCallbackArguments FCA;
5224 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5225 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5226 STATIC_ASSERT(FCA::kDataIndex == 4);
5227 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5228 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5229 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5230 STATIC_ASSERT(FCA::kHolderIndex == 0);
5231 STATIC_ASSERT(FCA::kArgsLength == 7);
5233 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5237 // load context from callee
5238 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5246 Register scratch = call_data;
5247 if (!call_data_undefined) {
5248 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5252 // return value default
5255 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5260 // Prepare arguments.
5261 __ mov(scratch, sp);
5263 // Allocate the v8::Arguments structure in the arguments' space since
5264 // it's not controlled by GC.
5265 const int kApiStackSpace = 4;
5267 FrameScope frame_scope(masm, StackFrame::MANUAL);
5268 __ EnterExitFrame(false, kApiStackSpace);
5270 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5271 // r0 = FunctionCallbackInfo&
5272 // Arguments is after the return address.
5273 __ add(r0, sp, Operand(1 * kPointerSize));
5274 // FunctionCallbackInfo::implicit_args_
5275 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
5276 if (argc.is_immediate()) {
5277 // FunctionCallbackInfo::values_
5279 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5280 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5281 // FunctionCallbackInfo::length_ = argc
5282 __ mov(ip, Operand(argc.immediate()));
5283 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5284 // FunctionCallbackInfo::is_construct_call_ = 0
5285 __ mov(ip, Operand::Zero());
5286 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5288 // FunctionCallbackInfo::values_
5289 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5290 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5291 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5292 // FunctionCallbackInfo::length_ = argc
5293 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5294 // FunctionCallbackInfo::is_construct_call_
5295 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5296 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5297 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5300 ExternalReference thunk_ref =
5301 ExternalReference::invoke_function_callback(masm->isolate());
5303 AllowExternalCallThatCantCauseGC scope(masm);
5304 MemOperand context_restore_operand(
5305 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5306 // Stores return the first js argument
5307 int return_value_offset = 0;
5308 if (return_first_arg) {
5309 return_value_offset = 2 + FCA::kArgsLength;
5311 return_value_offset = 2 + FCA::kReturnValueOffset;
5313 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5314 int stack_space = 0;
5315 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5316 MemOperand* stack_space_operand = &is_construct_call_operand;
5317 if (argc.is_immediate()) {
5318 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5319 stack_space_operand = NULL;
5321 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5322 stack_space_operand, return_value_operand,
5323 &context_restore_operand);
5327 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5328 bool call_data_undefined = this->call_data_undefined();
5329 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
5330 call_data_undefined);
5334 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5335 bool is_store = this->is_store();
5336 int argc = this->argc();
5337 bool call_data_undefined = this->call_data_undefined();
5338 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5339 call_data_undefined);
5343 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5344 // ----------- S t a t e -------------
5346 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5348 // -- r2 : api_function_address
5349 // -----------------------------------
5351 Register api_function_address = ApiGetterDescriptor::function_address();
5352 DCHECK(api_function_address.is(r2));
5354 __ mov(r0, sp); // r0 = Handle<Name>
5355 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
5357 const int kApiStackSpace = 1;
5358 FrameScope frame_scope(masm, StackFrame::MANUAL);
5359 __ EnterExitFrame(false, kApiStackSpace);
5361 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5362 // r1 (internal::Object** args_) as the data.
5363 __ str(r1, MemOperand(sp, 1 * kPointerSize));
5364 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
5366 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5368 ExternalReference thunk_ref =
5369 ExternalReference::invoke_accessor_getter_callback(isolate());
5370 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5371 kStackUnwindSpace, NULL,
5372 MemOperand(fp, 6 * kPointerSize), NULL);
5378 } // namespace internal
5381 #endif // V8_TARGET_ARCH_ARM