1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h"
11 #include "src/code-stubs.h"
12 #include "src/codegen.h"
13 #include "src/ic/handler-compiler.h"
14 #include "src/ic/ic.h"
15 #include "src/ic/stub-cache.h"
16 #include "src/isolate.h"
17 #include "src/jsregexp.h"
18 #include "src/regexp-macro-assembler.h"
19 #include "src/runtime/runtime.h"
25 static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
28 Address deopt_handler = Runtime::FunctionForId(
29 Runtime::kArrayConstructor)->entry;
31 if (constant_stack_parameter_count == 0) {
32 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
33 JS_FUNCTION_STUB_MODE);
35 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
36 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
41 static void InitializeInternalArrayConstructorDescriptor(
42 Isolate* isolate, CodeStubDescriptor* descriptor,
43 int constant_stack_parameter_count) {
44 Address deopt_handler = Runtime::FunctionForId(
45 Runtime::kInternalArrayConstructor)->entry;
47 if (constant_stack_parameter_count == 0) {
48 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
49 JS_FUNCTION_STUB_MODE);
51 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
52 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
57 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
63 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
64 CodeStubDescriptor* descriptor) {
65 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
69 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
70 CodeStubDescriptor* descriptor) {
71 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
75 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
76 CodeStubDescriptor* descriptor) {
77 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
81 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
82 CodeStubDescriptor* descriptor) {
83 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
87 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
88 CodeStubDescriptor* descriptor) {
89 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
93 #define __ ACCESS_MASM(masm)
96 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
97 Condition cond, Strength strength);
98 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
104 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
109 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
110 ExternalReference miss) {
111 // Update the static counter each time a new code stub is generated.
112 isolate()->counters()->code_stubs()->Increment();
114 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
115 int param_count = descriptor.GetRegisterParameterCount();
117 // Call the runtime system in a fresh internal frame.
118 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
119 DCHECK(param_count == 0 ||
120 r0.is(descriptor.GetRegisterParameter(param_count - 1)));
122 for (int i = 0; i < param_count; ++i) {
123 __ push(descriptor.GetRegisterParameter(i));
125 __ CallExternalReference(miss, param_count);
132 void DoubleToIStub::Generate(MacroAssembler* masm) {
133 Label out_of_range, only_low, negate, done;
134 Register input_reg = source();
135 Register result_reg = destination();
136 DCHECK(is_truncating());
138 int double_offset = offset();
139 // Account for saved regs if input is sp.
140 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
142 Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
143 Register scratch_low =
144 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
145 Register scratch_high =
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
147 LowDwVfpRegister double_scratch = kScratchDoubleReg;
149 __ Push(scratch_high, scratch_low, scratch);
151 if (!skip_fastpath()) {
152 // Load double input.
153 __ vldr(double_scratch, MemOperand(input_reg, double_offset));
154 __ vmov(scratch_low, scratch_high, double_scratch);
156 // Do fast-path convert from double to int.
157 __ vcvt_s32_f64(double_scratch.low(), double_scratch);
158 __ vmov(result_reg, double_scratch.low());
160 // If result is not saturated (0x7fffffff or 0x80000000), we are done.
161 __ sub(scratch, result_reg, Operand(1));
162 __ cmp(scratch, Operand(0x7ffffffe));
165 // We've already done MacroAssembler::TryFastTruncatedDoubleToILoad, so we
166 // know exponent > 31, so we can skip the vcvt_s32_f64 which will saturate.
167 if (double_offset == 0) {
168 __ ldm(ia, input_reg, scratch_low.bit() | scratch_high.bit());
170 __ ldr(scratch_low, MemOperand(input_reg, double_offset));
171 __ ldr(scratch_high, MemOperand(input_reg, double_offset + kIntSize));
175 __ Ubfx(scratch, scratch_high,
176 HeapNumber::kExponentShift, HeapNumber::kExponentBits);
177 // Load scratch with exponent - 1. This is faster than loading
178 // with exponent because Bias + 1 = 1024 which is an *ARM* immediate value.
179 STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
180 __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
181 // If exponent is greater than or equal to 84, the 32 less significant
182 // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
184 // Compare exponent with 84 (compare exponent - 1 with 83).
185 __ cmp(scratch, Operand(83));
186 __ b(ge, &out_of_range);
188 // If we reach this code, 31 <= exponent <= 83.
189 // So, we don't have to handle cases where 0 <= exponent <= 20 for
190 // which we would need to shift right the high part of the mantissa.
191 // Scratch contains exponent - 1.
192 // Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
193 __ rsb(scratch, scratch, Operand(51), SetCC);
195 // 21 <= exponent <= 51, shift scratch_low and scratch_high
196 // to generate the result.
197 __ mov(scratch_low, Operand(scratch_low, LSR, scratch));
198 // Scratch contains: 52 - exponent.
199 // We needs: exponent - 20.
200 // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
201 __ rsb(scratch, scratch, Operand(32));
202 __ Ubfx(result_reg, scratch_high,
203 0, HeapNumber::kMantissaBitsInTopWord);
204 // Set the implicit 1 before the mantissa part in scratch_high.
205 __ orr(result_reg, result_reg,
206 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
207 __ orr(result_reg, scratch_low, Operand(result_reg, LSL, scratch));
210 __ bind(&out_of_range);
211 __ mov(result_reg, Operand::Zero());
215 // 52 <= exponent <= 83, shift only scratch_low.
216 // On entry, scratch contains: 52 - exponent.
217 __ rsb(scratch, scratch, Operand::Zero());
218 __ mov(result_reg, Operand(scratch_low, LSL, scratch));
221 // If input was positive, scratch_high ASR 31 equals 0 and
222 // scratch_high LSR 31 equals zero.
223 // New result = (result eor 0) + 0 = result.
224 // If the input was negative, we have to negate the result.
225 // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
226 // New result = (result eor 0xffffffff) + 1 = 0 - result.
227 __ eor(result_reg, result_reg, Operand(scratch_high, ASR, 31));
228 __ add(result_reg, result_reg, Operand(scratch_high, LSR, 31));
232 __ Pop(scratch_high, scratch_low, scratch);
237 // Handle the case where the lhs and rhs are the same object.
238 // Equality is almost reflexive (everything but NaN), so this is a test
239 // for "identity and not NaN".
240 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
241 Condition cond, Strength strength) {
243 Label heap_number, return_equal;
245 __ b(ne, ¬_identical);
247 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
248 // so we do the second best thing - test it ourselves.
249 // They are both equal and they are not both Smis so both of them are not
250 // Smis. If it's not a heap number, then return equal.
251 if (cond == lt || cond == gt) {
252 // Call runtime on identical JSObjects.
253 __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE);
255 // Call runtime on identical symbols since we need to throw a TypeError.
256 __ cmp(r4, Operand(SYMBOL_TYPE));
258 // 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 __ TailCallExternalReference(
1841 ExternalReference(IC_Utility(IC::kLoadElementWithInterceptor),
1846 PropertyAccessCompiler::TailCallBuiltin(
1847 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1851 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1852 // sp[0] : number of parameters
1853 // sp[4] : receiver displacement
1855 // Check if the calling frame is an arguments adaptor frame.
1856 Label adaptor_frame, try_allocate, runtime;
1857 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1858 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1859 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1860 __ b(eq, &adaptor_frame);
1862 // Get the length from the frame.
1863 __ ldr(r1, MemOperand(sp, 0));
1864 __ b(&try_allocate);
1866 // Patch the arguments.length and the parameters pointer.
1867 __ bind(&adaptor_frame);
1868 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1869 __ str(r1, MemOperand(sp, 0));
1870 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1871 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1872 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1874 // Try the new space allocation. Start out with computing the size
1875 // of the arguments object and the elements array in words.
1876 Label add_arguments_object;
1877 __ bind(&try_allocate);
1878 __ SmiUntag(r1, SetCC);
1879 __ b(eq, &add_arguments_object);
1880 __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize));
1881 __ bind(&add_arguments_object);
1882 __ add(r1, r1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1884 // Do the allocation of both objects in one go.
1885 __ Allocate(r1, r0, r2, r3, &runtime,
1886 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1888 // Get the arguments boilerplate from the current native context.
1889 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1890 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1891 __ ldr(r4, MemOperand(
1892 r4, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1894 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1895 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1896 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1897 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
1899 // Get the length (smi tagged) and set that as an in-object property too.
1900 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1901 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1903 __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize +
1904 Heap::kArgumentsLengthIndex * kPointerSize));
1906 // If there are no actual arguments, we're done.
1908 __ cmp(r1, Operand::Zero());
1911 // Get the parameters pointer from the stack.
1912 __ ldr(r2, MemOperand(sp, 1 * kPointerSize));
1914 // Set up the elements pointer in the allocated arguments object and
1915 // initialize the header in the elements fixed array.
1916 __ add(r4, r0, Operand(Heap::kStrictArgumentsObjectSize));
1917 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1918 __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex);
1919 __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset));
1920 __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset));
1923 // Copy the fixed array slots.
1925 // Set up r4 to point to the first array slot.
1926 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1928 // Pre-decrement r2 with kPointerSize on each iteration.
1929 // Pre-decrement in order to skip receiver.
1930 __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
1931 // Post-increment r4 with kPointerSize on each iteration.
1932 __ str(r3, MemOperand(r4, kPointerSize, PostIndex));
1933 __ sub(r1, r1, Operand(1));
1934 __ cmp(r1, Operand::Zero());
1937 // Return and remove the on-stack parameters.
1939 __ add(sp, sp, Operand(3 * kPointerSize));
1942 // Do the runtime call to allocate the arguments object.
1944 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1948 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
1949 // Stack layout on entry.
1950 // sp[0] : language mode
1951 // sp[4] : index of rest parameter
1952 // sp[8] : number of parameters
1953 // sp[12] : receiver displacement
1956 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1957 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1958 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1961 // Patch the arguments.length and the parameters pointer.
1962 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1963 __ str(r1, MemOperand(sp, 2 * kPointerSize));
1964 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
1965 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1966 __ str(r3, MemOperand(sp, 3 * kPointerSize));
1969 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
1973 void RegExpExecStub::Generate(MacroAssembler* masm) {
1974 // Just jump directly to runtime if native RegExp is not selected at compile
1975 // time or if regexp entry in generated code is turned off runtime switch or
1977 #ifdef V8_INTERPRETED_REGEXP
1978 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1979 #else // V8_INTERPRETED_REGEXP
1981 // Stack frame on entry.
1982 // sp[0]: last_match_info (expected JSArray)
1983 // sp[4]: previous index
1984 // sp[8]: subject string
1985 // sp[12]: JSRegExp object
1987 const int kLastMatchInfoOffset = 0 * kPointerSize;
1988 const int kPreviousIndexOffset = 1 * kPointerSize;
1989 const int kSubjectOffset = 2 * kPointerSize;
1990 const int kJSRegExpOffset = 3 * kPointerSize;
1993 // Allocation of registers for this function. These are in callee save
1994 // registers and will be preserved by the call to the native RegExp code, as
1995 // this code is called using the normal C calling convention. When calling
1996 // directly from generated code the native RegExp code will not do a GC and
1997 // therefore the content of these registers are safe to use after the call.
1998 Register subject = r4;
1999 Register regexp_data = r5;
2000 Register last_match_info_elements = no_reg; // will be r6;
2002 // Ensure that a RegExp stack is allocated.
2003 ExternalReference address_of_regexp_stack_memory_address =
2004 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2005 ExternalReference address_of_regexp_stack_memory_size =
2006 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2007 __ mov(r0, Operand(address_of_regexp_stack_memory_size));
2008 __ ldr(r0, MemOperand(r0, 0));
2009 __ cmp(r0, Operand::Zero());
2012 // Check that the first argument is a JSRegExp object.
2013 __ ldr(r0, MemOperand(sp, kJSRegExpOffset));
2014 __ JumpIfSmi(r0, &runtime);
2015 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
2018 // Check that the RegExp has been compiled (data contains a fixed array).
2019 __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
2020 if (FLAG_debug_code) {
2021 __ SmiTst(regexp_data);
2022 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2023 __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
2024 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2027 // regexp_data: RegExp data (FixedArray)
2028 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2029 __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2030 __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2033 // regexp_data: RegExp data (FixedArray)
2034 // Check that the number of captures fit in the static offsets vector buffer.
2036 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2037 // Check (number_of_captures + 1) * 2 <= offsets vector size
2038 // Or number_of_captures * 2 <= offsets vector size - 2
2039 // Multiplying by 2 comes for free since r2 is smi-tagged.
2040 STATIC_ASSERT(kSmiTag == 0);
2041 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2042 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2043 __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2046 // Reset offset for possibly sliced string.
2047 __ mov(r9, Operand::Zero());
2048 __ ldr(subject, MemOperand(sp, kSubjectOffset));
2049 __ JumpIfSmi(subject, &runtime);
2050 __ mov(r3, subject); // Make a copy of the original subject string.
2051 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2052 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2053 // subject: subject string
2054 // r3: subject string
2055 // r0: subject string instance type
2056 // regexp_data: RegExp data (FixedArray)
2057 // Handle subject string according to its encoding and representation:
2058 // (1) Sequential string? If yes, go to (5).
2059 // (2) Anything but sequential or cons? If yes, go to (6).
2060 // (3) Cons string. If the string is flat, replace subject with first string.
2061 // Otherwise bailout.
2062 // (4) Is subject external? If yes, go to (7).
2063 // (5) Sequential string. Load regexp code according to encoding.
2067 // Deferred code at the end of the stub:
2068 // (6) Not a long external string? If yes, go to (8).
2069 // (7) External string. Make it, offset-wise, look like a sequential string.
2071 // (8) Short external string or not a string? If yes, bail out to runtime.
2072 // (9) Sliced string. Replace subject with parent. Go to (4).
2074 Label seq_string /* 5 */, external_string /* 7 */,
2075 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2076 not_long_external /* 8 */;
2078 // (1) Sequential string? If yes, go to (5).
2081 Operand(kIsNotStringMask |
2082 kStringRepresentationMask |
2083 kShortExternalStringMask),
2085 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2086 __ b(eq, &seq_string); // Go to (5).
2088 // (2) Anything but sequential or cons? If yes, go to (6).
2089 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2090 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2091 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2092 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2093 __ cmp(r1, Operand(kExternalStringTag));
2094 __ b(ge, ¬_seq_nor_cons); // Go to (6).
2096 // (3) Cons string. Check that it's flat.
2097 // Replace subject with first string and reload instance type.
2098 __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
2099 __ CompareRoot(r0, Heap::kempty_stringRootIndex);
2101 __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2103 // (4) Is subject external? If yes, go to (7).
2104 __ bind(&check_underlying);
2105 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2106 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2107 STATIC_ASSERT(kSeqStringTag == 0);
2108 __ tst(r0, Operand(kStringRepresentationMask));
2109 // The underlying external string is never a short external string.
2110 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2111 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2112 __ b(ne, &external_string); // Go to (7).
2114 // (5) Sequential string. Load regexp code according to encoding.
2115 __ bind(&seq_string);
2116 // subject: sequential subject string (or look-alike, external string)
2117 // r3: original subject string
2118 // Load previous index and check range before r3 is overwritten. We have to
2119 // use r3 instead of subject here because subject might have been only made
2120 // to look like a sequential string when it actually is an external string.
2121 __ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
2122 __ JumpIfNotSmi(r1, &runtime);
2123 __ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
2124 __ cmp(r3, Operand(r1));
2128 STATIC_ASSERT(4 == kOneByteStringTag);
2129 STATIC_ASSERT(kTwoByteStringTag == 0);
2130 __ and_(r0, r0, Operand(kStringEncodingMask));
2131 __ mov(r3, Operand(r0, ASR, 2), SetCC);
2132 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset),
2134 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
2136 // (E) Carry on. String handling is done.
2137 // r6: irregexp code
2138 // Check that the irregexp code has been generated for the actual string
2139 // encoding. If it has, the field contains a code object otherwise it contains
2140 // a smi (code flushing support).
2141 __ JumpIfSmi(r6, &runtime);
2143 // r1: previous index
2144 // r3: encoding of subject string (1 if one_byte, 0 if two_byte);
2146 // subject: Subject string
2147 // regexp_data: RegExp data (FixedArray)
2148 // All checks done. Now push arguments for native regexp code.
2149 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r0, r2);
2151 // Isolates: note we add an additional parameter here (isolate pointer).
2152 const int kRegExpExecuteArguments = 9;
2153 const int kParameterRegisters = 4;
2154 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2156 // Stack pointer now points to cell where return address is to be written.
2157 // Arguments are before that on the stack or in registers.
2159 // Argument 9 (sp[20]): Pass current isolate address.
2160 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2161 __ str(r0, MemOperand(sp, 5 * kPointerSize));
2163 // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
2164 __ mov(r0, Operand(1));
2165 __ str(r0, MemOperand(sp, 4 * kPointerSize));
2167 // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
2168 __ mov(r0, Operand(address_of_regexp_stack_memory_address));
2169 __ ldr(r0, MemOperand(r0, 0));
2170 __ mov(r2, Operand(address_of_regexp_stack_memory_size));
2171 __ ldr(r2, MemOperand(r2, 0));
2172 __ add(r0, r0, Operand(r2));
2173 __ str(r0, MemOperand(sp, 3 * kPointerSize));
2175 // Argument 6: Set the number of capture registers to zero to force global
2176 // regexps to behave as non-global. This does not affect non-global regexps.
2177 __ mov(r0, Operand::Zero());
2178 __ str(r0, MemOperand(sp, 2 * kPointerSize));
2180 // Argument 5 (sp[4]): static offsets vector buffer.
2182 Operand(ExternalReference::address_of_static_offsets_vector(
2184 __ str(r0, MemOperand(sp, 1 * kPointerSize));
2186 // For arguments 4 and 3 get string length, calculate start of string data and
2187 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2188 __ add(r7, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2189 __ eor(r3, r3, Operand(1));
2190 // Load the length from the original subject string from the previous stack
2191 // frame. Therefore we have to use fp, which points exactly to two pointer
2192 // sizes below the previous sp. (Because creating a new stack frame pushes
2193 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2194 __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2195 // If slice offset is not 0, load the length from the original sliced string.
2196 // Argument 4, r3: End of string data
2197 // Argument 3, r2: Start of string data
2198 // Prepare start and end index of the input.
2199 __ add(r9, r7, Operand(r9, LSL, r3));
2200 __ add(r2, r9, Operand(r1, LSL, r3));
2202 __ ldr(r7, FieldMemOperand(subject, String::kLengthOffset));
2204 __ add(r3, r9, Operand(r7, LSL, r3));
2206 // Argument 2 (r1): Previous index.
2209 // Argument 1 (r0): Subject string.
2210 __ mov(r0, subject);
2212 // Locate the code entry and call it.
2213 __ add(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
2214 DirectCEntryStub stub(isolate());
2215 stub.GenerateCall(masm, r6);
2217 __ LeaveExitFrame(false, no_reg, true);
2219 last_match_info_elements = r6;
2222 // subject: subject string (callee saved)
2223 // regexp_data: RegExp data (callee saved)
2224 // last_match_info_elements: Last match info elements (callee saved)
2225 // Check the result.
2227 __ cmp(r0, Operand(1));
2228 // We expect exactly one result since we force the called regexp to behave
2232 __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
2234 __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2235 // If not exception it can only be retry. Handle that in the runtime system.
2237 // Result must now be exception. If there is no pending exception already a
2238 // stack overflow (on the backtrack stack) was detected in RegExp code but
2239 // haven't created the exception yet. Handle that in the runtime system.
2240 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2241 __ mov(r1, Operand(isolate()->factory()->the_hole_value()));
2242 __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2244 __ ldr(r0, MemOperand(r2, 0));
2248 // For exception, throw the exception again.
2249 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2252 // For failure and exception return null.
2253 __ mov(r0, Operand(isolate()->factory()->null_value()));
2254 __ add(sp, sp, Operand(4 * kPointerSize));
2257 // Process the result from the native regexp code.
2260 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2261 // Calculate number of capture registers (number_of_captures + 1) * 2.
2262 // Multiplying by 2 comes for free since r1 is smi-tagged.
2263 STATIC_ASSERT(kSmiTag == 0);
2264 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2265 __ add(r1, r1, Operand(2)); // r1 was a smi.
2267 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2268 __ JumpIfSmi(r0, &runtime);
2269 __ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
2271 // Check that the JSArray is in fast case.
2272 __ ldr(last_match_info_elements,
2273 FieldMemOperand(r0, JSArray::kElementsOffset));
2274 __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2275 __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
2277 // Check that the last match info has space for the capture registers and the
2278 // additional information.
2280 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2281 __ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
2282 __ cmp(r2, Operand::SmiUntag(r0));
2285 // r1: number of capture registers
2286 // r4: subject string
2287 // Store the capture count.
2289 __ str(r2, FieldMemOperand(last_match_info_elements,
2290 RegExpImpl::kLastCaptureCountOffset));
2291 // Store last subject and last input.
2293 FieldMemOperand(last_match_info_elements,
2294 RegExpImpl::kLastSubjectOffset));
2295 __ mov(r2, subject);
2296 __ RecordWriteField(last_match_info_elements,
2297 RegExpImpl::kLastSubjectOffset,
2302 __ mov(subject, r2);
2304 FieldMemOperand(last_match_info_elements,
2305 RegExpImpl::kLastInputOffset));
2306 __ RecordWriteField(last_match_info_elements,
2307 RegExpImpl::kLastInputOffset,
2313 // Get the static offsets vector filled by the native regexp code.
2314 ExternalReference address_of_static_offsets_vector =
2315 ExternalReference::address_of_static_offsets_vector(isolate());
2316 __ mov(r2, Operand(address_of_static_offsets_vector));
2318 // r1: number of capture registers
2319 // r2: offsets vector
2320 Label next_capture, done;
2321 // Capture register counter starts from number of capture registers and
2322 // counts down until wraping after zero.
2324 last_match_info_elements,
2325 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2326 __ bind(&next_capture);
2327 __ sub(r1, r1, Operand(1), SetCC);
2329 // Read the value from the static offsets vector buffer.
2330 __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
2331 // Store the smi value in the last match info.
2333 __ str(r3, MemOperand(r0, kPointerSize, PostIndex));
2334 __ jmp(&next_capture);
2337 // Return last match info.
2338 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2339 __ add(sp, sp, Operand(4 * kPointerSize));
2342 // Do the runtime call to execute the regexp.
2344 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2346 // Deferred code for string handling.
2347 // (6) Not a long external string? If yes, go to (8).
2348 __ bind(¬_seq_nor_cons);
2349 // Compare flags are still set.
2350 __ b(gt, ¬_long_external); // Go to (8).
2352 // (7) External string. Make it, offset-wise, look like a sequential string.
2353 __ bind(&external_string);
2354 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2355 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2356 if (FLAG_debug_code) {
2357 // Assert that we do not have a cons or slice (indirect strings) here.
2358 // Sequential strings have already been ruled out.
2359 __ tst(r0, Operand(kIsIndirectStringMask));
2360 __ Assert(eq, kExternalStringExpectedButNotFound);
2363 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2364 // Move the pointer so that offset-wise, it looks like a sequential string.
2365 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2368 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2369 __ jmp(&seq_string); // Go to (5).
2371 // (8) Short external string or not a string? If yes, bail out to runtime.
2372 __ bind(¬_long_external);
2373 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2374 __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
2377 // (9) Sliced string. Replace subject with parent. Go to (4).
2378 // Load offset into r9 and replace subject string with parent.
2379 __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2381 __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2382 __ jmp(&check_underlying); // Go to (4).
2383 #endif // V8_INTERPRETED_REGEXP
2387 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
2388 // r0 : number of arguments to the construct function
2389 // r2 : Feedback vector
2390 // r3 : slot in feedback vector (Smi)
2391 // r1 : the function to call
2392 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2394 // Number-of-arguments register must be smi-tagged to call out.
2396 __ Push(r3, r2, r1, r0);
2400 __ Pop(r3, r2, r1, r0);
2405 static void GenerateRecordCallTarget(MacroAssembler* masm) {
2406 // Cache the called function in a feedback vector slot. Cache states
2407 // are uninitialized, monomorphic (indicated by a JSFunction), and
2409 // r0 : number of arguments to the construct function
2410 // r1 : the function to call
2411 // r2 : Feedback vector
2412 // r3 : slot in feedback vector (Smi)
2413 Label initialize, done, miss, megamorphic, not_array_function;
2415 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2416 masm->isolate()->heap()->megamorphic_symbol());
2417 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2418 masm->isolate()->heap()->uninitialized_symbol());
2420 // Load the cache state into r4.
2421 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2422 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2424 // A monomorphic cache hit or an already megamorphic state: invoke the
2425 // function without changing the state.
2426 // We don't know if r4 is a WeakCell or a Symbol, but it's harmless to read at
2427 // this position in a symbol (see static asserts in type-feedback-vector.h).
2428 Label check_allocation_site;
2429 Register feedback_map = r5;
2430 Register weak_value = r6;
2431 __ ldr(weak_value, FieldMemOperand(r4, WeakCell::kValueOffset));
2432 __ cmp(r1, weak_value);
2434 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2436 __ ldr(feedback_map, FieldMemOperand(r4, HeapObject::kMapOffset));
2437 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2438 __ b(ne, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2440 // If the weak cell is cleared, we have a new chance to become monomorphic.
2441 __ JumpIfSmi(weak_value, &initialize);
2442 __ jmp(&megamorphic);
2444 if (!FLAG_pretenuring_call_new) {
2445 __ bind(&check_allocation_site);
2446 // If we came here, we need to see if we are the array function.
2447 // If we didn't have a matching function, and we didn't find the megamorph
2448 // sentinel, then we have in the slot either some other function or an
2450 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
2453 // Make sure the function is the Array() function
2454 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2456 __ b(ne, &megamorphic);
2462 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2464 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2465 __ b(eq, &initialize);
2466 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2467 // write-barrier is needed.
2468 __ bind(&megamorphic);
2469 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2470 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2471 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2474 // An uninitialized cache is patched with the function
2475 __ bind(&initialize);
2477 if (!FLAG_pretenuring_call_new) {
2478 // Make sure the function is the Array() function
2479 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2481 __ b(ne, ¬_array_function);
2483 // The target function is the Array constructor,
2484 // Create an AllocationSite if we don't already have it, store it in the
2486 CreateAllocationSiteStub create_stub(masm->isolate());
2487 CallStubInRecordCallTarget(masm, &create_stub);
2490 __ bind(¬_array_function);
2493 CreateWeakCellStub create_stub(masm->isolate());
2494 CallStubInRecordCallTarget(masm, &create_stub);
2499 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2500 // Do not transform the receiver for strict mode functions.
2501 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2502 __ ldr(r4, FieldMemOperand(r3, SharedFunctionInfo::kCompilerHintsOffset));
2503 __ tst(r4, Operand(1 << (SharedFunctionInfo::kStrictModeFunction +
2507 // Do not transform the receiver for native (Compilerhints already in r3).
2508 __ tst(r4, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
2513 static void EmitSlowCase(MacroAssembler* masm,
2515 Label* non_function) {
2516 // Check for function proxy.
2517 __ cmp(r4, Operand(JS_FUNCTION_PROXY_TYPE));
2518 __ b(ne, non_function);
2519 __ push(r1); // put proxy as additional argument
2520 __ mov(r0, Operand(argc + 1, RelocInfo::NONE32));
2521 __ mov(r2, Operand::Zero());
2522 __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY);
2524 Handle<Code> adaptor =
2525 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2526 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2529 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2530 // of the original receiver from the call site).
2531 __ bind(non_function);
2532 __ str(r1, MemOperand(sp, argc * kPointerSize));
2533 __ mov(r0, Operand(argc)); // Set up the number of arguments.
2534 __ mov(r2, Operand::Zero());
2535 __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION);
2536 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2537 RelocInfo::CODE_TARGET);
2541 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2542 // Wrap the receiver and patch it back onto the stack.
2543 { FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2545 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2548 __ str(r0, MemOperand(sp, argc * kPointerSize));
2553 static void CallFunctionNoFeedback(MacroAssembler* masm,
2554 int argc, bool needs_checks,
2555 bool call_as_method) {
2556 // r1 : the function to call
2557 Label slow, non_function, wrap, cont;
2560 // Check that the function is really a JavaScript function.
2561 // r1: pushed function (to be verified)
2562 __ JumpIfSmi(r1, &non_function);
2564 // Goto slow case if we do not have a function.
2565 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2569 // Fast-case: Invoke the function now.
2570 // r1: pushed function
2571 ParameterCount actual(argc);
2573 if (call_as_method) {
2575 EmitContinueIfStrictOrNative(masm, &cont);
2578 // Compute the receiver in sloppy mode.
2579 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2582 __ JumpIfSmi(r3, &wrap);
2583 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2592 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2595 // Slow-case: Non-function called.
2597 EmitSlowCase(masm, argc, &non_function);
2600 if (call_as_method) {
2602 EmitWrapCase(masm, argc, &cont);
2607 void CallFunctionStub::Generate(MacroAssembler* masm) {
2608 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2612 void CallConstructStub::Generate(MacroAssembler* masm) {
2613 // r0 : number of arguments
2614 // r1 : the function to call
2615 // r2 : feedback vector
2616 // r3 : slot in feedback vector (Smi, for RecordCallTarget)
2617 // r4 : original constructor (for IsSuperConstructorCall)
2618 Label slow, non_function_call;
2620 // Check that the function is not a smi.
2621 __ JumpIfSmi(r1, &non_function_call);
2622 // Check that the function is a JSFunction.
2623 __ CompareObjectType(r1, r5, r5, JS_FUNCTION_TYPE);
2626 if (RecordCallTarget()) {
2627 if (IsSuperConstructorCall()) {
2630 // TODO(mstarzinger): Consider tweaking target recording to avoid push/pop.
2631 GenerateRecordCallTarget(masm);
2632 if (IsSuperConstructorCall()) {
2636 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2637 if (FLAG_pretenuring_call_new) {
2638 // Put the AllocationSite from the feedback vector into r2.
2639 // By adding kPointerSize we encode that we know the AllocationSite
2640 // entry is at the feedback vector slot given by r3 + 1.
2641 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize + kPointerSize));
2643 Label feedback_register_initialized;
2644 // Put the AllocationSite from the feedback vector into r2, or undefined.
2645 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2646 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2647 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2648 __ b(eq, &feedback_register_initialized);
2649 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2650 __ bind(&feedback_register_initialized);
2653 __ AssertUndefinedOrAllocationSite(r2, r5);
2656 // Pass function as original constructor.
2657 if (IsSuperConstructorCall()) {
2663 // Jump to the function-specific construct stub.
2664 Register jmp_reg = r4;
2665 __ ldr(jmp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2666 __ ldr(jmp_reg, FieldMemOperand(jmp_reg,
2667 SharedFunctionInfo::kConstructStubOffset));
2668 __ add(pc, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2670 // r0: number of arguments
2671 // r1: called object
2675 __ cmp(r5, Operand(JS_FUNCTION_PROXY_TYPE));
2676 __ b(ne, &non_function_call);
2677 __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2680 __ bind(&non_function_call);
2681 __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2683 // Set expected number of arguments to zero (not changing r0).
2684 __ mov(r2, Operand::Zero());
2685 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2686 RelocInfo::CODE_TARGET);
2690 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2691 __ ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2692 __ ldr(vector, FieldMemOperand(vector,
2693 JSFunction::kSharedFunctionInfoOffset));
2694 __ ldr(vector, FieldMemOperand(vector,
2695 SharedFunctionInfo::kFeedbackVectorOffset));
2699 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2704 int argc = arg_count();
2705 ParameterCount actual(argc);
2707 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2711 __ mov(r0, Operand(arg_count()));
2712 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2713 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2715 // Verify that r4 contains an AllocationSite
2716 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2717 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2720 // Increment the call count for monomorphic function calls.
2721 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2722 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2723 __ ldr(r3, FieldMemOperand(r2, 0));
2724 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2725 __ str(r3, FieldMemOperand(r2, 0));
2729 ArrayConstructorStub stub(masm->isolate(), arg_count());
2730 __ TailCallStub(&stub);
2735 // The slow case, we need this no matter what to complete a call after a miss.
2736 CallFunctionNoFeedback(masm,
2742 __ stop("Unexpected code address");
2746 void CallICStub::Generate(MacroAssembler* masm) {
2748 // r3 - slot id (Smi)
2750 const int with_types_offset =
2751 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2752 const int generic_offset =
2753 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2754 Label extra_checks_or_miss, slow_start;
2755 Label slow, non_function, wrap, cont;
2756 Label have_js_function;
2757 int argc = arg_count();
2758 ParameterCount actual(argc);
2760 // The checks. First, does r1 match the recorded monomorphic target?
2761 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2762 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2764 // We don't know that we have a weak cell. We might have a private symbol
2765 // or an AllocationSite, but the memory is safe to examine.
2766 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2768 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2769 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2770 // computed, meaning that it can't appear to be a pointer. If the low bit is
2771 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2773 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2774 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2775 WeakCell::kValueOffset &&
2776 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2778 __ ldr(r5, FieldMemOperand(r4, WeakCell::kValueOffset));
2780 __ b(ne, &extra_checks_or_miss);
2782 // The compare above could have been a SMI/SMI comparison. Guard against this
2783 // convincing us that we have a monomorphic JSFunction.
2784 __ JumpIfSmi(r1, &extra_checks_or_miss);
2786 // Increment the call count for monomorphic function calls.
2787 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2788 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2789 __ ldr(r3, FieldMemOperand(r2, 0));
2790 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2791 __ str(r3, FieldMemOperand(r2, 0));
2793 __ bind(&have_js_function);
2794 if (CallAsMethod()) {
2795 EmitContinueIfStrictOrNative(masm, &cont);
2796 // Compute the receiver in sloppy mode.
2797 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2799 __ JumpIfSmi(r3, &wrap);
2800 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2806 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2809 EmitSlowCase(masm, argc, &non_function);
2811 if (CallAsMethod()) {
2813 EmitWrapCase(masm, argc, &cont);
2816 __ bind(&extra_checks_or_miss);
2817 Label uninitialized, miss;
2819 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
2820 __ b(eq, &slow_start);
2822 // The following cases attempt to handle MISS cases without going to the
2824 if (FLAG_trace_ic) {
2828 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2829 __ b(eq, &uninitialized);
2831 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2832 // to handle it here. More complex cases are dealt with in the runtime.
2833 __ AssertNotSmi(r4);
2834 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2836 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2837 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2838 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2839 // We have to update statistics for runtime profiling.
2840 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2841 __ sub(r4, r4, Operand(Smi::FromInt(1)));
2842 __ str(r4, FieldMemOperand(r2, with_types_offset));
2843 __ ldr(r4, FieldMemOperand(r2, generic_offset));
2844 __ add(r4, r4, Operand(Smi::FromInt(1)));
2845 __ str(r4, FieldMemOperand(r2, generic_offset));
2846 __ jmp(&slow_start);
2848 __ bind(&uninitialized);
2850 // We are going monomorphic, provided we actually have a JSFunction.
2851 __ JumpIfSmi(r1, &miss);
2853 // Goto miss case if we do not have a function.
2854 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2857 // Make sure the function is not the Array() function, which requires special
2858 // behavior on MISS.
2859 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2864 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2865 __ add(r4, r4, Operand(Smi::FromInt(1)));
2866 __ str(r4, FieldMemOperand(r2, with_types_offset));
2868 // Initialize the call counter.
2869 __ Move(r5, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2870 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2871 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + kPointerSize));
2873 // Store the function. Use a stub since we need a frame for allocation.
2878 FrameScope scope(masm, StackFrame::INTERNAL);
2879 CreateWeakCellStub create_stub(masm->isolate());
2881 __ CallStub(&create_stub);
2885 __ jmp(&have_js_function);
2887 // We are here because tracing is on or we encountered a MISS case we can't
2893 __ bind(&slow_start);
2894 // Check that the function is really a JavaScript function.
2895 // r1: pushed function (to be verified)
2896 __ JumpIfSmi(r1, &non_function);
2898 // Goto slow case if we do not have a function.
2899 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2901 __ jmp(&have_js_function);
2905 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2906 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2908 // Push the receiver and the function and feedback info.
2909 __ Push(r1, r2, r3);
2912 IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
2913 : IC::kCallIC_Customization_Miss;
2915 ExternalReference miss = ExternalReference(IC_Utility(id), masm->isolate());
2916 __ CallExternalReference(miss, 3);
2918 // Move result to edi and exit the internal frame.
2923 // StringCharCodeAtGenerator
2924 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2925 // If the receiver is a smi trigger the non-string case.
2926 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2927 __ JumpIfSmi(object_, receiver_not_string_);
2929 // Fetch the instance type of the receiver into result register.
2930 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2931 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2932 // If the receiver is not a string trigger the non-string case.
2933 __ tst(result_, Operand(kIsNotStringMask));
2934 __ b(ne, receiver_not_string_);
2937 // If the index is non-smi trigger the non-smi case.
2938 __ JumpIfNotSmi(index_, &index_not_smi_);
2939 __ bind(&got_smi_index_);
2941 // Check for index out of range.
2942 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
2943 __ cmp(ip, Operand(index_));
2944 __ b(ls, index_out_of_range_);
2946 __ SmiUntag(index_);
2948 StringCharLoadGenerator::Generate(masm,
2959 void StringCharCodeAtGenerator::GenerateSlow(
2960 MacroAssembler* masm, EmbedMode embed_mode,
2961 const RuntimeCallHelper& call_helper) {
2962 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2964 // Index is not a smi.
2965 __ bind(&index_not_smi_);
2966 // If index is a heap number, try converting it to an integer.
2969 Heap::kHeapNumberMapRootIndex,
2972 call_helper.BeforeCall(masm);
2973 if (embed_mode == PART_OF_IC_HANDLER) {
2974 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2975 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2977 // index_ is consumed by runtime conversion function.
2978 __ Push(object_, index_);
2980 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2981 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2983 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2984 // NumberToSmi discards numbers that are not exact integers.
2985 __ CallRuntime(Runtime::kNumberToSmi, 1);
2987 // Save the conversion result before the pop instructions below
2988 // have a chance to overwrite it.
2989 __ Move(index_, r0);
2990 if (embed_mode == PART_OF_IC_HANDLER) {
2991 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2992 LoadWithVectorDescriptor::SlotRegister(), object_);
2996 // Reload the instance type.
2997 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2998 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2999 call_helper.AfterCall(masm);
3000 // If index is still not a smi, it must be out of range.
3001 __ JumpIfNotSmi(index_, index_out_of_range_);
3002 // Otherwise, return to the fast path.
3003 __ jmp(&got_smi_index_);
3005 // Call runtime. We get here when the receiver is a string and the
3006 // index is a number, but the code of getting the actual character
3007 // is too complex (e.g., when the string needs to be flattened).
3008 __ bind(&call_runtime_);
3009 call_helper.BeforeCall(masm);
3011 __ Push(object_, index_);
3012 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3013 __ Move(result_, r0);
3014 call_helper.AfterCall(masm);
3017 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3021 // -------------------------------------------------------------------------
3022 // StringCharFromCodeGenerator
3024 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3025 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3026 STATIC_ASSERT(kSmiTag == 0);
3027 STATIC_ASSERT(kSmiShiftSize == 0);
3028 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3029 __ tst(code_, Operand(kSmiTagMask |
3030 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3031 __ b(ne, &slow_case_);
3033 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3034 // At this point code register contains smi tagged one-byte char code.
3035 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
3036 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3037 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
3038 __ b(eq, &slow_case_);
3043 void StringCharFromCodeGenerator::GenerateSlow(
3044 MacroAssembler* masm,
3045 const RuntimeCallHelper& call_helper) {
3046 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3048 __ bind(&slow_case_);
3049 call_helper.BeforeCall(masm);
3051 __ CallRuntime(Runtime::kCharFromCode, 1);
3052 __ Move(result_, r0);
3053 call_helper.AfterCall(masm);
3056 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3060 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3063 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3068 String::Encoding encoding) {
3069 if (FLAG_debug_code) {
3070 // Check that destination is word aligned.
3071 __ tst(dest, Operand(kPointerAlignmentMask));
3072 __ Check(eq, kDestinationOfCopyNotAligned);
3075 // Assumes word reads and writes are little endian.
3076 // Nothing to do for zero characters.
3078 if (encoding == String::TWO_BYTE_ENCODING) {
3079 __ add(count, count, Operand(count), SetCC);
3082 Register limit = count; // Read until dest equals this.
3083 __ add(limit, dest, Operand(count));
3085 Label loop_entry, loop;
3086 // Copy bytes from src to dest until dest hits limit.
3089 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
3090 __ strb(scratch, MemOperand(dest, 1, PostIndex));
3091 __ bind(&loop_entry);
3092 __ cmp(dest, Operand(limit));
3099 void SubStringStub::Generate(MacroAssembler* masm) {
3102 // Stack frame on entry.
3103 // lr: return address
3108 // This stub is called from the native-call %_SubString(...), so
3109 // nothing can be assumed about the arguments. It is tested that:
3110 // "string" is a sequential string,
3111 // both "from" and "to" are smis, and
3112 // 0 <= from <= to <= string.length.
3113 // If any of these assumptions fail, we call the runtime system.
3115 const int kToOffset = 0 * kPointerSize;
3116 const int kFromOffset = 1 * kPointerSize;
3117 const int kStringOffset = 2 * kPointerSize;
3119 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
3120 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3121 STATIC_ASSERT(kSmiTag == 0);
3122 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3124 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
3125 // instead because we bail out on non-smi values: ROR and ASR are equivalent
3126 // for smis but they set the flags in a way that's easier to optimize.
3127 __ mov(r2, Operand(r2, ROR, 1), SetCC);
3128 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
3129 // If either to or from had the smi tag bit set, then C is set now, and N
3130 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
3131 // We want to bailout to runtime here if From is negative. In that case, the
3132 // next instruction is not executed and we fall through to bailing out to
3134 // Executed if both r2 and r3 are untagged integers.
3135 __ sub(r2, r2, Operand(r3), SetCC, cc);
3136 // One of the above un-smis or the above SUB could have set N==1.
3137 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
3139 // Make sure first argument is a string.
3140 __ ldr(r0, MemOperand(sp, kStringOffset));
3141 __ JumpIfSmi(r0, &runtime);
3142 Condition is_string = masm->IsObjectStringType(r0, r1);
3143 __ b(NegateCondition(is_string), &runtime);
3146 __ cmp(r2, Operand(1));
3147 __ b(eq, &single_char);
3149 // Short-cut for the case of trivial substring.
3151 // r0: original string
3152 // r2: result string length
3153 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
3154 __ cmp(r2, Operand(r4, ASR, 1));
3155 // Return original string.
3156 __ b(eq, &return_r0);
3157 // Longer than original string's length or negative: unsafe arguments.
3159 // Shorter than original string's length: an actual substring.
3161 // Deal with different string types: update the index if necessary
3162 // and put the underlying string into r5.
3163 // r0: original string
3164 // r1: instance type
3166 // r3: from index (untagged)
3167 Label underlying_unpacked, sliced_string, seq_or_external_string;
3168 // If the string is not indirect, it can only be sequential or external.
3169 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3170 STATIC_ASSERT(kIsIndirectStringMask != 0);
3171 __ tst(r1, Operand(kIsIndirectStringMask));
3172 __ b(eq, &seq_or_external_string);
3174 __ tst(r1, Operand(kSlicedNotConsMask));
3175 __ b(ne, &sliced_string);
3176 // Cons string. Check whether it is flat, then fetch first part.
3177 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
3178 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
3180 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
3181 // Update instance type.
3182 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3183 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3184 __ jmp(&underlying_unpacked);
3186 __ bind(&sliced_string);
3187 // Sliced string. Fetch parent and correct start index by offset.
3188 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3189 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3190 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
3191 // Update instance type.
3192 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3193 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3194 __ jmp(&underlying_unpacked);
3196 __ bind(&seq_or_external_string);
3197 // Sequential or external string. Just move string to the expected register.
3200 __ bind(&underlying_unpacked);
3202 if (FLAG_string_slices) {
3204 // r5: underlying subject string
3205 // r1: instance type of underlying subject string
3207 // r3: adjusted start index (untagged)
3208 __ cmp(r2, Operand(SlicedString::kMinLength));
3209 // Short slice. Copy instead of slicing.
3210 __ b(lt, ©_routine);
3211 // Allocate new sliced string. At this point we do not reload the instance
3212 // type including the string encoding because we simply rely on the info
3213 // provided by the original string. It does not matter if the original
3214 // string's encoding is wrong because we always have to recheck encoding of
3215 // the newly created string's parent anyways due to externalized strings.
3216 Label two_byte_slice, set_slice_header;
3217 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3218 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3219 __ tst(r1, Operand(kStringEncodingMask));
3220 __ b(eq, &two_byte_slice);
3221 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
3222 __ jmp(&set_slice_header);
3223 __ bind(&two_byte_slice);
3224 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
3225 __ bind(&set_slice_header);
3226 __ mov(r3, Operand(r3, LSL, 1));
3227 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3228 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3231 __ bind(©_routine);
3234 // r5: underlying subject string
3235 // r1: instance type of underlying subject string
3237 // r3: adjusted start index (untagged)
3238 Label two_byte_sequential, sequential_string, allocate_result;
3239 STATIC_ASSERT(kExternalStringTag != 0);
3240 STATIC_ASSERT(kSeqStringTag == 0);
3241 __ tst(r1, Operand(kExternalStringTag));
3242 __ b(eq, &sequential_string);
3244 // Handle external string.
3245 // Rule out short external strings.
3246 STATIC_ASSERT(kShortExternalStringTag != 0);
3247 __ tst(r1, Operand(kShortExternalStringTag));
3249 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
3250 // r5 already points to the first character of underlying string.
3251 __ jmp(&allocate_result);
3253 __ bind(&sequential_string);
3254 // Locate first character of underlying subject string.
3255 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3256 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3258 __ bind(&allocate_result);
3259 // Sequential acii string. Allocate the result.
3260 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3261 __ tst(r1, Operand(kStringEncodingMask));
3262 __ b(eq, &two_byte_sequential);
3264 // Allocate and copy the resulting one-byte string.
3265 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
3267 // Locate first character of substring to copy.
3269 // Locate first character of result.
3270 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3272 // r0: result string
3273 // r1: first character of result string
3274 // r2: result string length
3275 // r5: first character of substring to copy
3276 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3277 StringHelper::GenerateCopyCharacters(
3278 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
3281 // Allocate and copy the resulting two-byte string.
3282 __ bind(&two_byte_sequential);
3283 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
3285 // Locate first character of substring to copy.
3286 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3287 __ add(r5, r5, Operand(r3, LSL, 1));
3288 // Locate first character of result.
3289 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3291 // r0: result string.
3292 // r1: first character of result.
3293 // r2: result length.
3294 // r5: first character of substring to copy.
3295 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3296 StringHelper::GenerateCopyCharacters(
3297 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
3299 __ bind(&return_r0);
3300 Counters* counters = isolate()->counters();
3301 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
3305 // Just jump to runtime to create the sub string.
3307 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3309 __ bind(&single_char);
3310 // r0: original string
3311 // r1: instance type
3313 // r3: from index (untagged)
3315 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
3316 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3317 generator.GenerateFast(masm);
3320 generator.SkipSlow(masm, &runtime);
3324 void ToNumberStub::Generate(MacroAssembler* masm) {
3325 // The ToNumber stub takes one argument in r0.
3327 __ JumpIfNotSmi(r0, ¬_smi);
3331 Label not_heap_number;
3332 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
3333 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3335 // r1: instance type.
3336 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
3337 __ b(ne, ¬_heap_number);
3339 __ bind(¬_heap_number);
3341 Label not_string, slow_string;
3342 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
3343 __ b(hs, ¬_string);
3344 // Check if string has a cached array index.
3345 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
3346 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
3347 __ b(ne, &slow_string);
3348 __ IndexFromHash(r2, r0);
3350 __ bind(&slow_string);
3351 __ push(r0); // Push argument.
3352 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3353 __ bind(¬_string);
3356 __ cmp(r1, Operand(ODDBALL_TYPE));
3357 __ b(ne, ¬_oddball);
3358 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
3360 __ bind(¬_oddball);
3362 __ push(r0); // Push argument.
3363 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3367 void StringHelper::GenerateFlatOneByteStringEquals(
3368 MacroAssembler* masm, Register left, Register right, Register scratch1,
3369 Register scratch2, Register scratch3) {
3370 Register length = scratch1;
3373 Label strings_not_equal, check_zero_length;
3374 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
3375 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3376 __ cmp(length, scratch2);
3377 __ b(eq, &check_zero_length);
3378 __ bind(&strings_not_equal);
3379 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
3382 // Check if the length is zero.
3383 Label compare_chars;
3384 __ bind(&check_zero_length);
3385 STATIC_ASSERT(kSmiTag == 0);
3386 __ cmp(length, Operand::Zero());
3387 __ b(ne, &compare_chars);
3388 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3391 // Compare characters.
3392 __ bind(&compare_chars);
3393 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3394 &strings_not_equal);
3396 // Characters are equal.
3397 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3402 void StringHelper::GenerateCompareFlatOneByteStrings(
3403 MacroAssembler* masm, Register left, Register right, Register scratch1,
3404 Register scratch2, Register scratch3, Register scratch4) {
3405 Label result_not_equal, compare_lengths;
3406 // Find minimum length and length difference.
3407 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3408 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3409 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
3410 Register length_delta = scratch3;
3411 __ mov(scratch1, scratch2, LeaveCC, gt);
3412 Register min_length = scratch1;
3413 STATIC_ASSERT(kSmiTag == 0);
3414 __ cmp(min_length, Operand::Zero());
3415 __ b(eq, &compare_lengths);
3418 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3419 scratch4, &result_not_equal);
3421 // Compare lengths - strings up to min-length are equal.
3422 __ bind(&compare_lengths);
3423 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3424 // Use length_delta as result if it's zero.
3425 __ mov(r0, Operand(length_delta), SetCC);
3426 __ bind(&result_not_equal);
3427 // Conditionally update the result based either on length_delta or
3428 // the last comparion performed in the loop above.
3429 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
3430 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
3435 void StringHelper::GenerateOneByteCharsCompareLoop(
3436 MacroAssembler* masm, Register left, Register right, Register length,
3437 Register scratch1, Register scratch2, Label* chars_not_equal) {
3438 // Change index to run from -length to -1 by adding length to string
3439 // start. This means that loop ends when index reaches zero, which
3440 // doesn't need an additional compare.
3441 __ SmiUntag(length);
3442 __ add(scratch1, length,
3443 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3444 __ add(left, left, Operand(scratch1));
3445 __ add(right, right, Operand(scratch1));
3446 __ rsb(length, length, Operand::Zero());
3447 Register index = length; // index = -length;
3452 __ ldrb(scratch1, MemOperand(left, index));
3453 __ ldrb(scratch2, MemOperand(right, index));
3454 __ cmp(scratch1, scratch2);
3455 __ b(ne, chars_not_equal);
3456 __ add(index, index, Operand(1), SetCC);
3461 void StringCompareStub::Generate(MacroAssembler* masm) {
3464 Counters* counters = isolate()->counters();
3466 // Stack frame on entry.
3467 // sp[0]: right string
3468 // sp[4]: left string
3469 __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1.
3473 __ b(ne, ¬_same);
3474 STATIC_ASSERT(EQUAL == 0);
3475 STATIC_ASSERT(kSmiTag == 0);
3476 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3477 __ IncrementCounter(counters->string_compare_native(), 1, r1, r2);
3478 __ add(sp, sp, Operand(2 * kPointerSize));
3483 // Check that both objects are sequential one-byte strings.
3484 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
3486 // Compare flat one-byte strings natively. Remove arguments from stack first.
3487 __ IncrementCounter(counters->string_compare_native(), 1, r2, r3);
3488 __ add(sp, sp, Operand(2 * kPointerSize));
3489 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
3491 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3492 // tagged as a small integer.
3494 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3498 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3499 // ----------- S t a t e -------------
3502 // -- lr : return address
3503 // -----------------------------------
3505 // Load r2 with the allocation site. We stick an undefined dummy value here
3506 // and replace it with the real allocation site later when we instantiate this
3507 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3508 __ Move(r2, handle(isolate()->heap()->undefined_value()));
3510 // Make sure that we actually patched the allocation site.
3511 if (FLAG_debug_code) {
3512 __ tst(r2, Operand(kSmiTagMask));
3513 __ Assert(ne, kExpectedAllocationSite);
3515 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3516 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3519 __ Assert(eq, kExpectedAllocationSite);
3522 // Tail call into the stub that handles binary operations with allocation
3524 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3525 __ TailCallStub(&stub);
3529 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3530 DCHECK(state() == CompareICState::SMI);
3533 __ JumpIfNotSmi(r2, &miss);
3535 if (GetCondition() == eq) {
3536 // For equality we do not care about the sign of the result.
3537 __ sub(r0, r0, r1, SetCC);
3539 // Untag before subtracting to avoid handling overflow.
3541 __ sub(r0, r1, Operand::SmiUntag(r0));
3550 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3551 DCHECK(state() == CompareICState::NUMBER);
3554 Label unordered, maybe_undefined1, maybe_undefined2;
3557 if (left() == CompareICState::SMI) {
3558 __ JumpIfNotSmi(r1, &miss);
3560 if (right() == CompareICState::SMI) {
3561 __ JumpIfNotSmi(r0, &miss);
3564 // Inlining the double comparison and falling back to the general compare
3565 // stub if NaN is involved.
3566 // Load left and right operand.
3567 Label done, left, left_smi, right_smi;
3568 __ JumpIfSmi(r0, &right_smi);
3569 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3571 __ sub(r2, r0, Operand(kHeapObjectTag));
3572 __ vldr(d1, r2, HeapNumber::kValueOffset);
3574 __ bind(&right_smi);
3575 __ SmiToDouble(d1, r0);
3578 __ JumpIfSmi(r1, &left_smi);
3579 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3581 __ sub(r2, r1, Operand(kHeapObjectTag));
3582 __ vldr(d0, r2, HeapNumber::kValueOffset);
3585 __ SmiToDouble(d0, r1);
3588 // Compare operands.
3589 __ VFPCompareAndSetFlags(d0, d1);
3591 // Don't base result on status bits when a NaN is involved.
3592 __ b(vs, &unordered);
3594 // Return a result of -1, 0, or 1, based on status bits.
3595 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
3596 __ mov(r0, Operand(LESS), LeaveCC, lt);
3597 __ mov(r0, Operand(GREATER), LeaveCC, gt);
3600 __ bind(&unordered);
3601 __ bind(&generic_stub);
3602 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3603 CompareICState::GENERIC, CompareICState::GENERIC);
3604 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3606 __ bind(&maybe_undefined1);
3607 if (Token::IsOrderedRelationalCompareOp(op())) {
3608 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3610 __ JumpIfSmi(r1, &unordered);
3611 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3612 __ b(ne, &maybe_undefined2);
3616 __ bind(&maybe_undefined2);
3617 if (Token::IsOrderedRelationalCompareOp(op())) {
3618 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3619 __ b(eq, &unordered);
3627 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3628 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3631 // Registers containing left and right operands respectively.
3633 Register right = r0;
3637 // Check that both operands are heap objects.
3638 __ JumpIfEitherSmi(left, right, &miss);
3640 // Check that both operands are internalized strings.
3641 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3642 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3643 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3644 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3645 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3646 __ orr(tmp1, tmp1, Operand(tmp2));
3647 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3650 // Internalized strings are compared by identity.
3651 __ cmp(left, right);
3652 // Make sure r0 is non-zero. At this point input operands are
3653 // guaranteed to be non-zero.
3654 DCHECK(right.is(r0));
3655 STATIC_ASSERT(EQUAL == 0);
3656 STATIC_ASSERT(kSmiTag == 0);
3657 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3665 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3666 DCHECK(state() == CompareICState::UNIQUE_NAME);
3667 DCHECK(GetCondition() == eq);
3670 // Registers containing left and right operands respectively.
3672 Register right = r0;
3676 // Check that both operands are heap objects.
3677 __ JumpIfEitherSmi(left, right, &miss);
3679 // Check that both operands are unique names. This leaves the instance
3680 // types loaded in tmp1 and tmp2.
3681 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3682 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3683 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3684 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3686 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3687 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3689 // Unique names are compared by identity.
3690 __ cmp(left, right);
3691 // Make sure r0 is non-zero. At this point input operands are
3692 // guaranteed to be non-zero.
3693 DCHECK(right.is(r0));
3694 STATIC_ASSERT(EQUAL == 0);
3695 STATIC_ASSERT(kSmiTag == 0);
3696 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3704 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3705 DCHECK(state() == CompareICState::STRING);
3708 bool equality = Token::IsEqualityOp(op());
3710 // Registers containing left and right operands respectively.
3712 Register right = r0;
3718 // Check that both operands are heap objects.
3719 __ JumpIfEitherSmi(left, right, &miss);
3721 // Check that both operands are strings. This leaves the instance
3722 // types loaded in tmp1 and tmp2.
3723 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3724 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3725 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3726 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3727 STATIC_ASSERT(kNotStringTag != 0);
3728 __ orr(tmp3, tmp1, tmp2);
3729 __ tst(tmp3, Operand(kIsNotStringMask));
3732 // Fast check for identical strings.
3733 __ cmp(left, right);
3734 STATIC_ASSERT(EQUAL == 0);
3735 STATIC_ASSERT(kSmiTag == 0);
3736 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3739 // Handle not identical strings.
3741 // Check that both strings are internalized strings. If they are, we're done
3742 // because we already know they are not identical. We know they are both
3745 DCHECK(GetCondition() == eq);
3746 STATIC_ASSERT(kInternalizedTag == 0);
3747 __ orr(tmp3, tmp1, Operand(tmp2));
3748 __ tst(tmp3, Operand(kIsNotInternalizedMask));
3749 // Make sure r0 is non-zero. At this point input operands are
3750 // guaranteed to be non-zero.
3751 DCHECK(right.is(r0));
3755 // Check that both strings are sequential one-byte.
3757 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3760 // Compare flat one-byte strings. Returns when done.
3762 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3765 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3769 // Handle more complex cases in runtime.
3771 __ Push(left, right);
3773 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3775 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3783 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3784 DCHECK(state() == CompareICState::OBJECT);
3786 __ and_(r2, r1, Operand(r0));
3787 __ JumpIfSmi(r2, &miss);
3789 __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
3791 __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
3794 DCHECK(GetCondition() == eq);
3795 __ sub(r0, r0, Operand(r1));
3803 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3805 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3806 __ and_(r2, r1, Operand(r0));
3807 __ JumpIfSmi(r2, &miss);
3808 __ GetWeakValue(r4, cell);
3809 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3810 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
3816 __ sub(r0, r0, Operand(r1));
3824 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3826 // Call the runtime system in a fresh internal frame.
3827 ExternalReference miss =
3828 ExternalReference(IC_Utility(IC::kCompareIC_Miss), isolate());
3830 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
3832 __ Push(lr, r1, r0);
3833 __ mov(ip, Operand(Smi::FromInt(op())));
3835 __ CallExternalReference(miss, 3);
3836 // Compute the entry point of the rewritten stub.
3837 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3838 // Restore registers.
3847 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3848 // Place the return address on the stack, making the call
3849 // GC safe. The RegExp backend also relies on this.
3850 __ str(lr, MemOperand(sp, 0));
3851 __ blx(ip); // Call the C++ function.
3852 __ VFPEnsureFPSCRState(r2);
3853 __ ldr(pc, MemOperand(sp, 0));
3857 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3860 reinterpret_cast<intptr_t>(GetCode().location());
3861 __ Move(ip, target);
3862 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3863 __ blx(lr); // Call the stub.
3867 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3871 Register properties,
3873 Register scratch0) {
3874 DCHECK(name->IsUniqueName());
3875 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3876 // not equal to the name and kProbes-th slot is not used (its name is the
3877 // undefined value), it guarantees the hash table doesn't contain the
3878 // property. It's true even if some slots represent deleted properties
3879 // (their names are the hole value).
3880 for (int i = 0; i < kInlinedProbes; i++) {
3881 // scratch0 points to properties hash.
3882 // Compute the masked index: (hash + i + i * i) & mask.
3883 Register index = scratch0;
3884 // Capacity is smi 2^n.
3885 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3886 __ sub(index, index, Operand(1));
3887 __ and_(index, index, Operand(
3888 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3890 // Scale the index by multiplying by the entry size.
3891 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3892 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3894 Register entity_name = scratch0;
3895 // Having undefined at this place means the name is not contained.
3896 DCHECK_EQ(kSmiTagSize, 1);
3897 Register tmp = properties;
3898 __ add(tmp, properties, Operand(index, LSL, 1));
3899 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3901 DCHECK(!tmp.is(entity_name));
3902 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3903 __ cmp(entity_name, tmp);
3906 // Load the hole ready for use below:
3907 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3909 // Stop if found the property.
3910 __ cmp(entity_name, Operand(Handle<Name>(name)));
3914 __ cmp(entity_name, tmp);
3917 // Check if the entry name is not a unique name.
3918 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3919 __ ldrb(entity_name,
3920 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3921 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3924 // Restore the properties.
3926 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3929 const int spill_mask =
3930 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3931 r2.bit() | r1.bit() | r0.bit());
3933 __ stm(db_w, sp, spill_mask);
3934 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3935 __ mov(r1, Operand(Handle<Name>(name)));
3936 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3938 __ cmp(r0, Operand::Zero());
3939 __ ldm(ia_w, sp, spill_mask);
3946 // Probe the name dictionary in the |elements| register. Jump to the
3947 // |done| label if a property with the given name is found. Jump to
3948 // the |miss| label otherwise.
3949 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
3950 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3956 Register scratch2) {
3957 DCHECK(!elements.is(scratch1));
3958 DCHECK(!elements.is(scratch2));
3959 DCHECK(!name.is(scratch1));
3960 DCHECK(!name.is(scratch2));
3962 __ AssertName(name);
3964 // Compute the capacity mask.
3965 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
3966 __ SmiUntag(scratch1);
3967 __ sub(scratch1, scratch1, Operand(1));
3969 // Generate an unrolled loop that performs a few probes before
3970 // giving up. Measurements done on Gmail indicate that 2 probes
3971 // cover ~93% of loads from dictionaries.
3972 for (int i = 0; i < kInlinedProbes; i++) {
3973 // Compute the masked index: (hash + i + i * i) & mask.
3974 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3976 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3977 // the hash in a separate instruction. The value hash + i + i * i is right
3978 // shifted in the following and instruction.
3979 DCHECK(NameDictionary::GetProbeOffset(i) <
3980 1 << (32 - Name::kHashFieldOffset));
3981 __ add(scratch2, scratch2, Operand(
3982 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3984 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
3986 // Scale the index by multiplying by the element size.
3987 DCHECK(NameDictionary::kEntrySize == 3);
3988 // scratch2 = scratch2 * 3.
3989 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3991 // Check if the key is identical to the name.
3992 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3993 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3994 __ cmp(name, Operand(ip));
3998 const int spill_mask =
3999 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
4000 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
4001 ~(scratch1.bit() | scratch2.bit());
4003 __ stm(db_w, sp, spill_mask);
4005 DCHECK(!elements.is(r1));
4007 __ Move(r0, elements);
4009 __ Move(r0, elements);
4012 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4014 __ cmp(r0, Operand::Zero());
4015 __ mov(scratch2, Operand(r2));
4016 __ ldm(ia_w, sp, spill_mask);
4023 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4024 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4025 // we cannot call anything that could cause a GC from this stub.
4027 // result: NameDictionary to probe
4029 // dictionary: NameDictionary to probe.
4030 // index: will hold an index of entry if lookup is successful.
4031 // might alias with result_.
4033 // result_ is zero if lookup failed, non zero otherwise.
4035 Register result = r0;
4036 Register dictionary = r0;
4038 Register index = r2;
4041 Register undefined = r5;
4042 Register entry_key = r6;
4044 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4046 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
4048 __ sub(mask, mask, Operand(1));
4050 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4052 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4054 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4055 // Compute the masked index: (hash + i + i * i) & mask.
4056 // Capacity is smi 2^n.
4058 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4059 // the hash in a separate instruction. The value hash + i + i * i is right
4060 // shifted in the following and instruction.
4061 DCHECK(NameDictionary::GetProbeOffset(i) <
4062 1 << (32 - Name::kHashFieldOffset));
4063 __ add(index, hash, Operand(
4064 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4066 __ mov(index, Operand(hash));
4068 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
4070 // Scale the index by multiplying by the entry size.
4071 DCHECK(NameDictionary::kEntrySize == 3);
4072 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
4074 DCHECK_EQ(kSmiTagSize, 1);
4075 __ add(index, dictionary, Operand(index, LSL, 2));
4076 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
4078 // Having undefined at this place means the name is not contained.
4079 __ cmp(entry_key, Operand(undefined));
4080 __ b(eq, ¬_in_dictionary);
4082 // Stop if found the property.
4083 __ cmp(entry_key, Operand(key));
4084 __ b(eq, &in_dictionary);
4086 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4087 // Check if the entry name is not a unique name.
4088 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4090 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4091 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4095 __ bind(&maybe_in_dictionary);
4096 // If we are doing negative lookup then probing failure should be
4097 // treated as a lookup success. For positive lookup probing failure
4098 // should be treated as lookup failure.
4099 if (mode() == POSITIVE_LOOKUP) {
4100 __ mov(result, Operand::Zero());
4104 __ bind(&in_dictionary);
4105 __ mov(result, Operand(1));
4108 __ bind(¬_in_dictionary);
4109 __ mov(result, Operand::Zero());
4114 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4116 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4118 // Hydrogen code stubs need stub2 at snapshot time.
4119 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4124 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4125 // the value has just been written into the object, now this stub makes sure
4126 // we keep the GC informed. The word in the object where the value has been
4127 // written is in the address register.
4128 void RecordWriteStub::Generate(MacroAssembler* masm) {
4129 Label skip_to_incremental_noncompacting;
4130 Label skip_to_incremental_compacting;
4132 // The first two instructions are generated with labels so as to get the
4133 // offset fixed up correctly by the bind(Label*) call. We patch it back and
4134 // forth between a compare instructions (a nop in this position) and the
4135 // real branch when we start and stop incremental heap marking.
4136 // See RecordWriteStub::Patch for details.
4138 // Block literal pool emission, as the position of these two instructions
4139 // is assumed by the patching code.
4140 Assembler::BlockConstPoolScope block_const_pool(masm);
4141 __ b(&skip_to_incremental_noncompacting);
4142 __ b(&skip_to_incremental_compacting);
4145 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4146 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4147 MacroAssembler::kReturnAtEnd);
4151 __ bind(&skip_to_incremental_noncompacting);
4152 GenerateIncremental(masm, INCREMENTAL);
4154 __ bind(&skip_to_incremental_compacting);
4155 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4157 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4158 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4159 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4160 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
4161 PatchBranchIntoNop(masm, 0);
4162 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4166 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4169 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4170 Label dont_need_remembered_set;
4172 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4173 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4175 &dont_need_remembered_set);
4177 __ CheckPageFlag(regs_.object(),
4179 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4181 &dont_need_remembered_set);
4183 // First notify the incremental marker if necessary, then update the
4185 CheckNeedsToInformIncrementalMarker(
4186 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4187 InformIncrementalMarker(masm);
4188 regs_.Restore(masm);
4189 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4190 MacroAssembler::kReturnAtEnd);
4192 __ bind(&dont_need_remembered_set);
4195 CheckNeedsToInformIncrementalMarker(
4196 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4197 InformIncrementalMarker(masm);
4198 regs_.Restore(masm);
4203 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4204 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4205 int argument_count = 3;
4206 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4208 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4209 DCHECK(!address.is(regs_.object()));
4210 DCHECK(!address.is(r0));
4211 __ Move(address, regs_.address());
4212 __ Move(r0, regs_.object());
4213 __ Move(r1, address);
4214 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4216 AllowExternalCallThatCantCauseGC scope(masm);
4218 ExternalReference::incremental_marking_record_write_function(isolate()),
4220 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4224 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4225 MacroAssembler* masm,
4226 OnNoNeedToInformIncrementalMarker on_no_need,
4229 Label need_incremental;
4230 Label need_incremental_pop_scratch;
4232 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4233 __ ldr(regs_.scratch1(),
4234 MemOperand(regs_.scratch0(),
4235 MemoryChunk::kWriteBarrierCounterOffset));
4236 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4237 __ str(regs_.scratch1(),
4238 MemOperand(regs_.scratch0(),
4239 MemoryChunk::kWriteBarrierCounterOffset));
4240 __ b(mi, &need_incremental);
4242 // Let's look at the color of the object: If it is not black we don't have
4243 // to inform the incremental marker.
4244 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4246 regs_.Restore(masm);
4247 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4248 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4249 MacroAssembler::kReturnAtEnd);
4256 // Get the value from the slot.
4257 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4259 if (mode == INCREMENTAL_COMPACTION) {
4260 Label ensure_not_white;
4262 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4263 regs_.scratch1(), // Scratch.
4264 MemoryChunk::kEvacuationCandidateMask,
4268 __ CheckPageFlag(regs_.object(),
4269 regs_.scratch1(), // Scratch.
4270 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4274 __ bind(&ensure_not_white);
4277 // We need extra registers for this, so we push the object and the address
4278 // register temporarily.
4279 __ Push(regs_.object(), regs_.address());
4280 __ EnsureNotWhite(regs_.scratch0(), // The value.
4281 regs_.scratch1(), // Scratch.
4282 regs_.object(), // Scratch.
4283 regs_.address(), // Scratch.
4284 &need_incremental_pop_scratch);
4285 __ Pop(regs_.object(), regs_.address());
4287 regs_.Restore(masm);
4288 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4289 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
4290 MacroAssembler::kReturnAtEnd);
4295 __ bind(&need_incremental_pop_scratch);
4296 __ Pop(regs_.object(), regs_.address());
4298 __ bind(&need_incremental);
4300 // Fall through when we need to inform the incremental marker.
4304 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4305 // ----------- S t a t e -------------
4306 // -- r0 : element value to store
4307 // -- r3 : element index as smi
4308 // -- sp[0] : array literal index in function as smi
4309 // -- sp[4] : array literal
4310 // clobbers r1, r2, r4
4311 // -----------------------------------
4314 Label double_elements;
4316 Label slow_elements;
4317 Label fast_elements;
4319 // Get array literal index, array literal and its map.
4320 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4321 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4322 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4324 __ CheckFastElements(r2, r5, &double_elements);
4325 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
4326 __ JumpIfSmi(r0, &smi_element);
4327 __ CheckFastSmiElements(r2, r5, &fast_elements);
4329 // Store into the array literal requires a elements transition. Call into
4331 __ bind(&slow_elements);
4333 __ Push(r1, r3, r0);
4334 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4335 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4337 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4339 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4340 __ bind(&fast_elements);
4341 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4342 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4343 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4344 __ str(r0, MemOperand(r6, 0));
4345 // Update the write barrier for the array store.
4346 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4347 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4350 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4351 // and value is Smi.
4352 __ bind(&smi_element);
4353 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4354 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
4355 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4358 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4359 __ bind(&double_elements);
4360 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
4361 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
4366 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4367 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4368 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4369 int parameter_count_offset =
4370 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4371 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4372 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4373 __ add(r1, r1, Operand(1));
4375 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4376 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4382 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4383 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4384 LoadICStub stub(isolate(), state());
4385 stub.GenerateForTrampoline(masm);
4389 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4390 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4391 KeyedLoadICStub stub(isolate(), state());
4392 stub.GenerateForTrampoline(masm);
4396 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4397 EmitLoadTypeFeedbackVector(masm, r2);
4398 CallICStub stub(isolate(), state());
4399 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4403 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4404 EmitLoadTypeFeedbackVector(masm, r2);
4405 CallIC_ArrayStub stub(isolate(), state());
4406 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4410 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4413 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4414 GenerateImpl(masm, true);
4418 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4419 Register key, Register vector, Register slot,
4420 Register feedback, Register receiver_map,
4421 Register scratch1, Register scratch2,
4422 bool is_polymorphic, Label* miss) {
4423 // feedback initially contains the feedback array
4424 Label next_loop, prepare_next;
4425 Label start_polymorphic;
4427 Register cached_map = scratch1;
4430 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4431 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4432 __ cmp(receiver_map, cached_map);
4433 __ b(ne, &start_polymorphic);
4434 // found, now call handler.
4435 Register handler = feedback;
4436 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4437 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4440 Register length = scratch2;
4441 __ bind(&start_polymorphic);
4442 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4443 if (!is_polymorphic) {
4444 // If the IC could be monomorphic we have to make sure we don't go past the
4445 // end of the feedback array.
4446 __ cmp(length, Operand(Smi::FromInt(2)));
4450 Register too_far = length;
4451 Register pointer_reg = feedback;
4453 // +-----+------+------+-----+-----+ ... ----+
4454 // | map | len | wm0 | h0 | wm1 | hN |
4455 // +-----+------+------+-----+-----+ ... ----+
4459 // pointer_reg too_far
4460 // aka feedback scratch2
4461 // also need receiver_map
4462 // use cached_map (scratch1) to look in the weak map values.
4463 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
4464 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4465 __ add(pointer_reg, feedback,
4466 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4468 __ bind(&next_loop);
4469 __ ldr(cached_map, MemOperand(pointer_reg));
4470 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4471 __ cmp(receiver_map, cached_map);
4472 __ b(ne, &prepare_next);
4473 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
4474 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4476 __ bind(&prepare_next);
4477 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4478 __ cmp(pointer_reg, too_far);
4479 __ b(lt, &next_loop);
4481 // We exhausted our array of map handler pairs.
4486 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4487 Register receiver_map, Register feedback,
4488 Register vector, Register slot,
4489 Register scratch, Label* compare_map,
4490 Label* load_smi_map, Label* try_array) {
4491 __ JumpIfSmi(receiver, load_smi_map);
4492 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4493 __ bind(compare_map);
4494 Register cached_map = scratch;
4495 // Move the weak map into the weak_cell register.
4496 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4497 __ cmp(cached_map, receiver_map);
4498 __ b(ne, try_array);
4499 Register handler = feedback;
4500 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
4502 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4503 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4507 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4508 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4509 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
4510 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4511 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4512 Register feedback = r4;
4513 Register receiver_map = r5;
4514 Register scratch1 = r6;
4516 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4517 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4519 // Try to quickly handle the monomorphic case without knowing for sure
4520 // if we have a weak cell in feedback. We do know it's safe to look
4521 // at WeakCell::kValueOffset.
4522 Label try_array, load_smi_map, compare_map;
4523 Label not_array, miss;
4524 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4525 scratch1, &compare_map, &load_smi_map, &try_array);
4527 // Is it a fixed array?
4528 __ bind(&try_array);
4529 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4530 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4531 __ b(ne, ¬_array);
4532 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4533 scratch1, r9, true, &miss);
4535 __ bind(¬_array);
4536 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4538 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4539 Code::ComputeHandlerFlags(Code::LOAD_IC));
4540 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4541 false, receiver, name, feedback,
4542 receiver_map, scratch1, r9);
4545 LoadIC::GenerateMiss(masm);
4548 __ bind(&load_smi_map);
4549 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4550 __ jmp(&compare_map);
4554 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4555 GenerateImpl(masm, false);
4559 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4560 GenerateImpl(masm, true);
4564 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4565 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
4566 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
4567 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
4568 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
4569 Register feedback = r4;
4570 Register receiver_map = r5;
4571 Register scratch1 = r6;
4573 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4574 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4576 // Try to quickly handle the monomorphic case without knowing for sure
4577 // if we have a weak cell in feedback. We do know it's safe to look
4578 // at WeakCell::kValueOffset.
4579 Label try_array, load_smi_map, compare_map;
4580 Label not_array, miss;
4581 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4582 scratch1, &compare_map, &load_smi_map, &try_array);
4584 __ bind(&try_array);
4585 // Is it a fixed array?
4586 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4587 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4588 __ b(ne, ¬_array);
4590 // We have a polymorphic element handler.
4591 Label polymorphic, try_poly_name;
4592 __ bind(&polymorphic);
4593 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4594 scratch1, r9, true, &miss);
4596 __ bind(¬_array);
4598 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4599 __ b(ne, &try_poly_name);
4600 Handle<Code> megamorphic_stub =
4601 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4602 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4604 __ bind(&try_poly_name);
4605 // We might have a name in feedback, and a fixed array in the next slot.
4606 __ cmp(key, feedback);
4608 // If the name comparison succeeded, we know we have a fixed array with
4609 // at least one map/handler pair.
4610 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4612 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4613 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4614 scratch1, r9, false, &miss);
4617 KeyedLoadIC::GenerateMiss(masm);
4619 __ bind(&load_smi_map);
4620 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4621 __ jmp(&compare_map);
4625 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4626 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4627 VectorStoreICStub stub(isolate(), state());
4628 stub.GenerateForTrampoline(masm);
4632 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4633 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4634 VectorKeyedStoreICStub stub(isolate(), state());
4635 stub.GenerateForTrampoline(masm);
4639 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4640 GenerateImpl(masm, false);
4644 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4645 GenerateImpl(masm, true);
4649 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4652 // TODO(mvstanton): Implement.
4654 StoreIC::GenerateMiss(masm);
4658 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4659 GenerateImpl(masm, false);
4663 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4664 GenerateImpl(masm, true);
4668 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4671 // TODO(mvstanton): Implement.
4673 KeyedStoreIC::GenerateMiss(masm);
4677 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4678 if (masm->isolate()->function_entry_hook() != NULL) {
4679 ProfileEntryHookStub stub(masm->isolate());
4680 int code_size = masm->CallStubSize(&stub) + 2 * Assembler::kInstrSize;
4681 PredictableCodeSizeScope predictable(masm, code_size);
4689 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4690 // The entry hook is a "push lr" instruction, followed by a call.
4691 const int32_t kReturnAddressDistanceFromFunctionStart =
4692 3 * Assembler::kInstrSize;
4694 // This should contain all kCallerSaved registers.
4695 const RegList kSavedRegs =
4702 // We also save lr, so the count here is one higher than the mask indicates.
4703 const int32_t kNumSavedRegs = 7;
4705 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4707 // Save all caller-save registers as this may be called from anywhere.
4708 __ stm(db_w, sp, kSavedRegs | lr.bit());
4710 // Compute the function's address for the first argument.
4711 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4713 // The caller's return address is above the saved temporaries.
4714 // Grab that for the second argument to the hook.
4715 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4717 // Align the stack if necessary.
4718 int frame_alignment = masm->ActivationFrameAlignment();
4719 if (frame_alignment > kPointerSize) {
4721 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4722 __ and_(sp, sp, Operand(-frame_alignment));
4725 #if V8_HOST_ARCH_ARM
4726 int32_t entry_hook =
4727 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4728 __ mov(ip, Operand(entry_hook));
4730 // Under the simulator we need to indirect the entry hook through a
4731 // trampoline function at a known address.
4732 // It additionally takes an isolate as a third parameter
4733 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4735 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4736 __ mov(ip, Operand(ExternalReference(&dispatcher,
4737 ExternalReference::BUILTIN_CALL,
4742 // Restore the stack pointer if needed.
4743 if (frame_alignment > kPointerSize) {
4747 // Also pop pc to get Ret(0).
4748 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4753 static void CreateArrayDispatch(MacroAssembler* masm,
4754 AllocationSiteOverrideMode mode) {
4755 if (mode == DISABLE_ALLOCATION_SITES) {
4756 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4757 __ TailCallStub(&stub);
4758 } else if (mode == DONT_OVERRIDE) {
4759 int last_index = GetSequenceIndexFromFastElementsKind(
4760 TERMINAL_FAST_ELEMENTS_KIND);
4761 for (int i = 0; i <= last_index; ++i) {
4762 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4763 __ cmp(r3, Operand(kind));
4764 T stub(masm->isolate(), kind);
4765 __ TailCallStub(&stub, eq);
4768 // If we reached this point there is a problem.
4769 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4776 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4777 AllocationSiteOverrideMode mode) {
4778 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4779 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4780 // r0 - number of arguments
4781 // r1 - constructor?
4782 // sp[0] - last argument
4783 Label normal_sequence;
4784 if (mode == DONT_OVERRIDE) {
4785 DCHECK(FAST_SMI_ELEMENTS == 0);
4786 DCHECK(FAST_HOLEY_SMI_ELEMENTS == 1);
4787 DCHECK(FAST_ELEMENTS == 2);
4788 DCHECK(FAST_HOLEY_ELEMENTS == 3);
4789 DCHECK(FAST_DOUBLE_ELEMENTS == 4);
4790 DCHECK(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4792 // is the low bit set? If so, we are holey and that is good.
4793 __ tst(r3, Operand(1));
4794 __ b(ne, &normal_sequence);
4797 // look at the first argument
4798 __ ldr(r5, MemOperand(sp, 0));
4799 __ cmp(r5, Operand::Zero());
4800 __ b(eq, &normal_sequence);
4802 if (mode == DISABLE_ALLOCATION_SITES) {
4803 ElementsKind initial = GetInitialFastElementsKind();
4804 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4806 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4808 DISABLE_ALLOCATION_SITES);
4809 __ TailCallStub(&stub_holey);
4811 __ bind(&normal_sequence);
4812 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4814 DISABLE_ALLOCATION_SITES);
4815 __ TailCallStub(&stub);
4816 } else if (mode == DONT_OVERRIDE) {
4817 // We are going to create a holey array, but our kind is non-holey.
4818 // Fix kind and retry (only if we have an allocation site in the slot).
4819 __ add(r3, r3, Operand(1));
4821 if (FLAG_debug_code) {
4822 __ ldr(r5, FieldMemOperand(r2, 0));
4823 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4824 __ Assert(eq, kExpectedAllocationSite);
4827 // Save the resulting elements kind in type info. We can't just store r3
4828 // in the AllocationSite::transition_info field because elements kind is
4829 // restricted to a portion of the field...upper bits need to be left alone.
4830 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4831 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4832 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4833 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4835 __ bind(&normal_sequence);
4836 int last_index = GetSequenceIndexFromFastElementsKind(
4837 TERMINAL_FAST_ELEMENTS_KIND);
4838 for (int i = 0; i <= last_index; ++i) {
4839 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4840 __ cmp(r3, Operand(kind));
4841 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4842 __ TailCallStub(&stub, eq);
4845 // If we reached this point there is a problem.
4846 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4854 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4855 int to_index = GetSequenceIndexFromFastElementsKind(
4856 TERMINAL_FAST_ELEMENTS_KIND);
4857 for (int i = 0; i <= to_index; ++i) {
4858 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4859 T stub(isolate, kind);
4861 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4862 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4869 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4870 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4872 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4874 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4879 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4881 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4882 for (int i = 0; i < 2; i++) {
4883 // For internal arrays we only need a few things
4884 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4886 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4888 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4894 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4895 MacroAssembler* masm,
4896 AllocationSiteOverrideMode mode) {
4897 if (argument_count() == ANY) {
4898 Label not_zero_case, not_one_case;
4900 __ b(ne, ¬_zero_case);
4901 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4903 __ bind(¬_zero_case);
4904 __ cmp(r0, Operand(1));
4905 __ b(gt, ¬_one_case);
4906 CreateArrayDispatchOneArgument(masm, mode);
4908 __ bind(¬_one_case);
4909 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4910 } else if (argument_count() == NONE) {
4911 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4912 } else if (argument_count() == ONE) {
4913 CreateArrayDispatchOneArgument(masm, mode);
4914 } else if (argument_count() == MORE_THAN_ONE) {
4915 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4922 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4923 // ----------- S t a t e -------------
4924 // -- r0 : argc (only if argument_count() == ANY)
4925 // -- r1 : constructor
4926 // -- r2 : AllocationSite or undefined
4927 // -- r3 : original constructor
4928 // -- sp[0] : return address
4929 // -- sp[4] : last argument
4930 // -----------------------------------
4932 if (FLAG_debug_code) {
4933 // The array construct code is only set for the global and natives
4934 // builtin Array functions which always have maps.
4936 // Initial map for the builtin Array function should be a map.
4937 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4938 // Will both indicate a NULL and a Smi.
4939 __ tst(r4, Operand(kSmiTagMask));
4940 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4941 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4942 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4944 // We should either have undefined in r2 or a valid AllocationSite
4945 __ AssertUndefinedOrAllocationSite(r2, r4);
4950 __ b(ne, &subclassing);
4953 // Get the elements kind and case on that.
4954 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4957 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4959 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4960 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4961 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4964 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4966 __ bind(&subclassing);
4971 switch (argument_count()) {
4974 __ add(r0, r0, Operand(2));
4977 __ mov(r0, Operand(2));
4980 __ mov(r0, Operand(3));
4984 __ JumpToExternalReference(
4985 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
4989 void InternalArrayConstructorStub::GenerateCase(
4990 MacroAssembler* masm, ElementsKind kind) {
4991 __ cmp(r0, Operand(1));
4993 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4994 __ TailCallStub(&stub0, lo);
4996 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4997 __ TailCallStub(&stubN, hi);
4999 if (IsFastPackedElementsKind(kind)) {
5000 // We might need to create a holey array
5001 // look at the first argument
5002 __ ldr(r3, MemOperand(sp, 0));
5003 __ cmp(r3, Operand::Zero());
5005 InternalArraySingleArgumentConstructorStub
5006 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5007 __ TailCallStub(&stub1_holey, ne);
5010 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5011 __ TailCallStub(&stub1);
5015 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5016 // ----------- S t a t e -------------
5018 // -- r1 : constructor
5019 // -- sp[0] : return address
5020 // -- sp[4] : last argument
5021 // -----------------------------------
5023 if (FLAG_debug_code) {
5024 // The array construct code is only set for the global and natives
5025 // builtin Array functions which always have maps.
5027 // Initial map for the builtin Array function should be a map.
5028 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5029 // Will both indicate a NULL and a Smi.
5030 __ tst(r3, Operand(kSmiTagMask));
5031 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
5032 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
5033 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
5036 // Figure out the right elements kind
5037 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
5038 // Load the map's "bit field 2" into |result|. We only need the first byte,
5039 // but the following bit field extraction takes care of that anyway.
5040 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
5041 // Retrieve elements_kind from bit field 2.
5042 __ DecodeField<Map::ElementsKindBits>(r3);
5044 if (FLAG_debug_code) {
5046 __ cmp(r3, Operand(FAST_ELEMENTS));
5048 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
5050 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5054 Label fast_elements_case;
5055 __ cmp(r3, Operand(FAST_ELEMENTS));
5056 __ b(eq, &fast_elements_case);
5057 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5059 __ bind(&fast_elements_case);
5060 GenerateCase(masm, FAST_ELEMENTS);
5064 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5065 return ref0.address() - ref1.address();
5069 // Calls an API function. Allocates HandleScope, extracts returned value
5070 // from handle and propagates exceptions. Restores context. stack_space
5071 // - space to be unwound on exit (includes the call JS arguments space and
5072 // the additional space allocated for the fast call).
5073 static void CallApiFunctionAndReturn(MacroAssembler* masm,
5074 Register function_address,
5075 ExternalReference thunk_ref,
5077 MemOperand* stack_space_operand,
5078 MemOperand return_value_operand,
5079 MemOperand* context_restore_operand) {
5080 Isolate* isolate = masm->isolate();
5081 ExternalReference next_address =
5082 ExternalReference::handle_scope_next_address(isolate);
5083 const int kNextOffset = 0;
5084 const int kLimitOffset = AddressOffset(
5085 ExternalReference::handle_scope_limit_address(isolate), next_address);
5086 const int kLevelOffset = AddressOffset(
5087 ExternalReference::handle_scope_level_address(isolate), next_address);
5089 DCHECK(function_address.is(r1) || function_address.is(r2));
5091 Label profiler_disabled;
5092 Label end_profiler_check;
5093 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5094 __ ldrb(r9, MemOperand(r9, 0));
5095 __ cmp(r9, Operand(0));
5096 __ b(eq, &profiler_disabled);
5098 // Additional parameter is the address of the actual callback.
5099 __ mov(r3, Operand(thunk_ref));
5100 __ jmp(&end_profiler_check);
5102 __ bind(&profiler_disabled);
5103 __ Move(r3, function_address);
5104 __ bind(&end_profiler_check);
5106 // Allocate HandleScope in callee-save registers.
5107 __ mov(r9, Operand(next_address));
5108 __ ldr(r4, MemOperand(r9, kNextOffset));
5109 __ ldr(r5, MemOperand(r9, kLimitOffset));
5110 __ ldr(r6, MemOperand(r9, kLevelOffset));
5111 __ add(r6, r6, Operand(1));
5112 __ str(r6, MemOperand(r9, kLevelOffset));
5114 if (FLAG_log_timer_events) {
5115 FrameScope frame(masm, StackFrame::MANUAL);
5116 __ PushSafepointRegisters();
5117 __ PrepareCallCFunction(1, r0);
5118 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5119 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5121 __ PopSafepointRegisters();
5124 // Native call returns to the DirectCEntry stub which redirects to the
5125 // return address pushed on stack (could have moved after GC).
5126 // DirectCEntry stub itself is generated early and never moves.
5127 DirectCEntryStub stub(isolate);
5128 stub.GenerateCall(masm, r3);
5130 if (FLAG_log_timer_events) {
5131 FrameScope frame(masm, StackFrame::MANUAL);
5132 __ PushSafepointRegisters();
5133 __ PrepareCallCFunction(1, r0);
5134 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5135 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5137 __ PopSafepointRegisters();
5140 Label promote_scheduled_exception;
5141 Label delete_allocated_handles;
5142 Label leave_exit_frame;
5143 Label return_value_loaded;
5145 // load value from ReturnValue
5146 __ ldr(r0, return_value_operand);
5147 __ bind(&return_value_loaded);
5148 // No more valid handles (the result handle was the last one). Restore
5149 // previous handle scope.
5150 __ str(r4, MemOperand(r9, kNextOffset));
5151 if (__ emit_debug_code()) {
5152 __ ldr(r1, MemOperand(r9, kLevelOffset));
5154 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5156 __ sub(r6, r6, Operand(1));
5157 __ str(r6, MemOperand(r9, kLevelOffset));
5158 __ ldr(ip, MemOperand(r9, kLimitOffset));
5160 __ b(ne, &delete_allocated_handles);
5162 // Leave the API exit frame.
5163 __ bind(&leave_exit_frame);
5164 bool restore_context = context_restore_operand != NULL;
5165 if (restore_context) {
5166 __ ldr(cp, *context_restore_operand);
5168 // LeaveExitFrame expects unwind space to be in a register.
5169 if (stack_space_operand != NULL) {
5170 __ ldr(r4, *stack_space_operand);
5172 __ mov(r4, Operand(stack_space));
5174 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5176 // Check if the function scheduled an exception.
5177 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5178 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5179 __ ldr(r5, MemOperand(ip));
5181 __ b(ne, &promote_scheduled_exception);
5185 // Re-throw by promoting a scheduled exception.
5186 __ bind(&promote_scheduled_exception);
5187 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5189 // HandleScope limit has changed. Delete allocated extensions.
5190 __ bind(&delete_allocated_handles);
5191 __ str(r5, MemOperand(r9, kLimitOffset));
5193 __ PrepareCallCFunction(1, r5);
5194 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5195 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5198 __ jmp(&leave_exit_frame);
5202 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5203 const ParameterCount& argc,
5204 bool return_first_arg,
5205 bool call_data_undefined) {
5206 // ----------- S t a t e -------------
5208 // -- r4 : call_data
5210 // -- r1 : api_function_address
5211 // -- r3 : number of arguments if argc is a register
5214 // -- sp[0] : last argument
5216 // -- sp[(argc - 1)* 4] : first argument
5217 // -- sp[argc * 4] : receiver
5218 // -----------------------------------
5220 Register callee = r0;
5221 Register call_data = r4;
5222 Register holder = r2;
5223 Register api_function_address = r1;
5224 Register context = cp;
5226 typedef FunctionCallbackArguments FCA;
5228 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5229 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5230 STATIC_ASSERT(FCA::kDataIndex == 4);
5231 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5232 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5233 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5234 STATIC_ASSERT(FCA::kHolderIndex == 0);
5235 STATIC_ASSERT(FCA::kArgsLength == 7);
5237 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5241 // load context from callee
5242 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5250 Register scratch = call_data;
5251 if (!call_data_undefined) {
5252 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5256 // return value default
5259 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5264 // Prepare arguments.
5265 __ mov(scratch, sp);
5267 // Allocate the v8::Arguments structure in the arguments' space since
5268 // it's not controlled by GC.
5269 const int kApiStackSpace = 4;
5271 FrameScope frame_scope(masm, StackFrame::MANUAL);
5272 __ EnterExitFrame(false, kApiStackSpace);
5274 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5275 // r0 = FunctionCallbackInfo&
5276 // Arguments is after the return address.
5277 __ add(r0, sp, Operand(1 * kPointerSize));
5278 // FunctionCallbackInfo::implicit_args_
5279 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
5280 if (argc.is_immediate()) {
5281 // FunctionCallbackInfo::values_
5283 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5284 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5285 // FunctionCallbackInfo::length_ = argc
5286 __ mov(ip, Operand(argc.immediate()));
5287 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5288 // FunctionCallbackInfo::is_construct_call_ = 0
5289 __ mov(ip, Operand::Zero());
5290 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5292 // FunctionCallbackInfo::values_
5293 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5294 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5295 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5296 // FunctionCallbackInfo::length_ = argc
5297 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5298 // FunctionCallbackInfo::is_construct_call_
5299 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5300 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5301 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5304 ExternalReference thunk_ref =
5305 ExternalReference::invoke_function_callback(masm->isolate());
5307 AllowExternalCallThatCantCauseGC scope(masm);
5308 MemOperand context_restore_operand(
5309 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5310 // Stores return the first js argument
5311 int return_value_offset = 0;
5312 if (return_first_arg) {
5313 return_value_offset = 2 + FCA::kArgsLength;
5315 return_value_offset = 2 + FCA::kReturnValueOffset;
5317 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5318 int stack_space = 0;
5319 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5320 MemOperand* stack_space_operand = &is_construct_call_operand;
5321 if (argc.is_immediate()) {
5322 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5323 stack_space_operand = NULL;
5325 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5326 stack_space_operand, return_value_operand,
5327 &context_restore_operand);
5331 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5332 bool call_data_undefined = this->call_data_undefined();
5333 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
5334 call_data_undefined);
5338 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5339 bool is_store = this->is_store();
5340 int argc = this->argc();
5341 bool call_data_undefined = this->call_data_undefined();
5342 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5343 call_data_undefined);
5347 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5348 // ----------- S t a t e -------------
5350 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5352 // -- r2 : api_function_address
5353 // -----------------------------------
5355 Register api_function_address = ApiGetterDescriptor::function_address();
5356 DCHECK(api_function_address.is(r2));
5358 __ mov(r0, sp); // r0 = Handle<Name>
5359 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
5361 const int kApiStackSpace = 1;
5362 FrameScope frame_scope(masm, StackFrame::MANUAL);
5363 __ EnterExitFrame(false, kApiStackSpace);
5365 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5366 // r1 (internal::Object** args_) as the data.
5367 __ str(r1, MemOperand(sp, 1 * kPointerSize));
5368 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
5370 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5372 ExternalReference thunk_ref =
5373 ExternalReference::invoke_accessor_getter_callback(isolate());
5374 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5375 kStackUnwindSpace, NULL,
5376 MemOperand(fp, 6 * kPointerSize), NULL);
5382 } // namespace internal
5385 #endif // V8_TARGET_ARCH_ARM