blob: e773b531a1e2784ca34a05626728621c5fd4adc2 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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.
4
5#include "src/v8.h"
6
7#if V8_TARGET_ARCH_ARM64
8
9#include "src/bootstrapper.h"
10#include "src/code-stubs.h"
11#include "src/codegen.h"
12#include "src/ic/handler-compiler.h"
13#include "src/ic/ic.h"
14#include "src/isolate.h"
15#include "src/jsregexp.h"
16#include "src/regexp-macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040017#include "src/runtime/runtime.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000018
19namespace v8 {
20namespace internal {
21
22
23static void InitializeArrayConstructorDescriptor(
24 Isolate* isolate, CodeStubDescriptor* descriptor,
25 int constant_stack_parameter_count) {
26 // cp: context
27 // x1: function
28 // x2: allocation site with elements kind
29 // x0: number of arguments to the constructor function
30 Address deopt_handler = Runtime::FunctionForId(
31 Runtime::kArrayConstructor)->entry;
32
33 if (constant_stack_parameter_count == 0) {
34 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
35 JS_FUNCTION_STUB_MODE);
36 } else {
37 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
38 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
39 }
40}
41
42
43void ArrayNoArgumentConstructorStub::InitializeDescriptor(
44 CodeStubDescriptor* descriptor) {
45 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
46}
47
48
49void ArraySingleArgumentConstructorStub::InitializeDescriptor(
50 CodeStubDescriptor* descriptor) {
51 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
52}
53
54
55void ArrayNArgumentsConstructorStub::InitializeDescriptor(
56 CodeStubDescriptor* descriptor) {
57 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
58}
59
60
61static void InitializeInternalArrayConstructorDescriptor(
62 Isolate* isolate, CodeStubDescriptor* descriptor,
63 int constant_stack_parameter_count) {
64 Address deopt_handler = Runtime::FunctionForId(
65 Runtime::kInternalArrayConstructor)->entry;
66
67 if (constant_stack_parameter_count == 0) {
68 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
69 JS_FUNCTION_STUB_MODE);
70 } else {
71 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
72 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
73 }
74}
75
76
77void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
78 CodeStubDescriptor* descriptor) {
79 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
80}
81
82
83void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
84 CodeStubDescriptor* descriptor) {
85 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
86}
87
88
89void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
90 CodeStubDescriptor* descriptor) {
91 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
92}
93
94
95#define __ ACCESS_MASM(masm)
96
97
98void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
99 ExternalReference miss) {
100 // Update the static counter each time a new code stub is generated.
101 isolate()->counters()->code_stubs()->Increment();
102
103 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
104 int param_count = descriptor.GetEnvironmentParameterCount();
105 {
106 // Call the runtime system in a fresh internal frame.
107 FrameScope scope(masm, StackFrame::INTERNAL);
108 DCHECK((param_count == 0) ||
109 x0.Is(descriptor.GetEnvironmentParameterRegister(param_count - 1)));
110
111 // Push arguments
112 MacroAssembler::PushPopQueue queue(masm);
113 for (int i = 0; i < param_count; ++i) {
114 queue.Queue(descriptor.GetEnvironmentParameterRegister(i));
115 }
116 queue.PushQueued();
117
118 __ CallExternalReference(miss, param_count);
119 }
120
121 __ Ret();
122}
123
124
125void DoubleToIStub::Generate(MacroAssembler* masm) {
126 Label done;
127 Register input = source();
128 Register result = destination();
129 DCHECK(is_truncating());
130
131 DCHECK(result.Is64Bits());
132 DCHECK(jssp.Is(masm->StackPointer()));
133
134 int double_offset = offset();
135
136 DoubleRegister double_scratch = d0; // only used if !skip_fastpath()
137 Register scratch1 = GetAllocatableRegisterThatIsNotOneOf(input, result);
138 Register scratch2 =
139 GetAllocatableRegisterThatIsNotOneOf(input, result, scratch1);
140
141 __ Push(scratch1, scratch2);
142 // Account for saved regs if input is jssp.
143 if (input.is(jssp)) double_offset += 2 * kPointerSize;
144
145 if (!skip_fastpath()) {
146 __ Push(double_scratch);
147 if (input.is(jssp)) double_offset += 1 * kDoubleSize;
148 __ Ldr(double_scratch, MemOperand(input, double_offset));
149 // Try to convert with a FPU convert instruction. This handles all
150 // non-saturating cases.
151 __ TryConvertDoubleToInt64(result, double_scratch, &done);
152 __ Fmov(result, double_scratch);
153 } else {
154 __ Ldr(result, MemOperand(input, double_offset));
155 }
156
157 // If we reach here we need to manually convert the input to an int32.
158
159 // Extract the exponent.
160 Register exponent = scratch1;
161 __ Ubfx(exponent, result, HeapNumber::kMantissaBits,
162 HeapNumber::kExponentBits);
163
164 // It the exponent is >= 84 (kMantissaBits + 32), the result is always 0 since
165 // the mantissa gets shifted completely out of the int32_t result.
166 __ Cmp(exponent, HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 32);
167 __ CzeroX(result, ge);
168 __ B(ge, &done);
169
170 // The Fcvtzs sequence handles all cases except where the conversion causes
171 // signed overflow in the int64_t target. Since we've already handled
172 // exponents >= 84, we can guarantee that 63 <= exponent < 84.
173
174 if (masm->emit_debug_code()) {
175 __ Cmp(exponent, HeapNumber::kExponentBias + 63);
176 // Exponents less than this should have been handled by the Fcvt case.
177 __ Check(ge, kUnexpectedValue);
178 }
179
180 // Isolate the mantissa bits, and set the implicit '1'.
181 Register mantissa = scratch2;
182 __ Ubfx(mantissa, result, 0, HeapNumber::kMantissaBits);
183 __ Orr(mantissa, mantissa, 1UL << HeapNumber::kMantissaBits);
184
185 // Negate the mantissa if necessary.
186 __ Tst(result, kXSignMask);
187 __ Cneg(mantissa, mantissa, ne);
188
189 // Shift the mantissa bits in the correct place. We know that we have to shift
190 // it left here, because exponent >= 63 >= kMantissaBits.
191 __ Sub(exponent, exponent,
192 HeapNumber::kExponentBias + HeapNumber::kMantissaBits);
193 __ Lsl(result, mantissa, exponent);
194
195 __ Bind(&done);
196 if (!skip_fastpath()) {
197 __ Pop(double_scratch);
198 }
199 __ Pop(scratch2, scratch1);
200 __ Ret();
201}
202
203
204// See call site for description.
205static void EmitIdenticalObjectComparison(MacroAssembler* masm,
206 Register left,
207 Register right,
208 Register scratch,
209 FPRegister double_scratch,
210 Label* slow,
211 Condition cond) {
212 DCHECK(!AreAliased(left, right, scratch));
213 Label not_identical, return_equal, heap_number;
214 Register result = x0;
215
216 __ Cmp(right, left);
217 __ B(ne, &not_identical);
218
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 if ((cond == lt) || (cond == gt)) {
224 __ JumpIfObjectType(right, scratch, scratch, FIRST_SPEC_OBJECT_TYPE, slow,
225 ge);
226 } else if (cond == eq) {
227 __ JumpIfHeapNumber(right, &heap_number);
228 } else {
229 Register right_type = scratch;
230 __ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE,
231 &heap_number);
232 // Comparing JS objects with <=, >= is complicated.
233 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
234 __ B(ge, slow);
235 // Normally here we fall through to return_equal, but undefined is
236 // special: (undefined == undefined) == true, but
237 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
238 if ((cond == le) || (cond == ge)) {
239 __ Cmp(right_type, ODDBALL_TYPE);
240 __ B(ne, &return_equal);
241 __ JumpIfNotRoot(right, Heap::kUndefinedValueRootIndex, &return_equal);
242 if (cond == le) {
243 // undefined <= undefined should fail.
244 __ Mov(result, GREATER);
245 } else {
246 // undefined >= undefined should fail.
247 __ Mov(result, LESS);
248 }
249 __ Ret();
250 }
251 }
252
253 __ Bind(&return_equal);
254 if (cond == lt) {
255 __ Mov(result, GREATER); // Things aren't less than themselves.
256 } else if (cond == gt) {
257 __ Mov(result, LESS); // Things aren't greater than themselves.
258 } else {
259 __ Mov(result, EQUAL); // Things are <=, >=, ==, === themselves.
260 }
261 __ Ret();
262
263 // Cases lt and gt have been handled earlier, and case ne is never seen, as
264 // it is handled in the parser (see Parser::ParseBinaryExpression). We are
265 // only concerned with cases ge, le and eq here.
266 if ((cond != lt) && (cond != gt)) {
267 DCHECK((cond == ge) || (cond == le) || (cond == eq));
268 __ Bind(&heap_number);
269 // Left and right are identical pointers to a heap number object. Return
270 // non-equal if the heap number is a NaN, and equal otherwise. Comparing
271 // the number to itself will set the overflow flag iff the number is NaN.
272 __ Ldr(double_scratch, FieldMemOperand(right, HeapNumber::kValueOffset));
273 __ Fcmp(double_scratch, double_scratch);
274 __ B(vc, &return_equal); // Not NaN, so treat as normal heap number.
275
276 if (cond == le) {
277 __ Mov(result, GREATER);
278 } else {
279 __ Mov(result, LESS);
280 }
281 __ Ret();
282 }
283
284 // No fall through here.
285 if (FLAG_debug_code) {
286 __ Unreachable();
287 }
288
289 __ Bind(&not_identical);
290}
291
292
293// See call site for description.
294static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
295 Register left,
296 Register right,
297 Register left_type,
298 Register right_type,
299 Register scratch) {
300 DCHECK(!AreAliased(left, right, left_type, right_type, scratch));
301
302 if (masm->emit_debug_code()) {
303 // We assume that the arguments are not identical.
304 __ Cmp(left, right);
305 __ Assert(ne, kExpectedNonIdenticalObjects);
306 }
307
308 // If either operand is a JS object or an oddball value, then they are not
309 // equal since their pointers are different.
310 // There is no test for undetectability in strict equality.
311 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
312 Label right_non_object;
313
314 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
315 __ B(lt, &right_non_object);
316
317 // Return non-zero - x0 already contains a non-zero pointer.
318 DCHECK(left.is(x0) || right.is(x0));
319 Label return_not_equal;
320 __ Bind(&return_not_equal);
321 __ Ret();
322
323 __ Bind(&right_non_object);
324
325 // Check for oddballs: true, false, null, undefined.
326 __ Cmp(right_type, ODDBALL_TYPE);
327
328 // If right is not ODDBALL, test left. Otherwise, set eq condition.
329 __ Ccmp(left_type, ODDBALL_TYPE, ZFlag, ne);
330
331 // If right or left is not ODDBALL, test left >= FIRST_SPEC_OBJECT_TYPE.
332 // Otherwise, right or left is ODDBALL, so set a ge condition.
333 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NVFlag, ne);
334
335 __ B(ge, &return_not_equal);
336
337 // Internalized strings are unique, so they can only be equal if they are the
338 // same object. We have already tested that case, so if left and right are
339 // both internalized strings, they cannot be equal.
340 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
341 __ Orr(scratch, left_type, right_type);
342 __ TestAndBranchIfAllClear(
343 scratch, kIsNotStringMask | kIsNotInternalizedMask, &return_not_equal);
344}
345
346
347// See call site for description.
348static void EmitSmiNonsmiComparison(MacroAssembler* masm,
349 Register left,
350 Register right,
351 FPRegister left_d,
352 FPRegister right_d,
353 Label* slow,
354 bool strict) {
355 DCHECK(!AreAliased(left_d, right_d));
356 DCHECK((left.is(x0) && right.is(x1)) ||
357 (right.is(x0) && left.is(x1)));
358 Register result = x0;
359
360 Label right_is_smi, done;
361 __ JumpIfSmi(right, &right_is_smi);
362
363 // Left is the smi. Check whether right is a heap number.
364 if (strict) {
365 // If right is not a number and left is a smi, then strict equality cannot
366 // succeed. Return non-equal.
367 Label is_heap_number;
368 __ JumpIfHeapNumber(right, &is_heap_number);
369 // Register right is a non-zero pointer, which is a valid NOT_EQUAL result.
370 if (!right.is(result)) {
371 __ Mov(result, NOT_EQUAL);
372 }
373 __ Ret();
374 __ Bind(&is_heap_number);
375 } else {
376 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
377 // runtime.
378 __ JumpIfNotHeapNumber(right, slow);
379 }
380
381 // Left is the smi. Right is a heap number. Load right value into right_d, and
382 // convert left smi into double in left_d.
383 __ Ldr(right_d, FieldMemOperand(right, HeapNumber::kValueOffset));
384 __ SmiUntagToDouble(left_d, left);
385 __ B(&done);
386
387 __ Bind(&right_is_smi);
388 // Right is a smi. Check whether the non-smi left is a heap number.
389 if (strict) {
390 // If left is not a number and right is a smi then strict equality cannot
391 // succeed. Return non-equal.
392 Label is_heap_number;
393 __ JumpIfHeapNumber(left, &is_heap_number);
394 // Register left is a non-zero pointer, which is a valid NOT_EQUAL result.
395 if (!left.is(result)) {
396 __ Mov(result, NOT_EQUAL);
397 }
398 __ Ret();
399 __ Bind(&is_heap_number);
400 } else {
401 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
402 // runtime.
403 __ JumpIfNotHeapNumber(left, slow);
404 }
405
406 // Right is the smi. Left is a heap number. Load left value into left_d, and
407 // convert right smi into double in right_d.
408 __ Ldr(left_d, FieldMemOperand(left, HeapNumber::kValueOffset));
409 __ SmiUntagToDouble(right_d, right);
410
411 // Fall through to both_loaded_as_doubles.
412 __ Bind(&done);
413}
414
415
416// Fast negative check for internalized-to-internalized equality.
417// See call site for description.
418static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
419 Register left,
420 Register right,
421 Register left_map,
422 Register right_map,
423 Register left_type,
424 Register right_type,
425 Label* possible_strings,
426 Label* not_both_strings) {
427 DCHECK(!AreAliased(left, right, left_map, right_map, left_type, right_type));
428 Register result = x0;
429
430 Label object_test;
431 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
432 // TODO(all): reexamine this branch sequence for optimisation wrt branch
433 // prediction.
434 __ Tbnz(right_type, MaskToBit(kIsNotStringMask), &object_test);
435 __ Tbnz(right_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
436 __ Tbnz(left_type, MaskToBit(kIsNotStringMask), not_both_strings);
437 __ Tbnz(left_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
438
439 // Both are internalized. We already checked that they weren't the same
440 // pointer, so they are not equal.
441 __ Mov(result, NOT_EQUAL);
442 __ Ret();
443
444 __ Bind(&object_test);
445
446 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
447
448 // If right >= FIRST_SPEC_OBJECT_TYPE, test left.
449 // Otherwise, right < FIRST_SPEC_OBJECT_TYPE, so set lt condition.
450 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NFlag, ge);
451
452 __ B(lt, not_both_strings);
453
454 // If both objects are undetectable, they are equal. Otherwise, they are not
455 // equal, since they are different objects and an object is not equal to
456 // undefined.
457
458 // Returning here, so we can corrupt right_type and left_type.
459 Register right_bitfield = right_type;
460 Register left_bitfield = left_type;
461 __ Ldrb(right_bitfield, FieldMemOperand(right_map, Map::kBitFieldOffset));
462 __ Ldrb(left_bitfield, FieldMemOperand(left_map, Map::kBitFieldOffset));
463 __ And(result, right_bitfield, left_bitfield);
464 __ And(result, result, 1 << Map::kIsUndetectable);
465 __ Eor(result, result, 1 << Map::kIsUndetectable);
466 __ Ret();
467}
468
469
470static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
471 CompareICState::State expected,
472 Label* fail) {
473 Label ok;
474 if (expected == CompareICState::SMI) {
475 __ JumpIfNotSmi(input, fail);
476 } else if (expected == CompareICState::NUMBER) {
477 __ JumpIfSmi(input, &ok);
478 __ JumpIfNotHeapNumber(input, fail);
479 }
480 // We could be strict about internalized/non-internalized here, but as long as
481 // hydrogen doesn't care, the stub doesn't have to care either.
482 __ Bind(&ok);
483}
484
485
486void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
487 Register lhs = x1;
488 Register rhs = x0;
489 Register result = x0;
490 Condition cond = GetCondition();
491
492 Label miss;
493 CompareICStub_CheckInputType(masm, lhs, left(), &miss);
494 CompareICStub_CheckInputType(masm, rhs, right(), &miss);
495
496 Label slow; // Call builtin.
497 Label not_smis, both_loaded_as_doubles;
498 Label not_two_smis, smi_done;
499 __ JumpIfEitherNotSmi(lhs, rhs, &not_two_smis);
500 __ SmiUntag(lhs);
501 __ Sub(result, lhs, Operand::UntagSmi(rhs));
502 __ Ret();
503
504 __ Bind(&not_two_smis);
505
506 // NOTICE! This code is only reached after a smi-fast-case check, so it is
507 // certain that at least one operand isn't a smi.
508
509 // Handle the case where the objects are identical. Either returns the answer
510 // or goes to slow. Only falls through if the objects were not identical.
511 EmitIdenticalObjectComparison(masm, lhs, rhs, x10, d0, &slow, cond);
512
513 // If either is a smi (we know that at least one is not a smi), then they can
514 // only be strictly equal if the other is a HeapNumber.
515 __ JumpIfBothNotSmi(lhs, rhs, &not_smis);
516
517 // Exactly one operand is a smi. EmitSmiNonsmiComparison generates code that
518 // can:
519 // 1) Return the answer.
520 // 2) Branch to the slow case.
521 // 3) Fall through to both_loaded_as_doubles.
522 // In case 3, we have found out that we were dealing with a number-number
523 // comparison. The double values of the numbers have been loaded, right into
524 // rhs_d, left into lhs_d.
525 FPRegister rhs_d = d0;
526 FPRegister lhs_d = d1;
527 EmitSmiNonsmiComparison(masm, lhs, rhs, lhs_d, rhs_d, &slow, strict());
528
529 __ Bind(&both_loaded_as_doubles);
530 // The arguments have been converted to doubles and stored in rhs_d and
531 // lhs_d.
532 Label nan;
533 __ Fcmp(lhs_d, rhs_d);
534 __ B(vs, &nan); // Overflow flag set if either is NaN.
535 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
536 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
537 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
538 __ Ret();
539
540 __ Bind(&nan);
541 // Left and/or right is a NaN. Load the result register with whatever makes
542 // the comparison fail, since comparisons with NaN always fail (except ne,
543 // which is filtered out at a higher level.)
544 DCHECK(cond != ne);
545 if ((cond == lt) || (cond == le)) {
546 __ Mov(result, GREATER);
547 } else {
548 __ Mov(result, LESS);
549 }
550 __ Ret();
551
552 __ Bind(&not_smis);
553 // At this point we know we are dealing with two different objects, and
554 // neither of them is a smi. The objects are in rhs_ and lhs_.
555
556 // Load the maps and types of the objects.
557 Register rhs_map = x10;
558 Register rhs_type = x11;
559 Register lhs_map = x12;
560 Register lhs_type = x13;
561 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
562 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
563 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
564 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
565
566 if (strict()) {
567 // This emits a non-equal return sequence for some object types, or falls
568 // through if it was not lucky.
569 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs, lhs_type, rhs_type, x14);
570 }
571
572 Label check_for_internalized_strings;
573 Label flat_string_check;
574 // Check for heap number comparison. Branch to earlier double comparison code
575 // if they are heap numbers, otherwise, branch to internalized string check.
576 __ Cmp(rhs_type, HEAP_NUMBER_TYPE);
577 __ B(ne, &check_for_internalized_strings);
578 __ Cmp(lhs_map, rhs_map);
579
580 // If maps aren't equal, lhs_ and rhs_ are not heap numbers. Branch to flat
581 // string check.
582 __ B(ne, &flat_string_check);
583
584 // Both lhs_ and rhs_ are heap numbers. Load them and branch to the double
585 // comparison code.
586 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
587 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
588 __ B(&both_loaded_as_doubles);
589
590 __ Bind(&check_for_internalized_strings);
591 // In the strict case, the EmitStrictTwoHeapObjectCompare already took care
592 // of internalized strings.
593 if ((cond == eq) && !strict()) {
594 // Returns an answer for two internalized strings or two detectable objects.
595 // Otherwise branches to the string case or not both strings case.
596 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, lhs_map, rhs_map,
597 lhs_type, rhs_type,
598 &flat_string_check, &slow);
599 }
600
601 // Check for both being sequential one-byte strings,
602 // and inline if that is the case.
603 __ Bind(&flat_string_check);
604 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x14,
605 x15, &slow);
606
607 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x10,
608 x11);
609 if (cond == eq) {
610 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
611 x12);
612 } else {
613 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
614 x12, x13);
615 }
616
617 // Never fall through to here.
618 if (FLAG_debug_code) {
619 __ Unreachable();
620 }
621
622 __ Bind(&slow);
623
624 __ Push(lhs, rhs);
625 // Figure out which native to call and setup the arguments.
626 Builtins::JavaScript native;
627 if (cond == eq) {
628 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
629 } else {
630 native = Builtins::COMPARE;
631 int ncr; // NaN compare result
632 if ((cond == lt) || (cond == le)) {
633 ncr = GREATER;
634 } else {
635 DCHECK((cond == gt) || (cond == ge)); // remaining cases
636 ncr = LESS;
637 }
638 __ Mov(x10, Smi::FromInt(ncr));
639 __ Push(x10);
640 }
641
642 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
643 // tagged as a small integer.
644 __ InvokeBuiltin(native, JUMP_FUNCTION);
645
646 __ Bind(&miss);
647 GenerateMiss(masm);
648}
649
650
651void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
652 CPURegList saved_regs = kCallerSaved;
653 CPURegList saved_fp_regs = kCallerSavedFP;
654
655 // We don't allow a GC during a store buffer overflow so there is no need to
656 // store the registers in any particular way, but we do have to store and
657 // restore them.
658
659 // We don't care if MacroAssembler scratch registers are corrupted.
660 saved_regs.Remove(*(masm->TmpList()));
661 saved_fp_regs.Remove(*(masm->FPTmpList()));
662
663 __ PushCPURegList(saved_regs);
664 if (save_doubles()) {
665 __ PushCPURegList(saved_fp_regs);
666 }
667
668 AllowExternalCallThatCantCauseGC scope(masm);
669 __ Mov(x0, ExternalReference::isolate_address(isolate()));
670 __ CallCFunction(
671 ExternalReference::store_buffer_overflow_function(isolate()), 1, 0);
672
673 if (save_doubles()) {
674 __ PopCPURegList(saved_fp_regs);
675 }
676 __ PopCPURegList(saved_regs);
677 __ Ret();
678}
679
680
681void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
682 Isolate* isolate) {
683 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
684 stub1.GetCode();
685 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
686 stub2.GetCode();
687}
688
689
690void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
691 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
692 UseScratchRegisterScope temps(masm);
693 Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr());
694 Register return_address = temps.AcquireX();
695 __ Mov(return_address, lr);
696 // Restore lr with the value it had before the call to this stub (the value
697 // which must be pushed).
698 __ Mov(lr, saved_lr);
699 __ PushSafepointRegisters();
700 __ Ret(return_address);
701}
702
703
704void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
705 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
706 UseScratchRegisterScope temps(masm);
707 Register return_address = temps.AcquireX();
708 // Preserve the return address (lr will be clobbered by the pop).
709 __ Mov(return_address, lr);
710 __ PopSafepointRegisters();
711 __ Ret(return_address);
712}
713
714
715void MathPowStub::Generate(MacroAssembler* masm) {
716 // Stack on entry:
717 // jssp[0]: Exponent (as a tagged value).
718 // jssp[1]: Base (as a tagged value).
719 //
720 // The (tagged) result will be returned in x0, as a heap number.
721
722 Register result_tagged = x0;
723 Register base_tagged = x10;
724 Register exponent_tagged = MathPowTaggedDescriptor::exponent();
725 DCHECK(exponent_tagged.is(x11));
726 Register exponent_integer = MathPowIntegerDescriptor::exponent();
727 DCHECK(exponent_integer.is(x12));
728 Register scratch1 = x14;
729 Register scratch0 = x15;
730 Register saved_lr = x19;
731 FPRegister result_double = d0;
732 FPRegister base_double = d0;
733 FPRegister exponent_double = d1;
734 FPRegister base_double_copy = d2;
735 FPRegister scratch1_double = d6;
736 FPRegister scratch0_double = d7;
737
738 // A fast-path for integer exponents.
739 Label exponent_is_smi, exponent_is_integer;
740 // Bail out to runtime.
741 Label call_runtime;
742 // Allocate a heap number for the result, and return it.
743 Label done;
744
745 // Unpack the inputs.
746 if (exponent_type() == ON_STACK) {
747 Label base_is_smi;
748 Label unpack_exponent;
749
750 __ Pop(exponent_tagged, base_tagged);
751
752 __ JumpIfSmi(base_tagged, &base_is_smi);
753 __ JumpIfNotHeapNumber(base_tagged, &call_runtime);
754 // base_tagged is a heap number, so load its double value.
755 __ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset));
756 __ B(&unpack_exponent);
757 __ Bind(&base_is_smi);
758 // base_tagged is a SMI, so untag it and convert it to a double.
759 __ SmiUntagToDouble(base_double, base_tagged);
760
761 __ Bind(&unpack_exponent);
762 // x10 base_tagged The tagged base (input).
763 // x11 exponent_tagged The tagged exponent (input).
764 // d1 base_double The base as a double.
765 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
766 __ JumpIfNotHeapNumber(exponent_tagged, &call_runtime);
767 // exponent_tagged is a heap number, so load its double value.
768 __ Ldr(exponent_double,
769 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
770 } else if (exponent_type() == TAGGED) {
771 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
772 __ Ldr(exponent_double,
773 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
774 }
775
776 // Handle double (heap number) exponents.
777 if (exponent_type() != INTEGER) {
778 // Detect integer exponents stored as doubles and handle those in the
779 // integer fast-path.
780 __ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
781 scratch0_double, &exponent_is_integer);
782
783 if (exponent_type() == ON_STACK) {
784 FPRegister half_double = d3;
785 FPRegister minus_half_double = d4;
786 // Detect square root case. Crankshaft detects constant +/-0.5 at compile
787 // time and uses DoMathPowHalf instead. We then skip this check for
788 // non-constant cases of +/-0.5 as these hardly occur.
789
790 __ Fmov(minus_half_double, -0.5);
791 __ Fmov(half_double, 0.5);
792 __ Fcmp(minus_half_double, exponent_double);
793 __ Fccmp(half_double, exponent_double, NZFlag, ne);
794 // Condition flags at this point:
795 // 0.5; nZCv // Identified by eq && pl
796 // -0.5: NZcv // Identified by eq && mi
797 // other: ?z?? // Identified by ne
798 __ B(ne, &call_runtime);
799
800 // The exponent is 0.5 or -0.5.
801
802 // Given that exponent is known to be either 0.5 or -0.5, the following
803 // special cases could apply (according to ECMA-262 15.8.2.13):
804 //
805 // base.isNaN(): The result is NaN.
806 // (base == +INFINITY) || (base == -INFINITY)
807 // exponent == 0.5: The result is +INFINITY.
808 // exponent == -0.5: The result is +0.
809 // (base == +0) || (base == -0)
810 // exponent == 0.5: The result is +0.
811 // exponent == -0.5: The result is +INFINITY.
812 // (base < 0) && base.isFinite(): The result is NaN.
813 //
814 // Fsqrt (and Fdiv for the -0.5 case) can handle all of those except
815 // where base is -INFINITY or -0.
816
817 // Add +0 to base. This has no effect other than turning -0 into +0.
818 __ Fadd(base_double, base_double, fp_zero);
819 // The operation -0+0 results in +0 in all cases except where the
820 // FPCR rounding mode is 'round towards minus infinity' (RM). The
821 // ARM64 simulator does not currently simulate FPCR (where the rounding
822 // mode is set), so test the operation with some debug code.
823 if (masm->emit_debug_code()) {
824 UseScratchRegisterScope temps(masm);
825 Register temp = temps.AcquireX();
826 __ Fneg(scratch0_double, fp_zero);
827 // Verify that we correctly generated +0.0 and -0.0.
828 // bits(+0.0) = 0x0000000000000000
829 // bits(-0.0) = 0x8000000000000000
830 __ Fmov(temp, fp_zero);
831 __ CheckRegisterIsClear(temp, kCouldNotGenerateZero);
832 __ Fmov(temp, scratch0_double);
833 __ Eor(temp, temp, kDSignMask);
834 __ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero);
835 // Check that -0.0 + 0.0 == +0.0.
836 __ Fadd(scratch0_double, scratch0_double, fp_zero);
837 __ Fmov(temp, scratch0_double);
838 __ CheckRegisterIsClear(temp, kExpectedPositiveZero);
839 }
840
841 // If base is -INFINITY, make it +INFINITY.
842 // * Calculate base - base: All infinities will become NaNs since both
843 // -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64.
844 // * If the result is NaN, calculate abs(base).
845 __ Fsub(scratch0_double, base_double, base_double);
846 __ Fcmp(scratch0_double, 0.0);
847 __ Fabs(scratch1_double, base_double);
848 __ Fcsel(base_double, scratch1_double, base_double, vs);
849
850 // Calculate the square root of base.
851 __ Fsqrt(result_double, base_double);
852 __ Fcmp(exponent_double, 0.0);
853 __ B(ge, &done); // Finish now for exponents of 0.5.
854 // Find the inverse for exponents of -0.5.
855 __ Fmov(scratch0_double, 1.0);
856 __ Fdiv(result_double, scratch0_double, result_double);
857 __ B(&done);
858 }
859
860 {
861 AllowExternalCallThatCantCauseGC scope(masm);
862 __ Mov(saved_lr, lr);
863 __ CallCFunction(
864 ExternalReference::power_double_double_function(isolate()),
865 0, 2);
866 __ Mov(lr, saved_lr);
867 __ B(&done);
868 }
869
870 // Handle SMI exponents.
871 __ Bind(&exponent_is_smi);
872 // x10 base_tagged The tagged base (input).
873 // x11 exponent_tagged The tagged exponent (input).
874 // d1 base_double The base as a double.
875 __ SmiUntag(exponent_integer, exponent_tagged);
876 }
877
878 __ Bind(&exponent_is_integer);
879 // x10 base_tagged The tagged base (input).
880 // x11 exponent_tagged The tagged exponent (input).
881 // x12 exponent_integer The exponent as an integer.
882 // d1 base_double The base as a double.
883
884 // Find abs(exponent). For negative exponents, we can find the inverse later.
885 Register exponent_abs = x13;
886 __ Cmp(exponent_integer, 0);
887 __ Cneg(exponent_abs, exponent_integer, mi);
888 // x13 exponent_abs The value of abs(exponent_integer).
889
890 // Repeatedly multiply to calculate the power.
891 // result = 1.0;
892 // For each bit n (exponent_integer{n}) {
893 // if (exponent_integer{n}) {
894 // result *= base;
895 // }
896 // base *= base;
897 // if (remaining bits in exponent_integer are all zero) {
898 // break;
899 // }
900 // }
901 Label power_loop, power_loop_entry, power_loop_exit;
902 __ Fmov(scratch1_double, base_double);
903 __ Fmov(base_double_copy, base_double);
904 __ Fmov(result_double, 1.0);
905 __ B(&power_loop_entry);
906
907 __ Bind(&power_loop);
908 __ Fmul(scratch1_double, scratch1_double, scratch1_double);
909 __ Lsr(exponent_abs, exponent_abs, 1);
910 __ Cbz(exponent_abs, &power_loop_exit);
911
912 __ Bind(&power_loop_entry);
913 __ Tbz(exponent_abs, 0, &power_loop);
914 __ Fmul(result_double, result_double, scratch1_double);
915 __ B(&power_loop);
916
917 __ Bind(&power_loop_exit);
918
919 // If the exponent was positive, result_double holds the result.
920 __ Tbz(exponent_integer, kXSignBit, &done);
921
922 // The exponent was negative, so find the inverse.
923 __ Fmov(scratch0_double, 1.0);
924 __ Fdiv(result_double, scratch0_double, result_double);
925 // ECMA-262 only requires Math.pow to return an 'implementation-dependent
926 // approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
927 // to calculate the subnormal value 2^-1074. This method of calculating
928 // negative powers doesn't work because 2^1074 overflows to infinity. To
929 // catch this corner-case, we bail out if the result was 0. (This can only
930 // occur if the divisor is infinity or the base is zero.)
931 __ Fcmp(result_double, 0.0);
932 __ B(&done, ne);
933
934 if (exponent_type() == ON_STACK) {
935 // Bail out to runtime code.
936 __ Bind(&call_runtime);
937 // Put the arguments back on the stack.
938 __ Push(base_tagged, exponent_tagged);
939 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
940
941 // Return.
942 __ Bind(&done);
943 __ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1,
944 result_double);
945 DCHECK(result_tagged.is(x0));
946 __ IncrementCounter(
947 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
948 __ Ret();
949 } else {
950 AllowExternalCallThatCantCauseGC scope(masm);
951 __ Mov(saved_lr, lr);
952 __ Fmov(base_double, base_double_copy);
953 __ Scvtf(exponent_double, exponent_integer);
954 __ CallCFunction(
955 ExternalReference::power_double_double_function(isolate()),
956 0, 2);
957 __ Mov(lr, saved_lr);
958 __ Bind(&done);
959 __ IncrementCounter(
960 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
961 __ Ret();
962 }
963}
964
965
966void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
967 // It is important that the following stubs are generated in this order
968 // because pregenerated stubs can only call other pregenerated stubs.
969 // RecordWriteStub uses StoreBufferOverflowStub, which in turn uses
970 // CEntryStub.
971 CEntryStub::GenerateAheadOfTime(isolate);
972 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
973 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
974 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
975 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
976 BinaryOpICStub::GenerateAheadOfTime(isolate);
977 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
978 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
979 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
980}
981
982
983void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
984 StoreRegistersStateStub stub(isolate);
985 stub.GetCode();
986}
987
988
989void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
990 RestoreRegistersStateStub stub(isolate);
991 stub.GetCode();
992}
993
994
995void CodeStub::GenerateFPStubs(Isolate* isolate) {
996 // Floating-point code doesn't get special handling in ARM64, so there's
997 // nothing to do here.
998 USE(isolate);
999}
1000
1001
1002bool CEntryStub::NeedsImmovableCode() {
1003 // CEntryStub stores the return address on the stack before calling into
1004 // C++ code. In some cases, the VM accesses this address, but it is not used
1005 // when the C++ code returns to the stub because LR holds the return address
1006 // in AAPCS64. If the stub is moved (perhaps during a GC), we could end up
1007 // returning to dead code.
1008 // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't
1009 // find any comment to confirm this, and I don't hit any crashes whatever
1010 // this function returns. The anaylsis should be properly confirmed.
1011 return true;
1012}
1013
1014
1015void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1016 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1017 stub.GetCode();
1018 CEntryStub stub_fp(isolate, 1, kSaveFPRegs);
1019 stub_fp.GetCode();
1020}
1021
1022
1023void CEntryStub::Generate(MacroAssembler* masm) {
1024 // The Abort mechanism relies on CallRuntime, which in turn relies on
1025 // CEntryStub, so until this stub has been generated, we have to use a
1026 // fall-back Abort mechanism.
1027 //
1028 // Note that this stub must be generated before any use of Abort.
1029 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
1030
1031 ASM_LOCATION("CEntryStub::Generate entry");
1032 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1033
1034 // Register parameters:
1035 // x0: argc (including receiver, untagged)
1036 // x1: target
1037 //
1038 // The stack on entry holds the arguments and the receiver, with the receiver
1039 // at the highest address:
1040 //
1041 // jssp]argc-1]: receiver
1042 // jssp[argc-2]: arg[argc-2]
1043 // ... ...
1044 // jssp[1]: arg[1]
1045 // jssp[0]: arg[0]
1046 //
1047 // The arguments are in reverse order, so that arg[argc-2] is actually the
1048 // first argument to the target function and arg[0] is the last.
1049 DCHECK(jssp.Is(__ StackPointer()));
1050 const Register& argc_input = x0;
1051 const Register& target_input = x1;
1052
1053 // Calculate argv, argc and the target address, and store them in
1054 // callee-saved registers so we can retry the call without having to reload
1055 // these arguments.
1056 // TODO(jbramley): If the first call attempt succeeds in the common case (as
1057 // it should), then we might be better off putting these parameters directly
1058 // into their argument registers, rather than using callee-saved registers and
1059 // preserving them on the stack.
1060 const Register& argv = x21;
1061 const Register& argc = x22;
1062 const Register& target = x23;
1063
1064 // Derive argv from the stack pointer so that it points to the first argument
1065 // (arg[argc-2]), or just below the receiver in case there are no arguments.
1066 // - Adjust for the arg[] array.
1067 Register temp_argv = x11;
1068 __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
1069 // - Adjust for the receiver.
1070 __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
1071
1072 // Enter the exit frame. Reserve three slots to preserve x21-x23 callee-saved
1073 // registers.
1074 FrameScope scope(masm, StackFrame::MANUAL);
1075 __ EnterExitFrame(save_doubles(), x10, 3);
1076 DCHECK(csp.Is(__ StackPointer()));
1077
1078 // Poke callee-saved registers into reserved space.
1079 __ Poke(argv, 1 * kPointerSize);
1080 __ Poke(argc, 2 * kPointerSize);
1081 __ Poke(target, 3 * kPointerSize);
1082
1083 // We normally only keep tagged values in callee-saved registers, as they
1084 // could be pushed onto the stack by called stubs and functions, and on the
1085 // stack they can confuse the GC. However, we're only calling C functions
1086 // which can push arbitrary data onto the stack anyway, and so the GC won't
1087 // examine that part of the stack.
1088 __ Mov(argc, argc_input);
1089 __ Mov(target, target_input);
1090 __ Mov(argv, temp_argv);
1091
1092 // x21 : argv
1093 // x22 : argc
1094 // x23 : call target
1095 //
1096 // The stack (on entry) holds the arguments and the receiver, with the
1097 // receiver at the highest address:
1098 //
1099 // argv[8]: receiver
1100 // argv -> argv[0]: arg[argc-2]
1101 // ... ...
1102 // argv[...]: arg[1]
1103 // argv[...]: arg[0]
1104 //
1105 // Immediately below (after) this is the exit frame, as constructed by
1106 // EnterExitFrame:
1107 // fp[8]: CallerPC (lr)
1108 // fp -> fp[0]: CallerFP (old fp)
1109 // fp[-8]: Space reserved for SPOffset.
1110 // fp[-16]: CodeObject()
1111 // csp[...]: Saved doubles, if saved_doubles is true.
1112 // csp[32]: Alignment padding, if necessary.
1113 // csp[24]: Preserved x23 (used for target).
1114 // csp[16]: Preserved x22 (used for argc).
1115 // csp[8]: Preserved x21 (used for argv).
1116 // csp -> csp[0]: Space reserved for the return address.
1117 //
1118 // After a successful call, the exit frame, preserved registers (x21-x23) and
1119 // the arguments (including the receiver) are dropped or popped as
1120 // appropriate. The stub then returns.
1121 //
1122 // After an unsuccessful call, the exit frame and suchlike are left
1123 // untouched, and the stub either throws an exception by jumping to one of
1124 // the exception_returned label.
1125
1126 DCHECK(csp.Is(__ StackPointer()));
1127
1128 // Prepare AAPCS64 arguments to pass to the builtin.
1129 __ Mov(x0, argc);
1130 __ Mov(x1, argv);
1131 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1132
1133 Label return_location;
1134 __ Adr(x12, &return_location);
1135 __ Poke(x12, 0);
1136
1137 if (__ emit_debug_code()) {
1138 // Verify that the slot below fp[kSPOffset]-8 points to the return location
1139 // (currently in x12).
1140 UseScratchRegisterScope temps(masm);
1141 Register temp = temps.AcquireX();
1142 __ Ldr(temp, MemOperand(fp, ExitFrameConstants::kSPOffset));
1143 __ Ldr(temp, MemOperand(temp, -static_cast<int64_t>(kXRegSize)));
1144 __ Cmp(temp, x12);
1145 __ Check(eq, kReturnAddressNotFoundInFrame);
1146 }
1147
1148 // Call the builtin.
1149 __ Blr(target);
1150 __ Bind(&return_location);
1151
1152 // x0 result The return code from the call.
1153 // x21 argv
1154 // x22 argc
1155 // x23 target
1156 const Register& result = x0;
1157
1158 // Check result for exception sentinel.
1159 Label exception_returned;
1160 __ CompareRoot(result, Heap::kExceptionRootIndex);
1161 __ B(eq, &exception_returned);
1162
1163 // The call succeeded, so unwind the stack and return.
1164
1165 // Restore callee-saved registers x21-x23.
1166 __ Mov(x11, argc);
1167
1168 __ Peek(argv, 1 * kPointerSize);
1169 __ Peek(argc, 2 * kPointerSize);
1170 __ Peek(target, 3 * kPointerSize);
1171
1172 __ LeaveExitFrame(save_doubles(), x10, true);
1173 DCHECK(jssp.Is(__ StackPointer()));
1174 // Pop or drop the remaining stack slots and return from the stub.
1175 // jssp[24]: Arguments array (of size argc), including receiver.
1176 // jssp[16]: Preserved x23 (used for target).
1177 // jssp[8]: Preserved x22 (used for argc).
1178 // jssp[0]: Preserved x21 (used for argv).
1179 __ Drop(x11);
1180 __ AssertFPCRState();
1181 __ Ret();
1182
1183 // The stack pointer is still csp if we aren't returning, and the frame
1184 // hasn't changed (except for the return address).
1185 __ SetStackPointer(csp);
1186
1187 // Handling of exception.
1188 __ Bind(&exception_returned);
1189
1190 // Retrieve the pending exception.
1191 ExternalReference pending_exception_address(
1192 Isolate::kPendingExceptionAddress, isolate());
1193 const Register& exception = result;
1194 const Register& exception_address = x11;
1195 __ Mov(exception_address, Operand(pending_exception_address));
1196 __ Ldr(exception, MemOperand(exception_address));
1197
1198 // Clear the pending exception.
1199 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
1200 __ Str(x10, MemOperand(exception_address));
1201
1202 // x0 exception The exception descriptor.
1203 // x21 argv
1204 // x22 argc
1205 // x23 target
1206
1207 // Special handling of termination exceptions, which are uncatchable by
1208 // JavaScript code.
1209 Label throw_termination_exception;
1210 __ Cmp(exception, Operand(isolate()->factory()->termination_exception()));
1211 __ B(eq, &throw_termination_exception);
1212
1213 // We didn't execute a return case, so the stack frame hasn't been updated
1214 // (except for the return address slot). However, we don't need to initialize
1215 // jssp because the throw method will immediately overwrite it when it
1216 // unwinds the stack.
1217 __ SetStackPointer(jssp);
1218
1219 ASM_LOCATION("Throw normal");
1220 __ Mov(argv, 0);
1221 __ Mov(argc, 0);
1222 __ Mov(target, 0);
1223 __ Throw(x0, x10, x11, x12, x13);
1224
1225 __ Bind(&throw_termination_exception);
1226 ASM_LOCATION("Throw termination");
1227 __ Mov(argv, 0);
1228 __ Mov(argc, 0);
1229 __ Mov(target, 0);
1230 __ ThrowUncatchable(x0, x10, x11, x12, x13);
1231}
1232
1233
1234// This is the entry point from C++. 5 arguments are provided in x0-x4.
1235// See use of the CALL_GENERATED_CODE macro for example in src/execution.cc.
1236// Input:
1237// x0: code entry.
1238// x1: function.
1239// x2: receiver.
1240// x3: argc.
1241// x4: argv.
1242// Output:
1243// x0: result.
1244void JSEntryStub::Generate(MacroAssembler* masm) {
1245 DCHECK(jssp.Is(__ StackPointer()));
1246 Register code_entry = x0;
1247
1248 // Enable instruction instrumentation. This only works on the simulator, and
1249 // will have no effect on the model or real hardware.
1250 __ EnableInstrumentation();
1251
1252 Label invoke, handler_entry, exit;
1253
1254 // Push callee-saved registers and synchronize the system stack pointer (csp)
1255 // and the JavaScript stack pointer (jssp).
1256 //
1257 // We must not write to jssp until after the PushCalleeSavedRegisters()
1258 // call, since jssp is itself a callee-saved register.
1259 __ SetStackPointer(csp);
1260 __ PushCalleeSavedRegisters();
1261 __ Mov(jssp, csp);
1262 __ SetStackPointer(jssp);
1263
1264 // Configure the FPCR. We don't restore it, so this is technically not allowed
1265 // according to AAPCS64. However, we only set default-NaN mode and this will
1266 // be harmless for most C code. Also, it works for ARM.
1267 __ ConfigureFPCR();
1268
1269 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1270
1271 // Set up the reserved register for 0.0.
1272 __ Fmov(fp_zero, 0.0);
1273
1274 // Build an entry frame (see layout below).
1275 int marker = type();
1276 int64_t bad_frame_pointer = -1L; // Bad frame pointer to fail if it is used.
1277 __ Mov(x13, bad_frame_pointer);
1278 __ Mov(x12, Smi::FromInt(marker));
1279 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1280 __ Ldr(x10, MemOperand(x11));
1281
1282 __ Push(x13, xzr, x12, x10);
1283 // Set up fp.
1284 __ Sub(fp, jssp, EntryFrameConstants::kCallerFPOffset);
1285
1286 // Push the JS entry frame marker. Also set js_entry_sp if this is the
1287 // outermost JS call.
1288 Label non_outermost_js, done;
1289 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1290 __ Mov(x10, ExternalReference(js_entry_sp));
1291 __ Ldr(x11, MemOperand(x10));
1292 __ Cbnz(x11, &non_outermost_js);
1293 __ Str(fp, MemOperand(x10));
1294 __ Mov(x12, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1295 __ Push(x12);
1296 __ B(&done);
1297 __ Bind(&non_outermost_js);
1298 // We spare one instruction by pushing xzr since the marker is 0.
1299 DCHECK(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME) == NULL);
1300 __ Push(xzr);
1301 __ Bind(&done);
1302
1303 // The frame set up looks like this:
1304 // jssp[0] : JS entry frame marker.
1305 // jssp[1] : C entry FP.
1306 // jssp[2] : stack frame marker.
1307 // jssp[3] : stack frmae marker.
1308 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1309
1310
1311 // Jump to a faked try block that does the invoke, with a faked catch
1312 // block that sets the pending exception.
1313 __ B(&invoke);
1314
1315 // Prevent the constant pool from being emitted between the record of the
1316 // handler_entry position and the first instruction of the sequence here.
1317 // There is no risk because Assembler::Emit() emits the instruction before
1318 // checking for constant pool emission, but we do not want to depend on
1319 // that.
1320 {
1321 Assembler::BlockPoolsScope block_pools(masm);
1322 __ bind(&handler_entry);
1323 handler_offset_ = handler_entry.pos();
1324 // Caught exception: Store result (exception) in the pending exception
1325 // field in the JSEnv and return a failure sentinel. Coming in here the
1326 // fp will be invalid because the PushTryHandler below sets it to 0 to
1327 // signal the existence of the JSEntry frame.
1328 __ Mov(x10, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1329 isolate())));
1330 }
1331 __ Str(code_entry, MemOperand(x10));
1332 __ LoadRoot(x0, Heap::kExceptionRootIndex);
1333 __ B(&exit);
1334
1335 // Invoke: Link this frame into the handler chain. There's only one
1336 // handler block in this code object, so its index is 0.
1337 __ Bind(&invoke);
1338 __ PushTryHandler(StackHandler::JS_ENTRY, 0);
1339 // If an exception not caught by another handler occurs, this handler
1340 // returns control to the code after the B(&invoke) above, which
1341 // restores all callee-saved registers (including cp and fp) to their
1342 // saved values before returning a failure to C.
1343
1344 // Clear any pending exceptions.
1345 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
1346 __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1347 isolate())));
1348 __ Str(x10, MemOperand(x11));
1349
1350 // Invoke the function by calling through the JS entry trampoline builtin.
1351 // Notice that we cannot store a reference to the trampoline code directly in
1352 // this stub, because runtime stubs are not traversed when doing GC.
1353
1354 // Expected registers by Builtins::JSEntryTrampoline
1355 // x0: code entry.
1356 // x1: function.
1357 // x2: receiver.
1358 // x3: argc.
1359 // x4: argv.
1360 ExternalReference entry(type() == StackFrame::ENTRY_CONSTRUCT
1361 ? Builtins::kJSConstructEntryTrampoline
1362 : Builtins::kJSEntryTrampoline,
1363 isolate());
1364 __ Mov(x10, entry);
1365
1366 // Call the JSEntryTrampoline.
1367 __ Ldr(x11, MemOperand(x10)); // Dereference the address.
1368 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag);
1369 __ Blr(x12);
1370
1371 // Unlink this frame from the handler chain.
1372 __ PopTryHandler();
1373
1374
1375 __ Bind(&exit);
1376 // x0 holds the result.
1377 // The stack pointer points to the top of the entry frame pushed on entry from
1378 // C++ (at the beginning of this stub):
1379 // jssp[0] : JS entry frame marker.
1380 // jssp[1] : C entry FP.
1381 // jssp[2] : stack frame marker.
1382 // jssp[3] : stack frmae marker.
1383 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1384
1385 // Check if the current stack frame is marked as the outermost JS frame.
1386 Label non_outermost_js_2;
1387 __ Pop(x10);
1388 __ Cmp(x10, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1389 __ B(ne, &non_outermost_js_2);
1390 __ Mov(x11, ExternalReference(js_entry_sp));
1391 __ Str(xzr, MemOperand(x11));
1392 __ Bind(&non_outermost_js_2);
1393
1394 // Restore the top frame descriptors from the stack.
1395 __ Pop(x10);
1396 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1397 __ Str(x10, MemOperand(x11));
1398
1399 // Reset the stack to the callee saved registers.
1400 __ Drop(-EntryFrameConstants::kCallerFPOffset, kByteSizeInBytes);
1401 // Restore the callee-saved registers and return.
1402 DCHECK(jssp.Is(__ StackPointer()));
1403 __ Mov(csp, jssp);
1404 __ SetStackPointer(csp);
1405 __ PopCalleeSavedRegisters();
1406 // After this point, we must not modify jssp because it is a callee-saved
1407 // register which we have just restored.
1408 __ Ret();
1409}
1410
1411
1412void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1413 Label miss;
1414 Register receiver = LoadDescriptor::ReceiverRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001415 // Ensure that the vector and slot registers won't be clobbered before
1416 // calling the miss handler.
1417 DCHECK(!FLAG_vector_ics ||
1418 !AreAliased(x10, x11, VectorLoadICDescriptor::VectorRegister(),
1419 VectorLoadICDescriptor::SlotRegister()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001420
1421 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, x10,
1422 x11, &miss);
1423
1424 __ Bind(&miss);
1425 PropertyAccessCompiler::TailCallBuiltin(
1426 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1427}
1428
1429
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001430void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1431 // Return address is in lr.
1432 Label miss;
1433
1434 Register receiver = LoadDescriptor::ReceiverRegister();
1435 Register index = LoadDescriptor::NameRegister();
1436 Register result = x0;
1437 Register scratch = x10;
1438 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1439 DCHECK(!FLAG_vector_ics ||
1440 (!scratch.is(VectorLoadICDescriptor::VectorRegister()) &&
1441 result.is(VectorLoadICDescriptor::SlotRegister())));
1442
1443 // StringCharAtGenerator doesn't use the result register until it's passed
1444 // the different miss possibilities. If it did, we would have a conflict
1445 // when FLAG_vector_ics is true.
1446 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1447 &miss, // When not a string.
1448 &miss, // When not a number.
1449 &miss, // When index out of range.
1450 STRING_INDEX_IS_ARRAY_INDEX,
1451 RECEIVER_IS_STRING);
1452 char_at_generator.GenerateFast(masm);
1453 __ Ret();
1454
1455 StubRuntimeCallHelper call_helper;
1456 char_at_generator.GenerateSlow(masm, call_helper);
1457
1458 __ Bind(&miss);
1459 PropertyAccessCompiler::TailCallBuiltin(
1460 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1461}
1462
1463
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001464void InstanceofStub::Generate(MacroAssembler* masm) {
1465 // Stack on entry:
1466 // jssp[0]: function.
1467 // jssp[8]: object.
1468 //
1469 // Returns result in x0. Zero indicates instanceof, smi 1 indicates not
1470 // instanceof.
1471
1472 Register result = x0;
1473 Register function = right();
1474 Register object = left();
1475 Register scratch1 = x6;
1476 Register scratch2 = x7;
1477 Register res_true = x8;
1478 Register res_false = x9;
1479 // Only used if there was an inline map check site. (See
1480 // LCodeGen::DoInstanceOfKnownGlobal().)
1481 Register map_check_site = x4;
1482 // Delta for the instructions generated between the inline map check and the
1483 // instruction setting the result.
1484 const int32_t kDeltaToLoadBoolResult = 4 * kInstructionSize;
1485
1486 Label not_js_object, slow;
1487
1488 if (!HasArgsInRegisters()) {
1489 __ Pop(function, object);
1490 }
1491
1492 if (ReturnTrueFalseObject()) {
1493 __ LoadTrueFalseRoots(res_true, res_false);
1494 } else {
1495 // This is counter-intuitive, but correct.
1496 __ Mov(res_true, Smi::FromInt(0));
1497 __ Mov(res_false, Smi::FromInt(1));
1498 }
1499
1500 // Check that the left hand side is a JS object and load its map as a side
1501 // effect.
1502 Register map = x12;
1503 __ JumpIfSmi(object, &not_js_object);
1504 __ IsObjectJSObjectType(object, map, scratch2, &not_js_object);
1505
1506 // If there is a call site cache, don't look in the global cache, but do the
1507 // real lookup and update the call site cache.
1508 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
1509 Label miss;
1510 __ JumpIfNotRoot(function, Heap::kInstanceofCacheFunctionRootIndex, &miss);
1511 __ JumpIfNotRoot(map, Heap::kInstanceofCacheMapRootIndex, &miss);
1512 __ LoadRoot(result, Heap::kInstanceofCacheAnswerRootIndex);
1513 __ Ret();
1514 __ Bind(&miss);
1515 }
1516
1517 // Get the prototype of the function.
1518 Register prototype = x13;
1519 __ TryGetFunctionPrototype(function, prototype, scratch2, &slow,
1520 MacroAssembler::kMissOnBoundFunction);
1521
1522 // Check that the function prototype is a JS object.
1523 __ JumpIfSmi(prototype, &slow);
1524 __ IsObjectJSObjectType(prototype, scratch1, scratch2, &slow);
1525
1526 // Update the global instanceof or call site inlined cache with the current
1527 // map and function. The cached answer will be set when it is known below.
1528 if (HasCallSiteInlineCheck()) {
1529 // Patch the (relocated) inlined map check.
1530 __ GetRelocatedValueLocation(map_check_site, scratch1);
1531 // We have a cell, so need another level of dereferencing.
1532 __ Ldr(scratch1, MemOperand(scratch1));
1533 __ Str(map, FieldMemOperand(scratch1, Cell::kValueOffset));
1534 } else {
1535 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1536 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1537 }
1538
1539 Label return_true, return_result;
1540 Register smi_value = scratch1;
1541 {
1542 // Loop through the prototype chain looking for the function prototype.
1543 Register chain_map = x1;
1544 Register chain_prototype = x14;
1545 Register null_value = x15;
1546 Label loop;
1547 __ Ldr(chain_prototype, FieldMemOperand(map, Map::kPrototypeOffset));
1548 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
1549 // Speculatively set a result.
1550 __ Mov(result, res_false);
1551 if (!HasCallSiteInlineCheck() && ReturnTrueFalseObject()) {
1552 // Value to store in the cache cannot be an object.
1553 __ Mov(smi_value, Smi::FromInt(1));
1554 }
1555
1556 __ Bind(&loop);
1557
1558 // If the chain prototype is the object prototype, return true.
1559 __ Cmp(chain_prototype, prototype);
1560 __ B(eq, &return_true);
1561
1562 // If the chain prototype is null, we've reached the end of the chain, so
1563 // return false.
1564 __ Cmp(chain_prototype, null_value);
1565 __ B(eq, &return_result);
1566
1567 // Otherwise, load the next prototype in the chain, and loop.
1568 __ Ldr(chain_map, FieldMemOperand(chain_prototype, HeapObject::kMapOffset));
1569 __ Ldr(chain_prototype, FieldMemOperand(chain_map, Map::kPrototypeOffset));
1570 __ B(&loop);
1571 }
1572
1573 // Return sequence when no arguments are on the stack.
1574 // We cannot fall through to here.
1575 __ Bind(&return_true);
1576 __ Mov(result, res_true);
1577 if (!HasCallSiteInlineCheck() && ReturnTrueFalseObject()) {
1578 // Value to store in the cache cannot be an object.
1579 __ Mov(smi_value, Smi::FromInt(0));
1580 }
1581 __ Bind(&return_result);
1582 if (HasCallSiteInlineCheck()) {
1583 DCHECK(ReturnTrueFalseObject());
1584 __ Add(map_check_site, map_check_site, kDeltaToLoadBoolResult);
1585 __ GetRelocatedValueLocation(map_check_site, scratch2);
1586 __ Str(result, MemOperand(scratch2));
1587 } else {
1588 Register cached_value = ReturnTrueFalseObject() ? smi_value : result;
1589 __ StoreRoot(cached_value, Heap::kInstanceofCacheAnswerRootIndex);
1590 }
1591 __ Ret();
1592
1593 Label object_not_null, object_not_null_or_smi;
1594
1595 __ Bind(&not_js_object);
1596 Register object_type = x14;
1597 // x0 result result return register (uninit)
1598 // x10 function pointer to function
1599 // x11 object pointer to object
1600 // x14 object_type type of object (uninit)
1601
1602 // Before null, smi and string checks, check that the rhs is a function.
1603 // For a non-function rhs, an exception must be thrown.
1604 __ JumpIfSmi(function, &slow);
1605 __ JumpIfNotObjectType(
1606 function, scratch1, object_type, JS_FUNCTION_TYPE, &slow);
1607
1608 __ Mov(result, res_false);
1609
1610 // Null is not instance of anything.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001611 __ Cmp(object, Operand(isolate()->factory()->null_value()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001612 __ B(ne, &object_not_null);
1613 __ Ret();
1614
1615 __ Bind(&object_not_null);
1616 // Smi values are not instances of anything.
1617 __ JumpIfNotSmi(object, &object_not_null_or_smi);
1618 __ Ret();
1619
1620 __ Bind(&object_not_null_or_smi);
1621 // String values are not instances of anything.
1622 __ IsObjectJSStringType(object, scratch2, &slow);
1623 __ Ret();
1624
1625 // Slow-case. Tail call builtin.
1626 __ Bind(&slow);
1627 {
1628 FrameScope scope(masm, StackFrame::INTERNAL);
1629 // Arguments have either been passed into registers or have been previously
1630 // popped. We need to push them before calling builtin.
1631 __ Push(object, function);
1632 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1633 }
1634 if (ReturnTrueFalseObject()) {
1635 // Reload true/false because they were clobbered in the builtin call.
1636 __ LoadTrueFalseRoots(res_true, res_false);
1637 __ Cmp(result, 0);
1638 __ Csel(result, res_true, res_false, eq);
1639 }
1640 __ Ret();
1641}
1642
1643
1644void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1645 Register arg_count = ArgumentsAccessReadDescriptor::parameter_count();
1646 Register key = ArgumentsAccessReadDescriptor::index();
1647 DCHECK(arg_count.is(x0));
1648 DCHECK(key.is(x1));
1649
1650 // The displacement is the offset of the last parameter (if any) relative
1651 // to the frame pointer.
1652 static const int kDisplacement =
1653 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1654
1655 // Check that the key is a smi.
1656 Label slow;
1657 __ JumpIfNotSmi(key, &slow);
1658
1659 // Check if the calling frame is an arguments adaptor frame.
1660 Register local_fp = x11;
1661 Register caller_fp = x11;
1662 Register caller_ctx = x12;
1663 Label skip_adaptor;
1664 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1665 __ Ldr(caller_ctx, MemOperand(caller_fp,
1666 StandardFrameConstants::kContextOffset));
1667 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1668 __ Csel(local_fp, fp, caller_fp, ne);
1669 __ B(ne, &skip_adaptor);
1670
1671 // Load the actual arguments limit found in the arguments adaptor frame.
1672 __ Ldr(arg_count, MemOperand(caller_fp,
1673 ArgumentsAdaptorFrameConstants::kLengthOffset));
1674 __ Bind(&skip_adaptor);
1675
1676 // Check index against formal parameters count limit. Use unsigned comparison
1677 // to get negative check for free: branch if key < 0 or key >= arg_count.
1678 __ Cmp(key, arg_count);
1679 __ B(hs, &slow);
1680
1681 // Read the argument from the stack and return it.
1682 __ Sub(x10, arg_count, key);
1683 __ Add(x10, local_fp, Operand::UntagSmiAndScale(x10, kPointerSizeLog2));
1684 __ Ldr(x0, MemOperand(x10, kDisplacement));
1685 __ Ret();
1686
1687 // Slow case: handle non-smi or out-of-bounds access to arguments by calling
1688 // the runtime system.
1689 __ Bind(&slow);
1690 __ Push(key);
1691 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1692}
1693
1694
1695void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1696 // Stack layout on entry.
1697 // jssp[0]: number of parameters (tagged)
1698 // jssp[8]: address of receiver argument
1699 // jssp[16]: function
1700
1701 // Check if the calling frame is an arguments adaptor frame.
1702 Label runtime;
1703 Register caller_fp = x10;
1704 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1705 // Load and untag the context.
1706 __ Ldr(w11, UntagSmiMemOperand(caller_fp,
1707 StandardFrameConstants::kContextOffset));
1708 __ Cmp(w11, StackFrame::ARGUMENTS_ADAPTOR);
1709 __ B(ne, &runtime);
1710
1711 // Patch the arguments.length and parameters pointer in the current frame.
1712 __ Ldr(x11, MemOperand(caller_fp,
1713 ArgumentsAdaptorFrameConstants::kLengthOffset));
1714 __ Poke(x11, 0 * kXRegSize);
1715 __ Add(x10, caller_fp, Operand::UntagSmiAndScale(x11, kPointerSizeLog2));
1716 __ Add(x10, x10, StandardFrameConstants::kCallerSPOffset);
1717 __ Poke(x10, 1 * kXRegSize);
1718
1719 __ Bind(&runtime);
1720 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1721}
1722
1723
1724void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1725 // Stack layout on entry.
1726 // jssp[0]: number of parameters (tagged)
1727 // jssp[8]: address of receiver argument
1728 // jssp[16]: function
1729 //
1730 // Returns pointer to result object in x0.
1731
1732 // Note: arg_count_smi is an alias of param_count_smi.
1733 Register arg_count_smi = x3;
1734 Register param_count_smi = x3;
1735 Register param_count = x7;
1736 Register recv_arg = x14;
1737 Register function = x4;
1738 __ Pop(param_count_smi, recv_arg, function);
1739 __ SmiUntag(param_count, param_count_smi);
1740
1741 // Check if the calling frame is an arguments adaptor frame.
1742 Register caller_fp = x11;
1743 Register caller_ctx = x12;
1744 Label runtime;
1745 Label adaptor_frame, try_allocate;
1746 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1747 __ Ldr(caller_ctx, MemOperand(caller_fp,
1748 StandardFrameConstants::kContextOffset));
1749 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1750 __ B(eq, &adaptor_frame);
1751
1752 // No adaptor, parameter count = argument count.
1753
1754 // x1 mapped_params number of mapped params, min(params, args) (uninit)
1755 // x2 arg_count number of function arguments (uninit)
1756 // x3 arg_count_smi number of function arguments (smi)
1757 // x4 function function pointer
1758 // x7 param_count number of function parameters
1759 // x11 caller_fp caller's frame pointer
1760 // x14 recv_arg pointer to receiver arguments
1761
1762 Register arg_count = x2;
1763 __ Mov(arg_count, param_count);
1764 __ B(&try_allocate);
1765
1766 // We have an adaptor frame. Patch the parameters pointer.
1767 __ Bind(&adaptor_frame);
1768 __ Ldr(arg_count_smi,
1769 MemOperand(caller_fp,
1770 ArgumentsAdaptorFrameConstants::kLengthOffset));
1771 __ SmiUntag(arg_count, arg_count_smi);
1772 __ Add(x10, caller_fp, Operand(arg_count, LSL, kPointerSizeLog2));
1773 __ Add(recv_arg, x10, StandardFrameConstants::kCallerSPOffset);
1774
1775 // Compute the mapped parameter count = min(param_count, arg_count)
1776 Register mapped_params = x1;
1777 __ Cmp(param_count, arg_count);
1778 __ Csel(mapped_params, param_count, arg_count, lt);
1779
1780 __ Bind(&try_allocate);
1781
1782 // x0 alloc_obj pointer to allocated objects: param map, backing
1783 // store, arguments (uninit)
1784 // x1 mapped_params number of mapped parameters, min(params, args)
1785 // x2 arg_count number of function arguments
1786 // x3 arg_count_smi number of function arguments (smi)
1787 // x4 function function pointer
1788 // x7 param_count number of function parameters
1789 // x10 size size of objects to allocate (uninit)
1790 // x14 recv_arg pointer to receiver arguments
1791
1792 // Compute the size of backing store, parameter map, and arguments object.
1793 // 1. Parameter map, has two extra words containing context and backing
1794 // store.
1795 const int kParameterMapHeaderSize =
1796 FixedArray::kHeaderSize + 2 * kPointerSize;
1797
1798 // Calculate the parameter map size, assuming it exists.
1799 Register size = x10;
1800 __ Mov(size, Operand(mapped_params, LSL, kPointerSizeLog2));
1801 __ Add(size, size, kParameterMapHeaderSize);
1802
1803 // If there are no mapped parameters, set the running size total to zero.
1804 // Otherwise, use the parameter map size calculated earlier.
1805 __ Cmp(mapped_params, 0);
1806 __ CzeroX(size, eq);
1807
1808 // 2. Add the size of the backing store and arguments object.
1809 __ Add(size, size, Operand(arg_count, LSL, kPointerSizeLog2));
1810 __ Add(size, size,
1811 FixedArray::kHeaderSize + Heap::kSloppyArgumentsObjectSize);
1812
1813 // Do the allocation of all three objects in one go. Assign this to x0, as it
1814 // will be returned to the caller.
1815 Register alloc_obj = x0;
1816 __ Allocate(size, alloc_obj, x11, x12, &runtime, TAG_OBJECT);
1817
1818 // Get the arguments boilerplate from the current (global) context.
1819
1820 // x0 alloc_obj pointer to allocated objects (param map, backing
1821 // store, arguments)
1822 // x1 mapped_params number of mapped parameters, min(params, args)
1823 // x2 arg_count number of function arguments
1824 // x3 arg_count_smi number of function arguments (smi)
1825 // x4 function function pointer
1826 // x7 param_count number of function parameters
1827 // x11 sloppy_args_map offset to args (or aliased args) map (uninit)
1828 // x14 recv_arg pointer to receiver arguments
1829
1830 Register global_object = x10;
1831 Register global_ctx = x10;
1832 Register sloppy_args_map = x11;
1833 Register aliased_args_map = x10;
1834 __ Ldr(global_object, GlobalObjectMemOperand());
1835 __ Ldr(global_ctx, FieldMemOperand(global_object,
1836 GlobalObject::kNativeContextOffset));
1837
1838 __ Ldr(sloppy_args_map,
1839 ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1840 __ Ldr(aliased_args_map,
1841 ContextMemOperand(global_ctx, Context::ALIASED_ARGUMENTS_MAP_INDEX));
1842 __ Cmp(mapped_params, 0);
1843 __ CmovX(sloppy_args_map, aliased_args_map, ne);
1844
1845 // Copy the JS object part.
1846 __ Str(sloppy_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
1847 __ LoadRoot(x10, Heap::kEmptyFixedArrayRootIndex);
1848 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
1849 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1850
1851 // Set up the callee in-object property.
1852 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1853 const int kCalleeOffset = JSObject::kHeaderSize +
1854 Heap::kArgumentsCalleeIndex * kPointerSize;
1855 __ AssertNotSmi(function);
1856 __ Str(function, FieldMemOperand(alloc_obj, kCalleeOffset));
1857
1858 // Use the length and set that as an in-object property.
1859 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1860 const int kLengthOffset = JSObject::kHeaderSize +
1861 Heap::kArgumentsLengthIndex * kPointerSize;
1862 __ Str(arg_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
1863
1864 // Set up the elements pointer in the allocated arguments object.
1865 // If we allocated a parameter map, "elements" will point there, otherwise
1866 // it will point to the backing store.
1867
1868 // x0 alloc_obj pointer to allocated objects (param map, backing
1869 // store, arguments)
1870 // x1 mapped_params number of mapped parameters, min(params, args)
1871 // x2 arg_count number of function arguments
1872 // x3 arg_count_smi number of function arguments (smi)
1873 // x4 function function pointer
1874 // x5 elements pointer to parameter map or backing store (uninit)
1875 // x6 backing_store pointer to backing store (uninit)
1876 // x7 param_count number of function parameters
1877 // x14 recv_arg pointer to receiver arguments
1878
1879 Register elements = x5;
1880 __ Add(elements, alloc_obj, Heap::kSloppyArgumentsObjectSize);
1881 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1882
1883 // Initialize parameter map. If there are no mapped arguments, we're done.
1884 Label skip_parameter_map;
1885 __ Cmp(mapped_params, 0);
1886 // Set up backing store address, because it is needed later for filling in
1887 // the unmapped arguments.
1888 Register backing_store = x6;
1889 __ CmovX(backing_store, elements, eq);
1890 __ B(eq, &skip_parameter_map);
1891
1892 __ LoadRoot(x10, Heap::kSloppyArgumentsElementsMapRootIndex);
1893 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
1894 __ Add(x10, mapped_params, 2);
1895 __ SmiTag(x10);
1896 __ Str(x10, FieldMemOperand(elements, FixedArray::kLengthOffset));
1897 __ Str(cp, FieldMemOperand(elements,
1898 FixedArray::kHeaderSize + 0 * kPointerSize));
1899 __ Add(x10, elements, Operand(mapped_params, LSL, kPointerSizeLog2));
1900 __ Add(x10, x10, kParameterMapHeaderSize);
1901 __ Str(x10, FieldMemOperand(elements,
1902 FixedArray::kHeaderSize + 1 * kPointerSize));
1903
1904 // Copy the parameter slots and the holes in the arguments.
1905 // We need to fill in mapped_parameter_count slots. Then index the context,
1906 // where parameters are stored in reverse order, at:
1907 //
1908 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS + parameter_count - 1
1909 //
1910 // The mapped parameter thus needs to get indices:
1911 //
1912 // MIN_CONTEXT_SLOTS + parameter_count - 1 ..
1913 // MIN_CONTEXT_SLOTS + parameter_count - mapped_parameter_count
1914 //
1915 // We loop from right to left.
1916
1917 // x0 alloc_obj pointer to allocated objects (param map, backing
1918 // store, arguments)
1919 // x1 mapped_params number of mapped parameters, min(params, args)
1920 // x2 arg_count number of function arguments
1921 // x3 arg_count_smi number of function arguments (smi)
1922 // x4 function function pointer
1923 // x5 elements pointer to parameter map or backing store (uninit)
1924 // x6 backing_store pointer to backing store (uninit)
1925 // x7 param_count number of function parameters
1926 // x11 loop_count parameter loop counter (uninit)
1927 // x12 index parameter index (smi, uninit)
1928 // x13 the_hole hole value (uninit)
1929 // x14 recv_arg pointer to receiver arguments
1930
1931 Register loop_count = x11;
1932 Register index = x12;
1933 Register the_hole = x13;
1934 Label parameters_loop, parameters_test;
1935 __ Mov(loop_count, mapped_params);
1936 __ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS));
1937 __ Sub(index, index, mapped_params);
1938 __ SmiTag(index);
1939 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
1940 __ Add(backing_store, elements, Operand(loop_count, LSL, kPointerSizeLog2));
1941 __ Add(backing_store, backing_store, kParameterMapHeaderSize);
1942
1943 __ B(&parameters_test);
1944
1945 __ Bind(&parameters_loop);
1946 __ Sub(loop_count, loop_count, 1);
1947 __ Mov(x10, Operand(loop_count, LSL, kPointerSizeLog2));
1948 __ Add(x10, x10, kParameterMapHeaderSize - kHeapObjectTag);
1949 __ Str(index, MemOperand(elements, x10));
1950 __ Sub(x10, x10, kParameterMapHeaderSize - FixedArray::kHeaderSize);
1951 __ Str(the_hole, MemOperand(backing_store, x10));
1952 __ Add(index, index, Smi::FromInt(1));
1953 __ Bind(&parameters_test);
1954 __ Cbnz(loop_count, &parameters_loop);
1955
1956 __ Bind(&skip_parameter_map);
1957 // Copy arguments header and remaining slots (if there are any.)
1958 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
1959 __ Str(x10, FieldMemOperand(backing_store, FixedArray::kMapOffset));
1960 __ Str(arg_count_smi, FieldMemOperand(backing_store,
1961 FixedArray::kLengthOffset));
1962
1963 // x0 alloc_obj pointer to allocated objects (param map, backing
1964 // store, arguments)
1965 // x1 mapped_params number of mapped parameters, min(params, args)
1966 // x2 arg_count number of function arguments
1967 // x4 function function pointer
1968 // x3 arg_count_smi number of function arguments (smi)
1969 // x6 backing_store pointer to backing store (uninit)
1970 // x14 recv_arg pointer to receiver arguments
1971
1972 Label arguments_loop, arguments_test;
1973 __ Mov(x10, mapped_params);
1974 __ Sub(recv_arg, recv_arg, Operand(x10, LSL, kPointerSizeLog2));
1975 __ B(&arguments_test);
1976
1977 __ Bind(&arguments_loop);
1978 __ Sub(recv_arg, recv_arg, kPointerSize);
1979 __ Ldr(x11, MemOperand(recv_arg));
1980 __ Add(x12, backing_store, Operand(x10, LSL, kPointerSizeLog2));
1981 __ Str(x11, FieldMemOperand(x12, FixedArray::kHeaderSize));
1982 __ Add(x10, x10, 1);
1983
1984 __ Bind(&arguments_test);
1985 __ Cmp(x10, arg_count);
1986 __ B(lt, &arguments_loop);
1987
1988 __ Ret();
1989
1990 // Do the runtime call to allocate the arguments object.
1991 __ Bind(&runtime);
1992 __ Push(function, recv_arg, arg_count_smi);
1993 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1994}
1995
1996
1997void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1998 // Return address is in lr.
1999 Label slow;
2000
2001 Register receiver = LoadDescriptor::ReceiverRegister();
2002 Register key = LoadDescriptor::NameRegister();
2003
2004 // Check that the key is an array index, that is Uint32.
2005 __ TestAndBranchIfAnySet(key, kSmiTagMask | kSmiSignMask, &slow);
2006
2007 // Everything is fine, call runtime.
2008 __ Push(receiver, key);
2009 __ TailCallExternalReference(
2010 ExternalReference(IC_Utility(IC::kLoadElementWithInterceptor),
2011 masm->isolate()),
2012 2, 1);
2013
2014 __ Bind(&slow);
2015 PropertyAccessCompiler::TailCallBuiltin(
2016 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
2017}
2018
2019
2020void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
2021 // Stack layout on entry.
2022 // jssp[0]: number of parameters (tagged)
2023 // jssp[8]: address of receiver argument
2024 // jssp[16]: function
2025 //
2026 // Returns pointer to result object in x0.
2027
2028 // Get the stub arguments from the frame, and make an untagged copy of the
2029 // parameter count.
2030 Register param_count_smi = x1;
2031 Register params = x2;
2032 Register function = x3;
2033 Register param_count = x13;
2034 __ Pop(param_count_smi, params, function);
2035 __ SmiUntag(param_count, param_count_smi);
2036
2037 // Test if arguments adaptor needed.
2038 Register caller_fp = x11;
2039 Register caller_ctx = x12;
2040 Label try_allocate, runtime;
2041 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2042 __ Ldr(caller_ctx, MemOperand(caller_fp,
2043 StandardFrameConstants::kContextOffset));
2044 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2045 __ B(ne, &try_allocate);
2046
2047 // x1 param_count_smi number of parameters passed to function (smi)
2048 // x2 params pointer to parameters
2049 // x3 function function pointer
2050 // x11 caller_fp caller's frame pointer
2051 // x13 param_count number of parameters passed to function
2052
2053 // Patch the argument length and parameters pointer.
2054 __ Ldr(param_count_smi,
2055 MemOperand(caller_fp,
2056 ArgumentsAdaptorFrameConstants::kLengthOffset));
2057 __ SmiUntag(param_count, param_count_smi);
2058 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2059 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2060
2061 // Try the new space allocation. Start out with computing the size of the
2062 // arguments object and the elements array in words.
2063 Register size = x10;
2064 __ Bind(&try_allocate);
2065 __ Add(size, param_count, FixedArray::kHeaderSize / kPointerSize);
2066 __ Cmp(param_count, 0);
2067 __ CzeroX(size, eq);
2068 __ Add(size, size, Heap::kStrictArgumentsObjectSize / kPointerSize);
2069
2070 // Do the allocation of both objects in one go. Assign this to x0, as it will
2071 // be returned to the caller.
2072 Register alloc_obj = x0;
2073 __ Allocate(size, alloc_obj, x11, x12, &runtime,
2074 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
2075
2076 // Get the arguments boilerplate from the current (native) context.
2077 Register global_object = x10;
2078 Register global_ctx = x10;
2079 Register strict_args_map = x4;
2080 __ Ldr(global_object, GlobalObjectMemOperand());
2081 __ Ldr(global_ctx, FieldMemOperand(global_object,
2082 GlobalObject::kNativeContextOffset));
2083 __ Ldr(strict_args_map,
2084 ContextMemOperand(global_ctx, Context::STRICT_ARGUMENTS_MAP_INDEX));
2085
2086 // x0 alloc_obj pointer to allocated objects: parameter array and
2087 // arguments object
2088 // x1 param_count_smi number of parameters passed to function (smi)
2089 // x2 params pointer to parameters
2090 // x3 function function pointer
2091 // x4 strict_args_map offset to arguments map
2092 // x13 param_count number of parameters passed to function
2093 __ Str(strict_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
2094 __ LoadRoot(x5, Heap::kEmptyFixedArrayRootIndex);
2095 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
2096 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2097
2098 // Set the smi-tagged length as an in-object property.
2099 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2100 const int kLengthOffset = JSObject::kHeaderSize +
2101 Heap::kArgumentsLengthIndex * kPointerSize;
2102 __ Str(param_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
2103
2104 // If there are no actual arguments, we're done.
2105 Label done;
2106 __ Cbz(param_count, &done);
2107
2108 // Set up the elements pointer in the allocated arguments object and
2109 // initialize the header in the elements fixed array.
2110 Register elements = x5;
2111 __ Add(elements, alloc_obj, Heap::kStrictArgumentsObjectSize);
2112 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2113 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
2114 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
2115 __ Str(param_count_smi, FieldMemOperand(elements, FixedArray::kLengthOffset));
2116
2117 // x0 alloc_obj pointer to allocated objects: parameter array and
2118 // arguments object
2119 // x1 param_count_smi number of parameters passed to function (smi)
2120 // x2 params pointer to parameters
2121 // x3 function function pointer
2122 // x4 array pointer to array slot (uninit)
2123 // x5 elements pointer to elements array of alloc_obj
2124 // x13 param_count number of parameters passed to function
2125
2126 // Copy the fixed array slots.
2127 Label loop;
2128 Register array = x4;
2129 // Set up pointer to first array slot.
2130 __ Add(array, elements, FixedArray::kHeaderSize - kHeapObjectTag);
2131
2132 __ Bind(&loop);
2133 // Pre-decrement the parameters pointer by kPointerSize on each iteration.
2134 // Pre-decrement in order to skip receiver.
2135 __ Ldr(x10, MemOperand(params, -kPointerSize, PreIndex));
2136 // Post-increment elements by kPointerSize on each iteration.
2137 __ Str(x10, MemOperand(array, kPointerSize, PostIndex));
2138 __ Sub(param_count, param_count, 1);
2139 __ Cbnz(param_count, &loop);
2140
2141 // Return from stub.
2142 __ Bind(&done);
2143 __ Ret();
2144
2145 // Do the runtime call to allocate the arguments object.
2146 __ Bind(&runtime);
2147 __ Push(function, params, param_count_smi);
2148 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2149}
2150
2151
2152void RegExpExecStub::Generate(MacroAssembler* masm) {
2153#ifdef V8_INTERPRETED_REGEXP
2154 __ TailCallRuntime(Runtime::kRegExpExecRT, 4, 1);
2155#else // V8_INTERPRETED_REGEXP
2156
2157 // Stack frame on entry.
2158 // jssp[0]: last_match_info (expected JSArray)
2159 // jssp[8]: previous index
2160 // jssp[16]: subject string
2161 // jssp[24]: JSRegExp object
2162 Label runtime;
2163
2164 // Use of registers for this function.
2165
2166 // Variable registers:
2167 // x10-x13 used as scratch registers
2168 // w0 string_type type of subject string
2169 // x2 jsstring_length subject string length
2170 // x3 jsregexp_object JSRegExp object
2171 // w4 string_encoding Latin1 or UC16
2172 // w5 sliced_string_offset if the string is a SlicedString
2173 // offset to the underlying string
2174 // w6 string_representation groups attributes of the string:
2175 // - is a string
2176 // - type of the string
2177 // - is a short external string
2178 Register string_type = w0;
2179 Register jsstring_length = x2;
2180 Register jsregexp_object = x3;
2181 Register string_encoding = w4;
2182 Register sliced_string_offset = w5;
2183 Register string_representation = w6;
2184
2185 // These are in callee save registers and will be preserved by the call
2186 // to the native RegExp code, as this code is called using the normal
2187 // C calling convention. When calling directly from generated code the
2188 // native RegExp code will not do a GC and therefore the content of
2189 // these registers are safe to use after the call.
2190
2191 // x19 subject subject string
2192 // x20 regexp_data RegExp data (FixedArray)
2193 // x21 last_match_info_elements info relative to the last match
2194 // (FixedArray)
2195 // x22 code_object generated regexp code
2196 Register subject = x19;
2197 Register regexp_data = x20;
2198 Register last_match_info_elements = x21;
2199 Register code_object = x22;
2200
2201 // TODO(jbramley): Is it necessary to preserve these? I don't think ARM does.
2202 CPURegList used_callee_saved_registers(subject,
2203 regexp_data,
2204 last_match_info_elements,
2205 code_object);
2206 __ PushCPURegList(used_callee_saved_registers);
2207
2208 // Stack frame.
2209 // jssp[0] : x19
2210 // jssp[8] : x20
2211 // jssp[16]: x21
2212 // jssp[24]: x22
2213 // jssp[32]: last_match_info (JSArray)
2214 // jssp[40]: previous index
2215 // jssp[48]: subject string
2216 // jssp[56]: JSRegExp object
2217
2218 const int kLastMatchInfoOffset = 4 * kPointerSize;
2219 const int kPreviousIndexOffset = 5 * kPointerSize;
2220 const int kSubjectOffset = 6 * kPointerSize;
2221 const int kJSRegExpOffset = 7 * kPointerSize;
2222
2223 // Ensure that a RegExp stack is allocated.
2224 ExternalReference address_of_regexp_stack_memory_address =
2225 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2226 ExternalReference address_of_regexp_stack_memory_size =
2227 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2228 __ Mov(x10, address_of_regexp_stack_memory_size);
2229 __ Ldr(x10, MemOperand(x10));
2230 __ Cbz(x10, &runtime);
2231
2232 // Check that the first argument is a JSRegExp object.
2233 DCHECK(jssp.Is(__ StackPointer()));
2234 __ Peek(jsregexp_object, kJSRegExpOffset);
2235 __ JumpIfSmi(jsregexp_object, &runtime);
2236 __ JumpIfNotObjectType(jsregexp_object, x10, x10, JS_REGEXP_TYPE, &runtime);
2237
2238 // Check that the RegExp has been compiled (data contains a fixed array).
2239 __ Ldr(regexp_data, FieldMemOperand(jsregexp_object, JSRegExp::kDataOffset));
2240 if (FLAG_debug_code) {
2241 STATIC_ASSERT(kSmiTag == 0);
2242 __ Tst(regexp_data, kSmiTagMask);
2243 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2244 __ CompareObjectType(regexp_data, x10, x10, FIXED_ARRAY_TYPE);
2245 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2246 }
2247
2248 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2249 __ Ldr(x10, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2250 __ Cmp(x10, Smi::FromInt(JSRegExp::IRREGEXP));
2251 __ B(ne, &runtime);
2252
2253 // Check that the number of captures fit in the static offsets vector buffer.
2254 // We have always at least one capture for the whole match, plus additional
2255 // ones due to capturing parentheses. A capture takes 2 registers.
2256 // The number of capture registers then is (number_of_captures + 1) * 2.
2257 __ Ldrsw(x10,
2258 UntagSmiFieldMemOperand(regexp_data,
2259 JSRegExp::kIrregexpCaptureCountOffset));
2260 // Check (number_of_captures + 1) * 2 <= offsets vector size
2261 // number_of_captures * 2 <= offsets vector size - 2
2262 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2263 __ Add(x10, x10, x10);
2264 __ Cmp(x10, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
2265 __ B(hi, &runtime);
2266
2267 // Initialize offset for possibly sliced string.
2268 __ Mov(sliced_string_offset, 0);
2269
2270 DCHECK(jssp.Is(__ StackPointer()));
2271 __ Peek(subject, kSubjectOffset);
2272 __ JumpIfSmi(subject, &runtime);
2273
2274 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2275 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2276
2277 __ Ldr(jsstring_length, FieldMemOperand(subject, String::kLengthOffset));
2278
2279 // Handle subject string according to its encoding and representation:
2280 // (1) Sequential string? If yes, go to (5).
2281 // (2) Anything but sequential or cons? If yes, go to (6).
2282 // (3) Cons string. If the string is flat, replace subject with first string.
2283 // Otherwise bailout.
2284 // (4) Is subject external? If yes, go to (7).
2285 // (5) Sequential string. Load regexp code according to encoding.
2286 // (E) Carry on.
2287 /// [...]
2288
2289 // Deferred code at the end of the stub:
2290 // (6) Not a long external string? If yes, go to (8).
2291 // (7) External string. Make it, offset-wise, look like a sequential string.
2292 // Go to (5).
2293 // (8) Short external string or not a string? If yes, bail out to runtime.
2294 // (9) Sliced string. Replace subject with parent. Go to (4).
2295
2296 Label check_underlying; // (4)
2297 Label seq_string; // (5)
2298 Label not_seq_nor_cons; // (6)
2299 Label external_string; // (7)
2300 Label not_long_external; // (8)
2301
2302 // (1) Sequential string? If yes, go to (5).
2303 __ And(string_representation,
2304 string_type,
2305 kIsNotStringMask |
2306 kStringRepresentationMask |
2307 kShortExternalStringMask);
2308 // We depend on the fact that Strings of type
2309 // SeqString and not ShortExternalString are defined
2310 // by the following pattern:
2311 // string_type: 0XX0 XX00
2312 // ^ ^ ^^
2313 // | | ||
2314 // | | is a SeqString
2315 // | is not a short external String
2316 // is a String
2317 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2318 STATIC_ASSERT(kShortExternalStringTag != 0);
2319 __ Cbz(string_representation, &seq_string); // Go to (5).
2320
2321 // (2) Anything but sequential or cons? If yes, go to (6).
2322 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2323 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2324 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2325 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2326 __ Cmp(string_representation, kExternalStringTag);
2327 __ B(ge, &not_seq_nor_cons); // Go to (6).
2328
2329 // (3) Cons string. Check that it's flat.
2330 __ Ldr(x10, FieldMemOperand(subject, ConsString::kSecondOffset));
2331 __ JumpIfNotRoot(x10, Heap::kempty_stringRootIndex, &runtime);
2332 // Replace subject with first string.
2333 __ Ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2334
2335 // (4) Is subject external? If yes, go to (7).
2336 __ Bind(&check_underlying);
2337 // Reload the string type.
2338 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2339 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2340 STATIC_ASSERT(kSeqStringTag == 0);
2341 // The underlying external string is never a short external string.
2342 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2343 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2344 __ TestAndBranchIfAnySet(string_type.X(),
2345 kStringRepresentationMask,
2346 &external_string); // Go to (7).
2347
2348 // (5) Sequential string. Load regexp code according to encoding.
2349 __ Bind(&seq_string);
2350
2351 // Check that the third argument is a positive smi less than the subject
2352 // string length. A negative value will be greater (unsigned comparison).
2353 DCHECK(jssp.Is(__ StackPointer()));
2354 __ Peek(x10, kPreviousIndexOffset);
2355 __ JumpIfNotSmi(x10, &runtime);
2356 __ Cmp(jsstring_length, x10);
2357 __ B(ls, &runtime);
2358
2359 // Argument 2 (x1): We need to load argument 2 (the previous index) into x1
2360 // before entering the exit frame.
2361 __ SmiUntag(x1, x10);
2362
2363 // The third bit determines the string encoding in string_type.
2364 STATIC_ASSERT(kOneByteStringTag == 0x04);
2365 STATIC_ASSERT(kTwoByteStringTag == 0x00);
2366 STATIC_ASSERT(kStringEncodingMask == 0x04);
2367
2368 // Find the code object based on the assumptions above.
2369 // kDataOneByteCodeOffset and kDataUC16CodeOffset are adjacent, adds an offset
2370 // of kPointerSize to reach the latter.
2371 DCHECK_EQ(JSRegExp::kDataOneByteCodeOffset + kPointerSize,
2372 JSRegExp::kDataUC16CodeOffset);
2373 __ Mov(x10, kPointerSize);
2374 // We will need the encoding later: Latin1 = 0x04
2375 // UC16 = 0x00
2376 __ Ands(string_encoding, string_type, kStringEncodingMask);
2377 __ CzeroX(x10, ne);
2378 __ Add(x10, regexp_data, x10);
2379 __ Ldr(code_object, FieldMemOperand(x10, JSRegExp::kDataOneByteCodeOffset));
2380
2381 // (E) Carry on. String handling is done.
2382
2383 // Check that the irregexp code has been generated for the actual string
2384 // encoding. If it has, the field contains a code object otherwise it contains
2385 // a smi (code flushing support).
2386 __ JumpIfSmi(code_object, &runtime);
2387
2388 // All checks done. Now push arguments for native regexp code.
2389 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1,
2390 x10,
2391 x11);
2392
2393 // Isolates: note we add an additional parameter here (isolate pointer).
2394 __ EnterExitFrame(false, x10, 1);
2395 DCHECK(csp.Is(__ StackPointer()));
2396
2397 // We have 9 arguments to pass to the regexp code, therefore we have to pass
2398 // one on the stack and the rest as registers.
2399
2400 // Note that the placement of the argument on the stack isn't standard
2401 // AAPCS64:
2402 // csp[0]: Space for the return address placed by DirectCEntryStub.
2403 // csp[8]: Argument 9, the current isolate address.
2404
2405 __ Mov(x10, ExternalReference::isolate_address(isolate()));
2406 __ Poke(x10, kPointerSize);
2407
2408 Register length = w11;
2409 Register previous_index_in_bytes = w12;
2410 Register start = x13;
2411
2412 // Load start of the subject string.
2413 __ Add(start, subject, SeqString::kHeaderSize - kHeapObjectTag);
2414 // Load the length from the original subject string from the previous stack
2415 // frame. Therefore we have to use fp, which points exactly to two pointer
2416 // sizes below the previous sp. (Because creating a new stack frame pushes
2417 // the previous fp onto the stack and decrements sp by 2 * kPointerSize.)
2418 __ Ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2419 __ Ldr(length, UntagSmiFieldMemOperand(subject, String::kLengthOffset));
2420
2421 // Handle UC16 encoding, two bytes make one character.
2422 // string_encoding: if Latin1: 0x04
2423 // if UC16: 0x00
2424 STATIC_ASSERT(kStringEncodingMask == 0x04);
2425 __ Ubfx(string_encoding, string_encoding, 2, 1);
2426 __ Eor(string_encoding, string_encoding, 1);
2427 // string_encoding: if Latin1: 0
2428 // if UC16: 1
2429
2430 // Convert string positions from characters to bytes.
2431 // Previous index is in x1.
2432 __ Lsl(previous_index_in_bytes, w1, string_encoding);
2433 __ Lsl(length, length, string_encoding);
2434 __ Lsl(sliced_string_offset, sliced_string_offset, string_encoding);
2435
2436 // Argument 1 (x0): Subject string.
2437 __ Mov(x0, subject);
2438
2439 // Argument 2 (x1): Previous index, already there.
2440
2441 // Argument 3 (x2): Get the start of input.
2442 // Start of input = start of string + previous index + substring offset
2443 // (0 if the string
2444 // is not sliced).
2445 __ Add(w10, previous_index_in_bytes, sliced_string_offset);
2446 __ Add(x2, start, Operand(w10, UXTW));
2447
2448 // Argument 4 (x3):
2449 // End of input = start of input + (length of input - previous index)
2450 __ Sub(w10, length, previous_index_in_bytes);
2451 __ Add(x3, x2, Operand(w10, UXTW));
2452
2453 // Argument 5 (x4): static offsets vector buffer.
2454 __ Mov(x4, ExternalReference::address_of_static_offsets_vector(isolate()));
2455
2456 // Argument 6 (x5): Set the number of capture registers to zero to force
2457 // global regexps to behave as non-global. This stub is not used for global
2458 // regexps.
2459 __ Mov(x5, 0);
2460
2461 // Argument 7 (x6): Start (high end) of backtracking stack memory area.
2462 __ Mov(x10, address_of_regexp_stack_memory_address);
2463 __ Ldr(x10, MemOperand(x10));
2464 __ Mov(x11, address_of_regexp_stack_memory_size);
2465 __ Ldr(x11, MemOperand(x11));
2466 __ Add(x6, x10, x11);
2467
2468 // Argument 8 (x7): Indicate that this is a direct call from JavaScript.
2469 __ Mov(x7, 1);
2470
2471 // Locate the code entry and call it.
2472 __ Add(code_object, code_object, Code::kHeaderSize - kHeapObjectTag);
2473 DirectCEntryStub stub(isolate());
2474 stub.GenerateCall(masm, code_object);
2475
2476 __ LeaveExitFrame(false, x10, true);
2477
2478 // The generated regexp code returns an int32 in w0.
2479 Label failure, exception;
2480 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::FAILURE, eq, &failure);
2481 __ CompareAndBranch(w0,
2482 NativeRegExpMacroAssembler::EXCEPTION,
2483 eq,
2484 &exception);
2485 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::RETRY, eq, &runtime);
2486
2487 // Success: process the result from the native regexp code.
2488 Register number_of_capture_registers = x12;
2489
2490 // Calculate number of capture registers (number_of_captures + 1) * 2
2491 // and store it in the last match info.
2492 __ Ldrsw(x10,
2493 UntagSmiFieldMemOperand(regexp_data,
2494 JSRegExp::kIrregexpCaptureCountOffset));
2495 __ Add(x10, x10, x10);
2496 __ Add(number_of_capture_registers, x10, 2);
2497
2498 // Check that the fourth object is a JSArray object.
2499 DCHECK(jssp.Is(__ StackPointer()));
2500 __ Peek(x10, kLastMatchInfoOffset);
2501 __ JumpIfSmi(x10, &runtime);
2502 __ JumpIfNotObjectType(x10, x11, x11, JS_ARRAY_TYPE, &runtime);
2503
2504 // Check that the JSArray is the fast case.
2505 __ Ldr(last_match_info_elements,
2506 FieldMemOperand(x10, JSArray::kElementsOffset));
2507 __ Ldr(x10,
2508 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2509 __ JumpIfNotRoot(x10, Heap::kFixedArrayMapRootIndex, &runtime);
2510
2511 // Check that the last match info has space for the capture registers and the
2512 // additional information (overhead).
2513 // (number_of_captures + 1) * 2 + overhead <= last match info size
2514 // (number_of_captures * 2) + 2 + overhead <= last match info size
2515 // number_of_capture_registers + overhead <= last match info size
2516 __ Ldrsw(x10,
2517 UntagSmiFieldMemOperand(last_match_info_elements,
2518 FixedArray::kLengthOffset));
2519 __ Add(x11, number_of_capture_registers, RegExpImpl::kLastMatchOverhead);
2520 __ Cmp(x11, x10);
2521 __ B(gt, &runtime);
2522
2523 // Store the capture count.
2524 __ SmiTag(x10, number_of_capture_registers);
2525 __ Str(x10,
2526 FieldMemOperand(last_match_info_elements,
2527 RegExpImpl::kLastCaptureCountOffset));
2528 // Store last subject and last input.
2529 __ Str(subject,
2530 FieldMemOperand(last_match_info_elements,
2531 RegExpImpl::kLastSubjectOffset));
2532 // Use x10 as the subject string in order to only need
2533 // one RecordWriteStub.
2534 __ Mov(x10, subject);
2535 __ RecordWriteField(last_match_info_elements,
2536 RegExpImpl::kLastSubjectOffset,
2537 x10,
2538 x11,
2539 kLRHasNotBeenSaved,
2540 kDontSaveFPRegs);
2541 __ Str(subject,
2542 FieldMemOperand(last_match_info_elements,
2543 RegExpImpl::kLastInputOffset));
2544 __ Mov(x10, subject);
2545 __ RecordWriteField(last_match_info_elements,
2546 RegExpImpl::kLastInputOffset,
2547 x10,
2548 x11,
2549 kLRHasNotBeenSaved,
2550 kDontSaveFPRegs);
2551
2552 Register last_match_offsets = x13;
2553 Register offsets_vector_index = x14;
2554 Register current_offset = x15;
2555
2556 // Get the static offsets vector filled by the native regexp code
2557 // and fill the last match info.
2558 ExternalReference address_of_static_offsets_vector =
2559 ExternalReference::address_of_static_offsets_vector(isolate());
2560 __ Mov(offsets_vector_index, address_of_static_offsets_vector);
2561
2562 Label next_capture, done;
2563 // Capture register counter starts from number of capture registers and
2564 // iterates down to zero (inclusive).
2565 __ Add(last_match_offsets,
2566 last_match_info_elements,
2567 RegExpImpl::kFirstCaptureOffset - kHeapObjectTag);
2568 __ Bind(&next_capture);
2569 __ Subs(number_of_capture_registers, number_of_capture_registers, 2);
2570 __ B(mi, &done);
2571 // Read two 32 bit values from the static offsets vector buffer into
2572 // an X register
2573 __ Ldr(current_offset,
2574 MemOperand(offsets_vector_index, kWRegSize * 2, PostIndex));
2575 // Store the smi values in the last match info.
2576 __ SmiTag(x10, current_offset);
2577 // Clearing the 32 bottom bits gives us a Smi.
2578 STATIC_ASSERT(kSmiTag == 0);
2579 __ Bic(x11, current_offset, kSmiShiftMask);
2580 __ Stp(x10,
2581 x11,
2582 MemOperand(last_match_offsets, kXRegSize * 2, PostIndex));
2583 __ B(&next_capture);
2584 __ Bind(&done);
2585
2586 // Return last match info.
2587 __ Peek(x0, kLastMatchInfoOffset);
2588 __ PopCPURegList(used_callee_saved_registers);
2589 // Drop the 4 arguments of the stub from the stack.
2590 __ Drop(4);
2591 __ Ret();
2592
2593 __ Bind(&exception);
2594 Register exception_value = x0;
2595 // A stack overflow (on the backtrack stack) may have occured
2596 // in the RegExp code but no exception has been created yet.
2597 // If there is no pending exception, handle that in the runtime system.
2598 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
2599 __ Mov(x11,
2600 Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2601 isolate())));
2602 __ Ldr(exception_value, MemOperand(x11));
2603 __ Cmp(x10, exception_value);
2604 __ B(eq, &runtime);
2605
2606 __ Str(x10, MemOperand(x11)); // Clear pending exception.
2607
2608 // Check if the exception is a termination. If so, throw as uncatchable.
2609 Label termination_exception;
2610 __ JumpIfRoot(exception_value,
2611 Heap::kTerminationExceptionRootIndex,
2612 &termination_exception);
2613
2614 __ Throw(exception_value, x10, x11, x12, x13);
2615
2616 __ Bind(&termination_exception);
2617 __ ThrowUncatchable(exception_value, x10, x11, x12, x13);
2618
2619 __ Bind(&failure);
2620 __ Mov(x0, Operand(isolate()->factory()->null_value()));
2621 __ PopCPURegList(used_callee_saved_registers);
2622 // Drop the 4 arguments of the stub from the stack.
2623 __ Drop(4);
2624 __ Ret();
2625
2626 __ Bind(&runtime);
2627 __ PopCPURegList(used_callee_saved_registers);
2628 __ TailCallRuntime(Runtime::kRegExpExecRT, 4, 1);
2629
2630 // Deferred code for string handling.
2631 // (6) Not a long external string? If yes, go to (8).
2632 __ Bind(&not_seq_nor_cons);
2633 // Compare flags are still set.
2634 __ B(ne, &not_long_external); // Go to (8).
2635
2636 // (7) External string. Make it, offset-wise, look like a sequential string.
2637 __ Bind(&external_string);
2638 if (masm->emit_debug_code()) {
2639 // Assert that we do not have a cons or slice (indirect strings) here.
2640 // Sequential strings have already been ruled out.
2641 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2642 __ Ldrb(x10, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2643 __ Tst(x10, kIsIndirectStringMask);
2644 __ Check(eq, kExternalStringExpectedButNotFound);
2645 __ And(x10, x10, kStringRepresentationMask);
2646 __ Cmp(x10, 0);
2647 __ Check(ne, kExternalStringExpectedButNotFound);
2648 }
2649 __ Ldr(subject,
2650 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2651 // Move the pointer so that offset-wise, it looks like a sequential string.
2652 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2653 __ Sub(subject, subject, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2654 __ B(&seq_string); // Go to (5).
2655
2656 // (8) If this is a short external string or not a string, bail out to
2657 // runtime.
2658 __ Bind(&not_long_external);
2659 STATIC_ASSERT(kShortExternalStringTag != 0);
2660 __ TestAndBranchIfAnySet(string_representation,
2661 kShortExternalStringMask | kIsNotStringMask,
2662 &runtime);
2663
2664 // (9) Sliced string. Replace subject with parent.
2665 __ Ldr(sliced_string_offset,
2666 UntagSmiFieldMemOperand(subject, SlicedString::kOffsetOffset));
2667 __ Ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2668 __ B(&check_underlying); // Go to (4).
2669#endif
2670}
2671
2672
2673static void GenerateRecordCallTarget(MacroAssembler* masm,
2674 Register argc,
2675 Register function,
2676 Register feedback_vector,
2677 Register index,
2678 Register scratch1,
2679 Register scratch2) {
2680 ASM_LOCATION("GenerateRecordCallTarget");
2681 DCHECK(!AreAliased(scratch1, scratch2,
2682 argc, function, feedback_vector, index));
2683 // Cache the called function in a feedback vector slot. Cache states are
2684 // uninitialized, monomorphic (indicated by a JSFunction), and megamorphic.
2685 // argc : number of arguments to the construct function
2686 // function : the function to call
2687 // feedback_vector : the feedback vector
2688 // index : slot in feedback vector (smi)
2689 Label initialize, done, miss, megamorphic, not_array_function;
2690
2691 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2692 masm->isolate()->heap()->megamorphic_symbol());
2693 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2694 masm->isolate()->heap()->uninitialized_symbol());
2695
2696 // Load the cache state.
2697 __ Add(scratch1, feedback_vector,
2698 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2699 __ Ldr(scratch1, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
2700
2701 // A monomorphic cache hit or an already megamorphic state: invoke the
2702 // function without changing the state.
2703 __ Cmp(scratch1, function);
2704 __ B(eq, &done);
2705
2706 if (!FLAG_pretenuring_call_new) {
2707 // If we came here, we need to see if we are the array function.
2708 // If we didn't have a matching function, and we didn't find the megamorph
2709 // sentinel, then we have in the slot either some other function or an
2710 // AllocationSite. Do a map check on the object in scratch1 register.
2711 __ Ldr(scratch2, FieldMemOperand(scratch1, AllocationSite::kMapOffset));
2712 __ JumpIfNotRoot(scratch2, Heap::kAllocationSiteMapRootIndex, &miss);
2713
2714 // Make sure the function is the Array() function
2715 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2716 __ Cmp(function, scratch1);
2717 __ B(ne, &megamorphic);
2718 __ B(&done);
2719 }
2720
2721 __ Bind(&miss);
2722
2723 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2724 // megamorphic.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002725 __ JumpIfRoot(scratch1, Heap::kuninitialized_symbolRootIndex, &initialize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002726 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2727 // write-barrier is needed.
2728 __ Bind(&megamorphic);
2729 __ Add(scratch1, feedback_vector,
2730 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002731 __ LoadRoot(scratch2, Heap::kmegamorphic_symbolRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002732 __ Str(scratch2, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
2733 __ B(&done);
2734
2735 // An uninitialized cache is patched with the function or sentinel to
2736 // indicate the ElementsKind if function is the Array constructor.
2737 __ Bind(&initialize);
2738
2739 if (!FLAG_pretenuring_call_new) {
2740 // Make sure the function is the Array() function
2741 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2742 __ Cmp(function, scratch1);
2743 __ B(ne, &not_array_function);
2744
2745 // The target function is the Array constructor,
2746 // Create an AllocationSite if we don't already have it, store it in the
2747 // slot.
2748 {
2749 FrameScope scope(masm, StackFrame::INTERNAL);
2750 CreateAllocationSiteStub create_stub(masm->isolate());
2751
2752 // Arguments register must be smi-tagged to call out.
2753 __ SmiTag(argc);
2754 __ Push(argc, function, feedback_vector, index);
2755
2756 // CreateAllocationSiteStub expect the feedback vector in x2 and the slot
2757 // index in x3.
2758 DCHECK(feedback_vector.Is(x2) && index.Is(x3));
2759 __ CallStub(&create_stub);
2760
2761 __ Pop(index, feedback_vector, function, argc);
2762 __ SmiUntag(argc);
2763 }
2764 __ B(&done);
2765
2766 __ Bind(&not_array_function);
2767 }
2768
2769 // An uninitialized cache is patched with the function.
2770
2771 __ Add(scratch1, feedback_vector,
2772 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2773 __ Add(scratch1, scratch1, FixedArray::kHeaderSize - kHeapObjectTag);
2774 __ Str(function, MemOperand(scratch1, 0));
2775
2776 __ Push(function);
2777 __ RecordWrite(feedback_vector, scratch1, function, kLRHasNotBeenSaved,
2778 kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
2779 __ Pop(function);
2780
2781 __ Bind(&done);
2782}
2783
2784
2785static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2786 // Do not transform the receiver for strict mode functions.
2787 __ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
2788 __ Ldr(w4, FieldMemOperand(x3, SharedFunctionInfo::kCompilerHintsOffset));
2789 __ Tbnz(w4, SharedFunctionInfo::kStrictModeFunction, cont);
2790
2791 // Do not transform the receiver for native (Compilerhints already in x3).
2792 __ Tbnz(w4, SharedFunctionInfo::kNative, cont);
2793}
2794
2795
2796static void EmitSlowCase(MacroAssembler* masm,
2797 int argc,
2798 Register function,
2799 Register type,
2800 Label* non_function) {
2801 // Check for function proxy.
2802 // x10 : function type.
2803 __ CompareAndBranch(type, JS_FUNCTION_PROXY_TYPE, ne, non_function);
2804 __ Push(function); // put proxy as additional argument
2805 __ Mov(x0, argc + 1);
2806 __ Mov(x2, 0);
2807 __ GetBuiltinFunction(x1, Builtins::CALL_FUNCTION_PROXY);
2808 {
2809 Handle<Code> adaptor =
2810 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2811 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2812 }
2813
2814 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2815 // of the original receiver from the call site).
2816 __ Bind(non_function);
2817 __ Poke(function, argc * kXRegSize);
2818 __ Mov(x0, argc); // Set up the number of arguments.
2819 __ Mov(x2, 0);
2820 __ GetBuiltinFunction(function, Builtins::CALL_NON_FUNCTION);
2821 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2822 RelocInfo::CODE_TARGET);
2823}
2824
2825
2826static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2827 // Wrap the receiver and patch it back onto the stack.
2828 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2829 __ Push(x1, x3);
2830 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2831 __ Pop(x1);
2832 }
2833 __ Poke(x0, argc * kPointerSize);
2834 __ B(cont);
2835}
2836
2837
2838static void CallFunctionNoFeedback(MacroAssembler* masm,
2839 int argc, bool needs_checks,
2840 bool call_as_method) {
2841 // x1 function the function to call
2842 Register function = x1;
2843 Register type = x4;
2844 Label slow, non_function, wrap, cont;
2845
2846 // TODO(jbramley): This function has a lot of unnamed registers. Name them,
2847 // and tidy things up a bit.
2848
2849 if (needs_checks) {
2850 // Check that the function is really a JavaScript function.
2851 __ JumpIfSmi(function, &non_function);
2852
2853 // Goto slow case if we do not have a function.
2854 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
2855 }
2856
2857 // Fast-case: Invoke the function now.
2858 // x1 function pushed function
2859 ParameterCount actual(argc);
2860
2861 if (call_as_method) {
2862 if (needs_checks) {
2863 EmitContinueIfStrictOrNative(masm, &cont);
2864 }
2865
2866 // Compute the receiver in sloppy mode.
2867 __ Peek(x3, argc * kPointerSize);
2868
2869 if (needs_checks) {
2870 __ JumpIfSmi(x3, &wrap);
2871 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
2872 } else {
2873 __ B(&wrap);
2874 }
2875
2876 __ Bind(&cont);
2877 }
2878
2879 __ InvokeFunction(function,
2880 actual,
2881 JUMP_FUNCTION,
2882 NullCallWrapper());
2883 if (needs_checks) {
2884 // Slow-case: Non-function called.
2885 __ Bind(&slow);
2886 EmitSlowCase(masm, argc, function, type, &non_function);
2887 }
2888
2889 if (call_as_method) {
2890 __ Bind(&wrap);
2891 EmitWrapCase(masm, argc, &cont);
2892 }
2893}
2894
2895
2896void CallFunctionStub::Generate(MacroAssembler* masm) {
2897 ASM_LOCATION("CallFunctionStub::Generate");
2898 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2899}
2900
2901
2902void CallConstructStub::Generate(MacroAssembler* masm) {
2903 ASM_LOCATION("CallConstructStub::Generate");
2904 // x0 : number of arguments
2905 // x1 : the function to call
2906 // x2 : feedback vector
2907 // x3 : slot in feedback vector (smi) (if r2 is not the megamorphic symbol)
2908 Register function = x1;
2909 Label slow, non_function_call;
2910
2911 // Check that the function is not a smi.
2912 __ JumpIfSmi(function, &non_function_call);
2913 // Check that the function is a JSFunction.
2914 Register object_type = x10;
2915 __ JumpIfNotObjectType(function, object_type, object_type, JS_FUNCTION_TYPE,
2916 &slow);
2917
2918 if (RecordCallTarget()) {
2919 GenerateRecordCallTarget(masm, x0, function, x2, x3, x4, x5);
2920
2921 __ Add(x5, x2, Operand::UntagSmiAndScale(x3, kPointerSizeLog2));
2922 if (FLAG_pretenuring_call_new) {
2923 // Put the AllocationSite from the feedback vector into x2.
2924 // By adding kPointerSize we encode that we know the AllocationSite
2925 // entry is at the feedback vector slot given by x3 + 1.
2926 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize + kPointerSize));
2927 } else {
2928 Label feedback_register_initialized;
2929 // Put the AllocationSite from the feedback vector into x2, or undefined.
2930 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize));
2931 __ Ldr(x5, FieldMemOperand(x2, AllocationSite::kMapOffset));
2932 __ JumpIfRoot(x5, Heap::kAllocationSiteMapRootIndex,
2933 &feedback_register_initialized);
2934 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
2935 __ bind(&feedback_register_initialized);
2936 }
2937
2938 __ AssertUndefinedOrAllocationSite(x2, x5);
2939 }
2940
2941 // Jump to the function-specific construct stub.
2942 Register jump_reg = x4;
2943 Register shared_func_info = jump_reg;
2944 Register cons_stub = jump_reg;
2945 Register cons_stub_code = jump_reg;
2946 __ Ldr(shared_func_info,
2947 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
2948 __ Ldr(cons_stub,
2949 FieldMemOperand(shared_func_info,
2950 SharedFunctionInfo::kConstructStubOffset));
2951 __ Add(cons_stub_code, cons_stub, Code::kHeaderSize - kHeapObjectTag);
2952 __ Br(cons_stub_code);
2953
2954 Label do_call;
2955 __ Bind(&slow);
2956 __ Cmp(object_type, JS_FUNCTION_PROXY_TYPE);
2957 __ B(ne, &non_function_call);
2958 __ GetBuiltinFunction(x1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2959 __ B(&do_call);
2960
2961 __ Bind(&non_function_call);
2962 __ GetBuiltinFunction(x1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2963
2964 __ Bind(&do_call);
2965 // Set expected number of arguments to zero (not changing x0).
2966 __ Mov(x2, 0);
2967 __ Jump(isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2968 RelocInfo::CODE_TARGET);
2969}
2970
2971
2972static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2973 __ Ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2974 __ Ldr(vector, FieldMemOperand(vector,
2975 JSFunction::kSharedFunctionInfoOffset));
2976 __ Ldr(vector, FieldMemOperand(vector,
2977 SharedFunctionInfo::kFeedbackVectorOffset));
2978}
2979
2980
2981void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2982 // x1 - function
2983 // x3 - slot id
2984 Label miss;
2985 Register function = x1;
2986 Register feedback_vector = x2;
2987 Register index = x3;
2988 Register scratch = x4;
2989
2990 EmitLoadTypeFeedbackVector(masm, feedback_vector);
2991
2992 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch);
2993 __ Cmp(function, scratch);
2994 __ B(ne, &miss);
2995
2996 __ Mov(x0, Operand(arg_count()));
2997
2998 __ Add(scratch, feedback_vector,
2999 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3000 __ Ldr(scratch, FieldMemOperand(scratch, FixedArray::kHeaderSize));
3001
3002 // Verify that scratch contains an AllocationSite
3003 Register map = x5;
3004 __ Ldr(map, FieldMemOperand(scratch, HeapObject::kMapOffset));
3005 __ JumpIfNotRoot(map, Heap::kAllocationSiteMapRootIndex, &miss);
3006
3007 Register allocation_site = feedback_vector;
3008 __ Mov(allocation_site, scratch);
3009 ArrayConstructorStub stub(masm->isolate(), arg_count());
3010 __ TailCallStub(&stub);
3011
3012 __ bind(&miss);
3013 GenerateMiss(masm);
3014
3015 // The slow case, we need this no matter what to complete a call after a miss.
3016 CallFunctionNoFeedback(masm,
3017 arg_count(),
3018 true,
3019 CallAsMethod());
3020
3021 __ Unreachable();
3022}
3023
3024
3025void CallICStub::Generate(MacroAssembler* masm) {
3026 ASM_LOCATION("CallICStub");
3027
3028 // x1 - function
3029 // x3 - slot id (Smi)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003030 const int with_types_offset =
3031 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
3032 const int generic_offset =
3033 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003034 Label extra_checks_or_miss, slow_start;
3035 Label slow, non_function, wrap, cont;
3036 Label have_js_function;
3037 int argc = arg_count();
3038 ParameterCount actual(argc);
3039
3040 Register function = x1;
3041 Register feedback_vector = x2;
3042 Register index = x3;
3043 Register type = x4;
3044
3045 EmitLoadTypeFeedbackVector(masm, feedback_vector);
3046
3047 // The checks. First, does x1 match the recorded monomorphic target?
3048 __ Add(x4, feedback_vector,
3049 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3050 __ Ldr(x4, FieldMemOperand(x4, FixedArray::kHeaderSize));
3051
3052 __ Cmp(x4, function);
3053 __ B(ne, &extra_checks_or_miss);
3054
3055 __ bind(&have_js_function);
3056 if (CallAsMethod()) {
3057 EmitContinueIfStrictOrNative(masm, &cont);
3058
3059 // Compute the receiver in sloppy mode.
3060 __ Peek(x3, argc * kPointerSize);
3061
3062 __ JumpIfSmi(x3, &wrap);
3063 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
3064
3065 __ Bind(&cont);
3066 }
3067
3068 __ InvokeFunction(function,
3069 actual,
3070 JUMP_FUNCTION,
3071 NullCallWrapper());
3072
3073 __ bind(&slow);
3074 EmitSlowCase(masm, argc, function, type, &non_function);
3075
3076 if (CallAsMethod()) {
3077 __ bind(&wrap);
3078 EmitWrapCase(masm, argc, &cont);
3079 }
3080
3081 __ bind(&extra_checks_or_miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003082 Label uninitialized, miss;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003083
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003084 __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &slow_start);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003085
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003086 // The following cases attempt to handle MISS cases without going to the
3087 // runtime.
3088 if (FLAG_trace_ic) {
3089 __ jmp(&miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003090 }
3091
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003092 __ JumpIfRoot(x4, Heap::kuninitialized_symbolRootIndex, &miss);
3093
3094 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3095 // to handle it here. More complex cases are dealt with in the runtime.
3096 __ AssertNotSmi(x4);
3097 __ JumpIfNotObjectType(x4, x5, x5, JS_FUNCTION_TYPE, &miss);
3098 __ Add(x4, feedback_vector,
3099 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3100 __ LoadRoot(x5, Heap::kmegamorphic_symbolRootIndex);
3101 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize));
3102 // We have to update statistics for runtime profiling.
3103 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3104 __ Subs(x4, x4, Operand(Smi::FromInt(1)));
3105 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3106 __ Ldr(x4, FieldMemOperand(feedback_vector, generic_offset));
3107 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3108 __ Str(x4, FieldMemOperand(feedback_vector, generic_offset));
3109 __ B(&slow_start);
3110
3111 __ bind(&uninitialized);
3112
3113 // We are going monomorphic, provided we actually have a JSFunction.
3114 __ JumpIfSmi(function, &miss);
3115
3116 // Goto miss case if we do not have a function.
3117 __ JumpIfNotObjectType(function, x5, x5, JS_FUNCTION_TYPE, &miss);
3118
3119 // Make sure the function is not the Array() function, which requires special
3120 // behavior on MISS.
3121 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, x5);
3122 __ Cmp(function, x5);
3123 __ B(eq, &miss);
3124
3125 // Update stats.
3126 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3127 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3128 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3129
3130 // Store the function.
3131 __ Add(x4, feedback_vector,
3132 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3133 __ Str(function, FieldMemOperand(x4, FixedArray::kHeaderSize));
3134
3135 __ Add(x4, feedback_vector,
3136 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3137 __ Add(x4, x4, FixedArray::kHeaderSize - kHeapObjectTag);
3138 __ Str(function, MemOperand(x4, 0));
3139
3140 // Update the write barrier.
3141 __ Mov(x5, function);
3142 __ RecordWrite(feedback_vector, x4, x5, kLRHasNotBeenSaved, kDontSaveFPRegs,
3143 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3144 __ B(&have_js_function);
3145
3146 // We are here because tracing is on or we encountered a MISS case we can't
3147 // handle here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003148 __ bind(&miss);
3149 GenerateMiss(masm);
3150
3151 // the slow case
3152 __ bind(&slow_start);
3153
3154 // Check that the function is really a JavaScript function.
3155 __ JumpIfSmi(function, &non_function);
3156
3157 // Goto slow case if we do not have a function.
3158 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
3159 __ B(&have_js_function);
3160}
3161
3162
3163void CallICStub::GenerateMiss(MacroAssembler* masm) {
3164 ASM_LOCATION("CallICStub[Miss]");
3165
3166 // Get the receiver of the function from the stack; 1 ~ return address.
3167 __ Peek(x4, (arg_count() + 1) * kPointerSize);
3168
3169 {
3170 FrameScope scope(masm, StackFrame::INTERNAL);
3171
3172 // Push the receiver and the function and feedback info.
3173 __ Push(x4, x1, x2, x3);
3174
3175 // Call the entry.
3176 IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
3177 : IC::kCallIC_Customization_Miss;
3178
3179 ExternalReference miss = ExternalReference(IC_Utility(id),
3180 masm->isolate());
3181 __ CallExternalReference(miss, 4);
3182
3183 // Move result to edi and exit the internal frame.
3184 __ Mov(x1, x0);
3185 }
3186}
3187
3188
3189void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3190 // If the receiver is a smi trigger the non-string case.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003191 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3192 __ JumpIfSmi(object_, receiver_not_string_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003193
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003194 // Fetch the instance type of the receiver into result register.
3195 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3196 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003197
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003198 // If the receiver is not a string trigger the non-string case.
3199 __ TestAndBranchIfAnySet(result_, kIsNotStringMask, receiver_not_string_);
3200 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003201
3202 // If the index is non-smi trigger the non-smi case.
3203 __ JumpIfNotSmi(index_, &index_not_smi_);
3204
3205 __ Bind(&got_smi_index_);
3206 // Check for index out of range.
3207 __ Ldrsw(result_, UntagSmiFieldMemOperand(object_, String::kLengthOffset));
3208 __ Cmp(result_, Operand::UntagSmi(index_));
3209 __ B(ls, index_out_of_range_);
3210
3211 __ SmiUntag(index_);
3212
3213 StringCharLoadGenerator::Generate(masm,
3214 object_,
3215 index_.W(),
3216 result_,
3217 &call_runtime_);
3218 __ SmiTag(result_);
3219 __ Bind(&exit_);
3220}
3221
3222
3223void StringCharCodeAtGenerator::GenerateSlow(
3224 MacroAssembler* masm,
3225 const RuntimeCallHelper& call_helper) {
3226 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3227
3228 __ Bind(&index_not_smi_);
3229 // If index is a heap number, try converting it to an integer.
3230 __ JumpIfNotHeapNumber(index_, index_not_number_);
3231 call_helper.BeforeCall(masm);
3232 // Save object_ on the stack and pass index_ as argument for runtime call.
3233 __ Push(object_, index_);
3234 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3235 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3236 } else {
3237 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3238 // NumberToSmi discards numbers that are not exact integers.
3239 __ CallRuntime(Runtime::kNumberToSmi, 1);
3240 }
3241 // Save the conversion result before the pop instructions below
3242 // have a chance to overwrite it.
3243 __ Mov(index_, x0);
3244 __ Pop(object_);
3245 // Reload the instance type.
3246 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3247 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3248 call_helper.AfterCall(masm);
3249
3250 // If index is still not a smi, it must be out of range.
3251 __ JumpIfNotSmi(index_, index_out_of_range_);
3252 // Otherwise, return to the fast path.
3253 __ B(&got_smi_index_);
3254
3255 // Call runtime. We get here when the receiver is a string and the
3256 // index is a number, but the code of getting the actual character
3257 // is too complex (e.g., when the string needs to be flattened).
3258 __ Bind(&call_runtime_);
3259 call_helper.BeforeCall(masm);
3260 __ SmiTag(index_);
3261 __ Push(object_, index_);
3262 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3263 __ Mov(result_, x0);
3264 call_helper.AfterCall(masm);
3265 __ B(&exit_);
3266
3267 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3268}
3269
3270
3271void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3272 __ JumpIfNotSmi(code_, &slow_case_);
3273 __ Cmp(code_, Smi::FromInt(String::kMaxOneByteCharCode));
3274 __ B(hi, &slow_case_);
3275
3276 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3277 // At this point code register contains smi tagged one-byte char code.
3278 __ Add(result_, result_, Operand::UntagSmiAndScale(code_, kPointerSizeLog2));
3279 __ Ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3280 __ JumpIfRoot(result_, Heap::kUndefinedValueRootIndex, &slow_case_);
3281 __ Bind(&exit_);
3282}
3283
3284
3285void StringCharFromCodeGenerator::GenerateSlow(
3286 MacroAssembler* masm,
3287 const RuntimeCallHelper& call_helper) {
3288 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3289
3290 __ Bind(&slow_case_);
3291 call_helper.BeforeCall(masm);
3292 __ Push(code_);
3293 __ CallRuntime(Runtime::kCharFromCode, 1);
3294 __ Mov(result_, x0);
3295 call_helper.AfterCall(masm);
3296 __ B(&exit_);
3297
3298 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3299}
3300
3301
3302void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3303 // Inputs are in x0 (lhs) and x1 (rhs).
3304 DCHECK(state() == CompareICState::SMI);
3305 ASM_LOCATION("CompareICStub[Smis]");
3306 Label miss;
3307 // Bail out (to 'miss') unless both x0 and x1 are smis.
3308 __ JumpIfEitherNotSmi(x0, x1, &miss);
3309
3310 if (GetCondition() == eq) {
3311 // For equality we do not care about the sign of the result.
3312 __ Sub(x0, x0, x1);
3313 } else {
3314 // Untag before subtracting to avoid handling overflow.
3315 __ SmiUntag(x1);
3316 __ Sub(x0, x1, Operand::UntagSmi(x0));
3317 }
3318 __ Ret();
3319
3320 __ Bind(&miss);
3321 GenerateMiss(masm);
3322}
3323
3324
3325void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3326 DCHECK(state() == CompareICState::NUMBER);
3327 ASM_LOCATION("CompareICStub[HeapNumbers]");
3328
3329 Label unordered, maybe_undefined1, maybe_undefined2;
3330 Label miss, handle_lhs, values_in_d_regs;
3331 Label untag_rhs, untag_lhs;
3332
3333 Register result = x0;
3334 Register rhs = x0;
3335 Register lhs = x1;
3336 FPRegister rhs_d = d0;
3337 FPRegister lhs_d = d1;
3338
3339 if (left() == CompareICState::SMI) {
3340 __ JumpIfNotSmi(lhs, &miss);
3341 }
3342 if (right() == CompareICState::SMI) {
3343 __ JumpIfNotSmi(rhs, &miss);
3344 }
3345
3346 __ SmiUntagToDouble(rhs_d, rhs, kSpeculativeUntag);
3347 __ SmiUntagToDouble(lhs_d, lhs, kSpeculativeUntag);
3348
3349 // Load rhs if it's a heap number.
3350 __ JumpIfSmi(rhs, &handle_lhs);
3351 __ JumpIfNotHeapNumber(rhs, &maybe_undefined1);
3352 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
3353
3354 // Load lhs if it's a heap number.
3355 __ Bind(&handle_lhs);
3356 __ JumpIfSmi(lhs, &values_in_d_regs);
3357 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3358 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
3359
3360 __ Bind(&values_in_d_regs);
3361 __ Fcmp(lhs_d, rhs_d);
3362 __ B(vs, &unordered); // Overflow flag set if either is NaN.
3363 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
3364 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
3365 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
3366 __ Ret();
3367
3368 __ Bind(&unordered);
3369 CompareICStub stub(isolate(), op(), CompareICState::GENERIC,
3370 CompareICState::GENERIC, CompareICState::GENERIC);
3371 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3372
3373 __ Bind(&maybe_undefined1);
3374 if (Token::IsOrderedRelationalCompareOp(op())) {
3375 __ JumpIfNotRoot(rhs, Heap::kUndefinedValueRootIndex, &miss);
3376 __ JumpIfSmi(lhs, &unordered);
3377 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3378 __ B(&unordered);
3379 }
3380
3381 __ Bind(&maybe_undefined2);
3382 if (Token::IsOrderedRelationalCompareOp(op())) {
3383 __ JumpIfRoot(lhs, Heap::kUndefinedValueRootIndex, &unordered);
3384 }
3385
3386 __ Bind(&miss);
3387 GenerateMiss(masm);
3388}
3389
3390
3391void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3392 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3393 ASM_LOCATION("CompareICStub[InternalizedStrings]");
3394 Label miss;
3395
3396 Register result = x0;
3397 Register rhs = x0;
3398 Register lhs = x1;
3399
3400 // Check that both operands are heap objects.
3401 __ JumpIfEitherSmi(lhs, rhs, &miss);
3402
3403 // Check that both operands are internalized strings.
3404 Register rhs_map = x10;
3405 Register lhs_map = x11;
3406 Register rhs_type = x10;
3407 Register lhs_type = x11;
3408 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3409 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3410 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3411 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3412
3413 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
3414 __ Orr(x12, lhs_type, rhs_type);
3415 __ TestAndBranchIfAnySet(
3416 x12, kIsNotStringMask | kIsNotInternalizedMask, &miss);
3417
3418 // Internalized strings are compared by identity.
3419 STATIC_ASSERT(EQUAL == 0);
3420 __ Cmp(lhs, rhs);
3421 __ Cset(result, ne);
3422 __ Ret();
3423
3424 __ Bind(&miss);
3425 GenerateMiss(masm);
3426}
3427
3428
3429void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3430 DCHECK(state() == CompareICState::UNIQUE_NAME);
3431 ASM_LOCATION("CompareICStub[UniqueNames]");
3432 DCHECK(GetCondition() == eq);
3433 Label miss;
3434
3435 Register result = x0;
3436 Register rhs = x0;
3437 Register lhs = x1;
3438
3439 Register lhs_instance_type = w2;
3440 Register rhs_instance_type = w3;
3441
3442 // Check that both operands are heap objects.
3443 __ JumpIfEitherSmi(lhs, rhs, &miss);
3444
3445 // Check that both operands are unique names. This leaves the instance
3446 // types loaded in tmp1 and tmp2.
3447 __ Ldr(x10, FieldMemOperand(lhs, HeapObject::kMapOffset));
3448 __ Ldr(x11, FieldMemOperand(rhs, HeapObject::kMapOffset));
3449 __ Ldrb(lhs_instance_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
3450 __ Ldrb(rhs_instance_type, FieldMemOperand(x11, Map::kInstanceTypeOffset));
3451
3452 // To avoid a miss, each instance type should be either SYMBOL_TYPE or it
3453 // should have kInternalizedTag set.
3454 __ JumpIfNotUniqueNameInstanceType(lhs_instance_type, &miss);
3455 __ JumpIfNotUniqueNameInstanceType(rhs_instance_type, &miss);
3456
3457 // Unique names are compared by identity.
3458 STATIC_ASSERT(EQUAL == 0);
3459 __ Cmp(lhs, rhs);
3460 __ Cset(result, ne);
3461 __ Ret();
3462
3463 __ Bind(&miss);
3464 GenerateMiss(masm);
3465}
3466
3467
3468void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3469 DCHECK(state() == CompareICState::STRING);
3470 ASM_LOCATION("CompareICStub[Strings]");
3471
3472 Label miss;
3473
3474 bool equality = Token::IsEqualityOp(op());
3475
3476 Register result = x0;
3477 Register rhs = x0;
3478 Register lhs = x1;
3479
3480 // Check that both operands are heap objects.
3481 __ JumpIfEitherSmi(rhs, lhs, &miss);
3482
3483 // Check that both operands are strings.
3484 Register rhs_map = x10;
3485 Register lhs_map = x11;
3486 Register rhs_type = x10;
3487 Register lhs_type = x11;
3488 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3489 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3490 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3491 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3492 STATIC_ASSERT(kNotStringTag != 0);
3493 __ Orr(x12, lhs_type, rhs_type);
3494 __ Tbnz(x12, MaskToBit(kIsNotStringMask), &miss);
3495
3496 // Fast check for identical strings.
3497 Label not_equal;
3498 __ Cmp(lhs, rhs);
3499 __ B(ne, &not_equal);
3500 __ Mov(result, EQUAL);
3501 __ Ret();
3502
3503 __ Bind(&not_equal);
3504 // Handle not identical strings
3505
3506 // Check that both strings are internalized strings. If they are, we're done
3507 // because we already know they are not identical. We know they are both
3508 // strings.
3509 if (equality) {
3510 DCHECK(GetCondition() == eq);
3511 STATIC_ASSERT(kInternalizedTag == 0);
3512 Label not_internalized_strings;
3513 __ Orr(x12, lhs_type, rhs_type);
3514 __ TestAndBranchIfAnySet(
3515 x12, kIsNotInternalizedMask, &not_internalized_strings);
3516 // Result is in rhs (x0), and not EQUAL, as rhs is not a smi.
3517 __ Ret();
3518 __ Bind(&not_internalized_strings);
3519 }
3520
3521 // Check that both strings are sequential one-byte.
3522 Label runtime;
3523 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x12,
3524 x13, &runtime);
3525
3526 // Compare flat one-byte strings. Returns when done.
3527 if (equality) {
3528 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
3529 x12);
3530 } else {
3531 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
3532 x12, x13);
3533 }
3534
3535 // Handle more complex cases in runtime.
3536 __ Bind(&runtime);
3537 __ Push(lhs, rhs);
3538 if (equality) {
3539 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3540 } else {
3541 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3542 }
3543
3544 __ Bind(&miss);
3545 GenerateMiss(masm);
3546}
3547
3548
3549void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3550 DCHECK(state() == CompareICState::OBJECT);
3551 ASM_LOCATION("CompareICStub[Objects]");
3552
3553 Label miss;
3554
3555 Register result = x0;
3556 Register rhs = x0;
3557 Register lhs = x1;
3558
3559 __ JumpIfEitherSmi(rhs, lhs, &miss);
3560
3561 __ JumpIfNotObjectType(rhs, x10, x10, JS_OBJECT_TYPE, &miss);
3562 __ JumpIfNotObjectType(lhs, x10, x10, JS_OBJECT_TYPE, &miss);
3563
3564 DCHECK(GetCondition() == eq);
3565 __ Sub(result, rhs, lhs);
3566 __ Ret();
3567
3568 __ Bind(&miss);
3569 GenerateMiss(masm);
3570}
3571
3572
3573void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3574 ASM_LOCATION("CompareICStub[KnownObjects]");
3575
3576 Label miss;
3577
3578 Register result = x0;
3579 Register rhs = x0;
3580 Register lhs = x1;
3581
3582 __ JumpIfEitherSmi(rhs, lhs, &miss);
3583
3584 Register rhs_map = x10;
3585 Register lhs_map = x11;
3586 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3587 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3588 __ Cmp(rhs_map, Operand(known_map_));
3589 __ B(ne, &miss);
3590 __ Cmp(lhs_map, Operand(known_map_));
3591 __ B(ne, &miss);
3592
3593 __ Sub(result, rhs, lhs);
3594 __ Ret();
3595
3596 __ Bind(&miss);
3597 GenerateMiss(masm);
3598}
3599
3600
3601// This method handles the case where a compare stub had the wrong
3602// implementation. It calls a miss handler, which re-writes the stub. All other
3603// CompareICStub::Generate* methods should fall back into this one if their
3604// operands were not the expected types.
3605void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3606 ASM_LOCATION("CompareICStub[Miss]");
3607
3608 Register stub_entry = x11;
3609 {
3610 ExternalReference miss =
3611 ExternalReference(IC_Utility(IC::kCompareIC_Miss), isolate());
3612
3613 FrameScope scope(masm, StackFrame::INTERNAL);
3614 Register op = x10;
3615 Register left = x1;
3616 Register right = x0;
3617 // Preserve some caller-saved registers.
3618 __ Push(x1, x0, lr);
3619 // Push the arguments.
3620 __ Mov(op, Smi::FromInt(this->op()));
3621 __ Push(left, right, op);
3622
3623 // Call the miss handler. This also pops the arguments.
3624 __ CallExternalReference(miss, 3);
3625
3626 // Compute the entry point of the rewritten stub.
3627 __ Add(stub_entry, x0, Code::kHeaderSize - kHeapObjectTag);
3628 // Restore caller-saved registers.
3629 __ Pop(lr, x0, x1);
3630 }
3631
3632 // Tail-call to the new stub.
3633 __ Jump(stub_entry);
3634}
3635
3636
3637void SubStringStub::Generate(MacroAssembler* masm) {
3638 ASM_LOCATION("SubStringStub::Generate");
3639 Label runtime;
3640
3641 // Stack frame on entry.
3642 // lr: return address
3643 // jssp[0]: substring "to" offset
3644 // jssp[8]: substring "from" offset
3645 // jssp[16]: pointer to string object
3646
3647 // This stub is called from the native-call %_SubString(...), so
3648 // nothing can be assumed about the arguments. It is tested that:
3649 // "string" is a sequential string,
3650 // both "from" and "to" are smis, and
3651 // 0 <= from <= to <= string.length (in debug mode.)
3652 // If any of these assumptions fail, we call the runtime system.
3653
3654 static const int kToOffset = 0 * kPointerSize;
3655 static const int kFromOffset = 1 * kPointerSize;
3656 static const int kStringOffset = 2 * kPointerSize;
3657
3658 Register to = x0;
3659 Register from = x15;
3660 Register input_string = x10;
3661 Register input_length = x11;
3662 Register input_type = x12;
3663 Register result_string = x0;
3664 Register result_length = x1;
3665 Register temp = x3;
3666
3667 __ Peek(to, kToOffset);
3668 __ Peek(from, kFromOffset);
3669
3670 // Check that both from and to are smis. If not, jump to runtime.
3671 __ JumpIfEitherNotSmi(from, to, &runtime);
3672 __ SmiUntag(from);
3673 __ SmiUntag(to);
3674
3675 // Calculate difference between from and to. If to < from, branch to runtime.
3676 __ Subs(result_length, to, from);
3677 __ B(mi, &runtime);
3678
3679 // Check from is positive.
3680 __ Tbnz(from, kWSignBit, &runtime);
3681
3682 // Make sure first argument is a string.
3683 __ Peek(input_string, kStringOffset);
3684 __ JumpIfSmi(input_string, &runtime);
3685 __ IsObjectJSStringType(input_string, input_type, &runtime);
3686
3687 Label single_char;
3688 __ Cmp(result_length, 1);
3689 __ B(eq, &single_char);
3690
3691 // Short-cut for the case of trivial substring.
3692 Label return_x0;
3693 __ Ldrsw(input_length,
3694 UntagSmiFieldMemOperand(input_string, String::kLengthOffset));
3695
3696 __ Cmp(result_length, input_length);
3697 __ CmovX(x0, input_string, eq);
3698 // Return original string.
3699 __ B(eq, &return_x0);
3700
3701 // Longer than original string's length or negative: unsafe arguments.
3702 __ B(hi, &runtime);
3703
3704 // Shorter than original string's length: an actual substring.
3705
3706 // x0 to substring end character offset
3707 // x1 result_length length of substring result
3708 // x10 input_string pointer to input string object
3709 // x10 unpacked_string pointer to unpacked string object
3710 // x11 input_length length of input string
3711 // x12 input_type instance type of input string
3712 // x15 from substring start character offset
3713
3714 // Deal with different string types: update the index if necessary and put
3715 // the underlying string into register unpacked_string.
3716 Label underlying_unpacked, sliced_string, seq_or_external_string;
3717 Label update_instance_type;
3718 // If the string is not indirect, it can only be sequential or external.
3719 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3720 STATIC_ASSERT(kIsIndirectStringMask != 0);
3721
3722 // Test for string types, and branch/fall through to appropriate unpacking
3723 // code.
3724 __ Tst(input_type, kIsIndirectStringMask);
3725 __ B(eq, &seq_or_external_string);
3726 __ Tst(input_type, kSlicedNotConsMask);
3727 __ B(ne, &sliced_string);
3728
3729 Register unpacked_string = input_string;
3730
3731 // Cons string. Check whether it is flat, then fetch first part.
3732 __ Ldr(temp, FieldMemOperand(input_string, ConsString::kSecondOffset));
3733 __ JumpIfNotRoot(temp, Heap::kempty_stringRootIndex, &runtime);
3734 __ Ldr(unpacked_string,
3735 FieldMemOperand(input_string, ConsString::kFirstOffset));
3736 __ B(&update_instance_type);
3737
3738 __ Bind(&sliced_string);
3739 // Sliced string. Fetch parent and correct start index by offset.
3740 __ Ldrsw(temp,
3741 UntagSmiFieldMemOperand(input_string, SlicedString::kOffsetOffset));
3742 __ Add(from, from, temp);
3743 __ Ldr(unpacked_string,
3744 FieldMemOperand(input_string, SlicedString::kParentOffset));
3745
3746 __ Bind(&update_instance_type);
3747 __ Ldr(temp, FieldMemOperand(unpacked_string, HeapObject::kMapOffset));
3748 __ Ldrb(input_type, FieldMemOperand(temp, Map::kInstanceTypeOffset));
3749 // Now control must go to &underlying_unpacked. Since the no code is generated
3750 // before then we fall through instead of generating a useless branch.
3751
3752 __ Bind(&seq_or_external_string);
3753 // Sequential or external string. Registers unpacked_string and input_string
3754 // alias, so there's nothing to do here.
3755 // Note that if code is added here, the above code must be updated.
3756
3757 // x0 result_string pointer to result string object (uninit)
3758 // x1 result_length length of substring result
3759 // x10 unpacked_string pointer to unpacked string object
3760 // x11 input_length length of input string
3761 // x12 input_type instance type of input string
3762 // x15 from substring start character offset
3763 __ Bind(&underlying_unpacked);
3764
3765 if (FLAG_string_slices) {
3766 Label copy_routine;
3767 __ Cmp(result_length, SlicedString::kMinLength);
3768 // Short slice. Copy instead of slicing.
3769 __ B(lt, &copy_routine);
3770 // Allocate new sliced string. At this point we do not reload the instance
3771 // type including the string encoding because we simply rely on the info
3772 // provided by the original string. It does not matter if the original
3773 // string's encoding is wrong because we always have to recheck encoding of
3774 // the newly created string's parent anyway due to externalized strings.
3775 Label two_byte_slice, set_slice_header;
3776 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3777 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3778 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_slice);
3779 __ AllocateOneByteSlicedString(result_string, result_length, x3, x4,
3780 &runtime);
3781 __ B(&set_slice_header);
3782
3783 __ Bind(&two_byte_slice);
3784 __ AllocateTwoByteSlicedString(result_string, result_length, x3, x4,
3785 &runtime);
3786
3787 __ Bind(&set_slice_header);
3788 __ SmiTag(from);
3789 __ Str(from, FieldMemOperand(result_string, SlicedString::kOffsetOffset));
3790 __ Str(unpacked_string,
3791 FieldMemOperand(result_string, SlicedString::kParentOffset));
3792 __ B(&return_x0);
3793
3794 __ Bind(&copy_routine);
3795 }
3796
3797 // x0 result_string pointer to result string object (uninit)
3798 // x1 result_length length of substring result
3799 // x10 unpacked_string pointer to unpacked string object
3800 // x11 input_length length of input string
3801 // x12 input_type instance type of input string
3802 // x13 unpacked_char0 pointer to first char of unpacked string (uninit)
3803 // x13 substring_char0 pointer to first char of substring (uninit)
3804 // x14 result_char0 pointer to first char of result (uninit)
3805 // x15 from substring start character offset
3806 Register unpacked_char0 = x13;
3807 Register substring_char0 = x13;
3808 Register result_char0 = x14;
3809 Label two_byte_sequential, sequential_string, allocate_result;
3810 STATIC_ASSERT(kExternalStringTag != 0);
3811 STATIC_ASSERT(kSeqStringTag == 0);
3812
3813 __ Tst(input_type, kExternalStringTag);
3814 __ B(eq, &sequential_string);
3815
3816 __ Tst(input_type, kShortExternalStringTag);
3817 __ B(ne, &runtime);
3818 __ Ldr(unpacked_char0,
3819 FieldMemOperand(unpacked_string, ExternalString::kResourceDataOffset));
3820 // unpacked_char0 points to the first character of the underlying string.
3821 __ B(&allocate_result);
3822
3823 __ Bind(&sequential_string);
3824 // Locate first character of underlying subject string.
3825 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3826 __ Add(unpacked_char0, unpacked_string,
3827 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3828
3829 __ Bind(&allocate_result);
3830 // Sequential one-byte string. Allocate the result.
3831 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3832 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_sequential);
3833
3834 // Allocate and copy the resulting one-byte string.
3835 __ AllocateOneByteString(result_string, result_length, x3, x4, x5, &runtime);
3836
3837 // Locate first character of substring to copy.
3838 __ Add(substring_char0, unpacked_char0, from);
3839
3840 // Locate first character of result.
3841 __ Add(result_char0, result_string,
3842 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3843
3844 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3845 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3846 __ B(&return_x0);
3847
3848 // Allocate and copy the resulting two-byte string.
3849 __ Bind(&two_byte_sequential);
3850 __ AllocateTwoByteString(result_string, result_length, x3, x4, x5, &runtime);
3851
3852 // Locate first character of substring to copy.
3853 __ Add(substring_char0, unpacked_char0, Operand(from, LSL, 1));
3854
3855 // Locate first character of result.
3856 __ Add(result_char0, result_string,
3857 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
3858
3859 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3860 __ Add(result_length, result_length, result_length);
3861 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3862
3863 __ Bind(&return_x0);
3864 Counters* counters = isolate()->counters();
3865 __ IncrementCounter(counters->sub_string_native(), 1, x3, x4);
3866 __ Drop(3);
3867 __ Ret();
3868
3869 __ Bind(&runtime);
3870 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3871
3872 __ bind(&single_char);
3873 // x1: result_length
3874 // x10: input_string
3875 // x12: input_type
3876 // x15: from (untagged)
3877 __ SmiTag(from);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003878 StringCharAtGenerator generator(input_string, from, result_length, x0,
3879 &runtime, &runtime, &runtime,
3880 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003881 generator.GenerateFast(masm);
3882 __ Drop(3);
3883 __ Ret();
3884 generator.SkipSlow(masm, &runtime);
3885}
3886
3887
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003888void ToNumberStub::Generate(MacroAssembler* masm) {
3889 // The ToNumber stub takes one argument in x0.
3890 Label not_smi;
3891 __ JumpIfNotSmi(x0, &not_smi);
3892 __ Ret();
3893 __ Bind(&not_smi);
3894
3895 Label not_heap_number;
3896 __ Ldr(x1, FieldMemOperand(x0, HeapObject::kMapOffset));
3897 __ Ldrb(x1, FieldMemOperand(x1, Map::kInstanceTypeOffset));
3898 // x0: object
3899 // x1: instance type
3900 __ Cmp(x1, HEAP_NUMBER_TYPE);
3901 __ B(ne, &not_heap_number);
3902 __ Ret();
3903 __ Bind(&not_heap_number);
3904
3905 Label not_string, slow_string;
3906 __ Cmp(x1, FIRST_NONSTRING_TYPE);
3907 __ B(hs, &not_string);
3908 // Check if string has a cached array index.
3909 __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset));
3910 __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask));
3911 __ B(ne, &slow_string);
3912 __ IndexFromHash(x2, x0);
3913 __ Ret();
3914 __ Bind(&slow_string);
3915 __ Push(x0); // Push argument.
3916 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3917 __ Bind(&not_string);
3918
3919 Label not_oddball;
3920 __ Cmp(x1, ODDBALL_TYPE);
3921 __ B(ne, &not_oddball);
3922 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
3923 __ Ret();
3924 __ Bind(&not_oddball);
3925
3926 __ Push(x0); // Push argument.
3927 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3928}
3929
3930
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003931void StringHelper::GenerateFlatOneByteStringEquals(
3932 MacroAssembler* masm, Register left, Register right, Register scratch1,
3933 Register scratch2, Register scratch3) {
3934 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3));
3935 Register result = x0;
3936 Register left_length = scratch1;
3937 Register right_length = scratch2;
3938
3939 // Compare lengths. If lengths differ, strings can't be equal. Lengths are
3940 // smis, and don't need to be untagged.
3941 Label strings_not_equal, check_zero_length;
3942 __ Ldr(left_length, FieldMemOperand(left, String::kLengthOffset));
3943 __ Ldr(right_length, FieldMemOperand(right, String::kLengthOffset));
3944 __ Cmp(left_length, right_length);
3945 __ B(eq, &check_zero_length);
3946
3947 __ Bind(&strings_not_equal);
3948 __ Mov(result, Smi::FromInt(NOT_EQUAL));
3949 __ Ret();
3950
3951 // Check if the length is zero. If so, the strings must be equal (and empty.)
3952 Label compare_chars;
3953 __ Bind(&check_zero_length);
3954 STATIC_ASSERT(kSmiTag == 0);
3955 __ Cbnz(left_length, &compare_chars);
3956 __ Mov(result, Smi::FromInt(EQUAL));
3957 __ Ret();
3958
3959 // Compare characters. Falls through if all characters are equal.
3960 __ Bind(&compare_chars);
3961 GenerateOneByteCharsCompareLoop(masm, left, right, left_length, scratch2,
3962 scratch3, &strings_not_equal);
3963
3964 // Characters in strings are equal.
3965 __ Mov(result, Smi::FromInt(EQUAL));
3966 __ Ret();
3967}
3968
3969
3970void StringHelper::GenerateCompareFlatOneByteStrings(
3971 MacroAssembler* masm, Register left, Register right, Register scratch1,
3972 Register scratch2, Register scratch3, Register scratch4) {
3973 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3, scratch4));
3974 Label result_not_equal, compare_lengths;
3975
3976 // Find minimum length and length difference.
3977 Register length_delta = scratch3;
3978 __ Ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3979 __ Ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3980 __ Subs(length_delta, scratch1, scratch2);
3981
3982 Register min_length = scratch1;
3983 __ Csel(min_length, scratch2, scratch1, gt);
3984 __ Cbz(min_length, &compare_lengths);
3985
3986 // Compare loop.
3987 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3988 scratch4, &result_not_equal);
3989
3990 // Compare lengths - strings up to min-length are equal.
3991 __ Bind(&compare_lengths);
3992
3993 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3994
3995 // Use length_delta as result if it's zero.
3996 Register result = x0;
3997 __ Subs(result, length_delta, 0);
3998
3999 __ Bind(&result_not_equal);
4000 Register greater = x10;
4001 Register less = x11;
4002 __ Mov(greater, Smi::FromInt(GREATER));
4003 __ Mov(less, Smi::FromInt(LESS));
4004 __ CmovX(result, greater, gt);
4005 __ CmovX(result, less, lt);
4006 __ Ret();
4007}
4008
4009
4010void StringHelper::GenerateOneByteCharsCompareLoop(
4011 MacroAssembler* masm, Register left, Register right, Register length,
4012 Register scratch1, Register scratch2, Label* chars_not_equal) {
4013 DCHECK(!AreAliased(left, right, length, scratch1, scratch2));
4014
4015 // Change index to run from -length to -1 by adding length to string
4016 // start. This means that loop ends when index reaches zero, which
4017 // doesn't need an additional compare.
4018 __ SmiUntag(length);
4019 __ Add(scratch1, length, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4020 __ Add(left, left, scratch1);
4021 __ Add(right, right, scratch1);
4022
4023 Register index = length;
4024 __ Neg(index, length); // index = -length;
4025
4026 // Compare loop
4027 Label loop;
4028 __ Bind(&loop);
4029 __ Ldrb(scratch1, MemOperand(left, index));
4030 __ Ldrb(scratch2, MemOperand(right, index));
4031 __ Cmp(scratch1, scratch2);
4032 __ B(ne, chars_not_equal);
4033 __ Add(index, index, 1);
4034 __ Cbnz(index, &loop);
4035}
4036
4037
4038void StringCompareStub::Generate(MacroAssembler* masm) {
4039 Label runtime;
4040
4041 Counters* counters = isolate()->counters();
4042
4043 // Stack frame on entry.
4044 // sp[0]: right string
4045 // sp[8]: left string
4046 Register right = x10;
4047 Register left = x11;
4048 Register result = x0;
4049 __ Pop(right, left);
4050
4051 Label not_same;
4052 __ Subs(result, right, left);
4053 __ B(ne, &not_same);
4054 STATIC_ASSERT(EQUAL == 0);
4055 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4056 __ Ret();
4057
4058 __ Bind(&not_same);
4059
4060 // Check that both objects are sequential one-byte strings.
4061 __ JumpIfEitherIsNotSequentialOneByteStrings(left, right, x12, x13, &runtime);
4062
4063 // Compare flat one-byte strings natively. Remove arguments from stack first,
4064 // as this function will generate a return.
4065 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4066 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, x12, x13,
4067 x14, x15);
4068
4069 __ Bind(&runtime);
4070
4071 // Push arguments back on to the stack.
4072 // sp[0] = right string
4073 // sp[8] = left string.
4074 __ Push(left, right);
4075
4076 // Call the runtime.
4077 // Returns -1 (less), 0 (equal), or 1 (greater) tagged as a small integer.
4078 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
4079}
4080
4081
4082void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4083 // ----------- S t a t e -------------
4084 // -- x1 : left
4085 // -- x0 : right
4086 // -- lr : return address
4087 // -----------------------------------
4088
4089 // Load x2 with the allocation site. We stick an undefined dummy value here
4090 // and replace it with the real allocation site later when we instantiate this
4091 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
4092 __ LoadObject(x2, handle(isolate()->heap()->undefined_value()));
4093
4094 // Make sure that we actually patched the allocation site.
4095 if (FLAG_debug_code) {
4096 __ AssertNotSmi(x2, kExpectedAllocationSite);
4097 __ Ldr(x10, FieldMemOperand(x2, HeapObject::kMapOffset));
4098 __ AssertRegisterIsRoot(x10, Heap::kAllocationSiteMapRootIndex,
4099 kExpectedAllocationSite);
4100 }
4101
4102 // Tail call into the stub that handles binary operations with allocation
4103 // sites.
4104 BinaryOpWithAllocationSiteStub stub(isolate(), state());
4105 __ TailCallStub(&stub);
4106}
4107
4108
4109void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4110 // We need some extra registers for this stub, they have been allocated
4111 // but we need to save them before using them.
4112 regs_.Save(masm);
4113
4114 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4115 Label dont_need_remembered_set;
4116
4117 Register val = regs_.scratch0();
4118 __ Ldr(val, MemOperand(regs_.address()));
4119 __ JumpIfNotInNewSpace(val, &dont_need_remembered_set);
4120
4121 __ CheckPageFlagSet(regs_.object(), val, 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4122 &dont_need_remembered_set);
4123
4124 // First notify the incremental marker if necessary, then update the
4125 // remembered set.
4126 CheckNeedsToInformIncrementalMarker(
4127 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4128 InformIncrementalMarker(masm);
4129 regs_.Restore(masm); // Restore the extra scratch registers we used.
4130
4131 __ RememberedSetHelper(object(), address(),
4132 value(), // scratch1
4133 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4134
4135 __ Bind(&dont_need_remembered_set);
4136 }
4137
4138 CheckNeedsToInformIncrementalMarker(
4139 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4140 InformIncrementalMarker(masm);
4141 regs_.Restore(masm); // Restore the extra scratch registers we used.
4142 __ Ret();
4143}
4144
4145
4146void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4147 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4148 Register address =
4149 x0.Is(regs_.address()) ? regs_.scratch0() : regs_.address();
4150 DCHECK(!address.Is(regs_.object()));
4151 DCHECK(!address.Is(x0));
4152 __ Mov(address, regs_.address());
4153 __ Mov(x0, regs_.object());
4154 __ Mov(x1, address);
4155 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4156
4157 AllowExternalCallThatCantCauseGC scope(masm);
4158 ExternalReference function =
4159 ExternalReference::incremental_marking_record_write_function(
4160 isolate());
4161 __ CallCFunction(function, 3, 0);
4162
4163 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4164}
4165
4166
4167void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4168 MacroAssembler* masm,
4169 OnNoNeedToInformIncrementalMarker on_no_need,
4170 Mode mode) {
4171 Label on_black;
4172 Label need_incremental;
4173 Label need_incremental_pop_scratch;
4174
4175 Register mem_chunk = regs_.scratch0();
4176 Register counter = regs_.scratch1();
4177 __ Bic(mem_chunk, regs_.object(), Page::kPageAlignmentMask);
4178 __ Ldr(counter,
4179 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4180 __ Subs(counter, counter, 1);
4181 __ Str(counter,
4182 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4183 __ B(mi, &need_incremental);
4184
4185 // If the object is not black we don't have to inform the incremental marker.
4186 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4187
4188 regs_.Restore(masm); // Restore the extra scratch registers we used.
4189 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4190 __ RememberedSetHelper(object(), address(),
4191 value(), // scratch1
4192 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4193 } else {
4194 __ Ret();
4195 }
4196
4197 __ Bind(&on_black);
4198 // Get the value from the slot.
4199 Register val = regs_.scratch0();
4200 __ Ldr(val, MemOperand(regs_.address()));
4201
4202 if (mode == INCREMENTAL_COMPACTION) {
4203 Label ensure_not_white;
4204
4205 __ CheckPageFlagClear(val, regs_.scratch1(),
4206 MemoryChunk::kEvacuationCandidateMask,
4207 &ensure_not_white);
4208
4209 __ CheckPageFlagClear(regs_.object(),
4210 regs_.scratch1(),
4211 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4212 &need_incremental);
4213
4214 __ Bind(&ensure_not_white);
4215 }
4216
4217 // We need extra registers for this, so we push the object and the address
4218 // register temporarily.
4219 __ Push(regs_.address(), regs_.object());
4220 __ EnsureNotWhite(val,
4221 regs_.scratch1(), // Scratch.
4222 regs_.object(), // Scratch.
4223 regs_.address(), // Scratch.
4224 regs_.scratch2(), // Scratch.
4225 &need_incremental_pop_scratch);
4226 __ Pop(regs_.object(), regs_.address());
4227
4228 regs_.Restore(masm); // Restore the extra scratch registers we used.
4229 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4230 __ RememberedSetHelper(object(), address(),
4231 value(), // scratch1
4232 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4233 } else {
4234 __ Ret();
4235 }
4236
4237 __ Bind(&need_incremental_pop_scratch);
4238 __ Pop(regs_.object(), regs_.address());
4239
4240 __ Bind(&need_incremental);
4241 // Fall through when we need to inform the incremental marker.
4242}
4243
4244
4245void RecordWriteStub::Generate(MacroAssembler* masm) {
4246 Label skip_to_incremental_noncompacting;
4247 Label skip_to_incremental_compacting;
4248
4249 // We patch these two first instructions back and forth between a nop and
4250 // real branch when we start and stop incremental heap marking.
4251 // Initially the stub is expected to be in STORE_BUFFER_ONLY mode, so 2 nops
4252 // are generated.
4253 // See RecordWriteStub::Patch for details.
4254 {
4255 InstructionAccurateScope scope(masm, 2);
4256 __ adr(xzr, &skip_to_incremental_noncompacting);
4257 __ adr(xzr, &skip_to_incremental_compacting);
4258 }
4259
4260 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4261 __ RememberedSetHelper(object(), address(),
4262 value(), // scratch1
4263 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4264 }
4265 __ Ret();
4266
4267 __ Bind(&skip_to_incremental_noncompacting);
4268 GenerateIncremental(masm, INCREMENTAL);
4269
4270 __ Bind(&skip_to_incremental_compacting);
4271 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4272}
4273
4274
4275void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4276 // x0 value element value to store
4277 // x3 index_smi element index as smi
4278 // sp[0] array_index_smi array literal index in function as smi
4279 // sp[1] array array literal
4280
4281 Register value = x0;
4282 Register index_smi = x3;
4283
4284 Register array = x1;
4285 Register array_map = x2;
4286 Register array_index_smi = x4;
4287 __ PeekPair(array_index_smi, array, 0);
4288 __ Ldr(array_map, FieldMemOperand(array, JSObject::kMapOffset));
4289
4290 Label double_elements, smi_element, fast_elements, slow_elements;
4291 Register bitfield2 = x10;
4292 __ Ldrb(bitfield2, FieldMemOperand(array_map, Map::kBitField2Offset));
4293
4294 // Jump if array's ElementsKind is not FAST*_SMI_ELEMENTS, FAST_ELEMENTS or
4295 // FAST_HOLEY_ELEMENTS.
4296 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4297 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4298 STATIC_ASSERT(FAST_ELEMENTS == 2);
4299 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4300 __ Cmp(bitfield2, Map::kMaximumBitField2FastHoleyElementValue);
4301 __ B(hi, &double_elements);
4302
4303 __ JumpIfSmi(value, &smi_element);
4304
4305 // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS.
4306 __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::ElementsKindBits::kShift),
4307 &fast_elements);
4308
4309 // Store into the array literal requires an elements transition. Call into
4310 // the runtime.
4311 __ Bind(&slow_elements);
4312 __ Push(array, index_smi, value);
4313 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4314 __ Ldr(x11, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
4315 __ Push(x11, array_index_smi);
4316 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4317
4318 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4319 __ Bind(&fast_elements);
4320 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4321 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4322 __ Add(x11, x11, FixedArray::kHeaderSize - kHeapObjectTag);
4323 __ Str(value, MemOperand(x11));
4324 // Update the write barrier for the array store.
4325 __ RecordWrite(x10, x11, value, kLRHasNotBeenSaved, kDontSaveFPRegs,
4326 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4327 __ Ret();
4328
4329 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4330 // and value is Smi.
4331 __ Bind(&smi_element);
4332 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4333 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4334 __ Str(value, FieldMemOperand(x11, FixedArray::kHeaderSize));
4335 __ Ret();
4336
4337 __ Bind(&double_elements);
4338 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4339 __ StoreNumberToDoubleElements(value, index_smi, x10, x11, d0,
4340 &slow_elements);
4341 __ Ret();
4342}
4343
4344
4345void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4346 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4347 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4348 int parameter_count_offset =
4349 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4350 __ Ldr(x1, MemOperand(fp, parameter_count_offset));
4351 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4352 __ Add(x1, x1, 1);
4353 }
4354 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4355 __ Drop(x1);
4356 // Return to IC Miss stub, continuation still on stack.
4357 __ Ret();
4358}
4359
4360
4361void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4362 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister());
4363 VectorLoadStub stub(isolate(), state());
4364 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4365}
4366
4367
4368void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4369 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister());
4370 VectorKeyedLoadStub stub(isolate());
4371 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4372}
4373
4374
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004375// The entry hook is a "BumpSystemStackPointer" instruction (sub), followed by
4376// a "Push lr" instruction, followed by a call.
4377static const unsigned int kProfileEntryHookCallSize =
4378 Assembler::kCallSizeWithRelocation + (2 * kInstructionSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004379
4380
4381void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4382 if (masm->isolate()->function_entry_hook() != NULL) {
4383 ProfileEntryHookStub stub(masm->isolate());
4384 Assembler::BlockConstPoolScope no_const_pools(masm);
4385 DontEmitDebugCodeScope no_debug_code(masm);
4386 Label entry_hook_call_start;
4387 __ Bind(&entry_hook_call_start);
4388 __ Push(lr);
4389 __ CallStub(&stub);
4390 DCHECK(masm->SizeOfCodeGeneratedSince(&entry_hook_call_start) ==
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004391 kProfileEntryHookCallSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004392
4393 __ Pop(lr);
4394 }
4395}
4396
4397
4398void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4399 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
4400
4401 // Save all kCallerSaved registers (including lr), since this can be called
4402 // from anywhere.
4403 // TODO(jbramley): What about FP registers?
4404 __ PushCPURegList(kCallerSaved);
4405 DCHECK(kCallerSaved.IncludesAliasOf(lr));
4406 const int kNumSavedRegs = kCallerSaved.Count();
4407
4408 // Compute the function's address as the first argument.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004409 __ Sub(x0, lr, kProfileEntryHookCallSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004410
4411#if V8_HOST_ARCH_ARM64
4412 uintptr_t entry_hook =
4413 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
4414 __ Mov(x10, entry_hook);
4415#else
4416 // Under the simulator we need to indirect the entry hook through a trampoline
4417 // function at a known address.
4418 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4419 __ Mov(x10, Operand(ExternalReference(&dispatcher,
4420 ExternalReference::BUILTIN_CALL,
4421 isolate())));
4422 // It additionally takes an isolate as a third parameter
4423 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4424#endif
4425
4426 // The caller's return address is above the saved temporaries.
4427 // Grab its location for the second argument to the hook.
4428 __ Add(x1, __ StackPointer(), kNumSavedRegs * kPointerSize);
4429
4430 {
4431 // Create a dummy frame, as CallCFunction requires this.
4432 FrameScope frame(masm, StackFrame::MANUAL);
4433 __ CallCFunction(x10, 2, 0);
4434 }
4435
4436 __ PopCPURegList(kCallerSaved);
4437 __ Ret();
4438}
4439
4440
4441void DirectCEntryStub::Generate(MacroAssembler* masm) {
4442 // When calling into C++ code the stack pointer must be csp.
4443 // Therefore this code must use csp for peek/poke operations when the
4444 // stub is generated. When the stub is called
4445 // (via DirectCEntryStub::GenerateCall), the caller must setup an ExitFrame
4446 // and configure the stack pointer *before* doing the call.
4447 const Register old_stack_pointer = __ StackPointer();
4448 __ SetStackPointer(csp);
4449
4450 // Put return address on the stack (accessible to GC through exit frame pc).
4451 __ Poke(lr, 0);
4452 // Call the C++ function.
4453 __ Blr(x10);
4454 // Return to calling code.
4455 __ Peek(lr, 0);
4456 __ AssertFPCRState();
4457 __ Ret();
4458
4459 __ SetStackPointer(old_stack_pointer);
4460}
4461
4462void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4463 Register target) {
4464 // Make sure the caller configured the stack pointer (see comment in
4465 // DirectCEntryStub::Generate).
4466 DCHECK(csp.Is(__ StackPointer()));
4467
4468 intptr_t code =
4469 reinterpret_cast<intptr_t>(GetCode().location());
4470 __ Mov(lr, Operand(code, RelocInfo::CODE_TARGET));
4471 __ Mov(x10, target);
4472 // Branch to the stub.
4473 __ Blr(lr);
4474}
4475
4476
4477// Probe the name dictionary in the 'elements' register.
4478// Jump to the 'done' label if a property with the given name is found.
4479// Jump to the 'miss' label otherwise.
4480//
4481// If lookup was successful 'scratch2' will be equal to elements + 4 * index.
4482// 'elements' and 'name' registers are preserved on miss.
4483void NameDictionaryLookupStub::GeneratePositiveLookup(
4484 MacroAssembler* masm,
4485 Label* miss,
4486 Label* done,
4487 Register elements,
4488 Register name,
4489 Register scratch1,
4490 Register scratch2) {
4491 DCHECK(!AreAliased(elements, name, scratch1, scratch2));
4492
4493 // Assert that name contains a string.
4494 __ AssertName(name);
4495
4496 // Compute the capacity mask.
4497 __ Ldrsw(scratch1, UntagSmiFieldMemOperand(elements, kCapacityOffset));
4498 __ Sub(scratch1, scratch1, 1);
4499
4500 // Generate an unrolled loop that performs a few probes before giving up.
4501 for (int i = 0; i < kInlinedProbes; i++) {
4502 // Compute the masked index: (hash + i + i * i) & mask.
4503 __ Ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4504 if (i > 0) {
4505 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4506 // the hash in a separate instruction. The value hash + i + i * i is right
4507 // shifted in the following and instruction.
4508 DCHECK(NameDictionary::GetProbeOffset(i) <
4509 1 << (32 - Name::kHashFieldOffset));
4510 __ Add(scratch2, scratch2, Operand(
4511 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4512 }
4513 __ And(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
4514
4515 // Scale the index by multiplying by the element size.
4516 DCHECK(NameDictionary::kEntrySize == 3);
4517 __ Add(scratch2, scratch2, Operand(scratch2, LSL, 1));
4518
4519 // Check if the key is identical to the name.
4520 UseScratchRegisterScope temps(masm);
4521 Register scratch3 = temps.AcquireX();
4522 __ Add(scratch2, elements, Operand(scratch2, LSL, kPointerSizeLog2));
4523 __ Ldr(scratch3, FieldMemOperand(scratch2, kElementsStartOffset));
4524 __ Cmp(name, scratch3);
4525 __ B(eq, done);
4526 }
4527
4528 // The inlined probes didn't find the entry.
4529 // Call the complete stub to scan the whole dictionary.
4530
4531 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4532 spill_list.Combine(lr);
4533 spill_list.Remove(scratch1);
4534 spill_list.Remove(scratch2);
4535
4536 __ PushCPURegList(spill_list);
4537
4538 if (name.is(x0)) {
4539 DCHECK(!elements.is(x1));
4540 __ Mov(x1, name);
4541 __ Mov(x0, elements);
4542 } else {
4543 __ Mov(x0, elements);
4544 __ Mov(x1, name);
4545 }
4546
4547 Label not_found;
4548 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4549 __ CallStub(&stub);
4550 __ Cbz(x0, &not_found);
4551 __ Mov(scratch2, x2); // Move entry index into scratch2.
4552 __ PopCPURegList(spill_list);
4553 __ B(done);
4554
4555 __ Bind(&not_found);
4556 __ PopCPURegList(spill_list);
4557 __ B(miss);
4558}
4559
4560
4561void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4562 Label* miss,
4563 Label* done,
4564 Register receiver,
4565 Register properties,
4566 Handle<Name> name,
4567 Register scratch0) {
4568 DCHECK(!AreAliased(receiver, properties, scratch0));
4569 DCHECK(name->IsUniqueName());
4570 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4571 // not equal to the name and kProbes-th slot is not used (its name is the
4572 // undefined value), it guarantees the hash table doesn't contain the
4573 // property. It's true even if some slots represent deleted properties
4574 // (their names are the hole value).
4575 for (int i = 0; i < kInlinedProbes; i++) {
4576 // scratch0 points to properties hash.
4577 // Compute the masked index: (hash + i + i * i) & mask.
4578 Register index = scratch0;
4579 // Capacity is smi 2^n.
4580 __ Ldrsw(index, UntagSmiFieldMemOperand(properties, kCapacityOffset));
4581 __ Sub(index, index, 1);
4582 __ And(index, index, name->Hash() + NameDictionary::GetProbeOffset(i));
4583
4584 // Scale the index by multiplying by the entry size.
4585 DCHECK(NameDictionary::kEntrySize == 3);
4586 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
4587
4588 Register entity_name = scratch0;
4589 // Having undefined at this place means the name is not contained.
4590 Register tmp = index;
4591 __ Add(tmp, properties, Operand(index, LSL, kPointerSizeLog2));
4592 __ Ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4593
4594 __ JumpIfRoot(entity_name, Heap::kUndefinedValueRootIndex, done);
4595
4596 // Stop if found the property.
4597 __ Cmp(entity_name, Operand(name));
4598 __ B(eq, miss);
4599
4600 Label good;
4601 __ JumpIfRoot(entity_name, Heap::kTheHoleValueRootIndex, &good);
4602
4603 // Check if the entry name is not a unique name.
4604 __ Ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4605 __ Ldrb(entity_name,
4606 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4607 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4608 __ Bind(&good);
4609 }
4610
4611 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4612 spill_list.Combine(lr);
4613 spill_list.Remove(scratch0); // Scratch registers don't need to be preserved.
4614
4615 __ PushCPURegList(spill_list);
4616
4617 __ Ldr(x0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4618 __ Mov(x1, Operand(name));
4619 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4620 __ CallStub(&stub);
4621 // Move stub return value to scratch0. Note that scratch0 is not included in
4622 // spill_list and won't be clobbered by PopCPURegList.
4623 __ Mov(scratch0, x0);
4624 __ PopCPURegList(spill_list);
4625
4626 __ Cbz(scratch0, done);
4627 __ B(miss);
4628}
4629
4630
4631void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4632 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4633 // we cannot call anything that could cause a GC from this stub.
4634 //
4635 // Arguments are in x0 and x1:
4636 // x0: property dictionary.
4637 // x1: the name of the property we are looking for.
4638 //
4639 // Return value is in x0 and is zero if lookup failed, non zero otherwise.
4640 // If the lookup is successful, x2 will contains the index of the entry.
4641
4642 Register result = x0;
4643 Register dictionary = x0;
4644 Register key = x1;
4645 Register index = x2;
4646 Register mask = x3;
4647 Register hash = x4;
4648 Register undefined = x5;
4649 Register entry_key = x6;
4650
4651 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4652
4653 __ Ldrsw(mask, UntagSmiFieldMemOperand(dictionary, kCapacityOffset));
4654 __ Sub(mask, mask, 1);
4655
4656 __ Ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4657 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4658
4659 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4660 // Compute the masked index: (hash + i + i * i) & mask.
4661 // Capacity is smi 2^n.
4662 if (i > 0) {
4663 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4664 // the hash in a separate instruction. The value hash + i + i * i is right
4665 // shifted in the following and instruction.
4666 DCHECK(NameDictionary::GetProbeOffset(i) <
4667 1 << (32 - Name::kHashFieldOffset));
4668 __ Add(index, hash,
4669 NameDictionary::GetProbeOffset(i) << Name::kHashShift);
4670 } else {
4671 __ Mov(index, hash);
4672 }
4673 __ And(index, mask, Operand(index, LSR, Name::kHashShift));
4674
4675 // Scale the index by multiplying by the entry size.
4676 DCHECK(NameDictionary::kEntrySize == 3);
4677 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
4678
4679 __ Add(index, dictionary, Operand(index, LSL, kPointerSizeLog2));
4680 __ Ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
4681
4682 // Having undefined at this place means the name is not contained.
4683 __ Cmp(entry_key, undefined);
4684 __ B(eq, &not_in_dictionary);
4685
4686 // Stop if found the property.
4687 __ Cmp(entry_key, key);
4688 __ B(eq, &in_dictionary);
4689
4690 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4691 // Check if the entry name is not a unique name.
4692 __ Ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4693 __ Ldrb(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4694 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4695 }
4696 }
4697
4698 __ Bind(&maybe_in_dictionary);
4699 // If we are doing negative lookup then probing failure should be
4700 // treated as a lookup success. For positive lookup, probing failure
4701 // should be treated as lookup failure.
4702 if (mode() == POSITIVE_LOOKUP) {
4703 __ Mov(result, 0);
4704 __ Ret();
4705 }
4706
4707 __ Bind(&in_dictionary);
4708 __ Mov(result, 1);
4709 __ Ret();
4710
4711 __ Bind(&not_in_dictionary);
4712 __ Mov(result, 0);
4713 __ Ret();
4714}
4715
4716
4717template<class T>
4718static void CreateArrayDispatch(MacroAssembler* masm,
4719 AllocationSiteOverrideMode mode) {
4720 ASM_LOCATION("CreateArrayDispatch");
4721 if (mode == DISABLE_ALLOCATION_SITES) {
4722 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4723 __ TailCallStub(&stub);
4724
4725 } else if (mode == DONT_OVERRIDE) {
4726 Register kind = x3;
4727 int last_index =
4728 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
4729 for (int i = 0; i <= last_index; ++i) {
4730 Label next;
4731 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
4732 // TODO(jbramley): Is this the best way to handle this? Can we make the
4733 // tail calls conditional, rather than hopping over each one?
4734 __ CompareAndBranch(kind, candidate_kind, ne, &next);
4735 T stub(masm->isolate(), candidate_kind);
4736 __ TailCallStub(&stub);
4737 __ Bind(&next);
4738 }
4739
4740 // If we reached this point there is a problem.
4741 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4742
4743 } else {
4744 UNREACHABLE();
4745 }
4746}
4747
4748
4749// TODO(jbramley): If this needs to be a special case, make it a proper template
4750// specialization, and not a separate function.
4751static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4752 AllocationSiteOverrideMode mode) {
4753 ASM_LOCATION("CreateArrayDispatchOneArgument");
4754 // x0 - argc
4755 // x1 - constructor?
4756 // x2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4757 // x3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4758 // sp[0] - last argument
4759
4760 Register allocation_site = x2;
4761 Register kind = x3;
4762
4763 Label normal_sequence;
4764 if (mode == DONT_OVERRIDE) {
4765 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4766 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4767 STATIC_ASSERT(FAST_ELEMENTS == 2);
4768 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4769 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4770 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4771
4772 // Is the low bit set? If so, the array is holey.
4773 __ Tbnz(kind, 0, &normal_sequence);
4774 }
4775
4776 // Look at the last argument.
4777 // TODO(jbramley): What does a 0 argument represent?
4778 __ Peek(x10, 0);
4779 __ Cbz(x10, &normal_sequence);
4780
4781 if (mode == DISABLE_ALLOCATION_SITES) {
4782 ElementsKind initial = GetInitialFastElementsKind();
4783 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4784
4785 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4786 holey_initial,
4787 DISABLE_ALLOCATION_SITES);
4788 __ TailCallStub(&stub_holey);
4789
4790 __ Bind(&normal_sequence);
4791 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4792 initial,
4793 DISABLE_ALLOCATION_SITES);
4794 __ TailCallStub(&stub);
4795 } else if (mode == DONT_OVERRIDE) {
4796 // We are going to create a holey array, but our kind is non-holey.
4797 // Fix kind and retry (only if we have an allocation site in the slot).
4798 __ Orr(kind, kind, 1);
4799
4800 if (FLAG_debug_code) {
4801 __ Ldr(x10, FieldMemOperand(allocation_site, 0));
4802 __ JumpIfNotRoot(x10, Heap::kAllocationSiteMapRootIndex,
4803 &normal_sequence);
4804 __ Assert(eq, kExpectedAllocationSite);
4805 }
4806
4807 // Save the resulting elements kind in type info. We can't just store 'kind'
4808 // in the AllocationSite::transition_info field because elements kind is
4809 // restricted to a portion of the field; upper bits need to be left alone.
4810 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4811 __ Ldr(x11, FieldMemOperand(allocation_site,
4812 AllocationSite::kTransitionInfoOffset));
4813 __ Add(x11, x11, Smi::FromInt(kFastElementsKindPackedToHoley));
4814 __ Str(x11, FieldMemOperand(allocation_site,
4815 AllocationSite::kTransitionInfoOffset));
4816
4817 __ Bind(&normal_sequence);
4818 int last_index =
4819 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
4820 for (int i = 0; i <= last_index; ++i) {
4821 Label next;
4822 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
4823 __ CompareAndBranch(kind, candidate_kind, ne, &next);
4824 ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind);
4825 __ TailCallStub(&stub);
4826 __ Bind(&next);
4827 }
4828
4829 // If we reached this point there is a problem.
4830 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4831 } else {
4832 UNREACHABLE();
4833 }
4834}
4835
4836
4837template<class T>
4838static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4839 int to_index = GetSequenceIndexFromFastElementsKind(
4840 TERMINAL_FAST_ELEMENTS_KIND);
4841 for (int i = 0; i <= to_index; ++i) {
4842 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4843 T stub(isolate, kind);
4844 stub.GetCode();
4845 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4846 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4847 stub1.GetCode();
4848 }
4849 }
4850}
4851
4852
4853void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4854 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4855 isolate);
4856 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4857 isolate);
4858 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4859 isolate);
4860}
4861
4862
4863void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4864 Isolate* isolate) {
4865 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4866 for (int i = 0; i < 2; i++) {
4867 // For internal arrays we only need a few things
4868 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4869 stubh1.GetCode();
4870 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4871 stubh2.GetCode();
4872 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4873 stubh3.GetCode();
4874 }
4875}
4876
4877
4878void ArrayConstructorStub::GenerateDispatchToArrayStub(
4879 MacroAssembler* masm,
4880 AllocationSiteOverrideMode mode) {
4881 Register argc = x0;
4882 if (argument_count() == ANY) {
4883 Label zero_case, n_case;
4884 __ Cbz(argc, &zero_case);
4885 __ Cmp(argc, 1);
4886 __ B(ne, &n_case);
4887
4888 // One argument.
4889 CreateArrayDispatchOneArgument(masm, mode);
4890
4891 __ Bind(&zero_case);
4892 // No arguments.
4893 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4894
4895 __ Bind(&n_case);
4896 // N arguments.
4897 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4898
4899 } else if (argument_count() == NONE) {
4900 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4901 } else if (argument_count() == ONE) {
4902 CreateArrayDispatchOneArgument(masm, mode);
4903 } else if (argument_count() == MORE_THAN_ONE) {
4904 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4905 } else {
4906 UNREACHABLE();
4907 }
4908}
4909
4910
4911void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4912 ASM_LOCATION("ArrayConstructorStub::Generate");
4913 // ----------- S t a t e -------------
4914 // -- x0 : argc (only if argument_count() == ANY)
4915 // -- x1 : constructor
4916 // -- x2 : AllocationSite or undefined
4917 // -- sp[0] : return address
4918 // -- sp[4] : last argument
4919 // -----------------------------------
4920 Register constructor = x1;
4921 Register allocation_site = x2;
4922
4923 if (FLAG_debug_code) {
4924 // The array construct code is only set for the global and natives
4925 // builtin Array functions which always have maps.
4926
4927 Label unexpected_map, map_ok;
4928 // Initial map for the builtin Array function should be a map.
4929 __ Ldr(x10, FieldMemOperand(constructor,
4930 JSFunction::kPrototypeOrInitialMapOffset));
4931 // Will both indicate a NULL and a Smi.
4932 __ JumpIfSmi(x10, &unexpected_map);
4933 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
4934 __ Bind(&unexpected_map);
4935 __ Abort(kUnexpectedInitialMapForArrayFunction);
4936 __ Bind(&map_ok);
4937
4938 // We should either have undefined in the allocation_site register or a
4939 // valid AllocationSite.
4940 __ AssertUndefinedOrAllocationSite(allocation_site, x10);
4941 }
4942
4943 Register kind = x3;
4944 Label no_info;
4945 // Get the elements kind and case on that.
4946 __ JumpIfRoot(allocation_site, Heap::kUndefinedValueRootIndex, &no_info);
4947
4948 __ Ldrsw(kind,
4949 UntagSmiFieldMemOperand(allocation_site,
4950 AllocationSite::kTransitionInfoOffset));
4951 __ And(kind, kind, AllocationSite::ElementsKindBits::kMask);
4952 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4953
4954 __ Bind(&no_info);
4955 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4956}
4957
4958
4959void InternalArrayConstructorStub::GenerateCase(
4960 MacroAssembler* masm, ElementsKind kind) {
4961 Label zero_case, n_case;
4962 Register argc = x0;
4963
4964 __ Cbz(argc, &zero_case);
4965 __ CompareAndBranch(argc, 1, ne, &n_case);
4966
4967 // One argument.
4968 if (IsFastPackedElementsKind(kind)) {
4969 Label packed_case;
4970
4971 // We might need to create a holey array; look at the first argument.
4972 __ Peek(x10, 0);
4973 __ Cbz(x10, &packed_case);
4974
4975 InternalArraySingleArgumentConstructorStub
4976 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4977 __ TailCallStub(&stub1_holey);
4978
4979 __ Bind(&packed_case);
4980 }
4981 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4982 __ TailCallStub(&stub1);
4983
4984 __ Bind(&zero_case);
4985 // No arguments.
4986 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4987 __ TailCallStub(&stub0);
4988
4989 __ Bind(&n_case);
4990 // N arguments.
4991 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4992 __ TailCallStub(&stubN);
4993}
4994
4995
4996void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4997 // ----------- S t a t e -------------
4998 // -- x0 : argc
4999 // -- x1 : constructor
5000 // -- sp[0] : return address
5001 // -- sp[4] : last argument
5002 // -----------------------------------
5003
5004 Register constructor = x1;
5005
5006 if (FLAG_debug_code) {
5007 // The array construct code is only set for the global and natives
5008 // builtin Array functions which always have maps.
5009
5010 Label unexpected_map, map_ok;
5011 // Initial map for the builtin Array function should be a map.
5012 __ Ldr(x10, FieldMemOperand(constructor,
5013 JSFunction::kPrototypeOrInitialMapOffset));
5014 // Will both indicate a NULL and a Smi.
5015 __ JumpIfSmi(x10, &unexpected_map);
5016 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5017 __ Bind(&unexpected_map);
5018 __ Abort(kUnexpectedInitialMapForArrayFunction);
5019 __ Bind(&map_ok);
5020 }
5021
5022 Register kind = w3;
5023 // Figure out the right elements kind
5024 __ Ldr(x10, FieldMemOperand(constructor,
5025 JSFunction::kPrototypeOrInitialMapOffset));
5026
5027 // Retrieve elements_kind from map.
5028 __ LoadElementsKindFromMap(kind, x10);
5029
5030 if (FLAG_debug_code) {
5031 Label done;
5032 __ Cmp(x3, FAST_ELEMENTS);
5033 __ Ccmp(x3, FAST_HOLEY_ELEMENTS, ZFlag, ne);
5034 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5035 }
5036
5037 Label fast_elements_case;
5038 __ CompareAndBranch(kind, FAST_ELEMENTS, eq, &fast_elements_case);
5039 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5040
5041 __ Bind(&fast_elements_case);
5042 GenerateCase(masm, FAST_ELEMENTS);
5043}
5044
5045
5046void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5047 // ----------- S t a t e -------------
5048 // -- x0 : callee
5049 // -- x4 : call_data
5050 // -- x2 : holder
5051 // -- x1 : api_function_address
5052 // -- cp : context
5053 // --
5054 // -- sp[0] : last argument
5055 // -- ...
5056 // -- sp[(argc - 1) * 8] : first argument
5057 // -- sp[argc * 8] : receiver
5058 // -----------------------------------
5059
5060 Register callee = x0;
5061 Register call_data = x4;
5062 Register holder = x2;
5063 Register api_function_address = x1;
5064 Register context = cp;
5065
5066 int argc = this->argc();
5067 bool is_store = this->is_store();
5068 bool call_data_undefined = this->call_data_undefined();
5069
5070 typedef FunctionCallbackArguments FCA;
5071
5072 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5073 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5074 STATIC_ASSERT(FCA::kDataIndex == 4);
5075 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5076 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5077 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5078 STATIC_ASSERT(FCA::kHolderIndex == 0);
5079 STATIC_ASSERT(FCA::kArgsLength == 7);
5080
5081 // FunctionCallbackArguments: context, callee and call data.
5082 __ Push(context, callee, call_data);
5083
5084 // Load context from callee
5085 __ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5086
5087 if (!call_data_undefined) {
5088 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
5089 }
5090 Register isolate_reg = x5;
5091 __ Mov(isolate_reg, ExternalReference::isolate_address(isolate()));
5092
5093 // FunctionCallbackArguments:
5094 // return value, return value default, isolate, holder.
5095 __ Push(call_data, call_data, isolate_reg, holder);
5096
5097 // Prepare arguments.
5098 Register args = x6;
5099 __ Mov(args, masm->StackPointer());
5100
5101 // Allocate the v8::Arguments structure in the arguments' space, since it's
5102 // not controlled by GC.
5103 const int kApiStackSpace = 4;
5104
5105 // Allocate space for CallApiFunctionAndReturn can store some scratch
5106 // registeres on the stack.
5107 const int kCallApiFunctionSpillSpace = 4;
5108
5109 FrameScope frame_scope(masm, StackFrame::MANUAL);
5110 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5111
5112 DCHECK(!AreAliased(x0, api_function_address));
5113 // x0 = FunctionCallbackInfo&
5114 // Arguments is after the return address.
5115 __ Add(x0, masm->StackPointer(), 1 * kPointerSize);
5116 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5117 __ Add(x10, args, Operand((FCA::kArgsLength - 1 + argc) * kPointerSize));
5118 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5119 // FunctionCallbackInfo::length_ = argc and
5120 // FunctionCallbackInfo::is_construct_call = 0
5121 __ Mov(x10, argc);
5122 __ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize));
5123
5124 const int kStackUnwindSpace = argc + FCA::kArgsLength + 1;
5125 ExternalReference thunk_ref =
5126 ExternalReference::invoke_function_callback(isolate());
5127
5128 AllowExternalCallThatCantCauseGC scope(masm);
5129 MemOperand context_restore_operand(
5130 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5131 // Stores return the first js argument
5132 int return_value_offset = 0;
5133 if (is_store) {
5134 return_value_offset = 2 + FCA::kArgsLength;
5135 } else {
5136 return_value_offset = 2 + FCA::kReturnValueOffset;
5137 }
5138 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5139
5140 const int spill_offset = 1 + kApiStackSpace;
5141 __ CallApiFunctionAndReturn(api_function_address,
5142 thunk_ref,
5143 kStackUnwindSpace,
5144 spill_offset,
5145 return_value_operand,
5146 &context_restore_operand);
5147}
5148
5149
5150void CallApiGetterStub::Generate(MacroAssembler* masm) {
5151 // ----------- S t a t e -------------
5152 // -- sp[0] : name
5153 // -- sp[8 - kArgsLength*8] : PropertyCallbackArguments object
5154 // -- ...
5155 // -- x2 : api_function_address
5156 // -----------------------------------
5157
5158 Register api_function_address = ApiGetterDescriptor::function_address();
5159 DCHECK(api_function_address.is(x2));
5160
5161 __ Mov(x0, masm->StackPointer()); // x0 = Handle<Name>
5162 __ Add(x1, x0, 1 * kPointerSize); // x1 = PCA
5163
5164 const int kApiStackSpace = 1;
5165
5166 // Allocate space for CallApiFunctionAndReturn can store some scratch
5167 // registeres on the stack.
5168 const int kCallApiFunctionSpillSpace = 4;
5169
5170 FrameScope frame_scope(masm, StackFrame::MANUAL);
5171 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5172
5173 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5174 // x1 (internal::Object** args_) as the data.
5175 __ Poke(x1, 1 * kPointerSize);
5176 __ Add(x1, masm->StackPointer(), 1 * kPointerSize); // x1 = AccessorInfo&
5177
5178 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5179
5180 ExternalReference thunk_ref =
5181 ExternalReference::invoke_accessor_getter_callback(isolate());
5182
5183 const int spill_offset = 1 + kApiStackSpace;
5184 __ CallApiFunctionAndReturn(api_function_address,
5185 thunk_ref,
5186 kStackUnwindSpace,
5187 spill_offset,
5188 MemOperand(fp, 6 * kPointerSize),
5189 NULL);
5190}
5191
5192
5193#undef __
5194
5195} } // namespace v8::internal
5196
5197#endif // V8_TARGET_ARCH_ARM64