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/bootstrapper.h"
8 #include "src/code-stubs.h"
9 #include "src/codegen.h"
10 #include "src/ic/handler-compiler.h"
11 #include "src/ic/ic.h"
12 #include "src/ic/stub-cache.h"
13 #include "src/isolate.h"
14 #include "src/regexp/jsregexp.h"
15 #include "src/regexp/regexp-macro-assembler.h"
16 #include "src/runtime/runtime.h"
18 #include "src/arm64/code-stubs-arm64.h"
19 #include "src/arm64/frames-arm64.h"
25 static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
30 // x2: allocation site with elements kind
31 // x0: number of arguments to the constructor function
32 Address deopt_handler = Runtime::FunctionForId(
33 Runtime::kArrayConstructor)->entry;
35 if (constant_stack_parameter_count == 0) {
36 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
37 JS_FUNCTION_STUB_MODE);
39 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
40 JS_FUNCTION_STUB_MODE);
45 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
46 CodeStubDescriptor* descriptor) {
47 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
51 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
52 CodeStubDescriptor* descriptor) {
53 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
57 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
63 static void InitializeInternalArrayConstructorDescriptor(
64 Isolate* isolate, CodeStubDescriptor* descriptor,
65 int constant_stack_parameter_count) {
66 Address deopt_handler = Runtime::FunctionForId(
67 Runtime::kInternalArrayConstructor)->entry;
69 if (constant_stack_parameter_count == 0) {
70 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
71 JS_FUNCTION_STUB_MODE);
73 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
74 JS_FUNCTION_STUB_MODE);
79 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
80 CodeStubDescriptor* descriptor) {
81 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
85 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
86 CodeStubDescriptor* descriptor) {
87 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
91 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
92 CodeStubDescriptor* descriptor) {
93 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
97 #define __ ACCESS_MASM(masm)
100 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
101 ExternalReference miss) {
102 // Update the static counter each time a new code stub is generated.
103 isolate()->counters()->code_stubs()->Increment();
105 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
106 int param_count = descriptor.GetRegisterParameterCount();
108 // Call the runtime system in a fresh internal frame.
109 FrameScope scope(masm, StackFrame::INTERNAL);
110 DCHECK((param_count == 0) ||
111 x0.Is(descriptor.GetRegisterParameter(param_count - 1)));
114 MacroAssembler::PushPopQueue queue(masm);
115 for (int i = 0; i < param_count; ++i) {
116 queue.Queue(descriptor.GetRegisterParameter(i));
120 __ CallExternalReference(miss, param_count);
127 void DoubleToIStub::Generate(MacroAssembler* masm) {
129 Register input = source();
130 Register result = destination();
131 DCHECK(is_truncating());
133 DCHECK(result.Is64Bits());
134 DCHECK(jssp.Is(masm->StackPointer()));
136 int double_offset = offset();
138 DoubleRegister double_scratch = d0; // only used if !skip_fastpath()
139 Register scratch1 = GetAllocatableRegisterThatIsNotOneOf(input, result);
141 GetAllocatableRegisterThatIsNotOneOf(input, result, scratch1);
143 __ Push(scratch1, scratch2);
144 // Account for saved regs if input is jssp.
145 if (input.is(jssp)) double_offset += 2 * kPointerSize;
147 if (!skip_fastpath()) {
148 __ Push(double_scratch);
149 if (input.is(jssp)) double_offset += 1 * kDoubleSize;
150 __ Ldr(double_scratch, MemOperand(input, double_offset));
151 // Try to convert with a FPU convert instruction. This handles all
152 // non-saturating cases.
153 __ TryConvertDoubleToInt64(result, double_scratch, &done);
154 __ Fmov(result, double_scratch);
156 __ Ldr(result, MemOperand(input, double_offset));
159 // If we reach here we need to manually convert the input to an int32.
161 // Extract the exponent.
162 Register exponent = scratch1;
163 __ Ubfx(exponent, result, HeapNumber::kMantissaBits,
164 HeapNumber::kExponentBits);
166 // It the exponent is >= 84 (kMantissaBits + 32), the result is always 0 since
167 // the mantissa gets shifted completely out of the int32_t result.
168 __ Cmp(exponent, HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 32);
169 __ CzeroX(result, ge);
172 // The Fcvtzs sequence handles all cases except where the conversion causes
173 // signed overflow in the int64_t target. Since we've already handled
174 // exponents >= 84, we can guarantee that 63 <= exponent < 84.
176 if (masm->emit_debug_code()) {
177 __ Cmp(exponent, HeapNumber::kExponentBias + 63);
178 // Exponents less than this should have been handled by the Fcvt case.
179 __ Check(ge, kUnexpectedValue);
182 // Isolate the mantissa bits, and set the implicit '1'.
183 Register mantissa = scratch2;
184 __ Ubfx(mantissa, result, 0, HeapNumber::kMantissaBits);
185 __ Orr(mantissa, mantissa, 1UL << HeapNumber::kMantissaBits);
187 // Negate the mantissa if necessary.
188 __ Tst(result, kXSignMask);
189 __ Cneg(mantissa, mantissa, ne);
191 // Shift the mantissa bits in the correct place. We know that we have to shift
192 // it left here, because exponent >= 63 >= kMantissaBits.
193 __ Sub(exponent, exponent,
194 HeapNumber::kExponentBias + HeapNumber::kMantissaBits);
195 __ Lsl(result, mantissa, exponent);
198 if (!skip_fastpath()) {
199 __ Pop(double_scratch);
201 __ Pop(scratch2, scratch1);
206 // See call site for description.
207 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
208 Register right, Register scratch,
209 FPRegister double_scratch,
210 Label* slow, Condition cond,
212 DCHECK(!AreAliased(left, right, scratch));
213 Label not_identical, return_equal, heap_number;
214 Register result = x0;
217 __ B(ne, ¬_identical);
219 // Test for NaN. Sadly, we can't just compare to factory::nan_value(),
220 // so we do the second best thing - test it ourselves.
221 // They are both equal and they are not both Smis so both of them are not
222 // Smis. If it's not a heap number, then return equal.
223 Register right_type = scratch;
224 if ((cond == lt) || (cond == gt)) {
225 // Call runtime on identical JSObjects. Otherwise return equal.
226 __ JumpIfObjectType(right, right_type, right_type, FIRST_SPEC_OBJECT_TYPE,
228 // Call runtime on identical symbols since we need to throw a TypeError.
229 __ Cmp(right_type, SYMBOL_TYPE);
231 // Call runtime on identical SIMD values since we must throw a TypeError.
232 __ Cmp(right_type, SIMD128_VALUE_TYPE);
234 if (is_strong(strength)) {
235 // Call the runtime on anything that is converted in the semantics, since
236 // we need to throw a TypeError. Smis have already been ruled out.
237 __ Cmp(right_type, Operand(HEAP_NUMBER_TYPE));
238 __ B(eq, &return_equal);
239 __ Tst(right_type, Operand(kIsNotStringMask));
242 } else if (cond == eq) {
243 __ JumpIfHeapNumber(right, &heap_number);
245 __ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE,
247 // Comparing JS objects with <=, >= is complicated.
248 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
250 // Call runtime on identical symbols since we need to throw a TypeError.
251 __ Cmp(right_type, SYMBOL_TYPE);
253 // Call runtime on identical SIMD values since we must throw a TypeError.
254 __ Cmp(right_type, SIMD128_VALUE_TYPE);
256 if (is_strong(strength)) {
257 // Call the runtime on anything that is converted in the semantics,
258 // since we need to throw a TypeError. Smis and heap numbers have
259 // already been ruled out.
260 __ Tst(right_type, Operand(kIsNotStringMask));
263 // Normally here we fall through to return_equal, but undefined is
264 // special: (undefined == undefined) == true, but
265 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
266 if ((cond == le) || (cond == ge)) {
267 __ Cmp(right_type, ODDBALL_TYPE);
268 __ B(ne, &return_equal);
269 __ JumpIfNotRoot(right, Heap::kUndefinedValueRootIndex, &return_equal);
271 // undefined <= undefined should fail.
272 __ Mov(result, GREATER);
274 // undefined >= undefined should fail.
275 __ Mov(result, LESS);
281 __ Bind(&return_equal);
283 __ Mov(result, GREATER); // Things aren't less than themselves.
284 } else if (cond == gt) {
285 __ Mov(result, LESS); // Things aren't greater than themselves.
287 __ Mov(result, EQUAL); // Things are <=, >=, ==, === themselves.
291 // Cases lt and gt have been handled earlier, and case ne is never seen, as
292 // it is handled in the parser (see Parser::ParseBinaryExpression). We are
293 // only concerned with cases ge, le and eq here.
294 if ((cond != lt) && (cond != gt)) {
295 DCHECK((cond == ge) || (cond == le) || (cond == eq));
296 __ Bind(&heap_number);
297 // Left and right are identical pointers to a heap number object. Return
298 // non-equal if the heap number is a NaN, and equal otherwise. Comparing
299 // the number to itself will set the overflow flag iff the number is NaN.
300 __ Ldr(double_scratch, FieldMemOperand(right, HeapNumber::kValueOffset));
301 __ Fcmp(double_scratch, double_scratch);
302 __ B(vc, &return_equal); // Not NaN, so treat as normal heap number.
305 __ Mov(result, GREATER);
307 __ Mov(result, LESS);
312 // No fall through here.
313 if (FLAG_debug_code) {
317 __ Bind(¬_identical);
321 // See call site for description.
322 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
328 DCHECK(!AreAliased(left, right, left_type, right_type, scratch));
330 if (masm->emit_debug_code()) {
331 // We assume that the arguments are not identical.
333 __ Assert(ne, kExpectedNonIdenticalObjects);
336 // If either operand is a JS object or an oddball value, then they are not
337 // equal since their pointers are different.
338 // There is no test for undetectability in strict equality.
339 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
340 Label right_non_object;
342 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
343 __ B(lt, &right_non_object);
345 // Return non-zero - x0 already contains a non-zero pointer.
346 DCHECK(left.is(x0) || right.is(x0));
347 Label return_not_equal;
348 __ Bind(&return_not_equal);
351 __ Bind(&right_non_object);
353 // Check for oddballs: true, false, null, undefined.
354 __ Cmp(right_type, ODDBALL_TYPE);
356 // If right is not ODDBALL, test left. Otherwise, set eq condition.
357 __ Ccmp(left_type, ODDBALL_TYPE, ZFlag, ne);
359 // If right or left is not ODDBALL, test left >= FIRST_SPEC_OBJECT_TYPE.
360 // Otherwise, right or left is ODDBALL, so set a ge condition.
361 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NVFlag, ne);
363 __ B(ge, &return_not_equal);
365 // Internalized strings are unique, so they can only be equal if they are the
366 // same object. We have already tested that case, so if left and right are
367 // both internalized strings, they cannot be equal.
368 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
369 __ Orr(scratch, left_type, right_type);
370 __ TestAndBranchIfAllClear(
371 scratch, kIsNotStringMask | kIsNotInternalizedMask, &return_not_equal);
375 // See call site for description.
376 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
383 DCHECK(!AreAliased(left_d, right_d));
384 DCHECK((left.is(x0) && right.is(x1)) ||
385 (right.is(x0) && left.is(x1)));
386 Register result = x0;
388 Label right_is_smi, done;
389 __ JumpIfSmi(right, &right_is_smi);
391 // Left is the smi. Check whether right is a heap number.
393 // If right is not a number and left is a smi, then strict equality cannot
394 // succeed. Return non-equal.
395 Label is_heap_number;
396 __ JumpIfHeapNumber(right, &is_heap_number);
397 // Register right is a non-zero pointer, which is a valid NOT_EQUAL result.
398 if (!right.is(result)) {
399 __ Mov(result, NOT_EQUAL);
402 __ Bind(&is_heap_number);
404 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
406 __ JumpIfNotHeapNumber(right, slow);
409 // Left is the smi. Right is a heap number. Load right value into right_d, and
410 // convert left smi into double in left_d.
411 __ Ldr(right_d, FieldMemOperand(right, HeapNumber::kValueOffset));
412 __ SmiUntagToDouble(left_d, left);
415 __ Bind(&right_is_smi);
416 // Right is a smi. Check whether the non-smi left is a heap number.
418 // If left is not a number and right is a smi then strict equality cannot
419 // succeed. Return non-equal.
420 Label is_heap_number;
421 __ JumpIfHeapNumber(left, &is_heap_number);
422 // Register left is a non-zero pointer, which is a valid NOT_EQUAL result.
423 if (!left.is(result)) {
424 __ Mov(result, NOT_EQUAL);
427 __ Bind(&is_heap_number);
429 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
431 __ JumpIfNotHeapNumber(left, slow);
434 // Right is the smi. Left is a heap number. Load left value into left_d, and
435 // convert right smi into double in right_d.
436 __ Ldr(left_d, FieldMemOperand(left, HeapNumber::kValueOffset));
437 __ SmiUntagToDouble(right_d, right);
439 // Fall through to both_loaded_as_doubles.
444 // Fast negative check for internalized-to-internalized equality.
445 // See call site for description.
446 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
453 Label* possible_strings,
454 Label* not_both_strings) {
455 DCHECK(!AreAliased(left, right, left_map, right_map, left_type, right_type));
456 Register result = x0;
459 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
460 // TODO(all): reexamine this branch sequence for optimisation wrt branch
462 __ Tbnz(right_type, MaskToBit(kIsNotStringMask), &object_test);
463 __ Tbnz(right_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
464 __ Tbnz(left_type, MaskToBit(kIsNotStringMask), not_both_strings);
465 __ Tbnz(left_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
467 // Both are internalized. We already checked that they weren't the same
468 // pointer, so they are not equal.
469 __ Mov(result, NOT_EQUAL);
472 __ Bind(&object_test);
474 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
476 // If right >= FIRST_SPEC_OBJECT_TYPE, test left.
477 // Otherwise, right < FIRST_SPEC_OBJECT_TYPE, so set lt condition.
478 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NFlag, ge);
480 __ B(lt, not_both_strings);
482 // If both objects are undetectable, they are equal. Otherwise, they are not
483 // equal, since they are different objects and an object is not equal to
486 // Returning here, so we can corrupt right_type and left_type.
487 Register right_bitfield = right_type;
488 Register left_bitfield = left_type;
489 __ Ldrb(right_bitfield, FieldMemOperand(right_map, Map::kBitFieldOffset));
490 __ Ldrb(left_bitfield, FieldMemOperand(left_map, Map::kBitFieldOffset));
491 __ And(result, right_bitfield, left_bitfield);
492 __ And(result, result, 1 << Map::kIsUndetectable);
493 __ Eor(result, result, 1 << Map::kIsUndetectable);
498 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
499 CompareICState::State expected,
502 if (expected == CompareICState::SMI) {
503 __ JumpIfNotSmi(input, fail);
504 } else if (expected == CompareICState::NUMBER) {
505 __ JumpIfSmi(input, &ok);
506 __ JumpIfNotHeapNumber(input, fail);
508 // We could be strict about internalized/non-internalized here, but as long as
509 // hydrogen doesn't care, the stub doesn't have to care either.
514 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
517 Register result = x0;
518 Condition cond = GetCondition();
521 CompareICStub_CheckInputType(masm, lhs, left(), &miss);
522 CompareICStub_CheckInputType(masm, rhs, right(), &miss);
524 Label slow; // Call builtin.
525 Label not_smis, both_loaded_as_doubles;
526 Label not_two_smis, smi_done;
527 __ JumpIfEitherNotSmi(lhs, rhs, ¬_two_smis);
529 __ Sub(result, lhs, Operand::UntagSmi(rhs));
532 __ Bind(¬_two_smis);
534 // NOTICE! This code is only reached after a smi-fast-case check, so it is
535 // certain that at least one operand isn't a smi.
537 // Handle the case where the objects are identical. Either returns the answer
538 // or goes to slow. Only falls through if the objects were not identical.
539 EmitIdenticalObjectComparison(masm, lhs, rhs, x10, d0, &slow, cond,
542 // If either is a smi (we know that at least one is not a smi), then they can
543 // only be strictly equal if the other is a HeapNumber.
544 __ JumpIfBothNotSmi(lhs, rhs, ¬_smis);
546 // Exactly one operand is a smi. EmitSmiNonsmiComparison generates code that
548 // 1) Return the answer.
549 // 2) Branch to the slow case.
550 // 3) Fall through to both_loaded_as_doubles.
551 // In case 3, we have found out that we were dealing with a number-number
552 // comparison. The double values of the numbers have been loaded, right into
553 // rhs_d, left into lhs_d.
554 FPRegister rhs_d = d0;
555 FPRegister lhs_d = d1;
556 EmitSmiNonsmiComparison(masm, lhs, rhs, lhs_d, rhs_d, &slow, strict());
558 __ Bind(&both_loaded_as_doubles);
559 // The arguments have been converted to doubles and stored in rhs_d and
562 __ Fcmp(lhs_d, rhs_d);
563 __ B(vs, &nan); // Overflow flag set if either is NaN.
564 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
565 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
566 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
570 // Left and/or right is a NaN. Load the result register with whatever makes
571 // the comparison fail, since comparisons with NaN always fail (except ne,
572 // which is filtered out at a higher level.)
574 if ((cond == lt) || (cond == le)) {
575 __ Mov(result, GREATER);
577 __ Mov(result, LESS);
582 // At this point we know we are dealing with two different objects, and
583 // neither of them is a smi. The objects are in rhs_ and lhs_.
585 // Load the maps and types of the objects.
586 Register rhs_map = x10;
587 Register rhs_type = x11;
588 Register lhs_map = x12;
589 Register lhs_type = x13;
590 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
591 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
592 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
593 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
596 // This emits a non-equal return sequence for some object types, or falls
597 // through if it was not lucky.
598 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs, lhs_type, rhs_type, x14);
601 Label check_for_internalized_strings;
602 Label flat_string_check;
603 // Check for heap number comparison. Branch to earlier double comparison code
604 // if they are heap numbers, otherwise, branch to internalized string check.
605 __ Cmp(rhs_type, HEAP_NUMBER_TYPE);
606 __ B(ne, &check_for_internalized_strings);
607 __ Cmp(lhs_map, rhs_map);
609 // If maps aren't equal, lhs_ and rhs_ are not heap numbers. Branch to flat
611 __ B(ne, &flat_string_check);
613 // Both lhs_ and rhs_ are heap numbers. Load them and branch to the double
615 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
616 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
617 __ B(&both_loaded_as_doubles);
619 __ Bind(&check_for_internalized_strings);
620 // In the strict case, the EmitStrictTwoHeapObjectCompare already took care
621 // of internalized strings.
622 if ((cond == eq) && !strict()) {
623 // Returns an answer for two internalized strings or two detectable objects.
624 // Otherwise branches to the string case or not both strings case.
625 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, lhs_map, rhs_map,
627 &flat_string_check, &slow);
630 // Check for both being sequential one-byte strings,
631 // and inline if that is the case.
632 __ Bind(&flat_string_check);
633 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x14,
636 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x10,
639 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
642 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
646 // Never fall through to here.
647 if (FLAG_debug_code) {
654 // Figure out which native to call and setup the arguments.
655 if (cond == eq && strict()) {
656 __ TailCallRuntime(Runtime::kStrictEquals, 2, 1);
660 context_index = Context::EQUALS_BUILTIN_INDEX;
662 context_index = is_strong(strength())
663 ? Context::COMPARE_STRONG_BUILTIN_INDEX
664 : Context::COMPARE_BUILTIN_INDEX;
665 int ncr; // NaN compare result
666 if ((cond == lt) || (cond == le)) {
669 DCHECK((cond == gt) || (cond == ge)); // remaining cases
672 __ Mov(x10, Smi::FromInt(ncr));
676 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
677 // tagged as a small integer.
678 __ InvokeBuiltin(context_index, JUMP_FUNCTION);
686 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
687 CPURegList saved_regs = kCallerSaved;
688 CPURegList saved_fp_regs = kCallerSavedFP;
690 // We don't allow a GC during a store buffer overflow so there is no need to
691 // store the registers in any particular way, but we do have to store and
694 // We don't care if MacroAssembler scratch registers are corrupted.
695 saved_regs.Remove(*(masm->TmpList()));
696 saved_fp_regs.Remove(*(masm->FPTmpList()));
698 __ PushCPURegList(saved_regs);
699 if (save_doubles()) {
700 __ PushCPURegList(saved_fp_regs);
703 AllowExternalCallThatCantCauseGC scope(masm);
704 __ Mov(x0, ExternalReference::isolate_address(isolate()));
706 ExternalReference::store_buffer_overflow_function(isolate()), 1, 0);
708 if (save_doubles()) {
709 __ PopCPURegList(saved_fp_regs);
711 __ PopCPURegList(saved_regs);
716 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
718 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
720 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
725 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
726 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
727 UseScratchRegisterScope temps(masm);
728 Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr());
729 Register return_address = temps.AcquireX();
730 __ Mov(return_address, lr);
731 // Restore lr with the value it had before the call to this stub (the value
732 // which must be pushed).
733 __ Mov(lr, saved_lr);
734 __ PushSafepointRegisters();
735 __ Ret(return_address);
739 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
740 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
741 UseScratchRegisterScope temps(masm);
742 Register return_address = temps.AcquireX();
743 // Preserve the return address (lr will be clobbered by the pop).
744 __ Mov(return_address, lr);
745 __ PopSafepointRegisters();
746 __ Ret(return_address);
750 void MathPowStub::Generate(MacroAssembler* masm) {
752 // jssp[0]: Exponent (as a tagged value).
753 // jssp[1]: Base (as a tagged value).
755 // The (tagged) result will be returned in x0, as a heap number.
757 Register result_tagged = x0;
758 Register base_tagged = x10;
759 Register exponent_tagged = MathPowTaggedDescriptor::exponent();
760 DCHECK(exponent_tagged.is(x11));
761 Register exponent_integer = MathPowIntegerDescriptor::exponent();
762 DCHECK(exponent_integer.is(x12));
763 Register scratch1 = x14;
764 Register scratch0 = x15;
765 Register saved_lr = x19;
766 FPRegister result_double = d0;
767 FPRegister base_double = d0;
768 FPRegister exponent_double = d1;
769 FPRegister base_double_copy = d2;
770 FPRegister scratch1_double = d6;
771 FPRegister scratch0_double = d7;
773 // A fast-path for integer exponents.
774 Label exponent_is_smi, exponent_is_integer;
775 // Bail out to runtime.
777 // Allocate a heap number for the result, and return it.
780 // Unpack the inputs.
781 if (exponent_type() == ON_STACK) {
783 Label unpack_exponent;
785 __ Pop(exponent_tagged, base_tagged);
787 __ JumpIfSmi(base_tagged, &base_is_smi);
788 __ JumpIfNotHeapNumber(base_tagged, &call_runtime);
789 // base_tagged is a heap number, so load its double value.
790 __ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset));
791 __ B(&unpack_exponent);
792 __ Bind(&base_is_smi);
793 // base_tagged is a SMI, so untag it and convert it to a double.
794 __ SmiUntagToDouble(base_double, base_tagged);
796 __ Bind(&unpack_exponent);
797 // x10 base_tagged The tagged base (input).
798 // x11 exponent_tagged The tagged exponent (input).
799 // d1 base_double The base as a double.
800 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
801 __ JumpIfNotHeapNumber(exponent_tagged, &call_runtime);
802 // exponent_tagged is a heap number, so load its double value.
803 __ Ldr(exponent_double,
804 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
805 } else if (exponent_type() == TAGGED) {
806 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
807 __ Ldr(exponent_double,
808 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
811 // Handle double (heap number) exponents.
812 if (exponent_type() != INTEGER) {
813 // Detect integer exponents stored as doubles and handle those in the
814 // integer fast-path.
815 __ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
816 scratch0_double, &exponent_is_integer);
818 if (exponent_type() == ON_STACK) {
819 FPRegister half_double = d3;
820 FPRegister minus_half_double = d4;
821 // Detect square root case. Crankshaft detects constant +/-0.5 at compile
822 // time and uses DoMathPowHalf instead. We then skip this check for
823 // non-constant cases of +/-0.5 as these hardly occur.
825 __ Fmov(minus_half_double, -0.5);
826 __ Fmov(half_double, 0.5);
827 __ Fcmp(minus_half_double, exponent_double);
828 __ Fccmp(half_double, exponent_double, NZFlag, ne);
829 // Condition flags at this point:
830 // 0.5; nZCv // Identified by eq && pl
831 // -0.5: NZcv // Identified by eq && mi
832 // other: ?z?? // Identified by ne
833 __ B(ne, &call_runtime);
835 // The exponent is 0.5 or -0.5.
837 // Given that exponent is known to be either 0.5 or -0.5, the following
838 // special cases could apply (according to ECMA-262 15.8.2.13):
840 // base.isNaN(): The result is NaN.
841 // (base == +INFINITY) || (base == -INFINITY)
842 // exponent == 0.5: The result is +INFINITY.
843 // exponent == -0.5: The result is +0.
844 // (base == +0) || (base == -0)
845 // exponent == 0.5: The result is +0.
846 // exponent == -0.5: The result is +INFINITY.
847 // (base < 0) && base.isFinite(): The result is NaN.
849 // Fsqrt (and Fdiv for the -0.5 case) can handle all of those except
850 // where base is -INFINITY or -0.
852 // Add +0 to base. This has no effect other than turning -0 into +0.
853 __ Fadd(base_double, base_double, fp_zero);
854 // The operation -0+0 results in +0 in all cases except where the
855 // FPCR rounding mode is 'round towards minus infinity' (RM). The
856 // ARM64 simulator does not currently simulate FPCR (where the rounding
857 // mode is set), so test the operation with some debug code.
858 if (masm->emit_debug_code()) {
859 UseScratchRegisterScope temps(masm);
860 Register temp = temps.AcquireX();
861 __ Fneg(scratch0_double, fp_zero);
862 // Verify that we correctly generated +0.0 and -0.0.
863 // bits(+0.0) = 0x0000000000000000
864 // bits(-0.0) = 0x8000000000000000
865 __ Fmov(temp, fp_zero);
866 __ CheckRegisterIsClear(temp, kCouldNotGenerateZero);
867 __ Fmov(temp, scratch0_double);
868 __ Eor(temp, temp, kDSignMask);
869 __ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero);
870 // Check that -0.0 + 0.0 == +0.0.
871 __ Fadd(scratch0_double, scratch0_double, fp_zero);
872 __ Fmov(temp, scratch0_double);
873 __ CheckRegisterIsClear(temp, kExpectedPositiveZero);
876 // If base is -INFINITY, make it +INFINITY.
877 // * Calculate base - base: All infinities will become NaNs since both
878 // -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64.
879 // * If the result is NaN, calculate abs(base).
880 __ Fsub(scratch0_double, base_double, base_double);
881 __ Fcmp(scratch0_double, 0.0);
882 __ Fabs(scratch1_double, base_double);
883 __ Fcsel(base_double, scratch1_double, base_double, vs);
885 // Calculate the square root of base.
886 __ Fsqrt(result_double, base_double);
887 __ Fcmp(exponent_double, 0.0);
888 __ B(ge, &done); // Finish now for exponents of 0.5.
889 // Find the inverse for exponents of -0.5.
890 __ Fmov(scratch0_double, 1.0);
891 __ Fdiv(result_double, scratch0_double, result_double);
896 AllowExternalCallThatCantCauseGC scope(masm);
897 __ Mov(saved_lr, lr);
899 ExternalReference::power_double_double_function(isolate()),
901 __ Mov(lr, saved_lr);
905 // Handle SMI exponents.
906 __ Bind(&exponent_is_smi);
907 // x10 base_tagged The tagged base (input).
908 // x11 exponent_tagged The tagged exponent (input).
909 // d1 base_double The base as a double.
910 __ SmiUntag(exponent_integer, exponent_tagged);
913 __ Bind(&exponent_is_integer);
914 // x10 base_tagged The tagged base (input).
915 // x11 exponent_tagged The tagged exponent (input).
916 // x12 exponent_integer The exponent as an integer.
917 // d1 base_double The base as a double.
919 // Find abs(exponent). For negative exponents, we can find the inverse later.
920 Register exponent_abs = x13;
921 __ Cmp(exponent_integer, 0);
922 __ Cneg(exponent_abs, exponent_integer, mi);
923 // x13 exponent_abs The value of abs(exponent_integer).
925 // Repeatedly multiply to calculate the power.
927 // For each bit n (exponent_integer{n}) {
928 // if (exponent_integer{n}) {
932 // if (remaining bits in exponent_integer are all zero) {
936 Label power_loop, power_loop_entry, power_loop_exit;
937 __ Fmov(scratch1_double, base_double);
938 __ Fmov(base_double_copy, base_double);
939 __ Fmov(result_double, 1.0);
940 __ B(&power_loop_entry);
942 __ Bind(&power_loop);
943 __ Fmul(scratch1_double, scratch1_double, scratch1_double);
944 __ Lsr(exponent_abs, exponent_abs, 1);
945 __ Cbz(exponent_abs, &power_loop_exit);
947 __ Bind(&power_loop_entry);
948 __ Tbz(exponent_abs, 0, &power_loop);
949 __ Fmul(result_double, result_double, scratch1_double);
952 __ Bind(&power_loop_exit);
954 // If the exponent was positive, result_double holds the result.
955 __ Tbz(exponent_integer, kXSignBit, &done);
957 // The exponent was negative, so find the inverse.
958 __ Fmov(scratch0_double, 1.0);
959 __ Fdiv(result_double, scratch0_double, result_double);
960 // ECMA-262 only requires Math.pow to return an 'implementation-dependent
961 // approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
962 // to calculate the subnormal value 2^-1074. This method of calculating
963 // negative powers doesn't work because 2^1074 overflows to infinity. To
964 // catch this corner-case, we bail out if the result was 0. (This can only
965 // occur if the divisor is infinity or the base is zero.)
966 __ Fcmp(result_double, 0.0);
969 if (exponent_type() == ON_STACK) {
970 // Bail out to runtime code.
971 __ Bind(&call_runtime);
972 // Put the arguments back on the stack.
973 __ Push(base_tagged, exponent_tagged);
974 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
978 __ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1,
980 DCHECK(result_tagged.is(x0));
982 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
985 AllowExternalCallThatCantCauseGC scope(masm);
986 __ Mov(saved_lr, lr);
987 __ Fmov(base_double, base_double_copy);
988 __ Scvtf(exponent_double, exponent_integer);
990 ExternalReference::power_double_double_function(isolate()),
992 __ Mov(lr, saved_lr);
995 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
1001 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1002 // It is important that the following stubs are generated in this order
1003 // because pregenerated stubs can only call other pregenerated stubs.
1004 // RecordWriteStub uses StoreBufferOverflowStub, which in turn uses
1006 CEntryStub::GenerateAheadOfTime(isolate);
1007 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1008 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1009 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1010 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1011 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1012 BinaryOpICStub::GenerateAheadOfTime(isolate);
1013 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1014 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1015 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1016 StoreFastElementStub::GenerateAheadOfTime(isolate);
1017 TypeofStub::GenerateAheadOfTime(isolate);
1021 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1022 StoreRegistersStateStub stub(isolate);
1027 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1028 RestoreRegistersStateStub stub(isolate);
1033 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1034 // Floating-point code doesn't get special handling in ARM64, so there's
1035 // nothing to do here.
1040 bool CEntryStub::NeedsImmovableCode() {
1041 // CEntryStub stores the return address on the stack before calling into
1042 // C++ code. In some cases, the VM accesses this address, but it is not used
1043 // when the C++ code returns to the stub because LR holds the return address
1044 // in AAPCS64. If the stub is moved (perhaps during a GC), we could end up
1045 // returning to dead code.
1046 // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't
1047 // find any comment to confirm this, and I don't hit any crashes whatever
1048 // this function returns. The anaylsis should be properly confirmed.
1053 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1054 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1056 CEntryStub stub_fp(isolate, 1, kSaveFPRegs);
1061 void CEntryStub::Generate(MacroAssembler* masm) {
1062 // The Abort mechanism relies on CallRuntime, which in turn relies on
1063 // CEntryStub, so until this stub has been generated, we have to use a
1064 // fall-back Abort mechanism.
1066 // Note that this stub must be generated before any use of Abort.
1067 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
1069 ASM_LOCATION("CEntryStub::Generate entry");
1070 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1072 // Register parameters:
1073 // x0: argc (including receiver, untagged)
1076 // The stack on entry holds the arguments and the receiver, with the receiver
1077 // at the highest address:
1079 // jssp]argc-1]: receiver
1080 // jssp[argc-2]: arg[argc-2]
1085 // The arguments are in reverse order, so that arg[argc-2] is actually the
1086 // first argument to the target function and arg[0] is the last.
1087 DCHECK(jssp.Is(__ StackPointer()));
1088 const Register& argc_input = x0;
1089 const Register& target_input = x1;
1091 // Calculate argv, argc and the target address, and store them in
1092 // callee-saved registers so we can retry the call without having to reload
1094 // TODO(jbramley): If the first call attempt succeeds in the common case (as
1095 // it should), then we might be better off putting these parameters directly
1096 // into their argument registers, rather than using callee-saved registers and
1097 // preserving them on the stack.
1098 const Register& argv = x21;
1099 const Register& argc = x22;
1100 const Register& target = x23;
1102 // Derive argv from the stack pointer so that it points to the first argument
1103 // (arg[argc-2]), or just below the receiver in case there are no arguments.
1104 // - Adjust for the arg[] array.
1105 Register temp_argv = x11;
1106 __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
1107 // - Adjust for the receiver.
1108 __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
1110 // Enter the exit frame. Reserve three slots to preserve x21-x23 callee-saved
1112 FrameScope scope(masm, StackFrame::MANUAL);
1113 __ EnterExitFrame(save_doubles(), x10, 3);
1114 DCHECK(csp.Is(__ StackPointer()));
1116 // Poke callee-saved registers into reserved space.
1117 __ Poke(argv, 1 * kPointerSize);
1118 __ Poke(argc, 2 * kPointerSize);
1119 __ Poke(target, 3 * kPointerSize);
1121 // We normally only keep tagged values in callee-saved registers, as they
1122 // could be pushed onto the stack by called stubs and functions, and on the
1123 // stack they can confuse the GC. However, we're only calling C functions
1124 // which can push arbitrary data onto the stack anyway, and so the GC won't
1125 // examine that part of the stack.
1126 __ Mov(argc, argc_input);
1127 __ Mov(target, target_input);
1128 __ Mov(argv, temp_argv);
1132 // x23 : call target
1134 // The stack (on entry) holds the arguments and the receiver, with the
1135 // receiver at the highest address:
1137 // argv[8]: receiver
1138 // argv -> argv[0]: arg[argc-2]
1140 // argv[...]: arg[1]
1141 // argv[...]: arg[0]
1143 // Immediately below (after) this is the exit frame, as constructed by
1145 // fp[8]: CallerPC (lr)
1146 // fp -> fp[0]: CallerFP (old fp)
1147 // fp[-8]: Space reserved for SPOffset.
1148 // fp[-16]: CodeObject()
1149 // csp[...]: Saved doubles, if saved_doubles is true.
1150 // csp[32]: Alignment padding, if necessary.
1151 // csp[24]: Preserved x23 (used for target).
1152 // csp[16]: Preserved x22 (used for argc).
1153 // csp[8]: Preserved x21 (used for argv).
1154 // csp -> csp[0]: Space reserved for the return address.
1156 // After a successful call, the exit frame, preserved registers (x21-x23) and
1157 // the arguments (including the receiver) are dropped or popped as
1158 // appropriate. The stub then returns.
1160 // After an unsuccessful call, the exit frame and suchlike are left
1161 // untouched, and the stub either throws an exception by jumping to one of
1162 // the exception_returned label.
1164 DCHECK(csp.Is(__ StackPointer()));
1166 // Prepare AAPCS64 arguments to pass to the builtin.
1169 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1171 Label return_location;
1172 __ Adr(x12, &return_location);
1175 if (__ emit_debug_code()) {
1176 // Verify that the slot below fp[kSPOffset]-8 points to the return location
1177 // (currently in x12).
1178 UseScratchRegisterScope temps(masm);
1179 Register temp = temps.AcquireX();
1180 __ Ldr(temp, MemOperand(fp, ExitFrameConstants::kSPOffset));
1181 __ Ldr(temp, MemOperand(temp, -static_cast<int64_t>(kXRegSize)));
1183 __ Check(eq, kReturnAddressNotFoundInFrame);
1186 // Call the builtin.
1188 __ Bind(&return_location);
1190 // x0 result The return code from the call.
1194 const Register& result = x0;
1196 // Check result for exception sentinel.
1197 Label exception_returned;
1198 __ CompareRoot(result, Heap::kExceptionRootIndex);
1199 __ B(eq, &exception_returned);
1201 // The call succeeded, so unwind the stack and return.
1203 // Restore callee-saved registers x21-x23.
1206 __ Peek(argv, 1 * kPointerSize);
1207 __ Peek(argc, 2 * kPointerSize);
1208 __ Peek(target, 3 * kPointerSize);
1210 __ LeaveExitFrame(save_doubles(), x10, true);
1211 DCHECK(jssp.Is(__ StackPointer()));
1212 // Pop or drop the remaining stack slots and return from the stub.
1213 // jssp[24]: Arguments array (of size argc), including receiver.
1214 // jssp[16]: Preserved x23 (used for target).
1215 // jssp[8]: Preserved x22 (used for argc).
1216 // jssp[0]: Preserved x21 (used for argv).
1218 __ AssertFPCRState();
1221 // The stack pointer is still csp if we aren't returning, and the frame
1222 // hasn't changed (except for the return address).
1223 __ SetStackPointer(csp);
1225 // Handling of exception.
1226 __ Bind(&exception_returned);
1228 ExternalReference pending_handler_context_address(
1229 Isolate::kPendingHandlerContextAddress, isolate());
1230 ExternalReference pending_handler_code_address(
1231 Isolate::kPendingHandlerCodeAddress, isolate());
1232 ExternalReference pending_handler_offset_address(
1233 Isolate::kPendingHandlerOffsetAddress, isolate());
1234 ExternalReference pending_handler_fp_address(
1235 Isolate::kPendingHandlerFPAddress, isolate());
1236 ExternalReference pending_handler_sp_address(
1237 Isolate::kPendingHandlerSPAddress, isolate());
1239 // Ask the runtime for help to determine the handler. This will set x0 to
1240 // contain the current pending exception, don't clobber it.
1241 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1243 DCHECK(csp.Is(masm->StackPointer()));
1245 FrameScope scope(masm, StackFrame::MANUAL);
1246 __ Mov(x0, 0); // argc.
1247 __ Mov(x1, 0); // argv.
1248 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1249 __ CallCFunction(find_handler, 3);
1252 // We didn't execute a return case, so the stack frame hasn't been updated
1253 // (except for the return address slot). However, we don't need to initialize
1254 // jssp because the throw method will immediately overwrite it when it
1255 // unwinds the stack.
1256 __ SetStackPointer(jssp);
1258 // Retrieve the handler context, SP and FP.
1259 __ Mov(cp, Operand(pending_handler_context_address));
1260 __ Ldr(cp, MemOperand(cp));
1261 __ Mov(jssp, Operand(pending_handler_sp_address));
1262 __ Ldr(jssp, MemOperand(jssp));
1263 __ Mov(fp, Operand(pending_handler_fp_address));
1264 __ Ldr(fp, MemOperand(fp));
1266 // If the handler is a JS frame, restore the context to the frame. Note that
1267 // the context will be set to (cp == 0) for non-JS frames.
1269 __ Cbz(cp, ¬_js_frame);
1270 __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1271 __ Bind(¬_js_frame);
1273 // Compute the handler entry address and jump to it.
1274 __ Mov(x10, Operand(pending_handler_code_address));
1275 __ Ldr(x10, MemOperand(x10));
1276 __ Mov(x11, Operand(pending_handler_offset_address));
1277 __ Ldr(x11, MemOperand(x11));
1278 __ Add(x10, x10, Code::kHeaderSize - kHeapObjectTag);
1279 __ Add(x10, x10, x11);
1284 // This is the entry point from C++. 5 arguments are provided in x0-x4.
1285 // See use of the CALL_GENERATED_CODE macro for example in src/execution.cc.
1294 void JSEntryStub::Generate(MacroAssembler* masm) {
1295 DCHECK(jssp.Is(__ StackPointer()));
1296 Register code_entry = x0;
1298 // Enable instruction instrumentation. This only works on the simulator, and
1299 // will have no effect on the model or real hardware.
1300 __ EnableInstrumentation();
1302 Label invoke, handler_entry, exit;
1304 // Push callee-saved registers and synchronize the system stack pointer (csp)
1305 // and the JavaScript stack pointer (jssp).
1307 // We must not write to jssp until after the PushCalleeSavedRegisters()
1308 // call, since jssp is itself a callee-saved register.
1309 __ SetStackPointer(csp);
1310 __ PushCalleeSavedRegisters();
1312 __ SetStackPointer(jssp);
1314 // Configure the FPCR. We don't restore it, so this is technically not allowed
1315 // according to AAPCS64. However, we only set default-NaN mode and this will
1316 // be harmless for most C code. Also, it works for ARM.
1319 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1321 // Set up the reserved register for 0.0.
1322 __ Fmov(fp_zero, 0.0);
1324 // Build an entry frame (see layout below).
1325 int marker = type();
1326 int64_t bad_frame_pointer = -1L; // Bad frame pointer to fail if it is used.
1327 __ Mov(x13, bad_frame_pointer);
1328 __ Mov(x12, Smi::FromInt(marker));
1329 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1330 __ Ldr(x10, MemOperand(x11));
1332 __ Push(x13, xzr, x12, x10);
1334 __ Sub(fp, jssp, EntryFrameConstants::kCallerFPOffset);
1336 // Push the JS entry frame marker. Also set js_entry_sp if this is the
1337 // outermost JS call.
1338 Label non_outermost_js, done;
1339 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1340 __ Mov(x10, ExternalReference(js_entry_sp));
1341 __ Ldr(x11, MemOperand(x10));
1342 __ Cbnz(x11, &non_outermost_js);
1343 __ Str(fp, MemOperand(x10));
1344 __ Mov(x12, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1347 __ Bind(&non_outermost_js);
1348 // We spare one instruction by pushing xzr since the marker is 0.
1349 DCHECK(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME) == NULL);
1353 // The frame set up looks like this:
1354 // jssp[0] : JS entry frame marker.
1355 // jssp[1] : C entry FP.
1356 // jssp[2] : stack frame marker.
1357 // jssp[3] : stack frmae marker.
1358 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1361 // Jump to a faked try block that does the invoke, with a faked catch
1362 // block that sets the pending exception.
1365 // Prevent the constant pool from being emitted between the record of the
1366 // handler_entry position and the first instruction of the sequence here.
1367 // There is no risk because Assembler::Emit() emits the instruction before
1368 // checking for constant pool emission, but we do not want to depend on
1371 Assembler::BlockPoolsScope block_pools(masm);
1372 __ bind(&handler_entry);
1373 handler_offset_ = handler_entry.pos();
1374 // Caught exception: Store result (exception) in the pending exception
1375 // field in the JSEnv and return a failure sentinel. Coming in here the
1376 // fp will be invalid because the PushTryHandler below sets it to 0 to
1377 // signal the existence of the JSEntry frame.
1378 __ Mov(x10, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1381 __ Str(code_entry, MemOperand(x10));
1382 __ LoadRoot(x0, Heap::kExceptionRootIndex);
1385 // Invoke: Link this frame into the handler chain.
1387 __ PushStackHandler();
1388 // If an exception not caught by another handler occurs, this handler
1389 // returns control to the code after the B(&invoke) above, which
1390 // restores all callee-saved registers (including cp and fp) to their
1391 // saved values before returning a failure to C.
1393 // Clear any pending exceptions.
1394 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
1395 __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1397 __ Str(x10, MemOperand(x11));
1399 // Invoke the function by calling through the JS entry trampoline builtin.
1400 // Notice that we cannot store a reference to the trampoline code directly in
1401 // this stub, because runtime stubs are not traversed when doing GC.
1403 // Expected registers by Builtins::JSEntryTrampoline
1409 ExternalReference entry(type() == StackFrame::ENTRY_CONSTRUCT
1410 ? Builtins::kJSConstructEntryTrampoline
1411 : Builtins::kJSEntryTrampoline,
1415 // Call the JSEntryTrampoline.
1416 __ Ldr(x11, MemOperand(x10)); // Dereference the address.
1417 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag);
1420 // Unlink this frame from the handler chain.
1421 __ PopStackHandler();
1425 // x0 holds the result.
1426 // The stack pointer points to the top of the entry frame pushed on entry from
1427 // C++ (at the beginning of this stub):
1428 // jssp[0] : JS entry frame marker.
1429 // jssp[1] : C entry FP.
1430 // jssp[2] : stack frame marker.
1431 // jssp[3] : stack frmae marker.
1432 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1434 // Check if the current stack frame is marked as the outermost JS frame.
1435 Label non_outermost_js_2;
1437 __ Cmp(x10, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1438 __ B(ne, &non_outermost_js_2);
1439 __ Mov(x11, ExternalReference(js_entry_sp));
1440 __ Str(xzr, MemOperand(x11));
1441 __ Bind(&non_outermost_js_2);
1443 // Restore the top frame descriptors from the stack.
1445 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1446 __ Str(x10, MemOperand(x11));
1448 // Reset the stack to the callee saved registers.
1449 __ Drop(-EntryFrameConstants::kCallerFPOffset, kByteSizeInBytes);
1450 // Restore the callee-saved registers and return.
1451 DCHECK(jssp.Is(__ StackPointer()));
1453 __ SetStackPointer(csp);
1454 __ PopCalleeSavedRegisters();
1455 // After this point, we must not modify jssp because it is a callee-saved
1456 // register which we have just restored.
1461 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1463 Register receiver = LoadDescriptor::ReceiverRegister();
1464 // Ensure that the vector and slot registers won't be clobbered before
1465 // calling the miss handler.
1466 DCHECK(!AreAliased(x10, x11, LoadWithVectorDescriptor::VectorRegister(),
1467 LoadWithVectorDescriptor::SlotRegister()));
1469 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, x10,
1473 PropertyAccessCompiler::TailCallBuiltin(
1474 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1478 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1479 // Return address is in lr.
1482 Register receiver = LoadDescriptor::ReceiverRegister();
1483 Register index = LoadDescriptor::NameRegister();
1484 Register result = x0;
1485 Register scratch = x10;
1486 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1487 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1488 result.is(LoadWithVectorDescriptor::SlotRegister()));
1490 // StringCharAtGenerator doesn't use the result register until it's passed
1491 // the different miss possibilities. If it did, we would have a conflict
1492 // when FLAG_vector_ics is true.
1493 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1494 &miss, // When not a string.
1495 &miss, // When not a number.
1496 &miss, // When index out of range.
1497 STRING_INDEX_IS_ARRAY_INDEX,
1498 RECEIVER_IS_STRING);
1499 char_at_generator.GenerateFast(masm);
1502 StubRuntimeCallHelper call_helper;
1503 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1506 PropertyAccessCompiler::TailCallBuiltin(
1507 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1511 void InstanceOfStub::Generate(MacroAssembler* masm) {
1512 Register const object = x1; // Object (lhs).
1513 Register const function = x0; // Function (rhs).
1514 Register const object_map = x2; // Map of {object}.
1515 Register const function_map = x3; // Map of {function}.
1516 Register const function_prototype = x4; // Prototype of {function}.
1517 Register const scratch = x5;
1519 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1520 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1522 // Check if {object} is a smi.
1523 Label object_is_smi;
1524 __ JumpIfSmi(object, &object_is_smi);
1526 // Lookup the {function} and the {object} map in the global instanceof cache.
1527 // Note: This is safe because we clear the global instanceof cache whenever
1528 // we change the prototype of any object.
1529 Label fast_case, slow_case;
1530 __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1531 __ JumpIfNotRoot(function, Heap::kInstanceofCacheFunctionRootIndex,
1533 __ JumpIfNotRoot(object_map, Heap::kInstanceofCacheMapRootIndex, &fast_case);
1534 __ LoadRoot(x0, Heap::kInstanceofCacheAnswerRootIndex);
1537 // If {object} is a smi we can safely return false if {function} is a JS
1538 // function, otherwise we have to miss to the runtime and throw an exception.
1539 __ Bind(&object_is_smi);
1540 __ JumpIfSmi(function, &slow_case);
1541 __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
1543 __ LoadRoot(x0, Heap::kFalseValueRootIndex);
1546 // Fast-case: The {function} must be a valid JSFunction.
1547 __ Bind(&fast_case);
1548 __ JumpIfSmi(function, &slow_case);
1549 __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
1552 // Ensure that {function} has an instance prototype.
1553 __ Ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1554 __ Tbnz(scratch, Map::kHasNonInstancePrototype, &slow_case);
1556 // Ensure that {function} is not bound.
1557 Register const shared_info = scratch;
1558 Register const scratch_w = scratch.W();
1560 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1561 // On 64-bit platforms, compiler hints field is not a smi. See definition of
1562 // kCompilerHintsOffset in src/objects.h.
1563 __ Ldr(scratch_w, FieldMemOperand(shared_info,
1564 SharedFunctionInfo::kCompilerHintsOffset));
1565 __ Tbnz(scratch_w, SharedFunctionInfo::kBoundFunction, &slow_case);
1567 // Get the "prototype" (or initial map) of the {function}.
1568 __ Ldr(function_prototype,
1569 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1570 __ AssertNotSmi(function_prototype);
1572 // Resolve the prototype if the {function} has an initial map. Afterwards the
1573 // {function_prototype} will be either the JSReceiver prototype object or the
1574 // hole value, which means that no instances of the {function} were created so
1575 // far and hence we should return false.
1576 Label function_prototype_valid;
1577 __ JumpIfNotObjectType(function_prototype, scratch, scratch, MAP_TYPE,
1578 &function_prototype_valid);
1579 __ Ldr(function_prototype,
1580 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1581 __ Bind(&function_prototype_valid);
1582 __ AssertNotSmi(function_prototype);
1584 // Update the global instanceof cache with the current {object} map and
1585 // {function}. The cached answer will be set when it is known below.
1586 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1587 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1589 // Loop through the prototype chain looking for the {function} prototype.
1590 // Assume true, and change to false if not found.
1591 Register const object_prototype = object_map;
1592 Register const null = scratch;
1594 __ LoadRoot(x0, Heap::kTrueValueRootIndex);
1595 __ LoadRoot(null, Heap::kNullValueRootIndex);
1597 __ Ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1598 __ Cmp(object_prototype, function_prototype);
1600 __ Cmp(object_prototype, null);
1601 __ Ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1603 __ LoadRoot(x0, Heap::kFalseValueRootIndex);
1605 __ StoreRoot(x0, Heap::kInstanceofCacheAnswerRootIndex);
1608 // Slow-case: Call the runtime function.
1609 __ bind(&slow_case);
1610 __ Push(object, function);
1611 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1615 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1616 Register arg_count = ArgumentsAccessReadDescriptor::parameter_count();
1617 Register key = ArgumentsAccessReadDescriptor::index();
1618 DCHECK(arg_count.is(x0));
1621 // The displacement is the offset of the last parameter (if any) relative
1622 // to the frame pointer.
1623 static const int kDisplacement =
1624 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1626 // Check that the key is a smi.
1628 __ JumpIfNotSmi(key, &slow);
1630 // Check if the calling frame is an arguments adaptor frame.
1631 Register local_fp = x11;
1632 Register caller_fp = x11;
1633 Register caller_ctx = x12;
1635 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1636 __ Ldr(caller_ctx, MemOperand(caller_fp,
1637 StandardFrameConstants::kContextOffset));
1638 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1639 __ Csel(local_fp, fp, caller_fp, ne);
1640 __ B(ne, &skip_adaptor);
1642 // Load the actual arguments limit found in the arguments adaptor frame.
1643 __ Ldr(arg_count, MemOperand(caller_fp,
1644 ArgumentsAdaptorFrameConstants::kLengthOffset));
1645 __ Bind(&skip_adaptor);
1647 // Check index against formal parameters count limit. Use unsigned comparison
1648 // to get negative check for free: branch if key < 0 or key >= arg_count.
1649 __ Cmp(key, arg_count);
1652 // Read the argument from the stack and return it.
1653 __ Sub(x10, arg_count, key);
1654 __ Add(x10, local_fp, Operand::UntagSmiAndScale(x10, kPointerSizeLog2));
1655 __ Ldr(x0, MemOperand(x10, kDisplacement));
1658 // Slow case: handle non-smi or out-of-bounds access to arguments by calling
1659 // the runtime system.
1662 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1666 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1667 // Stack layout on entry.
1668 // jssp[0]: number of parameters (tagged)
1669 // jssp[8]: address of receiver argument
1670 // jssp[16]: function
1672 // Check if the calling frame is an arguments adaptor frame.
1674 Register caller_fp = x10;
1675 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1676 // Load and untag the context.
1677 __ Ldr(w11, UntagSmiMemOperand(caller_fp,
1678 StandardFrameConstants::kContextOffset));
1679 __ Cmp(w11, StackFrame::ARGUMENTS_ADAPTOR);
1682 // Patch the arguments.length and parameters pointer in the current frame.
1683 __ Ldr(x11, MemOperand(caller_fp,
1684 ArgumentsAdaptorFrameConstants::kLengthOffset));
1685 __ Poke(x11, 0 * kXRegSize);
1686 __ Add(x10, caller_fp, Operand::UntagSmiAndScale(x11, kPointerSizeLog2));
1687 __ Add(x10, x10, StandardFrameConstants::kCallerSPOffset);
1688 __ Poke(x10, 1 * kXRegSize);
1691 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1695 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1696 // Stack layout on entry.
1697 // jssp[0]: number of parameters (tagged)
1698 // jssp[8]: address of receiver argument
1699 // jssp[16]: function
1701 // Returns pointer to result object in x0.
1703 // Note: arg_count_smi is an alias of param_count_smi.
1704 Register arg_count_smi = x3;
1705 Register param_count_smi = x3;
1706 Register param_count = x7;
1707 Register recv_arg = x14;
1708 Register function = x4;
1709 __ Pop(param_count_smi, recv_arg, function);
1710 __ SmiUntag(param_count, param_count_smi);
1712 // Check if the calling frame is an arguments adaptor frame.
1713 Register caller_fp = x11;
1714 Register caller_ctx = x12;
1716 Label adaptor_frame, try_allocate;
1717 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1718 __ Ldr(caller_ctx, MemOperand(caller_fp,
1719 StandardFrameConstants::kContextOffset));
1720 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1721 __ B(eq, &adaptor_frame);
1723 // No adaptor, parameter count = argument count.
1725 // x1 mapped_params number of mapped params, min(params, args) (uninit)
1726 // x2 arg_count number of function arguments (uninit)
1727 // x3 arg_count_smi number of function arguments (smi)
1728 // x4 function function pointer
1729 // x7 param_count number of function parameters
1730 // x11 caller_fp caller's frame pointer
1731 // x14 recv_arg pointer to receiver arguments
1733 Register arg_count = x2;
1734 __ Mov(arg_count, param_count);
1735 __ B(&try_allocate);
1737 // We have an adaptor frame. Patch the parameters pointer.
1738 __ Bind(&adaptor_frame);
1739 __ Ldr(arg_count_smi,
1740 MemOperand(caller_fp,
1741 ArgumentsAdaptorFrameConstants::kLengthOffset));
1742 __ SmiUntag(arg_count, arg_count_smi);
1743 __ Add(x10, caller_fp, Operand(arg_count, LSL, kPointerSizeLog2));
1744 __ Add(recv_arg, x10, StandardFrameConstants::kCallerSPOffset);
1746 // Compute the mapped parameter count = min(param_count, arg_count)
1747 Register mapped_params = x1;
1748 __ Cmp(param_count, arg_count);
1749 __ Csel(mapped_params, param_count, arg_count, lt);
1751 __ Bind(&try_allocate);
1753 // x0 alloc_obj pointer to allocated objects: param map, backing
1754 // store, arguments (uninit)
1755 // x1 mapped_params number of mapped parameters, min(params, args)
1756 // x2 arg_count number of function arguments
1757 // x3 arg_count_smi number of function arguments (smi)
1758 // x4 function function pointer
1759 // x7 param_count number of function parameters
1760 // x10 size size of objects to allocate (uninit)
1761 // x14 recv_arg pointer to receiver arguments
1763 // Compute the size of backing store, parameter map, and arguments object.
1764 // 1. Parameter map, has two extra words containing context and backing
1766 const int kParameterMapHeaderSize =
1767 FixedArray::kHeaderSize + 2 * kPointerSize;
1769 // Calculate the parameter map size, assuming it exists.
1770 Register size = x10;
1771 __ Mov(size, Operand(mapped_params, LSL, kPointerSizeLog2));
1772 __ Add(size, size, kParameterMapHeaderSize);
1774 // If there are no mapped parameters, set the running size total to zero.
1775 // Otherwise, use the parameter map size calculated earlier.
1776 __ Cmp(mapped_params, 0);
1777 __ CzeroX(size, eq);
1779 // 2. Add the size of the backing store and arguments object.
1780 __ Add(size, size, Operand(arg_count, LSL, kPointerSizeLog2));
1782 FixedArray::kHeaderSize + Heap::kSloppyArgumentsObjectSize);
1784 // Do the allocation of all three objects in one go. Assign this to x0, as it
1785 // will be returned to the caller.
1786 Register alloc_obj = x0;
1787 __ Allocate(size, alloc_obj, x11, x12, &runtime, TAG_OBJECT);
1789 // Get the arguments boilerplate from the current (global) context.
1791 // x0 alloc_obj pointer to allocated objects (param map, backing
1792 // store, arguments)
1793 // x1 mapped_params number of mapped parameters, min(params, args)
1794 // x2 arg_count number of function arguments
1795 // x3 arg_count_smi number of function arguments (smi)
1796 // x4 function function pointer
1797 // x7 param_count number of function parameters
1798 // x11 sloppy_args_map offset to args (or aliased args) map (uninit)
1799 // x14 recv_arg pointer to receiver arguments
1801 Register global_object = x10;
1802 Register global_ctx = x10;
1803 Register sloppy_args_map = x11;
1804 Register aliased_args_map = x10;
1805 __ Ldr(global_object, GlobalObjectMemOperand());
1806 __ Ldr(global_ctx, FieldMemOperand(global_object,
1807 GlobalObject::kNativeContextOffset));
1809 __ Ldr(sloppy_args_map,
1810 ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1813 ContextMemOperand(global_ctx, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX));
1814 __ Cmp(mapped_params, 0);
1815 __ CmovX(sloppy_args_map, aliased_args_map, ne);
1817 // Copy the JS object part.
1818 __ Str(sloppy_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
1819 __ LoadRoot(x10, Heap::kEmptyFixedArrayRootIndex);
1820 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
1821 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1823 // Set up the callee in-object property.
1824 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1825 const int kCalleeOffset = JSObject::kHeaderSize +
1826 Heap::kArgumentsCalleeIndex * kPointerSize;
1827 __ AssertNotSmi(function);
1828 __ Str(function, FieldMemOperand(alloc_obj, kCalleeOffset));
1830 // Use the length and set that as an in-object property.
1831 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1832 const int kLengthOffset = JSObject::kHeaderSize +
1833 Heap::kArgumentsLengthIndex * kPointerSize;
1834 __ Str(arg_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
1836 // Set up the elements pointer in the allocated arguments object.
1837 // If we allocated a parameter map, "elements" will point there, otherwise
1838 // it will point to the backing store.
1840 // x0 alloc_obj pointer to allocated objects (param map, backing
1841 // store, arguments)
1842 // x1 mapped_params number of mapped parameters, min(params, args)
1843 // x2 arg_count number of function arguments
1844 // x3 arg_count_smi number of function arguments (smi)
1845 // x4 function function pointer
1846 // x5 elements pointer to parameter map or backing store (uninit)
1847 // x6 backing_store pointer to backing store (uninit)
1848 // x7 param_count number of function parameters
1849 // x14 recv_arg pointer to receiver arguments
1851 Register elements = x5;
1852 __ Add(elements, alloc_obj, Heap::kSloppyArgumentsObjectSize);
1853 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1855 // Initialize parameter map. If there are no mapped arguments, we're done.
1856 Label skip_parameter_map;
1857 __ Cmp(mapped_params, 0);
1858 // Set up backing store address, because it is needed later for filling in
1859 // the unmapped arguments.
1860 Register backing_store = x6;
1861 __ CmovX(backing_store, elements, eq);
1862 __ B(eq, &skip_parameter_map);
1864 __ LoadRoot(x10, Heap::kSloppyArgumentsElementsMapRootIndex);
1865 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
1866 __ Add(x10, mapped_params, 2);
1868 __ Str(x10, FieldMemOperand(elements, FixedArray::kLengthOffset));
1869 __ Str(cp, FieldMemOperand(elements,
1870 FixedArray::kHeaderSize + 0 * kPointerSize));
1871 __ Add(x10, elements, Operand(mapped_params, LSL, kPointerSizeLog2));
1872 __ Add(x10, x10, kParameterMapHeaderSize);
1873 __ Str(x10, FieldMemOperand(elements,
1874 FixedArray::kHeaderSize + 1 * kPointerSize));
1876 // Copy the parameter slots and the holes in the arguments.
1877 // We need to fill in mapped_parameter_count slots. Then index the context,
1878 // where parameters are stored in reverse order, at:
1880 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS + parameter_count - 1
1882 // The mapped parameter thus needs to get indices:
1884 // MIN_CONTEXT_SLOTS + parameter_count - 1 ..
1885 // MIN_CONTEXT_SLOTS + parameter_count - mapped_parameter_count
1887 // We loop from right to left.
1889 // x0 alloc_obj pointer to allocated objects (param map, backing
1890 // store, arguments)
1891 // x1 mapped_params number of mapped parameters, min(params, args)
1892 // x2 arg_count number of function arguments
1893 // x3 arg_count_smi number of function arguments (smi)
1894 // x4 function function pointer
1895 // x5 elements pointer to parameter map or backing store (uninit)
1896 // x6 backing_store pointer to backing store (uninit)
1897 // x7 param_count number of function parameters
1898 // x11 loop_count parameter loop counter (uninit)
1899 // x12 index parameter index (smi, uninit)
1900 // x13 the_hole hole value (uninit)
1901 // x14 recv_arg pointer to receiver arguments
1903 Register loop_count = x11;
1904 Register index = x12;
1905 Register the_hole = x13;
1906 Label parameters_loop, parameters_test;
1907 __ Mov(loop_count, mapped_params);
1908 __ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS));
1909 __ Sub(index, index, mapped_params);
1911 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
1912 __ Add(backing_store, elements, Operand(loop_count, LSL, kPointerSizeLog2));
1913 __ Add(backing_store, backing_store, kParameterMapHeaderSize);
1915 __ B(¶meters_test);
1917 __ Bind(¶meters_loop);
1918 __ Sub(loop_count, loop_count, 1);
1919 __ Mov(x10, Operand(loop_count, LSL, kPointerSizeLog2));
1920 __ Add(x10, x10, kParameterMapHeaderSize - kHeapObjectTag);
1921 __ Str(index, MemOperand(elements, x10));
1922 __ Sub(x10, x10, kParameterMapHeaderSize - FixedArray::kHeaderSize);
1923 __ Str(the_hole, MemOperand(backing_store, x10));
1924 __ Add(index, index, Smi::FromInt(1));
1925 __ Bind(¶meters_test);
1926 __ Cbnz(loop_count, ¶meters_loop);
1928 __ Bind(&skip_parameter_map);
1929 // Copy arguments header and remaining slots (if there are any.)
1930 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
1931 __ Str(x10, FieldMemOperand(backing_store, FixedArray::kMapOffset));
1932 __ Str(arg_count_smi, FieldMemOperand(backing_store,
1933 FixedArray::kLengthOffset));
1935 // x0 alloc_obj pointer to allocated objects (param map, backing
1936 // store, arguments)
1937 // x1 mapped_params number of mapped parameters, min(params, args)
1938 // x2 arg_count number of function arguments
1939 // x4 function function pointer
1940 // x3 arg_count_smi number of function arguments (smi)
1941 // x6 backing_store pointer to backing store (uninit)
1942 // x14 recv_arg pointer to receiver arguments
1944 Label arguments_loop, arguments_test;
1945 __ Mov(x10, mapped_params);
1946 __ Sub(recv_arg, recv_arg, Operand(x10, LSL, kPointerSizeLog2));
1947 __ B(&arguments_test);
1949 __ Bind(&arguments_loop);
1950 __ Sub(recv_arg, recv_arg, kPointerSize);
1951 __ Ldr(x11, MemOperand(recv_arg));
1952 __ Add(x12, backing_store, Operand(x10, LSL, kPointerSizeLog2));
1953 __ Str(x11, FieldMemOperand(x12, FixedArray::kHeaderSize));
1954 __ Add(x10, x10, 1);
1956 __ Bind(&arguments_test);
1957 __ Cmp(x10, arg_count);
1958 __ B(lt, &arguments_loop);
1962 // Do the runtime call to allocate the arguments object.
1964 __ Push(function, recv_arg, arg_count_smi);
1965 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1969 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1970 // Return address is in lr.
1973 Register receiver = LoadDescriptor::ReceiverRegister();
1974 Register key = LoadDescriptor::NameRegister();
1976 // Check that the key is an array index, that is Uint32.
1977 __ TestAndBranchIfAnySet(key, kSmiTagMask | kSmiSignMask, &slow);
1979 // Everything is fine, call runtime.
1980 __ Push(receiver, key);
1981 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1984 PropertyAccessCompiler::TailCallBuiltin(
1985 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1989 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1990 // Stack layout on entry.
1991 // jssp[0]: number of parameters (tagged)
1992 // jssp[8]: address of receiver argument
1993 // jssp[16]: function
1995 // Returns pointer to result object in x0.
1997 // Get the stub arguments from the frame, and make an untagged copy of the
1999 Register param_count_smi = x1;
2000 Register params = x2;
2001 Register function = x3;
2002 Register param_count = x13;
2003 __ Pop(param_count_smi, params, function);
2004 __ SmiUntag(param_count, param_count_smi);
2006 // Test if arguments adaptor needed.
2007 Register caller_fp = x11;
2008 Register caller_ctx = x12;
2009 Label try_allocate, runtime;
2010 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2011 __ Ldr(caller_ctx, MemOperand(caller_fp,
2012 StandardFrameConstants::kContextOffset));
2013 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2014 __ B(ne, &try_allocate);
2016 // x1 param_count_smi number of parameters passed to function (smi)
2017 // x2 params pointer to parameters
2018 // x3 function function pointer
2019 // x11 caller_fp caller's frame pointer
2020 // x13 param_count number of parameters passed to function
2022 // Patch the argument length and parameters pointer.
2023 __ Ldr(param_count_smi,
2024 MemOperand(caller_fp,
2025 ArgumentsAdaptorFrameConstants::kLengthOffset));
2026 __ SmiUntag(param_count, param_count_smi);
2027 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2028 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2030 // Try the new space allocation. Start out with computing the size of the
2031 // arguments object and the elements array in words.
2032 Register size = x10;
2033 __ Bind(&try_allocate);
2034 __ Add(size, param_count, FixedArray::kHeaderSize / kPointerSize);
2035 __ Cmp(param_count, 0);
2036 __ CzeroX(size, eq);
2037 __ Add(size, size, Heap::kStrictArgumentsObjectSize / kPointerSize);
2039 // Do the allocation of both objects in one go. Assign this to x0, as it will
2040 // be returned to the caller.
2041 Register alloc_obj = x0;
2042 __ Allocate(size, alloc_obj, x11, x12, &runtime,
2043 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
2045 // Get the arguments boilerplate from the current (native) context.
2046 Register global_object = x10;
2047 Register global_ctx = x10;
2048 Register strict_args_map = x4;
2049 __ Ldr(global_object, GlobalObjectMemOperand());
2050 __ Ldr(global_ctx, FieldMemOperand(global_object,
2051 GlobalObject::kNativeContextOffset));
2052 __ Ldr(strict_args_map,
2053 ContextMemOperand(global_ctx, Context::STRICT_ARGUMENTS_MAP_INDEX));
2055 // x0 alloc_obj pointer to allocated objects: parameter array and
2057 // x1 param_count_smi number of parameters passed to function (smi)
2058 // x2 params pointer to parameters
2059 // x3 function function pointer
2060 // x4 strict_args_map offset to arguments map
2061 // x13 param_count number of parameters passed to function
2062 __ Str(strict_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
2063 __ LoadRoot(x5, Heap::kEmptyFixedArrayRootIndex);
2064 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
2065 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2067 // Set the smi-tagged length as an in-object property.
2068 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2069 const int kLengthOffset = JSObject::kHeaderSize +
2070 Heap::kArgumentsLengthIndex * kPointerSize;
2071 __ Str(param_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
2073 // If there are no actual arguments, we're done.
2075 __ Cbz(param_count, &done);
2077 // Set up the elements pointer in the allocated arguments object and
2078 // initialize the header in the elements fixed array.
2079 Register elements = x5;
2080 __ Add(elements, alloc_obj, Heap::kStrictArgumentsObjectSize);
2081 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2082 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
2083 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
2084 __ Str(param_count_smi, FieldMemOperand(elements, FixedArray::kLengthOffset));
2086 // x0 alloc_obj pointer to allocated objects: parameter array and
2088 // x1 param_count_smi number of parameters passed to function (smi)
2089 // x2 params pointer to parameters
2090 // x3 function function pointer
2091 // x4 array pointer to array slot (uninit)
2092 // x5 elements pointer to elements array of alloc_obj
2093 // x13 param_count number of parameters passed to function
2095 // Copy the fixed array slots.
2097 Register array = x4;
2098 // Set up pointer to first array slot.
2099 __ Add(array, elements, FixedArray::kHeaderSize - kHeapObjectTag);
2102 // Pre-decrement the parameters pointer by kPointerSize on each iteration.
2103 // Pre-decrement in order to skip receiver.
2104 __ Ldr(x10, MemOperand(params, -kPointerSize, PreIndex));
2105 // Post-increment elements by kPointerSize on each iteration.
2106 __ Str(x10, MemOperand(array, kPointerSize, PostIndex));
2107 __ Sub(param_count, param_count, 1);
2108 __ Cbnz(param_count, &loop);
2110 // Return from stub.
2114 // Do the runtime call to allocate the arguments object.
2116 __ Push(function, params, param_count_smi);
2117 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2121 void RegExpExecStub::Generate(MacroAssembler* masm) {
2122 #ifdef V8_INTERPRETED_REGEXP
2123 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2124 #else // V8_INTERPRETED_REGEXP
2126 // Stack frame on entry.
2127 // jssp[0]: last_match_info (expected JSArray)
2128 // jssp[8]: previous index
2129 // jssp[16]: subject string
2130 // jssp[24]: JSRegExp object
2133 // Use of registers for this function.
2135 // Variable registers:
2136 // x10-x13 used as scratch registers
2137 // w0 string_type type of subject string
2138 // x2 jsstring_length subject string length
2139 // x3 jsregexp_object JSRegExp object
2140 // w4 string_encoding Latin1 or UC16
2141 // w5 sliced_string_offset if the string is a SlicedString
2142 // offset to the underlying string
2143 // w6 string_representation groups attributes of the string:
2145 // - type of the string
2146 // - is a short external string
2147 Register string_type = w0;
2148 Register jsstring_length = x2;
2149 Register jsregexp_object = x3;
2150 Register string_encoding = w4;
2151 Register sliced_string_offset = w5;
2152 Register string_representation = w6;
2154 // These are in callee save registers and will be preserved by the call
2155 // to the native RegExp code, as this code is called using the normal
2156 // C calling convention. When calling directly from generated code the
2157 // native RegExp code will not do a GC and therefore the content of
2158 // these registers are safe to use after the call.
2160 // x19 subject subject string
2161 // x20 regexp_data RegExp data (FixedArray)
2162 // x21 last_match_info_elements info relative to the last match
2164 // x22 code_object generated regexp code
2165 Register subject = x19;
2166 Register regexp_data = x20;
2167 Register last_match_info_elements = x21;
2168 Register code_object = x22;
2171 // jssp[00]: last_match_info (JSArray)
2172 // jssp[08]: previous index
2173 // jssp[16]: subject string
2174 // jssp[24]: JSRegExp object
2176 const int kLastMatchInfoOffset = 0 * kPointerSize;
2177 const int kPreviousIndexOffset = 1 * kPointerSize;
2178 const int kSubjectOffset = 2 * kPointerSize;
2179 const int kJSRegExpOffset = 3 * kPointerSize;
2181 // Ensure that a RegExp stack is allocated.
2182 ExternalReference address_of_regexp_stack_memory_address =
2183 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2184 ExternalReference address_of_regexp_stack_memory_size =
2185 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2186 __ Mov(x10, address_of_regexp_stack_memory_size);
2187 __ Ldr(x10, MemOperand(x10));
2188 __ Cbz(x10, &runtime);
2190 // Check that the first argument is a JSRegExp object.
2191 DCHECK(jssp.Is(__ StackPointer()));
2192 __ Peek(jsregexp_object, kJSRegExpOffset);
2193 __ JumpIfSmi(jsregexp_object, &runtime);
2194 __ JumpIfNotObjectType(jsregexp_object, x10, x10, JS_REGEXP_TYPE, &runtime);
2196 // Check that the RegExp has been compiled (data contains a fixed array).
2197 __ Ldr(regexp_data, FieldMemOperand(jsregexp_object, JSRegExp::kDataOffset));
2198 if (FLAG_debug_code) {
2199 STATIC_ASSERT(kSmiTag == 0);
2200 __ Tst(regexp_data, kSmiTagMask);
2201 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2202 __ CompareObjectType(regexp_data, x10, x10, FIXED_ARRAY_TYPE);
2203 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2206 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2207 __ Ldr(x10, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2208 __ Cmp(x10, Smi::FromInt(JSRegExp::IRREGEXP));
2211 // Check that the number of captures fit in the static offsets vector buffer.
2212 // We have always at least one capture for the whole match, plus additional
2213 // ones due to capturing parentheses. A capture takes 2 registers.
2214 // The number of capture registers then is (number_of_captures + 1) * 2.
2216 UntagSmiFieldMemOperand(regexp_data,
2217 JSRegExp::kIrregexpCaptureCountOffset));
2218 // Check (number_of_captures + 1) * 2 <= offsets vector size
2219 // number_of_captures * 2 <= offsets vector size - 2
2220 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2221 __ Add(x10, x10, x10);
2222 __ Cmp(x10, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
2225 // Initialize offset for possibly sliced string.
2226 __ Mov(sliced_string_offset, 0);
2228 DCHECK(jssp.Is(__ StackPointer()));
2229 __ Peek(subject, kSubjectOffset);
2230 __ JumpIfSmi(subject, &runtime);
2232 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2233 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2235 __ Ldr(jsstring_length, FieldMemOperand(subject, String::kLengthOffset));
2237 // Handle subject string according to its encoding and representation:
2238 // (1) Sequential string? If yes, go to (5).
2239 // (2) Anything but sequential or cons? If yes, go to (6).
2240 // (3) Cons string. If the string is flat, replace subject with first string.
2241 // Otherwise bailout.
2242 // (4) Is subject external? If yes, go to (7).
2243 // (5) Sequential string. Load regexp code according to encoding.
2247 // Deferred code at the end of the stub:
2248 // (6) Not a long external string? If yes, go to (8).
2249 // (7) External string. Make it, offset-wise, look like a sequential string.
2251 // (8) Short external string or not a string? If yes, bail out to runtime.
2252 // (9) Sliced string. Replace subject with parent. Go to (4).
2254 Label check_underlying; // (4)
2255 Label seq_string; // (5)
2256 Label not_seq_nor_cons; // (6)
2257 Label external_string; // (7)
2258 Label not_long_external; // (8)
2260 // (1) Sequential string? If yes, go to (5).
2261 __ And(string_representation,
2264 kStringRepresentationMask |
2265 kShortExternalStringMask);
2266 // We depend on the fact that Strings of type
2267 // SeqString and not ShortExternalString are defined
2268 // by the following pattern:
2269 // string_type: 0XX0 XX00
2272 // | | is a SeqString
2273 // | is not a short external String
2275 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2276 STATIC_ASSERT(kShortExternalStringTag != 0);
2277 __ Cbz(string_representation, &seq_string); // Go to (5).
2279 // (2) Anything but sequential or cons? If yes, go to (6).
2280 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2281 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2282 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2283 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2284 __ Cmp(string_representation, kExternalStringTag);
2285 __ B(ge, ¬_seq_nor_cons); // Go to (6).
2287 // (3) Cons string. Check that it's flat.
2288 __ Ldr(x10, FieldMemOperand(subject, ConsString::kSecondOffset));
2289 __ JumpIfNotRoot(x10, Heap::kempty_stringRootIndex, &runtime);
2290 // Replace subject with first string.
2291 __ Ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2293 // (4) Is subject external? If yes, go to (7).
2294 __ Bind(&check_underlying);
2295 // Reload the string type.
2296 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2297 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2298 STATIC_ASSERT(kSeqStringTag == 0);
2299 // The underlying external string is never a short external string.
2300 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2301 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2302 __ TestAndBranchIfAnySet(string_type.X(),
2303 kStringRepresentationMask,
2304 &external_string); // Go to (7).
2306 // (5) Sequential string. Load regexp code according to encoding.
2307 __ Bind(&seq_string);
2309 // Check that the third argument is a positive smi less than the subject
2310 // string length. A negative value will be greater (unsigned comparison).
2311 DCHECK(jssp.Is(__ StackPointer()));
2312 __ Peek(x10, kPreviousIndexOffset);
2313 __ JumpIfNotSmi(x10, &runtime);
2314 __ Cmp(jsstring_length, x10);
2317 // Argument 2 (x1): We need to load argument 2 (the previous index) into x1
2318 // before entering the exit frame.
2319 __ SmiUntag(x1, x10);
2321 // The third bit determines the string encoding in string_type.
2322 STATIC_ASSERT(kOneByteStringTag == 0x04);
2323 STATIC_ASSERT(kTwoByteStringTag == 0x00);
2324 STATIC_ASSERT(kStringEncodingMask == 0x04);
2326 // Find the code object based on the assumptions above.
2327 // kDataOneByteCodeOffset and kDataUC16CodeOffset are adjacent, adds an offset
2328 // of kPointerSize to reach the latter.
2329 STATIC_ASSERT(JSRegExp::kDataOneByteCodeOffset + kPointerSize ==
2330 JSRegExp::kDataUC16CodeOffset);
2331 __ Mov(x10, kPointerSize);
2332 // We will need the encoding later: Latin1 = 0x04
2334 __ Ands(string_encoding, string_type, kStringEncodingMask);
2336 __ Add(x10, regexp_data, x10);
2337 __ Ldr(code_object, FieldMemOperand(x10, JSRegExp::kDataOneByteCodeOffset));
2339 // (E) Carry on. String handling is done.
2341 // Check that the irregexp code has been generated for the actual string
2342 // encoding. If it has, the field contains a code object otherwise it contains
2343 // a smi (code flushing support).
2344 __ JumpIfSmi(code_object, &runtime);
2346 // All checks done. Now push arguments for native regexp code.
2347 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1,
2351 // Isolates: note we add an additional parameter here (isolate pointer).
2352 __ EnterExitFrame(false, x10, 1);
2353 DCHECK(csp.Is(__ StackPointer()));
2355 // We have 9 arguments to pass to the regexp code, therefore we have to pass
2356 // one on the stack and the rest as registers.
2358 // Note that the placement of the argument on the stack isn't standard
2360 // csp[0]: Space for the return address placed by DirectCEntryStub.
2361 // csp[8]: Argument 9, the current isolate address.
2363 __ Mov(x10, ExternalReference::isolate_address(isolate()));
2364 __ Poke(x10, kPointerSize);
2366 Register length = w11;
2367 Register previous_index_in_bytes = w12;
2368 Register start = x13;
2370 // Load start of the subject string.
2371 __ Add(start, subject, SeqString::kHeaderSize - kHeapObjectTag);
2372 // Load the length from the original subject string from the previous stack
2373 // frame. Therefore we have to use fp, which points exactly to two pointer
2374 // sizes below the previous sp. (Because creating a new stack frame pushes
2375 // the previous fp onto the stack and decrements sp by 2 * kPointerSize.)
2376 __ Ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2377 __ Ldr(length, UntagSmiFieldMemOperand(subject, String::kLengthOffset));
2379 // Handle UC16 encoding, two bytes make one character.
2380 // string_encoding: if Latin1: 0x04
2382 STATIC_ASSERT(kStringEncodingMask == 0x04);
2383 __ Ubfx(string_encoding, string_encoding, 2, 1);
2384 __ Eor(string_encoding, string_encoding, 1);
2385 // string_encoding: if Latin1: 0
2388 // Convert string positions from characters to bytes.
2389 // Previous index is in x1.
2390 __ Lsl(previous_index_in_bytes, w1, string_encoding);
2391 __ Lsl(length, length, string_encoding);
2392 __ Lsl(sliced_string_offset, sliced_string_offset, string_encoding);
2394 // Argument 1 (x0): Subject string.
2395 __ Mov(x0, subject);
2397 // Argument 2 (x1): Previous index, already there.
2399 // Argument 3 (x2): Get the start of input.
2400 // Start of input = start of string + previous index + substring offset
2403 __ Add(w10, previous_index_in_bytes, sliced_string_offset);
2404 __ Add(x2, start, Operand(w10, UXTW));
2407 // End of input = start of input + (length of input - previous index)
2408 __ Sub(w10, length, previous_index_in_bytes);
2409 __ Add(x3, x2, Operand(w10, UXTW));
2411 // Argument 5 (x4): static offsets vector buffer.
2412 __ Mov(x4, ExternalReference::address_of_static_offsets_vector(isolate()));
2414 // Argument 6 (x5): Set the number of capture registers to zero to force
2415 // global regexps to behave as non-global. This stub is not used for global
2419 // Argument 7 (x6): Start (high end) of backtracking stack memory area.
2420 __ Mov(x10, address_of_regexp_stack_memory_address);
2421 __ Ldr(x10, MemOperand(x10));
2422 __ Mov(x11, address_of_regexp_stack_memory_size);
2423 __ Ldr(x11, MemOperand(x11));
2424 __ Add(x6, x10, x11);
2426 // Argument 8 (x7): Indicate that this is a direct call from JavaScript.
2429 // Locate the code entry and call it.
2430 __ Add(code_object, code_object, Code::kHeaderSize - kHeapObjectTag);
2431 DirectCEntryStub stub(isolate());
2432 stub.GenerateCall(masm, code_object);
2434 __ LeaveExitFrame(false, x10, true);
2436 // The generated regexp code returns an int32 in w0.
2437 Label failure, exception;
2438 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::FAILURE, eq, &failure);
2439 __ CompareAndBranch(w0,
2440 NativeRegExpMacroAssembler::EXCEPTION,
2443 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::RETRY, eq, &runtime);
2445 // Success: process the result from the native regexp code.
2446 Register number_of_capture_registers = x12;
2448 // Calculate number of capture registers (number_of_captures + 1) * 2
2449 // and store it in the last match info.
2451 UntagSmiFieldMemOperand(regexp_data,
2452 JSRegExp::kIrregexpCaptureCountOffset));
2453 __ Add(x10, x10, x10);
2454 __ Add(number_of_capture_registers, x10, 2);
2456 // Check that the fourth object is a JSArray object.
2457 DCHECK(jssp.Is(__ StackPointer()));
2458 __ Peek(x10, kLastMatchInfoOffset);
2459 __ JumpIfSmi(x10, &runtime);
2460 __ JumpIfNotObjectType(x10, x11, x11, JS_ARRAY_TYPE, &runtime);
2462 // Check that the JSArray is the fast case.
2463 __ Ldr(last_match_info_elements,
2464 FieldMemOperand(x10, JSArray::kElementsOffset));
2466 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2467 __ JumpIfNotRoot(x10, Heap::kFixedArrayMapRootIndex, &runtime);
2469 // Check that the last match info has space for the capture registers and the
2470 // additional information (overhead).
2471 // (number_of_captures + 1) * 2 + overhead <= last match info size
2472 // (number_of_captures * 2) + 2 + overhead <= last match info size
2473 // number_of_capture_registers + overhead <= last match info size
2475 UntagSmiFieldMemOperand(last_match_info_elements,
2476 FixedArray::kLengthOffset));
2477 __ Add(x11, number_of_capture_registers, RegExpImpl::kLastMatchOverhead);
2481 // Store the capture count.
2482 __ SmiTag(x10, number_of_capture_registers);
2484 FieldMemOperand(last_match_info_elements,
2485 RegExpImpl::kLastCaptureCountOffset));
2486 // Store last subject and last input.
2488 FieldMemOperand(last_match_info_elements,
2489 RegExpImpl::kLastSubjectOffset));
2490 // Use x10 as the subject string in order to only need
2491 // one RecordWriteStub.
2492 __ Mov(x10, subject);
2493 __ RecordWriteField(last_match_info_elements,
2494 RegExpImpl::kLastSubjectOffset,
2500 FieldMemOperand(last_match_info_elements,
2501 RegExpImpl::kLastInputOffset));
2502 __ Mov(x10, subject);
2503 __ RecordWriteField(last_match_info_elements,
2504 RegExpImpl::kLastInputOffset,
2510 Register last_match_offsets = x13;
2511 Register offsets_vector_index = x14;
2512 Register current_offset = x15;
2514 // Get the static offsets vector filled by the native regexp code
2515 // and fill the last match info.
2516 ExternalReference address_of_static_offsets_vector =
2517 ExternalReference::address_of_static_offsets_vector(isolate());
2518 __ Mov(offsets_vector_index, address_of_static_offsets_vector);
2520 Label next_capture, done;
2521 // Capture register counter starts from number of capture registers and
2522 // iterates down to zero (inclusive).
2523 __ Add(last_match_offsets,
2524 last_match_info_elements,
2525 RegExpImpl::kFirstCaptureOffset - kHeapObjectTag);
2526 __ Bind(&next_capture);
2527 __ Subs(number_of_capture_registers, number_of_capture_registers, 2);
2529 // Read two 32 bit values from the static offsets vector buffer into
2531 __ Ldr(current_offset,
2532 MemOperand(offsets_vector_index, kWRegSize * 2, PostIndex));
2533 // Store the smi values in the last match info.
2534 __ SmiTag(x10, current_offset);
2535 // Clearing the 32 bottom bits gives us a Smi.
2536 STATIC_ASSERT(kSmiTag == 0);
2537 __ Bic(x11, current_offset, kSmiShiftMask);
2540 MemOperand(last_match_offsets, kXRegSize * 2, PostIndex));
2541 __ B(&next_capture);
2544 // Return last match info.
2545 __ Peek(x0, kLastMatchInfoOffset);
2546 // Drop the 4 arguments of the stub from the stack.
2550 __ Bind(&exception);
2551 Register exception_value = x0;
2552 // A stack overflow (on the backtrack stack) may have occured
2553 // in the RegExp code but no exception has been created yet.
2554 // If there is no pending exception, handle that in the runtime system.
2555 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
2557 Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2559 __ Ldr(exception_value, MemOperand(x11));
2560 __ Cmp(x10, exception_value);
2563 // For exception, throw the exception again.
2564 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2567 __ Mov(x0, Operand(isolate()->factory()->null_value()));
2568 // Drop the 4 arguments of the stub from the stack.
2573 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2575 // Deferred code for string handling.
2576 // (6) Not a long external string? If yes, go to (8).
2577 __ Bind(¬_seq_nor_cons);
2578 // Compare flags are still set.
2579 __ B(ne, ¬_long_external); // Go to (8).
2581 // (7) External string. Make it, offset-wise, look like a sequential string.
2582 __ Bind(&external_string);
2583 if (masm->emit_debug_code()) {
2584 // Assert that we do not have a cons or slice (indirect strings) here.
2585 // Sequential strings have already been ruled out.
2586 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2587 __ Ldrb(x10, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2588 __ Tst(x10, kIsIndirectStringMask);
2589 __ Check(eq, kExternalStringExpectedButNotFound);
2590 __ And(x10, x10, kStringRepresentationMask);
2592 __ Check(ne, kExternalStringExpectedButNotFound);
2595 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2596 // Move the pointer so that offset-wise, it looks like a sequential string.
2597 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2598 __ Sub(subject, subject, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2599 __ B(&seq_string); // Go to (5).
2601 // (8) If this is a short external string or not a string, bail out to
2603 __ Bind(¬_long_external);
2604 STATIC_ASSERT(kShortExternalStringTag != 0);
2605 __ TestAndBranchIfAnySet(string_representation,
2606 kShortExternalStringMask | kIsNotStringMask,
2609 // (9) Sliced string. Replace subject with parent.
2610 __ Ldr(sliced_string_offset,
2611 UntagSmiFieldMemOperand(subject, SlicedString::kOffsetOffset));
2612 __ Ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2613 __ B(&check_underlying); // Go to (4).
2618 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2619 Register argc, Register function,
2620 Register feedback_vector, Register index,
2621 Register orig_construct, bool is_super) {
2622 FrameScope scope(masm, StackFrame::INTERNAL);
2624 // Number-of-arguments register must be smi-tagged to call out.
2627 __ Push(argc, function, feedback_vector, index, orig_construct);
2629 __ Push(argc, function, feedback_vector, index);
2632 DCHECK(feedback_vector.Is(x2) && index.Is(x3));
2636 __ Pop(orig_construct, index, feedback_vector, function, argc);
2638 __ Pop(index, feedback_vector, function, argc);
2644 static void GenerateRecordCallTarget(MacroAssembler* masm, Register argc,
2646 Register feedback_vector, Register index,
2647 Register orig_construct, Register scratch1,
2648 Register scratch2, Register scratch3,
2650 ASM_LOCATION("GenerateRecordCallTarget");
2651 DCHECK(!AreAliased(scratch1, scratch2, scratch3, argc, function,
2652 feedback_vector, index, orig_construct));
2653 // Cache the called function in a feedback vector slot. Cache states are
2654 // uninitialized, monomorphic (indicated by a JSFunction), and megamorphic.
2655 // argc : number of arguments to the construct function
2656 // function : the function to call
2657 // feedback_vector : the feedback vector
2658 // index : slot in feedback vector (smi)
2659 // orig_construct : original constructor (for IsSuperConstructorCall)
2660 Label initialize, done, miss, megamorphic, not_array_function;
2662 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2663 masm->isolate()->heap()->megamorphic_symbol());
2664 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2665 masm->isolate()->heap()->uninitialized_symbol());
2667 // Load the cache state.
2668 Register feedback = scratch1;
2669 Register feedback_map = scratch2;
2670 Register feedback_value = scratch3;
2671 __ Add(feedback, feedback_vector,
2672 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2673 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
2675 // A monomorphic cache hit or an already megamorphic state: invoke the
2676 // function without changing the state.
2677 // We don't know if feedback value is a WeakCell or a Symbol, but it's
2678 // harmless to read at this position in a symbol (see static asserts in
2679 // type-feedback-vector.h).
2680 Label check_allocation_site;
2681 __ Ldr(feedback_value, FieldMemOperand(feedback, WeakCell::kValueOffset));
2682 __ Cmp(function, feedback_value);
2684 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
2686 __ Ldr(feedback_map, FieldMemOperand(feedback, HeapObject::kMapOffset));
2687 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2688 __ B(ne, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2690 // If the weak cell is cleared, we have a new chance to become monomorphic.
2691 __ JumpIfSmi(feedback_value, &initialize);
2694 if (!FLAG_pretenuring_call_new) {
2695 __ bind(&check_allocation_site);
2696 // If we came here, we need to see if we are the array function.
2697 // If we didn't have a matching function, and we didn't find the megamorph
2698 // sentinel, then we have in the slot either some other function or an
2700 __ JumpIfNotRoot(feedback_map, Heap::kAllocationSiteMapRootIndex, &miss);
2702 // Make sure the function is the Array() function
2703 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2704 __ Cmp(function, scratch1);
2705 __ B(ne, &megamorphic);
2711 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2713 __ JumpIfRoot(scratch1, Heap::kuninitialized_symbolRootIndex, &initialize);
2714 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2715 // write-barrier is needed.
2716 __ Bind(&megamorphic);
2717 __ Add(scratch1, feedback_vector,
2718 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2719 __ LoadRoot(scratch2, Heap::kmegamorphic_symbolRootIndex);
2720 __ Str(scratch2, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
2723 // An uninitialized cache is patched with the function or sentinel to
2724 // indicate the ElementsKind if function is the Array constructor.
2725 __ Bind(&initialize);
2727 if (!FLAG_pretenuring_call_new) {
2728 // Make sure the function is the Array() function
2729 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2730 __ Cmp(function, scratch1);
2731 __ B(ne, ¬_array_function);
2733 // The target function is the Array constructor,
2734 // Create an AllocationSite if we don't already have it, store it in the
2736 CreateAllocationSiteStub create_stub(masm->isolate());
2737 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2738 feedback_vector, index, orig_construct,
2742 __ Bind(¬_array_function);
2745 CreateWeakCellStub create_stub(masm->isolate());
2746 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2747 feedback_vector, index, orig_construct, is_super);
2752 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2753 // Do not transform the receiver for strict mode functions.
2754 __ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
2755 __ Ldr(w4, FieldMemOperand(x3, SharedFunctionInfo::kCompilerHintsOffset));
2756 __ Tbnz(w4, SharedFunctionInfo::kStrictModeFunction, cont);
2758 // Do not transform the receiver for native (Compilerhints already in x3).
2759 __ Tbnz(w4, SharedFunctionInfo::kNative, cont);
2763 static void EmitSlowCase(MacroAssembler* masm, int argc) {
2765 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2769 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2770 // Wrap the receiver and patch it back onto the stack.
2771 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2774 ToObjectStub stub(masm->isolate());
2778 __ Poke(x0, argc * kPointerSize);
2783 static void CallFunctionNoFeedback(MacroAssembler* masm,
2784 int argc, bool needs_checks,
2785 bool call_as_method) {
2786 // x1 function the function to call
2787 Register function = x1;
2789 Label slow, wrap, cont;
2791 // TODO(jbramley): This function has a lot of unnamed registers. Name them,
2792 // and tidy things up a bit.
2795 // Check that the function is really a JavaScript function.
2796 __ JumpIfSmi(function, &slow);
2798 // Goto slow case if we do not have a function.
2799 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
2802 // Fast-case: Invoke the function now.
2803 // x1 function pushed function
2804 ParameterCount actual(argc);
2806 if (call_as_method) {
2808 EmitContinueIfStrictOrNative(masm, &cont);
2811 // Compute the receiver in sloppy mode.
2812 __ Peek(x3, argc * kPointerSize);
2815 __ JumpIfSmi(x3, &wrap);
2816 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
2824 __ InvokeFunction(function,
2829 // Slow-case: Non-function called.
2831 EmitSlowCase(masm, argc);
2834 if (call_as_method) {
2836 EmitWrapCase(masm, argc, &cont);
2841 void CallFunctionStub::Generate(MacroAssembler* masm) {
2842 ASM_LOCATION("CallFunctionStub::Generate");
2843 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2847 void CallConstructStub::Generate(MacroAssembler* masm) {
2848 ASM_LOCATION("CallConstructStub::Generate");
2849 // x0 : number of arguments
2850 // x1 : the function to call
2851 // x2 : feedback vector
2852 // x3 : slot in feedback vector (Smi, for RecordCallTarget)
2853 // x4 : original constructor (for IsSuperConstructorCall)
2854 Register function = x1;
2855 Label slow, non_function_call;
2857 // Check that the function is not a smi.
2858 __ JumpIfSmi(function, &non_function_call);
2859 // Check that the function is a JSFunction.
2860 Register object_type = x10;
2861 __ JumpIfNotObjectType(function, object_type, object_type, JS_FUNCTION_TYPE,
2864 if (RecordCallTarget()) {
2865 GenerateRecordCallTarget(masm, x0, function, x2, x3, x4, x5, x11, x12,
2866 IsSuperConstructorCall());
2868 __ Add(x5, x2, Operand::UntagSmiAndScale(x3, kPointerSizeLog2));
2869 if (FLAG_pretenuring_call_new) {
2870 // Put the AllocationSite from the feedback vector into x2.
2871 // By adding kPointerSize we encode that we know the AllocationSite
2872 // entry is at the feedback vector slot given by x3 + 1.
2873 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize + kPointerSize));
2875 Label feedback_register_initialized;
2876 // Put the AllocationSite from the feedback vector into x2, or undefined.
2877 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize));
2878 __ Ldr(x5, FieldMemOperand(x2, AllocationSite::kMapOffset));
2879 __ JumpIfRoot(x5, Heap::kAllocationSiteMapRootIndex,
2880 &feedback_register_initialized);
2881 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
2882 __ bind(&feedback_register_initialized);
2885 __ AssertUndefinedOrAllocationSite(x2, x5);
2888 if (IsSuperConstructorCall()) {
2891 __ Mov(x3, function);
2894 // Jump to the function-specific construct stub.
2895 Register jump_reg = x4;
2896 Register shared_func_info = jump_reg;
2897 Register cons_stub = jump_reg;
2898 Register cons_stub_code = jump_reg;
2899 __ Ldr(shared_func_info,
2900 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
2902 FieldMemOperand(shared_func_info,
2903 SharedFunctionInfo::kConstructStubOffset));
2904 __ Add(cons_stub_code, cons_stub, Code::kHeaderSize - kHeapObjectTag);
2905 __ Br(cons_stub_code);
2909 __ Cmp(object_type, JS_FUNCTION_PROXY_TYPE);
2910 __ B(ne, &non_function_call);
2911 __ GetBuiltinFunction(
2912 x1, Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2915 __ Bind(&non_function_call);
2916 __ GetBuiltinFunction(
2917 x1, Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2920 // Set expected number of arguments to zero (not changing x0).
2922 __ Jump(isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2923 RelocInfo::CODE_TARGET);
2927 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2928 __ Ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2929 __ Ldr(vector, FieldMemOperand(vector,
2930 JSFunction::kSharedFunctionInfoOffset));
2931 __ Ldr(vector, FieldMemOperand(vector,
2932 SharedFunctionInfo::kFeedbackVectorOffset));
2936 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2941 Register function = x1;
2942 Register feedback_vector = x2;
2943 Register index = x3;
2944 Register scratch = x4;
2946 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch);
2947 __ Cmp(function, scratch);
2950 __ Mov(x0, Operand(arg_count()));
2952 __ Add(scratch, feedback_vector,
2953 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2954 __ Ldr(scratch, FieldMemOperand(scratch, FixedArray::kHeaderSize));
2956 // Verify that scratch contains an AllocationSite
2958 __ Ldr(map, FieldMemOperand(scratch, HeapObject::kMapOffset));
2959 __ JumpIfNotRoot(map, Heap::kAllocationSiteMapRootIndex, &miss);
2961 // Increment the call count for monomorphic function calls.
2962 __ Add(feedback_vector, feedback_vector,
2963 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2964 __ Add(feedback_vector, feedback_vector,
2965 Operand(FixedArray::kHeaderSize + kPointerSize));
2966 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
2967 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2968 __ Str(index, FieldMemOperand(feedback_vector, 0));
2970 Register allocation_site = feedback_vector;
2971 Register original_constructor = index;
2972 __ Mov(allocation_site, scratch);
2973 __ Mov(original_constructor, function);
2974 ArrayConstructorStub stub(masm->isolate(), arg_count());
2975 __ TailCallStub(&stub);
2980 // The slow case, we need this no matter what to complete a call after a miss.
2981 __ Mov(x0, arg_count());
2982 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2986 void CallICStub::Generate(MacroAssembler* masm) {
2987 ASM_LOCATION("CallICStub");
2990 // x3 - slot id (Smi)
2992 const int with_types_offset =
2993 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2994 const int generic_offset =
2995 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2996 Label extra_checks_or_miss, slow_start;
2997 Label slow, wrap, cont;
2998 Label have_js_function;
2999 int argc = arg_count();
3000 ParameterCount actual(argc);
3002 Register function = x1;
3003 Register feedback_vector = x2;
3004 Register index = x3;
3007 // The checks. First, does x1 match the recorded monomorphic target?
3008 __ Add(x4, feedback_vector,
3009 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3010 __ Ldr(x4, FieldMemOperand(x4, FixedArray::kHeaderSize));
3012 // We don't know that we have a weak cell. We might have a private symbol
3013 // or an AllocationSite, but the memory is safe to examine.
3014 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
3016 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
3017 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
3018 // computed, meaning that it can't appear to be a pointer. If the low bit is
3019 // 0, then hash is computed, but the 0 bit prevents the field from appearing
3021 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
3022 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
3023 WeakCell::kValueOffset &&
3024 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
3026 __ Ldr(x5, FieldMemOperand(x4, WeakCell::kValueOffset));
3027 __ Cmp(x5, function);
3028 __ B(ne, &extra_checks_or_miss);
3030 // The compare above could have been a SMI/SMI comparison. Guard against this
3031 // convincing us that we have a monomorphic JSFunction.
3032 __ JumpIfSmi(function, &extra_checks_or_miss);
3034 // Increment the call count for monomorphic function calls.
3035 __ Add(feedback_vector, feedback_vector,
3036 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3037 __ Add(feedback_vector, feedback_vector,
3038 Operand(FixedArray::kHeaderSize + kPointerSize));
3039 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
3040 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3041 __ Str(index, FieldMemOperand(feedback_vector, 0));
3043 __ bind(&have_js_function);
3044 if (CallAsMethod()) {
3045 EmitContinueIfStrictOrNative(masm, &cont);
3047 // Compute the receiver in sloppy mode.
3048 __ Peek(x3, argc * kPointerSize);
3050 __ JumpIfSmi(x3, &wrap);
3051 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
3056 __ InvokeFunction(function,
3062 EmitSlowCase(masm, argc);
3064 if (CallAsMethod()) {
3066 EmitWrapCase(masm, argc, &cont);
3069 __ bind(&extra_checks_or_miss);
3070 Label uninitialized, miss;
3072 __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &slow_start);
3074 // The following cases attempt to handle MISS cases without going to the
3076 if (FLAG_trace_ic) {
3080 __ JumpIfRoot(x4, Heap::kuninitialized_symbolRootIndex, &miss);
3082 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3083 // to handle it here. More complex cases are dealt with in the runtime.
3084 __ AssertNotSmi(x4);
3085 __ JumpIfNotObjectType(x4, x5, x5, JS_FUNCTION_TYPE, &miss);
3086 __ Add(x4, feedback_vector,
3087 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3088 __ LoadRoot(x5, Heap::kmegamorphic_symbolRootIndex);
3089 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize));
3090 // We have to update statistics for runtime profiling.
3091 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3092 __ Subs(x4, x4, Operand(Smi::FromInt(1)));
3093 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3094 __ Ldr(x4, FieldMemOperand(feedback_vector, generic_offset));
3095 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3096 __ Str(x4, FieldMemOperand(feedback_vector, generic_offset));
3099 __ bind(&uninitialized);
3101 // We are going monomorphic, provided we actually have a JSFunction.
3102 __ JumpIfSmi(function, &miss);
3104 // Goto miss case if we do not have a function.
3105 __ JumpIfNotObjectType(function, x5, x5, JS_FUNCTION_TYPE, &miss);
3107 // Make sure the function is not the Array() function, which requires special
3108 // behavior on MISS.
3109 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, x5);
3110 __ Cmp(function, x5);
3114 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3115 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3116 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3118 // Initialize the call counter.
3119 __ Mov(x5, Smi::FromInt(CallICNexus::kCallCountIncrement));
3120 __ Adds(x4, feedback_vector,
3121 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3122 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize + kPointerSize));
3124 // Store the function. Use a stub since we need a frame for allocation.
3129 FrameScope scope(masm, StackFrame::INTERNAL);
3130 CreateWeakCellStub create_stub(masm->isolate());
3132 __ CallStub(&create_stub);
3136 __ B(&have_js_function);
3138 // We are here because tracing is on or we encountered a MISS case we can't
3144 __ bind(&slow_start);
3146 // Check that the function is really a JavaScript function.
3147 __ JumpIfSmi(function, &slow);
3149 // Goto slow case if we do not have a function.
3150 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
3151 __ B(&have_js_function);
3155 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3156 ASM_LOCATION("CallICStub[Miss]");
3158 FrameScope scope(masm, StackFrame::INTERNAL);
3160 // Push the receiver and the function and feedback info.
3161 __ Push(x1, x2, x3);
3164 Runtime::FunctionId id = GetICState() == DEFAULT
3165 ? Runtime::kCallIC_Miss
3166 : Runtime::kCallIC_Customization_Miss;
3167 __ CallRuntime(id, 3);
3169 // Move result to edi and exit the internal frame.
3174 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3175 // If the receiver is a smi trigger the non-string case.
3176 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3177 __ JumpIfSmi(object_, receiver_not_string_);
3179 // Fetch the instance type of the receiver into result register.
3180 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3181 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3183 // If the receiver is not a string trigger the non-string case.
3184 __ TestAndBranchIfAnySet(result_, kIsNotStringMask, receiver_not_string_);
3187 // If the index is non-smi trigger the non-smi case.
3188 __ JumpIfNotSmi(index_, &index_not_smi_);
3190 __ Bind(&got_smi_index_);
3191 // Check for index out of range.
3192 __ Ldrsw(result_, UntagSmiFieldMemOperand(object_, String::kLengthOffset));
3193 __ Cmp(result_, Operand::UntagSmi(index_));
3194 __ B(ls, index_out_of_range_);
3196 __ SmiUntag(index_);
3198 StringCharLoadGenerator::Generate(masm,
3208 void StringCharCodeAtGenerator::GenerateSlow(
3209 MacroAssembler* masm, EmbedMode embed_mode,
3210 const RuntimeCallHelper& call_helper) {
3211 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3213 __ Bind(&index_not_smi_);
3214 // If index is a heap number, try converting it to an integer.
3215 __ JumpIfNotHeapNumber(index_, index_not_number_);
3216 call_helper.BeforeCall(masm);
3217 if (embed_mode == PART_OF_IC_HANDLER) {
3218 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3219 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3221 // Save object_ on the stack and pass index_ as argument for runtime call.
3222 __ Push(object_, index_);
3224 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3225 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3227 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3228 // NumberToSmi discards numbers that are not exact integers.
3229 __ CallRuntime(Runtime::kNumberToSmi, 1);
3231 // Save the conversion result before the pop instructions below
3232 // have a chance to overwrite it.
3234 if (embed_mode == PART_OF_IC_HANDLER) {
3235 __ Pop(object_, LoadWithVectorDescriptor::SlotRegister(),
3236 LoadWithVectorDescriptor::VectorRegister());
3240 // Reload the instance type.
3241 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3242 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3243 call_helper.AfterCall(masm);
3245 // If index is still not a smi, it must be out of range.
3246 __ JumpIfNotSmi(index_, index_out_of_range_);
3247 // Otherwise, return to the fast path.
3248 __ B(&got_smi_index_);
3250 // Call runtime. We get here when the receiver is a string and the
3251 // index is a number, but the code of getting the actual character
3252 // is too complex (e.g., when the string needs to be flattened).
3253 __ Bind(&call_runtime_);
3254 call_helper.BeforeCall(masm);
3256 __ Push(object_, index_);
3257 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3258 __ Mov(result_, x0);
3259 call_helper.AfterCall(masm);
3262 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3266 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3267 __ JumpIfNotSmi(code_, &slow_case_);
3268 __ Cmp(code_, Smi::FromInt(String::kMaxOneByteCharCode));
3269 __ B(hi, &slow_case_);
3271 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3272 // At this point code register contains smi tagged one-byte char code.
3273 __ Add(result_, result_, Operand::UntagSmiAndScale(code_, kPointerSizeLog2));
3274 __ Ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3275 __ JumpIfRoot(result_, Heap::kUndefinedValueRootIndex, &slow_case_);
3280 void StringCharFromCodeGenerator::GenerateSlow(
3281 MacroAssembler* masm,
3282 const RuntimeCallHelper& call_helper) {
3283 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3285 __ Bind(&slow_case_);
3286 call_helper.BeforeCall(masm);
3288 __ CallRuntime(Runtime::kCharFromCode, 1);
3289 __ Mov(result_, x0);
3290 call_helper.AfterCall(masm);
3293 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3297 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3298 // Inputs are in x0 (lhs) and x1 (rhs).
3299 DCHECK(state() == CompareICState::SMI);
3300 ASM_LOCATION("CompareICStub[Smis]");
3302 // Bail out (to 'miss') unless both x0 and x1 are smis.
3303 __ JumpIfEitherNotSmi(x0, x1, &miss);
3305 if (GetCondition() == eq) {
3306 // For equality we do not care about the sign of the result.
3309 // Untag before subtracting to avoid handling overflow.
3311 __ Sub(x0, x1, Operand::UntagSmi(x0));
3320 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3321 DCHECK(state() == CompareICState::NUMBER);
3322 ASM_LOCATION("CompareICStub[HeapNumbers]");
3324 Label unordered, maybe_undefined1, maybe_undefined2;
3325 Label miss, handle_lhs, values_in_d_regs;
3326 Label untag_rhs, untag_lhs;
3328 Register result = x0;
3331 FPRegister rhs_d = d0;
3332 FPRegister lhs_d = d1;
3334 if (left() == CompareICState::SMI) {
3335 __ JumpIfNotSmi(lhs, &miss);
3337 if (right() == CompareICState::SMI) {
3338 __ JumpIfNotSmi(rhs, &miss);
3341 __ SmiUntagToDouble(rhs_d, rhs, kSpeculativeUntag);
3342 __ SmiUntagToDouble(lhs_d, lhs, kSpeculativeUntag);
3344 // Load rhs if it's a heap number.
3345 __ JumpIfSmi(rhs, &handle_lhs);
3346 __ JumpIfNotHeapNumber(rhs, &maybe_undefined1);
3347 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
3349 // Load lhs if it's a heap number.
3350 __ Bind(&handle_lhs);
3351 __ JumpIfSmi(lhs, &values_in_d_regs);
3352 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3353 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
3355 __ Bind(&values_in_d_regs);
3356 __ Fcmp(lhs_d, rhs_d);
3357 __ B(vs, &unordered); // Overflow flag set if either is NaN.
3358 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
3359 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
3360 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
3363 __ Bind(&unordered);
3364 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3365 CompareICState::GENERIC, CompareICState::GENERIC);
3366 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3368 __ Bind(&maybe_undefined1);
3369 if (Token::IsOrderedRelationalCompareOp(op())) {
3370 __ JumpIfNotRoot(rhs, Heap::kUndefinedValueRootIndex, &miss);
3371 __ JumpIfSmi(lhs, &unordered);
3372 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3376 __ Bind(&maybe_undefined2);
3377 if (Token::IsOrderedRelationalCompareOp(op())) {
3378 __ JumpIfRoot(lhs, Heap::kUndefinedValueRootIndex, &unordered);
3386 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3387 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3388 ASM_LOCATION("CompareICStub[InternalizedStrings]");
3391 Register result = x0;
3395 // Check that both operands are heap objects.
3396 __ JumpIfEitherSmi(lhs, rhs, &miss);
3398 // Check that both operands are internalized strings.
3399 Register rhs_map = x10;
3400 Register lhs_map = x11;
3401 Register rhs_type = x10;
3402 Register lhs_type = x11;
3403 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3404 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3405 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3406 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3408 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
3409 __ Orr(x12, lhs_type, rhs_type);
3410 __ TestAndBranchIfAnySet(
3411 x12, kIsNotStringMask | kIsNotInternalizedMask, &miss);
3413 // Internalized strings are compared by identity.
3414 STATIC_ASSERT(EQUAL == 0);
3416 __ Cset(result, ne);
3424 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3425 DCHECK(state() == CompareICState::UNIQUE_NAME);
3426 ASM_LOCATION("CompareICStub[UniqueNames]");
3427 DCHECK(GetCondition() == eq);
3430 Register result = x0;
3434 Register lhs_instance_type = w2;
3435 Register rhs_instance_type = w3;
3437 // Check that both operands are heap objects.
3438 __ JumpIfEitherSmi(lhs, rhs, &miss);
3440 // Check that both operands are unique names. This leaves the instance
3441 // types loaded in tmp1 and tmp2.
3442 __ Ldr(x10, FieldMemOperand(lhs, HeapObject::kMapOffset));
3443 __ Ldr(x11, FieldMemOperand(rhs, HeapObject::kMapOffset));
3444 __ Ldrb(lhs_instance_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
3445 __ Ldrb(rhs_instance_type, FieldMemOperand(x11, Map::kInstanceTypeOffset));
3447 // To avoid a miss, each instance type should be either SYMBOL_TYPE or it
3448 // should have kInternalizedTag set.
3449 __ JumpIfNotUniqueNameInstanceType(lhs_instance_type, &miss);
3450 __ JumpIfNotUniqueNameInstanceType(rhs_instance_type, &miss);
3452 // Unique names are compared by identity.
3453 STATIC_ASSERT(EQUAL == 0);
3455 __ Cset(result, ne);
3463 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3464 DCHECK(state() == CompareICState::STRING);
3465 ASM_LOCATION("CompareICStub[Strings]");
3469 bool equality = Token::IsEqualityOp(op());
3471 Register result = x0;
3475 // Check that both operands are heap objects.
3476 __ JumpIfEitherSmi(rhs, lhs, &miss);
3478 // Check that both operands are strings.
3479 Register rhs_map = x10;
3480 Register lhs_map = x11;
3481 Register rhs_type = x10;
3482 Register lhs_type = x11;
3483 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3484 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3485 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3486 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3487 STATIC_ASSERT(kNotStringTag != 0);
3488 __ Orr(x12, lhs_type, rhs_type);
3489 __ Tbnz(x12, MaskToBit(kIsNotStringMask), &miss);
3491 // Fast check for identical strings.
3494 __ B(ne, ¬_equal);
3495 __ Mov(result, EQUAL);
3498 __ Bind(¬_equal);
3499 // Handle not identical strings
3501 // Check that both strings are internalized strings. If they are, we're done
3502 // because we already know they are not identical. We know they are both
3505 DCHECK(GetCondition() == eq);
3506 STATIC_ASSERT(kInternalizedTag == 0);
3507 Label not_internalized_strings;
3508 __ Orr(x12, lhs_type, rhs_type);
3509 __ TestAndBranchIfAnySet(
3510 x12, kIsNotInternalizedMask, ¬_internalized_strings);
3511 // Result is in rhs (x0), and not EQUAL, as rhs is not a smi.
3513 __ Bind(¬_internalized_strings);
3516 // Check that both strings are sequential one-byte.
3518 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x12,
3521 // Compare flat one-byte strings. Returns when done.
3523 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
3526 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
3530 // Handle more complex cases in runtime.
3534 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3536 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3544 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3545 DCHECK(state() == CompareICState::OBJECT);
3546 ASM_LOCATION("CompareICStub[Objects]");
3550 Register result = x0;
3554 __ JumpIfEitherSmi(rhs, lhs, &miss);
3556 __ JumpIfNotObjectType(rhs, x10, x10, JS_OBJECT_TYPE, &miss);
3557 __ JumpIfNotObjectType(lhs, x10, x10, JS_OBJECT_TYPE, &miss);
3559 DCHECK(GetCondition() == eq);
3560 __ Sub(result, rhs, lhs);
3568 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3569 ASM_LOCATION("CompareICStub[KnownObjects]");
3572 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3574 Register result = x0;
3578 __ JumpIfEitherSmi(rhs, lhs, &miss);
3580 Register rhs_map = x10;
3581 Register lhs_map = x11;
3583 __ GetWeakValue(map, cell);
3584 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3585 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3586 __ Cmp(rhs_map, map);
3588 __ Cmp(lhs_map, map);
3591 __ Sub(result, rhs, lhs);
3599 // This method handles the case where a compare stub had the wrong
3600 // implementation. It calls a miss handler, which re-writes the stub. All other
3601 // CompareICStub::Generate* methods should fall back into this one if their
3602 // operands were not the expected types.
3603 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3604 ASM_LOCATION("CompareICStub[Miss]");
3606 Register stub_entry = x11;
3608 FrameScope scope(masm, StackFrame::INTERNAL);
3611 Register right = x0;
3612 // Preserve some caller-saved registers.
3613 __ Push(x1, x0, lr);
3614 // Push the arguments.
3615 __ Mov(op, Smi::FromInt(this->op()));
3616 __ Push(left, right, op);
3618 // Call the miss handler. This also pops the arguments.
3619 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3621 // Compute the entry point of the rewritten stub.
3622 __ Add(stub_entry, x0, Code::kHeaderSize - kHeapObjectTag);
3623 // Restore caller-saved registers.
3627 // Tail-call to the new stub.
3628 __ Jump(stub_entry);
3632 void SubStringStub::Generate(MacroAssembler* masm) {
3633 ASM_LOCATION("SubStringStub::Generate");
3636 // Stack frame on entry.
3637 // lr: return address
3638 // jssp[0]: substring "to" offset
3639 // jssp[8]: substring "from" offset
3640 // jssp[16]: pointer to string object
3642 // This stub is called from the native-call %_SubString(...), so
3643 // nothing can be assumed about the arguments. It is tested that:
3644 // "string" is a sequential string,
3645 // both "from" and "to" are smis, and
3646 // 0 <= from <= to <= string.length (in debug mode.)
3647 // If any of these assumptions fail, we call the runtime system.
3649 static const int kToOffset = 0 * kPointerSize;
3650 static const int kFromOffset = 1 * kPointerSize;
3651 static const int kStringOffset = 2 * kPointerSize;
3654 Register from = x15;
3655 Register input_string = x10;
3656 Register input_length = x11;
3657 Register input_type = x12;
3658 Register result_string = x0;
3659 Register result_length = x1;
3662 __ Peek(to, kToOffset);
3663 __ Peek(from, kFromOffset);
3665 // Check that both from and to are smis. If not, jump to runtime.
3666 __ JumpIfEitherNotSmi(from, to, &runtime);
3670 // Calculate difference between from and to. If to < from, branch to runtime.
3671 __ Subs(result_length, to, from);
3674 // Check from is positive.
3675 __ Tbnz(from, kWSignBit, &runtime);
3677 // Make sure first argument is a string.
3678 __ Peek(input_string, kStringOffset);
3679 __ JumpIfSmi(input_string, &runtime);
3680 __ IsObjectJSStringType(input_string, input_type, &runtime);
3683 __ Cmp(result_length, 1);
3684 __ B(eq, &single_char);
3686 // Short-cut for the case of trivial substring.
3688 __ Ldrsw(input_length,
3689 UntagSmiFieldMemOperand(input_string, String::kLengthOffset));
3691 __ Cmp(result_length, input_length);
3692 __ CmovX(x0, input_string, eq);
3693 // Return original string.
3694 __ B(eq, &return_x0);
3696 // Longer than original string's length or negative: unsafe arguments.
3699 // Shorter than original string's length: an actual substring.
3701 // x0 to substring end character offset
3702 // x1 result_length length of substring result
3703 // x10 input_string pointer to input string object
3704 // x10 unpacked_string pointer to unpacked string object
3705 // x11 input_length length of input string
3706 // x12 input_type instance type of input string
3707 // x15 from substring start character offset
3709 // Deal with different string types: update the index if necessary and put
3710 // the underlying string into register unpacked_string.
3711 Label underlying_unpacked, sliced_string, seq_or_external_string;
3712 Label update_instance_type;
3713 // If the string is not indirect, it can only be sequential or external.
3714 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3715 STATIC_ASSERT(kIsIndirectStringMask != 0);
3717 // Test for string types, and branch/fall through to appropriate unpacking
3719 __ Tst(input_type, kIsIndirectStringMask);
3720 __ B(eq, &seq_or_external_string);
3721 __ Tst(input_type, kSlicedNotConsMask);
3722 __ B(ne, &sliced_string);
3724 Register unpacked_string = input_string;
3726 // Cons string. Check whether it is flat, then fetch first part.
3727 __ Ldr(temp, FieldMemOperand(input_string, ConsString::kSecondOffset));
3728 __ JumpIfNotRoot(temp, Heap::kempty_stringRootIndex, &runtime);
3729 __ Ldr(unpacked_string,
3730 FieldMemOperand(input_string, ConsString::kFirstOffset));
3731 __ B(&update_instance_type);
3733 __ Bind(&sliced_string);
3734 // Sliced string. Fetch parent and correct start index by offset.
3736 UntagSmiFieldMemOperand(input_string, SlicedString::kOffsetOffset));
3737 __ Add(from, from, temp);
3738 __ Ldr(unpacked_string,
3739 FieldMemOperand(input_string, SlicedString::kParentOffset));
3741 __ Bind(&update_instance_type);
3742 __ Ldr(temp, FieldMemOperand(unpacked_string, HeapObject::kMapOffset));
3743 __ Ldrb(input_type, FieldMemOperand(temp, Map::kInstanceTypeOffset));
3744 // Now control must go to &underlying_unpacked. Since the no code is generated
3745 // before then we fall through instead of generating a useless branch.
3747 __ Bind(&seq_or_external_string);
3748 // Sequential or external string. Registers unpacked_string and input_string
3749 // alias, so there's nothing to do here.
3750 // Note that if code is added here, the above code must be updated.
3752 // x0 result_string pointer to result string object (uninit)
3753 // x1 result_length length of substring result
3754 // x10 unpacked_string pointer to unpacked string object
3755 // x11 input_length length of input string
3756 // x12 input_type instance type of input string
3757 // x15 from substring start character offset
3758 __ Bind(&underlying_unpacked);
3760 if (FLAG_string_slices) {
3762 __ Cmp(result_length, SlicedString::kMinLength);
3763 // Short slice. Copy instead of slicing.
3764 __ B(lt, ©_routine);
3765 // Allocate new sliced string. At this point we do not reload the instance
3766 // type including the string encoding because we simply rely on the info
3767 // provided by the original string. It does not matter if the original
3768 // string's encoding is wrong because we always have to recheck encoding of
3769 // the newly created string's parent anyway due to externalized strings.
3770 Label two_byte_slice, set_slice_header;
3771 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3772 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3773 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_slice);
3774 __ AllocateOneByteSlicedString(result_string, result_length, x3, x4,
3776 __ B(&set_slice_header);
3778 __ Bind(&two_byte_slice);
3779 __ AllocateTwoByteSlicedString(result_string, result_length, x3, x4,
3782 __ Bind(&set_slice_header);
3784 __ Str(from, FieldMemOperand(result_string, SlicedString::kOffsetOffset));
3785 __ Str(unpacked_string,
3786 FieldMemOperand(result_string, SlicedString::kParentOffset));
3789 __ Bind(©_routine);
3792 // x0 result_string pointer to result string object (uninit)
3793 // x1 result_length length of substring result
3794 // x10 unpacked_string pointer to unpacked string object
3795 // x11 input_length length of input string
3796 // x12 input_type instance type of input string
3797 // x13 unpacked_char0 pointer to first char of unpacked string (uninit)
3798 // x13 substring_char0 pointer to first char of substring (uninit)
3799 // x14 result_char0 pointer to first char of result (uninit)
3800 // x15 from substring start character offset
3801 Register unpacked_char0 = x13;
3802 Register substring_char0 = x13;
3803 Register result_char0 = x14;
3804 Label two_byte_sequential, sequential_string, allocate_result;
3805 STATIC_ASSERT(kExternalStringTag != 0);
3806 STATIC_ASSERT(kSeqStringTag == 0);
3808 __ Tst(input_type, kExternalStringTag);
3809 __ B(eq, &sequential_string);
3811 __ Tst(input_type, kShortExternalStringTag);
3813 __ Ldr(unpacked_char0,
3814 FieldMemOperand(unpacked_string, ExternalString::kResourceDataOffset));
3815 // unpacked_char0 points to the first character of the underlying string.
3816 __ B(&allocate_result);
3818 __ Bind(&sequential_string);
3819 // Locate first character of underlying subject string.
3820 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3821 __ Add(unpacked_char0, unpacked_string,
3822 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3824 __ Bind(&allocate_result);
3825 // Sequential one-byte string. Allocate the result.
3826 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3827 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_sequential);
3829 // Allocate and copy the resulting one-byte string.
3830 __ AllocateOneByteString(result_string, result_length, x3, x4, x5, &runtime);
3832 // Locate first character of substring to copy.
3833 __ Add(substring_char0, unpacked_char0, from);
3835 // Locate first character of result.
3836 __ Add(result_char0, result_string,
3837 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3839 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3840 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3843 // Allocate and copy the resulting two-byte string.
3844 __ Bind(&two_byte_sequential);
3845 __ AllocateTwoByteString(result_string, result_length, x3, x4, x5, &runtime);
3847 // Locate first character of substring to copy.
3848 __ Add(substring_char0, unpacked_char0, Operand(from, LSL, 1));
3850 // Locate first character of result.
3851 __ Add(result_char0, result_string,
3852 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
3854 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3855 __ Add(result_length, result_length, result_length);
3856 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3858 __ Bind(&return_x0);
3859 Counters* counters = isolate()->counters();
3860 __ IncrementCounter(counters->sub_string_native(), 1, x3, x4);
3865 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3867 __ bind(&single_char);
3868 // x1: result_length
3869 // x10: input_string
3871 // x15: from (untagged)
3873 StringCharAtGenerator generator(input_string, from, result_length, x0,
3874 &runtime, &runtime, &runtime,
3875 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3876 generator.GenerateFast(masm);
3879 generator.SkipSlow(masm, &runtime);
3883 void ToNumberStub::Generate(MacroAssembler* masm) {
3884 // The ToNumber stub takes one argument in x0.
3886 __ JumpIfNotSmi(x0, ¬_smi);
3890 Label not_heap_number;
3891 __ Ldr(x1, FieldMemOperand(x0, HeapObject::kMapOffset));
3892 __ Ldrb(x1, FieldMemOperand(x1, Map::kInstanceTypeOffset));
3894 // x1: instance type
3895 __ Cmp(x1, HEAP_NUMBER_TYPE);
3896 __ B(ne, ¬_heap_number);
3898 __ Bind(¬_heap_number);
3900 Label not_string, slow_string;
3901 __ Cmp(x1, FIRST_NONSTRING_TYPE);
3902 __ B(hs, ¬_string);
3903 // Check if string has a cached array index.
3904 __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset));
3905 __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask));
3906 __ B(ne, &slow_string);
3907 __ IndexFromHash(x2, x0);
3909 __ Bind(&slow_string);
3910 __ Push(x0); // Push argument.
3911 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3912 __ Bind(¬_string);
3915 __ Cmp(x1, ODDBALL_TYPE);
3916 __ B(ne, ¬_oddball);
3917 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
3919 __ Bind(¬_oddball);
3921 __ Push(x0); // Push argument.
3922 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3926 void ToStringStub::Generate(MacroAssembler* masm) {
3927 // The ToString stub takes one argument in x0.
3929 __ JumpIfSmi(x0, &is_number);
3932 __ JumpIfObjectType(x0, x1, x1, FIRST_NONSTRING_TYPE, ¬_string, hs);
3934 // x1: receiver instance type
3936 __ Bind(¬_string);
3938 Label not_heap_number;
3939 __ Cmp(x1, HEAP_NUMBER_TYPE);
3940 __ B(ne, ¬_heap_number);
3941 __ Bind(&is_number);
3942 NumberToStringStub stub(isolate());
3943 __ TailCallStub(&stub);
3944 __ Bind(¬_heap_number);
3947 __ Cmp(x1, ODDBALL_TYPE);
3948 __ B(ne, ¬_oddball);
3949 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToStringOffset));
3951 __ Bind(¬_oddball);
3953 __ Push(x0); // Push argument.
3954 __ TailCallRuntime(Runtime::kToString, 1, 1);
3958 void StringHelper::GenerateFlatOneByteStringEquals(
3959 MacroAssembler* masm, Register left, Register right, Register scratch1,
3960 Register scratch2, Register scratch3) {
3961 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3));
3962 Register result = x0;
3963 Register left_length = scratch1;
3964 Register right_length = scratch2;
3966 // Compare lengths. If lengths differ, strings can't be equal. Lengths are
3967 // smis, and don't need to be untagged.
3968 Label strings_not_equal, check_zero_length;
3969 __ Ldr(left_length, FieldMemOperand(left, String::kLengthOffset));
3970 __ Ldr(right_length, FieldMemOperand(right, String::kLengthOffset));
3971 __ Cmp(left_length, right_length);
3972 __ B(eq, &check_zero_length);
3974 __ Bind(&strings_not_equal);
3975 __ Mov(result, Smi::FromInt(NOT_EQUAL));
3978 // Check if the length is zero. If so, the strings must be equal (and empty.)
3979 Label compare_chars;
3980 __ Bind(&check_zero_length);
3981 STATIC_ASSERT(kSmiTag == 0);
3982 __ Cbnz(left_length, &compare_chars);
3983 __ Mov(result, Smi::FromInt(EQUAL));
3986 // Compare characters. Falls through if all characters are equal.
3987 __ Bind(&compare_chars);
3988 GenerateOneByteCharsCompareLoop(masm, left, right, left_length, scratch2,
3989 scratch3, &strings_not_equal);
3991 // Characters in strings are equal.
3992 __ Mov(result, Smi::FromInt(EQUAL));
3997 void StringHelper::GenerateCompareFlatOneByteStrings(
3998 MacroAssembler* masm, Register left, Register right, Register scratch1,
3999 Register scratch2, Register scratch3, Register scratch4) {
4000 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3, scratch4));
4001 Label result_not_equal, compare_lengths;
4003 // Find minimum length and length difference.
4004 Register length_delta = scratch3;
4005 __ Ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
4006 __ Ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
4007 __ Subs(length_delta, scratch1, scratch2);
4009 Register min_length = scratch1;
4010 __ Csel(min_length, scratch2, scratch1, gt);
4011 __ Cbz(min_length, &compare_lengths);
4014 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
4015 scratch4, &result_not_equal);
4017 // Compare lengths - strings up to min-length are equal.
4018 __ Bind(&compare_lengths);
4020 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
4022 // Use length_delta as result if it's zero.
4023 Register result = x0;
4024 __ Subs(result, length_delta, 0);
4026 __ Bind(&result_not_equal);
4027 Register greater = x10;
4028 Register less = x11;
4029 __ Mov(greater, Smi::FromInt(GREATER));
4030 __ Mov(less, Smi::FromInt(LESS));
4031 __ CmovX(result, greater, gt);
4032 __ CmovX(result, less, lt);
4037 void StringHelper::GenerateOneByteCharsCompareLoop(
4038 MacroAssembler* masm, Register left, Register right, Register length,
4039 Register scratch1, Register scratch2, Label* chars_not_equal) {
4040 DCHECK(!AreAliased(left, right, length, scratch1, scratch2));
4042 // Change index to run from -length to -1 by adding length to string
4043 // start. This means that loop ends when index reaches zero, which
4044 // doesn't need an additional compare.
4045 __ SmiUntag(length);
4046 __ Add(scratch1, length, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4047 __ Add(left, left, scratch1);
4048 __ Add(right, right, scratch1);
4050 Register index = length;
4051 __ Neg(index, length); // index = -length;
4056 __ Ldrb(scratch1, MemOperand(left, index));
4057 __ Ldrb(scratch2, MemOperand(right, index));
4058 __ Cmp(scratch1, scratch2);
4059 __ B(ne, chars_not_equal);
4060 __ Add(index, index, 1);
4061 __ Cbnz(index, &loop);
4065 void StringCompareStub::Generate(MacroAssembler* masm) {
4068 Counters* counters = isolate()->counters();
4070 // Stack frame on entry.
4071 // sp[0]: right string
4072 // sp[8]: left string
4073 Register right = x10;
4074 Register left = x11;
4075 Register result = x0;
4076 __ Pop(right, left);
4079 __ Subs(result, right, left);
4080 __ B(ne, ¬_same);
4081 STATIC_ASSERT(EQUAL == 0);
4082 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4087 // Check that both objects are sequential one-byte strings.
4088 __ JumpIfEitherIsNotSequentialOneByteStrings(left, right, x12, x13, &runtime);
4090 // Compare flat one-byte strings natively. Remove arguments from stack first,
4091 // as this function will generate a return.
4092 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4093 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, x12, x13,
4098 // Push arguments back on to the stack.
4099 // sp[0] = right string
4100 // sp[8] = left string.
4101 __ Push(left, right);
4103 // Call the runtime.
4104 // Returns -1 (less), 0 (equal), or 1 (greater) tagged as a small integer.
4105 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
4109 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4110 // ----------- S t a t e -------------
4113 // -- lr : return address
4114 // -----------------------------------
4116 // Load x2 with the allocation site. We stick an undefined dummy value here
4117 // and replace it with the real allocation site later when we instantiate this
4118 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
4119 __ LoadObject(x2, handle(isolate()->heap()->undefined_value()));
4121 // Make sure that we actually patched the allocation site.
4122 if (FLAG_debug_code) {
4123 __ AssertNotSmi(x2, kExpectedAllocationSite);
4124 __ Ldr(x10, FieldMemOperand(x2, HeapObject::kMapOffset));
4125 __ AssertRegisterIsRoot(x10, Heap::kAllocationSiteMapRootIndex,
4126 kExpectedAllocationSite);
4129 // Tail call into the stub that handles binary operations with allocation
4131 BinaryOpWithAllocationSiteStub stub(isolate(), state());
4132 __ TailCallStub(&stub);
4136 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4137 // We need some extra registers for this stub, they have been allocated
4138 // but we need to save them before using them.
4141 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4142 Label dont_need_remembered_set;
4144 Register val = regs_.scratch0();
4145 __ Ldr(val, MemOperand(regs_.address()));
4146 __ JumpIfNotInNewSpace(val, &dont_need_remembered_set);
4148 __ CheckPageFlagSet(regs_.object(), val, 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4149 &dont_need_remembered_set);
4151 // First notify the incremental marker if necessary, then update the
4153 CheckNeedsToInformIncrementalMarker(
4154 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4155 InformIncrementalMarker(masm);
4156 regs_.Restore(masm); // Restore the extra scratch registers we used.
4158 __ RememberedSetHelper(object(), address(),
4159 value(), // scratch1
4160 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4162 __ Bind(&dont_need_remembered_set);
4165 CheckNeedsToInformIncrementalMarker(
4166 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4167 InformIncrementalMarker(masm);
4168 regs_.Restore(masm); // Restore the extra scratch registers we used.
4173 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4174 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4176 x0.Is(regs_.address()) ? regs_.scratch0() : regs_.address();
4177 DCHECK(!address.Is(regs_.object()));
4178 DCHECK(!address.Is(x0));
4179 __ Mov(address, regs_.address());
4180 __ Mov(x0, regs_.object());
4181 __ Mov(x1, address);
4182 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4184 AllowExternalCallThatCantCauseGC scope(masm);
4185 ExternalReference function =
4186 ExternalReference::incremental_marking_record_write_function(
4188 __ CallCFunction(function, 3, 0);
4190 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4194 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4195 MacroAssembler* masm,
4196 OnNoNeedToInformIncrementalMarker on_no_need,
4199 Label need_incremental;
4200 Label need_incremental_pop_scratch;
4202 Register mem_chunk = regs_.scratch0();
4203 Register counter = regs_.scratch1();
4204 __ Bic(mem_chunk, regs_.object(), Page::kPageAlignmentMask);
4206 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4207 __ Subs(counter, counter, 1);
4209 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4210 __ B(mi, &need_incremental);
4212 // If the object is not black we don't have to inform the incremental marker.
4213 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4215 regs_.Restore(masm); // Restore the extra scratch registers we used.
4216 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4217 __ RememberedSetHelper(object(), address(),
4218 value(), // scratch1
4219 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4225 // Get the value from the slot.
4226 Register val = regs_.scratch0();
4227 __ Ldr(val, MemOperand(regs_.address()));
4229 if (mode == INCREMENTAL_COMPACTION) {
4230 Label ensure_not_white;
4232 __ CheckPageFlagClear(val, regs_.scratch1(),
4233 MemoryChunk::kEvacuationCandidateMask,
4236 __ CheckPageFlagClear(regs_.object(),
4238 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4241 __ Bind(&ensure_not_white);
4244 // We need extra registers for this, so we push the object and the address
4245 // register temporarily.
4246 __ Push(regs_.address(), regs_.object());
4247 __ EnsureNotWhite(val,
4248 regs_.scratch1(), // Scratch.
4249 regs_.object(), // Scratch.
4250 regs_.address(), // Scratch.
4251 regs_.scratch2(), // Scratch.
4252 &need_incremental_pop_scratch);
4253 __ Pop(regs_.object(), regs_.address());
4255 regs_.Restore(masm); // Restore the extra scratch registers we used.
4256 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4257 __ RememberedSetHelper(object(), address(),
4258 value(), // scratch1
4259 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4264 __ Bind(&need_incremental_pop_scratch);
4265 __ Pop(regs_.object(), regs_.address());
4267 __ Bind(&need_incremental);
4268 // Fall through when we need to inform the incremental marker.
4272 void RecordWriteStub::Generate(MacroAssembler* masm) {
4273 Label skip_to_incremental_noncompacting;
4274 Label skip_to_incremental_compacting;
4276 // We patch these two first instructions back and forth between a nop and
4277 // real branch when we start and stop incremental heap marking.
4278 // Initially the stub is expected to be in STORE_BUFFER_ONLY mode, so 2 nops
4280 // See RecordWriteStub::Patch for details.
4282 InstructionAccurateScope scope(masm, 2);
4283 __ adr(xzr, &skip_to_incremental_noncompacting);
4284 __ adr(xzr, &skip_to_incremental_compacting);
4287 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4288 __ RememberedSetHelper(object(), address(),
4289 value(), // scratch1
4290 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4294 __ Bind(&skip_to_incremental_noncompacting);
4295 GenerateIncremental(masm, INCREMENTAL);
4297 __ Bind(&skip_to_incremental_compacting);
4298 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4302 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4303 // x0 value element value to store
4304 // x3 index_smi element index as smi
4305 // sp[0] array_index_smi array literal index in function as smi
4306 // sp[1] array array literal
4308 Register value = x0;
4309 Register index_smi = x3;
4311 Register array = x1;
4312 Register array_map = x2;
4313 Register array_index_smi = x4;
4314 __ PeekPair(array_index_smi, array, 0);
4315 __ Ldr(array_map, FieldMemOperand(array, JSObject::kMapOffset));
4317 Label double_elements, smi_element, fast_elements, slow_elements;
4318 Register bitfield2 = x10;
4319 __ Ldrb(bitfield2, FieldMemOperand(array_map, Map::kBitField2Offset));
4321 // Jump if array's ElementsKind is not FAST*_SMI_ELEMENTS, FAST_ELEMENTS or
4322 // FAST_HOLEY_ELEMENTS.
4323 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4324 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4325 STATIC_ASSERT(FAST_ELEMENTS == 2);
4326 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4327 __ Cmp(bitfield2, Map::kMaximumBitField2FastHoleyElementValue);
4328 __ B(hi, &double_elements);
4330 __ JumpIfSmi(value, &smi_element);
4332 // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS.
4333 __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::ElementsKindBits::kShift),
4336 // Store into the array literal requires an elements transition. Call into
4338 __ Bind(&slow_elements);
4339 __ Push(array, index_smi, value);
4340 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4341 __ Ldr(x11, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
4342 __ Push(x11, array_index_smi);
4343 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4345 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4346 __ Bind(&fast_elements);
4347 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4348 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4349 __ Add(x11, x11, FixedArray::kHeaderSize - kHeapObjectTag);
4350 __ Str(value, MemOperand(x11));
4351 // Update the write barrier for the array store.
4352 __ RecordWrite(x10, x11, value, kLRHasNotBeenSaved, kDontSaveFPRegs,
4353 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4356 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4357 // and value is Smi.
4358 __ Bind(&smi_element);
4359 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4360 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4361 __ Str(value, FieldMemOperand(x11, FixedArray::kHeaderSize));
4364 __ Bind(&double_elements);
4365 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4366 __ StoreNumberToDoubleElements(value, index_smi, x10, x11, d0,
4372 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4373 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4374 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4375 int parameter_count_offset =
4376 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4377 __ Ldr(x1, MemOperand(fp, parameter_count_offset));
4378 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4381 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4383 // Return to IC Miss stub, continuation still on stack.
4388 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4389 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4390 LoadICStub stub(isolate(), state());
4391 stub.GenerateForTrampoline(masm);
4395 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4396 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4397 KeyedLoadICStub stub(isolate(), state());
4398 stub.GenerateForTrampoline(masm);
4402 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4403 EmitLoadTypeFeedbackVector(masm, x2);
4404 CallICStub stub(isolate(), state());
4405 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4409 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4410 EmitLoadTypeFeedbackVector(masm, x2);
4411 CallIC_ArrayStub stub(isolate(), state());
4412 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4416 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4419 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4420 GenerateImpl(masm, true);
4424 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4425 Register receiver_map, Register scratch1,
4426 Register scratch2, bool is_polymorphic,
4428 // feedback initially contains the feedback array
4429 Label next_loop, prepare_next;
4430 Label load_smi_map, compare_map;
4431 Label start_polymorphic;
4433 Register cached_map = scratch1;
4436 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4437 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4438 __ Cmp(receiver_map, cached_map);
4439 __ B(ne, &start_polymorphic);
4440 // found, now call handler.
4441 Register handler = feedback;
4442 __ Ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4443 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4446 Register length = scratch2;
4447 __ Bind(&start_polymorphic);
4448 __ Ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4449 if (!is_polymorphic) {
4450 __ Cmp(length, Operand(Smi::FromInt(2)));
4454 Register too_far = length;
4455 Register pointer_reg = feedback;
4457 // +-----+------+------+-----+-----+ ... ----+
4458 // | map | len | wm0 | h0 | wm1 | hN |
4459 // +-----+------+------+-----+-----+ ... ----+
4463 // pointer_reg too_far
4464 // aka feedback scratch2
4465 // also need receiver_map
4466 // use cached_map (scratch1) to look in the weak map values.
4467 __ Add(too_far, feedback,
4468 Operand::UntagSmiAndScale(length, kPointerSizeLog2));
4469 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
4470 __ Add(pointer_reg, feedback,
4471 FixedArray::OffsetOfElementAt(2) - kHeapObjectTag);
4473 __ Bind(&next_loop);
4474 __ Ldr(cached_map, MemOperand(pointer_reg));
4475 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4476 __ Cmp(receiver_map, cached_map);
4477 __ B(ne, &prepare_next);
4478 __ Ldr(handler, MemOperand(pointer_reg, kPointerSize));
4479 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4482 __ Bind(&prepare_next);
4483 __ Add(pointer_reg, pointer_reg, kPointerSize * 2);
4484 __ Cmp(pointer_reg, too_far);
4485 __ B(lt, &next_loop);
4487 // We exhausted our array of map handler pairs.
4492 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4493 Register receiver_map, Register feedback,
4494 Register vector, Register slot,
4495 Register scratch, Label* compare_map,
4496 Label* load_smi_map, Label* try_array) {
4497 __ JumpIfSmi(receiver, load_smi_map);
4498 __ Ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4499 __ bind(compare_map);
4500 Register cached_map = scratch;
4501 // Move the weak map into the weak_cell register.
4502 __ Ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4503 __ Cmp(cached_map, receiver_map);
4504 __ B(ne, try_array);
4506 Register handler = feedback;
4507 __ Add(handler, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4509 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4510 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4515 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4516 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4517 Register name = LoadWithVectorDescriptor::NameRegister(); // x2
4518 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4519 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4520 Register feedback = x4;
4521 Register receiver_map = x5;
4522 Register scratch1 = x6;
4524 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4525 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4527 // Try to quickly handle the monomorphic case without knowing for sure
4528 // if we have a weak cell in feedback. We do know it's safe to look
4529 // at WeakCell::kValueOffset.
4530 Label try_array, load_smi_map, compare_map;
4531 Label not_array, miss;
4532 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4533 scratch1, &compare_map, &load_smi_map, &try_array);
4535 // Is it a fixed array?
4536 __ Bind(&try_array);
4537 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4538 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4539 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, true, &miss);
4541 __ Bind(¬_array);
4542 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
4543 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4544 Code::ComputeHandlerFlags(Code::LOAD_IC));
4545 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4546 receiver, name, feedback,
4547 receiver_map, scratch1, x7);
4550 LoadIC::GenerateMiss(masm);
4552 __ Bind(&load_smi_map);
4553 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4554 __ jmp(&compare_map);
4558 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4559 GenerateImpl(masm, false);
4563 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4564 GenerateImpl(masm, true);
4568 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4569 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4570 Register key = LoadWithVectorDescriptor::NameRegister(); // x2
4571 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4572 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4573 Register feedback = x4;
4574 Register receiver_map = x5;
4575 Register scratch1 = x6;
4577 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4578 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4580 // Try to quickly handle the monomorphic case without knowing for sure
4581 // if we have a weak cell in feedback. We do know it's safe to look
4582 // at WeakCell::kValueOffset.
4583 Label try_array, load_smi_map, compare_map;
4584 Label not_array, miss;
4585 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4586 scratch1, &compare_map, &load_smi_map, &try_array);
4588 __ Bind(&try_array);
4589 // Is it a fixed array?
4590 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4591 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4593 // We have a polymorphic element handler.
4594 Label polymorphic, try_poly_name;
4595 __ Bind(&polymorphic);
4596 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, true, &miss);
4598 __ Bind(¬_array);
4600 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
4602 Handle<Code> megamorphic_stub =
4603 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4604 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4606 __ Bind(&try_poly_name);
4607 // We might have a name in feedback, and a fixed array in the next slot.
4608 __ Cmp(key, feedback);
4610 // If the name comparison succeeded, we know we have a fixed array with
4611 // at least one map/handler pair.
4612 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4614 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4615 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, false, &miss);
4618 KeyedLoadIC::GenerateMiss(masm);
4620 __ Bind(&load_smi_map);
4621 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4622 __ jmp(&compare_map);
4626 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4627 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4628 VectorStoreICStub stub(isolate(), state());
4629 stub.GenerateForTrampoline(masm);
4633 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4634 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4635 VectorKeyedStoreICStub stub(isolate(), state());
4636 stub.GenerateForTrampoline(masm);
4640 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4641 GenerateImpl(masm, false);
4645 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4646 GenerateImpl(masm, true);
4650 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4651 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // x1
4652 Register key = VectorStoreICDescriptor::NameRegister(); // x2
4653 Register vector = VectorStoreICDescriptor::VectorRegister(); // x3
4654 Register slot = VectorStoreICDescriptor::SlotRegister(); // x4
4655 DCHECK(VectorStoreICDescriptor::ValueRegister().is(x0)); // x0
4656 Register feedback = x5;
4657 Register receiver_map = x6;
4658 Register scratch1 = x7;
4660 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4661 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4663 // Try to quickly handle the monomorphic case without knowing for sure
4664 // if we have a weak cell in feedback. We do know it's safe to look
4665 // at WeakCell::kValueOffset.
4666 Label try_array, load_smi_map, compare_map;
4667 Label not_array, miss;
4668 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4669 scratch1, &compare_map, &load_smi_map, &try_array);
4671 // Is it a fixed array?
4672 __ Bind(&try_array);
4673 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4674 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4675 HandleArrayCases(masm, feedback, receiver_map, scratch1, x8, true, &miss);
4677 __ Bind(¬_array);
4678 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
4679 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4680 Code::ComputeHandlerFlags(Code::STORE_IC));
4681 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags,
4682 receiver, key, feedback,
4683 receiver_map, scratch1, x8);
4686 StoreIC::GenerateMiss(masm);
4688 __ Bind(&load_smi_map);
4689 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4690 __ jmp(&compare_map);
4694 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4695 GenerateImpl(masm, false);
4699 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4700 GenerateImpl(masm, true);
4704 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4705 Register receiver_map, Register scratch1,
4706 Register scratch2, Label* miss) {
4707 // feedback initially contains the feedback array
4708 Label next_loop, prepare_next;
4709 Label start_polymorphic;
4710 Label transition_call;
4712 Register cached_map = scratch1;
4713 Register too_far = scratch2;
4714 Register pointer_reg = feedback;
4716 __ Ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4718 // +-----+------+------+-----+-----+-----+ ... ----+
4719 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4720 // +-----+------+------+-----+-----+ ----+ ... ----+
4724 // pointer_reg too_far
4725 // aka feedback scratch2
4726 // also need receiver_map
4727 // use cached_map (scratch1) to look in the weak map values.
4728 __ Add(too_far, feedback,
4729 Operand::UntagSmiAndScale(too_far, kPointerSizeLog2));
4730 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
4731 __ Add(pointer_reg, feedback,
4732 FixedArray::OffsetOfElementAt(0) - kHeapObjectTag);
4734 __ Bind(&next_loop);
4735 __ Ldr(cached_map, MemOperand(pointer_reg));
4736 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4737 __ Cmp(receiver_map, cached_map);
4738 __ B(ne, &prepare_next);
4739 // Is it a transitioning store?
4740 __ Ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4741 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4742 __ B(ne, &transition_call);
4744 __ Ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4745 __ Add(pointer_reg, pointer_reg, Code::kHeaderSize - kHeapObjectTag);
4746 __ Jump(pointer_reg);
4748 __ Bind(&transition_call);
4749 __ Ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4750 __ JumpIfSmi(too_far, miss);
4752 __ Ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4753 // Load the map into the correct register.
4754 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4755 __ mov(feedback, too_far);
4756 __ Add(receiver_map, receiver_map, Code::kHeaderSize - kHeapObjectTag);
4757 __ Jump(receiver_map);
4759 __ Bind(&prepare_next);
4760 __ Add(pointer_reg, pointer_reg, kPointerSize * 3);
4761 __ Cmp(pointer_reg, too_far);
4762 __ B(lt, &next_loop);
4764 // We exhausted our array of map handler pairs.
4769 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4770 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // x1
4771 Register key = VectorStoreICDescriptor::NameRegister(); // x2
4772 Register vector = VectorStoreICDescriptor::VectorRegister(); // x3
4773 Register slot = VectorStoreICDescriptor::SlotRegister(); // x4
4774 DCHECK(VectorStoreICDescriptor::ValueRegister().is(x0)); // x0
4775 Register feedback = x5;
4776 Register receiver_map = x6;
4777 Register scratch1 = x7;
4779 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4780 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4782 // Try to quickly handle the monomorphic case without knowing for sure
4783 // if we have a weak cell in feedback. We do know it's safe to look
4784 // at WeakCell::kValueOffset.
4785 Label try_array, load_smi_map, compare_map;
4786 Label not_array, miss;
4787 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4788 scratch1, &compare_map, &load_smi_map, &try_array);
4790 __ Bind(&try_array);
4791 // Is it a fixed array?
4792 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4793 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4795 // We have a polymorphic element handler.
4796 Label try_poly_name;
4797 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, x8, &miss);
4799 __ Bind(¬_array);
4801 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
4803 Handle<Code> megamorphic_stub =
4804 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4805 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4807 __ Bind(&try_poly_name);
4808 // We might have a name in feedback, and a fixed array in the next slot.
4809 __ Cmp(key, feedback);
4811 // If the name comparison succeeded, we know we have a fixed array with
4812 // at least one map/handler pair.
4813 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4815 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4816 HandleArrayCases(masm, feedback, receiver_map, scratch1, x8, false, &miss);
4819 KeyedStoreIC::GenerateMiss(masm);
4821 __ Bind(&load_smi_map);
4822 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4823 __ jmp(&compare_map);
4827 // The entry hook is a "BumpSystemStackPointer" instruction (sub), followed by
4828 // a "Push lr" instruction, followed by a call.
4829 static const unsigned int kProfileEntryHookCallSize =
4830 Assembler::kCallSizeWithRelocation + (2 * kInstructionSize);
4833 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4834 if (masm->isolate()->function_entry_hook() != NULL) {
4835 ProfileEntryHookStub stub(masm->isolate());
4836 Assembler::BlockConstPoolScope no_const_pools(masm);
4837 DontEmitDebugCodeScope no_debug_code(masm);
4838 Label entry_hook_call_start;
4839 __ Bind(&entry_hook_call_start);
4842 DCHECK(masm->SizeOfCodeGeneratedSince(&entry_hook_call_start) ==
4843 kProfileEntryHookCallSize);
4850 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4851 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
4853 // Save all kCallerSaved registers (including lr), since this can be called
4855 // TODO(jbramley): What about FP registers?
4856 __ PushCPURegList(kCallerSaved);
4857 DCHECK(kCallerSaved.IncludesAliasOf(lr));
4858 const int kNumSavedRegs = kCallerSaved.Count();
4860 // Compute the function's address as the first argument.
4861 __ Sub(x0, lr, kProfileEntryHookCallSize);
4863 #if V8_HOST_ARCH_ARM64
4864 uintptr_t entry_hook =
4865 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
4866 __ Mov(x10, entry_hook);
4868 // Under the simulator we need to indirect the entry hook through a trampoline
4869 // function at a known address.
4870 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4871 __ Mov(x10, Operand(ExternalReference(&dispatcher,
4872 ExternalReference::BUILTIN_CALL,
4874 // It additionally takes an isolate as a third parameter
4875 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4878 // The caller's return address is above the saved temporaries.
4879 // Grab its location for the second argument to the hook.
4880 __ Add(x1, __ StackPointer(), kNumSavedRegs * kPointerSize);
4883 // Create a dummy frame, as CallCFunction requires this.
4884 FrameScope frame(masm, StackFrame::MANUAL);
4885 __ CallCFunction(x10, 2, 0);
4888 __ PopCPURegList(kCallerSaved);
4893 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4894 // When calling into C++ code the stack pointer must be csp.
4895 // Therefore this code must use csp for peek/poke operations when the
4896 // stub is generated. When the stub is called
4897 // (via DirectCEntryStub::GenerateCall), the caller must setup an ExitFrame
4898 // and configure the stack pointer *before* doing the call.
4899 const Register old_stack_pointer = __ StackPointer();
4900 __ SetStackPointer(csp);
4902 // Put return address on the stack (accessible to GC through exit frame pc).
4904 // Call the C++ function.
4906 // Return to calling code.
4908 __ AssertFPCRState();
4911 __ SetStackPointer(old_stack_pointer);
4914 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4916 // Make sure the caller configured the stack pointer (see comment in
4917 // DirectCEntryStub::Generate).
4918 DCHECK(csp.Is(__ StackPointer()));
4921 reinterpret_cast<intptr_t>(GetCode().location());
4922 __ Mov(lr, Operand(code, RelocInfo::CODE_TARGET));
4923 __ Mov(x10, target);
4924 // Branch to the stub.
4929 // Probe the name dictionary in the 'elements' register.
4930 // Jump to the 'done' label if a property with the given name is found.
4931 // Jump to the 'miss' label otherwise.
4933 // If lookup was successful 'scratch2' will be equal to elements + 4 * index.
4934 // 'elements' and 'name' registers are preserved on miss.
4935 void NameDictionaryLookupStub::GeneratePositiveLookup(
4936 MacroAssembler* masm,
4942 Register scratch2) {
4943 DCHECK(!AreAliased(elements, name, scratch1, scratch2));
4945 // Assert that name contains a string.
4946 __ AssertName(name);
4948 // Compute the capacity mask.
4949 __ Ldrsw(scratch1, UntagSmiFieldMemOperand(elements, kCapacityOffset));
4950 __ Sub(scratch1, scratch1, 1);
4952 // Generate an unrolled loop that performs a few probes before giving up.
4953 for (int i = 0; i < kInlinedProbes; i++) {
4954 // Compute the masked index: (hash + i + i * i) & mask.
4955 __ Ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4957 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4958 // the hash in a separate instruction. The value hash + i + i * i is right
4959 // shifted in the following and instruction.
4960 DCHECK(NameDictionary::GetProbeOffset(i) <
4961 1 << (32 - Name::kHashFieldOffset));
4962 __ Add(scratch2, scratch2, Operand(
4963 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4965 __ And(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
4967 // Scale the index by multiplying by the element size.
4968 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4969 __ Add(scratch2, scratch2, Operand(scratch2, LSL, 1));
4971 // Check if the key is identical to the name.
4972 UseScratchRegisterScope temps(masm);
4973 Register scratch3 = temps.AcquireX();
4974 __ Add(scratch2, elements, Operand(scratch2, LSL, kPointerSizeLog2));
4975 __ Ldr(scratch3, FieldMemOperand(scratch2, kElementsStartOffset));
4976 __ Cmp(name, scratch3);
4980 // The inlined probes didn't find the entry.
4981 // Call the complete stub to scan the whole dictionary.
4983 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4984 spill_list.Combine(lr);
4985 spill_list.Remove(scratch1);
4986 spill_list.Remove(scratch2);
4988 __ PushCPURegList(spill_list);
4991 DCHECK(!elements.is(x1));
4993 __ Mov(x0, elements);
4995 __ Mov(x0, elements);
5000 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
5002 __ Cbz(x0, ¬_found);
5003 __ Mov(scratch2, x2); // Move entry index into scratch2.
5004 __ PopCPURegList(spill_list);
5007 __ Bind(¬_found);
5008 __ PopCPURegList(spill_list);
5013 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
5017 Register properties,
5019 Register scratch0) {
5020 DCHECK(!AreAliased(receiver, properties, scratch0));
5021 DCHECK(name->IsUniqueName());
5022 // If names of slots in range from 1 to kProbes - 1 for the hash value are
5023 // not equal to the name and kProbes-th slot is not used (its name is the
5024 // undefined value), it guarantees the hash table doesn't contain the
5025 // property. It's true even if some slots represent deleted properties
5026 // (their names are the hole value).
5027 for (int i = 0; i < kInlinedProbes; i++) {
5028 // scratch0 points to properties hash.
5029 // Compute the masked index: (hash + i + i * i) & mask.
5030 Register index = scratch0;
5031 // Capacity is smi 2^n.
5032 __ Ldrsw(index, UntagSmiFieldMemOperand(properties, kCapacityOffset));
5033 __ Sub(index, index, 1);
5034 __ And(index, index, name->Hash() + NameDictionary::GetProbeOffset(i));
5036 // Scale the index by multiplying by the entry size.
5037 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
5038 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5040 Register entity_name = scratch0;
5041 // Having undefined at this place means the name is not contained.
5042 Register tmp = index;
5043 __ Add(tmp, properties, Operand(index, LSL, kPointerSizeLog2));
5044 __ Ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
5046 __ JumpIfRoot(entity_name, Heap::kUndefinedValueRootIndex, done);
5048 // Stop if found the property.
5049 __ Cmp(entity_name, Operand(name));
5053 __ JumpIfRoot(entity_name, Heap::kTheHoleValueRootIndex, &good);
5055 // Check if the entry name is not a unique name.
5056 __ Ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
5057 __ Ldrb(entity_name,
5058 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
5059 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
5063 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
5064 spill_list.Combine(lr);
5065 spill_list.Remove(scratch0); // Scratch registers don't need to be preserved.
5067 __ PushCPURegList(spill_list);
5069 __ Ldr(x0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
5070 __ Mov(x1, Operand(name));
5071 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
5073 // Move stub return value to scratch0. Note that scratch0 is not included in
5074 // spill_list and won't be clobbered by PopCPURegList.
5075 __ Mov(scratch0, x0);
5076 __ PopCPURegList(spill_list);
5078 __ Cbz(scratch0, done);
5083 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
5084 // This stub overrides SometimesSetsUpAFrame() to return false. That means
5085 // we cannot call anything that could cause a GC from this stub.
5087 // Arguments are in x0 and x1:
5088 // x0: property dictionary.
5089 // x1: the name of the property we are looking for.
5091 // Return value is in x0 and is zero if lookup failed, non zero otherwise.
5092 // If the lookup is successful, x2 will contains the index of the entry.
5094 Register result = x0;
5095 Register dictionary = x0;
5097 Register index = x2;
5100 Register undefined = x5;
5101 Register entry_key = x6;
5103 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
5105 __ Ldrsw(mask, UntagSmiFieldMemOperand(dictionary, kCapacityOffset));
5106 __ Sub(mask, mask, 1);
5108 __ Ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
5109 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
5111 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
5112 // Compute the masked index: (hash + i + i * i) & mask.
5113 // Capacity is smi 2^n.
5115 // Add the probe offset (i + i * i) left shifted to avoid right shifting
5116 // the hash in a separate instruction. The value hash + i + i * i is right
5117 // shifted in the following and instruction.
5118 DCHECK(NameDictionary::GetProbeOffset(i) <
5119 1 << (32 - Name::kHashFieldOffset));
5121 NameDictionary::GetProbeOffset(i) << Name::kHashShift);
5123 __ Mov(index, hash);
5125 __ And(index, mask, Operand(index, LSR, Name::kHashShift));
5127 // Scale the index by multiplying by the entry size.
5128 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
5129 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5131 __ Add(index, dictionary, Operand(index, LSL, kPointerSizeLog2));
5132 __ Ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
5134 // Having undefined at this place means the name is not contained.
5135 __ Cmp(entry_key, undefined);
5136 __ B(eq, ¬_in_dictionary);
5138 // Stop if found the property.
5139 __ Cmp(entry_key, key);
5140 __ B(eq, &in_dictionary);
5142 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
5143 // Check if the entry name is not a unique name.
5144 __ Ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
5145 __ Ldrb(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
5146 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
5150 __ Bind(&maybe_in_dictionary);
5151 // If we are doing negative lookup then probing failure should be
5152 // treated as a lookup success. For positive lookup, probing failure
5153 // should be treated as lookup failure.
5154 if (mode() == POSITIVE_LOOKUP) {
5159 __ Bind(&in_dictionary);
5163 __ Bind(¬_in_dictionary);
5170 static void CreateArrayDispatch(MacroAssembler* masm,
5171 AllocationSiteOverrideMode mode) {
5172 ASM_LOCATION("CreateArrayDispatch");
5173 if (mode == DISABLE_ALLOCATION_SITES) {
5174 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5175 __ TailCallStub(&stub);
5177 } else if (mode == DONT_OVERRIDE) {
5180 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5181 for (int i = 0; i <= last_index; ++i) {
5183 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5184 // TODO(jbramley): Is this the best way to handle this? Can we make the
5185 // tail calls conditional, rather than hopping over each one?
5186 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5187 T stub(masm->isolate(), candidate_kind);
5188 __ TailCallStub(&stub);
5192 // If we reached this point there is a problem.
5193 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5201 // TODO(jbramley): If this needs to be a special case, make it a proper template
5202 // specialization, and not a separate function.
5203 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5204 AllocationSiteOverrideMode mode) {
5205 ASM_LOCATION("CreateArrayDispatchOneArgument");
5207 // x1 - constructor?
5208 // x2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5209 // x3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5210 // sp[0] - last argument
5212 Register allocation_site = x2;
5215 Label normal_sequence;
5216 if (mode == DONT_OVERRIDE) {
5217 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5218 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5219 STATIC_ASSERT(FAST_ELEMENTS == 2);
5220 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5221 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5222 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5224 // Is the low bit set? If so, the array is holey.
5225 __ Tbnz(kind, 0, &normal_sequence);
5228 // Look at the last argument.
5229 // TODO(jbramley): What does a 0 argument represent?
5231 __ Cbz(x10, &normal_sequence);
5233 if (mode == DISABLE_ALLOCATION_SITES) {
5234 ElementsKind initial = GetInitialFastElementsKind();
5235 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5237 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5239 DISABLE_ALLOCATION_SITES);
5240 __ TailCallStub(&stub_holey);
5242 __ Bind(&normal_sequence);
5243 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5245 DISABLE_ALLOCATION_SITES);
5246 __ TailCallStub(&stub);
5247 } else if (mode == DONT_OVERRIDE) {
5248 // We are going to create a holey array, but our kind is non-holey.
5249 // Fix kind and retry (only if we have an allocation site in the slot).
5250 __ Orr(kind, kind, 1);
5252 if (FLAG_debug_code) {
5253 __ Ldr(x10, FieldMemOperand(allocation_site, 0));
5254 __ JumpIfNotRoot(x10, Heap::kAllocationSiteMapRootIndex,
5256 __ Assert(eq, kExpectedAllocationSite);
5259 // Save the resulting elements kind in type info. We can't just store 'kind'
5260 // in the AllocationSite::transition_info field because elements kind is
5261 // restricted to a portion of the field; upper bits need to be left alone.
5262 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5263 __ Ldr(x11, FieldMemOperand(allocation_site,
5264 AllocationSite::kTransitionInfoOffset));
5265 __ Add(x11, x11, Smi::FromInt(kFastElementsKindPackedToHoley));
5266 __ Str(x11, FieldMemOperand(allocation_site,
5267 AllocationSite::kTransitionInfoOffset));
5269 __ Bind(&normal_sequence);
5271 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5272 for (int i = 0; i <= last_index; ++i) {
5274 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5275 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5276 ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind);
5277 __ TailCallStub(&stub);
5281 // If we reached this point there is a problem.
5282 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5290 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5291 int to_index = GetSequenceIndexFromFastElementsKind(
5292 TERMINAL_FAST_ELEMENTS_KIND);
5293 for (int i = 0; i <= to_index; ++i) {
5294 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5295 T stub(isolate, kind);
5297 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5298 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5305 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5306 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5308 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5310 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5315 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5317 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5318 for (int i = 0; i < 2; i++) {
5319 // For internal arrays we only need a few things
5320 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5322 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5324 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5330 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5331 MacroAssembler* masm,
5332 AllocationSiteOverrideMode mode) {
5334 if (argument_count() == ANY) {
5335 Label zero_case, n_case;
5336 __ Cbz(argc, &zero_case);
5341 CreateArrayDispatchOneArgument(masm, mode);
5343 __ Bind(&zero_case);
5345 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5349 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5351 } else if (argument_count() == NONE) {
5352 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5353 } else if (argument_count() == ONE) {
5354 CreateArrayDispatchOneArgument(masm, mode);
5355 } else if (argument_count() == MORE_THAN_ONE) {
5356 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5363 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5364 ASM_LOCATION("ArrayConstructorStub::Generate");
5365 // ----------- S t a t e -------------
5366 // -- x0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5367 // -- x1 : constructor
5368 // -- x2 : AllocationSite or undefined
5369 // -- x3 : original constructor
5370 // -- sp[0] : last argument
5371 // -----------------------------------
5372 Register constructor = x1;
5373 Register allocation_site = x2;
5374 Register original_constructor = x3;
5376 if (FLAG_debug_code) {
5377 // The array construct code is only set for the global and natives
5378 // builtin Array functions which always have maps.
5380 Label unexpected_map, map_ok;
5381 // Initial map for the builtin Array function should be a map.
5382 __ Ldr(x10, FieldMemOperand(constructor,
5383 JSFunction::kPrototypeOrInitialMapOffset));
5384 // Will both indicate a NULL and a Smi.
5385 __ JumpIfSmi(x10, &unexpected_map);
5386 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5387 __ Bind(&unexpected_map);
5388 __ Abort(kUnexpectedInitialMapForArrayFunction);
5391 // We should either have undefined in the allocation_site register or a
5392 // valid AllocationSite.
5393 __ AssertUndefinedOrAllocationSite(allocation_site, x10);
5397 __ Cmp(original_constructor, constructor);
5398 __ B(ne, &subclassing);
5402 // Get the elements kind and case on that.
5403 __ JumpIfRoot(allocation_site, Heap::kUndefinedValueRootIndex, &no_info);
5406 UntagSmiFieldMemOperand(allocation_site,
5407 AllocationSite::kTransitionInfoOffset));
5408 __ And(kind, kind, AllocationSite::ElementsKindBits::kMask);
5409 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5412 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5414 // Subclassing support.
5415 __ Bind(&subclassing);
5416 __ Push(constructor, original_constructor);
5418 switch (argument_count()) {
5421 __ add(x0, x0, Operand(2));
5424 __ Mov(x0, Operand(2));
5427 __ Mov(x0, Operand(3));
5430 __ JumpToExternalReference(
5431 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5435 void InternalArrayConstructorStub::GenerateCase(
5436 MacroAssembler* masm, ElementsKind kind) {
5437 Label zero_case, n_case;
5440 __ Cbz(argc, &zero_case);
5441 __ CompareAndBranch(argc, 1, ne, &n_case);
5444 if (IsFastPackedElementsKind(kind)) {
5447 // We might need to create a holey array; look at the first argument.
5449 __ Cbz(x10, &packed_case);
5451 InternalArraySingleArgumentConstructorStub
5452 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5453 __ TailCallStub(&stub1_holey);
5455 __ Bind(&packed_case);
5457 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5458 __ TailCallStub(&stub1);
5460 __ Bind(&zero_case);
5462 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5463 __ TailCallStub(&stub0);
5467 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5468 __ TailCallStub(&stubN);
5472 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5473 // ----------- S t a t e -------------
5475 // -- x1 : constructor
5476 // -- sp[0] : return address
5477 // -- sp[4] : last argument
5478 // -----------------------------------
5480 Register constructor = x1;
5482 if (FLAG_debug_code) {
5483 // The array construct code is only set for the global and natives
5484 // builtin Array functions which always have maps.
5486 Label unexpected_map, map_ok;
5487 // Initial map for the builtin Array function should be a map.
5488 __ Ldr(x10, FieldMemOperand(constructor,
5489 JSFunction::kPrototypeOrInitialMapOffset));
5490 // Will both indicate a NULL and a Smi.
5491 __ JumpIfSmi(x10, &unexpected_map);
5492 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5493 __ Bind(&unexpected_map);
5494 __ Abort(kUnexpectedInitialMapForArrayFunction);
5499 // Figure out the right elements kind
5500 __ Ldr(x10, FieldMemOperand(constructor,
5501 JSFunction::kPrototypeOrInitialMapOffset));
5503 // Retrieve elements_kind from map.
5504 __ LoadElementsKindFromMap(kind, x10);
5506 if (FLAG_debug_code) {
5508 __ Cmp(x3, FAST_ELEMENTS);
5509 __ Ccmp(x3, FAST_HOLEY_ELEMENTS, ZFlag, ne);
5510 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5513 Label fast_elements_case;
5514 __ CompareAndBranch(kind, FAST_ELEMENTS, eq, &fast_elements_case);
5515 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5517 __ Bind(&fast_elements_case);
5518 GenerateCase(masm, FAST_ELEMENTS);
5522 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5523 Register context = cp;
5524 Register result = x0;
5528 // Go up the context chain to the script context.
5529 for (int i = 0; i < depth(); ++i) {
5530 __ Ldr(result, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5534 // Load the PropertyCell value at the specified slot.
5535 __ Add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5536 __ Ldr(result, ContextMemOperand(result));
5537 __ Ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5539 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5540 __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &slow_case);
5543 // Fallback to runtime.
5544 __ Bind(&slow_case);
5547 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5551 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5552 Register context = cp;
5553 Register value = x0;
5555 Register context_temp = x10;
5556 Register cell = x10;
5557 Register cell_details = x11;
5558 Register cell_value = x12;
5559 Register cell_value_map = x13;
5560 Register value_map = x14;
5561 Label fast_heapobject_case, fast_smi_case, slow_case;
5563 if (FLAG_debug_code) {
5564 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5565 __ Check(ne, kUnexpectedValue);
5568 // Go up the context chain to the script context.
5569 for (int i = 0; i < depth(); i++) {
5570 __ Ldr(context_temp, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5571 context = context_temp;
5574 // Load the PropertyCell at the specified slot.
5575 __ Add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5576 __ Ldr(cell, ContextMemOperand(cell));
5578 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5579 __ Ldr(cell_details,
5580 UntagSmiFieldMemOperand(cell, PropertyCell::kDetailsOffset));
5581 __ And(cell_details, cell_details,
5582 PropertyDetails::PropertyCellTypeField::kMask |
5583 PropertyDetails::KindField::kMask |
5584 PropertyDetails::kAttributesReadOnlyMask);
5586 // Check if PropertyCell holds mutable data.
5587 Label not_mutable_data;
5588 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5589 PropertyCellType::kMutable) |
5590 PropertyDetails::KindField::encode(kData));
5591 __ B(ne, ¬_mutable_data);
5592 __ JumpIfSmi(value, &fast_smi_case);
5593 __ Bind(&fast_heapobject_case);
5594 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5595 // RecordWriteField clobbers the value register, so we copy it before the
5598 __ RecordWriteField(cell, PropertyCell::kValueOffset, x11, x12,
5599 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5603 __ Bind(¬_mutable_data);
5604 // Check if PropertyCell value matches the new value (relevant for Constant,
5605 // ConstantType and Undefined cells).
5606 Label not_same_value;
5607 __ Ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5608 __ Cmp(cell_value, value);
5609 __ B(ne, ¬_same_value);
5611 // Make sure the PropertyCell is not marked READ_ONLY.
5612 __ Tst(cell_details, PropertyDetails::kAttributesReadOnlyMask);
5613 __ B(ne, &slow_case);
5615 if (FLAG_debug_code) {
5617 // This can only be true for Constant, ConstantType and Undefined cells,
5618 // because we never store the_hole via this stub.
5619 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5620 PropertyCellType::kConstant) |
5621 PropertyDetails::KindField::encode(kData));
5623 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5624 PropertyCellType::kConstantType) |
5625 PropertyDetails::KindField::encode(kData));
5627 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5628 PropertyCellType::kUndefined) |
5629 PropertyDetails::KindField::encode(kData));
5630 __ Check(eq, kUnexpectedValue);
5634 __ Bind(¬_same_value);
5636 // Check if PropertyCell contains data with constant type (and is not
5638 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5639 PropertyCellType::kConstantType) |
5640 PropertyDetails::KindField::encode(kData));
5641 __ B(ne, &slow_case);
5643 // Now either both old and new values must be smis or both must be heap
5644 // objects with same map.
5645 Label value_is_heap_object;
5646 __ JumpIfNotSmi(value, &value_is_heap_object);
5647 __ JumpIfNotSmi(cell_value, &slow_case);
5648 // Old and new values are smis, no need for a write barrier here.
5649 __ Bind(&fast_smi_case);
5650 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5653 __ Bind(&value_is_heap_object);
5654 __ JumpIfSmi(cell_value, &slow_case);
5656 __ Ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5657 __ Ldr(value_map, FieldMemOperand(value, HeapObject::kMapOffset));
5658 __ Cmp(cell_value_map, value_map);
5659 __ B(eq, &fast_heapobject_case);
5661 // Fall back to the runtime.
5662 __ Bind(&slow_case);
5664 __ Push(slot, value);
5665 __ TailCallRuntime(is_strict(language_mode())
5666 ? Runtime::kStoreGlobalViaContext_Strict
5667 : Runtime::kStoreGlobalViaContext_Sloppy,
5672 // The number of register that CallApiFunctionAndReturn will need to save on
5673 // the stack. The space for these registers need to be allocated in the
5674 // ExitFrame before calling CallApiFunctionAndReturn.
5675 static const int kCallApiFunctionSpillSpace = 4;
5678 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5679 return static_cast<int>(ref0.address() - ref1.address());
5683 // Calls an API function. Allocates HandleScope, extracts returned value
5684 // from handle and propagates exceptions.
5685 // 'stack_space' is the space to be unwound on exit (includes the call JS
5686 // arguments space and the additional space allocated for the fast call).
5687 // 'spill_offset' is the offset from the stack pointer where
5688 // CallApiFunctionAndReturn can spill registers.
5689 static void CallApiFunctionAndReturn(
5690 MacroAssembler* masm, Register function_address,
5691 ExternalReference thunk_ref, int stack_space,
5692 MemOperand* stack_space_operand, int spill_offset,
5693 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5694 ASM_LOCATION("CallApiFunctionAndReturn");
5695 Isolate* isolate = masm->isolate();
5696 ExternalReference next_address =
5697 ExternalReference::handle_scope_next_address(isolate);
5698 const int kNextOffset = 0;
5699 const int kLimitOffset = AddressOffset(
5700 ExternalReference::handle_scope_limit_address(isolate), next_address);
5701 const int kLevelOffset = AddressOffset(
5702 ExternalReference::handle_scope_level_address(isolate), next_address);
5704 DCHECK(function_address.is(x1) || function_address.is(x2));
5706 Label profiler_disabled;
5707 Label end_profiler_check;
5708 __ Mov(x10, ExternalReference::is_profiling_address(isolate));
5709 __ Ldrb(w10, MemOperand(x10));
5710 __ Cbz(w10, &profiler_disabled);
5711 __ Mov(x3, thunk_ref);
5712 __ B(&end_profiler_check);
5714 __ Bind(&profiler_disabled);
5715 __ Mov(x3, function_address);
5716 __ Bind(&end_profiler_check);
5718 // Save the callee-save registers we are going to use.
5719 // TODO(all): Is this necessary? ARM doesn't do it.
5720 STATIC_ASSERT(kCallApiFunctionSpillSpace == 4);
5721 __ Poke(x19, (spill_offset + 0) * kXRegSize);
5722 __ Poke(x20, (spill_offset + 1) * kXRegSize);
5723 __ Poke(x21, (spill_offset + 2) * kXRegSize);
5724 __ Poke(x22, (spill_offset + 3) * kXRegSize);
5726 // Allocate HandleScope in callee-save registers.
5727 // We will need to restore the HandleScope after the call to the API function,
5728 // by allocating it in callee-save registers they will be preserved by C code.
5729 Register handle_scope_base = x22;
5730 Register next_address_reg = x19;
5731 Register limit_reg = x20;
5732 Register level_reg = w21;
5734 __ Mov(handle_scope_base, next_address);
5735 __ Ldr(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5736 __ Ldr(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5737 __ Ldr(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5738 __ Add(level_reg, level_reg, 1);
5739 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5741 if (FLAG_log_timer_events) {
5742 FrameScope frame(masm, StackFrame::MANUAL);
5743 __ PushSafepointRegisters();
5744 __ Mov(x0, ExternalReference::isolate_address(isolate));
5745 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5747 __ PopSafepointRegisters();
5750 // Native call returns to the DirectCEntry stub which redirects to the
5751 // return address pushed on stack (could have moved after GC).
5752 // DirectCEntry stub itself is generated early and never moves.
5753 DirectCEntryStub stub(isolate);
5754 stub.GenerateCall(masm, x3);
5756 if (FLAG_log_timer_events) {
5757 FrameScope frame(masm, StackFrame::MANUAL);
5758 __ PushSafepointRegisters();
5759 __ Mov(x0, ExternalReference::isolate_address(isolate));
5760 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5762 __ PopSafepointRegisters();
5765 Label promote_scheduled_exception;
5766 Label delete_allocated_handles;
5767 Label leave_exit_frame;
5768 Label return_value_loaded;
5770 // Load value from ReturnValue.
5771 __ Ldr(x0, return_value_operand);
5772 __ Bind(&return_value_loaded);
5773 // No more valid handles (the result handle was the last one). Restore
5774 // previous handle scope.
5775 __ Str(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5776 if (__ emit_debug_code()) {
5777 __ Ldr(w1, MemOperand(handle_scope_base, kLevelOffset));
5778 __ Cmp(w1, level_reg);
5779 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5781 __ Sub(level_reg, level_reg, 1);
5782 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5783 __ Ldr(x1, MemOperand(handle_scope_base, kLimitOffset));
5784 __ Cmp(limit_reg, x1);
5785 __ B(ne, &delete_allocated_handles);
5787 // Leave the API exit frame.
5788 __ Bind(&leave_exit_frame);
5789 // Restore callee-saved registers.
5790 __ Peek(x19, (spill_offset + 0) * kXRegSize);
5791 __ Peek(x20, (spill_offset + 1) * kXRegSize);
5792 __ Peek(x21, (spill_offset + 2) * kXRegSize);
5793 __ Peek(x22, (spill_offset + 3) * kXRegSize);
5795 bool restore_context = context_restore_operand != NULL;
5796 if (restore_context) {
5797 __ Ldr(cp, *context_restore_operand);
5800 if (stack_space_operand != NULL) {
5801 __ Ldr(w2, *stack_space_operand);
5804 __ LeaveExitFrame(false, x1, !restore_context);
5806 // Check if the function scheduled an exception.
5807 __ Mov(x5, ExternalReference::scheduled_exception_address(isolate));
5808 __ Ldr(x5, MemOperand(x5));
5809 __ JumpIfNotRoot(x5, Heap::kTheHoleValueRootIndex,
5810 &promote_scheduled_exception);
5812 if (stack_space_operand != NULL) {
5815 __ Drop(stack_space);
5819 // Re-throw by promoting a scheduled exception.
5820 __ Bind(&promote_scheduled_exception);
5821 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5823 // HandleScope limit has changed. Delete allocated extensions.
5824 __ Bind(&delete_allocated_handles);
5825 __ Str(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5826 // Save the return value in a callee-save register.
5827 Register saved_result = x19;
5828 __ Mov(saved_result, x0);
5829 __ Mov(x0, ExternalReference::isolate_address(isolate));
5830 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5832 __ Mov(x0, saved_result);
5833 __ B(&leave_exit_frame);
5837 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5838 const ParameterCount& argc,
5839 bool return_first_arg,
5840 bool call_data_undefined) {
5841 // ----------- S t a t e -------------
5843 // -- x4 : call_data
5845 // -- x1 : api_function_address
5846 // -- x3 : number of arguments if argc is a register
5849 // -- sp[0] : last argument
5851 // -- sp[(argc - 1) * 8] : first argument
5852 // -- sp[argc * 8] : receiver
5853 // -----------------------------------
5855 Register callee = x0;
5856 Register call_data = x4;
5857 Register holder = x2;
5858 Register api_function_address = x1;
5859 Register context = cp;
5861 typedef FunctionCallbackArguments FCA;
5863 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5864 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5865 STATIC_ASSERT(FCA::kDataIndex == 4);
5866 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5867 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5868 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5869 STATIC_ASSERT(FCA::kHolderIndex == 0);
5870 STATIC_ASSERT(FCA::kArgsLength == 7);
5872 DCHECK(argc.is_immediate() || x3.is(argc.reg()));
5874 // FunctionCallbackArguments: context, callee and call data.
5875 __ Push(context, callee, call_data);
5877 // Load context from callee
5878 __ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5880 if (!call_data_undefined) {
5881 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
5883 Register isolate_reg = x5;
5884 __ Mov(isolate_reg, ExternalReference::isolate_address(masm->isolate()));
5886 // FunctionCallbackArguments:
5887 // return value, return value default, isolate, holder.
5888 __ Push(call_data, call_data, isolate_reg, holder);
5890 // Prepare arguments.
5892 __ Mov(args, masm->StackPointer());
5894 // Allocate the v8::Arguments structure in the arguments' space, since it's
5895 // not controlled by GC.
5896 const int kApiStackSpace = 4;
5898 // Allocate space for CallApiFunctionAndReturn can store some scratch
5899 // registeres on the stack.
5900 const int kCallApiFunctionSpillSpace = 4;
5902 FrameScope frame_scope(masm, StackFrame::MANUAL);
5903 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5905 DCHECK(!AreAliased(x0, api_function_address));
5906 // x0 = FunctionCallbackInfo&
5907 // Arguments is after the return address.
5908 __ Add(x0, masm->StackPointer(), 1 * kPointerSize);
5909 if (argc.is_immediate()) {
5910 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5912 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5913 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5914 // FunctionCallbackInfo::length_ = argc and
5915 // FunctionCallbackInfo::is_construct_call = 0
5916 __ Mov(x10, argc.immediate());
5917 __ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize));
5919 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5920 __ Add(x10, args, Operand(argc.reg(), LSL, kPointerSizeLog2));
5921 __ Add(x10, x10, (FCA::kArgsLength - 1) * kPointerSize);
5922 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5923 // FunctionCallbackInfo::length_ = argc and
5924 // FunctionCallbackInfo::is_construct_call
5925 __ Add(x10, argc.reg(), FCA::kArgsLength + 1);
5926 __ Mov(x10, Operand(x10, LSL, kPointerSizeLog2));
5927 __ Stp(argc.reg(), x10, MemOperand(x0, 2 * kPointerSize));
5930 ExternalReference thunk_ref =
5931 ExternalReference::invoke_function_callback(masm->isolate());
5933 AllowExternalCallThatCantCauseGC scope(masm);
5934 MemOperand context_restore_operand(
5935 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5936 // Stores return the first js argument
5937 int return_value_offset = 0;
5938 if (return_first_arg) {
5939 return_value_offset = 2 + FCA::kArgsLength;
5941 return_value_offset = 2 + FCA::kReturnValueOffset;
5943 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5944 int stack_space = 0;
5945 MemOperand is_construct_call_operand =
5946 MemOperand(masm->StackPointer(), 4 * kPointerSize);
5947 MemOperand* stack_space_operand = &is_construct_call_operand;
5948 if (argc.is_immediate()) {
5949 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5950 stack_space_operand = NULL;
5953 const int spill_offset = 1 + kApiStackSpace;
5954 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5955 stack_space_operand, spill_offset,
5956 return_value_operand, &context_restore_operand);
5960 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5961 bool call_data_undefined = this->call_data_undefined();
5962 CallApiFunctionStubHelper(masm, ParameterCount(x3), false,
5963 call_data_undefined);
5967 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5968 bool is_store = this->is_store();
5969 int argc = this->argc();
5970 bool call_data_undefined = this->call_data_undefined();
5971 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5972 call_data_undefined);
5976 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5977 // ----------- S t a t e -------------
5979 // -- sp[8 - kArgsLength*8] : PropertyCallbackArguments object
5981 // -- x2 : api_function_address
5982 // -----------------------------------
5984 Register api_function_address = ApiGetterDescriptor::function_address();
5985 DCHECK(api_function_address.is(x2));
5987 __ Mov(x0, masm->StackPointer()); // x0 = Handle<Name>
5988 __ Add(x1, x0, 1 * kPointerSize); // x1 = PCA
5990 const int kApiStackSpace = 1;
5992 // Allocate space for CallApiFunctionAndReturn can store some scratch
5993 // registeres on the stack.
5994 const int kCallApiFunctionSpillSpace = 4;
5996 FrameScope frame_scope(masm, StackFrame::MANUAL);
5997 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5999 // Create PropertyAccessorInfo instance on the stack above the exit frame with
6000 // x1 (internal::Object** args_) as the data.
6001 __ Poke(x1, 1 * kPointerSize);
6002 __ Add(x1, masm->StackPointer(), 1 * kPointerSize); // x1 = AccessorInfo&
6004 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
6006 ExternalReference thunk_ref =
6007 ExternalReference::invoke_accessor_getter_callback(isolate());
6009 const int spill_offset = 1 + kApiStackSpace;
6010 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
6011 kStackUnwindSpace, NULL, spill_offset,
6012 MemOperand(fp, 6 * kPointerSize), NULL);
6018 } // namespace internal
6021 #endif // V8_TARGET_ARCH_ARM64