1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #if V8_TARGET_ARCH_ARM64
9 #include "src/bootstrapper.h"
10 #include "src/code-stubs.h"
11 #include "src/codegen.h"
12 #include "src/ic/handler-compiler.h"
13 #include "src/ic/ic.h"
14 #include "src/ic/stub-cache.h"
15 #include "src/isolate.h"
16 #include "src/jsregexp.h"
17 #include "src/regexp-macro-assembler.h"
18 #include "src/runtime/runtime.h"
24 static void InitializeArrayConstructorDescriptor(
25 Isolate* isolate, CodeStubDescriptor* descriptor,
26 int constant_stack_parameter_count) {
29 // x2: allocation site with elements kind
30 // x0: number of arguments to the constructor function
31 Address deopt_handler = Runtime::FunctionForId(
32 Runtime::kArrayConstructor)->entry;
34 if (constant_stack_parameter_count == 0) {
35 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
36 JS_FUNCTION_STUB_MODE);
38 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
39 JS_FUNCTION_STUB_MODE);
44 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
45 CodeStubDescriptor* descriptor) {
46 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
50 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
51 CodeStubDescriptor* descriptor) {
52 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
56 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
57 CodeStubDescriptor* descriptor) {
58 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
62 static void InitializeInternalArrayConstructorDescriptor(
63 Isolate* isolate, CodeStubDescriptor* descriptor,
64 int constant_stack_parameter_count) {
65 Address deopt_handler = Runtime::FunctionForId(
66 Runtime::kInternalArrayConstructor)->entry;
68 if (constant_stack_parameter_count == 0) {
69 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
70 JS_FUNCTION_STUB_MODE);
72 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
73 JS_FUNCTION_STUB_MODE);
78 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
79 CodeStubDescriptor* descriptor) {
80 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
84 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
85 CodeStubDescriptor* descriptor) {
86 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
90 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
91 CodeStubDescriptor* descriptor) {
92 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
96 #define __ ACCESS_MASM(masm)
99 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
100 ExternalReference miss) {
101 // Update the static counter each time a new code stub is generated.
102 isolate()->counters()->code_stubs()->Increment();
104 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
105 int param_count = descriptor.GetRegisterParameterCount();
107 // Call the runtime system in a fresh internal frame.
108 FrameScope scope(masm, StackFrame::INTERNAL);
109 DCHECK((param_count == 0) ||
110 x0.Is(descriptor.GetRegisterParameter(param_count - 1)));
113 MacroAssembler::PushPopQueue queue(masm);
114 for (int i = 0; i < param_count; ++i) {
115 queue.Queue(descriptor.GetRegisterParameter(i));
119 __ CallExternalReference(miss, param_count);
126 void DoubleToIStub::Generate(MacroAssembler* masm) {
128 Register input = source();
129 Register result = destination();
130 DCHECK(is_truncating());
132 DCHECK(result.Is64Bits());
133 DCHECK(jssp.Is(masm->StackPointer()));
135 int double_offset = offset();
137 DoubleRegister double_scratch = d0; // only used if !skip_fastpath()
138 Register scratch1 = GetAllocatableRegisterThatIsNotOneOf(input, result);
140 GetAllocatableRegisterThatIsNotOneOf(input, result, scratch1);
142 __ Push(scratch1, scratch2);
143 // Account for saved regs if input is jssp.
144 if (input.is(jssp)) double_offset += 2 * kPointerSize;
146 if (!skip_fastpath()) {
147 __ Push(double_scratch);
148 if (input.is(jssp)) double_offset += 1 * kDoubleSize;
149 __ Ldr(double_scratch, MemOperand(input, double_offset));
150 // Try to convert with a FPU convert instruction. This handles all
151 // non-saturating cases.
152 __ TryConvertDoubleToInt64(result, double_scratch, &done);
153 __ Fmov(result, double_scratch);
155 __ Ldr(result, MemOperand(input, double_offset));
158 // If we reach here we need to manually convert the input to an int32.
160 // Extract the exponent.
161 Register exponent = scratch1;
162 __ Ubfx(exponent, result, HeapNumber::kMantissaBits,
163 HeapNumber::kExponentBits);
165 // It the exponent is >= 84 (kMantissaBits + 32), the result is always 0 since
166 // the mantissa gets shifted completely out of the int32_t result.
167 __ Cmp(exponent, HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 32);
168 __ CzeroX(result, ge);
171 // The Fcvtzs sequence handles all cases except where the conversion causes
172 // signed overflow in the int64_t target. Since we've already handled
173 // exponents >= 84, we can guarantee that 63 <= exponent < 84.
175 if (masm->emit_debug_code()) {
176 __ Cmp(exponent, HeapNumber::kExponentBias + 63);
177 // Exponents less than this should have been handled by the Fcvt case.
178 __ Check(ge, kUnexpectedValue);
181 // Isolate the mantissa bits, and set the implicit '1'.
182 Register mantissa = scratch2;
183 __ Ubfx(mantissa, result, 0, HeapNumber::kMantissaBits);
184 __ Orr(mantissa, mantissa, 1UL << HeapNumber::kMantissaBits);
186 // Negate the mantissa if necessary.
187 __ Tst(result, kXSignMask);
188 __ Cneg(mantissa, mantissa, ne);
190 // Shift the mantissa bits in the correct place. We know that we have to shift
191 // it left here, because exponent >= 63 >= kMantissaBits.
192 __ Sub(exponent, exponent,
193 HeapNumber::kExponentBias + HeapNumber::kMantissaBits);
194 __ Lsl(result, mantissa, exponent);
197 if (!skip_fastpath()) {
198 __ Pop(double_scratch);
200 __ Pop(scratch2, scratch1);
205 // See call site for description.
206 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
207 Register right, Register scratch,
208 FPRegister double_scratch,
209 Label* slow, Condition cond,
211 DCHECK(!AreAliased(left, right, scratch));
212 Label not_identical, return_equal, heap_number;
213 Register result = x0;
216 __ B(ne, ¬_identical);
218 // Test for NaN. Sadly, we can't just compare to factory::nan_value(),
219 // so we do the second best thing - test it ourselves.
220 // They are both equal and they are not both Smis so both of them are not
221 // Smis. If it's not a heap number, then return equal.
222 Register right_type = scratch;
223 if ((cond == lt) || (cond == gt)) {
224 // Call runtime on identical JSObjects. Otherwise return equal.
225 __ JumpIfObjectType(right, right_type, right_type, FIRST_SPEC_OBJECT_TYPE,
227 // Call runtime on identical symbols since we need to throw a TypeError.
228 __ Cmp(right_type, SYMBOL_TYPE);
230 // Call runtime on identical SIMD values since we must throw a TypeError.
231 __ Cmp(right_type, FLOAT32X4_TYPE);
233 if (is_strong(strength)) {
234 // Call the runtime on anything that is converted in the semantics, since
235 // we need to throw a TypeError. Smis have already been ruled out.
236 __ Cmp(right_type, Operand(HEAP_NUMBER_TYPE));
237 __ B(eq, &return_equal);
238 __ Tst(right_type, Operand(kIsNotStringMask));
241 } else if (cond == eq) {
242 __ JumpIfHeapNumber(right, &heap_number);
244 __ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE,
246 // Comparing JS objects with <=, >= is complicated.
247 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
249 // Call runtime on identical symbols since we need to throw a TypeError.
250 __ Cmp(right_type, SYMBOL_TYPE);
252 // Call runtime on identical SIMD values since we must throw a TypeError.
253 __ Cmp(right_type, FLOAT32X4_TYPE);
255 if (is_strong(strength)) {
256 // Call the runtime on anything that is converted in the semantics,
257 // since we need to throw a TypeError. Smis and heap numbers have
258 // already been ruled out.
259 __ Tst(right_type, Operand(kIsNotStringMask));
262 // Normally here we fall through to return_equal, but undefined is
263 // special: (undefined == undefined) == true, but
264 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
265 if ((cond == le) || (cond == ge)) {
266 __ Cmp(right_type, ODDBALL_TYPE);
267 __ B(ne, &return_equal);
268 __ JumpIfNotRoot(right, Heap::kUndefinedValueRootIndex, &return_equal);
270 // undefined <= undefined should fail.
271 __ Mov(result, GREATER);
273 // undefined >= undefined should fail.
274 __ Mov(result, LESS);
280 __ Bind(&return_equal);
282 __ Mov(result, GREATER); // Things aren't less than themselves.
283 } else if (cond == gt) {
284 __ Mov(result, LESS); // Things aren't greater than themselves.
286 __ Mov(result, EQUAL); // Things are <=, >=, ==, === themselves.
290 // Cases lt and gt have been handled earlier, and case ne is never seen, as
291 // it is handled in the parser (see Parser::ParseBinaryExpression). We are
292 // only concerned with cases ge, le and eq here.
293 if ((cond != lt) && (cond != gt)) {
294 DCHECK((cond == ge) || (cond == le) || (cond == eq));
295 __ Bind(&heap_number);
296 // Left and right are identical pointers to a heap number object. Return
297 // non-equal if the heap number is a NaN, and equal otherwise. Comparing
298 // the number to itself will set the overflow flag iff the number is NaN.
299 __ Ldr(double_scratch, FieldMemOperand(right, HeapNumber::kValueOffset));
300 __ Fcmp(double_scratch, double_scratch);
301 __ B(vc, &return_equal); // Not NaN, so treat as normal heap number.
304 __ Mov(result, GREATER);
306 __ Mov(result, LESS);
311 // No fall through here.
312 if (FLAG_debug_code) {
316 __ Bind(¬_identical);
320 // See call site for description.
321 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
327 DCHECK(!AreAliased(left, right, left_type, right_type, scratch));
329 if (masm->emit_debug_code()) {
330 // We assume that the arguments are not identical.
332 __ Assert(ne, kExpectedNonIdenticalObjects);
335 // If either operand is a JS object or an oddball value, then they are not
336 // equal since their pointers are different.
337 // There is no test for undetectability in strict equality.
338 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
339 Label right_non_object;
341 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
342 __ B(lt, &right_non_object);
344 // Return non-zero - x0 already contains a non-zero pointer.
345 DCHECK(left.is(x0) || right.is(x0));
346 Label return_not_equal;
347 __ Bind(&return_not_equal);
350 __ Bind(&right_non_object);
352 // Check for oddballs: true, false, null, undefined.
353 __ Cmp(right_type, ODDBALL_TYPE);
355 // If right is not ODDBALL, test left. Otherwise, set eq condition.
356 __ Ccmp(left_type, ODDBALL_TYPE, ZFlag, ne);
358 // If right or left is not ODDBALL, test left >= FIRST_SPEC_OBJECT_TYPE.
359 // Otherwise, right or left is ODDBALL, so set a ge condition.
360 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NVFlag, ne);
362 __ B(ge, &return_not_equal);
364 // Internalized strings are unique, so they can only be equal if they are the
365 // same object. We have already tested that case, so if left and right are
366 // both internalized strings, they cannot be equal.
367 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
368 __ Orr(scratch, left_type, right_type);
369 __ TestAndBranchIfAllClear(
370 scratch, kIsNotStringMask | kIsNotInternalizedMask, &return_not_equal);
374 // See call site for description.
375 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
382 DCHECK(!AreAliased(left_d, right_d));
383 DCHECK((left.is(x0) && right.is(x1)) ||
384 (right.is(x0) && left.is(x1)));
385 Register result = x0;
387 Label right_is_smi, done;
388 __ JumpIfSmi(right, &right_is_smi);
390 // Left is the smi. Check whether right is a heap number.
392 // If right is not a number and left is a smi, then strict equality cannot
393 // succeed. Return non-equal.
394 Label is_heap_number;
395 __ JumpIfHeapNumber(right, &is_heap_number);
396 // Register right is a non-zero pointer, which is a valid NOT_EQUAL result.
397 if (!right.is(result)) {
398 __ Mov(result, NOT_EQUAL);
401 __ Bind(&is_heap_number);
403 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
405 __ JumpIfNotHeapNumber(right, slow);
408 // Left is the smi. Right is a heap number. Load right value into right_d, and
409 // convert left smi into double in left_d.
410 __ Ldr(right_d, FieldMemOperand(right, HeapNumber::kValueOffset));
411 __ SmiUntagToDouble(left_d, left);
414 __ Bind(&right_is_smi);
415 // Right is a smi. Check whether the non-smi left is a heap number.
417 // If left is not a number and right is a smi then strict equality cannot
418 // succeed. Return non-equal.
419 Label is_heap_number;
420 __ JumpIfHeapNumber(left, &is_heap_number);
421 // Register left is a non-zero pointer, which is a valid NOT_EQUAL result.
422 if (!left.is(result)) {
423 __ Mov(result, NOT_EQUAL);
426 __ Bind(&is_heap_number);
428 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
430 __ JumpIfNotHeapNumber(left, slow);
433 // Right is the smi. Left is a heap number. Load left value into left_d, and
434 // convert right smi into double in right_d.
435 __ Ldr(left_d, FieldMemOperand(left, HeapNumber::kValueOffset));
436 __ SmiUntagToDouble(right_d, right);
438 // Fall through to both_loaded_as_doubles.
443 // Fast negative check for internalized-to-internalized equality.
444 // See call site for description.
445 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
452 Label* possible_strings,
453 Label* not_both_strings) {
454 DCHECK(!AreAliased(left, right, left_map, right_map, left_type, right_type));
455 Register result = x0;
458 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
459 // TODO(all): reexamine this branch sequence for optimisation wrt branch
461 __ Tbnz(right_type, MaskToBit(kIsNotStringMask), &object_test);
462 __ Tbnz(right_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
463 __ Tbnz(left_type, MaskToBit(kIsNotStringMask), not_both_strings);
464 __ Tbnz(left_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
466 // Both are internalized. We already checked that they weren't the same
467 // pointer, so they are not equal.
468 __ Mov(result, NOT_EQUAL);
471 __ Bind(&object_test);
473 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
475 // If right >= FIRST_SPEC_OBJECT_TYPE, test left.
476 // Otherwise, right < FIRST_SPEC_OBJECT_TYPE, so set lt condition.
477 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NFlag, ge);
479 __ B(lt, not_both_strings);
481 // If both objects are undetectable, they are equal. Otherwise, they are not
482 // equal, since they are different objects and an object is not equal to
485 // Returning here, so we can corrupt right_type and left_type.
486 Register right_bitfield = right_type;
487 Register left_bitfield = left_type;
488 __ Ldrb(right_bitfield, FieldMemOperand(right_map, Map::kBitFieldOffset));
489 __ Ldrb(left_bitfield, FieldMemOperand(left_map, Map::kBitFieldOffset));
490 __ And(result, right_bitfield, left_bitfield);
491 __ And(result, result, 1 << Map::kIsUndetectable);
492 __ Eor(result, result, 1 << Map::kIsUndetectable);
497 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
498 CompareICState::State expected,
501 if (expected == CompareICState::SMI) {
502 __ JumpIfNotSmi(input, fail);
503 } else if (expected == CompareICState::NUMBER) {
504 __ JumpIfSmi(input, &ok);
505 __ JumpIfNotHeapNumber(input, fail);
507 // We could be strict about internalized/non-internalized here, but as long as
508 // hydrogen doesn't care, the stub doesn't have to care either.
513 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
516 Register result = x0;
517 Condition cond = GetCondition();
520 CompareICStub_CheckInputType(masm, lhs, left(), &miss);
521 CompareICStub_CheckInputType(masm, rhs, right(), &miss);
523 Label slow; // Call builtin.
524 Label not_smis, both_loaded_as_doubles;
525 Label not_two_smis, smi_done;
526 __ JumpIfEitherNotSmi(lhs, rhs, ¬_two_smis);
528 __ Sub(result, lhs, Operand::UntagSmi(rhs));
531 __ Bind(¬_two_smis);
533 // NOTICE! This code is only reached after a smi-fast-case check, so it is
534 // certain that at least one operand isn't a smi.
536 // Handle the case where the objects are identical. Either returns the answer
537 // or goes to slow. Only falls through if the objects were not identical.
538 EmitIdenticalObjectComparison(masm, lhs, rhs, x10, d0, &slow, cond,
541 // If either is a smi (we know that at least one is not a smi), then they can
542 // only be strictly equal if the other is a HeapNumber.
543 __ JumpIfBothNotSmi(lhs, rhs, ¬_smis);
545 // Exactly one operand is a smi. EmitSmiNonsmiComparison generates code that
547 // 1) Return the answer.
548 // 2) Branch to the slow case.
549 // 3) Fall through to both_loaded_as_doubles.
550 // In case 3, we have found out that we were dealing with a number-number
551 // comparison. The double values of the numbers have been loaded, right into
552 // rhs_d, left into lhs_d.
553 FPRegister rhs_d = d0;
554 FPRegister lhs_d = d1;
555 EmitSmiNonsmiComparison(masm, lhs, rhs, lhs_d, rhs_d, &slow, strict());
557 __ Bind(&both_loaded_as_doubles);
558 // The arguments have been converted to doubles and stored in rhs_d and
561 __ Fcmp(lhs_d, rhs_d);
562 __ B(vs, &nan); // Overflow flag set if either is NaN.
563 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
564 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
565 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
569 // Left and/or right is a NaN. Load the result register with whatever makes
570 // the comparison fail, since comparisons with NaN always fail (except ne,
571 // which is filtered out at a higher level.)
573 if ((cond == lt) || (cond == le)) {
574 __ Mov(result, GREATER);
576 __ Mov(result, LESS);
581 // At this point we know we are dealing with two different objects, and
582 // neither of them is a smi. The objects are in rhs_ and lhs_.
584 // Load the maps and types of the objects.
585 Register rhs_map = x10;
586 Register rhs_type = x11;
587 Register lhs_map = x12;
588 Register lhs_type = x13;
589 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
590 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
591 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
592 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
595 // This emits a non-equal return sequence for some object types, or falls
596 // through if it was not lucky.
597 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs, lhs_type, rhs_type, x14);
600 Label check_for_internalized_strings;
601 Label flat_string_check;
602 // Check for heap number comparison. Branch to earlier double comparison code
603 // if they are heap numbers, otherwise, branch to internalized string check.
604 __ Cmp(rhs_type, HEAP_NUMBER_TYPE);
605 __ B(ne, &check_for_internalized_strings);
606 __ Cmp(lhs_map, rhs_map);
608 // If maps aren't equal, lhs_ and rhs_ are not heap numbers. Branch to flat
610 __ B(ne, &flat_string_check);
612 // Both lhs_ and rhs_ are heap numbers. Load them and branch to the double
614 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
615 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
616 __ B(&both_loaded_as_doubles);
618 __ Bind(&check_for_internalized_strings);
619 // In the strict case, the EmitStrictTwoHeapObjectCompare already took care
620 // of internalized strings.
621 if ((cond == eq) && !strict()) {
622 // Returns an answer for two internalized strings or two detectable objects.
623 // Otherwise branches to the string case or not both strings case.
624 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, lhs_map, rhs_map,
626 &flat_string_check, &slow);
629 // Check for both being sequential one-byte strings,
630 // and inline if that is the case.
631 __ Bind(&flat_string_check);
632 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x14,
635 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x10,
638 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
641 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
645 // Never fall through to here.
646 if (FLAG_debug_code) {
653 // Figure out which native to call and setup the arguments.
654 Builtins::JavaScript native;
656 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
659 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
660 int ncr; // NaN compare result
661 if ((cond == lt) || (cond == le)) {
664 DCHECK((cond == gt) || (cond == ge)); // remaining cases
667 __ Mov(x10, Smi::FromInt(ncr));
671 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
672 // tagged as a small integer.
673 __ InvokeBuiltin(native, JUMP_FUNCTION);
680 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
681 CPURegList saved_regs = kCallerSaved;
682 CPURegList saved_fp_regs = kCallerSavedFP;
684 // We don't allow a GC during a store buffer overflow so there is no need to
685 // store the registers in any particular way, but we do have to store and
688 // We don't care if MacroAssembler scratch registers are corrupted.
689 saved_regs.Remove(*(masm->TmpList()));
690 saved_fp_regs.Remove(*(masm->FPTmpList()));
692 __ PushCPURegList(saved_regs);
693 if (save_doubles()) {
694 __ PushCPURegList(saved_fp_regs);
697 AllowExternalCallThatCantCauseGC scope(masm);
698 __ Mov(x0, ExternalReference::isolate_address(isolate()));
700 ExternalReference::store_buffer_overflow_function(isolate()), 1, 0);
702 if (save_doubles()) {
703 __ PopCPURegList(saved_fp_regs);
705 __ PopCPURegList(saved_regs);
710 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
712 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
714 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
719 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
720 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
721 UseScratchRegisterScope temps(masm);
722 Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr());
723 Register return_address = temps.AcquireX();
724 __ Mov(return_address, lr);
725 // Restore lr with the value it had before the call to this stub (the value
726 // which must be pushed).
727 __ Mov(lr, saved_lr);
728 __ PushSafepointRegisters();
729 __ Ret(return_address);
733 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
734 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
735 UseScratchRegisterScope temps(masm);
736 Register return_address = temps.AcquireX();
737 // Preserve the return address (lr will be clobbered by the pop).
738 __ Mov(return_address, lr);
739 __ PopSafepointRegisters();
740 __ Ret(return_address);
744 void MathPowStub::Generate(MacroAssembler* masm) {
746 // jssp[0]: Exponent (as a tagged value).
747 // jssp[1]: Base (as a tagged value).
749 // The (tagged) result will be returned in x0, as a heap number.
751 Register result_tagged = x0;
752 Register base_tagged = x10;
753 Register exponent_tagged = MathPowTaggedDescriptor::exponent();
754 DCHECK(exponent_tagged.is(x11));
755 Register exponent_integer = MathPowIntegerDescriptor::exponent();
756 DCHECK(exponent_integer.is(x12));
757 Register scratch1 = x14;
758 Register scratch0 = x15;
759 Register saved_lr = x19;
760 FPRegister result_double = d0;
761 FPRegister base_double = d0;
762 FPRegister exponent_double = d1;
763 FPRegister base_double_copy = d2;
764 FPRegister scratch1_double = d6;
765 FPRegister scratch0_double = d7;
767 // A fast-path for integer exponents.
768 Label exponent_is_smi, exponent_is_integer;
769 // Bail out to runtime.
771 // Allocate a heap number for the result, and return it.
774 // Unpack the inputs.
775 if (exponent_type() == ON_STACK) {
777 Label unpack_exponent;
779 __ Pop(exponent_tagged, base_tagged);
781 __ JumpIfSmi(base_tagged, &base_is_smi);
782 __ JumpIfNotHeapNumber(base_tagged, &call_runtime);
783 // base_tagged is a heap number, so load its double value.
784 __ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset));
785 __ B(&unpack_exponent);
786 __ Bind(&base_is_smi);
787 // base_tagged is a SMI, so untag it and convert it to a double.
788 __ SmiUntagToDouble(base_double, base_tagged);
790 __ Bind(&unpack_exponent);
791 // x10 base_tagged The tagged base (input).
792 // x11 exponent_tagged The tagged exponent (input).
793 // d1 base_double The base as a double.
794 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
795 __ JumpIfNotHeapNumber(exponent_tagged, &call_runtime);
796 // exponent_tagged is a heap number, so load its double value.
797 __ Ldr(exponent_double,
798 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
799 } else if (exponent_type() == TAGGED) {
800 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
801 __ Ldr(exponent_double,
802 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
805 // Handle double (heap number) exponents.
806 if (exponent_type() != INTEGER) {
807 // Detect integer exponents stored as doubles and handle those in the
808 // integer fast-path.
809 __ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
810 scratch0_double, &exponent_is_integer);
812 if (exponent_type() == ON_STACK) {
813 FPRegister half_double = d3;
814 FPRegister minus_half_double = d4;
815 // Detect square root case. Crankshaft detects constant +/-0.5 at compile
816 // time and uses DoMathPowHalf instead. We then skip this check for
817 // non-constant cases of +/-0.5 as these hardly occur.
819 __ Fmov(minus_half_double, -0.5);
820 __ Fmov(half_double, 0.5);
821 __ Fcmp(minus_half_double, exponent_double);
822 __ Fccmp(half_double, exponent_double, NZFlag, ne);
823 // Condition flags at this point:
824 // 0.5; nZCv // Identified by eq && pl
825 // -0.5: NZcv // Identified by eq && mi
826 // other: ?z?? // Identified by ne
827 __ B(ne, &call_runtime);
829 // The exponent is 0.5 or -0.5.
831 // Given that exponent is known to be either 0.5 or -0.5, the following
832 // special cases could apply (according to ECMA-262 15.8.2.13):
834 // base.isNaN(): The result is NaN.
835 // (base == +INFINITY) || (base == -INFINITY)
836 // exponent == 0.5: The result is +INFINITY.
837 // exponent == -0.5: The result is +0.
838 // (base == +0) || (base == -0)
839 // exponent == 0.5: The result is +0.
840 // exponent == -0.5: The result is +INFINITY.
841 // (base < 0) && base.isFinite(): The result is NaN.
843 // Fsqrt (and Fdiv for the -0.5 case) can handle all of those except
844 // where base is -INFINITY or -0.
846 // Add +0 to base. This has no effect other than turning -0 into +0.
847 __ Fadd(base_double, base_double, fp_zero);
848 // The operation -0+0 results in +0 in all cases except where the
849 // FPCR rounding mode is 'round towards minus infinity' (RM). The
850 // ARM64 simulator does not currently simulate FPCR (where the rounding
851 // mode is set), so test the operation with some debug code.
852 if (masm->emit_debug_code()) {
853 UseScratchRegisterScope temps(masm);
854 Register temp = temps.AcquireX();
855 __ Fneg(scratch0_double, fp_zero);
856 // Verify that we correctly generated +0.0 and -0.0.
857 // bits(+0.0) = 0x0000000000000000
858 // bits(-0.0) = 0x8000000000000000
859 __ Fmov(temp, fp_zero);
860 __ CheckRegisterIsClear(temp, kCouldNotGenerateZero);
861 __ Fmov(temp, scratch0_double);
862 __ Eor(temp, temp, kDSignMask);
863 __ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero);
864 // Check that -0.0 + 0.0 == +0.0.
865 __ Fadd(scratch0_double, scratch0_double, fp_zero);
866 __ Fmov(temp, scratch0_double);
867 __ CheckRegisterIsClear(temp, kExpectedPositiveZero);
870 // If base is -INFINITY, make it +INFINITY.
871 // * Calculate base - base: All infinities will become NaNs since both
872 // -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64.
873 // * If the result is NaN, calculate abs(base).
874 __ Fsub(scratch0_double, base_double, base_double);
875 __ Fcmp(scratch0_double, 0.0);
876 __ Fabs(scratch1_double, base_double);
877 __ Fcsel(base_double, scratch1_double, base_double, vs);
879 // Calculate the square root of base.
880 __ Fsqrt(result_double, base_double);
881 __ Fcmp(exponent_double, 0.0);
882 __ B(ge, &done); // Finish now for exponents of 0.5.
883 // Find the inverse for exponents of -0.5.
884 __ Fmov(scratch0_double, 1.0);
885 __ Fdiv(result_double, scratch0_double, result_double);
890 AllowExternalCallThatCantCauseGC scope(masm);
891 __ Mov(saved_lr, lr);
893 ExternalReference::power_double_double_function(isolate()),
895 __ Mov(lr, saved_lr);
899 // Handle SMI exponents.
900 __ Bind(&exponent_is_smi);
901 // x10 base_tagged The tagged base (input).
902 // x11 exponent_tagged The tagged exponent (input).
903 // d1 base_double The base as a double.
904 __ SmiUntag(exponent_integer, exponent_tagged);
907 __ Bind(&exponent_is_integer);
908 // x10 base_tagged The tagged base (input).
909 // x11 exponent_tagged The tagged exponent (input).
910 // x12 exponent_integer The exponent as an integer.
911 // d1 base_double The base as a double.
913 // Find abs(exponent). For negative exponents, we can find the inverse later.
914 Register exponent_abs = x13;
915 __ Cmp(exponent_integer, 0);
916 __ Cneg(exponent_abs, exponent_integer, mi);
917 // x13 exponent_abs The value of abs(exponent_integer).
919 // Repeatedly multiply to calculate the power.
921 // For each bit n (exponent_integer{n}) {
922 // if (exponent_integer{n}) {
926 // if (remaining bits in exponent_integer are all zero) {
930 Label power_loop, power_loop_entry, power_loop_exit;
931 __ Fmov(scratch1_double, base_double);
932 __ Fmov(base_double_copy, base_double);
933 __ Fmov(result_double, 1.0);
934 __ B(&power_loop_entry);
936 __ Bind(&power_loop);
937 __ Fmul(scratch1_double, scratch1_double, scratch1_double);
938 __ Lsr(exponent_abs, exponent_abs, 1);
939 __ Cbz(exponent_abs, &power_loop_exit);
941 __ Bind(&power_loop_entry);
942 __ Tbz(exponent_abs, 0, &power_loop);
943 __ Fmul(result_double, result_double, scratch1_double);
946 __ Bind(&power_loop_exit);
948 // If the exponent was positive, result_double holds the result.
949 __ Tbz(exponent_integer, kXSignBit, &done);
951 // The exponent was negative, so find the inverse.
952 __ Fmov(scratch0_double, 1.0);
953 __ Fdiv(result_double, scratch0_double, result_double);
954 // ECMA-262 only requires Math.pow to return an 'implementation-dependent
955 // approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
956 // to calculate the subnormal value 2^-1074. This method of calculating
957 // negative powers doesn't work because 2^1074 overflows to infinity. To
958 // catch this corner-case, we bail out if the result was 0. (This can only
959 // occur if the divisor is infinity or the base is zero.)
960 __ Fcmp(result_double, 0.0);
963 if (exponent_type() == ON_STACK) {
964 // Bail out to runtime code.
965 __ Bind(&call_runtime);
966 // Put the arguments back on the stack.
967 __ Push(base_tagged, exponent_tagged);
968 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
972 __ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1,
974 DCHECK(result_tagged.is(x0));
976 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
979 AllowExternalCallThatCantCauseGC scope(masm);
980 __ Mov(saved_lr, lr);
981 __ Fmov(base_double, base_double_copy);
982 __ Scvtf(exponent_double, exponent_integer);
984 ExternalReference::power_double_double_function(isolate()),
986 __ Mov(lr, saved_lr);
989 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
995 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
996 // It is important that the following stubs are generated in this order
997 // because pregenerated stubs can only call other pregenerated stubs.
998 // RecordWriteStub uses StoreBufferOverflowStub, which in turn uses
1000 CEntryStub::GenerateAheadOfTime(isolate);
1001 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1002 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1003 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1004 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1005 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1006 BinaryOpICStub::GenerateAheadOfTime(isolate);
1007 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1008 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1009 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1010 StoreFastElementStub::GenerateAheadOfTime(isolate);
1011 TypeofStub::GenerateAheadOfTime(isolate);
1015 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1016 StoreRegistersStateStub stub(isolate);
1021 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1022 RestoreRegistersStateStub stub(isolate);
1027 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1028 // Floating-point code doesn't get special handling in ARM64, so there's
1029 // nothing to do here.
1034 bool CEntryStub::NeedsImmovableCode() {
1035 // CEntryStub stores the return address on the stack before calling into
1036 // C++ code. In some cases, the VM accesses this address, but it is not used
1037 // when the C++ code returns to the stub because LR holds the return address
1038 // in AAPCS64. If the stub is moved (perhaps during a GC), we could end up
1039 // returning to dead code.
1040 // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't
1041 // find any comment to confirm this, and I don't hit any crashes whatever
1042 // this function returns. The anaylsis should be properly confirmed.
1047 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1048 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1050 CEntryStub stub_fp(isolate, 1, kSaveFPRegs);
1055 void CEntryStub::Generate(MacroAssembler* masm) {
1056 // The Abort mechanism relies on CallRuntime, which in turn relies on
1057 // CEntryStub, so until this stub has been generated, we have to use a
1058 // fall-back Abort mechanism.
1060 // Note that this stub must be generated before any use of Abort.
1061 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
1063 ASM_LOCATION("CEntryStub::Generate entry");
1064 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1066 // Register parameters:
1067 // x0: argc (including receiver, untagged)
1070 // The stack on entry holds the arguments and the receiver, with the receiver
1071 // at the highest address:
1073 // jssp]argc-1]: receiver
1074 // jssp[argc-2]: arg[argc-2]
1079 // The arguments are in reverse order, so that arg[argc-2] is actually the
1080 // first argument to the target function and arg[0] is the last.
1081 DCHECK(jssp.Is(__ StackPointer()));
1082 const Register& argc_input = x0;
1083 const Register& target_input = x1;
1085 // Calculate argv, argc and the target address, and store them in
1086 // callee-saved registers so we can retry the call without having to reload
1088 // TODO(jbramley): If the first call attempt succeeds in the common case (as
1089 // it should), then we might be better off putting these parameters directly
1090 // into their argument registers, rather than using callee-saved registers and
1091 // preserving them on the stack.
1092 const Register& argv = x21;
1093 const Register& argc = x22;
1094 const Register& target = x23;
1096 // Derive argv from the stack pointer so that it points to the first argument
1097 // (arg[argc-2]), or just below the receiver in case there are no arguments.
1098 // - Adjust for the arg[] array.
1099 Register temp_argv = x11;
1100 __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
1101 // - Adjust for the receiver.
1102 __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
1104 // Enter the exit frame. Reserve three slots to preserve x21-x23 callee-saved
1106 FrameScope scope(masm, StackFrame::MANUAL);
1107 __ EnterExitFrame(save_doubles(), x10, 3);
1108 DCHECK(csp.Is(__ StackPointer()));
1110 // Poke callee-saved registers into reserved space.
1111 __ Poke(argv, 1 * kPointerSize);
1112 __ Poke(argc, 2 * kPointerSize);
1113 __ Poke(target, 3 * kPointerSize);
1115 // We normally only keep tagged values in callee-saved registers, as they
1116 // could be pushed onto the stack by called stubs and functions, and on the
1117 // stack they can confuse the GC. However, we're only calling C functions
1118 // which can push arbitrary data onto the stack anyway, and so the GC won't
1119 // examine that part of the stack.
1120 __ Mov(argc, argc_input);
1121 __ Mov(target, target_input);
1122 __ Mov(argv, temp_argv);
1126 // x23 : call target
1128 // The stack (on entry) holds the arguments and the receiver, with the
1129 // receiver at the highest address:
1131 // argv[8]: receiver
1132 // argv -> argv[0]: arg[argc-2]
1134 // argv[...]: arg[1]
1135 // argv[...]: arg[0]
1137 // Immediately below (after) this is the exit frame, as constructed by
1139 // fp[8]: CallerPC (lr)
1140 // fp -> fp[0]: CallerFP (old fp)
1141 // fp[-8]: Space reserved for SPOffset.
1142 // fp[-16]: CodeObject()
1143 // csp[...]: Saved doubles, if saved_doubles is true.
1144 // csp[32]: Alignment padding, if necessary.
1145 // csp[24]: Preserved x23 (used for target).
1146 // csp[16]: Preserved x22 (used for argc).
1147 // csp[8]: Preserved x21 (used for argv).
1148 // csp -> csp[0]: Space reserved for the return address.
1150 // After a successful call, the exit frame, preserved registers (x21-x23) and
1151 // the arguments (including the receiver) are dropped or popped as
1152 // appropriate. The stub then returns.
1154 // After an unsuccessful call, the exit frame and suchlike are left
1155 // untouched, and the stub either throws an exception by jumping to one of
1156 // the exception_returned label.
1158 DCHECK(csp.Is(__ StackPointer()));
1160 // Prepare AAPCS64 arguments to pass to the builtin.
1163 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1165 Label return_location;
1166 __ Adr(x12, &return_location);
1169 if (__ emit_debug_code()) {
1170 // Verify that the slot below fp[kSPOffset]-8 points to the return location
1171 // (currently in x12).
1172 UseScratchRegisterScope temps(masm);
1173 Register temp = temps.AcquireX();
1174 __ Ldr(temp, MemOperand(fp, ExitFrameConstants::kSPOffset));
1175 __ Ldr(temp, MemOperand(temp, -static_cast<int64_t>(kXRegSize)));
1177 __ Check(eq, kReturnAddressNotFoundInFrame);
1180 // Call the builtin.
1182 __ Bind(&return_location);
1184 // x0 result The return code from the call.
1188 const Register& result = x0;
1190 // Check result for exception sentinel.
1191 Label exception_returned;
1192 __ CompareRoot(result, Heap::kExceptionRootIndex);
1193 __ B(eq, &exception_returned);
1195 // The call succeeded, so unwind the stack and return.
1197 // Restore callee-saved registers x21-x23.
1200 __ Peek(argv, 1 * kPointerSize);
1201 __ Peek(argc, 2 * kPointerSize);
1202 __ Peek(target, 3 * kPointerSize);
1204 __ LeaveExitFrame(save_doubles(), x10, true);
1205 DCHECK(jssp.Is(__ StackPointer()));
1206 // Pop or drop the remaining stack slots and return from the stub.
1207 // jssp[24]: Arguments array (of size argc), including receiver.
1208 // jssp[16]: Preserved x23 (used for target).
1209 // jssp[8]: Preserved x22 (used for argc).
1210 // jssp[0]: Preserved x21 (used for argv).
1212 __ AssertFPCRState();
1215 // The stack pointer is still csp if we aren't returning, and the frame
1216 // hasn't changed (except for the return address).
1217 __ SetStackPointer(csp);
1219 // Handling of exception.
1220 __ Bind(&exception_returned);
1222 ExternalReference pending_handler_context_address(
1223 Isolate::kPendingHandlerContextAddress, isolate());
1224 ExternalReference pending_handler_code_address(
1225 Isolate::kPendingHandlerCodeAddress, isolate());
1226 ExternalReference pending_handler_offset_address(
1227 Isolate::kPendingHandlerOffsetAddress, isolate());
1228 ExternalReference pending_handler_fp_address(
1229 Isolate::kPendingHandlerFPAddress, isolate());
1230 ExternalReference pending_handler_sp_address(
1231 Isolate::kPendingHandlerSPAddress, isolate());
1233 // Ask the runtime for help to determine the handler. This will set x0 to
1234 // contain the current pending exception, don't clobber it.
1235 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1237 DCHECK(csp.Is(masm->StackPointer()));
1239 FrameScope scope(masm, StackFrame::MANUAL);
1240 __ Mov(x0, 0); // argc.
1241 __ Mov(x1, 0); // argv.
1242 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1243 __ CallCFunction(find_handler, 3);
1246 // We didn't execute a return case, so the stack frame hasn't been updated
1247 // (except for the return address slot). However, we don't need to initialize
1248 // jssp because the throw method will immediately overwrite it when it
1249 // unwinds the stack.
1250 __ SetStackPointer(jssp);
1252 // Retrieve the handler context, SP and FP.
1253 __ Mov(cp, Operand(pending_handler_context_address));
1254 __ Ldr(cp, MemOperand(cp));
1255 __ Mov(jssp, Operand(pending_handler_sp_address));
1256 __ Ldr(jssp, MemOperand(jssp));
1257 __ Mov(fp, Operand(pending_handler_fp_address));
1258 __ Ldr(fp, MemOperand(fp));
1260 // If the handler is a JS frame, restore the context to the frame. Note that
1261 // the context will be set to (cp == 0) for non-JS frames.
1263 __ Cbz(cp, ¬_js_frame);
1264 __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1265 __ Bind(¬_js_frame);
1267 // Compute the handler entry address and jump to it.
1268 __ Mov(x10, Operand(pending_handler_code_address));
1269 __ Ldr(x10, MemOperand(x10));
1270 __ Mov(x11, Operand(pending_handler_offset_address));
1271 __ Ldr(x11, MemOperand(x11));
1272 __ Add(x10, x10, Code::kHeaderSize - kHeapObjectTag);
1273 __ Add(x10, x10, x11);
1278 // This is the entry point from C++. 5 arguments are provided in x0-x4.
1279 // See use of the CALL_GENERATED_CODE macro for example in src/execution.cc.
1288 void JSEntryStub::Generate(MacroAssembler* masm) {
1289 DCHECK(jssp.Is(__ StackPointer()));
1290 Register code_entry = x0;
1292 // Enable instruction instrumentation. This only works on the simulator, and
1293 // will have no effect on the model or real hardware.
1294 __ EnableInstrumentation();
1296 Label invoke, handler_entry, exit;
1298 // Push callee-saved registers and synchronize the system stack pointer (csp)
1299 // and the JavaScript stack pointer (jssp).
1301 // We must not write to jssp until after the PushCalleeSavedRegisters()
1302 // call, since jssp is itself a callee-saved register.
1303 __ SetStackPointer(csp);
1304 __ PushCalleeSavedRegisters();
1306 __ SetStackPointer(jssp);
1308 // Configure the FPCR. We don't restore it, so this is technically not allowed
1309 // according to AAPCS64. However, we only set default-NaN mode and this will
1310 // be harmless for most C code. Also, it works for ARM.
1313 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1315 // Set up the reserved register for 0.0.
1316 __ Fmov(fp_zero, 0.0);
1318 // Build an entry frame (see layout below).
1319 int marker = type();
1320 int64_t bad_frame_pointer = -1L; // Bad frame pointer to fail if it is used.
1321 __ Mov(x13, bad_frame_pointer);
1322 __ Mov(x12, Smi::FromInt(marker));
1323 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1324 __ Ldr(x10, MemOperand(x11));
1326 __ Push(x13, xzr, x12, x10);
1328 __ Sub(fp, jssp, EntryFrameConstants::kCallerFPOffset);
1330 // Push the JS entry frame marker. Also set js_entry_sp if this is the
1331 // outermost JS call.
1332 Label non_outermost_js, done;
1333 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1334 __ Mov(x10, ExternalReference(js_entry_sp));
1335 __ Ldr(x11, MemOperand(x10));
1336 __ Cbnz(x11, &non_outermost_js);
1337 __ Str(fp, MemOperand(x10));
1338 __ Mov(x12, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1341 __ Bind(&non_outermost_js);
1342 // We spare one instruction by pushing xzr since the marker is 0.
1343 DCHECK(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME) == NULL);
1347 // The frame set up looks like this:
1348 // jssp[0] : JS entry frame marker.
1349 // jssp[1] : C entry FP.
1350 // jssp[2] : stack frame marker.
1351 // jssp[3] : stack frmae marker.
1352 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1355 // Jump to a faked try block that does the invoke, with a faked catch
1356 // block that sets the pending exception.
1359 // Prevent the constant pool from being emitted between the record of the
1360 // handler_entry position and the first instruction of the sequence here.
1361 // There is no risk because Assembler::Emit() emits the instruction before
1362 // checking for constant pool emission, but we do not want to depend on
1365 Assembler::BlockPoolsScope block_pools(masm);
1366 __ bind(&handler_entry);
1367 handler_offset_ = handler_entry.pos();
1368 // Caught exception: Store result (exception) in the pending exception
1369 // field in the JSEnv and return a failure sentinel. Coming in here the
1370 // fp will be invalid because the PushTryHandler below sets it to 0 to
1371 // signal the existence of the JSEntry frame.
1372 __ Mov(x10, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1375 __ Str(code_entry, MemOperand(x10));
1376 __ LoadRoot(x0, Heap::kExceptionRootIndex);
1379 // Invoke: Link this frame into the handler chain.
1381 __ PushStackHandler();
1382 // If an exception not caught by another handler occurs, this handler
1383 // returns control to the code after the B(&invoke) above, which
1384 // restores all callee-saved registers (including cp and fp) to their
1385 // saved values before returning a failure to C.
1387 // Clear any pending exceptions.
1388 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
1389 __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1391 __ Str(x10, MemOperand(x11));
1393 // Invoke the function by calling through the JS entry trampoline builtin.
1394 // Notice that we cannot store a reference to the trampoline code directly in
1395 // this stub, because runtime stubs are not traversed when doing GC.
1397 // Expected registers by Builtins::JSEntryTrampoline
1403 ExternalReference entry(type() == StackFrame::ENTRY_CONSTRUCT
1404 ? Builtins::kJSConstructEntryTrampoline
1405 : Builtins::kJSEntryTrampoline,
1409 // Call the JSEntryTrampoline.
1410 __ Ldr(x11, MemOperand(x10)); // Dereference the address.
1411 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag);
1414 // Unlink this frame from the handler chain.
1415 __ PopStackHandler();
1419 // x0 holds the result.
1420 // The stack pointer points to the top of the entry frame pushed on entry from
1421 // C++ (at the beginning of this stub):
1422 // jssp[0] : JS entry frame marker.
1423 // jssp[1] : C entry FP.
1424 // jssp[2] : stack frame marker.
1425 // jssp[3] : stack frmae marker.
1426 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1428 // Check if the current stack frame is marked as the outermost JS frame.
1429 Label non_outermost_js_2;
1431 __ Cmp(x10, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1432 __ B(ne, &non_outermost_js_2);
1433 __ Mov(x11, ExternalReference(js_entry_sp));
1434 __ Str(xzr, MemOperand(x11));
1435 __ Bind(&non_outermost_js_2);
1437 // Restore the top frame descriptors from the stack.
1439 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1440 __ Str(x10, MemOperand(x11));
1442 // Reset the stack to the callee saved registers.
1443 __ Drop(-EntryFrameConstants::kCallerFPOffset, kByteSizeInBytes);
1444 // Restore the callee-saved registers and return.
1445 DCHECK(jssp.Is(__ StackPointer()));
1447 __ SetStackPointer(csp);
1448 __ PopCalleeSavedRegisters();
1449 // After this point, we must not modify jssp because it is a callee-saved
1450 // register which we have just restored.
1455 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1457 Register receiver = LoadDescriptor::ReceiverRegister();
1458 // Ensure that the vector and slot registers won't be clobbered before
1459 // calling the miss handler.
1460 DCHECK(!AreAliased(x10, x11, LoadWithVectorDescriptor::VectorRegister(),
1461 LoadWithVectorDescriptor::SlotRegister()));
1463 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, x10,
1467 PropertyAccessCompiler::TailCallBuiltin(
1468 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1472 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1473 // Return address is in lr.
1476 Register receiver = LoadDescriptor::ReceiverRegister();
1477 Register index = LoadDescriptor::NameRegister();
1478 Register result = x0;
1479 Register scratch = x10;
1480 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1481 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1482 result.is(LoadWithVectorDescriptor::SlotRegister()));
1484 // StringCharAtGenerator doesn't use the result register until it's passed
1485 // the different miss possibilities. If it did, we would have a conflict
1486 // when FLAG_vector_ics is true.
1487 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1488 &miss, // When not a string.
1489 &miss, // When not a number.
1490 &miss, // When index out of range.
1491 STRING_INDEX_IS_ARRAY_INDEX,
1492 RECEIVER_IS_STRING);
1493 char_at_generator.GenerateFast(masm);
1496 StubRuntimeCallHelper call_helper;
1497 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1500 PropertyAccessCompiler::TailCallBuiltin(
1501 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1505 void InstanceofStub::Generate(MacroAssembler* masm) {
1507 // jssp[0]: function.
1510 // Returns result in x0. Zero indicates instanceof, smi 1 indicates not
1513 Register result = x0;
1514 Register function = right();
1515 Register object = left();
1516 Register scratch1 = x6;
1517 Register scratch2 = x7;
1518 Register res_true = x8;
1519 Register res_false = x9;
1520 // Only used if there was an inline map check site. (See
1521 // LCodeGen::DoInstanceOfKnownGlobal().)
1522 Register map_check_site = x4;
1523 // Delta for the instructions generated between the inline map check and the
1524 // instruction setting the result.
1525 const int32_t kDeltaToLoadBoolResult = 4 * kInstructionSize;
1527 Label not_js_object, slow;
1529 if (!HasArgsInRegisters()) {
1530 __ Pop(function, object);
1533 if (ReturnTrueFalseObject()) {
1534 __ LoadTrueFalseRoots(res_true, res_false);
1536 // This is counter-intuitive, but correct.
1537 __ Mov(res_true, Smi::FromInt(0));
1538 __ Mov(res_false, Smi::FromInt(1));
1541 // Check that the left hand side is a JS object and load its map as a side
1544 __ JumpIfSmi(object, ¬_js_object);
1545 __ IsObjectJSObjectType(object, map, scratch2, ¬_js_object);
1547 // If there is a call site cache, don't look in the global cache, but do the
1548 // real lookup and update the call site cache.
1549 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
1551 __ JumpIfNotRoot(function, Heap::kInstanceofCacheFunctionRootIndex, &miss);
1552 __ JumpIfNotRoot(map, Heap::kInstanceofCacheMapRootIndex, &miss);
1553 __ LoadRoot(result, Heap::kInstanceofCacheAnswerRootIndex);
1558 // Get the prototype of the function.
1559 Register prototype = x13;
1560 __ TryGetFunctionPrototype(function, prototype, scratch2, &slow,
1561 MacroAssembler::kMissOnBoundFunction);
1563 // Check that the function prototype is a JS object.
1564 __ JumpIfSmi(prototype, &slow);
1565 __ IsObjectJSObjectType(prototype, scratch1, scratch2, &slow);
1567 // Update the global instanceof or call site inlined cache with the current
1568 // map and function. The cached answer will be set when it is known below.
1569 if (HasCallSiteInlineCheck()) {
1570 // Patch the (relocated) inlined map check.
1571 __ GetRelocatedValueLocation(map_check_site, scratch1);
1572 // We have a cell, so need another level of dereferencing.
1573 __ Ldr(scratch1, MemOperand(scratch1));
1574 __ Str(map, FieldMemOperand(scratch1, Cell::kValueOffset));
1577 // |scratch1| points at the beginning of the cell. Calculate the
1578 // field containing the map.
1579 __ Add(function, scratch1, Operand(Cell::kValueOffset - 1));
1580 __ RecordWriteField(scratch1, Cell::kValueOffset, x14, function,
1581 kLRHasNotBeenSaved, kDontSaveFPRegs,
1582 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
1584 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1585 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1588 Label return_true, return_result;
1589 Register smi_value = scratch1;
1591 // Loop through the prototype chain looking for the function prototype.
1592 Register chain_map = x1;
1593 Register chain_prototype = x14;
1594 Register null_value = x15;
1596 __ Ldr(chain_prototype, FieldMemOperand(map, Map::kPrototypeOffset));
1597 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
1598 // Speculatively set a result.
1599 __ Mov(result, res_false);
1600 if (!HasCallSiteInlineCheck() && ReturnTrueFalseObject()) {
1601 // Value to store in the cache cannot be an object.
1602 __ Mov(smi_value, Smi::FromInt(1));
1607 // If the chain prototype is the object prototype, return true.
1608 __ Cmp(chain_prototype, prototype);
1609 __ B(eq, &return_true);
1611 // If the chain prototype is null, we've reached the end of the chain, so
1613 __ Cmp(chain_prototype, null_value);
1614 __ B(eq, &return_result);
1616 // Otherwise, load the next prototype in the chain, and loop.
1617 __ Ldr(chain_map, FieldMemOperand(chain_prototype, HeapObject::kMapOffset));
1618 __ Ldr(chain_prototype, FieldMemOperand(chain_map, Map::kPrototypeOffset));
1622 // Return sequence when no arguments are on the stack.
1623 // We cannot fall through to here.
1624 __ Bind(&return_true);
1625 __ Mov(result, res_true);
1626 if (!HasCallSiteInlineCheck() && ReturnTrueFalseObject()) {
1627 // Value to store in the cache cannot be an object.
1628 __ Mov(smi_value, Smi::FromInt(0));
1630 __ Bind(&return_result);
1631 if (HasCallSiteInlineCheck()) {
1632 DCHECK(ReturnTrueFalseObject());
1633 __ Add(map_check_site, map_check_site, kDeltaToLoadBoolResult);
1634 __ GetRelocatedValueLocation(map_check_site, scratch2);
1635 __ Str(result, MemOperand(scratch2));
1637 Register cached_value = ReturnTrueFalseObject() ? smi_value : result;
1638 __ StoreRoot(cached_value, Heap::kInstanceofCacheAnswerRootIndex);
1642 Label object_not_null, object_not_null_or_smi;
1644 __ Bind(¬_js_object);
1645 Register object_type = x14;
1646 // x0 result result return register (uninit)
1647 // x10 function pointer to function
1648 // x11 object pointer to object
1649 // x14 object_type type of object (uninit)
1651 // Before null, smi and string checks, check that the rhs is a function.
1652 // For a non-function rhs, an exception must be thrown.
1653 __ JumpIfSmi(function, &slow);
1654 __ JumpIfNotObjectType(
1655 function, scratch1, object_type, JS_FUNCTION_TYPE, &slow);
1657 __ Mov(result, res_false);
1659 // Null is not instance of anything.
1660 __ Cmp(object, Operand(isolate()->factory()->null_value()));
1661 __ B(ne, &object_not_null);
1664 __ Bind(&object_not_null);
1665 // Smi values are not instances of anything.
1666 __ JumpIfNotSmi(object, &object_not_null_or_smi);
1669 __ Bind(&object_not_null_or_smi);
1670 // String values are not instances of anything.
1671 __ IsObjectJSStringType(object, scratch2, &slow);
1674 // Slow-case. Tail call builtin.
1677 FrameScope scope(masm, StackFrame::INTERNAL);
1678 // Arguments have either been passed into registers or have been previously
1679 // popped. We need to push them before calling builtin.
1680 __ Push(object, function);
1681 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1683 if (ReturnTrueFalseObject()) {
1684 // Reload true/false because they were clobbered in the builtin call.
1685 __ LoadTrueFalseRoots(res_true, res_false);
1687 __ Csel(result, res_true, res_false, eq);
1693 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1694 Register arg_count = ArgumentsAccessReadDescriptor::parameter_count();
1695 Register key = ArgumentsAccessReadDescriptor::index();
1696 DCHECK(arg_count.is(x0));
1699 // The displacement is the offset of the last parameter (if any) relative
1700 // to the frame pointer.
1701 static const int kDisplacement =
1702 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1704 // Check that the key is a smi.
1706 __ JumpIfNotSmi(key, &slow);
1708 // Check if the calling frame is an arguments adaptor frame.
1709 Register local_fp = x11;
1710 Register caller_fp = x11;
1711 Register caller_ctx = x12;
1713 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1714 __ Ldr(caller_ctx, MemOperand(caller_fp,
1715 StandardFrameConstants::kContextOffset));
1716 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1717 __ Csel(local_fp, fp, caller_fp, ne);
1718 __ B(ne, &skip_adaptor);
1720 // Load the actual arguments limit found in the arguments adaptor frame.
1721 __ Ldr(arg_count, MemOperand(caller_fp,
1722 ArgumentsAdaptorFrameConstants::kLengthOffset));
1723 __ Bind(&skip_adaptor);
1725 // Check index against formal parameters count limit. Use unsigned comparison
1726 // to get negative check for free: branch if key < 0 or key >= arg_count.
1727 __ Cmp(key, arg_count);
1730 // Read the argument from the stack and return it.
1731 __ Sub(x10, arg_count, key);
1732 __ Add(x10, local_fp, Operand::UntagSmiAndScale(x10, kPointerSizeLog2));
1733 __ Ldr(x0, MemOperand(x10, kDisplacement));
1736 // Slow case: handle non-smi or out-of-bounds access to arguments by calling
1737 // the runtime system.
1740 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1744 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1745 // Stack layout on entry.
1746 // jssp[0]: number of parameters (tagged)
1747 // jssp[8]: address of receiver argument
1748 // jssp[16]: function
1750 // Check if the calling frame is an arguments adaptor frame.
1752 Register caller_fp = x10;
1753 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1754 // Load and untag the context.
1755 __ Ldr(w11, UntagSmiMemOperand(caller_fp,
1756 StandardFrameConstants::kContextOffset));
1757 __ Cmp(w11, StackFrame::ARGUMENTS_ADAPTOR);
1760 // Patch the arguments.length and parameters pointer in the current frame.
1761 __ Ldr(x11, MemOperand(caller_fp,
1762 ArgumentsAdaptorFrameConstants::kLengthOffset));
1763 __ Poke(x11, 0 * kXRegSize);
1764 __ Add(x10, caller_fp, Operand::UntagSmiAndScale(x11, kPointerSizeLog2));
1765 __ Add(x10, x10, StandardFrameConstants::kCallerSPOffset);
1766 __ Poke(x10, 1 * kXRegSize);
1769 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1773 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1774 // Stack layout on entry.
1775 // jssp[0]: number of parameters (tagged)
1776 // jssp[8]: address of receiver argument
1777 // jssp[16]: function
1779 // Returns pointer to result object in x0.
1781 // Note: arg_count_smi is an alias of param_count_smi.
1782 Register arg_count_smi = x3;
1783 Register param_count_smi = x3;
1784 Register param_count = x7;
1785 Register recv_arg = x14;
1786 Register function = x4;
1787 __ Pop(param_count_smi, recv_arg, function);
1788 __ SmiUntag(param_count, param_count_smi);
1790 // Check if the calling frame is an arguments adaptor frame.
1791 Register caller_fp = x11;
1792 Register caller_ctx = x12;
1794 Label adaptor_frame, try_allocate;
1795 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1796 __ Ldr(caller_ctx, MemOperand(caller_fp,
1797 StandardFrameConstants::kContextOffset));
1798 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1799 __ B(eq, &adaptor_frame);
1801 // No adaptor, parameter count = argument count.
1803 // x1 mapped_params number of mapped params, min(params, args) (uninit)
1804 // x2 arg_count number of function arguments (uninit)
1805 // x3 arg_count_smi number of function arguments (smi)
1806 // x4 function function pointer
1807 // x7 param_count number of function parameters
1808 // x11 caller_fp caller's frame pointer
1809 // x14 recv_arg pointer to receiver arguments
1811 Register arg_count = x2;
1812 __ Mov(arg_count, param_count);
1813 __ B(&try_allocate);
1815 // We have an adaptor frame. Patch the parameters pointer.
1816 __ Bind(&adaptor_frame);
1817 __ Ldr(arg_count_smi,
1818 MemOperand(caller_fp,
1819 ArgumentsAdaptorFrameConstants::kLengthOffset));
1820 __ SmiUntag(arg_count, arg_count_smi);
1821 __ Add(x10, caller_fp, Operand(arg_count, LSL, kPointerSizeLog2));
1822 __ Add(recv_arg, x10, StandardFrameConstants::kCallerSPOffset);
1824 // Compute the mapped parameter count = min(param_count, arg_count)
1825 Register mapped_params = x1;
1826 __ Cmp(param_count, arg_count);
1827 __ Csel(mapped_params, param_count, arg_count, lt);
1829 __ Bind(&try_allocate);
1831 // x0 alloc_obj pointer to allocated objects: param map, backing
1832 // store, arguments (uninit)
1833 // x1 mapped_params number of mapped parameters, min(params, args)
1834 // x2 arg_count number of function arguments
1835 // x3 arg_count_smi number of function arguments (smi)
1836 // x4 function function pointer
1837 // x7 param_count number of function parameters
1838 // x10 size size of objects to allocate (uninit)
1839 // x14 recv_arg pointer to receiver arguments
1841 // Compute the size of backing store, parameter map, and arguments object.
1842 // 1. Parameter map, has two extra words containing context and backing
1844 const int kParameterMapHeaderSize =
1845 FixedArray::kHeaderSize + 2 * kPointerSize;
1847 // Calculate the parameter map size, assuming it exists.
1848 Register size = x10;
1849 __ Mov(size, Operand(mapped_params, LSL, kPointerSizeLog2));
1850 __ Add(size, size, kParameterMapHeaderSize);
1852 // If there are no mapped parameters, set the running size total to zero.
1853 // Otherwise, use the parameter map size calculated earlier.
1854 __ Cmp(mapped_params, 0);
1855 __ CzeroX(size, eq);
1857 // 2. Add the size of the backing store and arguments object.
1858 __ Add(size, size, Operand(arg_count, LSL, kPointerSizeLog2));
1860 FixedArray::kHeaderSize + Heap::kSloppyArgumentsObjectSize);
1862 // Do the allocation of all three objects in one go. Assign this to x0, as it
1863 // will be returned to the caller.
1864 Register alloc_obj = x0;
1865 __ Allocate(size, alloc_obj, x11, x12, &runtime, TAG_OBJECT);
1867 // Get the arguments boilerplate from the current (global) context.
1869 // x0 alloc_obj pointer to allocated objects (param map, backing
1870 // store, arguments)
1871 // x1 mapped_params number of mapped parameters, min(params, args)
1872 // x2 arg_count number of function arguments
1873 // x3 arg_count_smi number of function arguments (smi)
1874 // x4 function function pointer
1875 // x7 param_count number of function parameters
1876 // x11 sloppy_args_map offset to args (or aliased args) map (uninit)
1877 // x14 recv_arg pointer to receiver arguments
1879 Register global_object = x10;
1880 Register global_ctx = x10;
1881 Register sloppy_args_map = x11;
1882 Register aliased_args_map = x10;
1883 __ Ldr(global_object, GlobalObjectMemOperand());
1884 __ Ldr(global_ctx, FieldMemOperand(global_object,
1885 GlobalObject::kNativeContextOffset));
1887 __ Ldr(sloppy_args_map,
1888 ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1891 ContextMemOperand(global_ctx, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX));
1892 __ Cmp(mapped_params, 0);
1893 __ CmovX(sloppy_args_map, aliased_args_map, ne);
1895 // Copy the JS object part.
1896 __ Str(sloppy_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
1897 __ LoadRoot(x10, Heap::kEmptyFixedArrayRootIndex);
1898 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
1899 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1901 // Set up the callee in-object property.
1902 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1903 const int kCalleeOffset = JSObject::kHeaderSize +
1904 Heap::kArgumentsCalleeIndex * kPointerSize;
1905 __ AssertNotSmi(function);
1906 __ Str(function, FieldMemOperand(alloc_obj, kCalleeOffset));
1908 // Use the length and set that as an in-object property.
1909 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1910 const int kLengthOffset = JSObject::kHeaderSize +
1911 Heap::kArgumentsLengthIndex * kPointerSize;
1912 __ Str(arg_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
1914 // Set up the elements pointer in the allocated arguments object.
1915 // If we allocated a parameter map, "elements" will point there, otherwise
1916 // it will point to the backing store.
1918 // x0 alloc_obj pointer to allocated objects (param map, backing
1919 // store, arguments)
1920 // x1 mapped_params number of mapped parameters, min(params, args)
1921 // x2 arg_count number of function arguments
1922 // x3 arg_count_smi number of function arguments (smi)
1923 // x4 function function pointer
1924 // x5 elements pointer to parameter map or backing store (uninit)
1925 // x6 backing_store pointer to backing store (uninit)
1926 // x7 param_count number of function parameters
1927 // x14 recv_arg pointer to receiver arguments
1929 Register elements = x5;
1930 __ Add(elements, alloc_obj, Heap::kSloppyArgumentsObjectSize);
1931 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1933 // Initialize parameter map. If there are no mapped arguments, we're done.
1934 Label skip_parameter_map;
1935 __ Cmp(mapped_params, 0);
1936 // Set up backing store address, because it is needed later for filling in
1937 // the unmapped arguments.
1938 Register backing_store = x6;
1939 __ CmovX(backing_store, elements, eq);
1940 __ B(eq, &skip_parameter_map);
1942 __ LoadRoot(x10, Heap::kSloppyArgumentsElementsMapRootIndex);
1943 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
1944 __ Add(x10, mapped_params, 2);
1946 __ Str(x10, FieldMemOperand(elements, FixedArray::kLengthOffset));
1947 __ Str(cp, FieldMemOperand(elements,
1948 FixedArray::kHeaderSize + 0 * kPointerSize));
1949 __ Add(x10, elements, Operand(mapped_params, LSL, kPointerSizeLog2));
1950 __ Add(x10, x10, kParameterMapHeaderSize);
1951 __ Str(x10, FieldMemOperand(elements,
1952 FixedArray::kHeaderSize + 1 * kPointerSize));
1954 // Copy the parameter slots and the holes in the arguments.
1955 // We need to fill in mapped_parameter_count slots. Then index the context,
1956 // where parameters are stored in reverse order, at:
1958 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS + parameter_count - 1
1960 // The mapped parameter thus needs to get indices:
1962 // MIN_CONTEXT_SLOTS + parameter_count - 1 ..
1963 // MIN_CONTEXT_SLOTS + parameter_count - mapped_parameter_count
1965 // We loop from right to left.
1967 // x0 alloc_obj pointer to allocated objects (param map, backing
1968 // store, arguments)
1969 // x1 mapped_params number of mapped parameters, min(params, args)
1970 // x2 arg_count number of function arguments
1971 // x3 arg_count_smi number of function arguments (smi)
1972 // x4 function function pointer
1973 // x5 elements pointer to parameter map or backing store (uninit)
1974 // x6 backing_store pointer to backing store (uninit)
1975 // x7 param_count number of function parameters
1976 // x11 loop_count parameter loop counter (uninit)
1977 // x12 index parameter index (smi, uninit)
1978 // x13 the_hole hole value (uninit)
1979 // x14 recv_arg pointer to receiver arguments
1981 Register loop_count = x11;
1982 Register index = x12;
1983 Register the_hole = x13;
1984 Label parameters_loop, parameters_test;
1985 __ Mov(loop_count, mapped_params);
1986 __ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS));
1987 __ Sub(index, index, mapped_params);
1989 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
1990 __ Add(backing_store, elements, Operand(loop_count, LSL, kPointerSizeLog2));
1991 __ Add(backing_store, backing_store, kParameterMapHeaderSize);
1993 __ B(¶meters_test);
1995 __ Bind(¶meters_loop);
1996 __ Sub(loop_count, loop_count, 1);
1997 __ Mov(x10, Operand(loop_count, LSL, kPointerSizeLog2));
1998 __ Add(x10, x10, kParameterMapHeaderSize - kHeapObjectTag);
1999 __ Str(index, MemOperand(elements, x10));
2000 __ Sub(x10, x10, kParameterMapHeaderSize - FixedArray::kHeaderSize);
2001 __ Str(the_hole, MemOperand(backing_store, x10));
2002 __ Add(index, index, Smi::FromInt(1));
2003 __ Bind(¶meters_test);
2004 __ Cbnz(loop_count, ¶meters_loop);
2006 __ Bind(&skip_parameter_map);
2007 // Copy arguments header and remaining slots (if there are any.)
2008 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
2009 __ Str(x10, FieldMemOperand(backing_store, FixedArray::kMapOffset));
2010 __ Str(arg_count_smi, FieldMemOperand(backing_store,
2011 FixedArray::kLengthOffset));
2013 // x0 alloc_obj pointer to allocated objects (param map, backing
2014 // store, arguments)
2015 // x1 mapped_params number of mapped parameters, min(params, args)
2016 // x2 arg_count number of function arguments
2017 // x4 function function pointer
2018 // x3 arg_count_smi number of function arguments (smi)
2019 // x6 backing_store pointer to backing store (uninit)
2020 // x14 recv_arg pointer to receiver arguments
2022 Label arguments_loop, arguments_test;
2023 __ Mov(x10, mapped_params);
2024 __ Sub(recv_arg, recv_arg, Operand(x10, LSL, kPointerSizeLog2));
2025 __ B(&arguments_test);
2027 __ Bind(&arguments_loop);
2028 __ Sub(recv_arg, recv_arg, kPointerSize);
2029 __ Ldr(x11, MemOperand(recv_arg));
2030 __ Add(x12, backing_store, Operand(x10, LSL, kPointerSizeLog2));
2031 __ Str(x11, FieldMemOperand(x12, FixedArray::kHeaderSize));
2032 __ Add(x10, x10, 1);
2034 __ Bind(&arguments_test);
2035 __ Cmp(x10, arg_count);
2036 __ B(lt, &arguments_loop);
2040 // Do the runtime call to allocate the arguments object.
2042 __ Push(function, recv_arg, arg_count_smi);
2043 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
2047 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
2048 // Return address is in lr.
2051 Register receiver = LoadDescriptor::ReceiverRegister();
2052 Register key = LoadDescriptor::NameRegister();
2054 // Check that the key is an array index, that is Uint32.
2055 __ TestAndBranchIfAnySet(key, kSmiTagMask | kSmiSignMask, &slow);
2057 // Everything is fine, call runtime.
2058 __ Push(receiver, key);
2059 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
2062 PropertyAccessCompiler::TailCallBuiltin(
2063 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
2067 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
2068 // Stack layout on entry.
2069 // jssp[0]: number of parameters (tagged)
2070 // jssp[8]: address of receiver argument
2071 // jssp[16]: function
2073 // Returns pointer to result object in x0.
2075 // Get the stub arguments from the frame, and make an untagged copy of the
2077 Register param_count_smi = x1;
2078 Register params = x2;
2079 Register function = x3;
2080 Register param_count = x13;
2081 __ Pop(param_count_smi, params, function);
2082 __ SmiUntag(param_count, param_count_smi);
2084 // Test if arguments adaptor needed.
2085 Register caller_fp = x11;
2086 Register caller_ctx = x12;
2087 Label try_allocate, runtime;
2088 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2089 __ Ldr(caller_ctx, MemOperand(caller_fp,
2090 StandardFrameConstants::kContextOffset));
2091 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2092 __ B(ne, &try_allocate);
2094 // x1 param_count_smi number of parameters passed to function (smi)
2095 // x2 params pointer to parameters
2096 // x3 function function pointer
2097 // x11 caller_fp caller's frame pointer
2098 // x13 param_count number of parameters passed to function
2100 // Patch the argument length and parameters pointer.
2101 __ Ldr(param_count_smi,
2102 MemOperand(caller_fp,
2103 ArgumentsAdaptorFrameConstants::kLengthOffset));
2104 __ SmiUntag(param_count, param_count_smi);
2105 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2106 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2108 // Try the new space allocation. Start out with computing the size of the
2109 // arguments object and the elements array in words.
2110 Register size = x10;
2111 __ Bind(&try_allocate);
2112 __ Add(size, param_count, FixedArray::kHeaderSize / kPointerSize);
2113 __ Cmp(param_count, 0);
2114 __ CzeroX(size, eq);
2115 __ Add(size, size, Heap::kStrictArgumentsObjectSize / kPointerSize);
2117 // Do the allocation of both objects in one go. Assign this to x0, as it will
2118 // be returned to the caller.
2119 Register alloc_obj = x0;
2120 __ Allocate(size, alloc_obj, x11, x12, &runtime,
2121 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
2123 // Get the arguments boilerplate from the current (native) context.
2124 Register global_object = x10;
2125 Register global_ctx = x10;
2126 Register strict_args_map = x4;
2127 __ Ldr(global_object, GlobalObjectMemOperand());
2128 __ Ldr(global_ctx, FieldMemOperand(global_object,
2129 GlobalObject::kNativeContextOffset));
2130 __ Ldr(strict_args_map,
2131 ContextMemOperand(global_ctx, Context::STRICT_ARGUMENTS_MAP_INDEX));
2133 // x0 alloc_obj pointer to allocated objects: parameter array and
2135 // x1 param_count_smi number of parameters passed to function (smi)
2136 // x2 params pointer to parameters
2137 // x3 function function pointer
2138 // x4 strict_args_map offset to arguments map
2139 // x13 param_count number of parameters passed to function
2140 __ Str(strict_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
2141 __ LoadRoot(x5, Heap::kEmptyFixedArrayRootIndex);
2142 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
2143 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2145 // Set the smi-tagged length as an in-object property.
2146 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2147 const int kLengthOffset = JSObject::kHeaderSize +
2148 Heap::kArgumentsLengthIndex * kPointerSize;
2149 __ Str(param_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
2151 // If there are no actual arguments, we're done.
2153 __ Cbz(param_count, &done);
2155 // Set up the elements pointer in the allocated arguments object and
2156 // initialize the header in the elements fixed array.
2157 Register elements = x5;
2158 __ Add(elements, alloc_obj, Heap::kStrictArgumentsObjectSize);
2159 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2160 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
2161 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
2162 __ Str(param_count_smi, FieldMemOperand(elements, FixedArray::kLengthOffset));
2164 // x0 alloc_obj pointer to allocated objects: parameter array and
2166 // x1 param_count_smi number of parameters passed to function (smi)
2167 // x2 params pointer to parameters
2168 // x3 function function pointer
2169 // x4 array pointer to array slot (uninit)
2170 // x5 elements pointer to elements array of alloc_obj
2171 // x13 param_count number of parameters passed to function
2173 // Copy the fixed array slots.
2175 Register array = x4;
2176 // Set up pointer to first array slot.
2177 __ Add(array, elements, FixedArray::kHeaderSize - kHeapObjectTag);
2180 // Pre-decrement the parameters pointer by kPointerSize on each iteration.
2181 // Pre-decrement in order to skip receiver.
2182 __ Ldr(x10, MemOperand(params, -kPointerSize, PreIndex));
2183 // Post-increment elements by kPointerSize on each iteration.
2184 __ Str(x10, MemOperand(array, kPointerSize, PostIndex));
2185 __ Sub(param_count, param_count, 1);
2186 __ Cbnz(param_count, &loop);
2188 // Return from stub.
2192 // Do the runtime call to allocate the arguments object.
2194 __ Push(function, params, param_count_smi);
2195 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2199 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
2200 // Stack layout on entry.
2201 // jssp[0]: language mode (tagged)
2202 // jssp[8]: index of rest parameter (tagged)
2203 // jssp[16]: number of parameters (tagged)
2204 // jssp[24]: address of receiver argument
2206 // Returns pointer to result object in x0.
2208 // Get the stub arguments from the frame, and make an untagged copy of the
2210 Register language_mode_smi = x1;
2211 Register rest_index_smi = x2;
2212 Register param_count_smi = x3;
2213 Register params = x4;
2214 Register param_count = x13;
2215 __ Pop(language_mode_smi, rest_index_smi, param_count_smi, params);
2216 __ SmiUntag(param_count, param_count_smi);
2218 // Test if arguments adaptor needed.
2219 Register caller_fp = x11;
2220 Register caller_ctx = x12;
2222 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2223 __ Ldr(caller_ctx, MemOperand(caller_fp,
2224 StandardFrameConstants::kContextOffset));
2225 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2228 // x1 language_mode_smi language mode
2229 // x2 rest_index_smi index of rest parameter
2230 // x3 param_count_smi number of parameters passed to function (smi)
2231 // x4 params pointer to parameters
2232 // x11 caller_fp caller's frame pointer
2233 // x13 param_count number of parameters passed to function
2235 // Patch the argument length and parameters pointer.
2236 __ Ldr(param_count_smi,
2237 MemOperand(caller_fp,
2238 ArgumentsAdaptorFrameConstants::kLengthOffset));
2239 __ SmiUntag(param_count, param_count_smi);
2240 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2241 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2244 __ Push(params, param_count_smi, rest_index_smi, language_mode_smi);
2245 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
2249 void RegExpExecStub::Generate(MacroAssembler* masm) {
2250 #ifdef V8_INTERPRETED_REGEXP
2251 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2252 #else // V8_INTERPRETED_REGEXP
2254 // Stack frame on entry.
2255 // jssp[0]: last_match_info (expected JSArray)
2256 // jssp[8]: previous index
2257 // jssp[16]: subject string
2258 // jssp[24]: JSRegExp object
2261 // Use of registers for this function.
2263 // Variable registers:
2264 // x10-x13 used as scratch registers
2265 // w0 string_type type of subject string
2266 // x2 jsstring_length subject string length
2267 // x3 jsregexp_object JSRegExp object
2268 // w4 string_encoding Latin1 or UC16
2269 // w5 sliced_string_offset if the string is a SlicedString
2270 // offset to the underlying string
2271 // w6 string_representation groups attributes of the string:
2273 // - type of the string
2274 // - is a short external string
2275 Register string_type = w0;
2276 Register jsstring_length = x2;
2277 Register jsregexp_object = x3;
2278 Register string_encoding = w4;
2279 Register sliced_string_offset = w5;
2280 Register string_representation = w6;
2282 // These are in callee save registers and will be preserved by the call
2283 // to the native RegExp code, as this code is called using the normal
2284 // C calling convention. When calling directly from generated code the
2285 // native RegExp code will not do a GC and therefore the content of
2286 // these registers are safe to use after the call.
2288 // x19 subject subject string
2289 // x20 regexp_data RegExp data (FixedArray)
2290 // x21 last_match_info_elements info relative to the last match
2292 // x22 code_object generated regexp code
2293 Register subject = x19;
2294 Register regexp_data = x20;
2295 Register last_match_info_elements = x21;
2296 Register code_object = x22;
2299 // jssp[00]: last_match_info (JSArray)
2300 // jssp[08]: previous index
2301 // jssp[16]: subject string
2302 // jssp[24]: JSRegExp object
2304 const int kLastMatchInfoOffset = 0 * kPointerSize;
2305 const int kPreviousIndexOffset = 1 * kPointerSize;
2306 const int kSubjectOffset = 2 * kPointerSize;
2307 const int kJSRegExpOffset = 3 * kPointerSize;
2309 // Ensure that a RegExp stack is allocated.
2310 ExternalReference address_of_regexp_stack_memory_address =
2311 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2312 ExternalReference address_of_regexp_stack_memory_size =
2313 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2314 __ Mov(x10, address_of_regexp_stack_memory_size);
2315 __ Ldr(x10, MemOperand(x10));
2316 __ Cbz(x10, &runtime);
2318 // Check that the first argument is a JSRegExp object.
2319 DCHECK(jssp.Is(__ StackPointer()));
2320 __ Peek(jsregexp_object, kJSRegExpOffset);
2321 __ JumpIfSmi(jsregexp_object, &runtime);
2322 __ JumpIfNotObjectType(jsregexp_object, x10, x10, JS_REGEXP_TYPE, &runtime);
2324 // Check that the RegExp has been compiled (data contains a fixed array).
2325 __ Ldr(regexp_data, FieldMemOperand(jsregexp_object, JSRegExp::kDataOffset));
2326 if (FLAG_debug_code) {
2327 STATIC_ASSERT(kSmiTag == 0);
2328 __ Tst(regexp_data, kSmiTagMask);
2329 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2330 __ CompareObjectType(regexp_data, x10, x10, FIXED_ARRAY_TYPE);
2331 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2334 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2335 __ Ldr(x10, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2336 __ Cmp(x10, Smi::FromInt(JSRegExp::IRREGEXP));
2339 // Check that the number of captures fit in the static offsets vector buffer.
2340 // We have always at least one capture for the whole match, plus additional
2341 // ones due to capturing parentheses. A capture takes 2 registers.
2342 // The number of capture registers then is (number_of_captures + 1) * 2.
2344 UntagSmiFieldMemOperand(regexp_data,
2345 JSRegExp::kIrregexpCaptureCountOffset));
2346 // Check (number_of_captures + 1) * 2 <= offsets vector size
2347 // number_of_captures * 2 <= offsets vector size - 2
2348 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2349 __ Add(x10, x10, x10);
2350 __ Cmp(x10, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
2353 // Initialize offset for possibly sliced string.
2354 __ Mov(sliced_string_offset, 0);
2356 DCHECK(jssp.Is(__ StackPointer()));
2357 __ Peek(subject, kSubjectOffset);
2358 __ JumpIfSmi(subject, &runtime);
2360 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2361 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2363 __ Ldr(jsstring_length, FieldMemOperand(subject, String::kLengthOffset));
2365 // Handle subject string according to its encoding and representation:
2366 // (1) Sequential string? If yes, go to (5).
2367 // (2) Anything but sequential or cons? If yes, go to (6).
2368 // (3) Cons string. If the string is flat, replace subject with first string.
2369 // Otherwise bailout.
2370 // (4) Is subject external? If yes, go to (7).
2371 // (5) Sequential string. Load regexp code according to encoding.
2375 // Deferred code at the end of the stub:
2376 // (6) Not a long external string? If yes, go to (8).
2377 // (7) External string. Make it, offset-wise, look like a sequential string.
2379 // (8) Short external string or not a string? If yes, bail out to runtime.
2380 // (9) Sliced string. Replace subject with parent. Go to (4).
2382 Label check_underlying; // (4)
2383 Label seq_string; // (5)
2384 Label not_seq_nor_cons; // (6)
2385 Label external_string; // (7)
2386 Label not_long_external; // (8)
2388 // (1) Sequential string? If yes, go to (5).
2389 __ And(string_representation,
2392 kStringRepresentationMask |
2393 kShortExternalStringMask);
2394 // We depend on the fact that Strings of type
2395 // SeqString and not ShortExternalString are defined
2396 // by the following pattern:
2397 // string_type: 0XX0 XX00
2400 // | | is a SeqString
2401 // | is not a short external String
2403 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2404 STATIC_ASSERT(kShortExternalStringTag != 0);
2405 __ Cbz(string_representation, &seq_string); // Go to (5).
2407 // (2) Anything but sequential or cons? If yes, go to (6).
2408 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2409 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2410 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2411 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2412 __ Cmp(string_representation, kExternalStringTag);
2413 __ B(ge, ¬_seq_nor_cons); // Go to (6).
2415 // (3) Cons string. Check that it's flat.
2416 __ Ldr(x10, FieldMemOperand(subject, ConsString::kSecondOffset));
2417 __ JumpIfNotRoot(x10, Heap::kempty_stringRootIndex, &runtime);
2418 // Replace subject with first string.
2419 __ Ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2421 // (4) Is subject external? If yes, go to (7).
2422 __ Bind(&check_underlying);
2423 // Reload the string type.
2424 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2425 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2426 STATIC_ASSERT(kSeqStringTag == 0);
2427 // The underlying external string is never a short external string.
2428 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2429 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2430 __ TestAndBranchIfAnySet(string_type.X(),
2431 kStringRepresentationMask,
2432 &external_string); // Go to (7).
2434 // (5) Sequential string. Load regexp code according to encoding.
2435 __ Bind(&seq_string);
2437 // Check that the third argument is a positive smi less than the subject
2438 // string length. A negative value will be greater (unsigned comparison).
2439 DCHECK(jssp.Is(__ StackPointer()));
2440 __ Peek(x10, kPreviousIndexOffset);
2441 __ JumpIfNotSmi(x10, &runtime);
2442 __ Cmp(jsstring_length, x10);
2445 // Argument 2 (x1): We need to load argument 2 (the previous index) into x1
2446 // before entering the exit frame.
2447 __ SmiUntag(x1, x10);
2449 // The third bit determines the string encoding in string_type.
2450 STATIC_ASSERT(kOneByteStringTag == 0x04);
2451 STATIC_ASSERT(kTwoByteStringTag == 0x00);
2452 STATIC_ASSERT(kStringEncodingMask == 0x04);
2454 // Find the code object based on the assumptions above.
2455 // kDataOneByteCodeOffset and kDataUC16CodeOffset are adjacent, adds an offset
2456 // of kPointerSize to reach the latter.
2457 STATIC_ASSERT(JSRegExp::kDataOneByteCodeOffset + kPointerSize ==
2458 JSRegExp::kDataUC16CodeOffset);
2459 __ Mov(x10, kPointerSize);
2460 // We will need the encoding later: Latin1 = 0x04
2462 __ Ands(string_encoding, string_type, kStringEncodingMask);
2464 __ Add(x10, regexp_data, x10);
2465 __ Ldr(code_object, FieldMemOperand(x10, JSRegExp::kDataOneByteCodeOffset));
2467 // (E) Carry on. String handling is done.
2469 // Check that the irregexp code has been generated for the actual string
2470 // encoding. If it has, the field contains a code object otherwise it contains
2471 // a smi (code flushing support).
2472 __ JumpIfSmi(code_object, &runtime);
2474 // All checks done. Now push arguments for native regexp code.
2475 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1,
2479 // Isolates: note we add an additional parameter here (isolate pointer).
2480 __ EnterExitFrame(false, x10, 1);
2481 DCHECK(csp.Is(__ StackPointer()));
2483 // We have 9 arguments to pass to the regexp code, therefore we have to pass
2484 // one on the stack and the rest as registers.
2486 // Note that the placement of the argument on the stack isn't standard
2488 // csp[0]: Space for the return address placed by DirectCEntryStub.
2489 // csp[8]: Argument 9, the current isolate address.
2491 __ Mov(x10, ExternalReference::isolate_address(isolate()));
2492 __ Poke(x10, kPointerSize);
2494 Register length = w11;
2495 Register previous_index_in_bytes = w12;
2496 Register start = x13;
2498 // Load start of the subject string.
2499 __ Add(start, subject, SeqString::kHeaderSize - kHeapObjectTag);
2500 // Load the length from the original subject string from the previous stack
2501 // frame. Therefore we have to use fp, which points exactly to two pointer
2502 // sizes below the previous sp. (Because creating a new stack frame pushes
2503 // the previous fp onto the stack and decrements sp by 2 * kPointerSize.)
2504 __ Ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2505 __ Ldr(length, UntagSmiFieldMemOperand(subject, String::kLengthOffset));
2507 // Handle UC16 encoding, two bytes make one character.
2508 // string_encoding: if Latin1: 0x04
2510 STATIC_ASSERT(kStringEncodingMask == 0x04);
2511 __ Ubfx(string_encoding, string_encoding, 2, 1);
2512 __ Eor(string_encoding, string_encoding, 1);
2513 // string_encoding: if Latin1: 0
2516 // Convert string positions from characters to bytes.
2517 // Previous index is in x1.
2518 __ Lsl(previous_index_in_bytes, w1, string_encoding);
2519 __ Lsl(length, length, string_encoding);
2520 __ Lsl(sliced_string_offset, sliced_string_offset, string_encoding);
2522 // Argument 1 (x0): Subject string.
2523 __ Mov(x0, subject);
2525 // Argument 2 (x1): Previous index, already there.
2527 // Argument 3 (x2): Get the start of input.
2528 // Start of input = start of string + previous index + substring offset
2531 __ Add(w10, previous_index_in_bytes, sliced_string_offset);
2532 __ Add(x2, start, Operand(w10, UXTW));
2535 // End of input = start of input + (length of input - previous index)
2536 __ Sub(w10, length, previous_index_in_bytes);
2537 __ Add(x3, x2, Operand(w10, UXTW));
2539 // Argument 5 (x4): static offsets vector buffer.
2540 __ Mov(x4, ExternalReference::address_of_static_offsets_vector(isolate()));
2542 // Argument 6 (x5): Set the number of capture registers to zero to force
2543 // global regexps to behave as non-global. This stub is not used for global
2547 // Argument 7 (x6): Start (high end) of backtracking stack memory area.
2548 __ Mov(x10, address_of_regexp_stack_memory_address);
2549 __ Ldr(x10, MemOperand(x10));
2550 __ Mov(x11, address_of_regexp_stack_memory_size);
2551 __ Ldr(x11, MemOperand(x11));
2552 __ Add(x6, x10, x11);
2554 // Argument 8 (x7): Indicate that this is a direct call from JavaScript.
2557 // Locate the code entry and call it.
2558 __ Add(code_object, code_object, Code::kHeaderSize - kHeapObjectTag);
2559 DirectCEntryStub stub(isolate());
2560 stub.GenerateCall(masm, code_object);
2562 __ LeaveExitFrame(false, x10, true);
2564 // The generated regexp code returns an int32 in w0.
2565 Label failure, exception;
2566 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::FAILURE, eq, &failure);
2567 __ CompareAndBranch(w0,
2568 NativeRegExpMacroAssembler::EXCEPTION,
2571 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::RETRY, eq, &runtime);
2573 // Success: process the result from the native regexp code.
2574 Register number_of_capture_registers = x12;
2576 // Calculate number of capture registers (number_of_captures + 1) * 2
2577 // and store it in the last match info.
2579 UntagSmiFieldMemOperand(regexp_data,
2580 JSRegExp::kIrregexpCaptureCountOffset));
2581 __ Add(x10, x10, x10);
2582 __ Add(number_of_capture_registers, x10, 2);
2584 // Check that the fourth object is a JSArray object.
2585 DCHECK(jssp.Is(__ StackPointer()));
2586 __ Peek(x10, kLastMatchInfoOffset);
2587 __ JumpIfSmi(x10, &runtime);
2588 __ JumpIfNotObjectType(x10, x11, x11, JS_ARRAY_TYPE, &runtime);
2590 // Check that the JSArray is the fast case.
2591 __ Ldr(last_match_info_elements,
2592 FieldMemOperand(x10, JSArray::kElementsOffset));
2594 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2595 __ JumpIfNotRoot(x10, Heap::kFixedArrayMapRootIndex, &runtime);
2597 // Check that the last match info has space for the capture registers and the
2598 // additional information (overhead).
2599 // (number_of_captures + 1) * 2 + overhead <= last match info size
2600 // (number_of_captures * 2) + 2 + overhead <= last match info size
2601 // number_of_capture_registers + overhead <= last match info size
2603 UntagSmiFieldMemOperand(last_match_info_elements,
2604 FixedArray::kLengthOffset));
2605 __ Add(x11, number_of_capture_registers, RegExpImpl::kLastMatchOverhead);
2609 // Store the capture count.
2610 __ SmiTag(x10, number_of_capture_registers);
2612 FieldMemOperand(last_match_info_elements,
2613 RegExpImpl::kLastCaptureCountOffset));
2614 // Store last subject and last input.
2616 FieldMemOperand(last_match_info_elements,
2617 RegExpImpl::kLastSubjectOffset));
2618 // Use x10 as the subject string in order to only need
2619 // one RecordWriteStub.
2620 __ Mov(x10, subject);
2621 __ RecordWriteField(last_match_info_elements,
2622 RegExpImpl::kLastSubjectOffset,
2628 FieldMemOperand(last_match_info_elements,
2629 RegExpImpl::kLastInputOffset));
2630 __ Mov(x10, subject);
2631 __ RecordWriteField(last_match_info_elements,
2632 RegExpImpl::kLastInputOffset,
2638 Register last_match_offsets = x13;
2639 Register offsets_vector_index = x14;
2640 Register current_offset = x15;
2642 // Get the static offsets vector filled by the native regexp code
2643 // and fill the last match info.
2644 ExternalReference address_of_static_offsets_vector =
2645 ExternalReference::address_of_static_offsets_vector(isolate());
2646 __ Mov(offsets_vector_index, address_of_static_offsets_vector);
2648 Label next_capture, done;
2649 // Capture register counter starts from number of capture registers and
2650 // iterates down to zero (inclusive).
2651 __ Add(last_match_offsets,
2652 last_match_info_elements,
2653 RegExpImpl::kFirstCaptureOffset - kHeapObjectTag);
2654 __ Bind(&next_capture);
2655 __ Subs(number_of_capture_registers, number_of_capture_registers, 2);
2657 // Read two 32 bit values from the static offsets vector buffer into
2659 __ Ldr(current_offset,
2660 MemOperand(offsets_vector_index, kWRegSize * 2, PostIndex));
2661 // Store the smi values in the last match info.
2662 __ SmiTag(x10, current_offset);
2663 // Clearing the 32 bottom bits gives us a Smi.
2664 STATIC_ASSERT(kSmiTag == 0);
2665 __ Bic(x11, current_offset, kSmiShiftMask);
2668 MemOperand(last_match_offsets, kXRegSize * 2, PostIndex));
2669 __ B(&next_capture);
2672 // Return last match info.
2673 __ Peek(x0, kLastMatchInfoOffset);
2674 // Drop the 4 arguments of the stub from the stack.
2678 __ Bind(&exception);
2679 Register exception_value = x0;
2680 // A stack overflow (on the backtrack stack) may have occured
2681 // in the RegExp code but no exception has been created yet.
2682 // If there is no pending exception, handle that in the runtime system.
2683 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
2685 Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2687 __ Ldr(exception_value, MemOperand(x11));
2688 __ Cmp(x10, exception_value);
2691 // For exception, throw the exception again.
2692 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2695 __ Mov(x0, Operand(isolate()->factory()->null_value()));
2696 // Drop the 4 arguments of the stub from the stack.
2701 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2703 // Deferred code for string handling.
2704 // (6) Not a long external string? If yes, go to (8).
2705 __ Bind(¬_seq_nor_cons);
2706 // Compare flags are still set.
2707 __ B(ne, ¬_long_external); // Go to (8).
2709 // (7) External string. Make it, offset-wise, look like a sequential string.
2710 __ Bind(&external_string);
2711 if (masm->emit_debug_code()) {
2712 // Assert that we do not have a cons or slice (indirect strings) here.
2713 // Sequential strings have already been ruled out.
2714 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2715 __ Ldrb(x10, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2716 __ Tst(x10, kIsIndirectStringMask);
2717 __ Check(eq, kExternalStringExpectedButNotFound);
2718 __ And(x10, x10, kStringRepresentationMask);
2720 __ Check(ne, kExternalStringExpectedButNotFound);
2723 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2724 // Move the pointer so that offset-wise, it looks like a sequential string.
2725 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2726 __ Sub(subject, subject, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2727 __ B(&seq_string); // Go to (5).
2729 // (8) If this is a short external string or not a string, bail out to
2731 __ Bind(¬_long_external);
2732 STATIC_ASSERT(kShortExternalStringTag != 0);
2733 __ TestAndBranchIfAnySet(string_representation,
2734 kShortExternalStringMask | kIsNotStringMask,
2737 // (9) Sliced string. Replace subject with parent.
2738 __ Ldr(sliced_string_offset,
2739 UntagSmiFieldMemOperand(subject, SlicedString::kOffsetOffset));
2740 __ Ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2741 __ B(&check_underlying); // Go to (4).
2746 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2747 Register argc, Register function,
2748 Register feedback_vector, Register index,
2749 Register orig_construct, bool is_super) {
2750 FrameScope scope(masm, StackFrame::INTERNAL);
2752 // Number-of-arguments register must be smi-tagged to call out.
2755 __ Push(argc, function, feedback_vector, index, orig_construct);
2757 __ Push(argc, function, feedback_vector, index);
2760 DCHECK(feedback_vector.Is(x2) && index.Is(x3));
2764 __ Pop(orig_construct, index, feedback_vector, function, argc);
2766 __ Pop(index, feedback_vector, function, argc);
2772 static void GenerateRecordCallTarget(MacroAssembler* masm, Register argc,
2774 Register feedback_vector, Register index,
2775 Register orig_construct, Register scratch1,
2776 Register scratch2, Register scratch3,
2778 ASM_LOCATION("GenerateRecordCallTarget");
2779 DCHECK(!AreAliased(scratch1, scratch2, scratch3, argc, function,
2780 feedback_vector, index, orig_construct));
2781 // Cache the called function in a feedback vector slot. Cache states are
2782 // uninitialized, monomorphic (indicated by a JSFunction), and megamorphic.
2783 // argc : number of arguments to the construct function
2784 // function : the function to call
2785 // feedback_vector : the feedback vector
2786 // index : slot in feedback vector (smi)
2787 // orig_construct : original constructor (for IsSuperConstructorCall)
2788 Label initialize, done, miss, megamorphic, not_array_function;
2790 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2791 masm->isolate()->heap()->megamorphic_symbol());
2792 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2793 masm->isolate()->heap()->uninitialized_symbol());
2795 // Load the cache state.
2796 Register feedback = scratch1;
2797 Register feedback_map = scratch2;
2798 Register feedback_value = scratch3;
2799 __ Add(feedback, feedback_vector,
2800 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2801 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
2803 // A monomorphic cache hit or an already megamorphic state: invoke the
2804 // function without changing the state.
2805 // We don't know if feedback value is a WeakCell or a Symbol, but it's
2806 // harmless to read at this position in a symbol (see static asserts in
2807 // type-feedback-vector.h).
2808 Label check_allocation_site;
2809 __ Ldr(feedback_value, FieldMemOperand(feedback, WeakCell::kValueOffset));
2810 __ Cmp(function, feedback_value);
2812 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
2814 __ Ldr(feedback_map, FieldMemOperand(feedback, HeapObject::kMapOffset));
2815 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2816 __ B(ne, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2818 // If the weak cell is cleared, we have a new chance to become monomorphic.
2819 __ JumpIfSmi(feedback_value, &initialize);
2822 if (!FLAG_pretenuring_call_new) {
2823 __ bind(&check_allocation_site);
2824 // If we came here, we need to see if we are the array function.
2825 // If we didn't have a matching function, and we didn't find the megamorph
2826 // sentinel, then we have in the slot either some other function or an
2828 __ JumpIfNotRoot(feedback_map, Heap::kAllocationSiteMapRootIndex, &miss);
2830 // Make sure the function is the Array() function
2831 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2832 __ Cmp(function, scratch1);
2833 __ B(ne, &megamorphic);
2839 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2841 __ JumpIfRoot(scratch1, Heap::kuninitialized_symbolRootIndex, &initialize);
2842 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2843 // write-barrier is needed.
2844 __ Bind(&megamorphic);
2845 __ Add(scratch1, feedback_vector,
2846 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2847 __ LoadRoot(scratch2, Heap::kmegamorphic_symbolRootIndex);
2848 __ Str(scratch2, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
2851 // An uninitialized cache is patched with the function or sentinel to
2852 // indicate the ElementsKind if function is the Array constructor.
2853 __ Bind(&initialize);
2855 if (!FLAG_pretenuring_call_new) {
2856 // Make sure the function is the Array() function
2857 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2858 __ Cmp(function, scratch1);
2859 __ B(ne, ¬_array_function);
2861 // The target function is the Array constructor,
2862 // Create an AllocationSite if we don't already have it, store it in the
2864 CreateAllocationSiteStub create_stub(masm->isolate());
2865 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2866 feedback_vector, index, orig_construct,
2870 __ Bind(¬_array_function);
2873 CreateWeakCellStub create_stub(masm->isolate());
2874 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2875 feedback_vector, index, orig_construct, is_super);
2880 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2881 // Do not transform the receiver for strict mode functions.
2882 __ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
2883 __ Ldr(w4, FieldMemOperand(x3, SharedFunctionInfo::kCompilerHintsOffset));
2884 __ Tbnz(w4, SharedFunctionInfo::kStrictModeFunction, cont);
2886 // Do not transform the receiver for native (Compilerhints already in x3).
2887 __ Tbnz(w4, SharedFunctionInfo::kNative, cont);
2891 static void EmitSlowCase(MacroAssembler* masm,
2895 Label* non_function) {
2896 // Check for function proxy.
2897 // x10 : function type.
2898 __ CompareAndBranch(type, JS_FUNCTION_PROXY_TYPE, ne, non_function);
2899 __ Push(function); // put proxy as additional argument
2900 __ Mov(x0, argc + 1);
2902 __ GetBuiltinFunction(x1, Builtins::CALL_FUNCTION_PROXY);
2904 Handle<Code> adaptor =
2905 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2906 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2909 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2910 // of the original receiver from the call site).
2911 __ Bind(non_function);
2912 __ Poke(function, argc * kXRegSize);
2913 __ Mov(x0, argc); // Set up the number of arguments.
2915 __ GetBuiltinFunction(function, Builtins::CALL_NON_FUNCTION);
2916 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2917 RelocInfo::CODE_TARGET);
2921 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2922 // Wrap the receiver and patch it back onto the stack.
2923 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2925 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2928 __ Poke(x0, argc * kPointerSize);
2933 static void CallFunctionNoFeedback(MacroAssembler* masm,
2934 int argc, bool needs_checks,
2935 bool call_as_method) {
2936 // x1 function the function to call
2937 Register function = x1;
2939 Label slow, non_function, wrap, cont;
2941 // TODO(jbramley): This function has a lot of unnamed registers. Name them,
2942 // and tidy things up a bit.
2945 // Check that the function is really a JavaScript function.
2946 __ JumpIfSmi(function, &non_function);
2948 // Goto slow case if we do not have a function.
2949 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
2952 // Fast-case: Invoke the function now.
2953 // x1 function pushed function
2954 ParameterCount actual(argc);
2956 if (call_as_method) {
2958 EmitContinueIfStrictOrNative(masm, &cont);
2961 // Compute the receiver in sloppy mode.
2962 __ Peek(x3, argc * kPointerSize);
2965 __ JumpIfSmi(x3, &wrap);
2966 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
2974 __ InvokeFunction(function,
2979 // Slow-case: Non-function called.
2981 EmitSlowCase(masm, argc, function, type, &non_function);
2984 if (call_as_method) {
2986 EmitWrapCase(masm, argc, &cont);
2991 void CallFunctionStub::Generate(MacroAssembler* masm) {
2992 ASM_LOCATION("CallFunctionStub::Generate");
2993 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2997 void CallConstructStub::Generate(MacroAssembler* masm) {
2998 ASM_LOCATION("CallConstructStub::Generate");
2999 // x0 : number of arguments
3000 // x1 : the function to call
3001 // x2 : feedback vector
3002 // x3 : slot in feedback vector (Smi, for RecordCallTarget)
3003 // x4 : original constructor (for IsSuperConstructorCall)
3004 Register function = x1;
3005 Label slow, non_function_call;
3007 // Check that the function is not a smi.
3008 __ JumpIfSmi(function, &non_function_call);
3009 // Check that the function is a JSFunction.
3010 Register object_type = x10;
3011 __ JumpIfNotObjectType(function, object_type, object_type, JS_FUNCTION_TYPE,
3014 if (RecordCallTarget()) {
3015 GenerateRecordCallTarget(masm, x0, function, x2, x3, x4, x5, x11, x12,
3016 IsSuperConstructorCall());
3018 __ Add(x5, x2, Operand::UntagSmiAndScale(x3, kPointerSizeLog2));
3019 if (FLAG_pretenuring_call_new) {
3020 // Put the AllocationSite from the feedback vector into x2.
3021 // By adding kPointerSize we encode that we know the AllocationSite
3022 // entry is at the feedback vector slot given by x3 + 1.
3023 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize + kPointerSize));
3025 Label feedback_register_initialized;
3026 // Put the AllocationSite from the feedback vector into x2, or undefined.
3027 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize));
3028 __ Ldr(x5, FieldMemOperand(x2, AllocationSite::kMapOffset));
3029 __ JumpIfRoot(x5, Heap::kAllocationSiteMapRootIndex,
3030 &feedback_register_initialized);
3031 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
3032 __ bind(&feedback_register_initialized);
3035 __ AssertUndefinedOrAllocationSite(x2, x5);
3038 if (IsSuperConstructorCall()) {
3041 __ Mov(x3, function);
3044 // Jump to the function-specific construct stub.
3045 Register jump_reg = x4;
3046 Register shared_func_info = jump_reg;
3047 Register cons_stub = jump_reg;
3048 Register cons_stub_code = jump_reg;
3049 __ Ldr(shared_func_info,
3050 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
3052 FieldMemOperand(shared_func_info,
3053 SharedFunctionInfo::kConstructStubOffset));
3054 __ Add(cons_stub_code, cons_stub, Code::kHeaderSize - kHeapObjectTag);
3055 __ Br(cons_stub_code);
3059 __ Cmp(object_type, JS_FUNCTION_PROXY_TYPE);
3060 __ B(ne, &non_function_call);
3061 __ GetBuiltinFunction(x1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
3064 __ Bind(&non_function_call);
3065 __ GetBuiltinFunction(x1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
3068 // Set expected number of arguments to zero (not changing x0).
3070 __ Jump(isolate()->builtins()->ArgumentsAdaptorTrampoline(),
3071 RelocInfo::CODE_TARGET);
3075 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
3076 __ Ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
3077 __ Ldr(vector, FieldMemOperand(vector,
3078 JSFunction::kSharedFunctionInfoOffset));
3079 __ Ldr(vector, FieldMemOperand(vector,
3080 SharedFunctionInfo::kFeedbackVectorOffset));
3084 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
3089 Register function = x1;
3090 Register feedback_vector = x2;
3091 Register index = x3;
3092 Register scratch = x4;
3094 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch);
3095 __ Cmp(function, scratch);
3098 __ Mov(x0, Operand(arg_count()));
3100 __ Add(scratch, feedback_vector,
3101 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3102 __ Ldr(scratch, FieldMemOperand(scratch, FixedArray::kHeaderSize));
3104 // Verify that scratch contains an AllocationSite
3106 __ Ldr(map, FieldMemOperand(scratch, HeapObject::kMapOffset));
3107 __ JumpIfNotRoot(map, Heap::kAllocationSiteMapRootIndex, &miss);
3109 // Increment the call count for monomorphic function calls.
3110 __ Add(feedback_vector, feedback_vector,
3111 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3112 __ Add(feedback_vector, feedback_vector,
3113 Operand(FixedArray::kHeaderSize + kPointerSize));
3114 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
3115 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3116 __ Str(index, FieldMemOperand(feedback_vector, 0));
3118 Register allocation_site = feedback_vector;
3119 Register original_constructor = index;
3120 __ Mov(allocation_site, scratch);
3121 __ Mov(original_constructor, function);
3122 ArrayConstructorStub stub(masm->isolate(), arg_count());
3123 __ TailCallStub(&stub);
3128 // The slow case, we need this no matter what to complete a call after a miss.
3129 CallFunctionNoFeedback(masm,
3138 void CallICStub::Generate(MacroAssembler* masm) {
3139 ASM_LOCATION("CallICStub");
3142 // x3 - slot id (Smi)
3144 const int with_types_offset =
3145 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
3146 const int generic_offset =
3147 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
3148 Label extra_checks_or_miss, slow_start;
3149 Label slow, non_function, wrap, cont;
3150 Label have_js_function;
3151 int argc = arg_count();
3152 ParameterCount actual(argc);
3154 Register function = x1;
3155 Register feedback_vector = x2;
3156 Register index = x3;
3159 // The checks. First, does x1 match the recorded monomorphic target?
3160 __ Add(x4, feedback_vector,
3161 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3162 __ Ldr(x4, FieldMemOperand(x4, FixedArray::kHeaderSize));
3164 // We don't know that we have a weak cell. We might have a private symbol
3165 // or an AllocationSite, but the memory is safe to examine.
3166 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
3168 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
3169 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
3170 // computed, meaning that it can't appear to be a pointer. If the low bit is
3171 // 0, then hash is computed, but the 0 bit prevents the field from appearing
3173 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
3174 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
3175 WeakCell::kValueOffset &&
3176 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
3178 __ Ldr(x5, FieldMemOperand(x4, WeakCell::kValueOffset));
3179 __ Cmp(x5, function);
3180 __ B(ne, &extra_checks_or_miss);
3182 // The compare above could have been a SMI/SMI comparison. Guard against this
3183 // convincing us that we have a monomorphic JSFunction.
3184 __ JumpIfSmi(function, &extra_checks_or_miss);
3186 // Increment the call count for monomorphic function calls.
3187 __ Add(feedback_vector, feedback_vector,
3188 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3189 __ Add(feedback_vector, feedback_vector,
3190 Operand(FixedArray::kHeaderSize + kPointerSize));
3191 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
3192 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3193 __ Str(index, FieldMemOperand(feedback_vector, 0));
3195 __ bind(&have_js_function);
3196 if (CallAsMethod()) {
3197 EmitContinueIfStrictOrNative(masm, &cont);
3199 // Compute the receiver in sloppy mode.
3200 __ Peek(x3, argc * kPointerSize);
3202 __ JumpIfSmi(x3, &wrap);
3203 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
3208 __ InvokeFunction(function,
3214 EmitSlowCase(masm, argc, function, type, &non_function);
3216 if (CallAsMethod()) {
3218 EmitWrapCase(masm, argc, &cont);
3221 __ bind(&extra_checks_or_miss);
3222 Label uninitialized, miss;
3224 __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &slow_start);
3226 // The following cases attempt to handle MISS cases without going to the
3228 if (FLAG_trace_ic) {
3232 __ JumpIfRoot(x4, Heap::kuninitialized_symbolRootIndex, &miss);
3234 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3235 // to handle it here. More complex cases are dealt with in the runtime.
3236 __ AssertNotSmi(x4);
3237 __ JumpIfNotObjectType(x4, x5, x5, JS_FUNCTION_TYPE, &miss);
3238 __ Add(x4, feedback_vector,
3239 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3240 __ LoadRoot(x5, Heap::kmegamorphic_symbolRootIndex);
3241 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize));
3242 // We have to update statistics for runtime profiling.
3243 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3244 __ Subs(x4, x4, Operand(Smi::FromInt(1)));
3245 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3246 __ Ldr(x4, FieldMemOperand(feedback_vector, generic_offset));
3247 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3248 __ Str(x4, FieldMemOperand(feedback_vector, generic_offset));
3251 __ bind(&uninitialized);
3253 // We are going monomorphic, provided we actually have a JSFunction.
3254 __ JumpIfSmi(function, &miss);
3256 // Goto miss case if we do not have a function.
3257 __ JumpIfNotObjectType(function, x5, x5, JS_FUNCTION_TYPE, &miss);
3259 // Make sure the function is not the Array() function, which requires special
3260 // behavior on MISS.
3261 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, x5);
3262 __ Cmp(function, x5);
3266 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3267 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3268 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3270 // Initialize the call counter.
3271 __ Mov(x5, Smi::FromInt(CallICNexus::kCallCountIncrement));
3272 __ Adds(x4, feedback_vector,
3273 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3274 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize + kPointerSize));
3276 // Store the function. Use a stub since we need a frame for allocation.
3281 FrameScope scope(masm, StackFrame::INTERNAL);
3282 CreateWeakCellStub create_stub(masm->isolate());
3284 __ CallStub(&create_stub);
3288 __ B(&have_js_function);
3290 // We are here because tracing is on or we encountered a MISS case we can't
3296 __ bind(&slow_start);
3298 // Check that the function is really a JavaScript function.
3299 __ JumpIfSmi(function, &non_function);
3301 // Goto slow case if we do not have a function.
3302 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
3303 __ B(&have_js_function);
3307 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3308 ASM_LOCATION("CallICStub[Miss]");
3310 FrameScope scope(masm, StackFrame::INTERNAL);
3312 // Push the receiver and the function and feedback info.
3313 __ Push(x1, x2, x3);
3316 Runtime::FunctionId id = GetICState() == DEFAULT
3317 ? Runtime::kCallIC_Miss
3318 : Runtime::kCallIC_Customization_Miss;
3319 __ CallRuntime(id, 3);
3321 // Move result to edi and exit the internal frame.
3326 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3327 // If the receiver is a smi trigger the non-string case.
3328 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3329 __ JumpIfSmi(object_, receiver_not_string_);
3331 // Fetch the instance type of the receiver into result register.
3332 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3333 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3335 // If the receiver is not a string trigger the non-string case.
3336 __ TestAndBranchIfAnySet(result_, kIsNotStringMask, receiver_not_string_);
3339 // If the index is non-smi trigger the non-smi case.
3340 __ JumpIfNotSmi(index_, &index_not_smi_);
3342 __ Bind(&got_smi_index_);
3343 // Check for index out of range.
3344 __ Ldrsw(result_, UntagSmiFieldMemOperand(object_, String::kLengthOffset));
3345 __ Cmp(result_, Operand::UntagSmi(index_));
3346 __ B(ls, index_out_of_range_);
3348 __ SmiUntag(index_);
3350 StringCharLoadGenerator::Generate(masm,
3360 void StringCharCodeAtGenerator::GenerateSlow(
3361 MacroAssembler* masm, EmbedMode embed_mode,
3362 const RuntimeCallHelper& call_helper) {
3363 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3365 __ Bind(&index_not_smi_);
3366 // If index is a heap number, try converting it to an integer.
3367 __ JumpIfNotHeapNumber(index_, index_not_number_);
3368 call_helper.BeforeCall(masm);
3369 if (embed_mode == PART_OF_IC_HANDLER) {
3370 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3371 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3373 // Save object_ on the stack and pass index_ as argument for runtime call.
3374 __ Push(object_, index_);
3376 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3377 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3379 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3380 // NumberToSmi discards numbers that are not exact integers.
3381 __ CallRuntime(Runtime::kNumberToSmi, 1);
3383 // Save the conversion result before the pop instructions below
3384 // have a chance to overwrite it.
3386 if (embed_mode == PART_OF_IC_HANDLER) {
3387 __ Pop(object_, LoadWithVectorDescriptor::SlotRegister(),
3388 LoadWithVectorDescriptor::VectorRegister());
3392 // Reload the instance type.
3393 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3394 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3395 call_helper.AfterCall(masm);
3397 // If index is still not a smi, it must be out of range.
3398 __ JumpIfNotSmi(index_, index_out_of_range_);
3399 // Otherwise, return to the fast path.
3400 __ B(&got_smi_index_);
3402 // Call runtime. We get here when the receiver is a string and the
3403 // index is a number, but the code of getting the actual character
3404 // is too complex (e.g., when the string needs to be flattened).
3405 __ Bind(&call_runtime_);
3406 call_helper.BeforeCall(masm);
3408 __ Push(object_, index_);
3409 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3410 __ Mov(result_, x0);
3411 call_helper.AfterCall(masm);
3414 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3418 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3419 __ JumpIfNotSmi(code_, &slow_case_);
3420 __ Cmp(code_, Smi::FromInt(String::kMaxOneByteCharCode));
3421 __ B(hi, &slow_case_);
3423 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3424 // At this point code register contains smi tagged one-byte char code.
3425 __ Add(result_, result_, Operand::UntagSmiAndScale(code_, kPointerSizeLog2));
3426 __ Ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3427 __ JumpIfRoot(result_, Heap::kUndefinedValueRootIndex, &slow_case_);
3432 void StringCharFromCodeGenerator::GenerateSlow(
3433 MacroAssembler* masm,
3434 const RuntimeCallHelper& call_helper) {
3435 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3437 __ Bind(&slow_case_);
3438 call_helper.BeforeCall(masm);
3440 __ CallRuntime(Runtime::kCharFromCode, 1);
3441 __ Mov(result_, x0);
3442 call_helper.AfterCall(masm);
3445 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3449 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3450 // Inputs are in x0 (lhs) and x1 (rhs).
3451 DCHECK(state() == CompareICState::SMI);
3452 ASM_LOCATION("CompareICStub[Smis]");
3454 // Bail out (to 'miss') unless both x0 and x1 are smis.
3455 __ JumpIfEitherNotSmi(x0, x1, &miss);
3457 if (GetCondition() == eq) {
3458 // For equality we do not care about the sign of the result.
3461 // Untag before subtracting to avoid handling overflow.
3463 __ Sub(x0, x1, Operand::UntagSmi(x0));
3472 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3473 DCHECK(state() == CompareICState::NUMBER);
3474 ASM_LOCATION("CompareICStub[HeapNumbers]");
3476 Label unordered, maybe_undefined1, maybe_undefined2;
3477 Label miss, handle_lhs, values_in_d_regs;
3478 Label untag_rhs, untag_lhs;
3480 Register result = x0;
3483 FPRegister rhs_d = d0;
3484 FPRegister lhs_d = d1;
3486 if (left() == CompareICState::SMI) {
3487 __ JumpIfNotSmi(lhs, &miss);
3489 if (right() == CompareICState::SMI) {
3490 __ JumpIfNotSmi(rhs, &miss);
3493 __ SmiUntagToDouble(rhs_d, rhs, kSpeculativeUntag);
3494 __ SmiUntagToDouble(lhs_d, lhs, kSpeculativeUntag);
3496 // Load rhs if it's a heap number.
3497 __ JumpIfSmi(rhs, &handle_lhs);
3498 __ JumpIfNotHeapNumber(rhs, &maybe_undefined1);
3499 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
3501 // Load lhs if it's a heap number.
3502 __ Bind(&handle_lhs);
3503 __ JumpIfSmi(lhs, &values_in_d_regs);
3504 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3505 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
3507 __ Bind(&values_in_d_regs);
3508 __ Fcmp(lhs_d, rhs_d);
3509 __ B(vs, &unordered); // Overflow flag set if either is NaN.
3510 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
3511 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
3512 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
3515 __ Bind(&unordered);
3516 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3517 CompareICState::GENERIC, CompareICState::GENERIC);
3518 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3520 __ Bind(&maybe_undefined1);
3521 if (Token::IsOrderedRelationalCompareOp(op())) {
3522 __ JumpIfNotRoot(rhs, Heap::kUndefinedValueRootIndex, &miss);
3523 __ JumpIfSmi(lhs, &unordered);
3524 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3528 __ Bind(&maybe_undefined2);
3529 if (Token::IsOrderedRelationalCompareOp(op())) {
3530 __ JumpIfRoot(lhs, Heap::kUndefinedValueRootIndex, &unordered);
3538 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3539 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3540 ASM_LOCATION("CompareICStub[InternalizedStrings]");
3543 Register result = x0;
3547 // Check that both operands are heap objects.
3548 __ JumpIfEitherSmi(lhs, rhs, &miss);
3550 // Check that both operands are internalized strings.
3551 Register rhs_map = x10;
3552 Register lhs_map = x11;
3553 Register rhs_type = x10;
3554 Register lhs_type = x11;
3555 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3556 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3557 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3558 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3560 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
3561 __ Orr(x12, lhs_type, rhs_type);
3562 __ TestAndBranchIfAnySet(
3563 x12, kIsNotStringMask | kIsNotInternalizedMask, &miss);
3565 // Internalized strings are compared by identity.
3566 STATIC_ASSERT(EQUAL == 0);
3568 __ Cset(result, ne);
3576 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3577 DCHECK(state() == CompareICState::UNIQUE_NAME);
3578 ASM_LOCATION("CompareICStub[UniqueNames]");
3579 DCHECK(GetCondition() == eq);
3582 Register result = x0;
3586 Register lhs_instance_type = w2;
3587 Register rhs_instance_type = w3;
3589 // Check that both operands are heap objects.
3590 __ JumpIfEitherSmi(lhs, rhs, &miss);
3592 // Check that both operands are unique names. This leaves the instance
3593 // types loaded in tmp1 and tmp2.
3594 __ Ldr(x10, FieldMemOperand(lhs, HeapObject::kMapOffset));
3595 __ Ldr(x11, FieldMemOperand(rhs, HeapObject::kMapOffset));
3596 __ Ldrb(lhs_instance_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
3597 __ Ldrb(rhs_instance_type, FieldMemOperand(x11, Map::kInstanceTypeOffset));
3599 // To avoid a miss, each instance type should be either SYMBOL_TYPE or it
3600 // should have kInternalizedTag set.
3601 __ JumpIfNotUniqueNameInstanceType(lhs_instance_type, &miss);
3602 __ JumpIfNotUniqueNameInstanceType(rhs_instance_type, &miss);
3604 // Unique names are compared by identity.
3605 STATIC_ASSERT(EQUAL == 0);
3607 __ Cset(result, ne);
3615 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3616 DCHECK(state() == CompareICState::STRING);
3617 ASM_LOCATION("CompareICStub[Strings]");
3621 bool equality = Token::IsEqualityOp(op());
3623 Register result = x0;
3627 // Check that both operands are heap objects.
3628 __ JumpIfEitherSmi(rhs, lhs, &miss);
3630 // Check that both operands are strings.
3631 Register rhs_map = x10;
3632 Register lhs_map = x11;
3633 Register rhs_type = x10;
3634 Register lhs_type = x11;
3635 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3636 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3637 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3638 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3639 STATIC_ASSERT(kNotStringTag != 0);
3640 __ Orr(x12, lhs_type, rhs_type);
3641 __ Tbnz(x12, MaskToBit(kIsNotStringMask), &miss);
3643 // Fast check for identical strings.
3646 __ B(ne, ¬_equal);
3647 __ Mov(result, EQUAL);
3650 __ Bind(¬_equal);
3651 // Handle not identical strings
3653 // Check that both strings are internalized strings. If they are, we're done
3654 // because we already know they are not identical. We know they are both
3657 DCHECK(GetCondition() == eq);
3658 STATIC_ASSERT(kInternalizedTag == 0);
3659 Label not_internalized_strings;
3660 __ Orr(x12, lhs_type, rhs_type);
3661 __ TestAndBranchIfAnySet(
3662 x12, kIsNotInternalizedMask, ¬_internalized_strings);
3663 // Result is in rhs (x0), and not EQUAL, as rhs is not a smi.
3665 __ Bind(¬_internalized_strings);
3668 // Check that both strings are sequential one-byte.
3670 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x12,
3673 // Compare flat one-byte strings. Returns when done.
3675 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
3678 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
3682 // Handle more complex cases in runtime.
3686 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3688 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3696 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3697 DCHECK(state() == CompareICState::OBJECT);
3698 ASM_LOCATION("CompareICStub[Objects]");
3702 Register result = x0;
3706 __ JumpIfEitherSmi(rhs, lhs, &miss);
3708 __ JumpIfNotObjectType(rhs, x10, x10, JS_OBJECT_TYPE, &miss);
3709 __ JumpIfNotObjectType(lhs, x10, x10, JS_OBJECT_TYPE, &miss);
3711 DCHECK(GetCondition() == eq);
3712 __ Sub(result, rhs, lhs);
3720 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3721 ASM_LOCATION("CompareICStub[KnownObjects]");
3724 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3726 Register result = x0;
3730 __ JumpIfEitherSmi(rhs, lhs, &miss);
3732 Register rhs_map = x10;
3733 Register lhs_map = x11;
3735 __ GetWeakValue(map, cell);
3736 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3737 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3738 __ Cmp(rhs_map, map);
3740 __ Cmp(lhs_map, map);
3743 __ Sub(result, rhs, lhs);
3751 // This method handles the case where a compare stub had the wrong
3752 // implementation. It calls a miss handler, which re-writes the stub. All other
3753 // CompareICStub::Generate* methods should fall back into this one if their
3754 // operands were not the expected types.
3755 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3756 ASM_LOCATION("CompareICStub[Miss]");
3758 Register stub_entry = x11;
3760 FrameScope scope(masm, StackFrame::INTERNAL);
3763 Register right = x0;
3764 // Preserve some caller-saved registers.
3765 __ Push(x1, x0, lr);
3766 // Push the arguments.
3767 __ Mov(op, Smi::FromInt(this->op()));
3768 __ Push(left, right, op);
3770 // Call the miss handler. This also pops the arguments.
3771 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3773 // Compute the entry point of the rewritten stub.
3774 __ Add(stub_entry, x0, Code::kHeaderSize - kHeapObjectTag);
3775 // Restore caller-saved registers.
3779 // Tail-call to the new stub.
3780 __ Jump(stub_entry);
3784 void SubStringStub::Generate(MacroAssembler* masm) {
3785 ASM_LOCATION("SubStringStub::Generate");
3788 // Stack frame on entry.
3789 // lr: return address
3790 // jssp[0]: substring "to" offset
3791 // jssp[8]: substring "from" offset
3792 // jssp[16]: pointer to string object
3794 // This stub is called from the native-call %_SubString(...), so
3795 // nothing can be assumed about the arguments. It is tested that:
3796 // "string" is a sequential string,
3797 // both "from" and "to" are smis, and
3798 // 0 <= from <= to <= string.length (in debug mode.)
3799 // If any of these assumptions fail, we call the runtime system.
3801 static const int kToOffset = 0 * kPointerSize;
3802 static const int kFromOffset = 1 * kPointerSize;
3803 static const int kStringOffset = 2 * kPointerSize;
3806 Register from = x15;
3807 Register input_string = x10;
3808 Register input_length = x11;
3809 Register input_type = x12;
3810 Register result_string = x0;
3811 Register result_length = x1;
3814 __ Peek(to, kToOffset);
3815 __ Peek(from, kFromOffset);
3817 // Check that both from and to are smis. If not, jump to runtime.
3818 __ JumpIfEitherNotSmi(from, to, &runtime);
3822 // Calculate difference between from and to. If to < from, branch to runtime.
3823 __ Subs(result_length, to, from);
3826 // Check from is positive.
3827 __ Tbnz(from, kWSignBit, &runtime);
3829 // Make sure first argument is a string.
3830 __ Peek(input_string, kStringOffset);
3831 __ JumpIfSmi(input_string, &runtime);
3832 __ IsObjectJSStringType(input_string, input_type, &runtime);
3835 __ Cmp(result_length, 1);
3836 __ B(eq, &single_char);
3838 // Short-cut for the case of trivial substring.
3840 __ Ldrsw(input_length,
3841 UntagSmiFieldMemOperand(input_string, String::kLengthOffset));
3843 __ Cmp(result_length, input_length);
3844 __ CmovX(x0, input_string, eq);
3845 // Return original string.
3846 __ B(eq, &return_x0);
3848 // Longer than original string's length or negative: unsafe arguments.
3851 // Shorter than original string's length: an actual substring.
3853 // x0 to substring end character offset
3854 // x1 result_length length of substring result
3855 // x10 input_string pointer to input string object
3856 // x10 unpacked_string pointer to unpacked string object
3857 // x11 input_length length of input string
3858 // x12 input_type instance type of input string
3859 // x15 from substring start character offset
3861 // Deal with different string types: update the index if necessary and put
3862 // the underlying string into register unpacked_string.
3863 Label underlying_unpacked, sliced_string, seq_or_external_string;
3864 Label update_instance_type;
3865 // If the string is not indirect, it can only be sequential or external.
3866 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3867 STATIC_ASSERT(kIsIndirectStringMask != 0);
3869 // Test for string types, and branch/fall through to appropriate unpacking
3871 __ Tst(input_type, kIsIndirectStringMask);
3872 __ B(eq, &seq_or_external_string);
3873 __ Tst(input_type, kSlicedNotConsMask);
3874 __ B(ne, &sliced_string);
3876 Register unpacked_string = input_string;
3878 // Cons string. Check whether it is flat, then fetch first part.
3879 __ Ldr(temp, FieldMemOperand(input_string, ConsString::kSecondOffset));
3880 __ JumpIfNotRoot(temp, Heap::kempty_stringRootIndex, &runtime);
3881 __ Ldr(unpacked_string,
3882 FieldMemOperand(input_string, ConsString::kFirstOffset));
3883 __ B(&update_instance_type);
3885 __ Bind(&sliced_string);
3886 // Sliced string. Fetch parent and correct start index by offset.
3888 UntagSmiFieldMemOperand(input_string, SlicedString::kOffsetOffset));
3889 __ Add(from, from, temp);
3890 __ Ldr(unpacked_string,
3891 FieldMemOperand(input_string, SlicedString::kParentOffset));
3893 __ Bind(&update_instance_type);
3894 __ Ldr(temp, FieldMemOperand(unpacked_string, HeapObject::kMapOffset));
3895 __ Ldrb(input_type, FieldMemOperand(temp, Map::kInstanceTypeOffset));
3896 // Now control must go to &underlying_unpacked. Since the no code is generated
3897 // before then we fall through instead of generating a useless branch.
3899 __ Bind(&seq_or_external_string);
3900 // Sequential or external string. Registers unpacked_string and input_string
3901 // alias, so there's nothing to do here.
3902 // Note that if code is added here, the above code must be updated.
3904 // x0 result_string pointer to result string object (uninit)
3905 // x1 result_length length of substring result
3906 // x10 unpacked_string pointer to unpacked string object
3907 // x11 input_length length of input string
3908 // x12 input_type instance type of input string
3909 // x15 from substring start character offset
3910 __ Bind(&underlying_unpacked);
3912 if (FLAG_string_slices) {
3914 __ Cmp(result_length, SlicedString::kMinLength);
3915 // Short slice. Copy instead of slicing.
3916 __ B(lt, ©_routine);
3917 // Allocate new sliced string. At this point we do not reload the instance
3918 // type including the string encoding because we simply rely on the info
3919 // provided by the original string. It does not matter if the original
3920 // string's encoding is wrong because we always have to recheck encoding of
3921 // the newly created string's parent anyway due to externalized strings.
3922 Label two_byte_slice, set_slice_header;
3923 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3924 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3925 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_slice);
3926 __ AllocateOneByteSlicedString(result_string, result_length, x3, x4,
3928 __ B(&set_slice_header);
3930 __ Bind(&two_byte_slice);
3931 __ AllocateTwoByteSlicedString(result_string, result_length, x3, x4,
3934 __ Bind(&set_slice_header);
3936 __ Str(from, FieldMemOperand(result_string, SlicedString::kOffsetOffset));
3937 __ Str(unpacked_string,
3938 FieldMemOperand(result_string, SlicedString::kParentOffset));
3941 __ Bind(©_routine);
3944 // x0 result_string pointer to result string object (uninit)
3945 // x1 result_length length of substring result
3946 // x10 unpacked_string pointer to unpacked string object
3947 // x11 input_length length of input string
3948 // x12 input_type instance type of input string
3949 // x13 unpacked_char0 pointer to first char of unpacked string (uninit)
3950 // x13 substring_char0 pointer to first char of substring (uninit)
3951 // x14 result_char0 pointer to first char of result (uninit)
3952 // x15 from substring start character offset
3953 Register unpacked_char0 = x13;
3954 Register substring_char0 = x13;
3955 Register result_char0 = x14;
3956 Label two_byte_sequential, sequential_string, allocate_result;
3957 STATIC_ASSERT(kExternalStringTag != 0);
3958 STATIC_ASSERT(kSeqStringTag == 0);
3960 __ Tst(input_type, kExternalStringTag);
3961 __ B(eq, &sequential_string);
3963 __ Tst(input_type, kShortExternalStringTag);
3965 __ Ldr(unpacked_char0,
3966 FieldMemOperand(unpacked_string, ExternalString::kResourceDataOffset));
3967 // unpacked_char0 points to the first character of the underlying string.
3968 __ B(&allocate_result);
3970 __ Bind(&sequential_string);
3971 // Locate first character of underlying subject string.
3972 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3973 __ Add(unpacked_char0, unpacked_string,
3974 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3976 __ Bind(&allocate_result);
3977 // Sequential one-byte string. Allocate the result.
3978 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3979 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_sequential);
3981 // Allocate and copy the resulting one-byte string.
3982 __ AllocateOneByteString(result_string, result_length, x3, x4, x5, &runtime);
3984 // Locate first character of substring to copy.
3985 __ Add(substring_char0, unpacked_char0, from);
3987 // Locate first character of result.
3988 __ Add(result_char0, result_string,
3989 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3991 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3992 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3995 // Allocate and copy the resulting two-byte string.
3996 __ Bind(&two_byte_sequential);
3997 __ AllocateTwoByteString(result_string, result_length, x3, x4, x5, &runtime);
3999 // Locate first character of substring to copy.
4000 __ Add(substring_char0, unpacked_char0, Operand(from, LSL, 1));
4002 // Locate first character of result.
4003 __ Add(result_char0, result_string,
4004 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
4006 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
4007 __ Add(result_length, result_length, result_length);
4008 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
4010 __ Bind(&return_x0);
4011 Counters* counters = isolate()->counters();
4012 __ IncrementCounter(counters->sub_string_native(), 1, x3, x4);
4017 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
4019 __ bind(&single_char);
4020 // x1: result_length
4021 // x10: input_string
4023 // x15: from (untagged)
4025 StringCharAtGenerator generator(input_string, from, result_length, x0,
4026 &runtime, &runtime, &runtime,
4027 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
4028 generator.GenerateFast(masm);
4031 generator.SkipSlow(masm, &runtime);
4035 void ToNumberStub::Generate(MacroAssembler* masm) {
4036 // The ToNumber stub takes one argument in x0.
4038 __ JumpIfNotSmi(x0, ¬_smi);
4042 Label not_heap_number;
4043 __ Ldr(x1, FieldMemOperand(x0, HeapObject::kMapOffset));
4044 __ Ldrb(x1, FieldMemOperand(x1, Map::kInstanceTypeOffset));
4046 // x1: instance type
4047 __ Cmp(x1, HEAP_NUMBER_TYPE);
4048 __ B(ne, ¬_heap_number);
4050 __ Bind(¬_heap_number);
4052 Label not_string, slow_string;
4053 __ Cmp(x1, FIRST_NONSTRING_TYPE);
4054 __ B(hs, ¬_string);
4055 // Check if string has a cached array index.
4056 __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset));
4057 __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask));
4058 __ B(ne, &slow_string);
4059 __ IndexFromHash(x2, x0);
4061 __ Bind(&slow_string);
4062 __ Push(x0); // Push argument.
4063 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
4064 __ Bind(¬_string);
4067 __ Cmp(x1, ODDBALL_TYPE);
4068 __ B(ne, ¬_oddball);
4069 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
4071 __ Bind(¬_oddball);
4073 __ Push(x0); // Push argument.
4074 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
4078 void StringHelper::GenerateFlatOneByteStringEquals(
4079 MacroAssembler* masm, Register left, Register right, Register scratch1,
4080 Register scratch2, Register scratch3) {
4081 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3));
4082 Register result = x0;
4083 Register left_length = scratch1;
4084 Register right_length = scratch2;
4086 // Compare lengths. If lengths differ, strings can't be equal. Lengths are
4087 // smis, and don't need to be untagged.
4088 Label strings_not_equal, check_zero_length;
4089 __ Ldr(left_length, FieldMemOperand(left, String::kLengthOffset));
4090 __ Ldr(right_length, FieldMemOperand(right, String::kLengthOffset));
4091 __ Cmp(left_length, right_length);
4092 __ B(eq, &check_zero_length);
4094 __ Bind(&strings_not_equal);
4095 __ Mov(result, Smi::FromInt(NOT_EQUAL));
4098 // Check if the length is zero. If so, the strings must be equal (and empty.)
4099 Label compare_chars;
4100 __ Bind(&check_zero_length);
4101 STATIC_ASSERT(kSmiTag == 0);
4102 __ Cbnz(left_length, &compare_chars);
4103 __ Mov(result, Smi::FromInt(EQUAL));
4106 // Compare characters. Falls through if all characters are equal.
4107 __ Bind(&compare_chars);
4108 GenerateOneByteCharsCompareLoop(masm, left, right, left_length, scratch2,
4109 scratch3, &strings_not_equal);
4111 // Characters in strings are equal.
4112 __ Mov(result, Smi::FromInt(EQUAL));
4117 void StringHelper::GenerateCompareFlatOneByteStrings(
4118 MacroAssembler* masm, Register left, Register right, Register scratch1,
4119 Register scratch2, Register scratch3, Register scratch4) {
4120 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3, scratch4));
4121 Label result_not_equal, compare_lengths;
4123 // Find minimum length and length difference.
4124 Register length_delta = scratch3;
4125 __ Ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
4126 __ Ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
4127 __ Subs(length_delta, scratch1, scratch2);
4129 Register min_length = scratch1;
4130 __ Csel(min_length, scratch2, scratch1, gt);
4131 __ Cbz(min_length, &compare_lengths);
4134 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
4135 scratch4, &result_not_equal);
4137 // Compare lengths - strings up to min-length are equal.
4138 __ Bind(&compare_lengths);
4140 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
4142 // Use length_delta as result if it's zero.
4143 Register result = x0;
4144 __ Subs(result, length_delta, 0);
4146 __ Bind(&result_not_equal);
4147 Register greater = x10;
4148 Register less = x11;
4149 __ Mov(greater, Smi::FromInt(GREATER));
4150 __ Mov(less, Smi::FromInt(LESS));
4151 __ CmovX(result, greater, gt);
4152 __ CmovX(result, less, lt);
4157 void StringHelper::GenerateOneByteCharsCompareLoop(
4158 MacroAssembler* masm, Register left, Register right, Register length,
4159 Register scratch1, Register scratch2, Label* chars_not_equal) {
4160 DCHECK(!AreAliased(left, right, length, scratch1, scratch2));
4162 // Change index to run from -length to -1 by adding length to string
4163 // start. This means that loop ends when index reaches zero, which
4164 // doesn't need an additional compare.
4165 __ SmiUntag(length);
4166 __ Add(scratch1, length, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4167 __ Add(left, left, scratch1);
4168 __ Add(right, right, scratch1);
4170 Register index = length;
4171 __ Neg(index, length); // index = -length;
4176 __ Ldrb(scratch1, MemOperand(left, index));
4177 __ Ldrb(scratch2, MemOperand(right, index));
4178 __ Cmp(scratch1, scratch2);
4179 __ B(ne, chars_not_equal);
4180 __ Add(index, index, 1);
4181 __ Cbnz(index, &loop);
4185 void StringCompareStub::Generate(MacroAssembler* masm) {
4188 Counters* counters = isolate()->counters();
4190 // Stack frame on entry.
4191 // sp[0]: right string
4192 // sp[8]: left string
4193 Register right = x10;
4194 Register left = x11;
4195 Register result = x0;
4196 __ Pop(right, left);
4199 __ Subs(result, right, left);
4200 __ B(ne, ¬_same);
4201 STATIC_ASSERT(EQUAL == 0);
4202 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4207 // Check that both objects are sequential one-byte strings.
4208 __ JumpIfEitherIsNotSequentialOneByteStrings(left, right, x12, x13, &runtime);
4210 // Compare flat one-byte strings natively. Remove arguments from stack first,
4211 // as this function will generate a return.
4212 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4213 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, x12, x13,
4218 // Push arguments back on to the stack.
4219 // sp[0] = right string
4220 // sp[8] = left string.
4221 __ Push(left, right);
4223 // Call the runtime.
4224 // Returns -1 (less), 0 (equal), or 1 (greater) tagged as a small integer.
4225 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
4229 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4230 // ----------- S t a t e -------------
4233 // -- lr : return address
4234 // -----------------------------------
4236 // Load x2 with the allocation site. We stick an undefined dummy value here
4237 // and replace it with the real allocation site later when we instantiate this
4238 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
4239 __ LoadObject(x2, handle(isolate()->heap()->undefined_value()));
4241 // Make sure that we actually patched the allocation site.
4242 if (FLAG_debug_code) {
4243 __ AssertNotSmi(x2, kExpectedAllocationSite);
4244 __ Ldr(x10, FieldMemOperand(x2, HeapObject::kMapOffset));
4245 __ AssertRegisterIsRoot(x10, Heap::kAllocationSiteMapRootIndex,
4246 kExpectedAllocationSite);
4249 // Tail call into the stub that handles binary operations with allocation
4251 BinaryOpWithAllocationSiteStub stub(isolate(), state());
4252 __ TailCallStub(&stub);
4256 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4257 // We need some extra registers for this stub, they have been allocated
4258 // but we need to save them before using them.
4261 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4262 Label dont_need_remembered_set;
4264 Register val = regs_.scratch0();
4265 __ Ldr(val, MemOperand(regs_.address()));
4266 __ JumpIfNotInNewSpace(val, &dont_need_remembered_set);
4268 __ CheckPageFlagSet(regs_.object(), val, 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4269 &dont_need_remembered_set);
4271 // First notify the incremental marker if necessary, then update the
4273 CheckNeedsToInformIncrementalMarker(
4274 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4275 InformIncrementalMarker(masm);
4276 regs_.Restore(masm); // Restore the extra scratch registers we used.
4278 __ RememberedSetHelper(object(), address(),
4279 value(), // scratch1
4280 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4282 __ Bind(&dont_need_remembered_set);
4285 CheckNeedsToInformIncrementalMarker(
4286 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4287 InformIncrementalMarker(masm);
4288 regs_.Restore(masm); // Restore the extra scratch registers we used.
4293 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4294 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4296 x0.Is(regs_.address()) ? regs_.scratch0() : regs_.address();
4297 DCHECK(!address.Is(regs_.object()));
4298 DCHECK(!address.Is(x0));
4299 __ Mov(address, regs_.address());
4300 __ Mov(x0, regs_.object());
4301 __ Mov(x1, address);
4302 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4304 AllowExternalCallThatCantCauseGC scope(masm);
4305 ExternalReference function =
4306 ExternalReference::incremental_marking_record_write_function(
4308 __ CallCFunction(function, 3, 0);
4310 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4314 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4315 MacroAssembler* masm,
4316 OnNoNeedToInformIncrementalMarker on_no_need,
4319 Label need_incremental;
4320 Label need_incremental_pop_scratch;
4322 Register mem_chunk = regs_.scratch0();
4323 Register counter = regs_.scratch1();
4324 __ Bic(mem_chunk, regs_.object(), Page::kPageAlignmentMask);
4326 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4327 __ Subs(counter, counter, 1);
4329 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4330 __ B(mi, &need_incremental);
4332 // If the object is not black we don't have to inform the incremental marker.
4333 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4335 regs_.Restore(masm); // Restore the extra scratch registers we used.
4336 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4337 __ RememberedSetHelper(object(), address(),
4338 value(), // scratch1
4339 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4345 // Get the value from the slot.
4346 Register val = regs_.scratch0();
4347 __ Ldr(val, MemOperand(regs_.address()));
4349 if (mode == INCREMENTAL_COMPACTION) {
4350 Label ensure_not_white;
4352 __ CheckPageFlagClear(val, regs_.scratch1(),
4353 MemoryChunk::kEvacuationCandidateMask,
4356 __ CheckPageFlagClear(regs_.object(),
4358 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4361 __ Bind(&ensure_not_white);
4364 // We need extra registers for this, so we push the object and the address
4365 // register temporarily.
4366 __ Push(regs_.address(), regs_.object());
4367 __ EnsureNotWhite(val,
4368 regs_.scratch1(), // Scratch.
4369 regs_.object(), // Scratch.
4370 regs_.address(), // Scratch.
4371 regs_.scratch2(), // Scratch.
4372 &need_incremental_pop_scratch);
4373 __ Pop(regs_.object(), regs_.address());
4375 regs_.Restore(masm); // Restore the extra scratch registers we used.
4376 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4377 __ RememberedSetHelper(object(), address(),
4378 value(), // scratch1
4379 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4384 __ Bind(&need_incremental_pop_scratch);
4385 __ Pop(regs_.object(), regs_.address());
4387 __ Bind(&need_incremental);
4388 // Fall through when we need to inform the incremental marker.
4392 void RecordWriteStub::Generate(MacroAssembler* masm) {
4393 Label skip_to_incremental_noncompacting;
4394 Label skip_to_incremental_compacting;
4396 // We patch these two first instructions back and forth between a nop and
4397 // real branch when we start and stop incremental heap marking.
4398 // Initially the stub is expected to be in STORE_BUFFER_ONLY mode, so 2 nops
4400 // See RecordWriteStub::Patch for details.
4402 InstructionAccurateScope scope(masm, 2);
4403 __ adr(xzr, &skip_to_incremental_noncompacting);
4404 __ adr(xzr, &skip_to_incremental_compacting);
4407 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4408 __ RememberedSetHelper(object(), address(),
4409 value(), // scratch1
4410 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4414 __ Bind(&skip_to_incremental_noncompacting);
4415 GenerateIncremental(masm, INCREMENTAL);
4417 __ Bind(&skip_to_incremental_compacting);
4418 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4422 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4423 // x0 value element value to store
4424 // x3 index_smi element index as smi
4425 // sp[0] array_index_smi array literal index in function as smi
4426 // sp[1] array array literal
4428 Register value = x0;
4429 Register index_smi = x3;
4431 Register array = x1;
4432 Register array_map = x2;
4433 Register array_index_smi = x4;
4434 __ PeekPair(array_index_smi, array, 0);
4435 __ Ldr(array_map, FieldMemOperand(array, JSObject::kMapOffset));
4437 Label double_elements, smi_element, fast_elements, slow_elements;
4438 Register bitfield2 = x10;
4439 __ Ldrb(bitfield2, FieldMemOperand(array_map, Map::kBitField2Offset));
4441 // Jump if array's ElementsKind is not FAST*_SMI_ELEMENTS, FAST_ELEMENTS or
4442 // FAST_HOLEY_ELEMENTS.
4443 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4444 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4445 STATIC_ASSERT(FAST_ELEMENTS == 2);
4446 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4447 __ Cmp(bitfield2, Map::kMaximumBitField2FastHoleyElementValue);
4448 __ B(hi, &double_elements);
4450 __ JumpIfSmi(value, &smi_element);
4452 // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS.
4453 __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::ElementsKindBits::kShift),
4456 // Store into the array literal requires an elements transition. Call into
4458 __ Bind(&slow_elements);
4459 __ Push(array, index_smi, value);
4460 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4461 __ Ldr(x11, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
4462 __ Push(x11, array_index_smi);
4463 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4465 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4466 __ Bind(&fast_elements);
4467 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4468 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4469 __ Add(x11, x11, FixedArray::kHeaderSize - kHeapObjectTag);
4470 __ Str(value, MemOperand(x11));
4471 // Update the write barrier for the array store.
4472 __ RecordWrite(x10, x11, value, kLRHasNotBeenSaved, kDontSaveFPRegs,
4473 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4476 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4477 // and value is Smi.
4478 __ Bind(&smi_element);
4479 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4480 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4481 __ Str(value, FieldMemOperand(x11, FixedArray::kHeaderSize));
4484 __ Bind(&double_elements);
4485 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4486 __ StoreNumberToDoubleElements(value, index_smi, x10, x11, d0,
4492 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4493 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4494 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4495 int parameter_count_offset =
4496 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4497 __ Ldr(x1, MemOperand(fp, parameter_count_offset));
4498 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4501 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4503 // Return to IC Miss stub, continuation still on stack.
4508 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4509 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4510 LoadICStub stub(isolate(), state());
4511 stub.GenerateForTrampoline(masm);
4515 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4516 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4517 KeyedLoadICStub stub(isolate(), state());
4518 stub.GenerateForTrampoline(masm);
4522 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4523 EmitLoadTypeFeedbackVector(masm, x2);
4524 CallICStub stub(isolate(), state());
4525 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4529 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4530 EmitLoadTypeFeedbackVector(masm, x2);
4531 CallIC_ArrayStub stub(isolate(), state());
4532 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4536 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4539 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4540 GenerateImpl(masm, true);
4544 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4545 Register key, Register vector, Register slot,
4546 Register feedback, Register receiver_map,
4547 Register scratch1, Register scratch2,
4548 bool is_polymorphic, Label* miss) {
4549 // feedback initially contains the feedback array
4550 Label next_loop, prepare_next;
4551 Label load_smi_map, compare_map;
4552 Label start_polymorphic;
4554 Register cached_map = scratch1;
4557 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4558 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4559 __ Cmp(receiver_map, cached_map);
4560 __ B(ne, &start_polymorphic);
4561 // found, now call handler.
4562 Register handler = feedback;
4563 __ Ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4564 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4567 Register length = scratch2;
4568 __ Bind(&start_polymorphic);
4569 __ Ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4570 if (!is_polymorphic) {
4571 __ Cmp(length, Operand(Smi::FromInt(2)));
4575 Register too_far = length;
4576 Register pointer_reg = feedback;
4578 // +-----+------+------+-----+-----+ ... ----+
4579 // | map | len | wm0 | h0 | wm1 | hN |
4580 // +-----+------+------+-----+-----+ ... ----+
4584 // pointer_reg too_far
4585 // aka feedback scratch2
4586 // also need receiver_map
4587 // use cached_map (scratch1) to look in the weak map values.
4588 __ Add(too_far, feedback,
4589 Operand::UntagSmiAndScale(length, kPointerSizeLog2));
4590 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
4591 __ Add(pointer_reg, feedback,
4592 FixedArray::OffsetOfElementAt(2) - kHeapObjectTag);
4594 __ Bind(&next_loop);
4595 __ Ldr(cached_map, MemOperand(pointer_reg));
4596 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4597 __ Cmp(receiver_map, cached_map);
4598 __ B(ne, &prepare_next);
4599 __ Ldr(handler, MemOperand(pointer_reg, kPointerSize));
4600 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4603 __ Bind(&prepare_next);
4604 __ Add(pointer_reg, pointer_reg, kPointerSize * 2);
4605 __ Cmp(pointer_reg, too_far);
4606 __ B(lt, &next_loop);
4608 // We exhausted our array of map handler pairs.
4613 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4614 Register receiver_map, Register feedback,
4615 Register vector, Register slot,
4616 Register scratch, Label* compare_map,
4617 Label* load_smi_map, Label* try_array) {
4618 __ JumpIfSmi(receiver, load_smi_map);
4619 __ Ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4620 __ bind(compare_map);
4621 Register cached_map = scratch;
4622 // Move the weak map into the weak_cell register.
4623 __ Ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4624 __ Cmp(cached_map, receiver_map);
4625 __ B(ne, try_array);
4627 Register handler = feedback;
4628 __ Add(handler, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4630 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4631 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4636 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4637 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4638 Register name = LoadWithVectorDescriptor::NameRegister(); // x2
4639 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4640 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4641 Register feedback = x4;
4642 Register receiver_map = x5;
4643 Register scratch1 = x6;
4645 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4646 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4648 // Try to quickly handle the monomorphic case without knowing for sure
4649 // if we have a weak cell in feedback. We do know it's safe to look
4650 // at WeakCell::kValueOffset.
4651 Label try_array, load_smi_map, compare_map;
4652 Label not_array, miss;
4653 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4654 scratch1, &compare_map, &load_smi_map, &try_array);
4656 // Is it a fixed array?
4657 __ Bind(&try_array);
4658 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4659 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4660 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4661 scratch1, x7, true, &miss);
4663 __ Bind(¬_array);
4664 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
4665 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4666 Code::ComputeHandlerFlags(Code::LOAD_IC));
4667 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4668 false, receiver, name, feedback,
4669 receiver_map, scratch1, x7);
4672 LoadIC::GenerateMiss(masm);
4674 __ Bind(&load_smi_map);
4675 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4676 __ jmp(&compare_map);
4680 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4681 GenerateImpl(masm, false);
4685 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4686 GenerateImpl(masm, true);
4690 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4691 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4692 Register key = LoadWithVectorDescriptor::NameRegister(); // x2
4693 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4694 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4695 Register feedback = x4;
4696 Register receiver_map = x5;
4697 Register scratch1 = x6;
4699 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4700 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4702 // Try to quickly handle the monomorphic case without knowing for sure
4703 // if we have a weak cell in feedback. We do know it's safe to look
4704 // at WeakCell::kValueOffset.
4705 Label try_array, load_smi_map, compare_map;
4706 Label not_array, miss;
4707 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4708 scratch1, &compare_map, &load_smi_map, &try_array);
4710 __ Bind(&try_array);
4711 // Is it a fixed array?
4712 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4713 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4715 // We have a polymorphic element handler.
4716 Label polymorphic, try_poly_name;
4717 __ Bind(&polymorphic);
4718 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4719 scratch1, x7, true, &miss);
4721 __ Bind(¬_array);
4723 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
4725 Handle<Code> megamorphic_stub =
4726 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4727 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4729 __ Bind(&try_poly_name);
4730 // We might have a name in feedback, and a fixed array in the next slot.
4731 __ Cmp(key, feedback);
4733 // If the name comparison succeeded, we know we have a fixed array with
4734 // at least one map/handler pair.
4735 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4737 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4738 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4739 scratch1, x7, false, &miss);
4742 KeyedLoadIC::GenerateMiss(masm);
4744 __ Bind(&load_smi_map);
4745 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4746 __ jmp(&compare_map);
4750 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4751 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4752 VectorStoreICStub stub(isolate(), state());
4753 stub.GenerateForTrampoline(masm);
4757 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4758 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4759 VectorKeyedStoreICStub stub(isolate(), state());
4760 stub.GenerateForTrampoline(masm);
4764 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4765 GenerateImpl(masm, false);
4769 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4770 GenerateImpl(masm, true);
4774 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4777 // TODO(mvstanton): Implement.
4779 StoreIC::GenerateMiss(masm);
4783 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4784 GenerateImpl(masm, false);
4788 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4789 GenerateImpl(masm, true);
4793 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4796 // TODO(mvstanton): Implement.
4798 KeyedStoreIC::GenerateMiss(masm);
4802 // The entry hook is a "BumpSystemStackPointer" instruction (sub), followed by
4803 // a "Push lr" instruction, followed by a call.
4804 static const unsigned int kProfileEntryHookCallSize =
4805 Assembler::kCallSizeWithRelocation + (2 * kInstructionSize);
4808 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4809 if (masm->isolate()->function_entry_hook() != NULL) {
4810 ProfileEntryHookStub stub(masm->isolate());
4811 Assembler::BlockConstPoolScope no_const_pools(masm);
4812 DontEmitDebugCodeScope no_debug_code(masm);
4813 Label entry_hook_call_start;
4814 __ Bind(&entry_hook_call_start);
4817 DCHECK(masm->SizeOfCodeGeneratedSince(&entry_hook_call_start) ==
4818 kProfileEntryHookCallSize);
4825 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4826 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
4828 // Save all kCallerSaved registers (including lr), since this can be called
4830 // TODO(jbramley): What about FP registers?
4831 __ PushCPURegList(kCallerSaved);
4832 DCHECK(kCallerSaved.IncludesAliasOf(lr));
4833 const int kNumSavedRegs = kCallerSaved.Count();
4835 // Compute the function's address as the first argument.
4836 __ Sub(x0, lr, kProfileEntryHookCallSize);
4838 #if V8_HOST_ARCH_ARM64
4839 uintptr_t entry_hook =
4840 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
4841 __ Mov(x10, entry_hook);
4843 // Under the simulator we need to indirect the entry hook through a trampoline
4844 // function at a known address.
4845 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4846 __ Mov(x10, Operand(ExternalReference(&dispatcher,
4847 ExternalReference::BUILTIN_CALL,
4849 // It additionally takes an isolate as a third parameter
4850 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4853 // The caller's return address is above the saved temporaries.
4854 // Grab its location for the second argument to the hook.
4855 __ Add(x1, __ StackPointer(), kNumSavedRegs * kPointerSize);
4858 // Create a dummy frame, as CallCFunction requires this.
4859 FrameScope frame(masm, StackFrame::MANUAL);
4860 __ CallCFunction(x10, 2, 0);
4863 __ PopCPURegList(kCallerSaved);
4868 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4869 // When calling into C++ code the stack pointer must be csp.
4870 // Therefore this code must use csp for peek/poke operations when the
4871 // stub is generated. When the stub is called
4872 // (via DirectCEntryStub::GenerateCall), the caller must setup an ExitFrame
4873 // and configure the stack pointer *before* doing the call.
4874 const Register old_stack_pointer = __ StackPointer();
4875 __ SetStackPointer(csp);
4877 // Put return address on the stack (accessible to GC through exit frame pc).
4879 // Call the C++ function.
4881 // Return to calling code.
4883 __ AssertFPCRState();
4886 __ SetStackPointer(old_stack_pointer);
4889 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4891 // Make sure the caller configured the stack pointer (see comment in
4892 // DirectCEntryStub::Generate).
4893 DCHECK(csp.Is(__ StackPointer()));
4896 reinterpret_cast<intptr_t>(GetCode().location());
4897 __ Mov(lr, Operand(code, RelocInfo::CODE_TARGET));
4898 __ Mov(x10, target);
4899 // Branch to the stub.
4904 // Probe the name dictionary in the 'elements' register.
4905 // Jump to the 'done' label if a property with the given name is found.
4906 // Jump to the 'miss' label otherwise.
4908 // If lookup was successful 'scratch2' will be equal to elements + 4 * index.
4909 // 'elements' and 'name' registers are preserved on miss.
4910 void NameDictionaryLookupStub::GeneratePositiveLookup(
4911 MacroAssembler* masm,
4917 Register scratch2) {
4918 DCHECK(!AreAliased(elements, name, scratch1, scratch2));
4920 // Assert that name contains a string.
4921 __ AssertName(name);
4923 // Compute the capacity mask.
4924 __ Ldrsw(scratch1, UntagSmiFieldMemOperand(elements, kCapacityOffset));
4925 __ Sub(scratch1, scratch1, 1);
4927 // Generate an unrolled loop that performs a few probes before giving up.
4928 for (int i = 0; i < kInlinedProbes; i++) {
4929 // Compute the masked index: (hash + i + i * i) & mask.
4930 __ Ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4932 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4933 // the hash in a separate instruction. The value hash + i + i * i is right
4934 // shifted in the following and instruction.
4935 DCHECK(NameDictionary::GetProbeOffset(i) <
4936 1 << (32 - Name::kHashFieldOffset));
4937 __ Add(scratch2, scratch2, Operand(
4938 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4940 __ And(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
4942 // Scale the index by multiplying by the element size.
4943 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4944 __ Add(scratch2, scratch2, Operand(scratch2, LSL, 1));
4946 // Check if the key is identical to the name.
4947 UseScratchRegisterScope temps(masm);
4948 Register scratch3 = temps.AcquireX();
4949 __ Add(scratch2, elements, Operand(scratch2, LSL, kPointerSizeLog2));
4950 __ Ldr(scratch3, FieldMemOperand(scratch2, kElementsStartOffset));
4951 __ Cmp(name, scratch3);
4955 // The inlined probes didn't find the entry.
4956 // Call the complete stub to scan the whole dictionary.
4958 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4959 spill_list.Combine(lr);
4960 spill_list.Remove(scratch1);
4961 spill_list.Remove(scratch2);
4963 __ PushCPURegList(spill_list);
4966 DCHECK(!elements.is(x1));
4968 __ Mov(x0, elements);
4970 __ Mov(x0, elements);
4975 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4977 __ Cbz(x0, ¬_found);
4978 __ Mov(scratch2, x2); // Move entry index into scratch2.
4979 __ PopCPURegList(spill_list);
4982 __ Bind(¬_found);
4983 __ PopCPURegList(spill_list);
4988 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4992 Register properties,
4994 Register scratch0) {
4995 DCHECK(!AreAliased(receiver, properties, scratch0));
4996 DCHECK(name->IsUniqueName());
4997 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4998 // not equal to the name and kProbes-th slot is not used (its name is the
4999 // undefined value), it guarantees the hash table doesn't contain the
5000 // property. It's true even if some slots represent deleted properties
5001 // (their names are the hole value).
5002 for (int i = 0; i < kInlinedProbes; i++) {
5003 // scratch0 points to properties hash.
5004 // Compute the masked index: (hash + i + i * i) & mask.
5005 Register index = scratch0;
5006 // Capacity is smi 2^n.
5007 __ Ldrsw(index, UntagSmiFieldMemOperand(properties, kCapacityOffset));
5008 __ Sub(index, index, 1);
5009 __ And(index, index, name->Hash() + NameDictionary::GetProbeOffset(i));
5011 // Scale the index by multiplying by the entry size.
5012 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
5013 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5015 Register entity_name = scratch0;
5016 // Having undefined at this place means the name is not contained.
5017 Register tmp = index;
5018 __ Add(tmp, properties, Operand(index, LSL, kPointerSizeLog2));
5019 __ Ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
5021 __ JumpIfRoot(entity_name, Heap::kUndefinedValueRootIndex, done);
5023 // Stop if found the property.
5024 __ Cmp(entity_name, Operand(name));
5028 __ JumpIfRoot(entity_name, Heap::kTheHoleValueRootIndex, &good);
5030 // Check if the entry name is not a unique name.
5031 __ Ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
5032 __ Ldrb(entity_name,
5033 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
5034 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
5038 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
5039 spill_list.Combine(lr);
5040 spill_list.Remove(scratch0); // Scratch registers don't need to be preserved.
5042 __ PushCPURegList(spill_list);
5044 __ Ldr(x0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
5045 __ Mov(x1, Operand(name));
5046 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
5048 // Move stub return value to scratch0. Note that scratch0 is not included in
5049 // spill_list and won't be clobbered by PopCPURegList.
5050 __ Mov(scratch0, x0);
5051 __ PopCPURegList(spill_list);
5053 __ Cbz(scratch0, done);
5058 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
5059 // This stub overrides SometimesSetsUpAFrame() to return false. That means
5060 // we cannot call anything that could cause a GC from this stub.
5062 // Arguments are in x0 and x1:
5063 // x0: property dictionary.
5064 // x1: the name of the property we are looking for.
5066 // Return value is in x0 and is zero if lookup failed, non zero otherwise.
5067 // If the lookup is successful, x2 will contains the index of the entry.
5069 Register result = x0;
5070 Register dictionary = x0;
5072 Register index = x2;
5075 Register undefined = x5;
5076 Register entry_key = x6;
5078 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
5080 __ Ldrsw(mask, UntagSmiFieldMemOperand(dictionary, kCapacityOffset));
5081 __ Sub(mask, mask, 1);
5083 __ Ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
5084 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
5086 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
5087 // Compute the masked index: (hash + i + i * i) & mask.
5088 // Capacity is smi 2^n.
5090 // Add the probe offset (i + i * i) left shifted to avoid right shifting
5091 // the hash in a separate instruction. The value hash + i + i * i is right
5092 // shifted in the following and instruction.
5093 DCHECK(NameDictionary::GetProbeOffset(i) <
5094 1 << (32 - Name::kHashFieldOffset));
5096 NameDictionary::GetProbeOffset(i) << Name::kHashShift);
5098 __ Mov(index, hash);
5100 __ And(index, mask, Operand(index, LSR, Name::kHashShift));
5102 // Scale the index by multiplying by the entry size.
5103 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
5104 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5106 __ Add(index, dictionary, Operand(index, LSL, kPointerSizeLog2));
5107 __ Ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
5109 // Having undefined at this place means the name is not contained.
5110 __ Cmp(entry_key, undefined);
5111 __ B(eq, ¬_in_dictionary);
5113 // Stop if found the property.
5114 __ Cmp(entry_key, key);
5115 __ B(eq, &in_dictionary);
5117 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
5118 // Check if the entry name is not a unique name.
5119 __ Ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
5120 __ Ldrb(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
5121 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
5125 __ Bind(&maybe_in_dictionary);
5126 // If we are doing negative lookup then probing failure should be
5127 // treated as a lookup success. For positive lookup, probing failure
5128 // should be treated as lookup failure.
5129 if (mode() == POSITIVE_LOOKUP) {
5134 __ Bind(&in_dictionary);
5138 __ Bind(¬_in_dictionary);
5145 static void CreateArrayDispatch(MacroAssembler* masm,
5146 AllocationSiteOverrideMode mode) {
5147 ASM_LOCATION("CreateArrayDispatch");
5148 if (mode == DISABLE_ALLOCATION_SITES) {
5149 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5150 __ TailCallStub(&stub);
5152 } else if (mode == DONT_OVERRIDE) {
5155 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5156 for (int i = 0; i <= last_index; ++i) {
5158 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5159 // TODO(jbramley): Is this the best way to handle this? Can we make the
5160 // tail calls conditional, rather than hopping over each one?
5161 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5162 T stub(masm->isolate(), candidate_kind);
5163 __ TailCallStub(&stub);
5167 // If we reached this point there is a problem.
5168 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5176 // TODO(jbramley): If this needs to be a special case, make it a proper template
5177 // specialization, and not a separate function.
5178 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5179 AllocationSiteOverrideMode mode) {
5180 ASM_LOCATION("CreateArrayDispatchOneArgument");
5182 // x1 - constructor?
5183 // x2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5184 // x3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5185 // sp[0] - last argument
5187 Register allocation_site = x2;
5190 Label normal_sequence;
5191 if (mode == DONT_OVERRIDE) {
5192 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5193 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5194 STATIC_ASSERT(FAST_ELEMENTS == 2);
5195 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5196 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5197 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5199 // Is the low bit set? If so, the array is holey.
5200 __ Tbnz(kind, 0, &normal_sequence);
5203 // Look at the last argument.
5204 // TODO(jbramley): What does a 0 argument represent?
5206 __ Cbz(x10, &normal_sequence);
5208 if (mode == DISABLE_ALLOCATION_SITES) {
5209 ElementsKind initial = GetInitialFastElementsKind();
5210 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5212 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5214 DISABLE_ALLOCATION_SITES);
5215 __ TailCallStub(&stub_holey);
5217 __ Bind(&normal_sequence);
5218 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5220 DISABLE_ALLOCATION_SITES);
5221 __ TailCallStub(&stub);
5222 } else if (mode == DONT_OVERRIDE) {
5223 // We are going to create a holey array, but our kind is non-holey.
5224 // Fix kind and retry (only if we have an allocation site in the slot).
5225 __ Orr(kind, kind, 1);
5227 if (FLAG_debug_code) {
5228 __ Ldr(x10, FieldMemOperand(allocation_site, 0));
5229 __ JumpIfNotRoot(x10, Heap::kAllocationSiteMapRootIndex,
5231 __ Assert(eq, kExpectedAllocationSite);
5234 // Save the resulting elements kind in type info. We can't just store 'kind'
5235 // in the AllocationSite::transition_info field because elements kind is
5236 // restricted to a portion of the field; upper bits need to be left alone.
5237 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5238 __ Ldr(x11, FieldMemOperand(allocation_site,
5239 AllocationSite::kTransitionInfoOffset));
5240 __ Add(x11, x11, Smi::FromInt(kFastElementsKindPackedToHoley));
5241 __ Str(x11, FieldMemOperand(allocation_site,
5242 AllocationSite::kTransitionInfoOffset));
5244 __ Bind(&normal_sequence);
5246 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5247 for (int i = 0; i <= last_index; ++i) {
5249 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5250 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5251 ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind);
5252 __ TailCallStub(&stub);
5256 // If we reached this point there is a problem.
5257 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5265 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5266 int to_index = GetSequenceIndexFromFastElementsKind(
5267 TERMINAL_FAST_ELEMENTS_KIND);
5268 for (int i = 0; i <= to_index; ++i) {
5269 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5270 T stub(isolate, kind);
5272 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5273 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5280 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5281 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5283 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5285 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5290 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5292 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5293 for (int i = 0; i < 2; i++) {
5294 // For internal arrays we only need a few things
5295 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5297 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5299 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5305 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5306 MacroAssembler* masm,
5307 AllocationSiteOverrideMode mode) {
5309 if (argument_count() == ANY) {
5310 Label zero_case, n_case;
5311 __ Cbz(argc, &zero_case);
5316 CreateArrayDispatchOneArgument(masm, mode);
5318 __ Bind(&zero_case);
5320 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5324 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5326 } else if (argument_count() == NONE) {
5327 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5328 } else if (argument_count() == ONE) {
5329 CreateArrayDispatchOneArgument(masm, mode);
5330 } else if (argument_count() == MORE_THAN_ONE) {
5331 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5338 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5339 ASM_LOCATION("ArrayConstructorStub::Generate");
5340 // ----------- S t a t e -------------
5341 // -- x0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5342 // -- x1 : constructor
5343 // -- x2 : AllocationSite or undefined
5344 // -- x3 : original constructor
5345 // -- sp[0] : last argument
5346 // -----------------------------------
5347 Register constructor = x1;
5348 Register allocation_site = x2;
5349 Register original_constructor = x3;
5351 if (FLAG_debug_code) {
5352 // The array construct code is only set for the global and natives
5353 // builtin Array functions which always have maps.
5355 Label unexpected_map, map_ok;
5356 // Initial map for the builtin Array function should be a map.
5357 __ Ldr(x10, FieldMemOperand(constructor,
5358 JSFunction::kPrototypeOrInitialMapOffset));
5359 // Will both indicate a NULL and a Smi.
5360 __ JumpIfSmi(x10, &unexpected_map);
5361 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5362 __ Bind(&unexpected_map);
5363 __ Abort(kUnexpectedInitialMapForArrayFunction);
5366 // We should either have undefined in the allocation_site register or a
5367 // valid AllocationSite.
5368 __ AssertUndefinedOrAllocationSite(allocation_site, x10);
5372 __ Cmp(original_constructor, constructor);
5373 __ B(ne, &subclassing);
5377 // Get the elements kind and case on that.
5378 __ JumpIfRoot(allocation_site, Heap::kUndefinedValueRootIndex, &no_info);
5381 UntagSmiFieldMemOperand(allocation_site,
5382 AllocationSite::kTransitionInfoOffset));
5383 __ And(kind, kind, AllocationSite::ElementsKindBits::kMask);
5384 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5387 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5389 // Subclassing support.
5390 __ Bind(&subclassing);
5391 __ Push(constructor, original_constructor);
5393 switch (argument_count()) {
5396 __ add(x0, x0, Operand(2));
5399 __ Mov(x0, Operand(2));
5402 __ Mov(x0, Operand(3));
5405 __ JumpToExternalReference(
5406 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5410 void InternalArrayConstructorStub::GenerateCase(
5411 MacroAssembler* masm, ElementsKind kind) {
5412 Label zero_case, n_case;
5415 __ Cbz(argc, &zero_case);
5416 __ CompareAndBranch(argc, 1, ne, &n_case);
5419 if (IsFastPackedElementsKind(kind)) {
5422 // We might need to create a holey array; look at the first argument.
5424 __ Cbz(x10, &packed_case);
5426 InternalArraySingleArgumentConstructorStub
5427 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5428 __ TailCallStub(&stub1_holey);
5430 __ Bind(&packed_case);
5432 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5433 __ TailCallStub(&stub1);
5435 __ Bind(&zero_case);
5437 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5438 __ TailCallStub(&stub0);
5442 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5443 __ TailCallStub(&stubN);
5447 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5448 // ----------- S t a t e -------------
5450 // -- x1 : constructor
5451 // -- sp[0] : return address
5452 // -- sp[4] : last argument
5453 // -----------------------------------
5455 Register constructor = x1;
5457 if (FLAG_debug_code) {
5458 // The array construct code is only set for the global and natives
5459 // builtin Array functions which always have maps.
5461 Label unexpected_map, map_ok;
5462 // Initial map for the builtin Array function should be a map.
5463 __ Ldr(x10, FieldMemOperand(constructor,
5464 JSFunction::kPrototypeOrInitialMapOffset));
5465 // Will both indicate a NULL and a Smi.
5466 __ JumpIfSmi(x10, &unexpected_map);
5467 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5468 __ Bind(&unexpected_map);
5469 __ Abort(kUnexpectedInitialMapForArrayFunction);
5474 // Figure out the right elements kind
5475 __ Ldr(x10, FieldMemOperand(constructor,
5476 JSFunction::kPrototypeOrInitialMapOffset));
5478 // Retrieve elements_kind from map.
5479 __ LoadElementsKindFromMap(kind, x10);
5481 if (FLAG_debug_code) {
5483 __ Cmp(x3, FAST_ELEMENTS);
5484 __ Ccmp(x3, FAST_HOLEY_ELEMENTS, ZFlag, ne);
5485 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5488 Label fast_elements_case;
5489 __ CompareAndBranch(kind, FAST_ELEMENTS, eq, &fast_elements_case);
5490 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5492 __ Bind(&fast_elements_case);
5493 GenerateCase(masm, FAST_ELEMENTS);
5497 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5498 Register context = cp;
5499 Register result = x0;
5503 // Go up the context chain to the script context.
5504 for (int i = 0; i < depth(); ++i) {
5505 __ Ldr(result, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5509 // Load the PropertyCell value at the specified slot.
5510 __ Add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5511 __ Ldr(result, ContextMemOperand(result));
5512 __ Ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5514 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5515 __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &slow_case);
5518 // Fallback to runtime.
5519 __ Bind(&slow_case);
5522 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5526 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5527 Register context = cp;
5528 Register value = x0;
5530 Register context_temp = x10;
5531 Register cell = x10;
5532 Register cell_details = x11;
5533 Register cell_value = x12;
5534 Register cell_value_map = x13;
5535 Register value_map = x14;
5536 Label fast_heapobject_case, fast_smi_case, slow_case;
5538 if (FLAG_debug_code) {
5539 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5540 __ Check(ne, kUnexpectedValue);
5543 // Go up the context chain to the script context.
5544 for (int i = 0; i < depth(); i++) {
5545 __ Ldr(context_temp, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5546 context = context_temp;
5549 // Load the PropertyCell at the specified slot.
5550 __ Add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5551 __ Ldr(cell, ContextMemOperand(cell));
5553 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5554 __ Ldr(cell_details,
5555 UntagSmiFieldMemOperand(cell, PropertyCell::kDetailsOffset));
5556 __ And(cell_details, cell_details,
5557 PropertyDetails::PropertyCellTypeField::kMask |
5558 PropertyDetails::KindField::kMask |
5559 PropertyDetails::kAttributesReadOnlyMask);
5561 // Check if PropertyCell holds mutable data.
5562 Label not_mutable_data;
5563 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5564 PropertyCellType::kMutable) |
5565 PropertyDetails::KindField::encode(kData));
5566 __ B(ne, ¬_mutable_data);
5567 __ JumpIfSmi(value, &fast_smi_case);
5568 __ Bind(&fast_heapobject_case);
5569 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5570 // RecordWriteField clobbers the value register, so we copy it before the
5573 __ RecordWriteField(cell, PropertyCell::kValueOffset, x11, x12,
5574 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5578 __ Bind(¬_mutable_data);
5579 // Check if PropertyCell value matches the new value (relevant for Constant,
5580 // ConstantType and Undefined cells).
5581 Label not_same_value;
5582 __ Ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5583 __ Cmp(cell_value, value);
5584 __ B(ne, ¬_same_value);
5586 // Make sure the PropertyCell is not marked READ_ONLY.
5587 __ Tst(cell_details, PropertyDetails::kAttributesReadOnlyMask);
5588 __ B(ne, &slow_case);
5590 if (FLAG_debug_code) {
5592 // This can only be true for Constant, ConstantType and Undefined cells,
5593 // because we never store the_hole via this stub.
5594 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5595 PropertyCellType::kConstant) |
5596 PropertyDetails::KindField::encode(kData));
5598 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5599 PropertyCellType::kConstantType) |
5600 PropertyDetails::KindField::encode(kData));
5602 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5603 PropertyCellType::kUndefined) |
5604 PropertyDetails::KindField::encode(kData));
5605 __ Check(eq, kUnexpectedValue);
5609 __ Bind(¬_same_value);
5611 // Check if PropertyCell contains data with constant type (and is not
5613 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5614 PropertyCellType::kConstantType) |
5615 PropertyDetails::KindField::encode(kData));
5616 __ B(ne, &slow_case);
5618 // Now either both old and new values must be smis or both must be heap
5619 // objects with same map.
5620 Label value_is_heap_object;
5621 __ JumpIfNotSmi(value, &value_is_heap_object);
5622 __ JumpIfNotSmi(cell_value, &slow_case);
5623 // Old and new values are smis, no need for a write barrier here.
5624 __ Bind(&fast_smi_case);
5625 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5628 __ Bind(&value_is_heap_object);
5629 __ JumpIfSmi(cell_value, &slow_case);
5631 __ Ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5632 __ Ldr(value_map, FieldMemOperand(value, HeapObject::kMapOffset));
5633 __ Cmp(cell_value_map, value_map);
5634 __ B(eq, &fast_heapobject_case);
5636 // Fall back to the runtime.
5637 __ Bind(&slow_case);
5639 __ Push(slot, value);
5640 __ TailCallRuntime(is_strict(language_mode())
5641 ? Runtime::kStoreGlobalViaContext_Strict
5642 : Runtime::kStoreGlobalViaContext_Sloppy,
5647 // The number of register that CallApiFunctionAndReturn will need to save on
5648 // the stack. The space for these registers need to be allocated in the
5649 // ExitFrame before calling CallApiFunctionAndReturn.
5650 static const int kCallApiFunctionSpillSpace = 4;
5653 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5654 return static_cast<int>(ref0.address() - ref1.address());
5658 // Calls an API function. Allocates HandleScope, extracts returned value
5659 // from handle and propagates exceptions.
5660 // 'stack_space' is the space to be unwound on exit (includes the call JS
5661 // arguments space and the additional space allocated for the fast call).
5662 // 'spill_offset' is the offset from the stack pointer where
5663 // CallApiFunctionAndReturn can spill registers.
5664 static void CallApiFunctionAndReturn(
5665 MacroAssembler* masm, Register function_address,
5666 ExternalReference thunk_ref, int stack_space,
5667 MemOperand* stack_space_operand, int spill_offset,
5668 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5669 ASM_LOCATION("CallApiFunctionAndReturn");
5670 Isolate* isolate = masm->isolate();
5671 ExternalReference next_address =
5672 ExternalReference::handle_scope_next_address(isolate);
5673 const int kNextOffset = 0;
5674 const int kLimitOffset = AddressOffset(
5675 ExternalReference::handle_scope_limit_address(isolate), next_address);
5676 const int kLevelOffset = AddressOffset(
5677 ExternalReference::handle_scope_level_address(isolate), next_address);
5679 DCHECK(function_address.is(x1) || function_address.is(x2));
5681 Label profiler_disabled;
5682 Label end_profiler_check;
5683 __ Mov(x10, ExternalReference::is_profiling_address(isolate));
5684 __ Ldrb(w10, MemOperand(x10));
5685 __ Cbz(w10, &profiler_disabled);
5686 __ Mov(x3, thunk_ref);
5687 __ B(&end_profiler_check);
5689 __ Bind(&profiler_disabled);
5690 __ Mov(x3, function_address);
5691 __ Bind(&end_profiler_check);
5693 // Save the callee-save registers we are going to use.
5694 // TODO(all): Is this necessary? ARM doesn't do it.
5695 STATIC_ASSERT(kCallApiFunctionSpillSpace == 4);
5696 __ Poke(x19, (spill_offset + 0) * kXRegSize);
5697 __ Poke(x20, (spill_offset + 1) * kXRegSize);
5698 __ Poke(x21, (spill_offset + 2) * kXRegSize);
5699 __ Poke(x22, (spill_offset + 3) * kXRegSize);
5701 // Allocate HandleScope in callee-save registers.
5702 // We will need to restore the HandleScope after the call to the API function,
5703 // by allocating it in callee-save registers they will be preserved by C code.
5704 Register handle_scope_base = x22;
5705 Register next_address_reg = x19;
5706 Register limit_reg = x20;
5707 Register level_reg = w21;
5709 __ Mov(handle_scope_base, next_address);
5710 __ Ldr(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5711 __ Ldr(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5712 __ Ldr(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5713 __ Add(level_reg, level_reg, 1);
5714 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5716 if (FLAG_log_timer_events) {
5717 FrameScope frame(masm, StackFrame::MANUAL);
5718 __ PushSafepointRegisters();
5719 __ Mov(x0, ExternalReference::isolate_address(isolate));
5720 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5722 __ PopSafepointRegisters();
5725 // Native call returns to the DirectCEntry stub which redirects to the
5726 // return address pushed on stack (could have moved after GC).
5727 // DirectCEntry stub itself is generated early and never moves.
5728 DirectCEntryStub stub(isolate);
5729 stub.GenerateCall(masm, x3);
5731 if (FLAG_log_timer_events) {
5732 FrameScope frame(masm, StackFrame::MANUAL);
5733 __ PushSafepointRegisters();
5734 __ Mov(x0, ExternalReference::isolate_address(isolate));
5735 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5737 __ PopSafepointRegisters();
5740 Label promote_scheduled_exception;
5741 Label delete_allocated_handles;
5742 Label leave_exit_frame;
5743 Label return_value_loaded;
5745 // Load value from ReturnValue.
5746 __ Ldr(x0, return_value_operand);
5747 __ Bind(&return_value_loaded);
5748 // No more valid handles (the result handle was the last one). Restore
5749 // previous handle scope.
5750 __ Str(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5751 if (__ emit_debug_code()) {
5752 __ Ldr(w1, MemOperand(handle_scope_base, kLevelOffset));
5753 __ Cmp(w1, level_reg);
5754 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5756 __ Sub(level_reg, level_reg, 1);
5757 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5758 __ Ldr(x1, MemOperand(handle_scope_base, kLimitOffset));
5759 __ Cmp(limit_reg, x1);
5760 __ B(ne, &delete_allocated_handles);
5762 // Leave the API exit frame.
5763 __ Bind(&leave_exit_frame);
5764 // Restore callee-saved registers.
5765 __ Peek(x19, (spill_offset + 0) * kXRegSize);
5766 __ Peek(x20, (spill_offset + 1) * kXRegSize);
5767 __ Peek(x21, (spill_offset + 2) * kXRegSize);
5768 __ Peek(x22, (spill_offset + 3) * kXRegSize);
5770 bool restore_context = context_restore_operand != NULL;
5771 if (restore_context) {
5772 __ Ldr(cp, *context_restore_operand);
5775 if (stack_space_operand != NULL) {
5776 __ Ldr(w2, *stack_space_operand);
5779 __ LeaveExitFrame(false, x1, !restore_context);
5781 // Check if the function scheduled an exception.
5782 __ Mov(x5, ExternalReference::scheduled_exception_address(isolate));
5783 __ Ldr(x5, MemOperand(x5));
5784 __ JumpIfNotRoot(x5, Heap::kTheHoleValueRootIndex,
5785 &promote_scheduled_exception);
5787 if (stack_space_operand != NULL) {
5790 __ Drop(stack_space);
5794 // Re-throw by promoting a scheduled exception.
5795 __ Bind(&promote_scheduled_exception);
5796 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5798 // HandleScope limit has changed. Delete allocated extensions.
5799 __ Bind(&delete_allocated_handles);
5800 __ Str(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5801 // Save the return value in a callee-save register.
5802 Register saved_result = x19;
5803 __ Mov(saved_result, x0);
5804 __ Mov(x0, ExternalReference::isolate_address(isolate));
5805 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5807 __ Mov(x0, saved_result);
5808 __ B(&leave_exit_frame);
5812 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5813 const ParameterCount& argc,
5814 bool return_first_arg,
5815 bool call_data_undefined) {
5816 // ----------- S t a t e -------------
5818 // -- x4 : call_data
5820 // -- x1 : api_function_address
5821 // -- x3 : number of arguments if argc is a register
5824 // -- sp[0] : last argument
5826 // -- sp[(argc - 1) * 8] : first argument
5827 // -- sp[argc * 8] : receiver
5828 // -----------------------------------
5830 Register callee = x0;
5831 Register call_data = x4;
5832 Register holder = x2;
5833 Register api_function_address = x1;
5834 Register context = cp;
5836 typedef FunctionCallbackArguments FCA;
5838 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5839 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5840 STATIC_ASSERT(FCA::kDataIndex == 4);
5841 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5842 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5843 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5844 STATIC_ASSERT(FCA::kHolderIndex == 0);
5845 STATIC_ASSERT(FCA::kArgsLength == 7);
5847 DCHECK(argc.is_immediate() || x3.is(argc.reg()));
5849 // FunctionCallbackArguments: context, callee and call data.
5850 __ Push(context, callee, call_data);
5852 // Load context from callee
5853 __ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5855 if (!call_data_undefined) {
5856 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
5858 Register isolate_reg = x5;
5859 __ Mov(isolate_reg, ExternalReference::isolate_address(masm->isolate()));
5861 // FunctionCallbackArguments:
5862 // return value, return value default, isolate, holder.
5863 __ Push(call_data, call_data, isolate_reg, holder);
5865 // Prepare arguments.
5867 __ Mov(args, masm->StackPointer());
5869 // Allocate the v8::Arguments structure in the arguments' space, since it's
5870 // not controlled by GC.
5871 const int kApiStackSpace = 4;
5873 // Allocate space for CallApiFunctionAndReturn can store some scratch
5874 // registeres on the stack.
5875 const int kCallApiFunctionSpillSpace = 4;
5877 FrameScope frame_scope(masm, StackFrame::MANUAL);
5878 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5880 DCHECK(!AreAliased(x0, api_function_address));
5881 // x0 = FunctionCallbackInfo&
5882 // Arguments is after the return address.
5883 __ Add(x0, masm->StackPointer(), 1 * kPointerSize);
5884 if (argc.is_immediate()) {
5885 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5887 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5888 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5889 // FunctionCallbackInfo::length_ = argc and
5890 // FunctionCallbackInfo::is_construct_call = 0
5891 __ Mov(x10, argc.immediate());
5892 __ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize));
5894 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5895 __ Add(x10, args, Operand(argc.reg(), LSL, kPointerSizeLog2));
5896 __ Add(x10, x10, (FCA::kArgsLength - 1) * kPointerSize);
5897 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5898 // FunctionCallbackInfo::length_ = argc and
5899 // FunctionCallbackInfo::is_construct_call
5900 __ Add(x10, argc.reg(), FCA::kArgsLength + 1);
5901 __ Mov(x10, Operand(x10, LSL, kPointerSizeLog2));
5902 __ Stp(argc.reg(), x10, MemOperand(x0, 2 * kPointerSize));
5905 ExternalReference thunk_ref =
5906 ExternalReference::invoke_function_callback(masm->isolate());
5908 AllowExternalCallThatCantCauseGC scope(masm);
5909 MemOperand context_restore_operand(
5910 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5911 // Stores return the first js argument
5912 int return_value_offset = 0;
5913 if (return_first_arg) {
5914 return_value_offset = 2 + FCA::kArgsLength;
5916 return_value_offset = 2 + FCA::kReturnValueOffset;
5918 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5919 int stack_space = 0;
5920 MemOperand is_construct_call_operand =
5921 MemOperand(masm->StackPointer(), 4 * kPointerSize);
5922 MemOperand* stack_space_operand = &is_construct_call_operand;
5923 if (argc.is_immediate()) {
5924 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5925 stack_space_operand = NULL;
5928 const int spill_offset = 1 + kApiStackSpace;
5929 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5930 stack_space_operand, spill_offset,
5931 return_value_operand, &context_restore_operand);
5935 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5936 bool call_data_undefined = this->call_data_undefined();
5937 CallApiFunctionStubHelper(masm, ParameterCount(x3), false,
5938 call_data_undefined);
5942 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5943 bool is_store = this->is_store();
5944 int argc = this->argc();
5945 bool call_data_undefined = this->call_data_undefined();
5946 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5947 call_data_undefined);
5951 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5952 // ----------- S t a t e -------------
5954 // -- sp[8 - kArgsLength*8] : PropertyCallbackArguments object
5956 // -- x2 : api_function_address
5957 // -----------------------------------
5959 Register api_function_address = ApiGetterDescriptor::function_address();
5960 DCHECK(api_function_address.is(x2));
5962 __ Mov(x0, masm->StackPointer()); // x0 = Handle<Name>
5963 __ Add(x1, x0, 1 * kPointerSize); // x1 = PCA
5965 const int kApiStackSpace = 1;
5967 // Allocate space for CallApiFunctionAndReturn can store some scratch
5968 // registeres on the stack.
5969 const int kCallApiFunctionSpillSpace = 4;
5971 FrameScope frame_scope(masm, StackFrame::MANUAL);
5972 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5974 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5975 // x1 (internal::Object** args_) as the data.
5976 __ Poke(x1, 1 * kPointerSize);
5977 __ Add(x1, masm->StackPointer(), 1 * kPointerSize); // x1 = AccessorInfo&
5979 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5981 ExternalReference thunk_ref =
5982 ExternalReference::invoke_accessor_getter_callback(isolate());
5984 const int spill_offset = 1 + kApiStackSpace;
5985 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5986 kStackUnwindSpace, NULL, spill_offset,
5987 MemOperand(fp, 6 * kPointerSize), NULL);
5993 } // namespace internal
5996 #endif // V8_TARGET_ARCH_ARM64