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.
5 #if V8_TARGET_ARCH_ARM64
7 #include "src/arm64/frames-arm64.h"
8 #include "src/bootstrapper.h"
9 #include "src/code-stubs.h"
10 #include "src/codegen.h"
11 #include "src/ic/handler-compiler.h"
12 #include "src/ic/ic.h"
13 #include "src/ic/stub-cache.h"
14 #include "src/isolate.h"
15 #include "src/regexp/jsregexp.h"
16 #include "src/regexp/regexp-macro-assembler.h"
17 #include "src/runtime/runtime.h"
23 static void InitializeArrayConstructorDescriptor(
24 Isolate* isolate, CodeStubDescriptor* descriptor,
25 int constant_stack_parameter_count) {
28 // x2: allocation site with elements kind
29 // x0: number of arguments to the constructor function
30 Address deopt_handler = Runtime::FunctionForId(
31 Runtime::kArrayConstructor)->entry;
33 if (constant_stack_parameter_count == 0) {
34 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
35 JS_FUNCTION_STUB_MODE);
37 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
38 JS_FUNCTION_STUB_MODE);
43 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
44 CodeStubDescriptor* descriptor) {
45 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
49 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
50 CodeStubDescriptor* descriptor) {
51 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
55 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
56 CodeStubDescriptor* descriptor) {
57 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
61 static void InitializeInternalArrayConstructorDescriptor(
62 Isolate* isolate, CodeStubDescriptor* descriptor,
63 int constant_stack_parameter_count) {
64 Address deopt_handler = Runtime::FunctionForId(
65 Runtime::kInternalArrayConstructor)->entry;
67 if (constant_stack_parameter_count == 0) {
68 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
69 JS_FUNCTION_STUB_MODE);
71 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
72 JS_FUNCTION_STUB_MODE);
77 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
78 CodeStubDescriptor* descriptor) {
79 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
83 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
84 CodeStubDescriptor* descriptor) {
85 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
89 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
90 CodeStubDescriptor* descriptor) {
91 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
95 #define __ ACCESS_MASM(masm)
98 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
99 ExternalReference miss) {
100 // Update the static counter each time a new code stub is generated.
101 isolate()->counters()->code_stubs()->Increment();
103 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
104 int param_count = descriptor.GetRegisterParameterCount();
106 // Call the runtime system in a fresh internal frame.
107 FrameScope scope(masm, StackFrame::INTERNAL);
108 DCHECK((param_count == 0) ||
109 x0.Is(descriptor.GetRegisterParameter(param_count - 1)));
112 MacroAssembler::PushPopQueue queue(masm);
113 for (int i = 0; i < param_count; ++i) {
114 queue.Queue(descriptor.GetRegisterParameter(i));
118 __ CallExternalReference(miss, param_count);
125 void DoubleToIStub::Generate(MacroAssembler* masm) {
127 Register input = source();
128 Register result = destination();
129 DCHECK(is_truncating());
131 DCHECK(result.Is64Bits());
132 DCHECK(jssp.Is(masm->StackPointer()));
134 int double_offset = offset();
136 DoubleRegister double_scratch = d0; // only used if !skip_fastpath()
137 Register scratch1 = GetAllocatableRegisterThatIsNotOneOf(input, result);
139 GetAllocatableRegisterThatIsNotOneOf(input, result, scratch1);
141 __ Push(scratch1, scratch2);
142 // Account for saved regs if input is jssp.
143 if (input.is(jssp)) double_offset += 2 * kPointerSize;
145 if (!skip_fastpath()) {
146 __ Push(double_scratch);
147 if (input.is(jssp)) double_offset += 1 * kDoubleSize;
148 __ Ldr(double_scratch, MemOperand(input, double_offset));
149 // Try to convert with a FPU convert instruction. This handles all
150 // non-saturating cases.
151 __ TryConvertDoubleToInt64(result, double_scratch, &done);
152 __ Fmov(result, double_scratch);
154 __ Ldr(result, MemOperand(input, double_offset));
157 // If we reach here we need to manually convert the input to an int32.
159 // Extract the exponent.
160 Register exponent = scratch1;
161 __ Ubfx(exponent, result, HeapNumber::kMantissaBits,
162 HeapNumber::kExponentBits);
164 // It the exponent is >= 84 (kMantissaBits + 32), the result is always 0 since
165 // the mantissa gets shifted completely out of the int32_t result.
166 __ Cmp(exponent, HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 32);
167 __ CzeroX(result, ge);
170 // The Fcvtzs sequence handles all cases except where the conversion causes
171 // signed overflow in the int64_t target. Since we've already handled
172 // exponents >= 84, we can guarantee that 63 <= exponent < 84.
174 if (masm->emit_debug_code()) {
175 __ Cmp(exponent, HeapNumber::kExponentBias + 63);
176 // Exponents less than this should have been handled by the Fcvt case.
177 __ Check(ge, kUnexpectedValue);
180 // Isolate the mantissa bits, and set the implicit '1'.
181 Register mantissa = scratch2;
182 __ Ubfx(mantissa, result, 0, HeapNumber::kMantissaBits);
183 __ Orr(mantissa, mantissa, 1UL << HeapNumber::kMantissaBits);
185 // Negate the mantissa if necessary.
186 __ Tst(result, kXSignMask);
187 __ Cneg(mantissa, mantissa, ne);
189 // Shift the mantissa bits in the correct place. We know that we have to shift
190 // it left here, because exponent >= 63 >= kMantissaBits.
191 __ Sub(exponent, exponent,
192 HeapNumber::kExponentBias + HeapNumber::kMantissaBits);
193 __ Lsl(result, mantissa, exponent);
196 if (!skip_fastpath()) {
197 __ Pop(double_scratch);
199 __ Pop(scratch2, scratch1);
204 // See call site for description.
205 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
206 Register right, Register scratch,
207 FPRegister double_scratch,
208 Label* slow, Condition cond,
210 DCHECK(!AreAliased(left, right, scratch));
211 Label not_identical, return_equal, heap_number;
212 Register result = x0;
215 __ B(ne, ¬_identical);
217 // Test for NaN. Sadly, we can't just compare to factory::nan_value(),
218 // so we do the second best thing - test it ourselves.
219 // They are both equal and they are not both Smis so both of them are not
220 // Smis. If it's not a heap number, then return equal.
221 Register right_type = scratch;
222 if ((cond == lt) || (cond == gt)) {
223 // Call runtime on identical JSObjects. Otherwise return equal.
224 __ JumpIfObjectType(right, right_type, right_type, FIRST_SPEC_OBJECT_TYPE,
226 // Call runtime on identical symbols since we need to throw a TypeError.
227 __ Cmp(right_type, SYMBOL_TYPE);
229 // Call runtime on identical SIMD values since we must throw a TypeError.
230 __ Cmp(right_type, SIMD128_VALUE_TYPE);
232 if (is_strong(strength)) {
233 // Call the runtime on anything that is converted in the semantics, since
234 // we need to throw a TypeError. Smis have already been ruled out.
235 __ Cmp(right_type, Operand(HEAP_NUMBER_TYPE));
236 __ B(eq, &return_equal);
237 __ Tst(right_type, Operand(kIsNotStringMask));
240 } else if (cond == eq) {
241 __ JumpIfHeapNumber(right, &heap_number);
243 __ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE,
245 // Comparing JS objects with <=, >= is complicated.
246 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
248 // Call runtime on identical symbols since we need to throw a TypeError.
249 __ Cmp(right_type, SYMBOL_TYPE);
251 // Call runtime on identical SIMD values since we must throw a TypeError.
252 __ Cmp(right_type, SIMD128_VALUE_TYPE);
254 if (is_strong(strength)) {
255 // Call the runtime on anything that is converted in the semantics,
256 // since we need to throw a TypeError. Smis and heap numbers have
257 // already been ruled out.
258 __ Tst(right_type, Operand(kIsNotStringMask));
261 // Normally here we fall through to return_equal, but undefined is
262 // special: (undefined == undefined) == true, but
263 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
264 if ((cond == le) || (cond == ge)) {
265 __ Cmp(right_type, ODDBALL_TYPE);
266 __ B(ne, &return_equal);
267 __ JumpIfNotRoot(right, Heap::kUndefinedValueRootIndex, &return_equal);
269 // undefined <= undefined should fail.
270 __ Mov(result, GREATER);
272 // undefined >= undefined should fail.
273 __ Mov(result, LESS);
279 __ Bind(&return_equal);
281 __ Mov(result, GREATER); // Things aren't less than themselves.
282 } else if (cond == gt) {
283 __ Mov(result, LESS); // Things aren't greater than themselves.
285 __ Mov(result, EQUAL); // Things are <=, >=, ==, === themselves.
289 // Cases lt and gt have been handled earlier, and case ne is never seen, as
290 // it is handled in the parser (see Parser::ParseBinaryExpression). We are
291 // only concerned with cases ge, le and eq here.
292 if ((cond != lt) && (cond != gt)) {
293 DCHECK((cond == ge) || (cond == le) || (cond == eq));
294 __ Bind(&heap_number);
295 // Left and right are identical pointers to a heap number object. Return
296 // non-equal if the heap number is a NaN, and equal otherwise. Comparing
297 // the number to itself will set the overflow flag iff the number is NaN.
298 __ Ldr(double_scratch, FieldMemOperand(right, HeapNumber::kValueOffset));
299 __ Fcmp(double_scratch, double_scratch);
300 __ B(vc, &return_equal); // Not NaN, so treat as normal heap number.
303 __ Mov(result, GREATER);
305 __ Mov(result, LESS);
310 // No fall through here.
311 if (FLAG_debug_code) {
315 __ Bind(¬_identical);
319 // See call site for description.
320 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
326 DCHECK(!AreAliased(left, right, left_type, right_type, scratch));
328 if (masm->emit_debug_code()) {
329 // We assume that the arguments are not identical.
331 __ Assert(ne, kExpectedNonIdenticalObjects);
334 // If either operand is a JS object or an oddball value, then they are not
335 // equal since their pointers are different.
336 // There is no test for undetectability in strict equality.
337 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
338 Label right_non_object;
340 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
341 __ B(lt, &right_non_object);
343 // Return non-zero - x0 already contains a non-zero pointer.
344 DCHECK(left.is(x0) || right.is(x0));
345 Label return_not_equal;
346 __ Bind(&return_not_equal);
349 __ Bind(&right_non_object);
351 // Check for oddballs: true, false, null, undefined.
352 __ Cmp(right_type, ODDBALL_TYPE);
354 // If right is not ODDBALL, test left. Otherwise, set eq condition.
355 __ Ccmp(left_type, ODDBALL_TYPE, ZFlag, ne);
357 // If right or left is not ODDBALL, test left >= FIRST_SPEC_OBJECT_TYPE.
358 // Otherwise, right or left is ODDBALL, so set a ge condition.
359 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NVFlag, ne);
361 __ B(ge, &return_not_equal);
363 // Internalized strings are unique, so they can only be equal if they are the
364 // same object. We have already tested that case, so if left and right are
365 // both internalized strings, they cannot be equal.
366 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
367 __ Orr(scratch, left_type, right_type);
368 __ TestAndBranchIfAllClear(
369 scratch, kIsNotStringMask | kIsNotInternalizedMask, &return_not_equal);
373 // See call site for description.
374 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
381 DCHECK(!AreAliased(left_d, right_d));
382 DCHECK((left.is(x0) && right.is(x1)) ||
383 (right.is(x0) && left.is(x1)));
384 Register result = x0;
386 Label right_is_smi, done;
387 __ JumpIfSmi(right, &right_is_smi);
389 // Left is the smi. Check whether right is a heap number.
391 // If right is not a number and left is a smi, then strict equality cannot
392 // succeed. Return non-equal.
393 Label is_heap_number;
394 __ JumpIfHeapNumber(right, &is_heap_number);
395 // Register right is a non-zero pointer, which is a valid NOT_EQUAL result.
396 if (!right.is(result)) {
397 __ Mov(result, NOT_EQUAL);
400 __ Bind(&is_heap_number);
402 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
404 __ JumpIfNotHeapNumber(right, slow);
407 // Left is the smi. Right is a heap number. Load right value into right_d, and
408 // convert left smi into double in left_d.
409 __ Ldr(right_d, FieldMemOperand(right, HeapNumber::kValueOffset));
410 __ SmiUntagToDouble(left_d, left);
413 __ Bind(&right_is_smi);
414 // Right is a smi. Check whether the non-smi left is a heap number.
416 // If left is not a number and right is a smi then strict equality cannot
417 // succeed. Return non-equal.
418 Label is_heap_number;
419 __ JumpIfHeapNumber(left, &is_heap_number);
420 // Register left is a non-zero pointer, which is a valid NOT_EQUAL result.
421 if (!left.is(result)) {
422 __ Mov(result, NOT_EQUAL);
425 __ Bind(&is_heap_number);
427 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
429 __ JumpIfNotHeapNumber(left, slow);
432 // Right is the smi. Left is a heap number. Load left value into left_d, and
433 // convert right smi into double in right_d.
434 __ Ldr(left_d, FieldMemOperand(left, HeapNumber::kValueOffset));
435 __ SmiUntagToDouble(right_d, right);
437 // Fall through to both_loaded_as_doubles.
442 // Fast negative check for internalized-to-internalized equality.
443 // See call site for description.
444 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
451 Label* possible_strings,
452 Label* not_both_strings) {
453 DCHECK(!AreAliased(left, right, left_map, right_map, left_type, right_type));
454 Register result = x0;
457 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
458 // TODO(all): reexamine this branch sequence for optimisation wrt branch
460 __ Tbnz(right_type, MaskToBit(kIsNotStringMask), &object_test);
461 __ Tbnz(right_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
462 __ Tbnz(left_type, MaskToBit(kIsNotStringMask), not_both_strings);
463 __ Tbnz(left_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
465 // Both are internalized. We already checked that they weren't the same
466 // pointer, so they are not equal.
467 __ Mov(result, NOT_EQUAL);
470 __ Bind(&object_test);
472 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
474 // If right >= FIRST_SPEC_OBJECT_TYPE, test left.
475 // Otherwise, right < FIRST_SPEC_OBJECT_TYPE, so set lt condition.
476 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NFlag, ge);
478 __ B(lt, not_both_strings);
480 // If both objects are undetectable, they are equal. Otherwise, they are not
481 // equal, since they are different objects and an object is not equal to
484 // Returning here, so we can corrupt right_type and left_type.
485 Register right_bitfield = right_type;
486 Register left_bitfield = left_type;
487 __ Ldrb(right_bitfield, FieldMemOperand(right_map, Map::kBitFieldOffset));
488 __ Ldrb(left_bitfield, FieldMemOperand(left_map, Map::kBitFieldOffset));
489 __ And(result, right_bitfield, left_bitfield);
490 __ And(result, result, 1 << Map::kIsUndetectable);
491 __ Eor(result, result, 1 << Map::kIsUndetectable);
496 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
497 CompareICState::State expected,
500 if (expected == CompareICState::SMI) {
501 __ JumpIfNotSmi(input, fail);
502 } else if (expected == CompareICState::NUMBER) {
503 __ JumpIfSmi(input, &ok);
504 __ JumpIfNotHeapNumber(input, fail);
506 // We could be strict about internalized/non-internalized here, but as long as
507 // hydrogen doesn't care, the stub doesn't have to care either.
512 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
515 Register result = x0;
516 Condition cond = GetCondition();
519 CompareICStub_CheckInputType(masm, lhs, left(), &miss);
520 CompareICStub_CheckInputType(masm, rhs, right(), &miss);
522 Label slow; // Call builtin.
523 Label not_smis, both_loaded_as_doubles;
524 Label not_two_smis, smi_done;
525 __ JumpIfEitherNotSmi(lhs, rhs, ¬_two_smis);
527 __ Sub(result, lhs, Operand::UntagSmi(rhs));
530 __ Bind(¬_two_smis);
532 // NOTICE! This code is only reached after a smi-fast-case check, so it is
533 // certain that at least one operand isn't a smi.
535 // Handle the case where the objects are identical. Either returns the answer
536 // or goes to slow. Only falls through if the objects were not identical.
537 EmitIdenticalObjectComparison(masm, lhs, rhs, x10, d0, &slow, cond,
540 // If either is a smi (we know that at least one is not a smi), then they can
541 // only be strictly equal if the other is a HeapNumber.
542 __ JumpIfBothNotSmi(lhs, rhs, ¬_smis);
544 // Exactly one operand is a smi. EmitSmiNonsmiComparison generates code that
546 // 1) Return the answer.
547 // 2) Branch to the slow case.
548 // 3) Fall through to both_loaded_as_doubles.
549 // In case 3, we have found out that we were dealing with a number-number
550 // comparison. The double values of the numbers have been loaded, right into
551 // rhs_d, left into lhs_d.
552 FPRegister rhs_d = d0;
553 FPRegister lhs_d = d1;
554 EmitSmiNonsmiComparison(masm, lhs, rhs, lhs_d, rhs_d, &slow, strict());
556 __ Bind(&both_loaded_as_doubles);
557 // The arguments have been converted to doubles and stored in rhs_d and
560 __ Fcmp(lhs_d, rhs_d);
561 __ B(vs, &nan); // Overflow flag set if either is NaN.
562 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
563 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
564 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
568 // Left and/or right is a NaN. Load the result register with whatever makes
569 // the comparison fail, since comparisons with NaN always fail (except ne,
570 // which is filtered out at a higher level.)
572 if ((cond == lt) || (cond == le)) {
573 __ Mov(result, GREATER);
575 __ Mov(result, LESS);
580 // At this point we know we are dealing with two different objects, and
581 // neither of them is a smi. The objects are in rhs_ and lhs_.
583 // Load the maps and types of the objects.
584 Register rhs_map = x10;
585 Register rhs_type = x11;
586 Register lhs_map = x12;
587 Register lhs_type = x13;
588 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
589 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
590 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
591 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
594 // This emits a non-equal return sequence for some object types, or falls
595 // through if it was not lucky.
596 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs, lhs_type, rhs_type, x14);
599 Label check_for_internalized_strings;
600 Label flat_string_check;
601 // Check for heap number comparison. Branch to earlier double comparison code
602 // if they are heap numbers, otherwise, branch to internalized string check.
603 __ Cmp(rhs_type, HEAP_NUMBER_TYPE);
604 __ B(ne, &check_for_internalized_strings);
605 __ Cmp(lhs_map, rhs_map);
607 // If maps aren't equal, lhs_ and rhs_ are not heap numbers. Branch to flat
609 __ B(ne, &flat_string_check);
611 // Both lhs_ and rhs_ are heap numbers. Load them and branch to the double
613 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
614 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
615 __ B(&both_loaded_as_doubles);
617 __ Bind(&check_for_internalized_strings);
618 // In the strict case, the EmitStrictTwoHeapObjectCompare already took care
619 // of internalized strings.
620 if ((cond == eq) && !strict()) {
621 // Returns an answer for two internalized strings or two detectable objects.
622 // Otherwise branches to the string case or not both strings case.
623 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, lhs_map, rhs_map,
625 &flat_string_check, &slow);
628 // Check for both being sequential one-byte strings,
629 // and inline if that is the case.
630 __ Bind(&flat_string_check);
631 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x14,
634 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x10,
637 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
640 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
644 // Never fall through to here.
645 if (FLAG_debug_code) {
652 // Figure out which native to call and setup the arguments.
653 if (cond == eq && strict()) {
654 __ TailCallRuntime(Runtime::kStrictEquals, 2, 1);
658 context_index = Context::EQUALS_BUILTIN_INDEX;
660 context_index = is_strong(strength())
661 ? Context::COMPARE_STRONG_BUILTIN_INDEX
662 : Context::COMPARE_BUILTIN_INDEX;
663 int ncr; // NaN compare result
664 if ((cond == lt) || (cond == le)) {
667 DCHECK((cond == gt) || (cond == ge)); // remaining cases
670 __ Mov(x10, Smi::FromInt(ncr));
674 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
675 // tagged as a small integer.
676 __ InvokeBuiltin(context_index, JUMP_FUNCTION);
684 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
685 CPURegList saved_regs = kCallerSaved;
686 CPURegList saved_fp_regs = kCallerSavedFP;
688 // We don't allow a GC during a store buffer overflow so there is no need to
689 // store the registers in any particular way, but we do have to store and
692 // We don't care if MacroAssembler scratch registers are corrupted.
693 saved_regs.Remove(*(masm->TmpList()));
694 saved_fp_regs.Remove(*(masm->FPTmpList()));
696 __ PushCPURegList(saved_regs);
697 if (save_doubles()) {
698 __ PushCPURegList(saved_fp_regs);
701 AllowExternalCallThatCantCauseGC scope(masm);
702 __ Mov(x0, ExternalReference::isolate_address(isolate()));
704 ExternalReference::store_buffer_overflow_function(isolate()), 1, 0);
706 if (save_doubles()) {
707 __ PopCPURegList(saved_fp_regs);
709 __ PopCPURegList(saved_regs);
714 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
716 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
718 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
723 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
724 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
725 UseScratchRegisterScope temps(masm);
726 Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr());
727 Register return_address = temps.AcquireX();
728 __ Mov(return_address, lr);
729 // Restore lr with the value it had before the call to this stub (the value
730 // which must be pushed).
731 __ Mov(lr, saved_lr);
732 __ PushSafepointRegisters();
733 __ Ret(return_address);
737 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
738 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
739 UseScratchRegisterScope temps(masm);
740 Register return_address = temps.AcquireX();
741 // Preserve the return address (lr will be clobbered by the pop).
742 __ Mov(return_address, lr);
743 __ PopSafepointRegisters();
744 __ Ret(return_address);
748 void MathPowStub::Generate(MacroAssembler* masm) {
750 // jssp[0]: Exponent (as a tagged value).
751 // jssp[1]: Base (as a tagged value).
753 // The (tagged) result will be returned in x0, as a heap number.
755 Register result_tagged = x0;
756 Register base_tagged = x10;
757 Register exponent_tagged = MathPowTaggedDescriptor::exponent();
758 DCHECK(exponent_tagged.is(x11));
759 Register exponent_integer = MathPowIntegerDescriptor::exponent();
760 DCHECK(exponent_integer.is(x12));
761 Register scratch1 = x14;
762 Register scratch0 = x15;
763 Register saved_lr = x19;
764 FPRegister result_double = d0;
765 FPRegister base_double = d0;
766 FPRegister exponent_double = d1;
767 FPRegister base_double_copy = d2;
768 FPRegister scratch1_double = d6;
769 FPRegister scratch0_double = d7;
771 // A fast-path for integer exponents.
772 Label exponent_is_smi, exponent_is_integer;
773 // Bail out to runtime.
775 // Allocate a heap number for the result, and return it.
778 // Unpack the inputs.
779 if (exponent_type() == ON_STACK) {
781 Label unpack_exponent;
783 __ Pop(exponent_tagged, base_tagged);
785 __ JumpIfSmi(base_tagged, &base_is_smi);
786 __ JumpIfNotHeapNumber(base_tagged, &call_runtime);
787 // base_tagged is a heap number, so load its double value.
788 __ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset));
789 __ B(&unpack_exponent);
790 __ Bind(&base_is_smi);
791 // base_tagged is a SMI, so untag it and convert it to a double.
792 __ SmiUntagToDouble(base_double, base_tagged);
794 __ Bind(&unpack_exponent);
795 // x10 base_tagged The tagged base (input).
796 // x11 exponent_tagged The tagged exponent (input).
797 // d1 base_double The base as a double.
798 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
799 __ JumpIfNotHeapNumber(exponent_tagged, &call_runtime);
800 // exponent_tagged is a heap number, so load its double value.
801 __ Ldr(exponent_double,
802 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
803 } else if (exponent_type() == TAGGED) {
804 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
805 __ Ldr(exponent_double,
806 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
809 // Handle double (heap number) exponents.
810 if (exponent_type() != INTEGER) {
811 // Detect integer exponents stored as doubles and handle those in the
812 // integer fast-path.
813 __ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
814 scratch0_double, &exponent_is_integer);
816 if (exponent_type() == ON_STACK) {
817 FPRegister half_double = d3;
818 FPRegister minus_half_double = d4;
819 // Detect square root case. Crankshaft detects constant +/-0.5 at compile
820 // time and uses DoMathPowHalf instead. We then skip this check for
821 // non-constant cases of +/-0.5 as these hardly occur.
823 __ Fmov(minus_half_double, -0.5);
824 __ Fmov(half_double, 0.5);
825 __ Fcmp(minus_half_double, exponent_double);
826 __ Fccmp(half_double, exponent_double, NZFlag, ne);
827 // Condition flags at this point:
828 // 0.5; nZCv // Identified by eq && pl
829 // -0.5: NZcv // Identified by eq && mi
830 // other: ?z?? // Identified by ne
831 __ B(ne, &call_runtime);
833 // The exponent is 0.5 or -0.5.
835 // Given that exponent is known to be either 0.5 or -0.5, the following
836 // special cases could apply (according to ECMA-262 15.8.2.13):
838 // base.isNaN(): The result is NaN.
839 // (base == +INFINITY) || (base == -INFINITY)
840 // exponent == 0.5: The result is +INFINITY.
841 // exponent == -0.5: The result is +0.
842 // (base == +0) || (base == -0)
843 // exponent == 0.5: The result is +0.
844 // exponent == -0.5: The result is +INFINITY.
845 // (base < 0) && base.isFinite(): The result is NaN.
847 // Fsqrt (and Fdiv for the -0.5 case) can handle all of those except
848 // where base is -INFINITY or -0.
850 // Add +0 to base. This has no effect other than turning -0 into +0.
851 __ Fadd(base_double, base_double, fp_zero);
852 // The operation -0+0 results in +0 in all cases except where the
853 // FPCR rounding mode is 'round towards minus infinity' (RM). The
854 // ARM64 simulator does not currently simulate FPCR (where the rounding
855 // mode is set), so test the operation with some debug code.
856 if (masm->emit_debug_code()) {
857 UseScratchRegisterScope temps(masm);
858 Register temp = temps.AcquireX();
859 __ Fneg(scratch0_double, fp_zero);
860 // Verify that we correctly generated +0.0 and -0.0.
861 // bits(+0.0) = 0x0000000000000000
862 // bits(-0.0) = 0x8000000000000000
863 __ Fmov(temp, fp_zero);
864 __ CheckRegisterIsClear(temp, kCouldNotGenerateZero);
865 __ Fmov(temp, scratch0_double);
866 __ Eor(temp, temp, kDSignMask);
867 __ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero);
868 // Check that -0.0 + 0.0 == +0.0.
869 __ Fadd(scratch0_double, scratch0_double, fp_zero);
870 __ Fmov(temp, scratch0_double);
871 __ CheckRegisterIsClear(temp, kExpectedPositiveZero);
874 // If base is -INFINITY, make it +INFINITY.
875 // * Calculate base - base: All infinities will become NaNs since both
876 // -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64.
877 // * If the result is NaN, calculate abs(base).
878 __ Fsub(scratch0_double, base_double, base_double);
879 __ Fcmp(scratch0_double, 0.0);
880 __ Fabs(scratch1_double, base_double);
881 __ Fcsel(base_double, scratch1_double, base_double, vs);
883 // Calculate the square root of base.
884 __ Fsqrt(result_double, base_double);
885 __ Fcmp(exponent_double, 0.0);
886 __ B(ge, &done); // Finish now for exponents of 0.5.
887 // Find the inverse for exponents of -0.5.
888 __ Fmov(scratch0_double, 1.0);
889 __ Fdiv(result_double, scratch0_double, result_double);
894 AllowExternalCallThatCantCauseGC scope(masm);
895 __ Mov(saved_lr, lr);
897 ExternalReference::power_double_double_function(isolate()),
899 __ Mov(lr, saved_lr);
903 // Handle SMI exponents.
904 __ Bind(&exponent_is_smi);
905 // x10 base_tagged The tagged base (input).
906 // x11 exponent_tagged The tagged exponent (input).
907 // d1 base_double The base as a double.
908 __ SmiUntag(exponent_integer, exponent_tagged);
911 __ Bind(&exponent_is_integer);
912 // x10 base_tagged The tagged base (input).
913 // x11 exponent_tagged The tagged exponent (input).
914 // x12 exponent_integer The exponent as an integer.
915 // d1 base_double The base as a double.
917 // Find abs(exponent). For negative exponents, we can find the inverse later.
918 Register exponent_abs = x13;
919 __ Cmp(exponent_integer, 0);
920 __ Cneg(exponent_abs, exponent_integer, mi);
921 // x13 exponent_abs The value of abs(exponent_integer).
923 // Repeatedly multiply to calculate the power.
925 // For each bit n (exponent_integer{n}) {
926 // if (exponent_integer{n}) {
930 // if (remaining bits in exponent_integer are all zero) {
934 Label power_loop, power_loop_entry, power_loop_exit;
935 __ Fmov(scratch1_double, base_double);
936 __ Fmov(base_double_copy, base_double);
937 __ Fmov(result_double, 1.0);
938 __ B(&power_loop_entry);
940 __ Bind(&power_loop);
941 __ Fmul(scratch1_double, scratch1_double, scratch1_double);
942 __ Lsr(exponent_abs, exponent_abs, 1);
943 __ Cbz(exponent_abs, &power_loop_exit);
945 __ Bind(&power_loop_entry);
946 __ Tbz(exponent_abs, 0, &power_loop);
947 __ Fmul(result_double, result_double, scratch1_double);
950 __ Bind(&power_loop_exit);
952 // If the exponent was positive, result_double holds the result.
953 __ Tbz(exponent_integer, kXSignBit, &done);
955 // The exponent was negative, so find the inverse.
956 __ Fmov(scratch0_double, 1.0);
957 __ Fdiv(result_double, scratch0_double, result_double);
958 // ECMA-262 only requires Math.pow to return an 'implementation-dependent
959 // approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
960 // to calculate the subnormal value 2^-1074. This method of calculating
961 // negative powers doesn't work because 2^1074 overflows to infinity. To
962 // catch this corner-case, we bail out if the result was 0. (This can only
963 // occur if the divisor is infinity or the base is zero.)
964 __ Fcmp(result_double, 0.0);
967 if (exponent_type() == ON_STACK) {
968 // Bail out to runtime code.
969 __ Bind(&call_runtime);
970 // Put the arguments back on the stack.
971 __ Push(base_tagged, exponent_tagged);
972 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
976 __ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1,
978 DCHECK(result_tagged.is(x0));
980 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
983 AllowExternalCallThatCantCauseGC scope(masm);
984 __ Mov(saved_lr, lr);
985 __ Fmov(base_double, base_double_copy);
986 __ Scvtf(exponent_double, exponent_integer);
988 ExternalReference::power_double_double_function(isolate()),
990 __ Mov(lr, saved_lr);
993 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
999 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1000 // It is important that the following stubs are generated in this order
1001 // because pregenerated stubs can only call other pregenerated stubs.
1002 // RecordWriteStub uses StoreBufferOverflowStub, which in turn uses
1004 CEntryStub::GenerateAheadOfTime(isolate);
1005 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1006 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1007 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1008 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1009 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1010 BinaryOpICStub::GenerateAheadOfTime(isolate);
1011 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1012 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1013 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1014 StoreFastElementStub::GenerateAheadOfTime(isolate);
1015 TypeofStub::GenerateAheadOfTime(isolate);
1019 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1020 StoreRegistersStateStub stub(isolate);
1025 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1026 RestoreRegistersStateStub stub(isolate);
1031 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1032 // Floating-point code doesn't get special handling in ARM64, so there's
1033 // nothing to do here.
1038 bool CEntryStub::NeedsImmovableCode() {
1039 // CEntryStub stores the return address on the stack before calling into
1040 // C++ code. In some cases, the VM accesses this address, but it is not used
1041 // when the C++ code returns to the stub because LR holds the return address
1042 // in AAPCS64. If the stub is moved (perhaps during a GC), we could end up
1043 // returning to dead code.
1044 // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't
1045 // find any comment to confirm this, and I don't hit any crashes whatever
1046 // this function returns. The anaylsis should be properly confirmed.
1051 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1052 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1054 CEntryStub stub_fp(isolate, 1, kSaveFPRegs);
1059 void CEntryStub::Generate(MacroAssembler* masm) {
1060 // The Abort mechanism relies on CallRuntime, which in turn relies on
1061 // CEntryStub, so until this stub has been generated, we have to use a
1062 // fall-back Abort mechanism.
1064 // Note that this stub must be generated before any use of Abort.
1065 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
1067 ASM_LOCATION("CEntryStub::Generate entry");
1068 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1070 // Register parameters:
1071 // x0: argc (including receiver, untagged)
1074 // The stack on entry holds the arguments and the receiver, with the receiver
1075 // at the highest address:
1077 // jssp]argc-1]: receiver
1078 // jssp[argc-2]: arg[argc-2]
1083 // The arguments are in reverse order, so that arg[argc-2] is actually the
1084 // first argument to the target function and arg[0] is the last.
1085 DCHECK(jssp.Is(__ StackPointer()));
1086 const Register& argc_input = x0;
1087 const Register& target_input = x1;
1089 // Calculate argv, argc and the target address, and store them in
1090 // callee-saved registers so we can retry the call without having to reload
1092 // TODO(jbramley): If the first call attempt succeeds in the common case (as
1093 // it should), then we might be better off putting these parameters directly
1094 // into their argument registers, rather than using callee-saved registers and
1095 // preserving them on the stack.
1096 const Register& argv = x21;
1097 const Register& argc = x22;
1098 const Register& target = x23;
1100 // Derive argv from the stack pointer so that it points to the first argument
1101 // (arg[argc-2]), or just below the receiver in case there are no arguments.
1102 // - Adjust for the arg[] array.
1103 Register temp_argv = x11;
1104 __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
1105 // - Adjust for the receiver.
1106 __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
1108 // Enter the exit frame. Reserve three slots to preserve x21-x23 callee-saved
1110 FrameScope scope(masm, StackFrame::MANUAL);
1111 __ EnterExitFrame(save_doubles(), x10, 3);
1112 DCHECK(csp.Is(__ StackPointer()));
1114 // Poke callee-saved registers into reserved space.
1115 __ Poke(argv, 1 * kPointerSize);
1116 __ Poke(argc, 2 * kPointerSize);
1117 __ Poke(target, 3 * kPointerSize);
1119 // We normally only keep tagged values in callee-saved registers, as they
1120 // could be pushed onto the stack by called stubs and functions, and on the
1121 // stack they can confuse the GC. However, we're only calling C functions
1122 // which can push arbitrary data onto the stack anyway, and so the GC won't
1123 // examine that part of the stack.
1124 __ Mov(argc, argc_input);
1125 __ Mov(target, target_input);
1126 __ Mov(argv, temp_argv);
1130 // x23 : call target
1132 // The stack (on entry) holds the arguments and the receiver, with the
1133 // receiver at the highest address:
1135 // argv[8]: receiver
1136 // argv -> argv[0]: arg[argc-2]
1138 // argv[...]: arg[1]
1139 // argv[...]: arg[0]
1141 // Immediately below (after) this is the exit frame, as constructed by
1143 // fp[8]: CallerPC (lr)
1144 // fp -> fp[0]: CallerFP (old fp)
1145 // fp[-8]: Space reserved for SPOffset.
1146 // fp[-16]: CodeObject()
1147 // csp[...]: Saved doubles, if saved_doubles is true.
1148 // csp[32]: Alignment padding, if necessary.
1149 // csp[24]: Preserved x23 (used for target).
1150 // csp[16]: Preserved x22 (used for argc).
1151 // csp[8]: Preserved x21 (used for argv).
1152 // csp -> csp[0]: Space reserved for the return address.
1154 // After a successful call, the exit frame, preserved registers (x21-x23) and
1155 // the arguments (including the receiver) are dropped or popped as
1156 // appropriate. The stub then returns.
1158 // After an unsuccessful call, the exit frame and suchlike are left
1159 // untouched, and the stub either throws an exception by jumping to one of
1160 // the exception_returned label.
1162 DCHECK(csp.Is(__ StackPointer()));
1164 // Prepare AAPCS64 arguments to pass to the builtin.
1167 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1169 Label return_location;
1170 __ Adr(x12, &return_location);
1173 if (__ emit_debug_code()) {
1174 // Verify that the slot below fp[kSPOffset]-8 points to the return location
1175 // (currently in x12).
1176 UseScratchRegisterScope temps(masm);
1177 Register temp = temps.AcquireX();
1178 __ Ldr(temp, MemOperand(fp, ExitFrameConstants::kSPOffset));
1179 __ Ldr(temp, MemOperand(temp, -static_cast<int64_t>(kXRegSize)));
1181 __ Check(eq, kReturnAddressNotFoundInFrame);
1184 // Call the builtin.
1186 __ Bind(&return_location);
1188 // x0 result The return code from the call.
1192 const Register& result = x0;
1194 // Check result for exception sentinel.
1195 Label exception_returned;
1196 __ CompareRoot(result, Heap::kExceptionRootIndex);
1197 __ B(eq, &exception_returned);
1199 // The call succeeded, so unwind the stack and return.
1201 // Restore callee-saved registers x21-x23.
1204 __ Peek(argv, 1 * kPointerSize);
1205 __ Peek(argc, 2 * kPointerSize);
1206 __ Peek(target, 3 * kPointerSize);
1208 __ LeaveExitFrame(save_doubles(), x10, true);
1209 DCHECK(jssp.Is(__ StackPointer()));
1210 // Pop or drop the remaining stack slots and return from the stub.
1211 // jssp[24]: Arguments array (of size argc), including receiver.
1212 // jssp[16]: Preserved x23 (used for target).
1213 // jssp[8]: Preserved x22 (used for argc).
1214 // jssp[0]: Preserved x21 (used for argv).
1216 __ AssertFPCRState();
1219 // The stack pointer is still csp if we aren't returning, and the frame
1220 // hasn't changed (except for the return address).
1221 __ SetStackPointer(csp);
1223 // Handling of exception.
1224 __ Bind(&exception_returned);
1226 ExternalReference pending_handler_context_address(
1227 Isolate::kPendingHandlerContextAddress, isolate());
1228 ExternalReference pending_handler_code_address(
1229 Isolate::kPendingHandlerCodeAddress, isolate());
1230 ExternalReference pending_handler_offset_address(
1231 Isolate::kPendingHandlerOffsetAddress, isolate());
1232 ExternalReference pending_handler_fp_address(
1233 Isolate::kPendingHandlerFPAddress, isolate());
1234 ExternalReference pending_handler_sp_address(
1235 Isolate::kPendingHandlerSPAddress, isolate());
1237 // Ask the runtime for help to determine the handler. This will set x0 to
1238 // contain the current pending exception, don't clobber it.
1239 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1241 DCHECK(csp.Is(masm->StackPointer()));
1243 FrameScope scope(masm, StackFrame::MANUAL);
1244 __ Mov(x0, 0); // argc.
1245 __ Mov(x1, 0); // argv.
1246 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1247 __ CallCFunction(find_handler, 3);
1250 // We didn't execute a return case, so the stack frame hasn't been updated
1251 // (except for the return address slot). However, we don't need to initialize
1252 // jssp because the throw method will immediately overwrite it when it
1253 // unwinds the stack.
1254 __ SetStackPointer(jssp);
1256 // Retrieve the handler context, SP and FP.
1257 __ Mov(cp, Operand(pending_handler_context_address));
1258 __ Ldr(cp, MemOperand(cp));
1259 __ Mov(jssp, Operand(pending_handler_sp_address));
1260 __ Ldr(jssp, MemOperand(jssp));
1261 __ Mov(fp, Operand(pending_handler_fp_address));
1262 __ Ldr(fp, MemOperand(fp));
1264 // If the handler is a JS frame, restore the context to the frame. Note that
1265 // the context will be set to (cp == 0) for non-JS frames.
1267 __ Cbz(cp, ¬_js_frame);
1268 __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1269 __ Bind(¬_js_frame);
1271 // Compute the handler entry address and jump to it.
1272 __ Mov(x10, Operand(pending_handler_code_address));
1273 __ Ldr(x10, MemOperand(x10));
1274 __ Mov(x11, Operand(pending_handler_offset_address));
1275 __ Ldr(x11, MemOperand(x11));
1276 __ Add(x10, x10, Code::kHeaderSize - kHeapObjectTag);
1277 __ Add(x10, x10, x11);
1282 // This is the entry point from C++. 5 arguments are provided in x0-x4.
1283 // See use of the CALL_GENERATED_CODE macro for example in src/execution.cc.
1292 void JSEntryStub::Generate(MacroAssembler* masm) {
1293 DCHECK(jssp.Is(__ StackPointer()));
1294 Register code_entry = x0;
1296 // Enable instruction instrumentation. This only works on the simulator, and
1297 // will have no effect on the model or real hardware.
1298 __ EnableInstrumentation();
1300 Label invoke, handler_entry, exit;
1302 // Push callee-saved registers and synchronize the system stack pointer (csp)
1303 // and the JavaScript stack pointer (jssp).
1305 // We must not write to jssp until after the PushCalleeSavedRegisters()
1306 // call, since jssp is itself a callee-saved register.
1307 __ SetStackPointer(csp);
1308 __ PushCalleeSavedRegisters();
1310 __ SetStackPointer(jssp);
1312 // Configure the FPCR. We don't restore it, so this is technically not allowed
1313 // according to AAPCS64. However, we only set default-NaN mode and this will
1314 // be harmless for most C code. Also, it works for ARM.
1317 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1319 // Set up the reserved register for 0.0.
1320 __ Fmov(fp_zero, 0.0);
1322 // Build an entry frame (see layout below).
1323 int marker = type();
1324 int64_t bad_frame_pointer = -1L; // Bad frame pointer to fail if it is used.
1325 __ Mov(x13, bad_frame_pointer);
1326 __ Mov(x12, Smi::FromInt(marker));
1327 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1328 __ Ldr(x10, MemOperand(x11));
1330 __ Push(x13, xzr, x12, x10);
1332 __ Sub(fp, jssp, EntryFrameConstants::kCallerFPOffset);
1334 // Push the JS entry frame marker. Also set js_entry_sp if this is the
1335 // outermost JS call.
1336 Label non_outermost_js, done;
1337 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1338 __ Mov(x10, ExternalReference(js_entry_sp));
1339 __ Ldr(x11, MemOperand(x10));
1340 __ Cbnz(x11, &non_outermost_js);
1341 __ Str(fp, MemOperand(x10));
1342 __ Mov(x12, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1345 __ Bind(&non_outermost_js);
1346 // We spare one instruction by pushing xzr since the marker is 0.
1347 DCHECK(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME) == NULL);
1351 // The frame set up looks like this:
1352 // jssp[0] : JS entry frame marker.
1353 // jssp[1] : C entry FP.
1354 // jssp[2] : stack frame marker.
1355 // jssp[3] : stack frmae marker.
1356 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1359 // Jump to a faked try block that does the invoke, with a faked catch
1360 // block that sets the pending exception.
1363 // Prevent the constant pool from being emitted between the record of the
1364 // handler_entry position and the first instruction of the sequence here.
1365 // There is no risk because Assembler::Emit() emits the instruction before
1366 // checking for constant pool emission, but we do not want to depend on
1369 Assembler::BlockPoolsScope block_pools(masm);
1370 __ bind(&handler_entry);
1371 handler_offset_ = handler_entry.pos();
1372 // Caught exception: Store result (exception) in the pending exception
1373 // field in the JSEnv and return a failure sentinel. Coming in here the
1374 // fp will be invalid because the PushTryHandler below sets it to 0 to
1375 // signal the existence of the JSEntry frame.
1376 __ Mov(x10, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1379 __ Str(code_entry, MemOperand(x10));
1380 __ LoadRoot(x0, Heap::kExceptionRootIndex);
1383 // Invoke: Link this frame into the handler chain.
1385 __ PushStackHandler();
1386 // If an exception not caught by another handler occurs, this handler
1387 // returns control to the code after the B(&invoke) above, which
1388 // restores all callee-saved registers (including cp and fp) to their
1389 // saved values before returning a failure to C.
1391 // Clear any pending exceptions.
1392 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
1393 __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1395 __ Str(x10, MemOperand(x11));
1397 // Invoke the function by calling through the JS entry trampoline builtin.
1398 // Notice that we cannot store a reference to the trampoline code directly in
1399 // this stub, because runtime stubs are not traversed when doing GC.
1401 // Expected registers by Builtins::JSEntryTrampoline
1407 ExternalReference entry(type() == StackFrame::ENTRY_CONSTRUCT
1408 ? Builtins::kJSConstructEntryTrampoline
1409 : Builtins::kJSEntryTrampoline,
1413 // Call the JSEntryTrampoline.
1414 __ Ldr(x11, MemOperand(x10)); // Dereference the address.
1415 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag);
1418 // Unlink this frame from the handler chain.
1419 __ PopStackHandler();
1423 // x0 holds the result.
1424 // The stack pointer points to the top of the entry frame pushed on entry from
1425 // C++ (at the beginning of this stub):
1426 // jssp[0] : JS entry frame marker.
1427 // jssp[1] : C entry FP.
1428 // jssp[2] : stack frame marker.
1429 // jssp[3] : stack frmae marker.
1430 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1432 // Check if the current stack frame is marked as the outermost JS frame.
1433 Label non_outermost_js_2;
1435 __ Cmp(x10, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1436 __ B(ne, &non_outermost_js_2);
1437 __ Mov(x11, ExternalReference(js_entry_sp));
1438 __ Str(xzr, MemOperand(x11));
1439 __ Bind(&non_outermost_js_2);
1441 // Restore the top frame descriptors from the stack.
1443 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1444 __ Str(x10, MemOperand(x11));
1446 // Reset the stack to the callee saved registers.
1447 __ Drop(-EntryFrameConstants::kCallerFPOffset, kByteSizeInBytes);
1448 // Restore the callee-saved registers and return.
1449 DCHECK(jssp.Is(__ StackPointer()));
1451 __ SetStackPointer(csp);
1452 __ PopCalleeSavedRegisters();
1453 // After this point, we must not modify jssp because it is a callee-saved
1454 // register which we have just restored.
1459 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1461 Register receiver = LoadDescriptor::ReceiverRegister();
1462 // Ensure that the vector and slot registers won't be clobbered before
1463 // calling the miss handler.
1464 DCHECK(!AreAliased(x10, x11, LoadWithVectorDescriptor::VectorRegister(),
1465 LoadWithVectorDescriptor::SlotRegister()));
1467 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, x10,
1471 PropertyAccessCompiler::TailCallBuiltin(
1472 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1476 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1477 // Return address is in lr.
1480 Register receiver = LoadDescriptor::ReceiverRegister();
1481 Register index = LoadDescriptor::NameRegister();
1482 Register result = x0;
1483 Register scratch = x10;
1484 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1485 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1486 result.is(LoadWithVectorDescriptor::SlotRegister()));
1488 // StringCharAtGenerator doesn't use the result register until it's passed
1489 // the different miss possibilities. If it did, we would have a conflict
1490 // when FLAG_vector_ics is true.
1491 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1492 &miss, // When not a string.
1493 &miss, // When not a number.
1494 &miss, // When index out of range.
1495 STRING_INDEX_IS_ARRAY_INDEX,
1496 RECEIVER_IS_STRING);
1497 char_at_generator.GenerateFast(masm);
1500 StubRuntimeCallHelper call_helper;
1501 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1504 PropertyAccessCompiler::TailCallBuiltin(
1505 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1509 void InstanceOfStub::Generate(MacroAssembler* masm) {
1510 Register const object = x1; // Object (lhs).
1511 Register const function = x0; // Function (rhs).
1512 Register const object_map = x2; // Map of {object}.
1513 Register const function_map = x3; // Map of {function}.
1514 Register const function_prototype = x4; // Prototype of {function}.
1515 Register const scratch = x5;
1517 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1518 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1520 // Check if {object} is a smi.
1521 Label object_is_smi;
1522 __ JumpIfSmi(object, &object_is_smi);
1524 // Lookup the {function} and the {object} map in the global instanceof cache.
1525 // Note: This is safe because we clear the global instanceof cache whenever
1526 // we change the prototype of any object.
1527 Label fast_case, slow_case;
1528 __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1529 __ JumpIfNotRoot(function, Heap::kInstanceofCacheFunctionRootIndex,
1531 __ JumpIfNotRoot(object_map, Heap::kInstanceofCacheMapRootIndex, &fast_case);
1532 __ LoadRoot(x0, Heap::kInstanceofCacheAnswerRootIndex);
1535 // If {object} is a smi we can safely return false if {function} is a JS
1536 // function, otherwise we have to miss to the runtime and throw an exception.
1537 __ Bind(&object_is_smi);
1538 __ JumpIfSmi(function, &slow_case);
1539 __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
1541 __ LoadRoot(x0, Heap::kFalseValueRootIndex);
1544 // Fast-case: The {function} must be a valid JSFunction.
1545 __ Bind(&fast_case);
1546 __ JumpIfSmi(function, &slow_case);
1547 __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
1550 // Ensure that {function} has an instance prototype.
1551 __ Ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1552 __ Tbnz(scratch, Map::kHasNonInstancePrototype, &slow_case);
1554 // Ensure that {function} is not bound.
1555 Register const shared_info = scratch;
1556 Register const scratch_w = scratch.W();
1558 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1559 // On 64-bit platforms, compiler hints field is not a smi. See definition of
1560 // kCompilerHintsOffset in src/objects.h.
1561 __ Ldr(scratch_w, FieldMemOperand(shared_info,
1562 SharedFunctionInfo::kCompilerHintsOffset));
1563 __ Tbnz(scratch_w, SharedFunctionInfo::kBoundFunction, &slow_case);
1565 // Get the "prototype" (or initial map) of the {function}.
1566 __ Ldr(function_prototype,
1567 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1568 __ AssertNotSmi(function_prototype);
1570 // Resolve the prototype if the {function} has an initial map. Afterwards the
1571 // {function_prototype} will be either the JSReceiver prototype object or the
1572 // hole value, which means that no instances of the {function} were created so
1573 // far and hence we should return false.
1574 Label function_prototype_valid;
1575 __ JumpIfNotObjectType(function_prototype, scratch, scratch, MAP_TYPE,
1576 &function_prototype_valid);
1577 __ Ldr(function_prototype,
1578 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1579 __ Bind(&function_prototype_valid);
1580 __ AssertNotSmi(function_prototype);
1582 // Update the global instanceof cache with the current {object} map and
1583 // {function}. The cached answer will be set when it is known below.
1584 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1585 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1587 // Loop through the prototype chain looking for the {function} prototype.
1588 // Assume true, and change to false if not found.
1589 Register const object_prototype = object_map;
1590 Register const null = scratch;
1592 __ LoadRoot(x0, Heap::kTrueValueRootIndex);
1593 __ LoadRoot(null, Heap::kNullValueRootIndex);
1595 __ Ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1596 __ Cmp(object_prototype, function_prototype);
1598 __ Cmp(object_prototype, null);
1599 __ Ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1601 __ LoadRoot(x0, Heap::kFalseValueRootIndex);
1603 __ StoreRoot(x0, Heap::kInstanceofCacheAnswerRootIndex);
1606 // Slow-case: Call the runtime function.
1607 __ bind(&slow_case);
1608 __ Push(object, function);
1609 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1613 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1614 Register arg_count = ArgumentsAccessReadDescriptor::parameter_count();
1615 Register key = ArgumentsAccessReadDescriptor::index();
1616 DCHECK(arg_count.is(x0));
1619 // The displacement is the offset of the last parameter (if any) relative
1620 // to the frame pointer.
1621 static const int kDisplacement =
1622 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1624 // Check that the key is a smi.
1626 __ JumpIfNotSmi(key, &slow);
1628 // Check if the calling frame is an arguments adaptor frame.
1629 Register local_fp = x11;
1630 Register caller_fp = x11;
1631 Register caller_ctx = x12;
1633 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1634 __ Ldr(caller_ctx, MemOperand(caller_fp,
1635 StandardFrameConstants::kContextOffset));
1636 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1637 __ Csel(local_fp, fp, caller_fp, ne);
1638 __ B(ne, &skip_adaptor);
1640 // Load the actual arguments limit found in the arguments adaptor frame.
1641 __ Ldr(arg_count, MemOperand(caller_fp,
1642 ArgumentsAdaptorFrameConstants::kLengthOffset));
1643 __ Bind(&skip_adaptor);
1645 // Check index against formal parameters count limit. Use unsigned comparison
1646 // to get negative check for free: branch if key < 0 or key >= arg_count.
1647 __ Cmp(key, arg_count);
1650 // Read the argument from the stack and return it.
1651 __ Sub(x10, arg_count, key);
1652 __ Add(x10, local_fp, Operand::UntagSmiAndScale(x10, kPointerSizeLog2));
1653 __ Ldr(x0, MemOperand(x10, kDisplacement));
1656 // Slow case: handle non-smi or out-of-bounds access to arguments by calling
1657 // the runtime system.
1660 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1664 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1665 // Stack layout on entry.
1666 // jssp[0]: number of parameters (tagged)
1667 // jssp[8]: address of receiver argument
1668 // jssp[16]: function
1670 // Check if the calling frame is an arguments adaptor frame.
1672 Register caller_fp = x10;
1673 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1674 // Load and untag the context.
1675 __ Ldr(w11, UntagSmiMemOperand(caller_fp,
1676 StandardFrameConstants::kContextOffset));
1677 __ Cmp(w11, StackFrame::ARGUMENTS_ADAPTOR);
1680 // Patch the arguments.length and parameters pointer in the current frame.
1681 __ Ldr(x11, MemOperand(caller_fp,
1682 ArgumentsAdaptorFrameConstants::kLengthOffset));
1683 __ Poke(x11, 0 * kXRegSize);
1684 __ Add(x10, caller_fp, Operand::UntagSmiAndScale(x11, kPointerSizeLog2));
1685 __ Add(x10, x10, StandardFrameConstants::kCallerSPOffset);
1686 __ Poke(x10, 1 * kXRegSize);
1689 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1693 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1694 // Stack layout on entry.
1695 // jssp[0]: number of parameters (tagged)
1696 // jssp[8]: address of receiver argument
1697 // jssp[16]: function
1699 // Returns pointer to result object in x0.
1701 // Note: arg_count_smi is an alias of param_count_smi.
1702 Register arg_count_smi = x3;
1703 Register param_count_smi = x3;
1704 Register param_count = x7;
1705 Register recv_arg = x14;
1706 Register function = x4;
1707 __ Pop(param_count_smi, recv_arg, function);
1708 __ SmiUntag(param_count, param_count_smi);
1710 // Check if the calling frame is an arguments adaptor frame.
1711 Register caller_fp = x11;
1712 Register caller_ctx = x12;
1714 Label adaptor_frame, try_allocate;
1715 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1716 __ Ldr(caller_ctx, MemOperand(caller_fp,
1717 StandardFrameConstants::kContextOffset));
1718 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1719 __ B(eq, &adaptor_frame);
1721 // No adaptor, parameter count = argument count.
1723 // x1 mapped_params number of mapped params, min(params, args) (uninit)
1724 // x2 arg_count number of function arguments (uninit)
1725 // x3 arg_count_smi number of function arguments (smi)
1726 // x4 function function pointer
1727 // x7 param_count number of function parameters
1728 // x11 caller_fp caller's frame pointer
1729 // x14 recv_arg pointer to receiver arguments
1731 Register arg_count = x2;
1732 __ Mov(arg_count, param_count);
1733 __ B(&try_allocate);
1735 // We have an adaptor frame. Patch the parameters pointer.
1736 __ Bind(&adaptor_frame);
1737 __ Ldr(arg_count_smi,
1738 MemOperand(caller_fp,
1739 ArgumentsAdaptorFrameConstants::kLengthOffset));
1740 __ SmiUntag(arg_count, arg_count_smi);
1741 __ Add(x10, caller_fp, Operand(arg_count, LSL, kPointerSizeLog2));
1742 __ Add(recv_arg, x10, StandardFrameConstants::kCallerSPOffset);
1744 // Compute the mapped parameter count = min(param_count, arg_count)
1745 Register mapped_params = x1;
1746 __ Cmp(param_count, arg_count);
1747 __ Csel(mapped_params, param_count, arg_count, lt);
1749 __ Bind(&try_allocate);
1751 // x0 alloc_obj pointer to allocated objects: param map, backing
1752 // store, arguments (uninit)
1753 // x1 mapped_params number of mapped parameters, min(params, args)
1754 // x2 arg_count number of function arguments
1755 // x3 arg_count_smi number of function arguments (smi)
1756 // x4 function function pointer
1757 // x7 param_count number of function parameters
1758 // x10 size size of objects to allocate (uninit)
1759 // x14 recv_arg pointer to receiver arguments
1761 // Compute the size of backing store, parameter map, and arguments object.
1762 // 1. Parameter map, has two extra words containing context and backing
1764 const int kParameterMapHeaderSize =
1765 FixedArray::kHeaderSize + 2 * kPointerSize;
1767 // Calculate the parameter map size, assuming it exists.
1768 Register size = x10;
1769 __ Mov(size, Operand(mapped_params, LSL, kPointerSizeLog2));
1770 __ Add(size, size, kParameterMapHeaderSize);
1772 // If there are no mapped parameters, set the running size total to zero.
1773 // Otherwise, use the parameter map size calculated earlier.
1774 __ Cmp(mapped_params, 0);
1775 __ CzeroX(size, eq);
1777 // 2. Add the size of the backing store and arguments object.
1778 __ Add(size, size, Operand(arg_count, LSL, kPointerSizeLog2));
1780 FixedArray::kHeaderSize + Heap::kSloppyArgumentsObjectSize);
1782 // Do the allocation of all three objects in one go. Assign this to x0, as it
1783 // will be returned to the caller.
1784 Register alloc_obj = x0;
1785 __ Allocate(size, alloc_obj, x11, x12, &runtime, TAG_OBJECT);
1787 // Get the arguments boilerplate from the current (global) context.
1789 // x0 alloc_obj pointer to allocated objects (param map, backing
1790 // store, arguments)
1791 // x1 mapped_params number of mapped parameters, min(params, args)
1792 // x2 arg_count number of function arguments
1793 // x3 arg_count_smi number of function arguments (smi)
1794 // x4 function function pointer
1795 // x7 param_count number of function parameters
1796 // x11 sloppy_args_map offset to args (or aliased args) map (uninit)
1797 // x14 recv_arg pointer to receiver arguments
1799 Register global_object = x10;
1800 Register global_ctx = x10;
1801 Register sloppy_args_map = x11;
1802 Register aliased_args_map = x10;
1803 __ Ldr(global_object, GlobalObjectMemOperand());
1804 __ Ldr(global_ctx, FieldMemOperand(global_object,
1805 GlobalObject::kNativeContextOffset));
1807 __ Ldr(sloppy_args_map,
1808 ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1811 ContextMemOperand(global_ctx, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX));
1812 __ Cmp(mapped_params, 0);
1813 __ CmovX(sloppy_args_map, aliased_args_map, ne);
1815 // Copy the JS object part.
1816 __ Str(sloppy_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
1817 __ LoadRoot(x10, Heap::kEmptyFixedArrayRootIndex);
1818 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
1819 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1821 // Set up the callee in-object property.
1822 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1823 const int kCalleeOffset = JSObject::kHeaderSize +
1824 Heap::kArgumentsCalleeIndex * kPointerSize;
1825 __ AssertNotSmi(function);
1826 __ Str(function, FieldMemOperand(alloc_obj, kCalleeOffset));
1828 // Use the length and set that as an in-object property.
1829 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1830 const int kLengthOffset = JSObject::kHeaderSize +
1831 Heap::kArgumentsLengthIndex * kPointerSize;
1832 __ Str(arg_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
1834 // Set up the elements pointer in the allocated arguments object.
1835 // If we allocated a parameter map, "elements" will point there, otherwise
1836 // it will point to the backing store.
1838 // x0 alloc_obj pointer to allocated objects (param map, backing
1839 // store, arguments)
1840 // x1 mapped_params number of mapped parameters, min(params, args)
1841 // x2 arg_count number of function arguments
1842 // x3 arg_count_smi number of function arguments (smi)
1843 // x4 function function pointer
1844 // x5 elements pointer to parameter map or backing store (uninit)
1845 // x6 backing_store pointer to backing store (uninit)
1846 // x7 param_count number of function parameters
1847 // x14 recv_arg pointer to receiver arguments
1849 Register elements = x5;
1850 __ Add(elements, alloc_obj, Heap::kSloppyArgumentsObjectSize);
1851 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1853 // Initialize parameter map. If there are no mapped arguments, we're done.
1854 Label skip_parameter_map;
1855 __ Cmp(mapped_params, 0);
1856 // Set up backing store address, because it is needed later for filling in
1857 // the unmapped arguments.
1858 Register backing_store = x6;
1859 __ CmovX(backing_store, elements, eq);
1860 __ B(eq, &skip_parameter_map);
1862 __ LoadRoot(x10, Heap::kSloppyArgumentsElementsMapRootIndex);
1863 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
1864 __ Add(x10, mapped_params, 2);
1866 __ Str(x10, FieldMemOperand(elements, FixedArray::kLengthOffset));
1867 __ Str(cp, FieldMemOperand(elements,
1868 FixedArray::kHeaderSize + 0 * kPointerSize));
1869 __ Add(x10, elements, Operand(mapped_params, LSL, kPointerSizeLog2));
1870 __ Add(x10, x10, kParameterMapHeaderSize);
1871 __ Str(x10, FieldMemOperand(elements,
1872 FixedArray::kHeaderSize + 1 * kPointerSize));
1874 // Copy the parameter slots and the holes in the arguments.
1875 // We need to fill in mapped_parameter_count slots. Then index the context,
1876 // where parameters are stored in reverse order, at:
1878 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS + parameter_count - 1
1880 // The mapped parameter thus needs to get indices:
1882 // MIN_CONTEXT_SLOTS + parameter_count - 1 ..
1883 // MIN_CONTEXT_SLOTS + parameter_count - mapped_parameter_count
1885 // We loop from right to left.
1887 // x0 alloc_obj pointer to allocated objects (param map, backing
1888 // store, arguments)
1889 // x1 mapped_params number of mapped parameters, min(params, args)
1890 // x2 arg_count number of function arguments
1891 // x3 arg_count_smi number of function arguments (smi)
1892 // x4 function function pointer
1893 // x5 elements pointer to parameter map or backing store (uninit)
1894 // x6 backing_store pointer to backing store (uninit)
1895 // x7 param_count number of function parameters
1896 // x11 loop_count parameter loop counter (uninit)
1897 // x12 index parameter index (smi, uninit)
1898 // x13 the_hole hole value (uninit)
1899 // x14 recv_arg pointer to receiver arguments
1901 Register loop_count = x11;
1902 Register index = x12;
1903 Register the_hole = x13;
1904 Label parameters_loop, parameters_test;
1905 __ Mov(loop_count, mapped_params);
1906 __ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS));
1907 __ Sub(index, index, mapped_params);
1909 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
1910 __ Add(backing_store, elements, Operand(loop_count, LSL, kPointerSizeLog2));
1911 __ Add(backing_store, backing_store, kParameterMapHeaderSize);
1913 __ B(¶meters_test);
1915 __ Bind(¶meters_loop);
1916 __ Sub(loop_count, loop_count, 1);
1917 __ Mov(x10, Operand(loop_count, LSL, kPointerSizeLog2));
1918 __ Add(x10, x10, kParameterMapHeaderSize - kHeapObjectTag);
1919 __ Str(index, MemOperand(elements, x10));
1920 __ Sub(x10, x10, kParameterMapHeaderSize - FixedArray::kHeaderSize);
1921 __ Str(the_hole, MemOperand(backing_store, x10));
1922 __ Add(index, index, Smi::FromInt(1));
1923 __ Bind(¶meters_test);
1924 __ Cbnz(loop_count, ¶meters_loop);
1926 __ Bind(&skip_parameter_map);
1927 // Copy arguments header and remaining slots (if there are any.)
1928 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
1929 __ Str(x10, FieldMemOperand(backing_store, FixedArray::kMapOffset));
1930 __ Str(arg_count_smi, FieldMemOperand(backing_store,
1931 FixedArray::kLengthOffset));
1933 // x0 alloc_obj pointer to allocated objects (param map, backing
1934 // store, arguments)
1935 // x1 mapped_params number of mapped parameters, min(params, args)
1936 // x2 arg_count number of function arguments
1937 // x4 function function pointer
1938 // x3 arg_count_smi number of function arguments (smi)
1939 // x6 backing_store pointer to backing store (uninit)
1940 // x14 recv_arg pointer to receiver arguments
1942 Label arguments_loop, arguments_test;
1943 __ Mov(x10, mapped_params);
1944 __ Sub(recv_arg, recv_arg, Operand(x10, LSL, kPointerSizeLog2));
1945 __ B(&arguments_test);
1947 __ Bind(&arguments_loop);
1948 __ Sub(recv_arg, recv_arg, kPointerSize);
1949 __ Ldr(x11, MemOperand(recv_arg));
1950 __ Add(x12, backing_store, Operand(x10, LSL, kPointerSizeLog2));
1951 __ Str(x11, FieldMemOperand(x12, FixedArray::kHeaderSize));
1952 __ Add(x10, x10, 1);
1954 __ Bind(&arguments_test);
1955 __ Cmp(x10, arg_count);
1956 __ B(lt, &arguments_loop);
1960 // Do the runtime call to allocate the arguments object.
1962 __ Push(function, recv_arg, arg_count_smi);
1963 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1967 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1968 // Return address is in lr.
1971 Register receiver = LoadDescriptor::ReceiverRegister();
1972 Register key = LoadDescriptor::NameRegister();
1974 // Check that the key is an array index, that is Uint32.
1975 __ TestAndBranchIfAnySet(key, kSmiTagMask | kSmiSignMask, &slow);
1977 // Everything is fine, call runtime.
1978 __ Push(receiver, key);
1979 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1982 PropertyAccessCompiler::TailCallBuiltin(
1983 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1987 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1988 // Stack layout on entry.
1989 // jssp[0]: number of parameters (tagged)
1990 // jssp[8]: address of receiver argument
1991 // jssp[16]: function
1993 // Returns pointer to result object in x0.
1995 // Get the stub arguments from the frame, and make an untagged copy of the
1997 Register param_count_smi = x1;
1998 Register params = x2;
1999 Register function = x3;
2000 Register param_count = x13;
2001 __ Pop(param_count_smi, params, function);
2002 __ SmiUntag(param_count, param_count_smi);
2004 // Test if arguments adaptor needed.
2005 Register caller_fp = x11;
2006 Register caller_ctx = x12;
2007 Label try_allocate, runtime;
2008 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2009 __ Ldr(caller_ctx, MemOperand(caller_fp,
2010 StandardFrameConstants::kContextOffset));
2011 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2012 __ B(ne, &try_allocate);
2014 // x1 param_count_smi number of parameters passed to function (smi)
2015 // x2 params pointer to parameters
2016 // x3 function function pointer
2017 // x11 caller_fp caller's frame pointer
2018 // x13 param_count number of parameters passed to function
2020 // Patch the argument length and parameters pointer.
2021 __ Ldr(param_count_smi,
2022 MemOperand(caller_fp,
2023 ArgumentsAdaptorFrameConstants::kLengthOffset));
2024 __ SmiUntag(param_count, param_count_smi);
2025 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2026 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2028 // Try the new space allocation. Start out with computing the size of the
2029 // arguments object and the elements array in words.
2030 Register size = x10;
2031 __ Bind(&try_allocate);
2032 __ Add(size, param_count, FixedArray::kHeaderSize / kPointerSize);
2033 __ Cmp(param_count, 0);
2034 __ CzeroX(size, eq);
2035 __ Add(size, size, Heap::kStrictArgumentsObjectSize / kPointerSize);
2037 // Do the allocation of both objects in one go. Assign this to x0, as it will
2038 // be returned to the caller.
2039 Register alloc_obj = x0;
2040 __ Allocate(size, alloc_obj, x11, x12, &runtime,
2041 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
2043 // Get the arguments boilerplate from the current (native) context.
2044 Register global_object = x10;
2045 Register global_ctx = x10;
2046 Register strict_args_map = x4;
2047 __ Ldr(global_object, GlobalObjectMemOperand());
2048 __ Ldr(global_ctx, FieldMemOperand(global_object,
2049 GlobalObject::kNativeContextOffset));
2050 __ Ldr(strict_args_map,
2051 ContextMemOperand(global_ctx, Context::STRICT_ARGUMENTS_MAP_INDEX));
2053 // x0 alloc_obj pointer to allocated objects: parameter array and
2055 // x1 param_count_smi number of parameters passed to function (smi)
2056 // x2 params pointer to parameters
2057 // x3 function function pointer
2058 // x4 strict_args_map offset to arguments map
2059 // x13 param_count number of parameters passed to function
2060 __ Str(strict_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
2061 __ LoadRoot(x5, Heap::kEmptyFixedArrayRootIndex);
2062 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
2063 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2065 // Set the smi-tagged length as an in-object property.
2066 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2067 const int kLengthOffset = JSObject::kHeaderSize +
2068 Heap::kArgumentsLengthIndex * kPointerSize;
2069 __ Str(param_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
2071 // If there are no actual arguments, we're done.
2073 __ Cbz(param_count, &done);
2075 // Set up the elements pointer in the allocated arguments object and
2076 // initialize the header in the elements fixed array.
2077 Register elements = x5;
2078 __ Add(elements, alloc_obj, Heap::kStrictArgumentsObjectSize);
2079 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2080 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
2081 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
2082 __ Str(param_count_smi, FieldMemOperand(elements, FixedArray::kLengthOffset));
2084 // x0 alloc_obj pointer to allocated objects: parameter array and
2086 // x1 param_count_smi number of parameters passed to function (smi)
2087 // x2 params pointer to parameters
2088 // x3 function function pointer
2089 // x4 array pointer to array slot (uninit)
2090 // x5 elements pointer to elements array of alloc_obj
2091 // x13 param_count number of parameters passed to function
2093 // Copy the fixed array slots.
2095 Register array = x4;
2096 // Set up pointer to first array slot.
2097 __ Add(array, elements, FixedArray::kHeaderSize - kHeapObjectTag);
2100 // Pre-decrement the parameters pointer by kPointerSize on each iteration.
2101 // Pre-decrement in order to skip receiver.
2102 __ Ldr(x10, MemOperand(params, -kPointerSize, PreIndex));
2103 // Post-increment elements by kPointerSize on each iteration.
2104 __ Str(x10, MemOperand(array, kPointerSize, PostIndex));
2105 __ Sub(param_count, param_count, 1);
2106 __ Cbnz(param_count, &loop);
2108 // Return from stub.
2112 // Do the runtime call to allocate the arguments object.
2114 __ Push(function, params, param_count_smi);
2115 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2119 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
2120 // Stack layout on entry.
2121 // jssp[0]: language mode (tagged)
2122 // jssp[8]: index of rest parameter (tagged)
2123 // jssp[16]: number of parameters (tagged)
2124 // jssp[24]: address of receiver argument
2126 // Returns pointer to result object in x0.
2128 // Get the stub arguments from the frame, and make an untagged copy of the
2130 Register language_mode_smi = x1;
2131 Register rest_index_smi = x2;
2132 Register param_count_smi = x3;
2133 Register params = x4;
2134 Register param_count = x13;
2135 __ Pop(language_mode_smi, rest_index_smi, param_count_smi, params);
2136 __ SmiUntag(param_count, param_count_smi);
2138 // Test if arguments adaptor needed.
2139 Register caller_fp = x11;
2140 Register caller_ctx = x12;
2142 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2143 __ Ldr(caller_ctx, MemOperand(caller_fp,
2144 StandardFrameConstants::kContextOffset));
2145 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2148 // x1 language_mode_smi language mode
2149 // x2 rest_index_smi index of rest parameter
2150 // x3 param_count_smi number of parameters passed to function (smi)
2151 // x4 params pointer to parameters
2152 // x11 caller_fp caller's frame pointer
2153 // x13 param_count number of parameters passed to function
2155 // Patch the argument length and parameters pointer.
2156 __ Ldr(param_count_smi,
2157 MemOperand(caller_fp,
2158 ArgumentsAdaptorFrameConstants::kLengthOffset));
2159 __ SmiUntag(param_count, param_count_smi);
2160 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2161 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2164 __ Push(params, param_count_smi, rest_index_smi, language_mode_smi);
2165 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
2169 void RegExpExecStub::Generate(MacroAssembler* masm) {
2170 #ifdef V8_INTERPRETED_REGEXP
2171 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2172 #else // V8_INTERPRETED_REGEXP
2174 // Stack frame on entry.
2175 // jssp[0]: last_match_info (expected JSArray)
2176 // jssp[8]: previous index
2177 // jssp[16]: subject string
2178 // jssp[24]: JSRegExp object
2181 // Use of registers for this function.
2183 // Variable registers:
2184 // x10-x13 used as scratch registers
2185 // w0 string_type type of subject string
2186 // x2 jsstring_length subject string length
2187 // x3 jsregexp_object JSRegExp object
2188 // w4 string_encoding Latin1 or UC16
2189 // w5 sliced_string_offset if the string is a SlicedString
2190 // offset to the underlying string
2191 // w6 string_representation groups attributes of the string:
2193 // - type of the string
2194 // - is a short external string
2195 Register string_type = w0;
2196 Register jsstring_length = x2;
2197 Register jsregexp_object = x3;
2198 Register string_encoding = w4;
2199 Register sliced_string_offset = w5;
2200 Register string_representation = w6;
2202 // These are in callee save registers and will be preserved by the call
2203 // to the native RegExp code, as this code is called using the normal
2204 // C calling convention. When calling directly from generated code the
2205 // native RegExp code will not do a GC and therefore the content of
2206 // these registers are safe to use after the call.
2208 // x19 subject subject string
2209 // x20 regexp_data RegExp data (FixedArray)
2210 // x21 last_match_info_elements info relative to the last match
2212 // x22 code_object generated regexp code
2213 Register subject = x19;
2214 Register regexp_data = x20;
2215 Register last_match_info_elements = x21;
2216 Register code_object = x22;
2219 // jssp[00]: last_match_info (JSArray)
2220 // jssp[08]: previous index
2221 // jssp[16]: subject string
2222 // jssp[24]: JSRegExp object
2224 const int kLastMatchInfoOffset = 0 * kPointerSize;
2225 const int kPreviousIndexOffset = 1 * kPointerSize;
2226 const int kSubjectOffset = 2 * kPointerSize;
2227 const int kJSRegExpOffset = 3 * kPointerSize;
2229 // Ensure that a RegExp stack is allocated.
2230 ExternalReference address_of_regexp_stack_memory_address =
2231 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2232 ExternalReference address_of_regexp_stack_memory_size =
2233 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2234 __ Mov(x10, address_of_regexp_stack_memory_size);
2235 __ Ldr(x10, MemOperand(x10));
2236 __ Cbz(x10, &runtime);
2238 // Check that the first argument is a JSRegExp object.
2239 DCHECK(jssp.Is(__ StackPointer()));
2240 __ Peek(jsregexp_object, kJSRegExpOffset);
2241 __ JumpIfSmi(jsregexp_object, &runtime);
2242 __ JumpIfNotObjectType(jsregexp_object, x10, x10, JS_REGEXP_TYPE, &runtime);
2244 // Check that the RegExp has been compiled (data contains a fixed array).
2245 __ Ldr(regexp_data, FieldMemOperand(jsregexp_object, JSRegExp::kDataOffset));
2246 if (FLAG_debug_code) {
2247 STATIC_ASSERT(kSmiTag == 0);
2248 __ Tst(regexp_data, kSmiTagMask);
2249 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2250 __ CompareObjectType(regexp_data, x10, x10, FIXED_ARRAY_TYPE);
2251 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2254 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2255 __ Ldr(x10, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2256 __ Cmp(x10, Smi::FromInt(JSRegExp::IRREGEXP));
2259 // Check that the number of captures fit in the static offsets vector buffer.
2260 // We have always at least one capture for the whole match, plus additional
2261 // ones due to capturing parentheses. A capture takes 2 registers.
2262 // The number of capture registers then is (number_of_captures + 1) * 2.
2264 UntagSmiFieldMemOperand(regexp_data,
2265 JSRegExp::kIrregexpCaptureCountOffset));
2266 // Check (number_of_captures + 1) * 2 <= offsets vector size
2267 // number_of_captures * 2 <= offsets vector size - 2
2268 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2269 __ Add(x10, x10, x10);
2270 __ Cmp(x10, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
2273 // Initialize offset for possibly sliced string.
2274 __ Mov(sliced_string_offset, 0);
2276 DCHECK(jssp.Is(__ StackPointer()));
2277 __ Peek(subject, kSubjectOffset);
2278 __ JumpIfSmi(subject, &runtime);
2280 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2281 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2283 __ Ldr(jsstring_length, FieldMemOperand(subject, String::kLengthOffset));
2285 // Handle subject string according to its encoding and representation:
2286 // (1) Sequential string? If yes, go to (5).
2287 // (2) Anything but sequential or cons? If yes, go to (6).
2288 // (3) Cons string. If the string is flat, replace subject with first string.
2289 // Otherwise bailout.
2290 // (4) Is subject external? If yes, go to (7).
2291 // (5) Sequential string. Load regexp code according to encoding.
2295 // Deferred code at the end of the stub:
2296 // (6) Not a long external string? If yes, go to (8).
2297 // (7) External string. Make it, offset-wise, look like a sequential string.
2299 // (8) Short external string or not a string? If yes, bail out to runtime.
2300 // (9) Sliced string. Replace subject with parent. Go to (4).
2302 Label check_underlying; // (4)
2303 Label seq_string; // (5)
2304 Label not_seq_nor_cons; // (6)
2305 Label external_string; // (7)
2306 Label not_long_external; // (8)
2308 // (1) Sequential string? If yes, go to (5).
2309 __ And(string_representation,
2312 kStringRepresentationMask |
2313 kShortExternalStringMask);
2314 // We depend on the fact that Strings of type
2315 // SeqString and not ShortExternalString are defined
2316 // by the following pattern:
2317 // string_type: 0XX0 XX00
2320 // | | is a SeqString
2321 // | is not a short external String
2323 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2324 STATIC_ASSERT(kShortExternalStringTag != 0);
2325 __ Cbz(string_representation, &seq_string); // Go to (5).
2327 // (2) Anything but sequential or cons? If yes, go to (6).
2328 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2329 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2330 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2331 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2332 __ Cmp(string_representation, kExternalStringTag);
2333 __ B(ge, ¬_seq_nor_cons); // Go to (6).
2335 // (3) Cons string. Check that it's flat.
2336 __ Ldr(x10, FieldMemOperand(subject, ConsString::kSecondOffset));
2337 __ JumpIfNotRoot(x10, Heap::kempty_stringRootIndex, &runtime);
2338 // Replace subject with first string.
2339 __ Ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2341 // (4) Is subject external? If yes, go to (7).
2342 __ Bind(&check_underlying);
2343 // Reload the string type.
2344 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2345 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2346 STATIC_ASSERT(kSeqStringTag == 0);
2347 // The underlying external string is never a short external string.
2348 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2349 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2350 __ TestAndBranchIfAnySet(string_type.X(),
2351 kStringRepresentationMask,
2352 &external_string); // Go to (7).
2354 // (5) Sequential string. Load regexp code according to encoding.
2355 __ Bind(&seq_string);
2357 // Check that the third argument is a positive smi less than the subject
2358 // string length. A negative value will be greater (unsigned comparison).
2359 DCHECK(jssp.Is(__ StackPointer()));
2360 __ Peek(x10, kPreviousIndexOffset);
2361 __ JumpIfNotSmi(x10, &runtime);
2362 __ Cmp(jsstring_length, x10);
2365 // Argument 2 (x1): We need to load argument 2 (the previous index) into x1
2366 // before entering the exit frame.
2367 __ SmiUntag(x1, x10);
2369 // The third bit determines the string encoding in string_type.
2370 STATIC_ASSERT(kOneByteStringTag == 0x04);
2371 STATIC_ASSERT(kTwoByteStringTag == 0x00);
2372 STATIC_ASSERT(kStringEncodingMask == 0x04);
2374 // Find the code object based on the assumptions above.
2375 // kDataOneByteCodeOffset and kDataUC16CodeOffset are adjacent, adds an offset
2376 // of kPointerSize to reach the latter.
2377 STATIC_ASSERT(JSRegExp::kDataOneByteCodeOffset + kPointerSize ==
2378 JSRegExp::kDataUC16CodeOffset);
2379 __ Mov(x10, kPointerSize);
2380 // We will need the encoding later: Latin1 = 0x04
2382 __ Ands(string_encoding, string_type, kStringEncodingMask);
2384 __ Add(x10, regexp_data, x10);
2385 __ Ldr(code_object, FieldMemOperand(x10, JSRegExp::kDataOneByteCodeOffset));
2387 // (E) Carry on. String handling is done.
2389 // Check that the irregexp code has been generated for the actual string
2390 // encoding. If it has, the field contains a code object otherwise it contains
2391 // a smi (code flushing support).
2392 __ JumpIfSmi(code_object, &runtime);
2394 // All checks done. Now push arguments for native regexp code.
2395 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1,
2399 // Isolates: note we add an additional parameter here (isolate pointer).
2400 __ EnterExitFrame(false, x10, 1);
2401 DCHECK(csp.Is(__ StackPointer()));
2403 // We have 9 arguments to pass to the regexp code, therefore we have to pass
2404 // one on the stack and the rest as registers.
2406 // Note that the placement of the argument on the stack isn't standard
2408 // csp[0]: Space for the return address placed by DirectCEntryStub.
2409 // csp[8]: Argument 9, the current isolate address.
2411 __ Mov(x10, ExternalReference::isolate_address(isolate()));
2412 __ Poke(x10, kPointerSize);
2414 Register length = w11;
2415 Register previous_index_in_bytes = w12;
2416 Register start = x13;
2418 // Load start of the subject string.
2419 __ Add(start, subject, SeqString::kHeaderSize - kHeapObjectTag);
2420 // Load the length from the original subject string from the previous stack
2421 // frame. Therefore we have to use fp, which points exactly to two pointer
2422 // sizes below the previous sp. (Because creating a new stack frame pushes
2423 // the previous fp onto the stack and decrements sp by 2 * kPointerSize.)
2424 __ Ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2425 __ Ldr(length, UntagSmiFieldMemOperand(subject, String::kLengthOffset));
2427 // Handle UC16 encoding, two bytes make one character.
2428 // string_encoding: if Latin1: 0x04
2430 STATIC_ASSERT(kStringEncodingMask == 0x04);
2431 __ Ubfx(string_encoding, string_encoding, 2, 1);
2432 __ Eor(string_encoding, string_encoding, 1);
2433 // string_encoding: if Latin1: 0
2436 // Convert string positions from characters to bytes.
2437 // Previous index is in x1.
2438 __ Lsl(previous_index_in_bytes, w1, string_encoding);
2439 __ Lsl(length, length, string_encoding);
2440 __ Lsl(sliced_string_offset, sliced_string_offset, string_encoding);
2442 // Argument 1 (x0): Subject string.
2443 __ Mov(x0, subject);
2445 // Argument 2 (x1): Previous index, already there.
2447 // Argument 3 (x2): Get the start of input.
2448 // Start of input = start of string + previous index + substring offset
2451 __ Add(w10, previous_index_in_bytes, sliced_string_offset);
2452 __ Add(x2, start, Operand(w10, UXTW));
2455 // End of input = start of input + (length of input - previous index)
2456 __ Sub(w10, length, previous_index_in_bytes);
2457 __ Add(x3, x2, Operand(w10, UXTW));
2459 // Argument 5 (x4): static offsets vector buffer.
2460 __ Mov(x4, ExternalReference::address_of_static_offsets_vector(isolate()));
2462 // Argument 6 (x5): Set the number of capture registers to zero to force
2463 // global regexps to behave as non-global. This stub is not used for global
2467 // Argument 7 (x6): Start (high end) of backtracking stack memory area.
2468 __ Mov(x10, address_of_regexp_stack_memory_address);
2469 __ Ldr(x10, MemOperand(x10));
2470 __ Mov(x11, address_of_regexp_stack_memory_size);
2471 __ Ldr(x11, MemOperand(x11));
2472 __ Add(x6, x10, x11);
2474 // Argument 8 (x7): Indicate that this is a direct call from JavaScript.
2477 // Locate the code entry and call it.
2478 __ Add(code_object, code_object, Code::kHeaderSize - kHeapObjectTag);
2479 DirectCEntryStub stub(isolate());
2480 stub.GenerateCall(masm, code_object);
2482 __ LeaveExitFrame(false, x10, true);
2484 // The generated regexp code returns an int32 in w0.
2485 Label failure, exception;
2486 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::FAILURE, eq, &failure);
2487 __ CompareAndBranch(w0,
2488 NativeRegExpMacroAssembler::EXCEPTION,
2491 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::RETRY, eq, &runtime);
2493 // Success: process the result from the native regexp code.
2494 Register number_of_capture_registers = x12;
2496 // Calculate number of capture registers (number_of_captures + 1) * 2
2497 // and store it in the last match info.
2499 UntagSmiFieldMemOperand(regexp_data,
2500 JSRegExp::kIrregexpCaptureCountOffset));
2501 __ Add(x10, x10, x10);
2502 __ Add(number_of_capture_registers, x10, 2);
2504 // Check that the fourth object is a JSArray object.
2505 DCHECK(jssp.Is(__ StackPointer()));
2506 __ Peek(x10, kLastMatchInfoOffset);
2507 __ JumpIfSmi(x10, &runtime);
2508 __ JumpIfNotObjectType(x10, x11, x11, JS_ARRAY_TYPE, &runtime);
2510 // Check that the JSArray is the fast case.
2511 __ Ldr(last_match_info_elements,
2512 FieldMemOperand(x10, JSArray::kElementsOffset));
2514 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2515 __ JumpIfNotRoot(x10, Heap::kFixedArrayMapRootIndex, &runtime);
2517 // Check that the last match info has space for the capture registers and the
2518 // additional information (overhead).
2519 // (number_of_captures + 1) * 2 + overhead <= last match info size
2520 // (number_of_captures * 2) + 2 + overhead <= last match info size
2521 // number_of_capture_registers + overhead <= last match info size
2523 UntagSmiFieldMemOperand(last_match_info_elements,
2524 FixedArray::kLengthOffset));
2525 __ Add(x11, number_of_capture_registers, RegExpImpl::kLastMatchOverhead);
2529 // Store the capture count.
2530 __ SmiTag(x10, number_of_capture_registers);
2532 FieldMemOperand(last_match_info_elements,
2533 RegExpImpl::kLastCaptureCountOffset));
2534 // Store last subject and last input.
2536 FieldMemOperand(last_match_info_elements,
2537 RegExpImpl::kLastSubjectOffset));
2538 // Use x10 as the subject string in order to only need
2539 // one RecordWriteStub.
2540 __ Mov(x10, subject);
2541 __ RecordWriteField(last_match_info_elements,
2542 RegExpImpl::kLastSubjectOffset,
2548 FieldMemOperand(last_match_info_elements,
2549 RegExpImpl::kLastInputOffset));
2550 __ Mov(x10, subject);
2551 __ RecordWriteField(last_match_info_elements,
2552 RegExpImpl::kLastInputOffset,
2558 Register last_match_offsets = x13;
2559 Register offsets_vector_index = x14;
2560 Register current_offset = x15;
2562 // Get the static offsets vector filled by the native regexp code
2563 // and fill the last match info.
2564 ExternalReference address_of_static_offsets_vector =
2565 ExternalReference::address_of_static_offsets_vector(isolate());
2566 __ Mov(offsets_vector_index, address_of_static_offsets_vector);
2568 Label next_capture, done;
2569 // Capture register counter starts from number of capture registers and
2570 // iterates down to zero (inclusive).
2571 __ Add(last_match_offsets,
2572 last_match_info_elements,
2573 RegExpImpl::kFirstCaptureOffset - kHeapObjectTag);
2574 __ Bind(&next_capture);
2575 __ Subs(number_of_capture_registers, number_of_capture_registers, 2);
2577 // Read two 32 bit values from the static offsets vector buffer into
2579 __ Ldr(current_offset,
2580 MemOperand(offsets_vector_index, kWRegSize * 2, PostIndex));
2581 // Store the smi values in the last match info.
2582 __ SmiTag(x10, current_offset);
2583 // Clearing the 32 bottom bits gives us a Smi.
2584 STATIC_ASSERT(kSmiTag == 0);
2585 __ Bic(x11, current_offset, kSmiShiftMask);
2588 MemOperand(last_match_offsets, kXRegSize * 2, PostIndex));
2589 __ B(&next_capture);
2592 // Return last match info.
2593 __ Peek(x0, kLastMatchInfoOffset);
2594 // Drop the 4 arguments of the stub from the stack.
2598 __ Bind(&exception);
2599 Register exception_value = x0;
2600 // A stack overflow (on the backtrack stack) may have occured
2601 // in the RegExp code but no exception has been created yet.
2602 // If there is no pending exception, handle that in the runtime system.
2603 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
2605 Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2607 __ Ldr(exception_value, MemOperand(x11));
2608 __ Cmp(x10, exception_value);
2611 // For exception, throw the exception again.
2612 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2615 __ Mov(x0, Operand(isolate()->factory()->null_value()));
2616 // Drop the 4 arguments of the stub from the stack.
2621 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2623 // Deferred code for string handling.
2624 // (6) Not a long external string? If yes, go to (8).
2625 __ Bind(¬_seq_nor_cons);
2626 // Compare flags are still set.
2627 __ B(ne, ¬_long_external); // Go to (8).
2629 // (7) External string. Make it, offset-wise, look like a sequential string.
2630 __ Bind(&external_string);
2631 if (masm->emit_debug_code()) {
2632 // Assert that we do not have a cons or slice (indirect strings) here.
2633 // Sequential strings have already been ruled out.
2634 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2635 __ Ldrb(x10, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2636 __ Tst(x10, kIsIndirectStringMask);
2637 __ Check(eq, kExternalStringExpectedButNotFound);
2638 __ And(x10, x10, kStringRepresentationMask);
2640 __ Check(ne, kExternalStringExpectedButNotFound);
2643 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2644 // Move the pointer so that offset-wise, it looks like a sequential string.
2645 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2646 __ Sub(subject, subject, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2647 __ B(&seq_string); // Go to (5).
2649 // (8) If this is a short external string or not a string, bail out to
2651 __ Bind(¬_long_external);
2652 STATIC_ASSERT(kShortExternalStringTag != 0);
2653 __ TestAndBranchIfAnySet(string_representation,
2654 kShortExternalStringMask | kIsNotStringMask,
2657 // (9) Sliced string. Replace subject with parent.
2658 __ Ldr(sliced_string_offset,
2659 UntagSmiFieldMemOperand(subject, SlicedString::kOffsetOffset));
2660 __ Ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2661 __ B(&check_underlying); // Go to (4).
2666 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2667 Register argc, Register function,
2668 Register feedback_vector, Register index,
2669 Register orig_construct, bool is_super) {
2670 FrameScope scope(masm, StackFrame::INTERNAL);
2672 // Number-of-arguments register must be smi-tagged to call out.
2675 __ Push(argc, function, feedback_vector, index, orig_construct);
2677 __ Push(argc, function, feedback_vector, index);
2680 DCHECK(feedback_vector.Is(x2) && index.Is(x3));
2684 __ Pop(orig_construct, index, feedback_vector, function, argc);
2686 __ Pop(index, feedback_vector, function, argc);
2692 static void GenerateRecordCallTarget(MacroAssembler* masm, Register argc,
2694 Register feedback_vector, Register index,
2695 Register orig_construct, Register scratch1,
2696 Register scratch2, Register scratch3,
2698 ASM_LOCATION("GenerateRecordCallTarget");
2699 DCHECK(!AreAliased(scratch1, scratch2, scratch3, argc, function,
2700 feedback_vector, index, orig_construct));
2701 // Cache the called function in a feedback vector slot. Cache states are
2702 // uninitialized, monomorphic (indicated by a JSFunction), and megamorphic.
2703 // argc : number of arguments to the construct function
2704 // function : the function to call
2705 // feedback_vector : the feedback vector
2706 // index : slot in feedback vector (smi)
2707 // orig_construct : original constructor (for IsSuperConstructorCall)
2708 Label initialize, done, miss, megamorphic, not_array_function;
2710 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2711 masm->isolate()->heap()->megamorphic_symbol());
2712 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2713 masm->isolate()->heap()->uninitialized_symbol());
2715 // Load the cache state.
2716 Register feedback = scratch1;
2717 Register feedback_map = scratch2;
2718 Register feedback_value = scratch3;
2719 __ Add(feedback, feedback_vector,
2720 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2721 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
2723 // A monomorphic cache hit or an already megamorphic state: invoke the
2724 // function without changing the state.
2725 // We don't know if feedback value is a WeakCell or a Symbol, but it's
2726 // harmless to read at this position in a symbol (see static asserts in
2727 // type-feedback-vector.h).
2728 Label check_allocation_site;
2729 __ Ldr(feedback_value, FieldMemOperand(feedback, WeakCell::kValueOffset));
2730 __ Cmp(function, feedback_value);
2732 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
2734 __ Ldr(feedback_map, FieldMemOperand(feedback, HeapObject::kMapOffset));
2735 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2736 __ B(ne, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2738 // If the weak cell is cleared, we have a new chance to become monomorphic.
2739 __ JumpIfSmi(feedback_value, &initialize);
2742 if (!FLAG_pretenuring_call_new) {
2743 __ bind(&check_allocation_site);
2744 // If we came here, we need to see if we are the array function.
2745 // If we didn't have a matching function, and we didn't find the megamorph
2746 // sentinel, then we have in the slot either some other function or an
2748 __ JumpIfNotRoot(feedback_map, Heap::kAllocationSiteMapRootIndex, &miss);
2750 // Make sure the function is the Array() function
2751 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2752 __ Cmp(function, scratch1);
2753 __ B(ne, &megamorphic);
2759 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2761 __ JumpIfRoot(scratch1, Heap::kuninitialized_symbolRootIndex, &initialize);
2762 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2763 // write-barrier is needed.
2764 __ Bind(&megamorphic);
2765 __ Add(scratch1, feedback_vector,
2766 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2767 __ LoadRoot(scratch2, Heap::kmegamorphic_symbolRootIndex);
2768 __ Str(scratch2, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
2771 // An uninitialized cache is patched with the function or sentinel to
2772 // indicate the ElementsKind if function is the Array constructor.
2773 __ Bind(&initialize);
2775 if (!FLAG_pretenuring_call_new) {
2776 // Make sure the function is the Array() function
2777 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2778 __ Cmp(function, scratch1);
2779 __ B(ne, ¬_array_function);
2781 // The target function is the Array constructor,
2782 // Create an AllocationSite if we don't already have it, store it in the
2784 CreateAllocationSiteStub create_stub(masm->isolate());
2785 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2786 feedback_vector, index, orig_construct,
2790 __ Bind(¬_array_function);
2793 CreateWeakCellStub create_stub(masm->isolate());
2794 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2795 feedback_vector, index, orig_construct, is_super);
2800 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2801 // Do not transform the receiver for strict mode functions.
2802 __ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
2803 __ Ldr(w4, FieldMemOperand(x3, SharedFunctionInfo::kCompilerHintsOffset));
2804 __ Tbnz(w4, SharedFunctionInfo::kStrictModeFunction, cont);
2806 // Do not transform the receiver for native (Compilerhints already in x3).
2807 __ Tbnz(w4, SharedFunctionInfo::kNative, cont);
2811 static void EmitSlowCase(MacroAssembler* masm,
2815 Label* non_function) {
2816 // Check for function proxy.
2817 // x10 : function type.
2818 __ CompareAndBranch(type, JS_FUNCTION_PROXY_TYPE, ne, non_function);
2819 __ Push(function); // put proxy as additional argument
2820 __ Mov(x0, argc + 1);
2822 __ GetBuiltinFunction(x1, Context::CALL_FUNCTION_PROXY_BUILTIN_INDEX);
2824 Handle<Code> adaptor =
2825 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2826 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2829 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2830 // of the original receiver from the call site).
2831 __ Bind(non_function);
2832 __ Poke(function, argc * kXRegSize);
2833 __ Mov(x0, argc); // Set up the number of arguments.
2835 __ GetBuiltinFunction(function, Context::CALL_NON_FUNCTION_BUILTIN_INDEX);
2836 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2837 RelocInfo::CODE_TARGET);
2841 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2842 // Wrap the receiver and patch it back onto the stack.
2843 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2846 ToObjectStub stub(masm->isolate());
2850 __ Poke(x0, argc * kPointerSize);
2855 static void CallFunctionNoFeedback(MacroAssembler* masm,
2856 int argc, bool needs_checks,
2857 bool call_as_method) {
2858 // x1 function the function to call
2859 Register function = x1;
2861 Label slow, non_function, wrap, cont;
2863 // TODO(jbramley): This function has a lot of unnamed registers. Name them,
2864 // and tidy things up a bit.
2867 // Check that the function is really a JavaScript function.
2868 __ JumpIfSmi(function, &non_function);
2870 // Goto slow case if we do not have a function.
2871 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
2874 // Fast-case: Invoke the function now.
2875 // x1 function pushed function
2876 ParameterCount actual(argc);
2878 if (call_as_method) {
2880 EmitContinueIfStrictOrNative(masm, &cont);
2883 // Compute the receiver in sloppy mode.
2884 __ Peek(x3, argc * kPointerSize);
2887 __ JumpIfSmi(x3, &wrap);
2888 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
2896 __ InvokeFunction(function,
2901 // Slow-case: Non-function called.
2903 EmitSlowCase(masm, argc, function, type, &non_function);
2906 if (call_as_method) {
2908 EmitWrapCase(masm, argc, &cont);
2913 void CallFunctionStub::Generate(MacroAssembler* masm) {
2914 ASM_LOCATION("CallFunctionStub::Generate");
2915 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2919 void CallConstructStub::Generate(MacroAssembler* masm) {
2920 ASM_LOCATION("CallConstructStub::Generate");
2921 // x0 : number of arguments
2922 // x1 : the function to call
2923 // x2 : feedback vector
2924 // x3 : slot in feedback vector (Smi, for RecordCallTarget)
2925 // x4 : original constructor (for IsSuperConstructorCall)
2926 Register function = x1;
2927 Label slow, non_function_call;
2929 // Check that the function is not a smi.
2930 __ JumpIfSmi(function, &non_function_call);
2931 // Check that the function is a JSFunction.
2932 Register object_type = x10;
2933 __ JumpIfNotObjectType(function, object_type, object_type, JS_FUNCTION_TYPE,
2936 if (RecordCallTarget()) {
2937 GenerateRecordCallTarget(masm, x0, function, x2, x3, x4, x5, x11, x12,
2938 IsSuperConstructorCall());
2940 __ Add(x5, x2, Operand::UntagSmiAndScale(x3, kPointerSizeLog2));
2941 if (FLAG_pretenuring_call_new) {
2942 // Put the AllocationSite from the feedback vector into x2.
2943 // By adding kPointerSize we encode that we know the AllocationSite
2944 // entry is at the feedback vector slot given by x3 + 1.
2945 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize + kPointerSize));
2947 Label feedback_register_initialized;
2948 // Put the AllocationSite from the feedback vector into x2, or undefined.
2949 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize));
2950 __ Ldr(x5, FieldMemOperand(x2, AllocationSite::kMapOffset));
2951 __ JumpIfRoot(x5, Heap::kAllocationSiteMapRootIndex,
2952 &feedback_register_initialized);
2953 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
2954 __ bind(&feedback_register_initialized);
2957 __ AssertUndefinedOrAllocationSite(x2, x5);
2960 if (IsSuperConstructorCall()) {
2963 __ Mov(x3, function);
2966 // Jump to the function-specific construct stub.
2967 Register jump_reg = x4;
2968 Register shared_func_info = jump_reg;
2969 Register cons_stub = jump_reg;
2970 Register cons_stub_code = jump_reg;
2971 __ Ldr(shared_func_info,
2972 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
2974 FieldMemOperand(shared_func_info,
2975 SharedFunctionInfo::kConstructStubOffset));
2976 __ Add(cons_stub_code, cons_stub, Code::kHeaderSize - kHeapObjectTag);
2977 __ Br(cons_stub_code);
2981 __ Cmp(object_type, JS_FUNCTION_PROXY_TYPE);
2982 __ B(ne, &non_function_call);
2983 __ GetBuiltinFunction(
2984 x1, Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2987 __ Bind(&non_function_call);
2988 __ GetBuiltinFunction(
2989 x1, Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2992 // Set expected number of arguments to zero (not changing x0).
2994 __ Jump(isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2995 RelocInfo::CODE_TARGET);
2999 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
3000 __ Ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
3001 __ Ldr(vector, FieldMemOperand(vector,
3002 JSFunction::kSharedFunctionInfoOffset));
3003 __ Ldr(vector, FieldMemOperand(vector,
3004 SharedFunctionInfo::kFeedbackVectorOffset));
3008 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
3013 Register function = x1;
3014 Register feedback_vector = x2;
3015 Register index = x3;
3016 Register scratch = x4;
3018 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch);
3019 __ Cmp(function, scratch);
3022 __ Mov(x0, Operand(arg_count()));
3024 __ Add(scratch, feedback_vector,
3025 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3026 __ Ldr(scratch, FieldMemOperand(scratch, FixedArray::kHeaderSize));
3028 // Verify that scratch contains an AllocationSite
3030 __ Ldr(map, FieldMemOperand(scratch, HeapObject::kMapOffset));
3031 __ JumpIfNotRoot(map, Heap::kAllocationSiteMapRootIndex, &miss);
3033 // Increment the call count for monomorphic function calls.
3034 __ Add(feedback_vector, feedback_vector,
3035 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3036 __ Add(feedback_vector, feedback_vector,
3037 Operand(FixedArray::kHeaderSize + kPointerSize));
3038 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
3039 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3040 __ Str(index, FieldMemOperand(feedback_vector, 0));
3042 Register allocation_site = feedback_vector;
3043 Register original_constructor = index;
3044 __ Mov(allocation_site, scratch);
3045 __ Mov(original_constructor, function);
3046 ArrayConstructorStub stub(masm->isolate(), arg_count());
3047 __ TailCallStub(&stub);
3052 // The slow case, we need this no matter what to complete a call after a miss.
3053 CallFunctionNoFeedback(masm,
3062 void CallICStub::Generate(MacroAssembler* masm) {
3063 ASM_LOCATION("CallICStub");
3066 // x3 - slot id (Smi)
3068 const int with_types_offset =
3069 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
3070 const int generic_offset =
3071 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
3072 Label extra_checks_or_miss, slow_start;
3073 Label slow, non_function, wrap, cont;
3074 Label have_js_function;
3075 int argc = arg_count();
3076 ParameterCount actual(argc);
3078 Register function = x1;
3079 Register feedback_vector = x2;
3080 Register index = x3;
3083 // The checks. First, does x1 match the recorded monomorphic target?
3084 __ Add(x4, feedback_vector,
3085 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3086 __ Ldr(x4, FieldMemOperand(x4, FixedArray::kHeaderSize));
3088 // We don't know that we have a weak cell. We might have a private symbol
3089 // or an AllocationSite, but the memory is safe to examine.
3090 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
3092 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
3093 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
3094 // computed, meaning that it can't appear to be a pointer. If the low bit is
3095 // 0, then hash is computed, but the 0 bit prevents the field from appearing
3097 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
3098 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
3099 WeakCell::kValueOffset &&
3100 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
3102 __ Ldr(x5, FieldMemOperand(x4, WeakCell::kValueOffset));
3103 __ Cmp(x5, function);
3104 __ B(ne, &extra_checks_or_miss);
3106 // The compare above could have been a SMI/SMI comparison. Guard against this
3107 // convincing us that we have a monomorphic JSFunction.
3108 __ JumpIfSmi(function, &extra_checks_or_miss);
3110 // Increment the call count for monomorphic function calls.
3111 __ Add(feedback_vector, feedback_vector,
3112 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3113 __ Add(feedback_vector, feedback_vector,
3114 Operand(FixedArray::kHeaderSize + kPointerSize));
3115 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
3116 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3117 __ Str(index, FieldMemOperand(feedback_vector, 0));
3119 __ bind(&have_js_function);
3120 if (CallAsMethod()) {
3121 EmitContinueIfStrictOrNative(masm, &cont);
3123 // Compute the receiver in sloppy mode.
3124 __ Peek(x3, argc * kPointerSize);
3126 __ JumpIfSmi(x3, &wrap);
3127 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
3132 __ InvokeFunction(function,
3138 EmitSlowCase(masm, argc, function, type, &non_function);
3140 if (CallAsMethod()) {
3142 EmitWrapCase(masm, argc, &cont);
3145 __ bind(&extra_checks_or_miss);
3146 Label uninitialized, miss;
3148 __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &slow_start);
3150 // The following cases attempt to handle MISS cases without going to the
3152 if (FLAG_trace_ic) {
3156 __ JumpIfRoot(x4, Heap::kuninitialized_symbolRootIndex, &miss);
3158 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3159 // to handle it here. More complex cases are dealt with in the runtime.
3160 __ AssertNotSmi(x4);
3161 __ JumpIfNotObjectType(x4, x5, x5, JS_FUNCTION_TYPE, &miss);
3162 __ Add(x4, feedback_vector,
3163 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3164 __ LoadRoot(x5, Heap::kmegamorphic_symbolRootIndex);
3165 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize));
3166 // We have to update statistics for runtime profiling.
3167 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3168 __ Subs(x4, x4, Operand(Smi::FromInt(1)));
3169 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3170 __ Ldr(x4, FieldMemOperand(feedback_vector, generic_offset));
3171 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3172 __ Str(x4, FieldMemOperand(feedback_vector, generic_offset));
3175 __ bind(&uninitialized);
3177 // We are going monomorphic, provided we actually have a JSFunction.
3178 __ JumpIfSmi(function, &miss);
3180 // Goto miss case if we do not have a function.
3181 __ JumpIfNotObjectType(function, x5, x5, JS_FUNCTION_TYPE, &miss);
3183 // Make sure the function is not the Array() function, which requires special
3184 // behavior on MISS.
3185 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, x5);
3186 __ Cmp(function, x5);
3190 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3191 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3192 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3194 // Initialize the call counter.
3195 __ Mov(x5, Smi::FromInt(CallICNexus::kCallCountIncrement));
3196 __ Adds(x4, feedback_vector,
3197 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3198 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize + kPointerSize));
3200 // Store the function. Use a stub since we need a frame for allocation.
3205 FrameScope scope(masm, StackFrame::INTERNAL);
3206 CreateWeakCellStub create_stub(masm->isolate());
3208 __ CallStub(&create_stub);
3212 __ B(&have_js_function);
3214 // We are here because tracing is on or we encountered a MISS case we can't
3220 __ bind(&slow_start);
3222 // Check that the function is really a JavaScript function.
3223 __ JumpIfSmi(function, &non_function);
3225 // Goto slow case if we do not have a function.
3226 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
3227 __ B(&have_js_function);
3231 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3232 ASM_LOCATION("CallICStub[Miss]");
3234 FrameScope scope(masm, StackFrame::INTERNAL);
3236 // Push the receiver and the function and feedback info.
3237 __ Push(x1, x2, x3);
3240 Runtime::FunctionId id = GetICState() == DEFAULT
3241 ? Runtime::kCallIC_Miss
3242 : Runtime::kCallIC_Customization_Miss;
3243 __ CallRuntime(id, 3);
3245 // Move result to edi and exit the internal frame.
3250 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3251 // If the receiver is a smi trigger the non-string case.
3252 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3253 __ JumpIfSmi(object_, receiver_not_string_);
3255 // Fetch the instance type of the receiver into result register.
3256 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3257 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3259 // If the receiver is not a string trigger the non-string case.
3260 __ TestAndBranchIfAnySet(result_, kIsNotStringMask, receiver_not_string_);
3263 // If the index is non-smi trigger the non-smi case.
3264 __ JumpIfNotSmi(index_, &index_not_smi_);
3266 __ Bind(&got_smi_index_);
3267 // Check for index out of range.
3268 __ Ldrsw(result_, UntagSmiFieldMemOperand(object_, String::kLengthOffset));
3269 __ Cmp(result_, Operand::UntagSmi(index_));
3270 __ B(ls, index_out_of_range_);
3272 __ SmiUntag(index_);
3274 StringCharLoadGenerator::Generate(masm,
3284 void StringCharCodeAtGenerator::GenerateSlow(
3285 MacroAssembler* masm, EmbedMode embed_mode,
3286 const RuntimeCallHelper& call_helper) {
3287 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3289 __ Bind(&index_not_smi_);
3290 // If index is a heap number, try converting it to an integer.
3291 __ JumpIfNotHeapNumber(index_, index_not_number_);
3292 call_helper.BeforeCall(masm);
3293 if (embed_mode == PART_OF_IC_HANDLER) {
3294 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3295 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3297 // Save object_ on the stack and pass index_ as argument for runtime call.
3298 __ Push(object_, index_);
3300 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3301 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3303 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3304 // NumberToSmi discards numbers that are not exact integers.
3305 __ CallRuntime(Runtime::kNumberToSmi, 1);
3307 // Save the conversion result before the pop instructions below
3308 // have a chance to overwrite it.
3310 if (embed_mode == PART_OF_IC_HANDLER) {
3311 __ Pop(object_, LoadWithVectorDescriptor::SlotRegister(),
3312 LoadWithVectorDescriptor::VectorRegister());
3316 // Reload the instance type.
3317 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3318 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3319 call_helper.AfterCall(masm);
3321 // If index is still not a smi, it must be out of range.
3322 __ JumpIfNotSmi(index_, index_out_of_range_);
3323 // Otherwise, return to the fast path.
3324 __ B(&got_smi_index_);
3326 // Call runtime. We get here when the receiver is a string and the
3327 // index is a number, but the code of getting the actual character
3328 // is too complex (e.g., when the string needs to be flattened).
3329 __ Bind(&call_runtime_);
3330 call_helper.BeforeCall(masm);
3332 __ Push(object_, index_);
3333 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3334 __ Mov(result_, x0);
3335 call_helper.AfterCall(masm);
3338 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3342 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3343 __ JumpIfNotSmi(code_, &slow_case_);
3344 __ Cmp(code_, Smi::FromInt(String::kMaxOneByteCharCode));
3345 __ B(hi, &slow_case_);
3347 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3348 // At this point code register contains smi tagged one-byte char code.
3349 __ Add(result_, result_, Operand::UntagSmiAndScale(code_, kPointerSizeLog2));
3350 __ Ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3351 __ JumpIfRoot(result_, Heap::kUndefinedValueRootIndex, &slow_case_);
3356 void StringCharFromCodeGenerator::GenerateSlow(
3357 MacroAssembler* masm,
3358 const RuntimeCallHelper& call_helper) {
3359 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3361 __ Bind(&slow_case_);
3362 call_helper.BeforeCall(masm);
3364 __ CallRuntime(Runtime::kCharFromCode, 1);
3365 __ Mov(result_, x0);
3366 call_helper.AfterCall(masm);
3369 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3373 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3374 // Inputs are in x0 (lhs) and x1 (rhs).
3375 DCHECK(state() == CompareICState::SMI);
3376 ASM_LOCATION("CompareICStub[Smis]");
3378 // Bail out (to 'miss') unless both x0 and x1 are smis.
3379 __ JumpIfEitherNotSmi(x0, x1, &miss);
3381 if (GetCondition() == eq) {
3382 // For equality we do not care about the sign of the result.
3385 // Untag before subtracting to avoid handling overflow.
3387 __ Sub(x0, x1, Operand::UntagSmi(x0));
3396 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3397 DCHECK(state() == CompareICState::NUMBER);
3398 ASM_LOCATION("CompareICStub[HeapNumbers]");
3400 Label unordered, maybe_undefined1, maybe_undefined2;
3401 Label miss, handle_lhs, values_in_d_regs;
3402 Label untag_rhs, untag_lhs;
3404 Register result = x0;
3407 FPRegister rhs_d = d0;
3408 FPRegister lhs_d = d1;
3410 if (left() == CompareICState::SMI) {
3411 __ JumpIfNotSmi(lhs, &miss);
3413 if (right() == CompareICState::SMI) {
3414 __ JumpIfNotSmi(rhs, &miss);
3417 __ SmiUntagToDouble(rhs_d, rhs, kSpeculativeUntag);
3418 __ SmiUntagToDouble(lhs_d, lhs, kSpeculativeUntag);
3420 // Load rhs if it's a heap number.
3421 __ JumpIfSmi(rhs, &handle_lhs);
3422 __ JumpIfNotHeapNumber(rhs, &maybe_undefined1);
3423 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
3425 // Load lhs if it's a heap number.
3426 __ Bind(&handle_lhs);
3427 __ JumpIfSmi(lhs, &values_in_d_regs);
3428 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3429 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
3431 __ Bind(&values_in_d_regs);
3432 __ Fcmp(lhs_d, rhs_d);
3433 __ B(vs, &unordered); // Overflow flag set if either is NaN.
3434 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
3435 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
3436 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
3439 __ Bind(&unordered);
3440 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3441 CompareICState::GENERIC, CompareICState::GENERIC);
3442 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3444 __ Bind(&maybe_undefined1);
3445 if (Token::IsOrderedRelationalCompareOp(op())) {
3446 __ JumpIfNotRoot(rhs, Heap::kUndefinedValueRootIndex, &miss);
3447 __ JumpIfSmi(lhs, &unordered);
3448 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3452 __ Bind(&maybe_undefined2);
3453 if (Token::IsOrderedRelationalCompareOp(op())) {
3454 __ JumpIfRoot(lhs, Heap::kUndefinedValueRootIndex, &unordered);
3462 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3463 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3464 ASM_LOCATION("CompareICStub[InternalizedStrings]");
3467 Register result = x0;
3471 // Check that both operands are heap objects.
3472 __ JumpIfEitherSmi(lhs, rhs, &miss);
3474 // Check that both operands are internalized strings.
3475 Register rhs_map = x10;
3476 Register lhs_map = x11;
3477 Register rhs_type = x10;
3478 Register lhs_type = x11;
3479 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3480 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3481 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3482 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3484 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
3485 __ Orr(x12, lhs_type, rhs_type);
3486 __ TestAndBranchIfAnySet(
3487 x12, kIsNotStringMask | kIsNotInternalizedMask, &miss);
3489 // Internalized strings are compared by identity.
3490 STATIC_ASSERT(EQUAL == 0);
3492 __ Cset(result, ne);
3500 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3501 DCHECK(state() == CompareICState::UNIQUE_NAME);
3502 ASM_LOCATION("CompareICStub[UniqueNames]");
3503 DCHECK(GetCondition() == eq);
3506 Register result = x0;
3510 Register lhs_instance_type = w2;
3511 Register rhs_instance_type = w3;
3513 // Check that both operands are heap objects.
3514 __ JumpIfEitherSmi(lhs, rhs, &miss);
3516 // Check that both operands are unique names. This leaves the instance
3517 // types loaded in tmp1 and tmp2.
3518 __ Ldr(x10, FieldMemOperand(lhs, HeapObject::kMapOffset));
3519 __ Ldr(x11, FieldMemOperand(rhs, HeapObject::kMapOffset));
3520 __ Ldrb(lhs_instance_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
3521 __ Ldrb(rhs_instance_type, FieldMemOperand(x11, Map::kInstanceTypeOffset));
3523 // To avoid a miss, each instance type should be either SYMBOL_TYPE or it
3524 // should have kInternalizedTag set.
3525 __ JumpIfNotUniqueNameInstanceType(lhs_instance_type, &miss);
3526 __ JumpIfNotUniqueNameInstanceType(rhs_instance_type, &miss);
3528 // Unique names are compared by identity.
3529 STATIC_ASSERT(EQUAL == 0);
3531 __ Cset(result, ne);
3539 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3540 DCHECK(state() == CompareICState::STRING);
3541 ASM_LOCATION("CompareICStub[Strings]");
3545 bool equality = Token::IsEqualityOp(op());
3547 Register result = x0;
3551 // Check that both operands are heap objects.
3552 __ JumpIfEitherSmi(rhs, lhs, &miss);
3554 // Check that both operands are strings.
3555 Register rhs_map = x10;
3556 Register lhs_map = x11;
3557 Register rhs_type = x10;
3558 Register lhs_type = x11;
3559 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3560 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3561 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3562 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3563 STATIC_ASSERT(kNotStringTag != 0);
3564 __ Orr(x12, lhs_type, rhs_type);
3565 __ Tbnz(x12, MaskToBit(kIsNotStringMask), &miss);
3567 // Fast check for identical strings.
3570 __ B(ne, ¬_equal);
3571 __ Mov(result, EQUAL);
3574 __ Bind(¬_equal);
3575 // Handle not identical strings
3577 // Check that both strings are internalized strings. If they are, we're done
3578 // because we already know they are not identical. We know they are both
3581 DCHECK(GetCondition() == eq);
3582 STATIC_ASSERT(kInternalizedTag == 0);
3583 Label not_internalized_strings;
3584 __ Orr(x12, lhs_type, rhs_type);
3585 __ TestAndBranchIfAnySet(
3586 x12, kIsNotInternalizedMask, ¬_internalized_strings);
3587 // Result is in rhs (x0), and not EQUAL, as rhs is not a smi.
3589 __ Bind(¬_internalized_strings);
3592 // Check that both strings are sequential one-byte.
3594 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x12,
3597 // Compare flat one-byte strings. Returns when done.
3599 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
3602 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
3606 // Handle more complex cases in runtime.
3610 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3612 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3620 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3621 DCHECK(state() == CompareICState::OBJECT);
3622 ASM_LOCATION("CompareICStub[Objects]");
3626 Register result = x0;
3630 __ JumpIfEitherSmi(rhs, lhs, &miss);
3632 __ JumpIfNotObjectType(rhs, x10, x10, JS_OBJECT_TYPE, &miss);
3633 __ JumpIfNotObjectType(lhs, x10, x10, JS_OBJECT_TYPE, &miss);
3635 DCHECK(GetCondition() == eq);
3636 __ Sub(result, rhs, lhs);
3644 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3645 ASM_LOCATION("CompareICStub[KnownObjects]");
3648 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3650 Register result = x0;
3654 __ JumpIfEitherSmi(rhs, lhs, &miss);
3656 Register rhs_map = x10;
3657 Register lhs_map = x11;
3659 __ GetWeakValue(map, cell);
3660 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3661 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3662 __ Cmp(rhs_map, map);
3664 __ Cmp(lhs_map, map);
3667 __ Sub(result, rhs, lhs);
3675 // This method handles the case where a compare stub had the wrong
3676 // implementation. It calls a miss handler, which re-writes the stub. All other
3677 // CompareICStub::Generate* methods should fall back into this one if their
3678 // operands were not the expected types.
3679 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3680 ASM_LOCATION("CompareICStub[Miss]");
3682 Register stub_entry = x11;
3684 FrameScope scope(masm, StackFrame::INTERNAL);
3687 Register right = x0;
3688 // Preserve some caller-saved registers.
3689 __ Push(x1, x0, lr);
3690 // Push the arguments.
3691 __ Mov(op, Smi::FromInt(this->op()));
3692 __ Push(left, right, op);
3694 // Call the miss handler. This also pops the arguments.
3695 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3697 // Compute the entry point of the rewritten stub.
3698 __ Add(stub_entry, x0, Code::kHeaderSize - kHeapObjectTag);
3699 // Restore caller-saved registers.
3703 // Tail-call to the new stub.
3704 __ Jump(stub_entry);
3708 void SubStringStub::Generate(MacroAssembler* masm) {
3709 ASM_LOCATION("SubStringStub::Generate");
3712 // Stack frame on entry.
3713 // lr: return address
3714 // jssp[0]: substring "to" offset
3715 // jssp[8]: substring "from" offset
3716 // jssp[16]: pointer to string object
3718 // This stub is called from the native-call %_SubString(...), so
3719 // nothing can be assumed about the arguments. It is tested that:
3720 // "string" is a sequential string,
3721 // both "from" and "to" are smis, and
3722 // 0 <= from <= to <= string.length (in debug mode.)
3723 // If any of these assumptions fail, we call the runtime system.
3725 static const int kToOffset = 0 * kPointerSize;
3726 static const int kFromOffset = 1 * kPointerSize;
3727 static const int kStringOffset = 2 * kPointerSize;
3730 Register from = x15;
3731 Register input_string = x10;
3732 Register input_length = x11;
3733 Register input_type = x12;
3734 Register result_string = x0;
3735 Register result_length = x1;
3738 __ Peek(to, kToOffset);
3739 __ Peek(from, kFromOffset);
3741 // Check that both from and to are smis. If not, jump to runtime.
3742 __ JumpIfEitherNotSmi(from, to, &runtime);
3746 // Calculate difference between from and to. If to < from, branch to runtime.
3747 __ Subs(result_length, to, from);
3750 // Check from is positive.
3751 __ Tbnz(from, kWSignBit, &runtime);
3753 // Make sure first argument is a string.
3754 __ Peek(input_string, kStringOffset);
3755 __ JumpIfSmi(input_string, &runtime);
3756 __ IsObjectJSStringType(input_string, input_type, &runtime);
3759 __ Cmp(result_length, 1);
3760 __ B(eq, &single_char);
3762 // Short-cut for the case of trivial substring.
3764 __ Ldrsw(input_length,
3765 UntagSmiFieldMemOperand(input_string, String::kLengthOffset));
3767 __ Cmp(result_length, input_length);
3768 __ CmovX(x0, input_string, eq);
3769 // Return original string.
3770 __ B(eq, &return_x0);
3772 // Longer than original string's length or negative: unsafe arguments.
3775 // Shorter than original string's length: an actual substring.
3777 // x0 to substring end character offset
3778 // x1 result_length length of substring result
3779 // x10 input_string pointer to input string object
3780 // x10 unpacked_string pointer to unpacked string object
3781 // x11 input_length length of input string
3782 // x12 input_type instance type of input string
3783 // x15 from substring start character offset
3785 // Deal with different string types: update the index if necessary and put
3786 // the underlying string into register unpacked_string.
3787 Label underlying_unpacked, sliced_string, seq_or_external_string;
3788 Label update_instance_type;
3789 // If the string is not indirect, it can only be sequential or external.
3790 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3791 STATIC_ASSERT(kIsIndirectStringMask != 0);
3793 // Test for string types, and branch/fall through to appropriate unpacking
3795 __ Tst(input_type, kIsIndirectStringMask);
3796 __ B(eq, &seq_or_external_string);
3797 __ Tst(input_type, kSlicedNotConsMask);
3798 __ B(ne, &sliced_string);
3800 Register unpacked_string = input_string;
3802 // Cons string. Check whether it is flat, then fetch first part.
3803 __ Ldr(temp, FieldMemOperand(input_string, ConsString::kSecondOffset));
3804 __ JumpIfNotRoot(temp, Heap::kempty_stringRootIndex, &runtime);
3805 __ Ldr(unpacked_string,
3806 FieldMemOperand(input_string, ConsString::kFirstOffset));
3807 __ B(&update_instance_type);
3809 __ Bind(&sliced_string);
3810 // Sliced string. Fetch parent and correct start index by offset.
3812 UntagSmiFieldMemOperand(input_string, SlicedString::kOffsetOffset));
3813 __ Add(from, from, temp);
3814 __ Ldr(unpacked_string,
3815 FieldMemOperand(input_string, SlicedString::kParentOffset));
3817 __ Bind(&update_instance_type);
3818 __ Ldr(temp, FieldMemOperand(unpacked_string, HeapObject::kMapOffset));
3819 __ Ldrb(input_type, FieldMemOperand(temp, Map::kInstanceTypeOffset));
3820 // Now control must go to &underlying_unpacked. Since the no code is generated
3821 // before then we fall through instead of generating a useless branch.
3823 __ Bind(&seq_or_external_string);
3824 // Sequential or external string. Registers unpacked_string and input_string
3825 // alias, so there's nothing to do here.
3826 // Note that if code is added here, the above code must be updated.
3828 // x0 result_string pointer to result string object (uninit)
3829 // x1 result_length length of substring result
3830 // x10 unpacked_string pointer to unpacked string object
3831 // x11 input_length length of input string
3832 // x12 input_type instance type of input string
3833 // x15 from substring start character offset
3834 __ Bind(&underlying_unpacked);
3836 if (FLAG_string_slices) {
3838 __ Cmp(result_length, SlicedString::kMinLength);
3839 // Short slice. Copy instead of slicing.
3840 __ B(lt, ©_routine);
3841 // Allocate new sliced string. At this point we do not reload the instance
3842 // type including the string encoding because we simply rely on the info
3843 // provided by the original string. It does not matter if the original
3844 // string's encoding is wrong because we always have to recheck encoding of
3845 // the newly created string's parent anyway due to externalized strings.
3846 Label two_byte_slice, set_slice_header;
3847 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3848 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3849 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_slice);
3850 __ AllocateOneByteSlicedString(result_string, result_length, x3, x4,
3852 __ B(&set_slice_header);
3854 __ Bind(&two_byte_slice);
3855 __ AllocateTwoByteSlicedString(result_string, result_length, x3, x4,
3858 __ Bind(&set_slice_header);
3860 __ Str(from, FieldMemOperand(result_string, SlicedString::kOffsetOffset));
3861 __ Str(unpacked_string,
3862 FieldMemOperand(result_string, SlicedString::kParentOffset));
3865 __ Bind(©_routine);
3868 // x0 result_string pointer to result string object (uninit)
3869 // x1 result_length length of substring result
3870 // x10 unpacked_string pointer to unpacked string object
3871 // x11 input_length length of input string
3872 // x12 input_type instance type of input string
3873 // x13 unpacked_char0 pointer to first char of unpacked string (uninit)
3874 // x13 substring_char0 pointer to first char of substring (uninit)
3875 // x14 result_char0 pointer to first char of result (uninit)
3876 // x15 from substring start character offset
3877 Register unpacked_char0 = x13;
3878 Register substring_char0 = x13;
3879 Register result_char0 = x14;
3880 Label two_byte_sequential, sequential_string, allocate_result;
3881 STATIC_ASSERT(kExternalStringTag != 0);
3882 STATIC_ASSERT(kSeqStringTag == 0);
3884 __ Tst(input_type, kExternalStringTag);
3885 __ B(eq, &sequential_string);
3887 __ Tst(input_type, kShortExternalStringTag);
3889 __ Ldr(unpacked_char0,
3890 FieldMemOperand(unpacked_string, ExternalString::kResourceDataOffset));
3891 // unpacked_char0 points to the first character of the underlying string.
3892 __ B(&allocate_result);
3894 __ Bind(&sequential_string);
3895 // Locate first character of underlying subject string.
3896 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3897 __ Add(unpacked_char0, unpacked_string,
3898 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3900 __ Bind(&allocate_result);
3901 // Sequential one-byte string. Allocate the result.
3902 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3903 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_sequential);
3905 // Allocate and copy the resulting one-byte string.
3906 __ AllocateOneByteString(result_string, result_length, x3, x4, x5, &runtime);
3908 // Locate first character of substring to copy.
3909 __ Add(substring_char0, unpacked_char0, from);
3911 // Locate first character of result.
3912 __ Add(result_char0, result_string,
3913 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3915 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3916 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3919 // Allocate and copy the resulting two-byte string.
3920 __ Bind(&two_byte_sequential);
3921 __ AllocateTwoByteString(result_string, result_length, x3, x4, x5, &runtime);
3923 // Locate first character of substring to copy.
3924 __ Add(substring_char0, unpacked_char0, Operand(from, LSL, 1));
3926 // Locate first character of result.
3927 __ Add(result_char0, result_string,
3928 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
3930 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3931 __ Add(result_length, result_length, result_length);
3932 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3934 __ Bind(&return_x0);
3935 Counters* counters = isolate()->counters();
3936 __ IncrementCounter(counters->sub_string_native(), 1, x3, x4);
3941 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3943 __ bind(&single_char);
3944 // x1: result_length
3945 // x10: input_string
3947 // x15: from (untagged)
3949 StringCharAtGenerator generator(input_string, from, result_length, x0,
3950 &runtime, &runtime, &runtime,
3951 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3952 generator.GenerateFast(masm);
3955 generator.SkipSlow(masm, &runtime);
3959 void ToNumberStub::Generate(MacroAssembler* masm) {
3960 // The ToNumber stub takes one argument in x0.
3962 __ JumpIfNotSmi(x0, ¬_smi);
3966 Label not_heap_number;
3967 __ Ldr(x1, FieldMemOperand(x0, HeapObject::kMapOffset));
3968 __ Ldrb(x1, FieldMemOperand(x1, Map::kInstanceTypeOffset));
3970 // x1: instance type
3971 __ Cmp(x1, HEAP_NUMBER_TYPE);
3972 __ B(ne, ¬_heap_number);
3974 __ Bind(¬_heap_number);
3976 Label not_string, slow_string;
3977 __ Cmp(x1, FIRST_NONSTRING_TYPE);
3978 __ B(hs, ¬_string);
3979 // Check if string has a cached array index.
3980 __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset));
3981 __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask));
3982 __ B(ne, &slow_string);
3983 __ IndexFromHash(x2, x0);
3985 __ Bind(&slow_string);
3986 __ Push(x0); // Push argument.
3987 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3988 __ Bind(¬_string);
3991 __ Cmp(x1, ODDBALL_TYPE);
3992 __ B(ne, ¬_oddball);
3993 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
3995 __ Bind(¬_oddball);
3997 __ Push(x0); // Push argument.
3998 __ InvokeBuiltin(Context::TO_NUMBER_BUILTIN_INDEX, JUMP_FUNCTION);
4002 void StringHelper::GenerateFlatOneByteStringEquals(
4003 MacroAssembler* masm, Register left, Register right, Register scratch1,
4004 Register scratch2, Register scratch3) {
4005 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3));
4006 Register result = x0;
4007 Register left_length = scratch1;
4008 Register right_length = scratch2;
4010 // Compare lengths. If lengths differ, strings can't be equal. Lengths are
4011 // smis, and don't need to be untagged.
4012 Label strings_not_equal, check_zero_length;
4013 __ Ldr(left_length, FieldMemOperand(left, String::kLengthOffset));
4014 __ Ldr(right_length, FieldMemOperand(right, String::kLengthOffset));
4015 __ Cmp(left_length, right_length);
4016 __ B(eq, &check_zero_length);
4018 __ Bind(&strings_not_equal);
4019 __ Mov(result, Smi::FromInt(NOT_EQUAL));
4022 // Check if the length is zero. If so, the strings must be equal (and empty.)
4023 Label compare_chars;
4024 __ Bind(&check_zero_length);
4025 STATIC_ASSERT(kSmiTag == 0);
4026 __ Cbnz(left_length, &compare_chars);
4027 __ Mov(result, Smi::FromInt(EQUAL));
4030 // Compare characters. Falls through if all characters are equal.
4031 __ Bind(&compare_chars);
4032 GenerateOneByteCharsCompareLoop(masm, left, right, left_length, scratch2,
4033 scratch3, &strings_not_equal);
4035 // Characters in strings are equal.
4036 __ Mov(result, Smi::FromInt(EQUAL));
4041 void StringHelper::GenerateCompareFlatOneByteStrings(
4042 MacroAssembler* masm, Register left, Register right, Register scratch1,
4043 Register scratch2, Register scratch3, Register scratch4) {
4044 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3, scratch4));
4045 Label result_not_equal, compare_lengths;
4047 // Find minimum length and length difference.
4048 Register length_delta = scratch3;
4049 __ Ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
4050 __ Ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
4051 __ Subs(length_delta, scratch1, scratch2);
4053 Register min_length = scratch1;
4054 __ Csel(min_length, scratch2, scratch1, gt);
4055 __ Cbz(min_length, &compare_lengths);
4058 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
4059 scratch4, &result_not_equal);
4061 // Compare lengths - strings up to min-length are equal.
4062 __ Bind(&compare_lengths);
4064 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
4066 // Use length_delta as result if it's zero.
4067 Register result = x0;
4068 __ Subs(result, length_delta, 0);
4070 __ Bind(&result_not_equal);
4071 Register greater = x10;
4072 Register less = x11;
4073 __ Mov(greater, Smi::FromInt(GREATER));
4074 __ Mov(less, Smi::FromInt(LESS));
4075 __ CmovX(result, greater, gt);
4076 __ CmovX(result, less, lt);
4081 void StringHelper::GenerateOneByteCharsCompareLoop(
4082 MacroAssembler* masm, Register left, Register right, Register length,
4083 Register scratch1, Register scratch2, Label* chars_not_equal) {
4084 DCHECK(!AreAliased(left, right, length, scratch1, scratch2));
4086 // Change index to run from -length to -1 by adding length to string
4087 // start. This means that loop ends when index reaches zero, which
4088 // doesn't need an additional compare.
4089 __ SmiUntag(length);
4090 __ Add(scratch1, length, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4091 __ Add(left, left, scratch1);
4092 __ Add(right, right, scratch1);
4094 Register index = length;
4095 __ Neg(index, length); // index = -length;
4100 __ Ldrb(scratch1, MemOperand(left, index));
4101 __ Ldrb(scratch2, MemOperand(right, index));
4102 __ Cmp(scratch1, scratch2);
4103 __ B(ne, chars_not_equal);
4104 __ Add(index, index, 1);
4105 __ Cbnz(index, &loop);
4109 void StringCompareStub::Generate(MacroAssembler* masm) {
4112 Counters* counters = isolate()->counters();
4114 // Stack frame on entry.
4115 // sp[0]: right string
4116 // sp[8]: left string
4117 Register right = x10;
4118 Register left = x11;
4119 Register result = x0;
4120 __ Pop(right, left);
4123 __ Subs(result, right, left);
4124 __ B(ne, ¬_same);
4125 STATIC_ASSERT(EQUAL == 0);
4126 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4131 // Check that both objects are sequential one-byte strings.
4132 __ JumpIfEitherIsNotSequentialOneByteStrings(left, right, x12, x13, &runtime);
4134 // Compare flat one-byte strings natively. Remove arguments from stack first,
4135 // as this function will generate a return.
4136 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4137 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, x12, x13,
4142 // Push arguments back on to the stack.
4143 // sp[0] = right string
4144 // sp[8] = left string.
4145 __ Push(left, right);
4147 // Call the runtime.
4148 // Returns -1 (less), 0 (equal), or 1 (greater) tagged as a small integer.
4149 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
4153 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4154 // ----------- S t a t e -------------
4157 // -- lr : return address
4158 // -----------------------------------
4160 // Load x2 with the allocation site. We stick an undefined dummy value here
4161 // and replace it with the real allocation site later when we instantiate this
4162 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
4163 __ LoadObject(x2, handle(isolate()->heap()->undefined_value()));
4165 // Make sure that we actually patched the allocation site.
4166 if (FLAG_debug_code) {
4167 __ AssertNotSmi(x2, kExpectedAllocationSite);
4168 __ Ldr(x10, FieldMemOperand(x2, HeapObject::kMapOffset));
4169 __ AssertRegisterIsRoot(x10, Heap::kAllocationSiteMapRootIndex,
4170 kExpectedAllocationSite);
4173 // Tail call into the stub that handles binary operations with allocation
4175 BinaryOpWithAllocationSiteStub stub(isolate(), state());
4176 __ TailCallStub(&stub);
4180 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4181 // We need some extra registers for this stub, they have been allocated
4182 // but we need to save them before using them.
4185 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4186 Label dont_need_remembered_set;
4188 Register val = regs_.scratch0();
4189 __ Ldr(val, MemOperand(regs_.address()));
4190 __ JumpIfNotInNewSpace(val, &dont_need_remembered_set);
4192 __ CheckPageFlagSet(regs_.object(), val, 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4193 &dont_need_remembered_set);
4195 // First notify the incremental marker if necessary, then update the
4197 CheckNeedsToInformIncrementalMarker(
4198 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4199 InformIncrementalMarker(masm);
4200 regs_.Restore(masm); // Restore the extra scratch registers we used.
4202 __ RememberedSetHelper(object(), address(),
4203 value(), // scratch1
4204 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4206 __ Bind(&dont_need_remembered_set);
4209 CheckNeedsToInformIncrementalMarker(
4210 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4211 InformIncrementalMarker(masm);
4212 regs_.Restore(masm); // Restore the extra scratch registers we used.
4217 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4218 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4220 x0.Is(regs_.address()) ? regs_.scratch0() : regs_.address();
4221 DCHECK(!address.Is(regs_.object()));
4222 DCHECK(!address.Is(x0));
4223 __ Mov(address, regs_.address());
4224 __ Mov(x0, regs_.object());
4225 __ Mov(x1, address);
4226 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4228 AllowExternalCallThatCantCauseGC scope(masm);
4229 ExternalReference function =
4230 ExternalReference::incremental_marking_record_write_function(
4232 __ CallCFunction(function, 3, 0);
4234 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4238 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4239 MacroAssembler* masm,
4240 OnNoNeedToInformIncrementalMarker on_no_need,
4243 Label need_incremental;
4244 Label need_incremental_pop_scratch;
4246 Register mem_chunk = regs_.scratch0();
4247 Register counter = regs_.scratch1();
4248 __ Bic(mem_chunk, regs_.object(), Page::kPageAlignmentMask);
4250 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4251 __ Subs(counter, counter, 1);
4253 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4254 __ B(mi, &need_incremental);
4256 // If the object is not black we don't have to inform the incremental marker.
4257 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4259 regs_.Restore(masm); // Restore the extra scratch registers we used.
4260 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4261 __ RememberedSetHelper(object(), address(),
4262 value(), // scratch1
4263 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4269 // Get the value from the slot.
4270 Register val = regs_.scratch0();
4271 __ Ldr(val, MemOperand(regs_.address()));
4273 if (mode == INCREMENTAL_COMPACTION) {
4274 Label ensure_not_white;
4276 __ CheckPageFlagClear(val, regs_.scratch1(),
4277 MemoryChunk::kEvacuationCandidateMask,
4280 __ CheckPageFlagClear(regs_.object(),
4282 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4285 __ Bind(&ensure_not_white);
4288 // We need extra registers for this, so we push the object and the address
4289 // register temporarily.
4290 __ Push(regs_.address(), regs_.object());
4291 __ EnsureNotWhite(val,
4292 regs_.scratch1(), // Scratch.
4293 regs_.object(), // Scratch.
4294 regs_.address(), // Scratch.
4295 regs_.scratch2(), // Scratch.
4296 &need_incremental_pop_scratch);
4297 __ Pop(regs_.object(), regs_.address());
4299 regs_.Restore(masm); // Restore the extra scratch registers we used.
4300 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4301 __ RememberedSetHelper(object(), address(),
4302 value(), // scratch1
4303 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4308 __ Bind(&need_incremental_pop_scratch);
4309 __ Pop(regs_.object(), regs_.address());
4311 __ Bind(&need_incremental);
4312 // Fall through when we need to inform the incremental marker.
4316 void RecordWriteStub::Generate(MacroAssembler* masm) {
4317 Label skip_to_incremental_noncompacting;
4318 Label skip_to_incremental_compacting;
4320 // We patch these two first instructions back and forth between a nop and
4321 // real branch when we start and stop incremental heap marking.
4322 // Initially the stub is expected to be in STORE_BUFFER_ONLY mode, so 2 nops
4324 // See RecordWriteStub::Patch for details.
4326 InstructionAccurateScope scope(masm, 2);
4327 __ adr(xzr, &skip_to_incremental_noncompacting);
4328 __ adr(xzr, &skip_to_incremental_compacting);
4331 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4332 __ RememberedSetHelper(object(), address(),
4333 value(), // scratch1
4334 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4338 __ Bind(&skip_to_incremental_noncompacting);
4339 GenerateIncremental(masm, INCREMENTAL);
4341 __ Bind(&skip_to_incremental_compacting);
4342 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4346 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4347 // x0 value element value to store
4348 // x3 index_smi element index as smi
4349 // sp[0] array_index_smi array literal index in function as smi
4350 // sp[1] array array literal
4352 Register value = x0;
4353 Register index_smi = x3;
4355 Register array = x1;
4356 Register array_map = x2;
4357 Register array_index_smi = x4;
4358 __ PeekPair(array_index_smi, array, 0);
4359 __ Ldr(array_map, FieldMemOperand(array, JSObject::kMapOffset));
4361 Label double_elements, smi_element, fast_elements, slow_elements;
4362 Register bitfield2 = x10;
4363 __ Ldrb(bitfield2, FieldMemOperand(array_map, Map::kBitField2Offset));
4365 // Jump if array's ElementsKind is not FAST*_SMI_ELEMENTS, FAST_ELEMENTS or
4366 // FAST_HOLEY_ELEMENTS.
4367 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4368 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4369 STATIC_ASSERT(FAST_ELEMENTS == 2);
4370 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4371 __ Cmp(bitfield2, Map::kMaximumBitField2FastHoleyElementValue);
4372 __ B(hi, &double_elements);
4374 __ JumpIfSmi(value, &smi_element);
4376 // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS.
4377 __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::ElementsKindBits::kShift),
4380 // Store into the array literal requires an elements transition. Call into
4382 __ Bind(&slow_elements);
4383 __ Push(array, index_smi, value);
4384 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4385 __ Ldr(x11, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
4386 __ Push(x11, array_index_smi);
4387 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4389 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4390 __ Bind(&fast_elements);
4391 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4392 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4393 __ Add(x11, x11, FixedArray::kHeaderSize - kHeapObjectTag);
4394 __ Str(value, MemOperand(x11));
4395 // Update the write barrier for the array store.
4396 __ RecordWrite(x10, x11, value, kLRHasNotBeenSaved, kDontSaveFPRegs,
4397 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4400 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4401 // and value is Smi.
4402 __ Bind(&smi_element);
4403 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4404 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4405 __ Str(value, FieldMemOperand(x11, FixedArray::kHeaderSize));
4408 __ Bind(&double_elements);
4409 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4410 __ StoreNumberToDoubleElements(value, index_smi, x10, x11, d0,
4416 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4417 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4418 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4419 int parameter_count_offset =
4420 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4421 __ Ldr(x1, MemOperand(fp, parameter_count_offset));
4422 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4425 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4427 // Return to IC Miss stub, continuation still on stack.
4432 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4433 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4434 LoadICStub stub(isolate(), state());
4435 stub.GenerateForTrampoline(masm);
4439 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4440 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4441 KeyedLoadICStub stub(isolate(), state());
4442 stub.GenerateForTrampoline(masm);
4446 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4447 EmitLoadTypeFeedbackVector(masm, x2);
4448 CallICStub stub(isolate(), state());
4449 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4453 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4454 EmitLoadTypeFeedbackVector(masm, x2);
4455 CallIC_ArrayStub stub(isolate(), state());
4456 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4460 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4463 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4464 GenerateImpl(masm, true);
4468 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4469 Register key, Register vector, Register slot,
4470 Register feedback, Register receiver_map,
4471 Register scratch1, Register scratch2,
4472 bool is_polymorphic, Label* miss) {
4473 // feedback initially contains the feedback array
4474 Label next_loop, prepare_next;
4475 Label load_smi_map, compare_map;
4476 Label start_polymorphic;
4478 Register cached_map = scratch1;
4481 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4482 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4483 __ Cmp(receiver_map, cached_map);
4484 __ B(ne, &start_polymorphic);
4485 // found, now call handler.
4486 Register handler = feedback;
4487 __ Ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4488 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4491 Register length = scratch2;
4492 __ Bind(&start_polymorphic);
4493 __ Ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4494 if (!is_polymorphic) {
4495 __ Cmp(length, Operand(Smi::FromInt(2)));
4499 Register too_far = length;
4500 Register pointer_reg = feedback;
4502 // +-----+------+------+-----+-----+ ... ----+
4503 // | map | len | wm0 | h0 | wm1 | hN |
4504 // +-----+------+------+-----+-----+ ... ----+
4508 // pointer_reg too_far
4509 // aka feedback scratch2
4510 // also need receiver_map
4511 // use cached_map (scratch1) to look in the weak map values.
4512 __ Add(too_far, feedback,
4513 Operand::UntagSmiAndScale(length, kPointerSizeLog2));
4514 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
4515 __ Add(pointer_reg, feedback,
4516 FixedArray::OffsetOfElementAt(2) - kHeapObjectTag);
4518 __ Bind(&next_loop);
4519 __ Ldr(cached_map, MemOperand(pointer_reg));
4520 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4521 __ Cmp(receiver_map, cached_map);
4522 __ B(ne, &prepare_next);
4523 __ Ldr(handler, MemOperand(pointer_reg, kPointerSize));
4524 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4527 __ Bind(&prepare_next);
4528 __ Add(pointer_reg, pointer_reg, kPointerSize * 2);
4529 __ Cmp(pointer_reg, too_far);
4530 __ B(lt, &next_loop);
4532 // We exhausted our array of map handler pairs.
4537 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4538 Register receiver_map, Register feedback,
4539 Register vector, Register slot,
4540 Register scratch, Label* compare_map,
4541 Label* load_smi_map, Label* try_array) {
4542 __ JumpIfSmi(receiver, load_smi_map);
4543 __ Ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4544 __ bind(compare_map);
4545 Register cached_map = scratch;
4546 // Move the weak map into the weak_cell register.
4547 __ Ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4548 __ Cmp(cached_map, receiver_map);
4549 __ B(ne, try_array);
4551 Register handler = feedback;
4552 __ Add(handler, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4554 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4555 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4560 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4561 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4562 Register name = LoadWithVectorDescriptor::NameRegister(); // x2
4563 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4564 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4565 Register feedback = x4;
4566 Register receiver_map = x5;
4567 Register scratch1 = x6;
4569 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4570 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4572 // Try to quickly handle the monomorphic case without knowing for sure
4573 // if we have a weak cell in feedback. We do know it's safe to look
4574 // at WeakCell::kValueOffset.
4575 Label try_array, load_smi_map, compare_map;
4576 Label not_array, miss;
4577 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4578 scratch1, &compare_map, &load_smi_map, &try_array);
4580 // Is it a fixed array?
4581 __ Bind(&try_array);
4582 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4583 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4584 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4585 scratch1, x7, true, &miss);
4587 __ Bind(¬_array);
4588 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
4589 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4590 Code::ComputeHandlerFlags(Code::LOAD_IC));
4591 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4592 receiver, name, feedback,
4593 receiver_map, scratch1, x7);
4596 LoadIC::GenerateMiss(masm);
4598 __ Bind(&load_smi_map);
4599 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4600 __ jmp(&compare_map);
4604 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4605 GenerateImpl(masm, false);
4609 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4610 GenerateImpl(masm, true);
4614 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4615 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4616 Register key = LoadWithVectorDescriptor::NameRegister(); // x2
4617 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4618 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4619 Register feedback = x4;
4620 Register receiver_map = x5;
4621 Register scratch1 = x6;
4623 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4624 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4626 // Try to quickly handle the monomorphic case without knowing for sure
4627 // if we have a weak cell in feedback. We do know it's safe to look
4628 // at WeakCell::kValueOffset.
4629 Label try_array, load_smi_map, compare_map;
4630 Label not_array, miss;
4631 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4632 scratch1, &compare_map, &load_smi_map, &try_array);
4634 __ Bind(&try_array);
4635 // Is it a fixed array?
4636 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4637 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4639 // We have a polymorphic element handler.
4640 Label polymorphic, try_poly_name;
4641 __ Bind(&polymorphic);
4642 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4643 scratch1, x7, true, &miss);
4645 __ Bind(¬_array);
4647 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
4649 Handle<Code> megamorphic_stub =
4650 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4651 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4653 __ Bind(&try_poly_name);
4654 // We might have a name in feedback, and a fixed array in the next slot.
4655 __ Cmp(key, feedback);
4657 // If the name comparison succeeded, we know we have a fixed array with
4658 // at least one map/handler pair.
4659 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4661 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4662 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4663 scratch1, x7, false, &miss);
4666 KeyedLoadIC::GenerateMiss(masm);
4668 __ Bind(&load_smi_map);
4669 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4670 __ jmp(&compare_map);
4674 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4675 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4676 VectorStoreICStub stub(isolate(), state());
4677 stub.GenerateForTrampoline(masm);
4681 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4682 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4683 VectorKeyedStoreICStub stub(isolate(), state());
4684 stub.GenerateForTrampoline(masm);
4688 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4689 GenerateImpl(masm, false);
4693 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4694 GenerateImpl(masm, true);
4698 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4701 // TODO(mvstanton): Implement.
4703 StoreIC::GenerateMiss(masm);
4707 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4708 GenerateImpl(masm, false);
4712 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4713 GenerateImpl(masm, true);
4717 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4720 // TODO(mvstanton): Implement.
4722 KeyedStoreIC::GenerateMiss(masm);
4726 // The entry hook is a "BumpSystemStackPointer" instruction (sub), followed by
4727 // a "Push lr" instruction, followed by a call.
4728 static const unsigned int kProfileEntryHookCallSize =
4729 Assembler::kCallSizeWithRelocation + (2 * kInstructionSize);
4732 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4733 if (masm->isolate()->function_entry_hook() != NULL) {
4734 ProfileEntryHookStub stub(masm->isolate());
4735 Assembler::BlockConstPoolScope no_const_pools(masm);
4736 DontEmitDebugCodeScope no_debug_code(masm);
4737 Label entry_hook_call_start;
4738 __ Bind(&entry_hook_call_start);
4741 DCHECK(masm->SizeOfCodeGeneratedSince(&entry_hook_call_start) ==
4742 kProfileEntryHookCallSize);
4749 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4750 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
4752 // Save all kCallerSaved registers (including lr), since this can be called
4754 // TODO(jbramley): What about FP registers?
4755 __ PushCPURegList(kCallerSaved);
4756 DCHECK(kCallerSaved.IncludesAliasOf(lr));
4757 const int kNumSavedRegs = kCallerSaved.Count();
4759 // Compute the function's address as the first argument.
4760 __ Sub(x0, lr, kProfileEntryHookCallSize);
4762 #if V8_HOST_ARCH_ARM64
4763 uintptr_t entry_hook =
4764 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
4765 __ Mov(x10, entry_hook);
4767 // Under the simulator we need to indirect the entry hook through a trampoline
4768 // function at a known address.
4769 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4770 __ Mov(x10, Operand(ExternalReference(&dispatcher,
4771 ExternalReference::BUILTIN_CALL,
4773 // It additionally takes an isolate as a third parameter
4774 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4777 // The caller's return address is above the saved temporaries.
4778 // Grab its location for the second argument to the hook.
4779 __ Add(x1, __ StackPointer(), kNumSavedRegs * kPointerSize);
4782 // Create a dummy frame, as CallCFunction requires this.
4783 FrameScope frame(masm, StackFrame::MANUAL);
4784 __ CallCFunction(x10, 2, 0);
4787 __ PopCPURegList(kCallerSaved);
4792 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4793 // When calling into C++ code the stack pointer must be csp.
4794 // Therefore this code must use csp for peek/poke operations when the
4795 // stub is generated. When the stub is called
4796 // (via DirectCEntryStub::GenerateCall), the caller must setup an ExitFrame
4797 // and configure the stack pointer *before* doing the call.
4798 const Register old_stack_pointer = __ StackPointer();
4799 __ SetStackPointer(csp);
4801 // Put return address on the stack (accessible to GC through exit frame pc).
4803 // Call the C++ function.
4805 // Return to calling code.
4807 __ AssertFPCRState();
4810 __ SetStackPointer(old_stack_pointer);
4813 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4815 // Make sure the caller configured the stack pointer (see comment in
4816 // DirectCEntryStub::Generate).
4817 DCHECK(csp.Is(__ StackPointer()));
4820 reinterpret_cast<intptr_t>(GetCode().location());
4821 __ Mov(lr, Operand(code, RelocInfo::CODE_TARGET));
4822 __ Mov(x10, target);
4823 // Branch to the stub.
4828 // Probe the name dictionary in the 'elements' register.
4829 // Jump to the 'done' label if a property with the given name is found.
4830 // Jump to the 'miss' label otherwise.
4832 // If lookup was successful 'scratch2' will be equal to elements + 4 * index.
4833 // 'elements' and 'name' registers are preserved on miss.
4834 void NameDictionaryLookupStub::GeneratePositiveLookup(
4835 MacroAssembler* masm,
4841 Register scratch2) {
4842 DCHECK(!AreAliased(elements, name, scratch1, scratch2));
4844 // Assert that name contains a string.
4845 __ AssertName(name);
4847 // Compute the capacity mask.
4848 __ Ldrsw(scratch1, UntagSmiFieldMemOperand(elements, kCapacityOffset));
4849 __ Sub(scratch1, scratch1, 1);
4851 // Generate an unrolled loop that performs a few probes before giving up.
4852 for (int i = 0; i < kInlinedProbes; i++) {
4853 // Compute the masked index: (hash + i + i * i) & mask.
4854 __ Ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4856 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4857 // the hash in a separate instruction. The value hash + i + i * i is right
4858 // shifted in the following and instruction.
4859 DCHECK(NameDictionary::GetProbeOffset(i) <
4860 1 << (32 - Name::kHashFieldOffset));
4861 __ Add(scratch2, scratch2, Operand(
4862 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4864 __ And(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
4866 // Scale the index by multiplying by the element size.
4867 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4868 __ Add(scratch2, scratch2, Operand(scratch2, LSL, 1));
4870 // Check if the key is identical to the name.
4871 UseScratchRegisterScope temps(masm);
4872 Register scratch3 = temps.AcquireX();
4873 __ Add(scratch2, elements, Operand(scratch2, LSL, kPointerSizeLog2));
4874 __ Ldr(scratch3, FieldMemOperand(scratch2, kElementsStartOffset));
4875 __ Cmp(name, scratch3);
4879 // The inlined probes didn't find the entry.
4880 // Call the complete stub to scan the whole dictionary.
4882 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4883 spill_list.Combine(lr);
4884 spill_list.Remove(scratch1);
4885 spill_list.Remove(scratch2);
4887 __ PushCPURegList(spill_list);
4890 DCHECK(!elements.is(x1));
4892 __ Mov(x0, elements);
4894 __ Mov(x0, elements);
4899 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4901 __ Cbz(x0, ¬_found);
4902 __ Mov(scratch2, x2); // Move entry index into scratch2.
4903 __ PopCPURegList(spill_list);
4906 __ Bind(¬_found);
4907 __ PopCPURegList(spill_list);
4912 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4916 Register properties,
4918 Register scratch0) {
4919 DCHECK(!AreAliased(receiver, properties, scratch0));
4920 DCHECK(name->IsUniqueName());
4921 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4922 // not equal to the name and kProbes-th slot is not used (its name is the
4923 // undefined value), it guarantees the hash table doesn't contain the
4924 // property. It's true even if some slots represent deleted properties
4925 // (their names are the hole value).
4926 for (int i = 0; i < kInlinedProbes; i++) {
4927 // scratch0 points to properties hash.
4928 // Compute the masked index: (hash + i + i * i) & mask.
4929 Register index = scratch0;
4930 // Capacity is smi 2^n.
4931 __ Ldrsw(index, UntagSmiFieldMemOperand(properties, kCapacityOffset));
4932 __ Sub(index, index, 1);
4933 __ And(index, index, name->Hash() + NameDictionary::GetProbeOffset(i));
4935 // Scale the index by multiplying by the entry size.
4936 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4937 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
4939 Register entity_name = scratch0;
4940 // Having undefined at this place means the name is not contained.
4941 Register tmp = index;
4942 __ Add(tmp, properties, Operand(index, LSL, kPointerSizeLog2));
4943 __ Ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4945 __ JumpIfRoot(entity_name, Heap::kUndefinedValueRootIndex, done);
4947 // Stop if found the property.
4948 __ Cmp(entity_name, Operand(name));
4952 __ JumpIfRoot(entity_name, Heap::kTheHoleValueRootIndex, &good);
4954 // Check if the entry name is not a unique name.
4955 __ Ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4956 __ Ldrb(entity_name,
4957 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4958 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4962 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4963 spill_list.Combine(lr);
4964 spill_list.Remove(scratch0); // Scratch registers don't need to be preserved.
4966 __ PushCPURegList(spill_list);
4968 __ Ldr(x0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4969 __ Mov(x1, Operand(name));
4970 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4972 // Move stub return value to scratch0. Note that scratch0 is not included in
4973 // spill_list and won't be clobbered by PopCPURegList.
4974 __ Mov(scratch0, x0);
4975 __ PopCPURegList(spill_list);
4977 __ Cbz(scratch0, done);
4982 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4983 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4984 // we cannot call anything that could cause a GC from this stub.
4986 // Arguments are in x0 and x1:
4987 // x0: property dictionary.
4988 // x1: the name of the property we are looking for.
4990 // Return value is in x0 and is zero if lookup failed, non zero otherwise.
4991 // If the lookup is successful, x2 will contains the index of the entry.
4993 Register result = x0;
4994 Register dictionary = x0;
4996 Register index = x2;
4999 Register undefined = x5;
5000 Register entry_key = x6;
5002 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
5004 __ Ldrsw(mask, UntagSmiFieldMemOperand(dictionary, kCapacityOffset));
5005 __ Sub(mask, mask, 1);
5007 __ Ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
5008 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
5010 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
5011 // Compute the masked index: (hash + i + i * i) & mask.
5012 // Capacity is smi 2^n.
5014 // Add the probe offset (i + i * i) left shifted to avoid right shifting
5015 // the hash in a separate instruction. The value hash + i + i * i is right
5016 // shifted in the following and instruction.
5017 DCHECK(NameDictionary::GetProbeOffset(i) <
5018 1 << (32 - Name::kHashFieldOffset));
5020 NameDictionary::GetProbeOffset(i) << Name::kHashShift);
5022 __ Mov(index, hash);
5024 __ And(index, mask, Operand(index, LSR, Name::kHashShift));
5026 // Scale the index by multiplying by the entry size.
5027 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
5028 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5030 __ Add(index, dictionary, Operand(index, LSL, kPointerSizeLog2));
5031 __ Ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
5033 // Having undefined at this place means the name is not contained.
5034 __ Cmp(entry_key, undefined);
5035 __ B(eq, ¬_in_dictionary);
5037 // Stop if found the property.
5038 __ Cmp(entry_key, key);
5039 __ B(eq, &in_dictionary);
5041 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
5042 // Check if the entry name is not a unique name.
5043 __ Ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
5044 __ Ldrb(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
5045 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
5049 __ Bind(&maybe_in_dictionary);
5050 // If we are doing negative lookup then probing failure should be
5051 // treated as a lookup success. For positive lookup, probing failure
5052 // should be treated as lookup failure.
5053 if (mode() == POSITIVE_LOOKUP) {
5058 __ Bind(&in_dictionary);
5062 __ Bind(¬_in_dictionary);
5069 static void CreateArrayDispatch(MacroAssembler* masm,
5070 AllocationSiteOverrideMode mode) {
5071 ASM_LOCATION("CreateArrayDispatch");
5072 if (mode == DISABLE_ALLOCATION_SITES) {
5073 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5074 __ TailCallStub(&stub);
5076 } else if (mode == DONT_OVERRIDE) {
5079 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5080 for (int i = 0; i <= last_index; ++i) {
5082 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5083 // TODO(jbramley): Is this the best way to handle this? Can we make the
5084 // tail calls conditional, rather than hopping over each one?
5085 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5086 T stub(masm->isolate(), candidate_kind);
5087 __ TailCallStub(&stub);
5091 // If we reached this point there is a problem.
5092 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5100 // TODO(jbramley): If this needs to be a special case, make it a proper template
5101 // specialization, and not a separate function.
5102 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5103 AllocationSiteOverrideMode mode) {
5104 ASM_LOCATION("CreateArrayDispatchOneArgument");
5106 // x1 - constructor?
5107 // x2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5108 // x3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5109 // sp[0] - last argument
5111 Register allocation_site = x2;
5114 Label normal_sequence;
5115 if (mode == DONT_OVERRIDE) {
5116 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5117 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5118 STATIC_ASSERT(FAST_ELEMENTS == 2);
5119 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5120 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5121 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5123 // Is the low bit set? If so, the array is holey.
5124 __ Tbnz(kind, 0, &normal_sequence);
5127 // Look at the last argument.
5128 // TODO(jbramley): What does a 0 argument represent?
5130 __ Cbz(x10, &normal_sequence);
5132 if (mode == DISABLE_ALLOCATION_SITES) {
5133 ElementsKind initial = GetInitialFastElementsKind();
5134 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5136 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5138 DISABLE_ALLOCATION_SITES);
5139 __ TailCallStub(&stub_holey);
5141 __ Bind(&normal_sequence);
5142 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5144 DISABLE_ALLOCATION_SITES);
5145 __ TailCallStub(&stub);
5146 } else if (mode == DONT_OVERRIDE) {
5147 // We are going to create a holey array, but our kind is non-holey.
5148 // Fix kind and retry (only if we have an allocation site in the slot).
5149 __ Orr(kind, kind, 1);
5151 if (FLAG_debug_code) {
5152 __ Ldr(x10, FieldMemOperand(allocation_site, 0));
5153 __ JumpIfNotRoot(x10, Heap::kAllocationSiteMapRootIndex,
5155 __ Assert(eq, kExpectedAllocationSite);
5158 // Save the resulting elements kind in type info. We can't just store 'kind'
5159 // in the AllocationSite::transition_info field because elements kind is
5160 // restricted to a portion of the field; upper bits need to be left alone.
5161 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5162 __ Ldr(x11, FieldMemOperand(allocation_site,
5163 AllocationSite::kTransitionInfoOffset));
5164 __ Add(x11, x11, Smi::FromInt(kFastElementsKindPackedToHoley));
5165 __ Str(x11, FieldMemOperand(allocation_site,
5166 AllocationSite::kTransitionInfoOffset));
5168 __ Bind(&normal_sequence);
5170 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5171 for (int i = 0; i <= last_index; ++i) {
5173 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5174 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5175 ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind);
5176 __ TailCallStub(&stub);
5180 // If we reached this point there is a problem.
5181 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5189 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5190 int to_index = GetSequenceIndexFromFastElementsKind(
5191 TERMINAL_FAST_ELEMENTS_KIND);
5192 for (int i = 0; i <= to_index; ++i) {
5193 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5194 T stub(isolate, kind);
5196 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5197 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5204 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5205 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5207 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5209 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5214 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5216 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5217 for (int i = 0; i < 2; i++) {
5218 // For internal arrays we only need a few things
5219 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5221 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5223 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5229 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5230 MacroAssembler* masm,
5231 AllocationSiteOverrideMode mode) {
5233 if (argument_count() == ANY) {
5234 Label zero_case, n_case;
5235 __ Cbz(argc, &zero_case);
5240 CreateArrayDispatchOneArgument(masm, mode);
5242 __ Bind(&zero_case);
5244 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5248 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5250 } else if (argument_count() == NONE) {
5251 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5252 } else if (argument_count() == ONE) {
5253 CreateArrayDispatchOneArgument(masm, mode);
5254 } else if (argument_count() == MORE_THAN_ONE) {
5255 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5262 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5263 ASM_LOCATION("ArrayConstructorStub::Generate");
5264 // ----------- S t a t e -------------
5265 // -- x0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5266 // -- x1 : constructor
5267 // -- x2 : AllocationSite or undefined
5268 // -- x3 : original constructor
5269 // -- sp[0] : last argument
5270 // -----------------------------------
5271 Register constructor = x1;
5272 Register allocation_site = x2;
5273 Register original_constructor = x3;
5275 if (FLAG_debug_code) {
5276 // The array construct code is only set for the global and natives
5277 // builtin Array functions which always have maps.
5279 Label unexpected_map, map_ok;
5280 // Initial map for the builtin Array function should be a map.
5281 __ Ldr(x10, FieldMemOperand(constructor,
5282 JSFunction::kPrototypeOrInitialMapOffset));
5283 // Will both indicate a NULL and a Smi.
5284 __ JumpIfSmi(x10, &unexpected_map);
5285 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5286 __ Bind(&unexpected_map);
5287 __ Abort(kUnexpectedInitialMapForArrayFunction);
5290 // We should either have undefined in the allocation_site register or a
5291 // valid AllocationSite.
5292 __ AssertUndefinedOrAllocationSite(allocation_site, x10);
5296 __ Cmp(original_constructor, constructor);
5297 __ B(ne, &subclassing);
5301 // Get the elements kind and case on that.
5302 __ JumpIfRoot(allocation_site, Heap::kUndefinedValueRootIndex, &no_info);
5305 UntagSmiFieldMemOperand(allocation_site,
5306 AllocationSite::kTransitionInfoOffset));
5307 __ And(kind, kind, AllocationSite::ElementsKindBits::kMask);
5308 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5311 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5313 // Subclassing support.
5314 __ Bind(&subclassing);
5315 __ Push(constructor, original_constructor);
5317 switch (argument_count()) {
5320 __ add(x0, x0, Operand(2));
5323 __ Mov(x0, Operand(2));
5326 __ Mov(x0, Operand(3));
5329 __ JumpToExternalReference(
5330 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5334 void InternalArrayConstructorStub::GenerateCase(
5335 MacroAssembler* masm, ElementsKind kind) {
5336 Label zero_case, n_case;
5339 __ Cbz(argc, &zero_case);
5340 __ CompareAndBranch(argc, 1, ne, &n_case);
5343 if (IsFastPackedElementsKind(kind)) {
5346 // We might need to create a holey array; look at the first argument.
5348 __ Cbz(x10, &packed_case);
5350 InternalArraySingleArgumentConstructorStub
5351 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5352 __ TailCallStub(&stub1_holey);
5354 __ Bind(&packed_case);
5356 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5357 __ TailCallStub(&stub1);
5359 __ Bind(&zero_case);
5361 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5362 __ TailCallStub(&stub0);
5366 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5367 __ TailCallStub(&stubN);
5371 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5372 // ----------- S t a t e -------------
5374 // -- x1 : constructor
5375 // -- sp[0] : return address
5376 // -- sp[4] : last argument
5377 // -----------------------------------
5379 Register constructor = x1;
5381 if (FLAG_debug_code) {
5382 // The array construct code is only set for the global and natives
5383 // builtin Array functions which always have maps.
5385 Label unexpected_map, map_ok;
5386 // Initial map for the builtin Array function should be a map.
5387 __ Ldr(x10, FieldMemOperand(constructor,
5388 JSFunction::kPrototypeOrInitialMapOffset));
5389 // Will both indicate a NULL and a Smi.
5390 __ JumpIfSmi(x10, &unexpected_map);
5391 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5392 __ Bind(&unexpected_map);
5393 __ Abort(kUnexpectedInitialMapForArrayFunction);
5398 // Figure out the right elements kind
5399 __ Ldr(x10, FieldMemOperand(constructor,
5400 JSFunction::kPrototypeOrInitialMapOffset));
5402 // Retrieve elements_kind from map.
5403 __ LoadElementsKindFromMap(kind, x10);
5405 if (FLAG_debug_code) {
5407 __ Cmp(x3, FAST_ELEMENTS);
5408 __ Ccmp(x3, FAST_HOLEY_ELEMENTS, ZFlag, ne);
5409 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5412 Label fast_elements_case;
5413 __ CompareAndBranch(kind, FAST_ELEMENTS, eq, &fast_elements_case);
5414 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5416 __ Bind(&fast_elements_case);
5417 GenerateCase(masm, FAST_ELEMENTS);
5421 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5422 Register context = cp;
5423 Register result = x0;
5427 // Go up the context chain to the script context.
5428 for (int i = 0; i < depth(); ++i) {
5429 __ Ldr(result, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5433 // Load the PropertyCell value at the specified slot.
5434 __ Add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5435 __ Ldr(result, ContextMemOperand(result));
5436 __ Ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5438 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5439 __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &slow_case);
5442 // Fallback to runtime.
5443 __ Bind(&slow_case);
5446 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5450 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5451 Register context = cp;
5452 Register value = x0;
5454 Register context_temp = x10;
5455 Register cell = x10;
5456 Register cell_details = x11;
5457 Register cell_value = x12;
5458 Register cell_value_map = x13;
5459 Register value_map = x14;
5460 Label fast_heapobject_case, fast_smi_case, slow_case;
5462 if (FLAG_debug_code) {
5463 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5464 __ Check(ne, kUnexpectedValue);
5467 // Go up the context chain to the script context.
5468 for (int i = 0; i < depth(); i++) {
5469 __ Ldr(context_temp, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5470 context = context_temp;
5473 // Load the PropertyCell at the specified slot.
5474 __ Add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5475 __ Ldr(cell, ContextMemOperand(cell));
5477 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5478 __ Ldr(cell_details,
5479 UntagSmiFieldMemOperand(cell, PropertyCell::kDetailsOffset));
5480 __ And(cell_details, cell_details,
5481 PropertyDetails::PropertyCellTypeField::kMask |
5482 PropertyDetails::KindField::kMask |
5483 PropertyDetails::kAttributesReadOnlyMask);
5485 // Check if PropertyCell holds mutable data.
5486 Label not_mutable_data;
5487 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5488 PropertyCellType::kMutable) |
5489 PropertyDetails::KindField::encode(kData));
5490 __ B(ne, ¬_mutable_data);
5491 __ JumpIfSmi(value, &fast_smi_case);
5492 __ Bind(&fast_heapobject_case);
5493 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5494 // RecordWriteField clobbers the value register, so we copy it before the
5497 __ RecordWriteField(cell, PropertyCell::kValueOffset, x11, x12,
5498 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5502 __ Bind(¬_mutable_data);
5503 // Check if PropertyCell value matches the new value (relevant for Constant,
5504 // ConstantType and Undefined cells).
5505 Label not_same_value;
5506 __ Ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5507 __ Cmp(cell_value, value);
5508 __ B(ne, ¬_same_value);
5510 // Make sure the PropertyCell is not marked READ_ONLY.
5511 __ Tst(cell_details, PropertyDetails::kAttributesReadOnlyMask);
5512 __ B(ne, &slow_case);
5514 if (FLAG_debug_code) {
5516 // This can only be true for Constant, ConstantType and Undefined cells,
5517 // because we never store the_hole via this stub.
5518 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5519 PropertyCellType::kConstant) |
5520 PropertyDetails::KindField::encode(kData));
5522 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5523 PropertyCellType::kConstantType) |
5524 PropertyDetails::KindField::encode(kData));
5526 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5527 PropertyCellType::kUndefined) |
5528 PropertyDetails::KindField::encode(kData));
5529 __ Check(eq, kUnexpectedValue);
5533 __ Bind(¬_same_value);
5535 // Check if PropertyCell contains data with constant type (and is not
5537 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5538 PropertyCellType::kConstantType) |
5539 PropertyDetails::KindField::encode(kData));
5540 __ B(ne, &slow_case);
5542 // Now either both old and new values must be smis or both must be heap
5543 // objects with same map.
5544 Label value_is_heap_object;
5545 __ JumpIfNotSmi(value, &value_is_heap_object);
5546 __ JumpIfNotSmi(cell_value, &slow_case);
5547 // Old and new values are smis, no need for a write barrier here.
5548 __ Bind(&fast_smi_case);
5549 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5552 __ Bind(&value_is_heap_object);
5553 __ JumpIfSmi(cell_value, &slow_case);
5555 __ Ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5556 __ Ldr(value_map, FieldMemOperand(value, HeapObject::kMapOffset));
5557 __ Cmp(cell_value_map, value_map);
5558 __ B(eq, &fast_heapobject_case);
5560 // Fall back to the runtime.
5561 __ Bind(&slow_case);
5563 __ Push(slot, value);
5564 __ TailCallRuntime(is_strict(language_mode())
5565 ? Runtime::kStoreGlobalViaContext_Strict
5566 : Runtime::kStoreGlobalViaContext_Sloppy,
5571 // The number of register that CallApiFunctionAndReturn will need to save on
5572 // the stack. The space for these registers need to be allocated in the
5573 // ExitFrame before calling CallApiFunctionAndReturn.
5574 static const int kCallApiFunctionSpillSpace = 4;
5577 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5578 return static_cast<int>(ref0.address() - ref1.address());
5582 // Calls an API function. Allocates HandleScope, extracts returned value
5583 // from handle and propagates exceptions.
5584 // 'stack_space' is the space to be unwound on exit (includes the call JS
5585 // arguments space and the additional space allocated for the fast call).
5586 // 'spill_offset' is the offset from the stack pointer where
5587 // CallApiFunctionAndReturn can spill registers.
5588 static void CallApiFunctionAndReturn(
5589 MacroAssembler* masm, Register function_address,
5590 ExternalReference thunk_ref, int stack_space,
5591 MemOperand* stack_space_operand, int spill_offset,
5592 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5593 ASM_LOCATION("CallApiFunctionAndReturn");
5594 Isolate* isolate = masm->isolate();
5595 ExternalReference next_address =
5596 ExternalReference::handle_scope_next_address(isolate);
5597 const int kNextOffset = 0;
5598 const int kLimitOffset = AddressOffset(
5599 ExternalReference::handle_scope_limit_address(isolate), next_address);
5600 const int kLevelOffset = AddressOffset(
5601 ExternalReference::handle_scope_level_address(isolate), next_address);
5603 DCHECK(function_address.is(x1) || function_address.is(x2));
5605 Label profiler_disabled;
5606 Label end_profiler_check;
5607 __ Mov(x10, ExternalReference::is_profiling_address(isolate));
5608 __ Ldrb(w10, MemOperand(x10));
5609 __ Cbz(w10, &profiler_disabled);
5610 __ Mov(x3, thunk_ref);
5611 __ B(&end_profiler_check);
5613 __ Bind(&profiler_disabled);
5614 __ Mov(x3, function_address);
5615 __ Bind(&end_profiler_check);
5617 // Save the callee-save registers we are going to use.
5618 // TODO(all): Is this necessary? ARM doesn't do it.
5619 STATIC_ASSERT(kCallApiFunctionSpillSpace == 4);
5620 __ Poke(x19, (spill_offset + 0) * kXRegSize);
5621 __ Poke(x20, (spill_offset + 1) * kXRegSize);
5622 __ Poke(x21, (spill_offset + 2) * kXRegSize);
5623 __ Poke(x22, (spill_offset + 3) * kXRegSize);
5625 // Allocate HandleScope in callee-save registers.
5626 // We will need to restore the HandleScope after the call to the API function,
5627 // by allocating it in callee-save registers they will be preserved by C code.
5628 Register handle_scope_base = x22;
5629 Register next_address_reg = x19;
5630 Register limit_reg = x20;
5631 Register level_reg = w21;
5633 __ Mov(handle_scope_base, next_address);
5634 __ Ldr(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5635 __ Ldr(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5636 __ Ldr(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5637 __ Add(level_reg, level_reg, 1);
5638 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5640 if (FLAG_log_timer_events) {
5641 FrameScope frame(masm, StackFrame::MANUAL);
5642 __ PushSafepointRegisters();
5643 __ Mov(x0, ExternalReference::isolate_address(isolate));
5644 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5646 __ PopSafepointRegisters();
5649 // Native call returns to the DirectCEntry stub which redirects to the
5650 // return address pushed on stack (could have moved after GC).
5651 // DirectCEntry stub itself is generated early and never moves.
5652 DirectCEntryStub stub(isolate);
5653 stub.GenerateCall(masm, x3);
5655 if (FLAG_log_timer_events) {
5656 FrameScope frame(masm, StackFrame::MANUAL);
5657 __ PushSafepointRegisters();
5658 __ Mov(x0, ExternalReference::isolate_address(isolate));
5659 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5661 __ PopSafepointRegisters();
5664 Label promote_scheduled_exception;
5665 Label delete_allocated_handles;
5666 Label leave_exit_frame;
5667 Label return_value_loaded;
5669 // Load value from ReturnValue.
5670 __ Ldr(x0, return_value_operand);
5671 __ Bind(&return_value_loaded);
5672 // No more valid handles (the result handle was the last one). Restore
5673 // previous handle scope.
5674 __ Str(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5675 if (__ emit_debug_code()) {
5676 __ Ldr(w1, MemOperand(handle_scope_base, kLevelOffset));
5677 __ Cmp(w1, level_reg);
5678 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5680 __ Sub(level_reg, level_reg, 1);
5681 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5682 __ Ldr(x1, MemOperand(handle_scope_base, kLimitOffset));
5683 __ Cmp(limit_reg, x1);
5684 __ B(ne, &delete_allocated_handles);
5686 // Leave the API exit frame.
5687 __ Bind(&leave_exit_frame);
5688 // Restore callee-saved registers.
5689 __ Peek(x19, (spill_offset + 0) * kXRegSize);
5690 __ Peek(x20, (spill_offset + 1) * kXRegSize);
5691 __ Peek(x21, (spill_offset + 2) * kXRegSize);
5692 __ Peek(x22, (spill_offset + 3) * kXRegSize);
5694 bool restore_context = context_restore_operand != NULL;
5695 if (restore_context) {
5696 __ Ldr(cp, *context_restore_operand);
5699 if (stack_space_operand != NULL) {
5700 __ Ldr(w2, *stack_space_operand);
5703 __ LeaveExitFrame(false, x1, !restore_context);
5705 // Check if the function scheduled an exception.
5706 __ Mov(x5, ExternalReference::scheduled_exception_address(isolate));
5707 __ Ldr(x5, MemOperand(x5));
5708 __ JumpIfNotRoot(x5, Heap::kTheHoleValueRootIndex,
5709 &promote_scheduled_exception);
5711 if (stack_space_operand != NULL) {
5714 __ Drop(stack_space);
5718 // Re-throw by promoting a scheduled exception.
5719 __ Bind(&promote_scheduled_exception);
5720 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5722 // HandleScope limit has changed. Delete allocated extensions.
5723 __ Bind(&delete_allocated_handles);
5724 __ Str(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5725 // Save the return value in a callee-save register.
5726 Register saved_result = x19;
5727 __ Mov(saved_result, x0);
5728 __ Mov(x0, ExternalReference::isolate_address(isolate));
5729 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5731 __ Mov(x0, saved_result);
5732 __ B(&leave_exit_frame);
5736 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5737 const ParameterCount& argc,
5738 bool return_first_arg,
5739 bool call_data_undefined) {
5740 // ----------- S t a t e -------------
5742 // -- x4 : call_data
5744 // -- x1 : api_function_address
5745 // -- x3 : number of arguments if argc is a register
5748 // -- sp[0] : last argument
5750 // -- sp[(argc - 1) * 8] : first argument
5751 // -- sp[argc * 8] : receiver
5752 // -----------------------------------
5754 Register callee = x0;
5755 Register call_data = x4;
5756 Register holder = x2;
5757 Register api_function_address = x1;
5758 Register context = cp;
5760 typedef FunctionCallbackArguments FCA;
5762 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5763 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5764 STATIC_ASSERT(FCA::kDataIndex == 4);
5765 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5766 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5767 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5768 STATIC_ASSERT(FCA::kHolderIndex == 0);
5769 STATIC_ASSERT(FCA::kArgsLength == 7);
5771 DCHECK(argc.is_immediate() || x3.is(argc.reg()));
5773 // FunctionCallbackArguments: context, callee and call data.
5774 __ Push(context, callee, call_data);
5776 // Load context from callee
5777 __ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5779 if (!call_data_undefined) {
5780 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
5782 Register isolate_reg = x5;
5783 __ Mov(isolate_reg, ExternalReference::isolate_address(masm->isolate()));
5785 // FunctionCallbackArguments:
5786 // return value, return value default, isolate, holder.
5787 __ Push(call_data, call_data, isolate_reg, holder);
5789 // Prepare arguments.
5791 __ Mov(args, masm->StackPointer());
5793 // Allocate the v8::Arguments structure in the arguments' space, since it's
5794 // not controlled by GC.
5795 const int kApiStackSpace = 4;
5797 // Allocate space for CallApiFunctionAndReturn can store some scratch
5798 // registeres on the stack.
5799 const int kCallApiFunctionSpillSpace = 4;
5801 FrameScope frame_scope(masm, StackFrame::MANUAL);
5802 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5804 DCHECK(!AreAliased(x0, api_function_address));
5805 // x0 = FunctionCallbackInfo&
5806 // Arguments is after the return address.
5807 __ Add(x0, masm->StackPointer(), 1 * kPointerSize);
5808 if (argc.is_immediate()) {
5809 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5811 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5812 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5813 // FunctionCallbackInfo::length_ = argc and
5814 // FunctionCallbackInfo::is_construct_call = 0
5815 __ Mov(x10, argc.immediate());
5816 __ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize));
5818 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5819 __ Add(x10, args, Operand(argc.reg(), LSL, kPointerSizeLog2));
5820 __ Add(x10, x10, (FCA::kArgsLength - 1) * kPointerSize);
5821 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5822 // FunctionCallbackInfo::length_ = argc and
5823 // FunctionCallbackInfo::is_construct_call
5824 __ Add(x10, argc.reg(), FCA::kArgsLength + 1);
5825 __ Mov(x10, Operand(x10, LSL, kPointerSizeLog2));
5826 __ Stp(argc.reg(), x10, MemOperand(x0, 2 * kPointerSize));
5829 ExternalReference thunk_ref =
5830 ExternalReference::invoke_function_callback(masm->isolate());
5832 AllowExternalCallThatCantCauseGC scope(masm);
5833 MemOperand context_restore_operand(
5834 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5835 // Stores return the first js argument
5836 int return_value_offset = 0;
5837 if (return_first_arg) {
5838 return_value_offset = 2 + FCA::kArgsLength;
5840 return_value_offset = 2 + FCA::kReturnValueOffset;
5842 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5843 int stack_space = 0;
5844 MemOperand is_construct_call_operand =
5845 MemOperand(masm->StackPointer(), 4 * kPointerSize);
5846 MemOperand* stack_space_operand = &is_construct_call_operand;
5847 if (argc.is_immediate()) {
5848 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5849 stack_space_operand = NULL;
5852 const int spill_offset = 1 + kApiStackSpace;
5853 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5854 stack_space_operand, spill_offset,
5855 return_value_operand, &context_restore_operand);
5859 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5860 bool call_data_undefined = this->call_data_undefined();
5861 CallApiFunctionStubHelper(masm, ParameterCount(x3), false,
5862 call_data_undefined);
5866 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5867 bool is_store = this->is_store();
5868 int argc = this->argc();
5869 bool call_data_undefined = this->call_data_undefined();
5870 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5871 call_data_undefined);
5875 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5876 // ----------- S t a t e -------------
5878 // -- sp[8 - kArgsLength*8] : PropertyCallbackArguments object
5880 // -- x2 : api_function_address
5881 // -----------------------------------
5883 Register api_function_address = ApiGetterDescriptor::function_address();
5884 DCHECK(api_function_address.is(x2));
5886 __ Mov(x0, masm->StackPointer()); // x0 = Handle<Name>
5887 __ Add(x1, x0, 1 * kPointerSize); // x1 = PCA
5889 const int kApiStackSpace = 1;
5891 // Allocate space for CallApiFunctionAndReturn can store some scratch
5892 // registeres on the stack.
5893 const int kCallApiFunctionSpillSpace = 4;
5895 FrameScope frame_scope(masm, StackFrame::MANUAL);
5896 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5898 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5899 // x1 (internal::Object** args_) as the data.
5900 __ Poke(x1, 1 * kPointerSize);
5901 __ Add(x1, masm->StackPointer(), 1 * kPointerSize); // x1 = AccessorInfo&
5903 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5905 ExternalReference thunk_ref =
5906 ExternalReference::invoke_accessor_getter_callback(isolate());
5908 const int spill_offset = 1 + kApiStackSpace;
5909 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5910 kStackUnwindSpace, NULL, spill_offset,
5911 MemOperand(fp, 6 * kPointerSize), NULL);
5917 } // namespace internal
5920 #endif // V8_TARGET_ARCH_ARM64