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.
656 __ TailCallRuntime(strict() ? Runtime::kStrictEquals : Runtime::kEquals, 2,
659 int ncr; // NaN compare result
660 if ((cond == lt) || (cond == le)) {
663 DCHECK((cond == gt) || (cond == ge)); // remaining cases
666 __ Mov(x10, Smi::FromInt(ncr));
669 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
670 // tagged as a small integer.
672 is_strong(strength()) ? Runtime::kCompare_Strong : Runtime::kCompare, 3,
681 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
682 CPURegList saved_regs = kCallerSaved;
683 CPURegList saved_fp_regs = kCallerSavedFP;
685 // We don't allow a GC during a store buffer overflow so there is no need to
686 // store the registers in any particular way, but we do have to store and
689 // We don't care if MacroAssembler scratch registers are corrupted.
690 saved_regs.Remove(*(masm->TmpList()));
691 saved_fp_regs.Remove(*(masm->FPTmpList()));
693 __ PushCPURegList(saved_regs);
694 if (save_doubles()) {
695 __ PushCPURegList(saved_fp_regs);
698 AllowExternalCallThatCantCauseGC scope(masm);
699 __ Mov(x0, ExternalReference::isolate_address(isolate()));
701 ExternalReference::store_buffer_overflow_function(isolate()), 1, 0);
703 if (save_doubles()) {
704 __ PopCPURegList(saved_fp_regs);
706 __ PopCPURegList(saved_regs);
711 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
713 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
715 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
720 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
721 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
722 UseScratchRegisterScope temps(masm);
723 Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr());
724 Register return_address = temps.AcquireX();
725 __ Mov(return_address, lr);
726 // Restore lr with the value it had before the call to this stub (the value
727 // which must be pushed).
728 __ Mov(lr, saved_lr);
729 __ PushSafepointRegisters();
730 __ Ret(return_address);
734 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
735 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
736 UseScratchRegisterScope temps(masm);
737 Register return_address = temps.AcquireX();
738 // Preserve the return address (lr will be clobbered by the pop).
739 __ Mov(return_address, lr);
740 __ PopSafepointRegisters();
741 __ Ret(return_address);
745 void MathPowStub::Generate(MacroAssembler* masm) {
747 // jssp[0]: Exponent (as a tagged value).
748 // jssp[1]: Base (as a tagged value).
750 // The (tagged) result will be returned in x0, as a heap number.
752 Register result_tagged = x0;
753 Register base_tagged = x10;
754 Register exponent_tagged = MathPowTaggedDescriptor::exponent();
755 DCHECK(exponent_tagged.is(x11));
756 Register exponent_integer = MathPowIntegerDescriptor::exponent();
757 DCHECK(exponent_integer.is(x12));
758 Register scratch1 = x14;
759 Register scratch0 = x15;
760 Register saved_lr = x19;
761 FPRegister result_double = d0;
762 FPRegister base_double = d0;
763 FPRegister exponent_double = d1;
764 FPRegister base_double_copy = d2;
765 FPRegister scratch1_double = d6;
766 FPRegister scratch0_double = d7;
768 // A fast-path for integer exponents.
769 Label exponent_is_smi, exponent_is_integer;
770 // Bail out to runtime.
772 // Allocate a heap number for the result, and return it.
775 // Unpack the inputs.
776 if (exponent_type() == ON_STACK) {
778 Label unpack_exponent;
780 __ Pop(exponent_tagged, base_tagged);
782 __ JumpIfSmi(base_tagged, &base_is_smi);
783 __ JumpIfNotHeapNumber(base_tagged, &call_runtime);
784 // base_tagged is a heap number, so load its double value.
785 __ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset));
786 __ B(&unpack_exponent);
787 __ Bind(&base_is_smi);
788 // base_tagged is a SMI, so untag it and convert it to a double.
789 __ SmiUntagToDouble(base_double, base_tagged);
791 __ Bind(&unpack_exponent);
792 // x10 base_tagged The tagged base (input).
793 // x11 exponent_tagged The tagged exponent (input).
794 // d1 base_double The base as a double.
795 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
796 __ JumpIfNotHeapNumber(exponent_tagged, &call_runtime);
797 // exponent_tagged is a heap number, so load its double value.
798 __ Ldr(exponent_double,
799 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
800 } else if (exponent_type() == TAGGED) {
801 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
802 __ Ldr(exponent_double,
803 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
806 // Handle double (heap number) exponents.
807 if (exponent_type() != INTEGER) {
808 // Detect integer exponents stored as doubles and handle those in the
809 // integer fast-path.
810 __ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
811 scratch0_double, &exponent_is_integer);
813 if (exponent_type() == ON_STACK) {
814 FPRegister half_double = d3;
815 FPRegister minus_half_double = d4;
816 // Detect square root case. Crankshaft detects constant +/-0.5 at compile
817 // time and uses DoMathPowHalf instead. We then skip this check for
818 // non-constant cases of +/-0.5 as these hardly occur.
820 __ Fmov(minus_half_double, -0.5);
821 __ Fmov(half_double, 0.5);
822 __ Fcmp(minus_half_double, exponent_double);
823 __ Fccmp(half_double, exponent_double, NZFlag, ne);
824 // Condition flags at this point:
825 // 0.5; nZCv // Identified by eq && pl
826 // -0.5: NZcv // Identified by eq && mi
827 // other: ?z?? // Identified by ne
828 __ B(ne, &call_runtime);
830 // The exponent is 0.5 or -0.5.
832 // Given that exponent is known to be either 0.5 or -0.5, the following
833 // special cases could apply (according to ECMA-262 15.8.2.13):
835 // base.isNaN(): The result is NaN.
836 // (base == +INFINITY) || (base == -INFINITY)
837 // exponent == 0.5: The result is +INFINITY.
838 // exponent == -0.5: The result is +0.
839 // (base == +0) || (base == -0)
840 // exponent == 0.5: The result is +0.
841 // exponent == -0.5: The result is +INFINITY.
842 // (base < 0) && base.isFinite(): The result is NaN.
844 // Fsqrt (and Fdiv for the -0.5 case) can handle all of those except
845 // where base is -INFINITY or -0.
847 // Add +0 to base. This has no effect other than turning -0 into +0.
848 __ Fadd(base_double, base_double, fp_zero);
849 // The operation -0+0 results in +0 in all cases except where the
850 // FPCR rounding mode is 'round towards minus infinity' (RM). The
851 // ARM64 simulator does not currently simulate FPCR (where the rounding
852 // mode is set), so test the operation with some debug code.
853 if (masm->emit_debug_code()) {
854 UseScratchRegisterScope temps(masm);
855 Register temp = temps.AcquireX();
856 __ Fneg(scratch0_double, fp_zero);
857 // Verify that we correctly generated +0.0 and -0.0.
858 // bits(+0.0) = 0x0000000000000000
859 // bits(-0.0) = 0x8000000000000000
860 __ Fmov(temp, fp_zero);
861 __ CheckRegisterIsClear(temp, kCouldNotGenerateZero);
862 __ Fmov(temp, scratch0_double);
863 __ Eor(temp, temp, kDSignMask);
864 __ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero);
865 // Check that -0.0 + 0.0 == +0.0.
866 __ Fadd(scratch0_double, scratch0_double, fp_zero);
867 __ Fmov(temp, scratch0_double);
868 __ CheckRegisterIsClear(temp, kExpectedPositiveZero);
871 // If base is -INFINITY, make it +INFINITY.
872 // * Calculate base - base: All infinities will become NaNs since both
873 // -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64.
874 // * If the result is NaN, calculate abs(base).
875 __ Fsub(scratch0_double, base_double, base_double);
876 __ Fcmp(scratch0_double, 0.0);
877 __ Fabs(scratch1_double, base_double);
878 __ Fcsel(base_double, scratch1_double, base_double, vs);
880 // Calculate the square root of base.
881 __ Fsqrt(result_double, base_double);
882 __ Fcmp(exponent_double, 0.0);
883 __ B(ge, &done); // Finish now for exponents of 0.5.
884 // Find the inverse for exponents of -0.5.
885 __ Fmov(scratch0_double, 1.0);
886 __ Fdiv(result_double, scratch0_double, result_double);
891 AllowExternalCallThatCantCauseGC scope(masm);
892 __ Mov(saved_lr, lr);
894 ExternalReference::power_double_double_function(isolate()),
896 __ Mov(lr, saved_lr);
900 // Handle SMI exponents.
901 __ Bind(&exponent_is_smi);
902 // x10 base_tagged The tagged base (input).
903 // x11 exponent_tagged The tagged exponent (input).
904 // d1 base_double The base as a double.
905 __ SmiUntag(exponent_integer, exponent_tagged);
908 __ Bind(&exponent_is_integer);
909 // x10 base_tagged The tagged base (input).
910 // x11 exponent_tagged The tagged exponent (input).
911 // x12 exponent_integer The exponent as an integer.
912 // d1 base_double The base as a double.
914 // Find abs(exponent). For negative exponents, we can find the inverse later.
915 Register exponent_abs = x13;
916 __ Cmp(exponent_integer, 0);
917 __ Cneg(exponent_abs, exponent_integer, mi);
918 // x13 exponent_abs The value of abs(exponent_integer).
920 // Repeatedly multiply to calculate the power.
922 // For each bit n (exponent_integer{n}) {
923 // if (exponent_integer{n}) {
927 // if (remaining bits in exponent_integer are all zero) {
931 Label power_loop, power_loop_entry, power_loop_exit;
932 __ Fmov(scratch1_double, base_double);
933 __ Fmov(base_double_copy, base_double);
934 __ Fmov(result_double, 1.0);
935 __ B(&power_loop_entry);
937 __ Bind(&power_loop);
938 __ Fmul(scratch1_double, scratch1_double, scratch1_double);
939 __ Lsr(exponent_abs, exponent_abs, 1);
940 __ Cbz(exponent_abs, &power_loop_exit);
942 __ Bind(&power_loop_entry);
943 __ Tbz(exponent_abs, 0, &power_loop);
944 __ Fmul(result_double, result_double, scratch1_double);
947 __ Bind(&power_loop_exit);
949 // If the exponent was positive, result_double holds the result.
950 __ Tbz(exponent_integer, kXSignBit, &done);
952 // The exponent was negative, so find the inverse.
953 __ Fmov(scratch0_double, 1.0);
954 __ Fdiv(result_double, scratch0_double, result_double);
955 // ECMA-262 only requires Math.pow to return an 'implementation-dependent
956 // approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
957 // to calculate the subnormal value 2^-1074. This method of calculating
958 // negative powers doesn't work because 2^1074 overflows to infinity. To
959 // catch this corner-case, we bail out if the result was 0. (This can only
960 // occur if the divisor is infinity or the base is zero.)
961 __ Fcmp(result_double, 0.0);
964 if (exponent_type() == ON_STACK) {
965 // Bail out to runtime code.
966 __ Bind(&call_runtime);
967 // Put the arguments back on the stack.
968 __ Push(base_tagged, exponent_tagged);
969 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
973 __ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1,
975 DCHECK(result_tagged.is(x0));
977 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
980 AllowExternalCallThatCantCauseGC scope(masm);
981 __ Mov(saved_lr, lr);
982 __ Fmov(base_double, base_double_copy);
983 __ Scvtf(exponent_double, exponent_integer);
985 ExternalReference::power_double_double_function(isolate()),
987 __ Mov(lr, saved_lr);
990 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
996 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
997 // It is important that the following stubs are generated in this order
998 // because pregenerated stubs can only call other pregenerated stubs.
999 // RecordWriteStub uses StoreBufferOverflowStub, which in turn uses
1001 CEntryStub::GenerateAheadOfTime(isolate);
1002 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1003 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1004 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1005 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1006 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1007 BinaryOpICStub::GenerateAheadOfTime(isolate);
1008 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1009 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1010 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1011 StoreFastElementStub::GenerateAheadOfTime(isolate);
1012 TypeofStub::GenerateAheadOfTime(isolate);
1016 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1017 StoreRegistersStateStub stub(isolate);
1022 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1023 RestoreRegistersStateStub stub(isolate);
1028 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1029 // Floating-point code doesn't get special handling in ARM64, so there's
1030 // nothing to do here.
1035 bool CEntryStub::NeedsImmovableCode() {
1036 // CEntryStub stores the return address on the stack before calling into
1037 // C++ code. In some cases, the VM accesses this address, but it is not used
1038 // when the C++ code returns to the stub because LR holds the return address
1039 // in AAPCS64. If the stub is moved (perhaps during a GC), we could end up
1040 // returning to dead code.
1041 // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't
1042 // find any comment to confirm this, and I don't hit any crashes whatever
1043 // this function returns. The anaylsis should be properly confirmed.
1048 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1049 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1051 CEntryStub stub_fp(isolate, 1, kSaveFPRegs);
1056 void CEntryStub::Generate(MacroAssembler* masm) {
1057 // The Abort mechanism relies on CallRuntime, which in turn relies on
1058 // CEntryStub, so until this stub has been generated, we have to use a
1059 // fall-back Abort mechanism.
1061 // Note that this stub must be generated before any use of Abort.
1062 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
1064 ASM_LOCATION("CEntryStub::Generate entry");
1065 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1067 // Register parameters:
1068 // x0: argc (including receiver, untagged)
1071 // The stack on entry holds the arguments and the receiver, with the receiver
1072 // at the highest address:
1074 // jssp]argc-1]: receiver
1075 // jssp[argc-2]: arg[argc-2]
1080 // The arguments are in reverse order, so that arg[argc-2] is actually the
1081 // first argument to the target function and arg[0] is the last.
1082 DCHECK(jssp.Is(__ StackPointer()));
1083 const Register& argc_input = x0;
1084 const Register& target_input = x1;
1086 // Calculate argv, argc and the target address, and store them in
1087 // callee-saved registers so we can retry the call without having to reload
1089 // TODO(jbramley): If the first call attempt succeeds in the common case (as
1090 // it should), then we might be better off putting these parameters directly
1091 // into their argument registers, rather than using callee-saved registers and
1092 // preserving them on the stack.
1093 const Register& argv = x21;
1094 const Register& argc = x22;
1095 const Register& target = x23;
1097 // Derive argv from the stack pointer so that it points to the first argument
1098 // (arg[argc-2]), or just below the receiver in case there are no arguments.
1099 // - Adjust for the arg[] array.
1100 Register temp_argv = x11;
1101 __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
1102 // - Adjust for the receiver.
1103 __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
1105 // Enter the exit frame. Reserve three slots to preserve x21-x23 callee-saved
1107 FrameScope scope(masm, StackFrame::MANUAL);
1108 __ EnterExitFrame(save_doubles(), x10, 3);
1109 DCHECK(csp.Is(__ StackPointer()));
1111 // Poke callee-saved registers into reserved space.
1112 __ Poke(argv, 1 * kPointerSize);
1113 __ Poke(argc, 2 * kPointerSize);
1114 __ Poke(target, 3 * kPointerSize);
1116 // We normally only keep tagged values in callee-saved registers, as they
1117 // could be pushed onto the stack by called stubs and functions, and on the
1118 // stack they can confuse the GC. However, we're only calling C functions
1119 // which can push arbitrary data onto the stack anyway, and so the GC won't
1120 // examine that part of the stack.
1121 __ Mov(argc, argc_input);
1122 __ Mov(target, target_input);
1123 __ Mov(argv, temp_argv);
1127 // x23 : call target
1129 // The stack (on entry) holds the arguments and the receiver, with the
1130 // receiver at the highest address:
1132 // argv[8]: receiver
1133 // argv -> argv[0]: arg[argc-2]
1135 // argv[...]: arg[1]
1136 // argv[...]: arg[0]
1138 // Immediately below (after) this is the exit frame, as constructed by
1140 // fp[8]: CallerPC (lr)
1141 // fp -> fp[0]: CallerFP (old fp)
1142 // fp[-8]: Space reserved for SPOffset.
1143 // fp[-16]: CodeObject()
1144 // csp[...]: Saved doubles, if saved_doubles is true.
1145 // csp[32]: Alignment padding, if necessary.
1146 // csp[24]: Preserved x23 (used for target).
1147 // csp[16]: Preserved x22 (used for argc).
1148 // csp[8]: Preserved x21 (used for argv).
1149 // csp -> csp[0]: Space reserved for the return address.
1151 // After a successful call, the exit frame, preserved registers (x21-x23) and
1152 // the arguments (including the receiver) are dropped or popped as
1153 // appropriate. The stub then returns.
1155 // After an unsuccessful call, the exit frame and suchlike are left
1156 // untouched, and the stub either throws an exception by jumping to one of
1157 // the exception_returned label.
1159 DCHECK(csp.Is(__ StackPointer()));
1161 // Prepare AAPCS64 arguments to pass to the builtin.
1164 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1166 Label return_location;
1167 __ Adr(x12, &return_location);
1170 if (__ emit_debug_code()) {
1171 // Verify that the slot below fp[kSPOffset]-8 points to the return location
1172 // (currently in x12).
1173 UseScratchRegisterScope temps(masm);
1174 Register temp = temps.AcquireX();
1175 __ Ldr(temp, MemOperand(fp, ExitFrameConstants::kSPOffset));
1176 __ Ldr(temp, MemOperand(temp, -static_cast<int64_t>(kXRegSize)));
1178 __ Check(eq, kReturnAddressNotFoundInFrame);
1181 // Call the builtin.
1183 __ Bind(&return_location);
1185 // x0 result The return code from the call.
1189 const Register& result = x0;
1191 // Check result for exception sentinel.
1192 Label exception_returned;
1193 __ CompareRoot(result, Heap::kExceptionRootIndex);
1194 __ B(eq, &exception_returned);
1196 // The call succeeded, so unwind the stack and return.
1198 // Restore callee-saved registers x21-x23.
1201 __ Peek(argv, 1 * kPointerSize);
1202 __ Peek(argc, 2 * kPointerSize);
1203 __ Peek(target, 3 * kPointerSize);
1205 __ LeaveExitFrame(save_doubles(), x10, true);
1206 DCHECK(jssp.Is(__ StackPointer()));
1207 // Pop or drop the remaining stack slots and return from the stub.
1208 // jssp[24]: Arguments array (of size argc), including receiver.
1209 // jssp[16]: Preserved x23 (used for target).
1210 // jssp[8]: Preserved x22 (used for argc).
1211 // jssp[0]: Preserved x21 (used for argv).
1213 __ AssertFPCRState();
1216 // The stack pointer is still csp if we aren't returning, and the frame
1217 // hasn't changed (except for the return address).
1218 __ SetStackPointer(csp);
1220 // Handling of exception.
1221 __ Bind(&exception_returned);
1223 ExternalReference pending_handler_context_address(
1224 Isolate::kPendingHandlerContextAddress, isolate());
1225 ExternalReference pending_handler_code_address(
1226 Isolate::kPendingHandlerCodeAddress, isolate());
1227 ExternalReference pending_handler_offset_address(
1228 Isolate::kPendingHandlerOffsetAddress, isolate());
1229 ExternalReference pending_handler_fp_address(
1230 Isolate::kPendingHandlerFPAddress, isolate());
1231 ExternalReference pending_handler_sp_address(
1232 Isolate::kPendingHandlerSPAddress, isolate());
1234 // Ask the runtime for help to determine the handler. This will set x0 to
1235 // contain the current pending exception, don't clobber it.
1236 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1238 DCHECK(csp.Is(masm->StackPointer()));
1240 FrameScope scope(masm, StackFrame::MANUAL);
1241 __ Mov(x0, 0); // argc.
1242 __ Mov(x1, 0); // argv.
1243 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1244 __ CallCFunction(find_handler, 3);
1247 // We didn't execute a return case, so the stack frame hasn't been updated
1248 // (except for the return address slot). However, we don't need to initialize
1249 // jssp because the throw method will immediately overwrite it when it
1250 // unwinds the stack.
1251 __ SetStackPointer(jssp);
1253 // Retrieve the handler context, SP and FP.
1254 __ Mov(cp, Operand(pending_handler_context_address));
1255 __ Ldr(cp, MemOperand(cp));
1256 __ Mov(jssp, Operand(pending_handler_sp_address));
1257 __ Ldr(jssp, MemOperand(jssp));
1258 __ Mov(fp, Operand(pending_handler_fp_address));
1259 __ Ldr(fp, MemOperand(fp));
1261 // If the handler is a JS frame, restore the context to the frame. Note that
1262 // the context will be set to (cp == 0) for non-JS frames.
1264 __ Cbz(cp, ¬_js_frame);
1265 __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1266 __ Bind(¬_js_frame);
1268 // Compute the handler entry address and jump to it.
1269 __ Mov(x10, Operand(pending_handler_code_address));
1270 __ Ldr(x10, MemOperand(x10));
1271 __ Mov(x11, Operand(pending_handler_offset_address));
1272 __ Ldr(x11, MemOperand(x11));
1273 __ Add(x10, x10, Code::kHeaderSize - kHeapObjectTag);
1274 __ Add(x10, x10, x11);
1279 // This is the entry point from C++. 5 arguments are provided in x0-x4.
1280 // See use of the CALL_GENERATED_CODE macro for example in src/execution.cc.
1289 void JSEntryStub::Generate(MacroAssembler* masm) {
1290 DCHECK(jssp.Is(__ StackPointer()));
1291 Register code_entry = x0;
1293 // Enable instruction instrumentation. This only works on the simulator, and
1294 // will have no effect on the model or real hardware.
1295 __ EnableInstrumentation();
1297 Label invoke, handler_entry, exit;
1299 // Push callee-saved registers and synchronize the system stack pointer (csp)
1300 // and the JavaScript stack pointer (jssp).
1302 // We must not write to jssp until after the PushCalleeSavedRegisters()
1303 // call, since jssp is itself a callee-saved register.
1304 __ SetStackPointer(csp);
1305 __ PushCalleeSavedRegisters();
1307 __ SetStackPointer(jssp);
1309 // Configure the FPCR. We don't restore it, so this is technically not allowed
1310 // according to AAPCS64. However, we only set default-NaN mode and this will
1311 // be harmless for most C code. Also, it works for ARM.
1314 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1316 // Set up the reserved register for 0.0.
1317 __ Fmov(fp_zero, 0.0);
1319 // Build an entry frame (see layout below).
1320 int marker = type();
1321 int64_t bad_frame_pointer = -1L; // Bad frame pointer to fail if it is used.
1322 __ Mov(x13, bad_frame_pointer);
1323 __ Mov(x12, Smi::FromInt(marker));
1324 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1325 __ Ldr(x10, MemOperand(x11));
1327 __ Push(x13, xzr, x12, x10);
1329 __ Sub(fp, jssp, EntryFrameConstants::kCallerFPOffset);
1331 // Push the JS entry frame marker. Also set js_entry_sp if this is the
1332 // outermost JS call.
1333 Label non_outermost_js, done;
1334 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1335 __ Mov(x10, ExternalReference(js_entry_sp));
1336 __ Ldr(x11, MemOperand(x10));
1337 __ Cbnz(x11, &non_outermost_js);
1338 __ Str(fp, MemOperand(x10));
1339 __ Mov(x12, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1342 __ Bind(&non_outermost_js);
1343 // We spare one instruction by pushing xzr since the marker is 0.
1344 DCHECK(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME) == NULL);
1348 // The frame set up looks like this:
1349 // jssp[0] : JS entry frame marker.
1350 // jssp[1] : C entry FP.
1351 // jssp[2] : stack frame marker.
1352 // jssp[3] : stack frmae marker.
1353 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1356 // Jump to a faked try block that does the invoke, with a faked catch
1357 // block that sets the pending exception.
1360 // Prevent the constant pool from being emitted between the record of the
1361 // handler_entry position and the first instruction of the sequence here.
1362 // There is no risk because Assembler::Emit() emits the instruction before
1363 // checking for constant pool emission, but we do not want to depend on
1366 Assembler::BlockPoolsScope block_pools(masm);
1367 __ bind(&handler_entry);
1368 handler_offset_ = handler_entry.pos();
1369 // Caught exception: Store result (exception) in the pending exception
1370 // field in the JSEnv and return a failure sentinel. Coming in here the
1371 // fp will be invalid because the PushTryHandler below sets it to 0 to
1372 // signal the existence of the JSEntry frame.
1373 __ Mov(x10, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1376 __ Str(code_entry, MemOperand(x10));
1377 __ LoadRoot(x0, Heap::kExceptionRootIndex);
1380 // Invoke: Link this frame into the handler chain.
1382 __ PushStackHandler();
1383 // If an exception not caught by another handler occurs, this handler
1384 // returns control to the code after the B(&invoke) above, which
1385 // restores all callee-saved registers (including cp and fp) to their
1386 // saved values before returning a failure to C.
1388 // Clear any pending exceptions.
1389 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
1390 __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1392 __ Str(x10, MemOperand(x11));
1394 // Invoke the function by calling through the JS entry trampoline builtin.
1395 // Notice that we cannot store a reference to the trampoline code directly in
1396 // this stub, because runtime stubs are not traversed when doing GC.
1398 // Expected registers by Builtins::JSEntryTrampoline
1404 ExternalReference entry(type() == StackFrame::ENTRY_CONSTRUCT
1405 ? Builtins::kJSConstructEntryTrampoline
1406 : Builtins::kJSEntryTrampoline,
1410 // Call the JSEntryTrampoline.
1411 __ Ldr(x11, MemOperand(x10)); // Dereference the address.
1412 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag);
1415 // Unlink this frame from the handler chain.
1416 __ PopStackHandler();
1420 // x0 holds the result.
1421 // The stack pointer points to the top of the entry frame pushed on entry from
1422 // C++ (at the beginning of this stub):
1423 // jssp[0] : JS entry frame marker.
1424 // jssp[1] : C entry FP.
1425 // jssp[2] : stack frame marker.
1426 // jssp[3] : stack frmae marker.
1427 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1429 // Check if the current stack frame is marked as the outermost JS frame.
1430 Label non_outermost_js_2;
1432 __ Cmp(x10, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1433 __ B(ne, &non_outermost_js_2);
1434 __ Mov(x11, ExternalReference(js_entry_sp));
1435 __ Str(xzr, MemOperand(x11));
1436 __ Bind(&non_outermost_js_2);
1438 // Restore the top frame descriptors from the stack.
1440 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1441 __ Str(x10, MemOperand(x11));
1443 // Reset the stack to the callee saved registers.
1444 __ Drop(-EntryFrameConstants::kCallerFPOffset, kByteSizeInBytes);
1445 // Restore the callee-saved registers and return.
1446 DCHECK(jssp.Is(__ StackPointer()));
1448 __ SetStackPointer(csp);
1449 __ PopCalleeSavedRegisters();
1450 // After this point, we must not modify jssp because it is a callee-saved
1451 // register which we have just restored.
1456 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1458 Register receiver = LoadDescriptor::ReceiverRegister();
1459 // Ensure that the vector and slot registers won't be clobbered before
1460 // calling the miss handler.
1461 DCHECK(!AreAliased(x10, x11, LoadWithVectorDescriptor::VectorRegister(),
1462 LoadWithVectorDescriptor::SlotRegister()));
1464 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, x10,
1468 PropertyAccessCompiler::TailCallBuiltin(
1469 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1473 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1474 // Return address is in lr.
1477 Register receiver = LoadDescriptor::ReceiverRegister();
1478 Register index = LoadDescriptor::NameRegister();
1479 Register result = x0;
1480 Register scratch = x10;
1481 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1482 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1483 result.is(LoadWithVectorDescriptor::SlotRegister()));
1485 // StringCharAtGenerator doesn't use the result register until it's passed
1486 // the different miss possibilities. If it did, we would have a conflict
1487 // when FLAG_vector_ics is true.
1488 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1489 &miss, // When not a string.
1490 &miss, // When not a number.
1491 &miss, // When index out of range.
1492 STRING_INDEX_IS_ARRAY_INDEX,
1493 RECEIVER_IS_STRING);
1494 char_at_generator.GenerateFast(masm);
1497 StubRuntimeCallHelper call_helper;
1498 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1501 PropertyAccessCompiler::TailCallBuiltin(
1502 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1506 void InstanceOfStub::Generate(MacroAssembler* masm) {
1507 Register const object = x1; // Object (lhs).
1508 Register const function = x0; // Function (rhs).
1509 Register const object_map = x2; // Map of {object}.
1510 Register const function_map = x3; // Map of {function}.
1511 Register const function_prototype = x4; // Prototype of {function}.
1512 Register const scratch = x5;
1514 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1515 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1517 // Check if {object} is a smi.
1518 Label object_is_smi;
1519 __ JumpIfSmi(object, &object_is_smi);
1521 // Lookup the {function} and the {object} map in the global instanceof cache.
1522 // Note: This is safe because we clear the global instanceof cache whenever
1523 // we change the prototype of any object.
1524 Label fast_case, slow_case;
1525 __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1526 __ JumpIfNotRoot(function, Heap::kInstanceofCacheFunctionRootIndex,
1528 __ JumpIfNotRoot(object_map, Heap::kInstanceofCacheMapRootIndex, &fast_case);
1529 __ LoadRoot(x0, Heap::kInstanceofCacheAnswerRootIndex);
1532 // If {object} is a smi we can safely return false if {function} is a JS
1533 // function, otherwise we have to miss to the runtime and throw an exception.
1534 __ Bind(&object_is_smi);
1535 __ JumpIfSmi(function, &slow_case);
1536 __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
1538 __ LoadRoot(x0, Heap::kFalseValueRootIndex);
1541 // Fast-case: The {function} must be a valid JSFunction.
1542 __ Bind(&fast_case);
1543 __ JumpIfSmi(function, &slow_case);
1544 __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
1547 // Ensure that {function} has an instance prototype.
1548 __ Ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1549 __ Tbnz(scratch, Map::kHasNonInstancePrototype, &slow_case);
1551 // Ensure that {function} is not bound.
1552 Register const shared_info = scratch;
1553 Register const scratch_w = scratch.W();
1555 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1556 // On 64-bit platforms, compiler hints field is not a smi. See definition of
1557 // kCompilerHintsOffset in src/objects.h.
1558 __ Ldr(scratch_w, FieldMemOperand(shared_info,
1559 SharedFunctionInfo::kCompilerHintsOffset));
1560 __ Tbnz(scratch_w, SharedFunctionInfo::kBoundFunction, &slow_case);
1562 // Get the "prototype" (or initial map) of the {function}.
1563 __ Ldr(function_prototype,
1564 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1565 __ AssertNotSmi(function_prototype);
1567 // Resolve the prototype if the {function} has an initial map. Afterwards the
1568 // {function_prototype} will be either the JSReceiver prototype object or the
1569 // hole value, which means that no instances of the {function} were created so
1570 // far and hence we should return false.
1571 Label function_prototype_valid;
1572 __ JumpIfNotObjectType(function_prototype, scratch, scratch, MAP_TYPE,
1573 &function_prototype_valid);
1574 __ Ldr(function_prototype,
1575 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1576 __ Bind(&function_prototype_valid);
1577 __ AssertNotSmi(function_prototype);
1579 // Update the global instanceof cache with the current {object} map and
1580 // {function}. The cached answer will be set when it is known below.
1581 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1582 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1584 // Loop through the prototype chain looking for the {function} prototype.
1585 // Assume true, and change to false if not found.
1586 Register const object_prototype = object_map;
1587 Register const null = scratch;
1589 __ LoadRoot(x0, Heap::kTrueValueRootIndex);
1590 __ LoadRoot(null, Heap::kNullValueRootIndex);
1592 __ Ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1593 __ Cmp(object_prototype, function_prototype);
1595 __ Cmp(object_prototype, null);
1596 __ Ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1598 __ LoadRoot(x0, Heap::kFalseValueRootIndex);
1600 __ StoreRoot(x0, Heap::kInstanceofCacheAnswerRootIndex);
1603 // Slow-case: Call the runtime function.
1604 __ bind(&slow_case);
1605 __ Push(object, function);
1606 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1610 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1611 Register arg_count = ArgumentsAccessReadDescriptor::parameter_count();
1612 Register key = ArgumentsAccessReadDescriptor::index();
1613 DCHECK(arg_count.is(x0));
1616 // The displacement is the offset of the last parameter (if any) relative
1617 // to the frame pointer.
1618 static const int kDisplacement =
1619 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1621 // Check that the key is a smi.
1623 __ JumpIfNotSmi(key, &slow);
1625 // Check if the calling frame is an arguments adaptor frame.
1626 Register local_fp = x11;
1627 Register caller_fp = x11;
1628 Register caller_ctx = x12;
1630 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1631 __ Ldr(caller_ctx, MemOperand(caller_fp,
1632 StandardFrameConstants::kContextOffset));
1633 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1634 __ Csel(local_fp, fp, caller_fp, ne);
1635 __ B(ne, &skip_adaptor);
1637 // Load the actual arguments limit found in the arguments adaptor frame.
1638 __ Ldr(arg_count, MemOperand(caller_fp,
1639 ArgumentsAdaptorFrameConstants::kLengthOffset));
1640 __ Bind(&skip_adaptor);
1642 // Check index against formal parameters count limit. Use unsigned comparison
1643 // to get negative check for free: branch if key < 0 or key >= arg_count.
1644 __ Cmp(key, arg_count);
1647 // Read the argument from the stack and return it.
1648 __ Sub(x10, arg_count, key);
1649 __ Add(x10, local_fp, Operand::UntagSmiAndScale(x10, kPointerSizeLog2));
1650 __ Ldr(x0, MemOperand(x10, kDisplacement));
1653 // Slow case: handle non-smi or out-of-bounds access to arguments by calling
1654 // the runtime system.
1657 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1661 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1662 // Stack layout on entry.
1663 // jssp[0]: number of parameters (tagged)
1664 // jssp[8]: address of receiver argument
1665 // jssp[16]: function
1667 // Check if the calling frame is an arguments adaptor frame.
1669 Register caller_fp = x10;
1670 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1671 // Load and untag the context.
1672 __ Ldr(w11, UntagSmiMemOperand(caller_fp,
1673 StandardFrameConstants::kContextOffset));
1674 __ Cmp(w11, StackFrame::ARGUMENTS_ADAPTOR);
1677 // Patch the arguments.length and parameters pointer in the current frame.
1678 __ Ldr(x11, MemOperand(caller_fp,
1679 ArgumentsAdaptorFrameConstants::kLengthOffset));
1680 __ Poke(x11, 0 * kXRegSize);
1681 __ Add(x10, caller_fp, Operand::UntagSmiAndScale(x11, kPointerSizeLog2));
1682 __ Add(x10, x10, StandardFrameConstants::kCallerSPOffset);
1683 __ Poke(x10, 1 * kXRegSize);
1686 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1690 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1691 // Stack layout on entry.
1692 // jssp[0]: number of parameters (tagged)
1693 // jssp[8]: address of receiver argument
1694 // jssp[16]: function
1696 // Returns pointer to result object in x0.
1698 // Note: arg_count_smi is an alias of param_count_smi.
1699 Register arg_count_smi = x3;
1700 Register param_count_smi = x3;
1701 Register param_count = x7;
1702 Register recv_arg = x14;
1703 Register function = x4;
1704 __ Pop(param_count_smi, recv_arg, function);
1705 __ SmiUntag(param_count, param_count_smi);
1707 // Check if the calling frame is an arguments adaptor frame.
1708 Register caller_fp = x11;
1709 Register caller_ctx = x12;
1711 Label adaptor_frame, try_allocate;
1712 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1713 __ Ldr(caller_ctx, MemOperand(caller_fp,
1714 StandardFrameConstants::kContextOffset));
1715 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1716 __ B(eq, &adaptor_frame);
1718 // No adaptor, parameter count = argument count.
1720 // x1 mapped_params number of mapped params, min(params, args) (uninit)
1721 // x2 arg_count number of function arguments (uninit)
1722 // x3 arg_count_smi number of function arguments (smi)
1723 // x4 function function pointer
1724 // x7 param_count number of function parameters
1725 // x11 caller_fp caller's frame pointer
1726 // x14 recv_arg pointer to receiver arguments
1728 Register arg_count = x2;
1729 __ Mov(arg_count, param_count);
1730 __ B(&try_allocate);
1732 // We have an adaptor frame. Patch the parameters pointer.
1733 __ Bind(&adaptor_frame);
1734 __ Ldr(arg_count_smi,
1735 MemOperand(caller_fp,
1736 ArgumentsAdaptorFrameConstants::kLengthOffset));
1737 __ SmiUntag(arg_count, arg_count_smi);
1738 __ Add(x10, caller_fp, Operand(arg_count, LSL, kPointerSizeLog2));
1739 __ Add(recv_arg, x10, StandardFrameConstants::kCallerSPOffset);
1741 // Compute the mapped parameter count = min(param_count, arg_count)
1742 Register mapped_params = x1;
1743 __ Cmp(param_count, arg_count);
1744 __ Csel(mapped_params, param_count, arg_count, lt);
1746 __ Bind(&try_allocate);
1748 // x0 alloc_obj pointer to allocated objects: param map, backing
1749 // store, arguments (uninit)
1750 // x1 mapped_params number of mapped parameters, min(params, args)
1751 // x2 arg_count number of function arguments
1752 // x3 arg_count_smi number of function arguments (smi)
1753 // x4 function function pointer
1754 // x7 param_count number of function parameters
1755 // x10 size size of objects to allocate (uninit)
1756 // x14 recv_arg pointer to receiver arguments
1758 // Compute the size of backing store, parameter map, and arguments object.
1759 // 1. Parameter map, has two extra words containing context and backing
1761 const int kParameterMapHeaderSize =
1762 FixedArray::kHeaderSize + 2 * kPointerSize;
1764 // Calculate the parameter map size, assuming it exists.
1765 Register size = x10;
1766 __ Mov(size, Operand(mapped_params, LSL, kPointerSizeLog2));
1767 __ Add(size, size, kParameterMapHeaderSize);
1769 // If there are no mapped parameters, set the running size total to zero.
1770 // Otherwise, use the parameter map size calculated earlier.
1771 __ Cmp(mapped_params, 0);
1772 __ CzeroX(size, eq);
1774 // 2. Add the size of the backing store and arguments object.
1775 __ Add(size, size, Operand(arg_count, LSL, kPointerSizeLog2));
1777 FixedArray::kHeaderSize + Heap::kSloppyArgumentsObjectSize);
1779 // Do the allocation of all three objects in one go. Assign this to x0, as it
1780 // will be returned to the caller.
1781 Register alloc_obj = x0;
1782 __ Allocate(size, alloc_obj, x11, x12, &runtime, TAG_OBJECT);
1784 // Get the arguments boilerplate from the current (global) context.
1786 // x0 alloc_obj pointer to allocated objects (param map, backing
1787 // store, arguments)
1788 // x1 mapped_params number of mapped parameters, min(params, args)
1789 // x2 arg_count number of function arguments
1790 // x3 arg_count_smi number of function arguments (smi)
1791 // x4 function function pointer
1792 // x7 param_count number of function parameters
1793 // x11 sloppy_args_map offset to args (or aliased args) map (uninit)
1794 // x14 recv_arg pointer to receiver arguments
1796 Register global_object = x10;
1797 Register global_ctx = x10;
1798 Register sloppy_args_map = x11;
1799 Register aliased_args_map = x10;
1800 __ Ldr(global_object, GlobalObjectMemOperand());
1801 __ Ldr(global_ctx, FieldMemOperand(global_object,
1802 GlobalObject::kNativeContextOffset));
1804 __ Ldr(sloppy_args_map,
1805 ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1808 ContextMemOperand(global_ctx, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX));
1809 __ Cmp(mapped_params, 0);
1810 __ CmovX(sloppy_args_map, aliased_args_map, ne);
1812 // Copy the JS object part.
1813 __ Str(sloppy_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
1814 __ LoadRoot(x10, Heap::kEmptyFixedArrayRootIndex);
1815 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
1816 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1818 // Set up the callee in-object property.
1819 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1820 const int kCalleeOffset = JSObject::kHeaderSize +
1821 Heap::kArgumentsCalleeIndex * kPointerSize;
1822 __ AssertNotSmi(function);
1823 __ Str(function, FieldMemOperand(alloc_obj, kCalleeOffset));
1825 // Use the length and set that as an in-object property.
1826 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1827 const int kLengthOffset = JSObject::kHeaderSize +
1828 Heap::kArgumentsLengthIndex * kPointerSize;
1829 __ Str(arg_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
1831 // Set up the elements pointer in the allocated arguments object.
1832 // If we allocated a parameter map, "elements" will point there, otherwise
1833 // it will point to the backing store.
1835 // x0 alloc_obj pointer to allocated objects (param map, backing
1836 // store, arguments)
1837 // x1 mapped_params number of mapped parameters, min(params, args)
1838 // x2 arg_count number of function arguments
1839 // x3 arg_count_smi number of function arguments (smi)
1840 // x4 function function pointer
1841 // x5 elements pointer to parameter map or backing store (uninit)
1842 // x6 backing_store pointer to backing store (uninit)
1843 // x7 param_count number of function parameters
1844 // x14 recv_arg pointer to receiver arguments
1846 Register elements = x5;
1847 __ Add(elements, alloc_obj, Heap::kSloppyArgumentsObjectSize);
1848 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1850 // Initialize parameter map. If there are no mapped arguments, we're done.
1851 Label skip_parameter_map;
1852 __ Cmp(mapped_params, 0);
1853 // Set up backing store address, because it is needed later for filling in
1854 // the unmapped arguments.
1855 Register backing_store = x6;
1856 __ CmovX(backing_store, elements, eq);
1857 __ B(eq, &skip_parameter_map);
1859 __ LoadRoot(x10, Heap::kSloppyArgumentsElementsMapRootIndex);
1860 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
1861 __ Add(x10, mapped_params, 2);
1863 __ Str(x10, FieldMemOperand(elements, FixedArray::kLengthOffset));
1864 __ Str(cp, FieldMemOperand(elements,
1865 FixedArray::kHeaderSize + 0 * kPointerSize));
1866 __ Add(x10, elements, Operand(mapped_params, LSL, kPointerSizeLog2));
1867 __ Add(x10, x10, kParameterMapHeaderSize);
1868 __ Str(x10, FieldMemOperand(elements,
1869 FixedArray::kHeaderSize + 1 * kPointerSize));
1871 // Copy the parameter slots and the holes in the arguments.
1872 // We need to fill in mapped_parameter_count slots. Then index the context,
1873 // where parameters are stored in reverse order, at:
1875 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS + parameter_count - 1
1877 // The mapped parameter thus needs to get indices:
1879 // MIN_CONTEXT_SLOTS + parameter_count - 1 ..
1880 // MIN_CONTEXT_SLOTS + parameter_count - mapped_parameter_count
1882 // We loop from right to left.
1884 // x0 alloc_obj pointer to allocated objects (param map, backing
1885 // store, arguments)
1886 // x1 mapped_params number of mapped parameters, min(params, args)
1887 // x2 arg_count number of function arguments
1888 // x3 arg_count_smi number of function arguments (smi)
1889 // x4 function function pointer
1890 // x5 elements pointer to parameter map or backing store (uninit)
1891 // x6 backing_store pointer to backing store (uninit)
1892 // x7 param_count number of function parameters
1893 // x11 loop_count parameter loop counter (uninit)
1894 // x12 index parameter index (smi, uninit)
1895 // x13 the_hole hole value (uninit)
1896 // x14 recv_arg pointer to receiver arguments
1898 Register loop_count = x11;
1899 Register index = x12;
1900 Register the_hole = x13;
1901 Label parameters_loop, parameters_test;
1902 __ Mov(loop_count, mapped_params);
1903 __ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS));
1904 __ Sub(index, index, mapped_params);
1906 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
1907 __ Add(backing_store, elements, Operand(loop_count, LSL, kPointerSizeLog2));
1908 __ Add(backing_store, backing_store, kParameterMapHeaderSize);
1910 __ B(¶meters_test);
1912 __ Bind(¶meters_loop);
1913 __ Sub(loop_count, loop_count, 1);
1914 __ Mov(x10, Operand(loop_count, LSL, kPointerSizeLog2));
1915 __ Add(x10, x10, kParameterMapHeaderSize - kHeapObjectTag);
1916 __ Str(index, MemOperand(elements, x10));
1917 __ Sub(x10, x10, kParameterMapHeaderSize - FixedArray::kHeaderSize);
1918 __ Str(the_hole, MemOperand(backing_store, x10));
1919 __ Add(index, index, Smi::FromInt(1));
1920 __ Bind(¶meters_test);
1921 __ Cbnz(loop_count, ¶meters_loop);
1923 __ Bind(&skip_parameter_map);
1924 // Copy arguments header and remaining slots (if there are any.)
1925 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
1926 __ Str(x10, FieldMemOperand(backing_store, FixedArray::kMapOffset));
1927 __ Str(arg_count_smi, FieldMemOperand(backing_store,
1928 FixedArray::kLengthOffset));
1930 // x0 alloc_obj pointer to allocated objects (param map, backing
1931 // store, arguments)
1932 // x1 mapped_params number of mapped parameters, min(params, args)
1933 // x2 arg_count number of function arguments
1934 // x4 function function pointer
1935 // x3 arg_count_smi number of function arguments (smi)
1936 // x6 backing_store pointer to backing store (uninit)
1937 // x14 recv_arg pointer to receiver arguments
1939 Label arguments_loop, arguments_test;
1940 __ Mov(x10, mapped_params);
1941 __ Sub(recv_arg, recv_arg, Operand(x10, LSL, kPointerSizeLog2));
1942 __ B(&arguments_test);
1944 __ Bind(&arguments_loop);
1945 __ Sub(recv_arg, recv_arg, kPointerSize);
1946 __ Ldr(x11, MemOperand(recv_arg));
1947 __ Add(x12, backing_store, Operand(x10, LSL, kPointerSizeLog2));
1948 __ Str(x11, FieldMemOperand(x12, FixedArray::kHeaderSize));
1949 __ Add(x10, x10, 1);
1951 __ Bind(&arguments_test);
1952 __ Cmp(x10, arg_count);
1953 __ B(lt, &arguments_loop);
1957 // Do the runtime call to allocate the arguments object.
1959 __ Push(function, recv_arg, arg_count_smi);
1960 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1964 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1965 // Return address is in lr.
1968 Register receiver = LoadDescriptor::ReceiverRegister();
1969 Register key = LoadDescriptor::NameRegister();
1971 // Check that the key is an array index, that is Uint32.
1972 __ TestAndBranchIfAnySet(key, kSmiTagMask | kSmiSignMask, &slow);
1974 // Everything is fine, call runtime.
1975 __ Push(receiver, key);
1976 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1979 PropertyAccessCompiler::TailCallBuiltin(
1980 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1984 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1985 // Stack layout on entry.
1986 // jssp[0]: number of parameters (tagged)
1987 // jssp[8]: address of receiver argument
1988 // jssp[16]: function
1990 // Returns pointer to result object in x0.
1992 // Get the stub arguments from the frame, and make an untagged copy of the
1994 Register param_count_smi = x1;
1995 Register params = x2;
1996 Register function = x3;
1997 Register param_count = x13;
1998 __ Pop(param_count_smi, params, function);
1999 __ SmiUntag(param_count, param_count_smi);
2001 // Test if arguments adaptor needed.
2002 Register caller_fp = x11;
2003 Register caller_ctx = x12;
2004 Label try_allocate, runtime;
2005 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2006 __ Ldr(caller_ctx, MemOperand(caller_fp,
2007 StandardFrameConstants::kContextOffset));
2008 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2009 __ B(ne, &try_allocate);
2011 // x1 param_count_smi number of parameters passed to function (smi)
2012 // x2 params pointer to parameters
2013 // x3 function function pointer
2014 // x11 caller_fp caller's frame pointer
2015 // x13 param_count number of parameters passed to function
2017 // Patch the argument length and parameters pointer.
2018 __ Ldr(param_count_smi,
2019 MemOperand(caller_fp,
2020 ArgumentsAdaptorFrameConstants::kLengthOffset));
2021 __ SmiUntag(param_count, param_count_smi);
2022 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2023 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2025 // Try the new space allocation. Start out with computing the size of the
2026 // arguments object and the elements array in words.
2027 Register size = x10;
2028 __ Bind(&try_allocate);
2029 __ Add(size, param_count, FixedArray::kHeaderSize / kPointerSize);
2030 __ Cmp(param_count, 0);
2031 __ CzeroX(size, eq);
2032 __ Add(size, size, Heap::kStrictArgumentsObjectSize / kPointerSize);
2034 // Do the allocation of both objects in one go. Assign this to x0, as it will
2035 // be returned to the caller.
2036 Register alloc_obj = x0;
2037 __ Allocate(size, alloc_obj, x11, x12, &runtime,
2038 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
2040 // Get the arguments boilerplate from the current (native) context.
2041 Register global_object = x10;
2042 Register global_ctx = x10;
2043 Register strict_args_map = x4;
2044 __ Ldr(global_object, GlobalObjectMemOperand());
2045 __ Ldr(global_ctx, FieldMemOperand(global_object,
2046 GlobalObject::kNativeContextOffset));
2047 __ Ldr(strict_args_map,
2048 ContextMemOperand(global_ctx, Context::STRICT_ARGUMENTS_MAP_INDEX));
2050 // x0 alloc_obj pointer to allocated objects: parameter array and
2052 // x1 param_count_smi number of parameters passed to function (smi)
2053 // x2 params pointer to parameters
2054 // x3 function function pointer
2055 // x4 strict_args_map offset to arguments map
2056 // x13 param_count number of parameters passed to function
2057 __ Str(strict_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
2058 __ LoadRoot(x5, Heap::kEmptyFixedArrayRootIndex);
2059 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
2060 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2062 // Set the smi-tagged length as an in-object property.
2063 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2064 const int kLengthOffset = JSObject::kHeaderSize +
2065 Heap::kArgumentsLengthIndex * kPointerSize;
2066 __ Str(param_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
2068 // If there are no actual arguments, we're done.
2070 __ Cbz(param_count, &done);
2072 // Set up the elements pointer in the allocated arguments object and
2073 // initialize the header in the elements fixed array.
2074 Register elements = x5;
2075 __ Add(elements, alloc_obj, Heap::kStrictArgumentsObjectSize);
2076 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2077 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
2078 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
2079 __ Str(param_count_smi, FieldMemOperand(elements, FixedArray::kLengthOffset));
2081 // x0 alloc_obj pointer to allocated objects: parameter array and
2083 // x1 param_count_smi number of parameters passed to function (smi)
2084 // x2 params pointer to parameters
2085 // x3 function function pointer
2086 // x4 array pointer to array slot (uninit)
2087 // x5 elements pointer to elements array of alloc_obj
2088 // x13 param_count number of parameters passed to function
2090 // Copy the fixed array slots.
2092 Register array = x4;
2093 // Set up pointer to first array slot.
2094 __ Add(array, elements, FixedArray::kHeaderSize - kHeapObjectTag);
2097 // Pre-decrement the parameters pointer by kPointerSize on each iteration.
2098 // Pre-decrement in order to skip receiver.
2099 __ Ldr(x10, MemOperand(params, -kPointerSize, PreIndex));
2100 // Post-increment elements by kPointerSize on each iteration.
2101 __ Str(x10, MemOperand(array, kPointerSize, PostIndex));
2102 __ Sub(param_count, param_count, 1);
2103 __ Cbnz(param_count, &loop);
2105 // Return from stub.
2109 // Do the runtime call to allocate the arguments object.
2111 __ Push(function, params, param_count_smi);
2112 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2116 void RegExpExecStub::Generate(MacroAssembler* masm) {
2117 #ifdef V8_INTERPRETED_REGEXP
2118 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2119 #else // V8_INTERPRETED_REGEXP
2121 // Stack frame on entry.
2122 // jssp[0]: last_match_info (expected JSArray)
2123 // jssp[8]: previous index
2124 // jssp[16]: subject string
2125 // jssp[24]: JSRegExp object
2128 // Use of registers for this function.
2130 // Variable registers:
2131 // x10-x13 used as scratch registers
2132 // w0 string_type type of subject string
2133 // x2 jsstring_length subject string length
2134 // x3 jsregexp_object JSRegExp object
2135 // w4 string_encoding Latin1 or UC16
2136 // w5 sliced_string_offset if the string is a SlicedString
2137 // offset to the underlying string
2138 // w6 string_representation groups attributes of the string:
2140 // - type of the string
2141 // - is a short external string
2142 Register string_type = w0;
2143 Register jsstring_length = x2;
2144 Register jsregexp_object = x3;
2145 Register string_encoding = w4;
2146 Register sliced_string_offset = w5;
2147 Register string_representation = w6;
2149 // These are in callee save registers and will be preserved by the call
2150 // to the native RegExp code, as this code is called using the normal
2151 // C calling convention. When calling directly from generated code the
2152 // native RegExp code will not do a GC and therefore the content of
2153 // these registers are safe to use after the call.
2155 // x19 subject subject string
2156 // x20 regexp_data RegExp data (FixedArray)
2157 // x21 last_match_info_elements info relative to the last match
2159 // x22 code_object generated regexp code
2160 Register subject = x19;
2161 Register regexp_data = x20;
2162 Register last_match_info_elements = x21;
2163 Register code_object = x22;
2166 // jssp[00]: last_match_info (JSArray)
2167 // jssp[08]: previous index
2168 // jssp[16]: subject string
2169 // jssp[24]: JSRegExp object
2171 const int kLastMatchInfoOffset = 0 * kPointerSize;
2172 const int kPreviousIndexOffset = 1 * kPointerSize;
2173 const int kSubjectOffset = 2 * kPointerSize;
2174 const int kJSRegExpOffset = 3 * kPointerSize;
2176 // Ensure that a RegExp stack is allocated.
2177 ExternalReference address_of_regexp_stack_memory_address =
2178 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2179 ExternalReference address_of_regexp_stack_memory_size =
2180 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2181 __ Mov(x10, address_of_regexp_stack_memory_size);
2182 __ Ldr(x10, MemOperand(x10));
2183 __ Cbz(x10, &runtime);
2185 // Check that the first argument is a JSRegExp object.
2186 DCHECK(jssp.Is(__ StackPointer()));
2187 __ Peek(jsregexp_object, kJSRegExpOffset);
2188 __ JumpIfSmi(jsregexp_object, &runtime);
2189 __ JumpIfNotObjectType(jsregexp_object, x10, x10, JS_REGEXP_TYPE, &runtime);
2191 // Check that the RegExp has been compiled (data contains a fixed array).
2192 __ Ldr(regexp_data, FieldMemOperand(jsregexp_object, JSRegExp::kDataOffset));
2193 if (FLAG_debug_code) {
2194 STATIC_ASSERT(kSmiTag == 0);
2195 __ Tst(regexp_data, kSmiTagMask);
2196 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2197 __ CompareObjectType(regexp_data, x10, x10, FIXED_ARRAY_TYPE);
2198 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2201 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2202 __ Ldr(x10, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2203 __ Cmp(x10, Smi::FromInt(JSRegExp::IRREGEXP));
2206 // Check that the number of captures fit in the static offsets vector buffer.
2207 // We have always at least one capture for the whole match, plus additional
2208 // ones due to capturing parentheses. A capture takes 2 registers.
2209 // The number of capture registers then is (number_of_captures + 1) * 2.
2211 UntagSmiFieldMemOperand(regexp_data,
2212 JSRegExp::kIrregexpCaptureCountOffset));
2213 // Check (number_of_captures + 1) * 2 <= offsets vector size
2214 // number_of_captures * 2 <= offsets vector size - 2
2215 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2216 __ Add(x10, x10, x10);
2217 __ Cmp(x10, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
2220 // Initialize offset for possibly sliced string.
2221 __ Mov(sliced_string_offset, 0);
2223 DCHECK(jssp.Is(__ StackPointer()));
2224 __ Peek(subject, kSubjectOffset);
2225 __ JumpIfSmi(subject, &runtime);
2227 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2228 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2230 __ Ldr(jsstring_length, FieldMemOperand(subject, String::kLengthOffset));
2232 // Handle subject string according to its encoding and representation:
2233 // (1) Sequential string? If yes, go to (5).
2234 // (2) Anything but sequential or cons? If yes, go to (6).
2235 // (3) Cons string. If the string is flat, replace subject with first string.
2236 // Otherwise bailout.
2237 // (4) Is subject external? If yes, go to (7).
2238 // (5) Sequential string. Load regexp code according to encoding.
2242 // Deferred code at the end of the stub:
2243 // (6) Not a long external string? If yes, go to (8).
2244 // (7) External string. Make it, offset-wise, look like a sequential string.
2246 // (8) Short external string or not a string? If yes, bail out to runtime.
2247 // (9) Sliced string. Replace subject with parent. Go to (4).
2249 Label check_underlying; // (4)
2250 Label seq_string; // (5)
2251 Label not_seq_nor_cons; // (6)
2252 Label external_string; // (7)
2253 Label not_long_external; // (8)
2255 // (1) Sequential string? If yes, go to (5).
2256 __ And(string_representation,
2259 kStringRepresentationMask |
2260 kShortExternalStringMask);
2261 // We depend on the fact that Strings of type
2262 // SeqString and not ShortExternalString are defined
2263 // by the following pattern:
2264 // string_type: 0XX0 XX00
2267 // | | is a SeqString
2268 // | is not a short external String
2270 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2271 STATIC_ASSERT(kShortExternalStringTag != 0);
2272 __ Cbz(string_representation, &seq_string); // Go to (5).
2274 // (2) Anything but sequential or cons? If yes, go to (6).
2275 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2276 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2277 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2278 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2279 __ Cmp(string_representation, kExternalStringTag);
2280 __ B(ge, ¬_seq_nor_cons); // Go to (6).
2282 // (3) Cons string. Check that it's flat.
2283 __ Ldr(x10, FieldMemOperand(subject, ConsString::kSecondOffset));
2284 __ JumpIfNotRoot(x10, Heap::kempty_stringRootIndex, &runtime);
2285 // Replace subject with first string.
2286 __ Ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2288 // (4) Is subject external? If yes, go to (7).
2289 __ Bind(&check_underlying);
2290 // Reload the string type.
2291 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2292 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2293 STATIC_ASSERT(kSeqStringTag == 0);
2294 // The underlying external string is never a short external string.
2295 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2296 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2297 __ TestAndBranchIfAnySet(string_type.X(),
2298 kStringRepresentationMask,
2299 &external_string); // Go to (7).
2301 // (5) Sequential string. Load regexp code according to encoding.
2302 __ Bind(&seq_string);
2304 // Check that the third argument is a positive smi less than the subject
2305 // string length. A negative value will be greater (unsigned comparison).
2306 DCHECK(jssp.Is(__ StackPointer()));
2307 __ Peek(x10, kPreviousIndexOffset);
2308 __ JumpIfNotSmi(x10, &runtime);
2309 __ Cmp(jsstring_length, x10);
2312 // Argument 2 (x1): We need to load argument 2 (the previous index) into x1
2313 // before entering the exit frame.
2314 __ SmiUntag(x1, x10);
2316 // The third bit determines the string encoding in string_type.
2317 STATIC_ASSERT(kOneByteStringTag == 0x04);
2318 STATIC_ASSERT(kTwoByteStringTag == 0x00);
2319 STATIC_ASSERT(kStringEncodingMask == 0x04);
2321 // Find the code object based on the assumptions above.
2322 // kDataOneByteCodeOffset and kDataUC16CodeOffset are adjacent, adds an offset
2323 // of kPointerSize to reach the latter.
2324 STATIC_ASSERT(JSRegExp::kDataOneByteCodeOffset + kPointerSize ==
2325 JSRegExp::kDataUC16CodeOffset);
2326 __ Mov(x10, kPointerSize);
2327 // We will need the encoding later: Latin1 = 0x04
2329 __ Ands(string_encoding, string_type, kStringEncodingMask);
2331 __ Add(x10, regexp_data, x10);
2332 __ Ldr(code_object, FieldMemOperand(x10, JSRegExp::kDataOneByteCodeOffset));
2334 // (E) Carry on. String handling is done.
2336 // Check that the irregexp code has been generated for the actual string
2337 // encoding. If it has, the field contains a code object otherwise it contains
2338 // a smi (code flushing support).
2339 __ JumpIfSmi(code_object, &runtime);
2341 // All checks done. Now push arguments for native regexp code.
2342 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1,
2346 // Isolates: note we add an additional parameter here (isolate pointer).
2347 __ EnterExitFrame(false, x10, 1);
2348 DCHECK(csp.Is(__ StackPointer()));
2350 // We have 9 arguments to pass to the regexp code, therefore we have to pass
2351 // one on the stack and the rest as registers.
2353 // Note that the placement of the argument on the stack isn't standard
2355 // csp[0]: Space for the return address placed by DirectCEntryStub.
2356 // csp[8]: Argument 9, the current isolate address.
2358 __ Mov(x10, ExternalReference::isolate_address(isolate()));
2359 __ Poke(x10, kPointerSize);
2361 Register length = w11;
2362 Register previous_index_in_bytes = w12;
2363 Register start = x13;
2365 // Load start of the subject string.
2366 __ Add(start, subject, SeqString::kHeaderSize - kHeapObjectTag);
2367 // Load the length from the original subject string from the previous stack
2368 // frame. Therefore we have to use fp, which points exactly to two pointer
2369 // sizes below the previous sp. (Because creating a new stack frame pushes
2370 // the previous fp onto the stack and decrements sp by 2 * kPointerSize.)
2371 __ Ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2372 __ Ldr(length, UntagSmiFieldMemOperand(subject, String::kLengthOffset));
2374 // Handle UC16 encoding, two bytes make one character.
2375 // string_encoding: if Latin1: 0x04
2377 STATIC_ASSERT(kStringEncodingMask == 0x04);
2378 __ Ubfx(string_encoding, string_encoding, 2, 1);
2379 __ Eor(string_encoding, string_encoding, 1);
2380 // string_encoding: if Latin1: 0
2383 // Convert string positions from characters to bytes.
2384 // Previous index is in x1.
2385 __ Lsl(previous_index_in_bytes, w1, string_encoding);
2386 __ Lsl(length, length, string_encoding);
2387 __ Lsl(sliced_string_offset, sliced_string_offset, string_encoding);
2389 // Argument 1 (x0): Subject string.
2390 __ Mov(x0, subject);
2392 // Argument 2 (x1): Previous index, already there.
2394 // Argument 3 (x2): Get the start of input.
2395 // Start of input = start of string + previous index + substring offset
2398 __ Add(w10, previous_index_in_bytes, sliced_string_offset);
2399 __ Add(x2, start, Operand(w10, UXTW));
2402 // End of input = start of input + (length of input - previous index)
2403 __ Sub(w10, length, previous_index_in_bytes);
2404 __ Add(x3, x2, Operand(w10, UXTW));
2406 // Argument 5 (x4): static offsets vector buffer.
2407 __ Mov(x4, ExternalReference::address_of_static_offsets_vector(isolate()));
2409 // Argument 6 (x5): Set the number of capture registers to zero to force
2410 // global regexps to behave as non-global. This stub is not used for global
2414 // Argument 7 (x6): Start (high end) of backtracking stack memory area.
2415 __ Mov(x10, address_of_regexp_stack_memory_address);
2416 __ Ldr(x10, MemOperand(x10));
2417 __ Mov(x11, address_of_regexp_stack_memory_size);
2418 __ Ldr(x11, MemOperand(x11));
2419 __ Add(x6, x10, x11);
2421 // Argument 8 (x7): Indicate that this is a direct call from JavaScript.
2424 // Locate the code entry and call it.
2425 __ Add(code_object, code_object, Code::kHeaderSize - kHeapObjectTag);
2426 DirectCEntryStub stub(isolate());
2427 stub.GenerateCall(masm, code_object);
2429 __ LeaveExitFrame(false, x10, true);
2431 // The generated regexp code returns an int32 in w0.
2432 Label failure, exception;
2433 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::FAILURE, eq, &failure);
2434 __ CompareAndBranch(w0,
2435 NativeRegExpMacroAssembler::EXCEPTION,
2438 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::RETRY, eq, &runtime);
2440 // Success: process the result from the native regexp code.
2441 Register number_of_capture_registers = x12;
2443 // Calculate number of capture registers (number_of_captures + 1) * 2
2444 // and store it in the last match info.
2446 UntagSmiFieldMemOperand(regexp_data,
2447 JSRegExp::kIrregexpCaptureCountOffset));
2448 __ Add(x10, x10, x10);
2449 __ Add(number_of_capture_registers, x10, 2);
2451 // Check that the fourth object is a JSArray object.
2452 DCHECK(jssp.Is(__ StackPointer()));
2453 __ Peek(x10, kLastMatchInfoOffset);
2454 __ JumpIfSmi(x10, &runtime);
2455 __ JumpIfNotObjectType(x10, x11, x11, JS_ARRAY_TYPE, &runtime);
2457 // Check that the JSArray is the fast case.
2458 __ Ldr(last_match_info_elements,
2459 FieldMemOperand(x10, JSArray::kElementsOffset));
2461 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2462 __ JumpIfNotRoot(x10, Heap::kFixedArrayMapRootIndex, &runtime);
2464 // Check that the last match info has space for the capture registers and the
2465 // additional information (overhead).
2466 // (number_of_captures + 1) * 2 + overhead <= last match info size
2467 // (number_of_captures * 2) + 2 + overhead <= last match info size
2468 // number_of_capture_registers + overhead <= last match info size
2470 UntagSmiFieldMemOperand(last_match_info_elements,
2471 FixedArray::kLengthOffset));
2472 __ Add(x11, number_of_capture_registers, RegExpImpl::kLastMatchOverhead);
2476 // Store the capture count.
2477 __ SmiTag(x10, number_of_capture_registers);
2479 FieldMemOperand(last_match_info_elements,
2480 RegExpImpl::kLastCaptureCountOffset));
2481 // Store last subject and last input.
2483 FieldMemOperand(last_match_info_elements,
2484 RegExpImpl::kLastSubjectOffset));
2485 // Use x10 as the subject string in order to only need
2486 // one RecordWriteStub.
2487 __ Mov(x10, subject);
2488 __ RecordWriteField(last_match_info_elements,
2489 RegExpImpl::kLastSubjectOffset,
2495 FieldMemOperand(last_match_info_elements,
2496 RegExpImpl::kLastInputOffset));
2497 __ Mov(x10, subject);
2498 __ RecordWriteField(last_match_info_elements,
2499 RegExpImpl::kLastInputOffset,
2505 Register last_match_offsets = x13;
2506 Register offsets_vector_index = x14;
2507 Register current_offset = x15;
2509 // Get the static offsets vector filled by the native regexp code
2510 // and fill the last match info.
2511 ExternalReference address_of_static_offsets_vector =
2512 ExternalReference::address_of_static_offsets_vector(isolate());
2513 __ Mov(offsets_vector_index, address_of_static_offsets_vector);
2515 Label next_capture, done;
2516 // Capture register counter starts from number of capture registers and
2517 // iterates down to zero (inclusive).
2518 __ Add(last_match_offsets,
2519 last_match_info_elements,
2520 RegExpImpl::kFirstCaptureOffset - kHeapObjectTag);
2521 __ Bind(&next_capture);
2522 __ Subs(number_of_capture_registers, number_of_capture_registers, 2);
2524 // Read two 32 bit values from the static offsets vector buffer into
2526 __ Ldr(current_offset,
2527 MemOperand(offsets_vector_index, kWRegSize * 2, PostIndex));
2528 // Store the smi values in the last match info.
2529 __ SmiTag(x10, current_offset);
2530 // Clearing the 32 bottom bits gives us a Smi.
2531 STATIC_ASSERT(kSmiTag == 0);
2532 __ Bic(x11, current_offset, kSmiShiftMask);
2535 MemOperand(last_match_offsets, kXRegSize * 2, PostIndex));
2536 __ B(&next_capture);
2539 // Return last match info.
2540 __ Peek(x0, kLastMatchInfoOffset);
2541 // Drop the 4 arguments of the stub from the stack.
2545 __ Bind(&exception);
2546 Register exception_value = x0;
2547 // A stack overflow (on the backtrack stack) may have occured
2548 // in the RegExp code but no exception has been created yet.
2549 // If there is no pending exception, handle that in the runtime system.
2550 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
2552 Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2554 __ Ldr(exception_value, MemOperand(x11));
2555 __ Cmp(x10, exception_value);
2558 // For exception, throw the exception again.
2559 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2562 __ Mov(x0, Operand(isolate()->factory()->null_value()));
2563 // Drop the 4 arguments of the stub from the stack.
2568 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2570 // Deferred code for string handling.
2571 // (6) Not a long external string? If yes, go to (8).
2572 __ Bind(¬_seq_nor_cons);
2573 // Compare flags are still set.
2574 __ B(ne, ¬_long_external); // Go to (8).
2576 // (7) External string. Make it, offset-wise, look like a sequential string.
2577 __ Bind(&external_string);
2578 if (masm->emit_debug_code()) {
2579 // Assert that we do not have a cons or slice (indirect strings) here.
2580 // Sequential strings have already been ruled out.
2581 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2582 __ Ldrb(x10, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2583 __ Tst(x10, kIsIndirectStringMask);
2584 __ Check(eq, kExternalStringExpectedButNotFound);
2585 __ And(x10, x10, kStringRepresentationMask);
2587 __ Check(ne, kExternalStringExpectedButNotFound);
2590 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2591 // Move the pointer so that offset-wise, it looks like a sequential string.
2592 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2593 __ Sub(subject, subject, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2594 __ B(&seq_string); // Go to (5).
2596 // (8) If this is a short external string or not a string, bail out to
2598 __ Bind(¬_long_external);
2599 STATIC_ASSERT(kShortExternalStringTag != 0);
2600 __ TestAndBranchIfAnySet(string_representation,
2601 kShortExternalStringMask | kIsNotStringMask,
2604 // (9) Sliced string. Replace subject with parent.
2605 __ Ldr(sliced_string_offset,
2606 UntagSmiFieldMemOperand(subject, SlicedString::kOffsetOffset));
2607 __ Ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2608 __ B(&check_underlying); // Go to (4).
2613 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2614 Register argc, Register function,
2615 Register feedback_vector, Register index,
2616 Register orig_construct, bool is_super) {
2617 FrameScope scope(masm, StackFrame::INTERNAL);
2619 // Number-of-arguments register must be smi-tagged to call out.
2622 __ Push(argc, function, feedback_vector, index, orig_construct);
2624 __ Push(argc, function, feedback_vector, index);
2627 DCHECK(feedback_vector.Is(x2) && index.Is(x3));
2631 __ Pop(orig_construct, index, feedback_vector, function, argc);
2633 __ Pop(index, feedback_vector, function, argc);
2639 static void GenerateRecordCallTarget(MacroAssembler* masm, Register argc,
2641 Register feedback_vector, Register index,
2642 Register orig_construct, Register scratch1,
2643 Register scratch2, Register scratch3,
2645 ASM_LOCATION("GenerateRecordCallTarget");
2646 DCHECK(!AreAliased(scratch1, scratch2, scratch3, argc, function,
2647 feedback_vector, index, orig_construct));
2648 // Cache the called function in a feedback vector slot. Cache states are
2649 // uninitialized, monomorphic (indicated by a JSFunction), and megamorphic.
2650 // argc : number of arguments to the construct function
2651 // function : the function to call
2652 // feedback_vector : the feedback vector
2653 // index : slot in feedback vector (smi)
2654 // orig_construct : original constructor (for IsSuperConstructorCall)
2655 Label initialize, done, miss, megamorphic, not_array_function;
2657 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2658 masm->isolate()->heap()->megamorphic_symbol());
2659 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2660 masm->isolate()->heap()->uninitialized_symbol());
2662 // Load the cache state.
2663 Register feedback = scratch1;
2664 Register feedback_map = scratch2;
2665 Register feedback_value = scratch3;
2666 __ Add(feedback, feedback_vector,
2667 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2668 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
2670 // A monomorphic cache hit or an already megamorphic state: invoke the
2671 // function without changing the state.
2672 // We don't know if feedback value is a WeakCell or a Symbol, but it's
2673 // harmless to read at this position in a symbol (see static asserts in
2674 // type-feedback-vector.h).
2675 Label check_allocation_site;
2676 __ Ldr(feedback_value, FieldMemOperand(feedback, WeakCell::kValueOffset));
2677 __ Cmp(function, feedback_value);
2679 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
2681 __ Ldr(feedback_map, FieldMemOperand(feedback, HeapObject::kMapOffset));
2682 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2683 __ B(ne, &check_allocation_site);
2685 // If the weak cell is cleared, we have a new chance to become monomorphic.
2686 __ JumpIfSmi(feedback_value, &initialize);
2689 __ bind(&check_allocation_site);
2690 // If we came here, we need to see if we are the array function.
2691 // If we didn't have a matching function, and we didn't find the megamorph
2692 // sentinel, then we have in the slot either some other function or an
2694 __ JumpIfNotRoot(feedback_map, Heap::kAllocationSiteMapRootIndex, &miss);
2696 // Make sure the function is the Array() function
2697 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2698 __ Cmp(function, scratch1);
2699 __ B(ne, &megamorphic);
2704 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2706 __ JumpIfRoot(scratch1, Heap::kuninitialized_symbolRootIndex, &initialize);
2707 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2708 // write-barrier is needed.
2709 __ Bind(&megamorphic);
2710 __ Add(scratch1, feedback_vector,
2711 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2712 __ LoadRoot(scratch2, Heap::kmegamorphic_symbolRootIndex);
2713 __ Str(scratch2, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
2716 // An uninitialized cache is patched with the function or sentinel to
2717 // indicate the ElementsKind if function is the Array constructor.
2718 __ Bind(&initialize);
2720 // Make sure the function is the Array() function
2721 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2722 __ Cmp(function, scratch1);
2723 __ B(ne, ¬_array_function);
2725 // The target function is the Array constructor,
2726 // Create an AllocationSite if we don't already have it, store it in the
2728 CreateAllocationSiteStub create_stub(masm->isolate());
2729 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2730 feedback_vector, index, orig_construct, is_super);
2733 __ Bind(¬_array_function);
2734 CreateWeakCellStub weak_cell_stub(masm->isolate());
2735 CallStubInRecordCallTarget(masm, &weak_cell_stub, argc, function,
2736 feedback_vector, index, orig_construct, is_super);
2741 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2742 // Do not transform the receiver for strict mode functions.
2743 __ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
2744 __ Ldr(w4, FieldMemOperand(x3, SharedFunctionInfo::kCompilerHintsOffset));
2745 __ Tbnz(w4, SharedFunctionInfo::kStrictModeFunction, cont);
2747 // Do not transform the receiver for native (Compilerhints already in x3).
2748 __ Tbnz(w4, SharedFunctionInfo::kNative, cont);
2752 static void EmitSlowCase(MacroAssembler* masm, int argc) {
2754 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2758 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2759 // Wrap the receiver and patch it back onto the stack.
2760 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2763 ToObjectStub stub(masm->isolate());
2767 __ Poke(x0, argc * kPointerSize);
2772 static void CallFunctionNoFeedback(MacroAssembler* masm,
2773 int argc, bool needs_checks,
2774 bool call_as_method) {
2775 // x1 function the function to call
2776 Register function = x1;
2778 Label slow, wrap, cont;
2780 // TODO(jbramley): This function has a lot of unnamed registers. Name them,
2781 // and tidy things up a bit.
2784 // Check that the function is really a JavaScript function.
2785 __ JumpIfSmi(function, &slow);
2787 // Goto slow case if we do not have a function.
2788 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
2791 // Fast-case: Invoke the function now.
2792 // x1 function pushed function
2793 ParameterCount actual(argc);
2795 if (call_as_method) {
2797 EmitContinueIfStrictOrNative(masm, &cont);
2800 // Compute the receiver in sloppy mode.
2801 __ Peek(x3, argc * kPointerSize);
2804 __ JumpIfSmi(x3, &wrap);
2805 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
2813 __ InvokeFunction(function,
2818 // Slow-case: Non-function called.
2820 EmitSlowCase(masm, argc);
2823 if (call_as_method) {
2825 EmitWrapCase(masm, argc, &cont);
2830 void CallFunctionStub::Generate(MacroAssembler* masm) {
2831 ASM_LOCATION("CallFunctionStub::Generate");
2832 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2836 void CallConstructStub::Generate(MacroAssembler* masm) {
2837 ASM_LOCATION("CallConstructStub::Generate");
2838 // x0 : number of arguments
2839 // x1 : the function to call
2840 // x2 : feedback vector
2841 // x3 : slot in feedback vector (Smi, for RecordCallTarget)
2842 // x4 : original constructor (for IsSuperConstructorCall)
2843 Register function = x1;
2844 Label slow, non_function_call;
2846 // Check that the function is not a smi.
2847 __ JumpIfSmi(function, &non_function_call);
2848 // Check that the function is a JSFunction.
2849 Register object_type = x10;
2850 __ JumpIfNotObjectType(function, object_type, object_type, JS_FUNCTION_TYPE,
2853 if (RecordCallTarget()) {
2854 GenerateRecordCallTarget(masm, x0, function, x2, x3, x4, x5, x11, x12,
2855 IsSuperConstructorCall());
2857 __ Add(x5, x2, Operand::UntagSmiAndScale(x3, kPointerSizeLog2));
2858 Label feedback_register_initialized;
2859 // Put the AllocationSite from the feedback vector into x2, or undefined.
2860 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize));
2861 __ Ldr(x5, FieldMemOperand(x2, AllocationSite::kMapOffset));
2862 __ JumpIfRoot(x5, Heap::kAllocationSiteMapRootIndex,
2863 &feedback_register_initialized);
2864 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
2865 __ bind(&feedback_register_initialized);
2867 __ AssertUndefinedOrAllocationSite(x2, x5);
2870 if (IsSuperConstructorCall()) {
2873 __ Mov(x3, function);
2876 // Jump to the function-specific construct stub.
2877 Register jump_reg = x4;
2878 Register shared_func_info = jump_reg;
2879 Register cons_stub = jump_reg;
2880 Register cons_stub_code = jump_reg;
2881 __ Ldr(shared_func_info,
2882 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
2884 FieldMemOperand(shared_func_info,
2885 SharedFunctionInfo::kConstructStubOffset));
2886 __ Add(cons_stub_code, cons_stub, Code::kHeaderSize - kHeapObjectTag);
2887 __ Br(cons_stub_code);
2891 __ Cmp(object_type, JS_FUNCTION_PROXY_TYPE);
2892 __ B(ne, &non_function_call);
2893 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies.
2894 __ Ldr(x1, FieldMemOperand(x1, JSFunctionProxy::kConstructTrapOffset));
2895 __ Jump(isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2897 __ Bind(&non_function_call);
2899 // Determine the delegate for the target (if any).
2900 FrameScope scope(masm, StackFrame::INTERNAL);
2903 __ CallRuntime(Runtime::kGetConstructorDelegate, 1);
2908 // The delegate is always a regular function.
2909 __ AssertFunction(x1);
2910 __ Jump(masm->isolate()->builtins()->CallFunction(),
2911 RelocInfo::CODE_TARGET);
2916 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2917 __ Ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2918 __ Ldr(vector, FieldMemOperand(vector,
2919 JSFunction::kSharedFunctionInfoOffset));
2920 __ Ldr(vector, FieldMemOperand(vector,
2921 SharedFunctionInfo::kFeedbackVectorOffset));
2925 void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
2929 // x4 - allocation site (loaded from vector[slot])
2930 Register function = x1;
2931 Register feedback_vector = x2;
2932 Register index = x3;
2933 Register allocation_site = x4;
2934 Register scratch = x5;
2936 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch);
2937 __ Cmp(function, scratch);
2940 __ Mov(x0, Operand(arg_count()));
2942 // Increment the call count for monomorphic function calls.
2943 __ Add(feedback_vector, feedback_vector,
2944 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2945 __ Add(feedback_vector, feedback_vector,
2946 Operand(FixedArray::kHeaderSize + kPointerSize));
2947 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
2948 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2949 __ Str(index, FieldMemOperand(feedback_vector, 0));
2951 // Set up arguments for the array constructor stub.
2952 Register allocation_site_arg = feedback_vector;
2953 Register original_constructor_arg = index;
2954 __ Mov(allocation_site_arg, allocation_site);
2955 __ Mov(original_constructor_arg, function);
2956 ArrayConstructorStub stub(masm->isolate(), arg_count());
2957 __ TailCallStub(&stub);
2961 void CallICStub::Generate(MacroAssembler* masm) {
2962 ASM_LOCATION("CallICStub");
2965 // x3 - slot id (Smi)
2967 const int with_types_offset =
2968 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2969 const int generic_offset =
2970 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2971 Label extra_checks_or_miss, slow_start;
2972 Label slow, wrap, cont;
2973 Label have_js_function;
2974 int argc = arg_count();
2975 ParameterCount actual(argc);
2977 Register function = x1;
2978 Register feedback_vector = x2;
2979 Register index = x3;
2982 // The checks. First, does x1 match the recorded monomorphic target?
2983 __ Add(x4, feedback_vector,
2984 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2985 __ Ldr(x4, FieldMemOperand(x4, FixedArray::kHeaderSize));
2987 // We don't know that we have a weak cell. We might have a private symbol
2988 // or an AllocationSite, but the memory is safe to examine.
2989 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2991 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2992 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2993 // computed, meaning that it can't appear to be a pointer. If the low bit is
2994 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2996 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2997 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2998 WeakCell::kValueOffset &&
2999 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
3001 __ Ldr(x5, FieldMemOperand(x4, WeakCell::kValueOffset));
3002 __ Cmp(x5, function);
3003 __ B(ne, &extra_checks_or_miss);
3005 // The compare above could have been a SMI/SMI comparison. Guard against this
3006 // convincing us that we have a monomorphic JSFunction.
3007 __ JumpIfSmi(function, &extra_checks_or_miss);
3009 // Increment the call count for monomorphic function calls.
3010 __ Add(feedback_vector, feedback_vector,
3011 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3012 __ Add(feedback_vector, feedback_vector,
3013 Operand(FixedArray::kHeaderSize + kPointerSize));
3014 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
3015 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3016 __ Str(index, FieldMemOperand(feedback_vector, 0));
3018 __ bind(&have_js_function);
3019 if (CallAsMethod()) {
3020 EmitContinueIfStrictOrNative(masm, &cont);
3022 // Compute the receiver in sloppy mode.
3023 __ Peek(x3, argc * kPointerSize);
3025 __ JumpIfSmi(x3, &wrap);
3026 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
3031 __ InvokeFunction(function,
3037 EmitSlowCase(masm, argc);
3039 if (CallAsMethod()) {
3041 EmitWrapCase(masm, argc, &cont);
3044 __ bind(&extra_checks_or_miss);
3045 Label uninitialized, miss, not_allocation_site;
3047 __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &slow_start);
3049 __ Ldr(x5, FieldMemOperand(x4, HeapObject::kMapOffset));
3050 __ JumpIfNotRoot(x5, Heap::kAllocationSiteMapRootIndex, ¬_allocation_site);
3052 HandleArrayCase(masm, &miss);
3054 __ bind(¬_allocation_site);
3056 // The following cases attempt to handle MISS cases without going to the
3058 if (FLAG_trace_ic) {
3062 __ JumpIfRoot(x4, Heap::kuninitialized_symbolRootIndex, &miss);
3064 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3065 // to handle it here. More complex cases are dealt with in the runtime.
3066 __ AssertNotSmi(x4);
3067 __ JumpIfNotObjectType(x4, x5, x5, JS_FUNCTION_TYPE, &miss);
3068 __ Add(x4, feedback_vector,
3069 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3070 __ LoadRoot(x5, Heap::kmegamorphic_symbolRootIndex);
3071 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize));
3072 // We have to update statistics for runtime profiling.
3073 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3074 __ Subs(x4, x4, Operand(Smi::FromInt(1)));
3075 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3076 __ Ldr(x4, FieldMemOperand(feedback_vector, generic_offset));
3077 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3078 __ Str(x4, FieldMemOperand(feedback_vector, generic_offset));
3081 __ bind(&uninitialized);
3083 // We are going monomorphic, provided we actually have a JSFunction.
3084 __ JumpIfSmi(function, &miss);
3086 // Goto miss case if we do not have a function.
3087 __ JumpIfNotObjectType(function, x5, x5, JS_FUNCTION_TYPE, &miss);
3089 // Make sure the function is not the Array() function, which requires special
3090 // behavior on MISS.
3091 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, x5);
3092 __ Cmp(function, x5);
3096 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3097 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3098 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3100 // Initialize the call counter.
3101 __ Mov(x5, Smi::FromInt(CallICNexus::kCallCountIncrement));
3102 __ Adds(x4, feedback_vector,
3103 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3104 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize + kPointerSize));
3106 // Store the function. Use a stub since we need a frame for allocation.
3111 FrameScope scope(masm, StackFrame::INTERNAL);
3112 CreateWeakCellStub create_stub(masm->isolate());
3114 __ CallStub(&create_stub);
3118 __ B(&have_js_function);
3120 // We are here because tracing is on or we encountered a MISS case we can't
3126 __ bind(&slow_start);
3128 // Check that the function is really a JavaScript function.
3129 __ JumpIfSmi(function, &slow);
3131 // Goto slow case if we do not have a function.
3132 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
3133 __ B(&have_js_function);
3137 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3138 ASM_LOCATION("CallICStub[Miss]");
3140 FrameScope scope(masm, StackFrame::INTERNAL);
3142 // Push the receiver and the function and feedback info.
3143 __ Push(x1, x2, x3);
3146 __ CallRuntime(Runtime::kCallIC_Miss, 3);
3148 // Move result to edi and exit the internal frame.
3153 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3154 // If the receiver is a smi trigger the non-string case.
3155 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3156 __ JumpIfSmi(object_, receiver_not_string_);
3158 // Fetch the instance type of the receiver into result register.
3159 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3160 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3162 // If the receiver is not a string trigger the non-string case.
3163 __ TestAndBranchIfAnySet(result_, kIsNotStringMask, receiver_not_string_);
3166 // If the index is non-smi trigger the non-smi case.
3167 __ JumpIfNotSmi(index_, &index_not_smi_);
3169 __ Bind(&got_smi_index_);
3170 // Check for index out of range.
3171 __ Ldrsw(result_, UntagSmiFieldMemOperand(object_, String::kLengthOffset));
3172 __ Cmp(result_, Operand::UntagSmi(index_));
3173 __ B(ls, index_out_of_range_);
3175 __ SmiUntag(index_);
3177 StringCharLoadGenerator::Generate(masm,
3187 void StringCharCodeAtGenerator::GenerateSlow(
3188 MacroAssembler* masm, EmbedMode embed_mode,
3189 const RuntimeCallHelper& call_helper) {
3190 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3192 __ Bind(&index_not_smi_);
3193 // If index is a heap number, try converting it to an integer.
3194 __ JumpIfNotHeapNumber(index_, index_not_number_);
3195 call_helper.BeforeCall(masm);
3196 if (embed_mode == PART_OF_IC_HANDLER) {
3197 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3198 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3200 // Save object_ on the stack and pass index_ as argument for runtime call.
3201 __ Push(object_, index_);
3203 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3204 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3206 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3207 // NumberToSmi discards numbers that are not exact integers.
3208 __ CallRuntime(Runtime::kNumberToSmi, 1);
3210 // Save the conversion result before the pop instructions below
3211 // have a chance to overwrite it.
3213 if (embed_mode == PART_OF_IC_HANDLER) {
3214 __ Pop(object_, LoadWithVectorDescriptor::SlotRegister(),
3215 LoadWithVectorDescriptor::VectorRegister());
3219 // Reload the instance type.
3220 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3221 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3222 call_helper.AfterCall(masm);
3224 // If index is still not a smi, it must be out of range.
3225 __ JumpIfNotSmi(index_, index_out_of_range_);
3226 // Otherwise, return to the fast path.
3227 __ B(&got_smi_index_);
3229 // Call runtime. We get here when the receiver is a string and the
3230 // index is a number, but the code of getting the actual character
3231 // is too complex (e.g., when the string needs to be flattened).
3232 __ Bind(&call_runtime_);
3233 call_helper.BeforeCall(masm);
3235 __ Push(object_, index_);
3236 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3237 __ Mov(result_, x0);
3238 call_helper.AfterCall(masm);
3241 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3245 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3246 __ JumpIfNotSmi(code_, &slow_case_);
3247 __ Cmp(code_, Smi::FromInt(String::kMaxOneByteCharCode));
3248 __ B(hi, &slow_case_);
3250 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3251 // At this point code register contains smi tagged one-byte char code.
3252 __ Add(result_, result_, Operand::UntagSmiAndScale(code_, kPointerSizeLog2));
3253 __ Ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3254 __ JumpIfRoot(result_, Heap::kUndefinedValueRootIndex, &slow_case_);
3259 void StringCharFromCodeGenerator::GenerateSlow(
3260 MacroAssembler* masm,
3261 const RuntimeCallHelper& call_helper) {
3262 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3264 __ Bind(&slow_case_);
3265 call_helper.BeforeCall(masm);
3267 __ CallRuntime(Runtime::kCharFromCode, 1);
3268 __ Mov(result_, x0);
3269 call_helper.AfterCall(masm);
3272 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3276 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3277 // Inputs are in x0 (lhs) and x1 (rhs).
3278 DCHECK(state() == CompareICState::SMI);
3279 ASM_LOCATION("CompareICStub[Smis]");
3281 // Bail out (to 'miss') unless both x0 and x1 are smis.
3282 __ JumpIfEitherNotSmi(x0, x1, &miss);
3284 if (GetCondition() == eq) {
3285 // For equality we do not care about the sign of the result.
3288 // Untag before subtracting to avoid handling overflow.
3290 __ Sub(x0, x1, Operand::UntagSmi(x0));
3299 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3300 DCHECK(state() == CompareICState::NUMBER);
3301 ASM_LOCATION("CompareICStub[HeapNumbers]");
3303 Label unordered, maybe_undefined1, maybe_undefined2;
3304 Label miss, handle_lhs, values_in_d_regs;
3305 Label untag_rhs, untag_lhs;
3307 Register result = x0;
3310 FPRegister rhs_d = d0;
3311 FPRegister lhs_d = d1;
3313 if (left() == CompareICState::SMI) {
3314 __ JumpIfNotSmi(lhs, &miss);
3316 if (right() == CompareICState::SMI) {
3317 __ JumpIfNotSmi(rhs, &miss);
3320 __ SmiUntagToDouble(rhs_d, rhs, kSpeculativeUntag);
3321 __ SmiUntagToDouble(lhs_d, lhs, kSpeculativeUntag);
3323 // Load rhs if it's a heap number.
3324 __ JumpIfSmi(rhs, &handle_lhs);
3325 __ JumpIfNotHeapNumber(rhs, &maybe_undefined1);
3326 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
3328 // Load lhs if it's a heap number.
3329 __ Bind(&handle_lhs);
3330 __ JumpIfSmi(lhs, &values_in_d_regs);
3331 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3332 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
3334 __ Bind(&values_in_d_regs);
3335 __ Fcmp(lhs_d, rhs_d);
3336 __ B(vs, &unordered); // Overflow flag set if either is NaN.
3337 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
3338 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
3339 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
3342 __ Bind(&unordered);
3343 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3344 CompareICState::GENERIC, CompareICState::GENERIC);
3345 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3347 __ Bind(&maybe_undefined1);
3348 if (Token::IsOrderedRelationalCompareOp(op())) {
3349 __ JumpIfNotRoot(rhs, Heap::kUndefinedValueRootIndex, &miss);
3350 __ JumpIfSmi(lhs, &unordered);
3351 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3355 __ Bind(&maybe_undefined2);
3356 if (Token::IsOrderedRelationalCompareOp(op())) {
3357 __ JumpIfRoot(lhs, Heap::kUndefinedValueRootIndex, &unordered);
3365 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3366 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3367 ASM_LOCATION("CompareICStub[InternalizedStrings]");
3370 Register result = x0;
3374 // Check that both operands are heap objects.
3375 __ JumpIfEitherSmi(lhs, rhs, &miss);
3377 // Check that both operands are internalized strings.
3378 Register rhs_map = x10;
3379 Register lhs_map = x11;
3380 Register rhs_type = x10;
3381 Register lhs_type = x11;
3382 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3383 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3384 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3385 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3387 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
3388 __ Orr(x12, lhs_type, rhs_type);
3389 __ TestAndBranchIfAnySet(
3390 x12, kIsNotStringMask | kIsNotInternalizedMask, &miss);
3392 // Internalized strings are compared by identity.
3393 STATIC_ASSERT(EQUAL == 0);
3395 __ Cset(result, ne);
3403 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3404 DCHECK(state() == CompareICState::UNIQUE_NAME);
3405 ASM_LOCATION("CompareICStub[UniqueNames]");
3406 DCHECK(GetCondition() == eq);
3409 Register result = x0;
3413 Register lhs_instance_type = w2;
3414 Register rhs_instance_type = w3;
3416 // Check that both operands are heap objects.
3417 __ JumpIfEitherSmi(lhs, rhs, &miss);
3419 // Check that both operands are unique names. This leaves the instance
3420 // types loaded in tmp1 and tmp2.
3421 __ Ldr(x10, FieldMemOperand(lhs, HeapObject::kMapOffset));
3422 __ Ldr(x11, FieldMemOperand(rhs, HeapObject::kMapOffset));
3423 __ Ldrb(lhs_instance_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
3424 __ Ldrb(rhs_instance_type, FieldMemOperand(x11, Map::kInstanceTypeOffset));
3426 // To avoid a miss, each instance type should be either SYMBOL_TYPE or it
3427 // should have kInternalizedTag set.
3428 __ JumpIfNotUniqueNameInstanceType(lhs_instance_type, &miss);
3429 __ JumpIfNotUniqueNameInstanceType(rhs_instance_type, &miss);
3431 // Unique names are compared by identity.
3432 STATIC_ASSERT(EQUAL == 0);
3434 __ Cset(result, ne);
3442 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3443 DCHECK(state() == CompareICState::STRING);
3444 ASM_LOCATION("CompareICStub[Strings]");
3448 bool equality = Token::IsEqualityOp(op());
3450 Register result = x0;
3454 // Check that both operands are heap objects.
3455 __ JumpIfEitherSmi(rhs, lhs, &miss);
3457 // Check that both operands are strings.
3458 Register rhs_map = x10;
3459 Register lhs_map = x11;
3460 Register rhs_type = x10;
3461 Register lhs_type = x11;
3462 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3463 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3464 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3465 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3466 STATIC_ASSERT(kNotStringTag != 0);
3467 __ Orr(x12, lhs_type, rhs_type);
3468 __ Tbnz(x12, MaskToBit(kIsNotStringMask), &miss);
3470 // Fast check for identical strings.
3473 __ B(ne, ¬_equal);
3474 __ Mov(result, EQUAL);
3477 __ Bind(¬_equal);
3478 // Handle not identical strings
3480 // Check that both strings are internalized strings. If they are, we're done
3481 // because we already know they are not identical. We know they are both
3484 DCHECK(GetCondition() == eq);
3485 STATIC_ASSERT(kInternalizedTag == 0);
3486 Label not_internalized_strings;
3487 __ Orr(x12, lhs_type, rhs_type);
3488 __ TestAndBranchIfAnySet(
3489 x12, kIsNotInternalizedMask, ¬_internalized_strings);
3490 // Result is in rhs (x0), and not EQUAL, as rhs is not a smi.
3492 __ Bind(¬_internalized_strings);
3495 // Check that both strings are sequential one-byte.
3497 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x12,
3500 // Compare flat one-byte strings. Returns when done.
3502 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
3505 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
3509 // Handle more complex cases in runtime.
3513 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3515 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3523 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3524 DCHECK(state() == CompareICState::OBJECT);
3525 ASM_LOCATION("CompareICStub[Objects]");
3529 Register result = x0;
3533 __ JumpIfEitherSmi(rhs, lhs, &miss);
3535 __ JumpIfNotObjectType(rhs, x10, x10, JS_OBJECT_TYPE, &miss);
3536 __ JumpIfNotObjectType(lhs, x10, x10, JS_OBJECT_TYPE, &miss);
3538 DCHECK(GetCondition() == eq);
3539 __ Sub(result, rhs, lhs);
3547 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3548 ASM_LOCATION("CompareICStub[KnownObjects]");
3551 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3553 Register result = x0;
3557 __ JumpIfEitherSmi(rhs, lhs, &miss);
3559 Register rhs_map = x10;
3560 Register lhs_map = x11;
3562 __ GetWeakValue(map, cell);
3563 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3564 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3565 __ Cmp(rhs_map, map);
3567 __ Cmp(lhs_map, map);
3570 if (Token::IsEqualityOp(op())) {
3571 __ Sub(result, rhs, lhs);
3573 } else if (is_strong(strength())) {
3574 __ TailCallRuntime(Runtime::kThrowStrongModeImplicitConversion, 0, 1);
3577 if (op() == Token::LT || op() == Token::LTE) {
3578 __ Mov(ncr, Smi::FromInt(GREATER));
3580 __ Mov(ncr, Smi::FromInt(LESS));
3582 __ Push(lhs, rhs, ncr);
3583 __ TailCallRuntime(Runtime::kCompare, 3, 1);
3591 // This method handles the case where a compare stub had the wrong
3592 // implementation. It calls a miss handler, which re-writes the stub. All other
3593 // CompareICStub::Generate* methods should fall back into this one if their
3594 // operands were not the expected types.
3595 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3596 ASM_LOCATION("CompareICStub[Miss]");
3598 Register stub_entry = x11;
3600 FrameScope scope(masm, StackFrame::INTERNAL);
3603 Register right = x0;
3604 // Preserve some caller-saved registers.
3605 __ Push(x1, x0, lr);
3606 // Push the arguments.
3607 __ Mov(op, Smi::FromInt(this->op()));
3608 __ Push(left, right, op);
3610 // Call the miss handler. This also pops the arguments.
3611 __ CallRuntime(Runtime::kCompareIC_Miss, 3);
3613 // Compute the entry point of the rewritten stub.
3614 __ Add(stub_entry, x0, Code::kHeaderSize - kHeapObjectTag);
3615 // Restore caller-saved registers.
3619 // Tail-call to the new stub.
3620 __ Jump(stub_entry);
3624 void SubStringStub::Generate(MacroAssembler* masm) {
3625 ASM_LOCATION("SubStringStub::Generate");
3628 // Stack frame on entry.
3629 // lr: return address
3630 // jssp[0]: substring "to" offset
3631 // jssp[8]: substring "from" offset
3632 // jssp[16]: pointer to string object
3634 // This stub is called from the native-call %_SubString(...), so
3635 // nothing can be assumed about the arguments. It is tested that:
3636 // "string" is a sequential string,
3637 // both "from" and "to" are smis, and
3638 // 0 <= from <= to <= string.length (in debug mode.)
3639 // If any of these assumptions fail, we call the runtime system.
3641 static const int kToOffset = 0 * kPointerSize;
3642 static const int kFromOffset = 1 * kPointerSize;
3643 static const int kStringOffset = 2 * kPointerSize;
3646 Register from = x15;
3647 Register input_string = x10;
3648 Register input_length = x11;
3649 Register input_type = x12;
3650 Register result_string = x0;
3651 Register result_length = x1;
3654 __ Peek(to, kToOffset);
3655 __ Peek(from, kFromOffset);
3657 // Check that both from and to are smis. If not, jump to runtime.
3658 __ JumpIfEitherNotSmi(from, to, &runtime);
3662 // Calculate difference between from and to. If to < from, branch to runtime.
3663 __ Subs(result_length, to, from);
3666 // Check from is positive.
3667 __ Tbnz(from, kWSignBit, &runtime);
3669 // Make sure first argument is a string.
3670 __ Peek(input_string, kStringOffset);
3671 __ JumpIfSmi(input_string, &runtime);
3672 __ IsObjectJSStringType(input_string, input_type, &runtime);
3675 __ Cmp(result_length, 1);
3676 __ B(eq, &single_char);
3678 // Short-cut for the case of trivial substring.
3680 __ Ldrsw(input_length,
3681 UntagSmiFieldMemOperand(input_string, String::kLengthOffset));
3683 __ Cmp(result_length, input_length);
3684 __ CmovX(x0, input_string, eq);
3685 // Return original string.
3686 __ B(eq, &return_x0);
3688 // Longer than original string's length or negative: unsafe arguments.
3691 // Shorter than original string's length: an actual substring.
3693 // x0 to substring end character offset
3694 // x1 result_length length of substring result
3695 // x10 input_string pointer to input string object
3696 // x10 unpacked_string pointer to unpacked string object
3697 // x11 input_length length of input string
3698 // x12 input_type instance type of input string
3699 // x15 from substring start character offset
3701 // Deal with different string types: update the index if necessary and put
3702 // the underlying string into register unpacked_string.
3703 Label underlying_unpacked, sliced_string, seq_or_external_string;
3704 Label update_instance_type;
3705 // If the string is not indirect, it can only be sequential or external.
3706 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3707 STATIC_ASSERT(kIsIndirectStringMask != 0);
3709 // Test for string types, and branch/fall through to appropriate unpacking
3711 __ Tst(input_type, kIsIndirectStringMask);
3712 __ B(eq, &seq_or_external_string);
3713 __ Tst(input_type, kSlicedNotConsMask);
3714 __ B(ne, &sliced_string);
3716 Register unpacked_string = input_string;
3718 // Cons string. Check whether it is flat, then fetch first part.
3719 __ Ldr(temp, FieldMemOperand(input_string, ConsString::kSecondOffset));
3720 __ JumpIfNotRoot(temp, Heap::kempty_stringRootIndex, &runtime);
3721 __ Ldr(unpacked_string,
3722 FieldMemOperand(input_string, ConsString::kFirstOffset));
3723 __ B(&update_instance_type);
3725 __ Bind(&sliced_string);
3726 // Sliced string. Fetch parent and correct start index by offset.
3728 UntagSmiFieldMemOperand(input_string, SlicedString::kOffsetOffset));
3729 __ Add(from, from, temp);
3730 __ Ldr(unpacked_string,
3731 FieldMemOperand(input_string, SlicedString::kParentOffset));
3733 __ Bind(&update_instance_type);
3734 __ Ldr(temp, FieldMemOperand(unpacked_string, HeapObject::kMapOffset));
3735 __ Ldrb(input_type, FieldMemOperand(temp, Map::kInstanceTypeOffset));
3736 // Now control must go to &underlying_unpacked. Since the no code is generated
3737 // before then we fall through instead of generating a useless branch.
3739 __ Bind(&seq_or_external_string);
3740 // Sequential or external string. Registers unpacked_string and input_string
3741 // alias, so there's nothing to do here.
3742 // Note that if code is added here, the above code must be updated.
3744 // x0 result_string pointer to result string object (uninit)
3745 // x1 result_length length of substring result
3746 // x10 unpacked_string pointer to unpacked string object
3747 // x11 input_length length of input string
3748 // x12 input_type instance type of input string
3749 // x15 from substring start character offset
3750 __ Bind(&underlying_unpacked);
3752 if (FLAG_string_slices) {
3754 __ Cmp(result_length, SlicedString::kMinLength);
3755 // Short slice. Copy instead of slicing.
3756 __ B(lt, ©_routine);
3757 // Allocate new sliced string. At this point we do not reload the instance
3758 // type including the string encoding because we simply rely on the info
3759 // provided by the original string. It does not matter if the original
3760 // string's encoding is wrong because we always have to recheck encoding of
3761 // the newly created string's parent anyway due to externalized strings.
3762 Label two_byte_slice, set_slice_header;
3763 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3764 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3765 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_slice);
3766 __ AllocateOneByteSlicedString(result_string, result_length, x3, x4,
3768 __ B(&set_slice_header);
3770 __ Bind(&two_byte_slice);
3771 __ AllocateTwoByteSlicedString(result_string, result_length, x3, x4,
3774 __ Bind(&set_slice_header);
3776 __ Str(from, FieldMemOperand(result_string, SlicedString::kOffsetOffset));
3777 __ Str(unpacked_string,
3778 FieldMemOperand(result_string, SlicedString::kParentOffset));
3781 __ Bind(©_routine);
3784 // x0 result_string pointer to result string object (uninit)
3785 // x1 result_length length of substring result
3786 // x10 unpacked_string pointer to unpacked string object
3787 // x11 input_length length of input string
3788 // x12 input_type instance type of input string
3789 // x13 unpacked_char0 pointer to first char of unpacked string (uninit)
3790 // x13 substring_char0 pointer to first char of substring (uninit)
3791 // x14 result_char0 pointer to first char of result (uninit)
3792 // x15 from substring start character offset
3793 Register unpacked_char0 = x13;
3794 Register substring_char0 = x13;
3795 Register result_char0 = x14;
3796 Label two_byte_sequential, sequential_string, allocate_result;
3797 STATIC_ASSERT(kExternalStringTag != 0);
3798 STATIC_ASSERT(kSeqStringTag == 0);
3800 __ Tst(input_type, kExternalStringTag);
3801 __ B(eq, &sequential_string);
3803 __ Tst(input_type, kShortExternalStringTag);
3805 __ Ldr(unpacked_char0,
3806 FieldMemOperand(unpacked_string, ExternalString::kResourceDataOffset));
3807 // unpacked_char0 points to the first character of the underlying string.
3808 __ B(&allocate_result);
3810 __ Bind(&sequential_string);
3811 // Locate first character of underlying subject string.
3812 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3813 __ Add(unpacked_char0, unpacked_string,
3814 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3816 __ Bind(&allocate_result);
3817 // Sequential one-byte string. Allocate the result.
3818 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3819 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_sequential);
3821 // Allocate and copy the resulting one-byte string.
3822 __ AllocateOneByteString(result_string, result_length, x3, x4, x5, &runtime);
3824 // Locate first character of substring to copy.
3825 __ Add(substring_char0, unpacked_char0, from);
3827 // Locate first character of result.
3828 __ Add(result_char0, result_string,
3829 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3831 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3832 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3835 // Allocate and copy the resulting two-byte string.
3836 __ Bind(&two_byte_sequential);
3837 __ AllocateTwoByteString(result_string, result_length, x3, x4, x5, &runtime);
3839 // Locate first character of substring to copy.
3840 __ Add(substring_char0, unpacked_char0, Operand(from, LSL, 1));
3842 // Locate first character of result.
3843 __ Add(result_char0, result_string,
3844 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
3846 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3847 __ Add(result_length, result_length, result_length);
3848 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3850 __ Bind(&return_x0);
3851 Counters* counters = isolate()->counters();
3852 __ IncrementCounter(counters->sub_string_native(), 1, x3, x4);
3857 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3859 __ bind(&single_char);
3860 // x1: result_length
3861 // x10: input_string
3863 // x15: from (untagged)
3865 StringCharAtGenerator generator(input_string, from, result_length, x0,
3866 &runtime, &runtime, &runtime,
3867 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3868 generator.GenerateFast(masm);
3871 generator.SkipSlow(masm, &runtime);
3875 void ToNumberStub::Generate(MacroAssembler* masm) {
3876 // The ToNumber stub takes one argument in x0.
3878 __ JumpIfNotSmi(x0, ¬_smi);
3882 Label not_heap_number;
3883 __ Ldr(x1, FieldMemOperand(x0, HeapObject::kMapOffset));
3884 __ Ldrb(x1, FieldMemOperand(x1, Map::kInstanceTypeOffset));
3886 // x1: instance type
3887 __ Cmp(x1, HEAP_NUMBER_TYPE);
3888 __ B(ne, ¬_heap_number);
3890 __ Bind(¬_heap_number);
3892 Label not_string, slow_string;
3893 __ Cmp(x1, FIRST_NONSTRING_TYPE);
3894 __ B(hs, ¬_string);
3895 // Check if string has a cached array index.
3896 __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset));
3897 __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask));
3898 __ B(ne, &slow_string);
3899 __ IndexFromHash(x2, x0);
3901 __ Bind(&slow_string);
3902 __ Push(x0); // Push argument.
3903 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3904 __ Bind(¬_string);
3907 __ Cmp(x1, ODDBALL_TYPE);
3908 __ B(ne, ¬_oddball);
3909 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
3911 __ Bind(¬_oddball);
3913 __ Push(x0); // Push argument.
3914 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3918 void ToStringStub::Generate(MacroAssembler* masm) {
3919 // The ToString stub takes one argument in x0.
3921 __ JumpIfSmi(x0, &is_number);
3924 __ JumpIfObjectType(x0, x1, x1, FIRST_NONSTRING_TYPE, ¬_string, hs);
3926 // x1: receiver instance type
3928 __ Bind(¬_string);
3930 Label not_heap_number;
3931 __ Cmp(x1, HEAP_NUMBER_TYPE);
3932 __ B(ne, ¬_heap_number);
3933 __ Bind(&is_number);
3934 NumberToStringStub stub(isolate());
3935 __ TailCallStub(&stub);
3936 __ Bind(¬_heap_number);
3939 __ Cmp(x1, ODDBALL_TYPE);
3940 __ B(ne, ¬_oddball);
3941 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToStringOffset));
3943 __ Bind(¬_oddball);
3945 __ Push(x0); // Push argument.
3946 __ TailCallRuntime(Runtime::kToString, 1, 1);
3950 void StringHelper::GenerateFlatOneByteStringEquals(
3951 MacroAssembler* masm, Register left, Register right, Register scratch1,
3952 Register scratch2, Register scratch3) {
3953 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3));
3954 Register result = x0;
3955 Register left_length = scratch1;
3956 Register right_length = scratch2;
3958 // Compare lengths. If lengths differ, strings can't be equal. Lengths are
3959 // smis, and don't need to be untagged.
3960 Label strings_not_equal, check_zero_length;
3961 __ Ldr(left_length, FieldMemOperand(left, String::kLengthOffset));
3962 __ Ldr(right_length, FieldMemOperand(right, String::kLengthOffset));
3963 __ Cmp(left_length, right_length);
3964 __ B(eq, &check_zero_length);
3966 __ Bind(&strings_not_equal);
3967 __ Mov(result, Smi::FromInt(NOT_EQUAL));
3970 // Check if the length is zero. If so, the strings must be equal (and empty.)
3971 Label compare_chars;
3972 __ Bind(&check_zero_length);
3973 STATIC_ASSERT(kSmiTag == 0);
3974 __ Cbnz(left_length, &compare_chars);
3975 __ Mov(result, Smi::FromInt(EQUAL));
3978 // Compare characters. Falls through if all characters are equal.
3979 __ Bind(&compare_chars);
3980 GenerateOneByteCharsCompareLoop(masm, left, right, left_length, scratch2,
3981 scratch3, &strings_not_equal);
3983 // Characters in strings are equal.
3984 __ Mov(result, Smi::FromInt(EQUAL));
3989 void StringHelper::GenerateCompareFlatOneByteStrings(
3990 MacroAssembler* masm, Register left, Register right, Register scratch1,
3991 Register scratch2, Register scratch3, Register scratch4) {
3992 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3, scratch4));
3993 Label result_not_equal, compare_lengths;
3995 // Find minimum length and length difference.
3996 Register length_delta = scratch3;
3997 __ Ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3998 __ Ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3999 __ Subs(length_delta, scratch1, scratch2);
4001 Register min_length = scratch1;
4002 __ Csel(min_length, scratch2, scratch1, gt);
4003 __ Cbz(min_length, &compare_lengths);
4006 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
4007 scratch4, &result_not_equal);
4009 // Compare lengths - strings up to min-length are equal.
4010 __ Bind(&compare_lengths);
4012 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
4014 // Use length_delta as result if it's zero.
4015 Register result = x0;
4016 __ Subs(result, length_delta, 0);
4018 __ Bind(&result_not_equal);
4019 Register greater = x10;
4020 Register less = x11;
4021 __ Mov(greater, Smi::FromInt(GREATER));
4022 __ Mov(less, Smi::FromInt(LESS));
4023 __ CmovX(result, greater, gt);
4024 __ CmovX(result, less, lt);
4029 void StringHelper::GenerateOneByteCharsCompareLoop(
4030 MacroAssembler* masm, Register left, Register right, Register length,
4031 Register scratch1, Register scratch2, Label* chars_not_equal) {
4032 DCHECK(!AreAliased(left, right, length, scratch1, scratch2));
4034 // Change index to run from -length to -1 by adding length to string
4035 // start. This means that loop ends when index reaches zero, which
4036 // doesn't need an additional compare.
4037 __ SmiUntag(length);
4038 __ Add(scratch1, length, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4039 __ Add(left, left, scratch1);
4040 __ Add(right, right, scratch1);
4042 Register index = length;
4043 __ Neg(index, length); // index = -length;
4048 __ Ldrb(scratch1, MemOperand(left, index));
4049 __ Ldrb(scratch2, MemOperand(right, index));
4050 __ Cmp(scratch1, scratch2);
4051 __ B(ne, chars_not_equal);
4052 __ Add(index, index, 1);
4053 __ Cbnz(index, &loop);
4057 void StringCompareStub::Generate(MacroAssembler* masm) {
4058 // ----------- S t a t e -------------
4061 // -- lr : return address
4062 // -----------------------------------
4063 __ AssertString(x1);
4064 __ AssertString(x0);
4068 __ B(ne, ¬_same);
4069 __ Mov(x0, Smi::FromInt(EQUAL));
4070 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x3,
4076 // Check that both objects are sequential one-byte strings.
4078 __ JumpIfEitherIsNotSequentialOneByteStrings(x1, x0, x12, x13, &runtime);
4080 // Compare flat one-byte strings natively.
4081 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x3,
4083 StringHelper::GenerateCompareFlatOneByteStrings(masm, x1, x0, x12, x13, x14,
4086 // Call the runtime.
4087 // Returns -1 (less), 0 (equal), or 1 (greater) tagged as a small integer.
4090 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
4094 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4095 // ----------- S t a t e -------------
4098 // -- lr : return address
4099 // -----------------------------------
4101 // Load x2 with the allocation site. We stick an undefined dummy value here
4102 // and replace it with the real allocation site later when we instantiate this
4103 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
4104 __ LoadObject(x2, handle(isolate()->heap()->undefined_value()));
4106 // Make sure that we actually patched the allocation site.
4107 if (FLAG_debug_code) {
4108 __ AssertNotSmi(x2, kExpectedAllocationSite);
4109 __ Ldr(x10, FieldMemOperand(x2, HeapObject::kMapOffset));
4110 __ AssertRegisterIsRoot(x10, Heap::kAllocationSiteMapRootIndex,
4111 kExpectedAllocationSite);
4114 // Tail call into the stub that handles binary operations with allocation
4116 BinaryOpWithAllocationSiteStub stub(isolate(), state());
4117 __ TailCallStub(&stub);
4121 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4122 // We need some extra registers for this stub, they have been allocated
4123 // but we need to save them before using them.
4126 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4127 Label dont_need_remembered_set;
4129 Register val = regs_.scratch0();
4130 __ Ldr(val, MemOperand(regs_.address()));
4131 __ JumpIfNotInNewSpace(val, &dont_need_remembered_set);
4133 __ CheckPageFlagSet(regs_.object(), val, 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4134 &dont_need_remembered_set);
4136 // First notify the incremental marker if necessary, then update the
4138 CheckNeedsToInformIncrementalMarker(
4139 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4140 InformIncrementalMarker(masm);
4141 regs_.Restore(masm); // Restore the extra scratch registers we used.
4143 __ RememberedSetHelper(object(), address(),
4144 value(), // scratch1
4145 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4147 __ Bind(&dont_need_remembered_set);
4150 CheckNeedsToInformIncrementalMarker(
4151 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4152 InformIncrementalMarker(masm);
4153 regs_.Restore(masm); // Restore the extra scratch registers we used.
4158 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4159 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4161 x0.Is(regs_.address()) ? regs_.scratch0() : regs_.address();
4162 DCHECK(!address.Is(regs_.object()));
4163 DCHECK(!address.Is(x0));
4164 __ Mov(address, regs_.address());
4165 __ Mov(x0, regs_.object());
4166 __ Mov(x1, address);
4167 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4169 AllowExternalCallThatCantCauseGC scope(masm);
4170 ExternalReference function =
4171 ExternalReference::incremental_marking_record_write_function(
4173 __ CallCFunction(function, 3, 0);
4175 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4179 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4180 MacroAssembler* masm,
4181 OnNoNeedToInformIncrementalMarker on_no_need,
4184 Label need_incremental;
4185 Label need_incremental_pop_scratch;
4187 Register mem_chunk = regs_.scratch0();
4188 Register counter = regs_.scratch1();
4189 __ Bic(mem_chunk, regs_.object(), Page::kPageAlignmentMask);
4191 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4192 __ Subs(counter, counter, 1);
4194 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4195 __ B(mi, &need_incremental);
4197 // If the object is not black we don't have to inform the incremental marker.
4198 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4200 regs_.Restore(masm); // Restore the extra scratch registers we used.
4201 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4202 __ RememberedSetHelper(object(), address(),
4203 value(), // scratch1
4204 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4210 // Get the value from the slot.
4211 Register val = regs_.scratch0();
4212 __ Ldr(val, MemOperand(regs_.address()));
4214 if (mode == INCREMENTAL_COMPACTION) {
4215 Label ensure_not_white;
4217 __ CheckPageFlagClear(val, regs_.scratch1(),
4218 MemoryChunk::kEvacuationCandidateMask,
4221 __ CheckPageFlagClear(regs_.object(),
4223 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4226 __ Bind(&ensure_not_white);
4229 // We need extra registers for this, so we push the object and the address
4230 // register temporarily.
4231 __ Push(regs_.address(), regs_.object());
4232 __ EnsureNotWhite(val,
4233 regs_.scratch1(), // Scratch.
4234 regs_.object(), // Scratch.
4235 regs_.address(), // Scratch.
4236 regs_.scratch2(), // Scratch.
4237 &need_incremental_pop_scratch);
4238 __ Pop(regs_.object(), regs_.address());
4240 regs_.Restore(masm); // Restore the extra scratch registers we used.
4241 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4242 __ RememberedSetHelper(object(), address(),
4243 value(), // scratch1
4244 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4249 __ Bind(&need_incremental_pop_scratch);
4250 __ Pop(regs_.object(), regs_.address());
4252 __ Bind(&need_incremental);
4253 // Fall through when we need to inform the incremental marker.
4257 void RecordWriteStub::Generate(MacroAssembler* masm) {
4258 Label skip_to_incremental_noncompacting;
4259 Label skip_to_incremental_compacting;
4261 // We patch these two first instructions back and forth between a nop and
4262 // real branch when we start and stop incremental heap marking.
4263 // Initially the stub is expected to be in STORE_BUFFER_ONLY mode, so 2 nops
4265 // See RecordWriteStub::Patch for details.
4267 InstructionAccurateScope scope(masm, 2);
4268 __ adr(xzr, &skip_to_incremental_noncompacting);
4269 __ adr(xzr, &skip_to_incremental_compacting);
4272 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4273 __ RememberedSetHelper(object(), address(),
4274 value(), // scratch1
4275 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4279 __ Bind(&skip_to_incremental_noncompacting);
4280 GenerateIncremental(masm, INCREMENTAL);
4282 __ Bind(&skip_to_incremental_compacting);
4283 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4287 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4288 // x0 value element value to store
4289 // x3 index_smi element index as smi
4290 // sp[0] array_index_smi array literal index in function as smi
4291 // sp[1] array array literal
4293 Register value = x0;
4294 Register index_smi = x3;
4296 Register array = x1;
4297 Register array_map = x2;
4298 Register array_index_smi = x4;
4299 __ PeekPair(array_index_smi, array, 0);
4300 __ Ldr(array_map, FieldMemOperand(array, JSObject::kMapOffset));
4302 Label double_elements, smi_element, fast_elements, slow_elements;
4303 Register bitfield2 = x10;
4304 __ Ldrb(bitfield2, FieldMemOperand(array_map, Map::kBitField2Offset));
4306 // Jump if array's ElementsKind is not FAST*_SMI_ELEMENTS, FAST_ELEMENTS or
4307 // FAST_HOLEY_ELEMENTS.
4308 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4309 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4310 STATIC_ASSERT(FAST_ELEMENTS == 2);
4311 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4312 __ Cmp(bitfield2, Map::kMaximumBitField2FastHoleyElementValue);
4313 __ B(hi, &double_elements);
4315 __ JumpIfSmi(value, &smi_element);
4317 // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS.
4318 __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::ElementsKindBits::kShift),
4321 // Store into the array literal requires an elements transition. Call into
4323 __ Bind(&slow_elements);
4324 __ Push(array, index_smi, value);
4325 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4326 __ Ldr(x11, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
4327 __ Push(x11, array_index_smi);
4328 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4330 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4331 __ Bind(&fast_elements);
4332 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4333 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4334 __ Add(x11, x11, FixedArray::kHeaderSize - kHeapObjectTag);
4335 __ Str(value, MemOperand(x11));
4336 // Update the write barrier for the array store.
4337 __ RecordWrite(x10, x11, value, kLRHasNotBeenSaved, kDontSaveFPRegs,
4338 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4341 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4342 // and value is Smi.
4343 __ Bind(&smi_element);
4344 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4345 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4346 __ Str(value, FieldMemOperand(x11, FixedArray::kHeaderSize));
4349 __ Bind(&double_elements);
4350 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4351 __ StoreNumberToDoubleElements(value, index_smi, x10, x11, d0,
4357 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4358 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4359 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4360 int parameter_count_offset =
4361 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4362 __ Ldr(x1, MemOperand(fp, parameter_count_offset));
4363 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4366 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4368 // Return to IC Miss stub, continuation still on stack.
4373 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4374 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4375 LoadICStub stub(isolate(), state());
4376 stub.GenerateForTrampoline(masm);
4380 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4381 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4382 KeyedLoadICStub stub(isolate(), state());
4383 stub.GenerateForTrampoline(masm);
4387 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4388 EmitLoadTypeFeedbackVector(masm, x2);
4389 CallICStub stub(isolate(), state());
4390 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4394 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4397 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4398 GenerateImpl(masm, true);
4402 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4403 Register receiver_map, Register scratch1,
4404 Register scratch2, bool is_polymorphic,
4406 // feedback initially contains the feedback array
4407 Label next_loop, prepare_next;
4408 Label load_smi_map, compare_map;
4409 Label start_polymorphic;
4411 Register cached_map = scratch1;
4414 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4415 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4416 __ Cmp(receiver_map, cached_map);
4417 __ B(ne, &start_polymorphic);
4418 // found, now call handler.
4419 Register handler = feedback;
4420 __ Ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4421 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4424 Register length = scratch2;
4425 __ Bind(&start_polymorphic);
4426 __ Ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4427 if (!is_polymorphic) {
4428 __ Cmp(length, Operand(Smi::FromInt(2)));
4432 Register too_far = length;
4433 Register pointer_reg = feedback;
4435 // +-----+------+------+-----+-----+ ... ----+
4436 // | map | len | wm0 | h0 | wm1 | hN |
4437 // +-----+------+------+-----+-----+ ... ----+
4441 // pointer_reg too_far
4442 // aka feedback scratch2
4443 // also need receiver_map
4444 // use cached_map (scratch1) to look in the weak map values.
4445 __ Add(too_far, feedback,
4446 Operand::UntagSmiAndScale(length, kPointerSizeLog2));
4447 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
4448 __ Add(pointer_reg, feedback,
4449 FixedArray::OffsetOfElementAt(2) - kHeapObjectTag);
4451 __ Bind(&next_loop);
4452 __ Ldr(cached_map, MemOperand(pointer_reg));
4453 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4454 __ Cmp(receiver_map, cached_map);
4455 __ B(ne, &prepare_next);
4456 __ Ldr(handler, MemOperand(pointer_reg, kPointerSize));
4457 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4460 __ Bind(&prepare_next);
4461 __ Add(pointer_reg, pointer_reg, kPointerSize * 2);
4462 __ Cmp(pointer_reg, too_far);
4463 __ B(lt, &next_loop);
4465 // We exhausted our array of map handler pairs.
4470 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4471 Register receiver_map, Register feedback,
4472 Register vector, Register slot,
4473 Register scratch, Label* compare_map,
4474 Label* load_smi_map, Label* try_array) {
4475 __ JumpIfSmi(receiver, load_smi_map);
4476 __ Ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4477 __ bind(compare_map);
4478 Register cached_map = scratch;
4479 // Move the weak map into the weak_cell register.
4480 __ Ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4481 __ Cmp(cached_map, receiver_map);
4482 __ B(ne, try_array);
4484 Register handler = feedback;
4485 __ Add(handler, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4487 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4488 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4493 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4494 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4495 Register name = LoadWithVectorDescriptor::NameRegister(); // x2
4496 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4497 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4498 Register feedback = x4;
4499 Register receiver_map = x5;
4500 Register scratch1 = x6;
4502 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4503 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4505 // Try to quickly handle the monomorphic case without knowing for sure
4506 // if we have a weak cell in feedback. We do know it's safe to look
4507 // at WeakCell::kValueOffset.
4508 Label try_array, load_smi_map, compare_map;
4509 Label not_array, miss;
4510 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4511 scratch1, &compare_map, &load_smi_map, &try_array);
4513 // Is it a fixed array?
4514 __ Bind(&try_array);
4515 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4516 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4517 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, true, &miss);
4519 __ Bind(¬_array);
4520 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
4521 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4522 Code::ComputeHandlerFlags(Code::LOAD_IC));
4523 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4524 receiver, name, feedback,
4525 receiver_map, scratch1, x7);
4528 LoadIC::GenerateMiss(masm);
4530 __ Bind(&load_smi_map);
4531 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4532 __ jmp(&compare_map);
4536 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4537 GenerateImpl(masm, false);
4541 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4542 GenerateImpl(masm, true);
4546 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4547 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4548 Register key = LoadWithVectorDescriptor::NameRegister(); // x2
4549 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4550 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4551 Register feedback = x4;
4552 Register receiver_map = x5;
4553 Register scratch1 = x6;
4555 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4556 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4558 // Try to quickly handle the monomorphic case without knowing for sure
4559 // if we have a weak cell in feedback. We do know it's safe to look
4560 // at WeakCell::kValueOffset.
4561 Label try_array, load_smi_map, compare_map;
4562 Label not_array, miss;
4563 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4564 scratch1, &compare_map, &load_smi_map, &try_array);
4566 __ Bind(&try_array);
4567 // Is it a fixed array?
4568 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4569 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4571 // We have a polymorphic element handler.
4572 Label polymorphic, try_poly_name;
4573 __ Bind(&polymorphic);
4574 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, true, &miss);
4576 __ Bind(¬_array);
4578 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
4580 Handle<Code> megamorphic_stub =
4581 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4582 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4584 __ Bind(&try_poly_name);
4585 // We might have a name in feedback, and a fixed array in the next slot.
4586 __ Cmp(key, feedback);
4588 // If the name comparison succeeded, we know we have a fixed array with
4589 // at least one map/handler pair.
4590 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4592 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4593 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, false, &miss);
4596 KeyedLoadIC::GenerateMiss(masm);
4598 __ Bind(&load_smi_map);
4599 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4600 __ jmp(&compare_map);
4604 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4605 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4606 VectorStoreICStub stub(isolate(), state());
4607 stub.GenerateForTrampoline(masm);
4611 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4612 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4613 VectorKeyedStoreICStub stub(isolate(), state());
4614 stub.GenerateForTrampoline(masm);
4618 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4619 GenerateImpl(masm, false);
4623 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4624 GenerateImpl(masm, true);
4628 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4629 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // x1
4630 Register key = VectorStoreICDescriptor::NameRegister(); // x2
4631 Register vector = VectorStoreICDescriptor::VectorRegister(); // x3
4632 Register slot = VectorStoreICDescriptor::SlotRegister(); // x4
4633 DCHECK(VectorStoreICDescriptor::ValueRegister().is(x0)); // x0
4634 Register feedback = x5;
4635 Register receiver_map = x6;
4636 Register scratch1 = x7;
4638 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4639 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4641 // Try to quickly handle the monomorphic case without knowing for sure
4642 // if we have a weak cell in feedback. We do know it's safe to look
4643 // at WeakCell::kValueOffset.
4644 Label try_array, load_smi_map, compare_map;
4645 Label not_array, miss;
4646 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4647 scratch1, &compare_map, &load_smi_map, &try_array);
4649 // Is it a fixed array?
4650 __ Bind(&try_array);
4651 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4652 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4653 HandleArrayCases(masm, feedback, receiver_map, scratch1, x8, true, &miss);
4655 __ Bind(¬_array);
4656 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
4657 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4658 Code::ComputeHandlerFlags(Code::STORE_IC));
4659 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags,
4660 receiver, key, feedback,
4661 receiver_map, scratch1, x8);
4664 StoreIC::GenerateMiss(masm);
4666 __ Bind(&load_smi_map);
4667 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4668 __ jmp(&compare_map);
4672 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4673 GenerateImpl(masm, false);
4677 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4678 GenerateImpl(masm, true);
4682 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4683 Register receiver_map, Register scratch1,
4684 Register scratch2, Label* miss) {
4685 // feedback initially contains the feedback array
4686 Label next_loop, prepare_next;
4687 Label start_polymorphic;
4688 Label transition_call;
4690 Register cached_map = scratch1;
4691 Register too_far = scratch2;
4692 Register pointer_reg = feedback;
4694 __ Ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4696 // +-----+------+------+-----+-----+-----+ ... ----+
4697 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4698 // +-----+------+------+-----+-----+ ----+ ... ----+
4702 // pointer_reg too_far
4703 // aka feedback scratch2
4704 // also need receiver_map
4705 // use cached_map (scratch1) to look in the weak map values.
4706 __ Add(too_far, feedback,
4707 Operand::UntagSmiAndScale(too_far, kPointerSizeLog2));
4708 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
4709 __ Add(pointer_reg, feedback,
4710 FixedArray::OffsetOfElementAt(0) - kHeapObjectTag);
4712 __ Bind(&next_loop);
4713 __ Ldr(cached_map, MemOperand(pointer_reg));
4714 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4715 __ Cmp(receiver_map, cached_map);
4716 __ B(ne, &prepare_next);
4717 // Is it a transitioning store?
4718 __ Ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4719 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4720 __ B(ne, &transition_call);
4722 __ Ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4723 __ Add(pointer_reg, pointer_reg, Code::kHeaderSize - kHeapObjectTag);
4724 __ Jump(pointer_reg);
4726 __ Bind(&transition_call);
4727 __ Ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4728 __ JumpIfSmi(too_far, miss);
4730 __ Ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4731 // Load the map into the correct register.
4732 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4733 __ mov(feedback, too_far);
4734 __ Add(receiver_map, receiver_map, Code::kHeaderSize - kHeapObjectTag);
4735 __ Jump(receiver_map);
4737 __ Bind(&prepare_next);
4738 __ Add(pointer_reg, pointer_reg, kPointerSize * 3);
4739 __ Cmp(pointer_reg, too_far);
4740 __ B(lt, &next_loop);
4742 // We exhausted our array of map handler pairs.
4747 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4748 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // x1
4749 Register key = VectorStoreICDescriptor::NameRegister(); // x2
4750 Register vector = VectorStoreICDescriptor::VectorRegister(); // x3
4751 Register slot = VectorStoreICDescriptor::SlotRegister(); // x4
4752 DCHECK(VectorStoreICDescriptor::ValueRegister().is(x0)); // x0
4753 Register feedback = x5;
4754 Register receiver_map = x6;
4755 Register scratch1 = x7;
4757 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4758 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4760 // Try to quickly handle the monomorphic case without knowing for sure
4761 // if we have a weak cell in feedback. We do know it's safe to look
4762 // at WeakCell::kValueOffset.
4763 Label try_array, load_smi_map, compare_map;
4764 Label not_array, miss;
4765 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4766 scratch1, &compare_map, &load_smi_map, &try_array);
4768 __ Bind(&try_array);
4769 // Is it a fixed array?
4770 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4771 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4773 // We have a polymorphic element handler.
4774 Label try_poly_name;
4775 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, x8, &miss);
4777 __ Bind(¬_array);
4779 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
4781 Handle<Code> megamorphic_stub =
4782 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4783 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4785 __ Bind(&try_poly_name);
4786 // We might have a name in feedback, and a fixed array in the next slot.
4787 __ Cmp(key, feedback);
4789 // If the name comparison succeeded, we know we have a fixed array with
4790 // at least one map/handler pair.
4791 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4793 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4794 HandleArrayCases(masm, feedback, receiver_map, scratch1, x8, false, &miss);
4797 KeyedStoreIC::GenerateMiss(masm);
4799 __ Bind(&load_smi_map);
4800 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4801 __ jmp(&compare_map);
4805 // The entry hook is a "BumpSystemStackPointer" instruction (sub), followed by
4806 // a "Push lr" instruction, followed by a call.
4807 static const unsigned int kProfileEntryHookCallSize =
4808 Assembler::kCallSizeWithRelocation + (2 * kInstructionSize);
4811 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4812 if (masm->isolate()->function_entry_hook() != NULL) {
4813 ProfileEntryHookStub stub(masm->isolate());
4814 Assembler::BlockConstPoolScope no_const_pools(masm);
4815 DontEmitDebugCodeScope no_debug_code(masm);
4816 Label entry_hook_call_start;
4817 __ Bind(&entry_hook_call_start);
4820 DCHECK(masm->SizeOfCodeGeneratedSince(&entry_hook_call_start) ==
4821 kProfileEntryHookCallSize);
4828 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4829 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
4831 // Save all kCallerSaved registers (including lr), since this can be called
4833 // TODO(jbramley): What about FP registers?
4834 __ PushCPURegList(kCallerSaved);
4835 DCHECK(kCallerSaved.IncludesAliasOf(lr));
4836 const int kNumSavedRegs = kCallerSaved.Count();
4838 // Compute the function's address as the first argument.
4839 __ Sub(x0, lr, kProfileEntryHookCallSize);
4841 #if V8_HOST_ARCH_ARM64
4842 uintptr_t entry_hook =
4843 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
4844 __ Mov(x10, entry_hook);
4846 // Under the simulator we need to indirect the entry hook through a trampoline
4847 // function at a known address.
4848 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4849 __ Mov(x10, Operand(ExternalReference(&dispatcher,
4850 ExternalReference::BUILTIN_CALL,
4852 // It additionally takes an isolate as a third parameter
4853 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4856 // The caller's return address is above the saved temporaries.
4857 // Grab its location for the second argument to the hook.
4858 __ Add(x1, __ StackPointer(), kNumSavedRegs * kPointerSize);
4861 // Create a dummy frame, as CallCFunction requires this.
4862 FrameScope frame(masm, StackFrame::MANUAL);
4863 __ CallCFunction(x10, 2, 0);
4866 __ PopCPURegList(kCallerSaved);
4871 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4872 // When calling into C++ code the stack pointer must be csp.
4873 // Therefore this code must use csp for peek/poke operations when the
4874 // stub is generated. When the stub is called
4875 // (via DirectCEntryStub::GenerateCall), the caller must setup an ExitFrame
4876 // and configure the stack pointer *before* doing the call.
4877 const Register old_stack_pointer = __ StackPointer();
4878 __ SetStackPointer(csp);
4880 // Put return address on the stack (accessible to GC through exit frame pc).
4882 // Call the C++ function.
4884 // Return to calling code.
4886 __ AssertFPCRState();
4889 __ SetStackPointer(old_stack_pointer);
4892 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4894 // Make sure the caller configured the stack pointer (see comment in
4895 // DirectCEntryStub::Generate).
4896 DCHECK(csp.Is(__ StackPointer()));
4899 reinterpret_cast<intptr_t>(GetCode().location());
4900 __ Mov(lr, Operand(code, RelocInfo::CODE_TARGET));
4901 __ Mov(x10, target);
4902 // Branch to the stub.
4907 // Probe the name dictionary in the 'elements' register.
4908 // Jump to the 'done' label if a property with the given name is found.
4909 // Jump to the 'miss' label otherwise.
4911 // If lookup was successful 'scratch2' will be equal to elements + 4 * index.
4912 // 'elements' and 'name' registers are preserved on miss.
4913 void NameDictionaryLookupStub::GeneratePositiveLookup(
4914 MacroAssembler* masm,
4920 Register scratch2) {
4921 DCHECK(!AreAliased(elements, name, scratch1, scratch2));
4923 // Assert that name contains a string.
4924 __ AssertName(name);
4926 // Compute the capacity mask.
4927 __ Ldrsw(scratch1, UntagSmiFieldMemOperand(elements, kCapacityOffset));
4928 __ Sub(scratch1, scratch1, 1);
4930 // Generate an unrolled loop that performs a few probes before giving up.
4931 for (int i = 0; i < kInlinedProbes; i++) {
4932 // Compute the masked index: (hash + i + i * i) & mask.
4933 __ Ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4935 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4936 // the hash in a separate instruction. The value hash + i + i * i is right
4937 // shifted in the following and instruction.
4938 DCHECK(NameDictionary::GetProbeOffset(i) <
4939 1 << (32 - Name::kHashFieldOffset));
4940 __ Add(scratch2, scratch2, Operand(
4941 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4943 __ And(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
4945 // Scale the index by multiplying by the element size.
4946 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4947 __ Add(scratch2, scratch2, Operand(scratch2, LSL, 1));
4949 // Check if the key is identical to the name.
4950 UseScratchRegisterScope temps(masm);
4951 Register scratch3 = temps.AcquireX();
4952 __ Add(scratch2, elements, Operand(scratch2, LSL, kPointerSizeLog2));
4953 __ Ldr(scratch3, FieldMemOperand(scratch2, kElementsStartOffset));
4954 __ Cmp(name, scratch3);
4958 // The inlined probes didn't find the entry.
4959 // Call the complete stub to scan the whole dictionary.
4961 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4962 spill_list.Combine(lr);
4963 spill_list.Remove(scratch1);
4964 spill_list.Remove(scratch2);
4966 __ PushCPURegList(spill_list);
4969 DCHECK(!elements.is(x1));
4971 __ Mov(x0, elements);
4973 __ Mov(x0, elements);
4978 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4980 __ Cbz(x0, ¬_found);
4981 __ Mov(scratch2, x2); // Move entry index into scratch2.
4982 __ PopCPURegList(spill_list);
4985 __ Bind(¬_found);
4986 __ PopCPURegList(spill_list);
4991 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4995 Register properties,
4997 Register scratch0) {
4998 DCHECK(!AreAliased(receiver, properties, scratch0));
4999 DCHECK(name->IsUniqueName());
5000 // If names of slots in range from 1 to kProbes - 1 for the hash value are
5001 // not equal to the name and kProbes-th slot is not used (its name is the
5002 // undefined value), it guarantees the hash table doesn't contain the
5003 // property. It's true even if some slots represent deleted properties
5004 // (their names are the hole value).
5005 for (int i = 0; i < kInlinedProbes; i++) {
5006 // scratch0 points to properties hash.
5007 // Compute the masked index: (hash + i + i * i) & mask.
5008 Register index = scratch0;
5009 // Capacity is smi 2^n.
5010 __ Ldrsw(index, UntagSmiFieldMemOperand(properties, kCapacityOffset));
5011 __ Sub(index, index, 1);
5012 __ And(index, index, name->Hash() + NameDictionary::GetProbeOffset(i));
5014 // Scale the index by multiplying by the entry size.
5015 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
5016 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5018 Register entity_name = scratch0;
5019 // Having undefined at this place means the name is not contained.
5020 Register tmp = index;
5021 __ Add(tmp, properties, Operand(index, LSL, kPointerSizeLog2));
5022 __ Ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
5024 __ JumpIfRoot(entity_name, Heap::kUndefinedValueRootIndex, done);
5026 // Stop if found the property.
5027 __ Cmp(entity_name, Operand(name));
5031 __ JumpIfRoot(entity_name, Heap::kTheHoleValueRootIndex, &good);
5033 // Check if the entry name is not a unique name.
5034 __ Ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
5035 __ Ldrb(entity_name,
5036 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
5037 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
5041 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
5042 spill_list.Combine(lr);
5043 spill_list.Remove(scratch0); // Scratch registers don't need to be preserved.
5045 __ PushCPURegList(spill_list);
5047 __ Ldr(x0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
5048 __ Mov(x1, Operand(name));
5049 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
5051 // Move stub return value to scratch0. Note that scratch0 is not included in
5052 // spill_list and won't be clobbered by PopCPURegList.
5053 __ Mov(scratch0, x0);
5054 __ PopCPURegList(spill_list);
5056 __ Cbz(scratch0, done);
5061 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
5062 // This stub overrides SometimesSetsUpAFrame() to return false. That means
5063 // we cannot call anything that could cause a GC from this stub.
5065 // Arguments are in x0 and x1:
5066 // x0: property dictionary.
5067 // x1: the name of the property we are looking for.
5069 // Return value is in x0 and is zero if lookup failed, non zero otherwise.
5070 // If the lookup is successful, x2 will contains the index of the entry.
5072 Register result = x0;
5073 Register dictionary = x0;
5075 Register index = x2;
5078 Register undefined = x5;
5079 Register entry_key = x6;
5081 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
5083 __ Ldrsw(mask, UntagSmiFieldMemOperand(dictionary, kCapacityOffset));
5084 __ Sub(mask, mask, 1);
5086 __ Ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
5087 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
5089 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
5090 // Compute the masked index: (hash + i + i * i) & mask.
5091 // Capacity is smi 2^n.
5093 // Add the probe offset (i + i * i) left shifted to avoid right shifting
5094 // the hash in a separate instruction. The value hash + i + i * i is right
5095 // shifted in the following and instruction.
5096 DCHECK(NameDictionary::GetProbeOffset(i) <
5097 1 << (32 - Name::kHashFieldOffset));
5099 NameDictionary::GetProbeOffset(i) << Name::kHashShift);
5101 __ Mov(index, hash);
5103 __ And(index, mask, Operand(index, LSR, Name::kHashShift));
5105 // Scale the index by multiplying by the entry size.
5106 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
5107 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5109 __ Add(index, dictionary, Operand(index, LSL, kPointerSizeLog2));
5110 __ Ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
5112 // Having undefined at this place means the name is not contained.
5113 __ Cmp(entry_key, undefined);
5114 __ B(eq, ¬_in_dictionary);
5116 // Stop if found the property.
5117 __ Cmp(entry_key, key);
5118 __ B(eq, &in_dictionary);
5120 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
5121 // Check if the entry name is not a unique name.
5122 __ Ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
5123 __ Ldrb(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
5124 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
5128 __ Bind(&maybe_in_dictionary);
5129 // If we are doing negative lookup then probing failure should be
5130 // treated as a lookup success. For positive lookup, probing failure
5131 // should be treated as lookup failure.
5132 if (mode() == POSITIVE_LOOKUP) {
5137 __ Bind(&in_dictionary);
5141 __ Bind(¬_in_dictionary);
5148 static void CreateArrayDispatch(MacroAssembler* masm,
5149 AllocationSiteOverrideMode mode) {
5150 ASM_LOCATION("CreateArrayDispatch");
5151 if (mode == DISABLE_ALLOCATION_SITES) {
5152 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5153 __ TailCallStub(&stub);
5155 } else if (mode == DONT_OVERRIDE) {
5158 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5159 for (int i = 0; i <= last_index; ++i) {
5161 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5162 // TODO(jbramley): Is this the best way to handle this? Can we make the
5163 // tail calls conditional, rather than hopping over each one?
5164 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5165 T stub(masm->isolate(), candidate_kind);
5166 __ TailCallStub(&stub);
5170 // If we reached this point there is a problem.
5171 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5179 // TODO(jbramley): If this needs to be a special case, make it a proper template
5180 // specialization, and not a separate function.
5181 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5182 AllocationSiteOverrideMode mode) {
5183 ASM_LOCATION("CreateArrayDispatchOneArgument");
5185 // x1 - constructor?
5186 // x2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5187 // x3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5188 // sp[0] - last argument
5190 Register allocation_site = x2;
5193 Label normal_sequence;
5194 if (mode == DONT_OVERRIDE) {
5195 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5196 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5197 STATIC_ASSERT(FAST_ELEMENTS == 2);
5198 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5199 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5200 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5202 // Is the low bit set? If so, the array is holey.
5203 __ Tbnz(kind, 0, &normal_sequence);
5206 // Look at the last argument.
5207 // TODO(jbramley): What does a 0 argument represent?
5209 __ Cbz(x10, &normal_sequence);
5211 if (mode == DISABLE_ALLOCATION_SITES) {
5212 ElementsKind initial = GetInitialFastElementsKind();
5213 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5215 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5217 DISABLE_ALLOCATION_SITES);
5218 __ TailCallStub(&stub_holey);
5220 __ Bind(&normal_sequence);
5221 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5223 DISABLE_ALLOCATION_SITES);
5224 __ TailCallStub(&stub);
5225 } else if (mode == DONT_OVERRIDE) {
5226 // We are going to create a holey array, but our kind is non-holey.
5227 // Fix kind and retry (only if we have an allocation site in the slot).
5228 __ Orr(kind, kind, 1);
5230 if (FLAG_debug_code) {
5231 __ Ldr(x10, FieldMemOperand(allocation_site, 0));
5232 __ JumpIfNotRoot(x10, Heap::kAllocationSiteMapRootIndex,
5234 __ Assert(eq, kExpectedAllocationSite);
5237 // Save the resulting elements kind in type info. We can't just store 'kind'
5238 // in the AllocationSite::transition_info field because elements kind is
5239 // restricted to a portion of the field; upper bits need to be left alone.
5240 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5241 __ Ldr(x11, FieldMemOperand(allocation_site,
5242 AllocationSite::kTransitionInfoOffset));
5243 __ Add(x11, x11, Smi::FromInt(kFastElementsKindPackedToHoley));
5244 __ Str(x11, FieldMemOperand(allocation_site,
5245 AllocationSite::kTransitionInfoOffset));
5247 __ Bind(&normal_sequence);
5249 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5250 for (int i = 0; i <= last_index; ++i) {
5252 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5253 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5254 ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind);
5255 __ TailCallStub(&stub);
5259 // If we reached this point there is a problem.
5260 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5268 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5269 int to_index = GetSequenceIndexFromFastElementsKind(
5270 TERMINAL_FAST_ELEMENTS_KIND);
5271 for (int i = 0; i <= to_index; ++i) {
5272 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5273 T stub(isolate, kind);
5275 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5276 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5283 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5284 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5286 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5288 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5293 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5295 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5296 for (int i = 0; i < 2; i++) {
5297 // For internal arrays we only need a few things
5298 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5300 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5302 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5308 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5309 MacroAssembler* masm,
5310 AllocationSiteOverrideMode mode) {
5312 if (argument_count() == ANY) {
5313 Label zero_case, n_case;
5314 __ Cbz(argc, &zero_case);
5319 CreateArrayDispatchOneArgument(masm, mode);
5321 __ Bind(&zero_case);
5323 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5327 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5329 } else if (argument_count() == NONE) {
5330 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5331 } else if (argument_count() == ONE) {
5332 CreateArrayDispatchOneArgument(masm, mode);
5333 } else if (argument_count() == MORE_THAN_ONE) {
5334 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5341 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5342 ASM_LOCATION("ArrayConstructorStub::Generate");
5343 // ----------- S t a t e -------------
5344 // -- x0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5345 // -- x1 : constructor
5346 // -- x2 : AllocationSite or undefined
5347 // -- x3 : original constructor
5348 // -- sp[0] : last argument
5349 // -----------------------------------
5350 Register constructor = x1;
5351 Register allocation_site = x2;
5352 Register original_constructor = x3;
5354 if (FLAG_debug_code) {
5355 // The array construct code is only set for the global and natives
5356 // builtin Array functions which always have maps.
5358 Label unexpected_map, map_ok;
5359 // Initial map for the builtin Array function should be a map.
5360 __ Ldr(x10, FieldMemOperand(constructor,
5361 JSFunction::kPrototypeOrInitialMapOffset));
5362 // Will both indicate a NULL and a Smi.
5363 __ JumpIfSmi(x10, &unexpected_map);
5364 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5365 __ Bind(&unexpected_map);
5366 __ Abort(kUnexpectedInitialMapForArrayFunction);
5369 // We should either have undefined in the allocation_site register or a
5370 // valid AllocationSite.
5371 __ AssertUndefinedOrAllocationSite(allocation_site, x10);
5375 __ Cmp(original_constructor, constructor);
5376 __ B(ne, &subclassing);
5380 // Get the elements kind and case on that.
5381 __ JumpIfRoot(allocation_site, Heap::kUndefinedValueRootIndex, &no_info);
5384 UntagSmiFieldMemOperand(allocation_site,
5385 AllocationSite::kTransitionInfoOffset));
5386 __ And(kind, kind, AllocationSite::ElementsKindBits::kMask);
5387 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5390 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5392 // Subclassing support.
5393 __ Bind(&subclassing);
5394 __ Push(constructor, original_constructor);
5396 switch (argument_count()) {
5399 __ add(x0, x0, Operand(2));
5402 __ Mov(x0, Operand(2));
5405 __ Mov(x0, Operand(3));
5408 __ JumpToExternalReference(
5409 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5413 void InternalArrayConstructorStub::GenerateCase(
5414 MacroAssembler* masm, ElementsKind kind) {
5415 Label zero_case, n_case;
5418 __ Cbz(argc, &zero_case);
5419 __ CompareAndBranch(argc, 1, ne, &n_case);
5422 if (IsFastPackedElementsKind(kind)) {
5425 // We might need to create a holey array; look at the first argument.
5427 __ Cbz(x10, &packed_case);
5429 InternalArraySingleArgumentConstructorStub
5430 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5431 __ TailCallStub(&stub1_holey);
5433 __ Bind(&packed_case);
5435 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5436 __ TailCallStub(&stub1);
5438 __ Bind(&zero_case);
5440 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5441 __ TailCallStub(&stub0);
5445 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5446 __ TailCallStub(&stubN);
5450 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5451 // ----------- S t a t e -------------
5453 // -- x1 : constructor
5454 // -- sp[0] : return address
5455 // -- sp[4] : last argument
5456 // -----------------------------------
5458 Register constructor = x1;
5460 if (FLAG_debug_code) {
5461 // The array construct code is only set for the global and natives
5462 // builtin Array functions which always have maps.
5464 Label unexpected_map, map_ok;
5465 // Initial map for the builtin Array function should be a map.
5466 __ Ldr(x10, FieldMemOperand(constructor,
5467 JSFunction::kPrototypeOrInitialMapOffset));
5468 // Will both indicate a NULL and a Smi.
5469 __ JumpIfSmi(x10, &unexpected_map);
5470 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5471 __ Bind(&unexpected_map);
5472 __ Abort(kUnexpectedInitialMapForArrayFunction);
5477 // Figure out the right elements kind
5478 __ Ldr(x10, FieldMemOperand(constructor,
5479 JSFunction::kPrototypeOrInitialMapOffset));
5481 // Retrieve elements_kind from map.
5482 __ LoadElementsKindFromMap(kind, x10);
5484 if (FLAG_debug_code) {
5486 __ Cmp(x3, FAST_ELEMENTS);
5487 __ Ccmp(x3, FAST_HOLEY_ELEMENTS, ZFlag, ne);
5488 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5491 Label fast_elements_case;
5492 __ CompareAndBranch(kind, FAST_ELEMENTS, eq, &fast_elements_case);
5493 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5495 __ Bind(&fast_elements_case);
5496 GenerateCase(masm, FAST_ELEMENTS);
5500 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5501 Register context = cp;
5502 Register result = x0;
5506 // Go up the context chain to the script context.
5507 for (int i = 0; i < depth(); ++i) {
5508 __ Ldr(result, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5512 // Load the PropertyCell value at the specified slot.
5513 __ Add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5514 __ Ldr(result, ContextMemOperand(result));
5515 __ Ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5517 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5518 __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &slow_case);
5521 // Fallback to runtime.
5522 __ Bind(&slow_case);
5525 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5529 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5530 Register context = cp;
5531 Register value = x0;
5533 Register context_temp = x10;
5534 Register cell = x10;
5535 Register cell_details = x11;
5536 Register cell_value = x12;
5537 Register cell_value_map = x13;
5538 Register value_map = x14;
5539 Label fast_heapobject_case, fast_smi_case, slow_case;
5541 if (FLAG_debug_code) {
5542 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5543 __ Check(ne, kUnexpectedValue);
5546 // Go up the context chain to the script context.
5547 for (int i = 0; i < depth(); i++) {
5548 __ Ldr(context_temp, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5549 context = context_temp;
5552 // Load the PropertyCell at the specified slot.
5553 __ Add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5554 __ Ldr(cell, ContextMemOperand(cell));
5556 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5557 __ Ldr(cell_details,
5558 UntagSmiFieldMemOperand(cell, PropertyCell::kDetailsOffset));
5559 __ And(cell_details, cell_details,
5560 PropertyDetails::PropertyCellTypeField::kMask |
5561 PropertyDetails::KindField::kMask |
5562 PropertyDetails::kAttributesReadOnlyMask);
5564 // Check if PropertyCell holds mutable data.
5565 Label not_mutable_data;
5566 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5567 PropertyCellType::kMutable) |
5568 PropertyDetails::KindField::encode(kData));
5569 __ B(ne, ¬_mutable_data);
5570 __ JumpIfSmi(value, &fast_smi_case);
5571 __ Bind(&fast_heapobject_case);
5572 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5573 // RecordWriteField clobbers the value register, so we copy it before the
5576 __ RecordWriteField(cell, PropertyCell::kValueOffset, x11, x12,
5577 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5581 __ Bind(¬_mutable_data);
5582 // Check if PropertyCell value matches the new value (relevant for Constant,
5583 // ConstantType and Undefined cells).
5584 Label not_same_value;
5585 __ Ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5586 __ Cmp(cell_value, value);
5587 __ B(ne, ¬_same_value);
5589 // Make sure the PropertyCell is not marked READ_ONLY.
5590 __ Tst(cell_details, PropertyDetails::kAttributesReadOnlyMask);
5591 __ B(ne, &slow_case);
5593 if (FLAG_debug_code) {
5595 // This can only be true for Constant, ConstantType and Undefined cells,
5596 // because we never store the_hole via this stub.
5597 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5598 PropertyCellType::kConstant) |
5599 PropertyDetails::KindField::encode(kData));
5601 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5602 PropertyCellType::kConstantType) |
5603 PropertyDetails::KindField::encode(kData));
5605 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5606 PropertyCellType::kUndefined) |
5607 PropertyDetails::KindField::encode(kData));
5608 __ Check(eq, kUnexpectedValue);
5612 __ Bind(¬_same_value);
5614 // Check if PropertyCell contains data with constant type (and is not
5616 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5617 PropertyCellType::kConstantType) |
5618 PropertyDetails::KindField::encode(kData));
5619 __ B(ne, &slow_case);
5621 // Now either both old and new values must be smis or both must be heap
5622 // objects with same map.
5623 Label value_is_heap_object;
5624 __ JumpIfNotSmi(value, &value_is_heap_object);
5625 __ JumpIfNotSmi(cell_value, &slow_case);
5626 // Old and new values are smis, no need for a write barrier here.
5627 __ Bind(&fast_smi_case);
5628 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5631 __ Bind(&value_is_heap_object);
5632 __ JumpIfSmi(cell_value, &slow_case);
5634 __ Ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5635 __ Ldr(value_map, FieldMemOperand(value, HeapObject::kMapOffset));
5636 __ Cmp(cell_value_map, value_map);
5637 __ B(eq, &fast_heapobject_case);
5639 // Fall back to the runtime.
5640 __ Bind(&slow_case);
5642 __ Push(slot, value);
5643 __ TailCallRuntime(is_strict(language_mode())
5644 ? Runtime::kStoreGlobalViaContext_Strict
5645 : Runtime::kStoreGlobalViaContext_Sloppy,
5650 // The number of register that CallApiFunctionAndReturn will need to save on
5651 // the stack. The space for these registers need to be allocated in the
5652 // ExitFrame before calling CallApiFunctionAndReturn.
5653 static const int kCallApiFunctionSpillSpace = 4;
5656 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5657 return static_cast<int>(ref0.address() - ref1.address());
5661 // Calls an API function. Allocates HandleScope, extracts returned value
5662 // from handle and propagates exceptions.
5663 // 'stack_space' is the space to be unwound on exit (includes the call JS
5664 // arguments space and the additional space allocated for the fast call).
5665 // 'spill_offset' is the offset from the stack pointer where
5666 // CallApiFunctionAndReturn can spill registers.
5667 static void CallApiFunctionAndReturn(
5668 MacroAssembler* masm, Register function_address,
5669 ExternalReference thunk_ref, int stack_space,
5670 MemOperand* stack_space_operand, int spill_offset,
5671 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5672 ASM_LOCATION("CallApiFunctionAndReturn");
5673 Isolate* isolate = masm->isolate();
5674 ExternalReference next_address =
5675 ExternalReference::handle_scope_next_address(isolate);
5676 const int kNextOffset = 0;
5677 const int kLimitOffset = AddressOffset(
5678 ExternalReference::handle_scope_limit_address(isolate), next_address);
5679 const int kLevelOffset = AddressOffset(
5680 ExternalReference::handle_scope_level_address(isolate), next_address);
5682 DCHECK(function_address.is(x1) || function_address.is(x2));
5684 Label profiler_disabled;
5685 Label end_profiler_check;
5686 __ Mov(x10, ExternalReference::is_profiling_address(isolate));
5687 __ Ldrb(w10, MemOperand(x10));
5688 __ Cbz(w10, &profiler_disabled);
5689 __ Mov(x3, thunk_ref);
5690 __ B(&end_profiler_check);
5692 __ Bind(&profiler_disabled);
5693 __ Mov(x3, function_address);
5694 __ Bind(&end_profiler_check);
5696 // Save the callee-save registers we are going to use.
5697 // TODO(all): Is this necessary? ARM doesn't do it.
5698 STATIC_ASSERT(kCallApiFunctionSpillSpace == 4);
5699 __ Poke(x19, (spill_offset + 0) * kXRegSize);
5700 __ Poke(x20, (spill_offset + 1) * kXRegSize);
5701 __ Poke(x21, (spill_offset + 2) * kXRegSize);
5702 __ Poke(x22, (spill_offset + 3) * kXRegSize);
5704 // Allocate HandleScope in callee-save registers.
5705 // We will need to restore the HandleScope after the call to the API function,
5706 // by allocating it in callee-save registers they will be preserved by C code.
5707 Register handle_scope_base = x22;
5708 Register next_address_reg = x19;
5709 Register limit_reg = x20;
5710 Register level_reg = w21;
5712 __ Mov(handle_scope_base, next_address);
5713 __ Ldr(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5714 __ Ldr(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5715 __ Ldr(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5716 __ Add(level_reg, level_reg, 1);
5717 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5719 if (FLAG_log_timer_events) {
5720 FrameScope frame(masm, StackFrame::MANUAL);
5721 __ PushSafepointRegisters();
5722 __ Mov(x0, ExternalReference::isolate_address(isolate));
5723 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5725 __ PopSafepointRegisters();
5728 // Native call returns to the DirectCEntry stub which redirects to the
5729 // return address pushed on stack (could have moved after GC).
5730 // DirectCEntry stub itself is generated early and never moves.
5731 DirectCEntryStub stub(isolate);
5732 stub.GenerateCall(masm, x3);
5734 if (FLAG_log_timer_events) {
5735 FrameScope frame(masm, StackFrame::MANUAL);
5736 __ PushSafepointRegisters();
5737 __ Mov(x0, ExternalReference::isolate_address(isolate));
5738 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5740 __ PopSafepointRegisters();
5743 Label promote_scheduled_exception;
5744 Label delete_allocated_handles;
5745 Label leave_exit_frame;
5746 Label return_value_loaded;
5748 // Load value from ReturnValue.
5749 __ Ldr(x0, return_value_operand);
5750 __ Bind(&return_value_loaded);
5751 // No more valid handles (the result handle was the last one). Restore
5752 // previous handle scope.
5753 __ Str(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5754 if (__ emit_debug_code()) {
5755 __ Ldr(w1, MemOperand(handle_scope_base, kLevelOffset));
5756 __ Cmp(w1, level_reg);
5757 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5759 __ Sub(level_reg, level_reg, 1);
5760 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5761 __ Ldr(x1, MemOperand(handle_scope_base, kLimitOffset));
5762 __ Cmp(limit_reg, x1);
5763 __ B(ne, &delete_allocated_handles);
5765 // Leave the API exit frame.
5766 __ Bind(&leave_exit_frame);
5767 // Restore callee-saved registers.
5768 __ Peek(x19, (spill_offset + 0) * kXRegSize);
5769 __ Peek(x20, (spill_offset + 1) * kXRegSize);
5770 __ Peek(x21, (spill_offset + 2) * kXRegSize);
5771 __ Peek(x22, (spill_offset + 3) * kXRegSize);
5773 bool restore_context = context_restore_operand != NULL;
5774 if (restore_context) {
5775 __ Ldr(cp, *context_restore_operand);
5778 if (stack_space_operand != NULL) {
5779 __ Ldr(w2, *stack_space_operand);
5782 __ LeaveExitFrame(false, x1, !restore_context);
5784 // Check if the function scheduled an exception.
5785 __ Mov(x5, ExternalReference::scheduled_exception_address(isolate));
5786 __ Ldr(x5, MemOperand(x5));
5787 __ JumpIfNotRoot(x5, Heap::kTheHoleValueRootIndex,
5788 &promote_scheduled_exception);
5790 if (stack_space_operand != NULL) {
5793 __ Drop(stack_space);
5797 // Re-throw by promoting a scheduled exception.
5798 __ Bind(&promote_scheduled_exception);
5799 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5801 // HandleScope limit has changed. Delete allocated extensions.
5802 __ Bind(&delete_allocated_handles);
5803 __ Str(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5804 // Save the return value in a callee-save register.
5805 Register saved_result = x19;
5806 __ Mov(saved_result, x0);
5807 __ Mov(x0, ExternalReference::isolate_address(isolate));
5808 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5810 __ Mov(x0, saved_result);
5811 __ B(&leave_exit_frame);
5815 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5816 const ParameterCount& argc,
5817 bool return_first_arg,
5818 bool call_data_undefined) {
5819 // ----------- S t a t e -------------
5821 // -- x4 : call_data
5823 // -- x1 : api_function_address
5824 // -- x3 : number of arguments if argc is a register
5827 // -- sp[0] : last argument
5829 // -- sp[(argc - 1) * 8] : first argument
5830 // -- sp[argc * 8] : receiver
5831 // -----------------------------------
5833 Register callee = x0;
5834 Register call_data = x4;
5835 Register holder = x2;
5836 Register api_function_address = x1;
5837 Register context = cp;
5839 typedef FunctionCallbackArguments FCA;
5841 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5842 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5843 STATIC_ASSERT(FCA::kDataIndex == 4);
5844 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5845 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5846 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5847 STATIC_ASSERT(FCA::kHolderIndex == 0);
5848 STATIC_ASSERT(FCA::kArgsLength == 7);
5850 DCHECK(argc.is_immediate() || x3.is(argc.reg()));
5852 // FunctionCallbackArguments: context, callee and call data.
5853 __ Push(context, callee, call_data);
5855 // Load context from callee
5856 __ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5858 if (!call_data_undefined) {
5859 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
5861 Register isolate_reg = x5;
5862 __ Mov(isolate_reg, ExternalReference::isolate_address(masm->isolate()));
5864 // FunctionCallbackArguments:
5865 // return value, return value default, isolate, holder.
5866 __ Push(call_data, call_data, isolate_reg, holder);
5868 // Prepare arguments.
5870 __ Mov(args, masm->StackPointer());
5872 // Allocate the v8::Arguments structure in the arguments' space, since it's
5873 // not controlled by GC.
5874 const int kApiStackSpace = 4;
5876 // Allocate space for CallApiFunctionAndReturn can store some scratch
5877 // registeres on the stack.
5878 const int kCallApiFunctionSpillSpace = 4;
5880 FrameScope frame_scope(masm, StackFrame::MANUAL);
5881 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5883 DCHECK(!AreAliased(x0, api_function_address));
5884 // x0 = FunctionCallbackInfo&
5885 // Arguments is after the return address.
5886 __ Add(x0, masm->StackPointer(), 1 * kPointerSize);
5887 if (argc.is_immediate()) {
5888 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5890 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5891 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5892 // FunctionCallbackInfo::length_ = argc and
5893 // FunctionCallbackInfo::is_construct_call = 0
5894 __ Mov(x10, argc.immediate());
5895 __ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize));
5897 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5898 __ Add(x10, args, Operand(argc.reg(), LSL, kPointerSizeLog2));
5899 __ Add(x10, x10, (FCA::kArgsLength - 1) * kPointerSize);
5900 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5901 // FunctionCallbackInfo::length_ = argc and
5902 // FunctionCallbackInfo::is_construct_call
5903 __ Add(x10, argc.reg(), FCA::kArgsLength + 1);
5904 __ Mov(x10, Operand(x10, LSL, kPointerSizeLog2));
5905 __ Stp(argc.reg(), x10, MemOperand(x0, 2 * kPointerSize));
5908 ExternalReference thunk_ref =
5909 ExternalReference::invoke_function_callback(masm->isolate());
5911 AllowExternalCallThatCantCauseGC scope(masm);
5912 MemOperand context_restore_operand(
5913 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5914 // Stores return the first js argument
5915 int return_value_offset = 0;
5916 if (return_first_arg) {
5917 return_value_offset = 2 + FCA::kArgsLength;
5919 return_value_offset = 2 + FCA::kReturnValueOffset;
5921 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5922 int stack_space = 0;
5923 MemOperand is_construct_call_operand =
5924 MemOperand(masm->StackPointer(), 4 * kPointerSize);
5925 MemOperand* stack_space_operand = &is_construct_call_operand;
5926 if (argc.is_immediate()) {
5927 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5928 stack_space_operand = NULL;
5931 const int spill_offset = 1 + kApiStackSpace;
5932 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5933 stack_space_operand, spill_offset,
5934 return_value_operand, &context_restore_operand);
5938 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5939 bool call_data_undefined = this->call_data_undefined();
5940 CallApiFunctionStubHelper(masm, ParameterCount(x3), false,
5941 call_data_undefined);
5945 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5946 bool is_store = this->is_store();
5947 int argc = this->argc();
5948 bool call_data_undefined = this->call_data_undefined();
5949 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5950 call_data_undefined);
5954 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5955 // ----------- S t a t e -------------
5957 // -- sp[8 - kArgsLength*8] : PropertyCallbackArguments object
5959 // -- x2 : api_function_address
5960 // -----------------------------------
5962 Register api_function_address = ApiGetterDescriptor::function_address();
5963 DCHECK(api_function_address.is(x2));
5965 __ Mov(x0, masm->StackPointer()); // x0 = Handle<Name>
5966 __ Add(x1, x0, 1 * kPointerSize); // x1 = PCA
5968 const int kApiStackSpace = 1;
5970 // Allocate space for CallApiFunctionAndReturn can store some scratch
5971 // registeres on the stack.
5972 const int kCallApiFunctionSpillSpace = 4;
5974 FrameScope frame_scope(masm, StackFrame::MANUAL);
5975 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5977 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5978 // x1 (internal::Object** args_) as the data.
5979 __ Poke(x1, 1 * kPointerSize);
5980 __ Add(x1, masm->StackPointer(), 1 * kPointerSize); // x1 = AccessorInfo&
5982 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5984 ExternalReference thunk_ref =
5985 ExternalReference::invoke_accessor_getter_callback(isolate());
5987 const int spill_offset = 1 + kApiStackSpace;
5988 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5989 kStackUnwindSpace, NULL, spill_offset,
5990 MemOperand(fp, 6 * kPointerSize), NULL);
5996 } // namespace internal
5999 #endif // V8_TARGET_ARCH_ARM64