blob: ad566e68fc207308be3523b1e3915bc482a1758f [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
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_ARM64
6
7#include "src/bootstrapper.h"
8#include "src/code-stubs.h"
9#include "src/codegen.h"
10#include "src/ic/handler-compiler.h"
11#include "src/ic/ic.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/ic/stub-cache.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000014#include "src/regexp/jsregexp.h"
15#include "src/regexp/regexp-macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040016#include "src/runtime/runtime.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000017
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018#include "src/arm64/code-stubs-arm64.h"
19#include "src/arm64/frames-arm64.h"
20
Ben Murdochb8a8cc12014-11-26 15:28:44 +000021namespace v8 {
22namespace internal {
23
24
25static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
28 // cp: context
29 // x1: function
30 // x2: allocation site with elements kind
31 // x0: number of arguments to the constructor function
32 Address deopt_handler = Runtime::FunctionForId(
33 Runtime::kArrayConstructor)->entry;
34
35 if (constant_stack_parameter_count == 0) {
36 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
37 JS_FUNCTION_STUB_MODE);
38 } else {
39 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000040 JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000041 }
42}
43
44
45void ArrayNoArgumentConstructorStub::InitializeDescriptor(
46 CodeStubDescriptor* descriptor) {
47 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
48}
49
50
51void ArraySingleArgumentConstructorStub::InitializeDescriptor(
52 CodeStubDescriptor* descriptor) {
53 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
54}
55
56
57void ArrayNArgumentsConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
60}
61
62
63static void InitializeInternalArrayConstructorDescriptor(
64 Isolate* isolate, CodeStubDescriptor* descriptor,
65 int constant_stack_parameter_count) {
66 Address deopt_handler = Runtime::FunctionForId(
67 Runtime::kInternalArrayConstructor)->entry;
68
69 if (constant_stack_parameter_count == 0) {
70 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
71 JS_FUNCTION_STUB_MODE);
72 } else {
73 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000074 JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075 }
76}
77
78
79void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
80 CodeStubDescriptor* descriptor) {
81 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
82}
83
84
85void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
86 CodeStubDescriptor* descriptor) {
87 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
88}
89
90
91void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
92 CodeStubDescriptor* descriptor) {
93 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
94}
95
96
97#define __ ACCESS_MASM(masm)
98
99
100void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
101 ExternalReference miss) {
102 // Update the static counter each time a new code stub is generated.
103 isolate()->counters()->code_stubs()->Increment();
104
105 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000106 int param_count = descriptor.GetRegisterParameterCount();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 {
108 // Call the runtime system in a fresh internal frame.
109 FrameScope scope(masm, StackFrame::INTERNAL);
110 DCHECK((param_count == 0) ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 x0.Is(descriptor.GetRegisterParameter(param_count - 1)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000112
113 // Push arguments
114 MacroAssembler::PushPopQueue queue(masm);
115 for (int i = 0; i < param_count; ++i) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000116 queue.Queue(descriptor.GetRegisterParameter(i));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000117 }
118 queue.PushQueued();
119
120 __ CallExternalReference(miss, param_count);
121 }
122
123 __ Ret();
124}
125
126
127void DoubleToIStub::Generate(MacroAssembler* masm) {
128 Label done;
129 Register input = source();
130 Register result = destination();
131 DCHECK(is_truncating());
132
133 DCHECK(result.Is64Bits());
134 DCHECK(jssp.Is(masm->StackPointer()));
135
136 int double_offset = offset();
137
138 DoubleRegister double_scratch = d0; // only used if !skip_fastpath()
139 Register scratch1 = GetAllocatableRegisterThatIsNotOneOf(input, result);
140 Register scratch2 =
141 GetAllocatableRegisterThatIsNotOneOf(input, result, scratch1);
142
143 __ Push(scratch1, scratch2);
144 // Account for saved regs if input is jssp.
145 if (input.is(jssp)) double_offset += 2 * kPointerSize;
146
147 if (!skip_fastpath()) {
148 __ Push(double_scratch);
149 if (input.is(jssp)) double_offset += 1 * kDoubleSize;
150 __ Ldr(double_scratch, MemOperand(input, double_offset));
151 // Try to convert with a FPU convert instruction. This handles all
152 // non-saturating cases.
153 __ TryConvertDoubleToInt64(result, double_scratch, &done);
154 __ Fmov(result, double_scratch);
155 } else {
156 __ Ldr(result, MemOperand(input, double_offset));
157 }
158
159 // If we reach here we need to manually convert the input to an int32.
160
161 // Extract the exponent.
162 Register exponent = scratch1;
163 __ Ubfx(exponent, result, HeapNumber::kMantissaBits,
164 HeapNumber::kExponentBits);
165
166 // It the exponent is >= 84 (kMantissaBits + 32), the result is always 0 since
167 // the mantissa gets shifted completely out of the int32_t result.
168 __ Cmp(exponent, HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 32);
169 __ CzeroX(result, ge);
170 __ B(ge, &done);
171
172 // The Fcvtzs sequence handles all cases except where the conversion causes
173 // signed overflow in the int64_t target. Since we've already handled
174 // exponents >= 84, we can guarantee that 63 <= exponent < 84.
175
176 if (masm->emit_debug_code()) {
177 __ Cmp(exponent, HeapNumber::kExponentBias + 63);
178 // Exponents less than this should have been handled by the Fcvt case.
179 __ Check(ge, kUnexpectedValue);
180 }
181
182 // Isolate the mantissa bits, and set the implicit '1'.
183 Register mantissa = scratch2;
184 __ Ubfx(mantissa, result, 0, HeapNumber::kMantissaBits);
185 __ Orr(mantissa, mantissa, 1UL << HeapNumber::kMantissaBits);
186
187 // Negate the mantissa if necessary.
188 __ Tst(result, kXSignMask);
189 __ Cneg(mantissa, mantissa, ne);
190
191 // Shift the mantissa bits in the correct place. We know that we have to shift
192 // it left here, because exponent >= 63 >= kMantissaBits.
193 __ Sub(exponent, exponent,
194 HeapNumber::kExponentBias + HeapNumber::kMantissaBits);
195 __ Lsl(result, mantissa, exponent);
196
197 __ Bind(&done);
198 if (!skip_fastpath()) {
199 __ Pop(double_scratch);
200 }
201 __ Pop(scratch2, scratch1);
202 __ Ret();
203}
204
205
206// See call site for description.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000207static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
208 Register right, Register scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000209 FPRegister double_scratch,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100210 Label* slow, Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000211 DCHECK(!AreAliased(left, right, scratch));
212 Label not_identical, return_equal, heap_number;
213 Register result = x0;
214
215 __ Cmp(right, left);
216 __ B(ne, &not_identical);
217
218 // Test for NaN. Sadly, we can't just compare to factory::nan_value(),
219 // so we do the second best thing - test it ourselves.
220 // They are both equal and they are not both Smis so both of them are not
221 // Smis. If it's not a heap number, then return equal.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000222 Register right_type = scratch;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000223 if ((cond == lt) || (cond == gt)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000224 // Call runtime on identical JSObjects. Otherwise return equal.
225 __ JumpIfObjectType(right, right_type, right_type, FIRST_JS_RECEIVER_TYPE,
226 slow, ge);
227 // Call runtime on identical symbols since we need to throw a TypeError.
228 __ Cmp(right_type, SYMBOL_TYPE);
229 __ B(eq, slow);
230 // Call runtime on identical SIMD values since we must throw a TypeError.
231 __ Cmp(right_type, SIMD128_VALUE_TYPE);
232 __ B(eq, slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000233 } else if (cond == eq) {
234 __ JumpIfHeapNumber(right, &heap_number);
235 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000236 __ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE,
237 &heap_number);
238 // Comparing JS objects with <=, >= is complicated.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000239 __ Cmp(right_type, FIRST_JS_RECEIVER_TYPE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000240 __ B(ge, slow);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000241 // Call runtime on identical symbols since we need to throw a TypeError.
242 __ Cmp(right_type, SYMBOL_TYPE);
243 __ B(eq, slow);
244 // Call runtime on identical SIMD values since we must throw a TypeError.
245 __ Cmp(right_type, SIMD128_VALUE_TYPE);
246 __ B(eq, slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000247 // Normally here we fall through to return_equal, but undefined is
248 // special: (undefined == undefined) == true, but
249 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
250 if ((cond == le) || (cond == ge)) {
251 __ Cmp(right_type, ODDBALL_TYPE);
252 __ B(ne, &return_equal);
253 __ JumpIfNotRoot(right, Heap::kUndefinedValueRootIndex, &return_equal);
254 if (cond == le) {
255 // undefined <= undefined should fail.
256 __ Mov(result, GREATER);
257 } else {
258 // undefined >= undefined should fail.
259 __ Mov(result, LESS);
260 }
261 __ Ret();
262 }
263 }
264
265 __ Bind(&return_equal);
266 if (cond == lt) {
267 __ Mov(result, GREATER); // Things aren't less than themselves.
268 } else if (cond == gt) {
269 __ Mov(result, LESS); // Things aren't greater than themselves.
270 } else {
271 __ Mov(result, EQUAL); // Things are <=, >=, ==, === themselves.
272 }
273 __ Ret();
274
275 // Cases lt and gt have been handled earlier, and case ne is never seen, as
276 // it is handled in the parser (see Parser::ParseBinaryExpression). We are
277 // only concerned with cases ge, le and eq here.
278 if ((cond != lt) && (cond != gt)) {
279 DCHECK((cond == ge) || (cond == le) || (cond == eq));
280 __ Bind(&heap_number);
281 // Left and right are identical pointers to a heap number object. Return
282 // non-equal if the heap number is a NaN, and equal otherwise. Comparing
283 // the number to itself will set the overflow flag iff the number is NaN.
284 __ Ldr(double_scratch, FieldMemOperand(right, HeapNumber::kValueOffset));
285 __ Fcmp(double_scratch, double_scratch);
286 __ B(vc, &return_equal); // Not NaN, so treat as normal heap number.
287
288 if (cond == le) {
289 __ Mov(result, GREATER);
290 } else {
291 __ Mov(result, LESS);
292 }
293 __ Ret();
294 }
295
296 // No fall through here.
297 if (FLAG_debug_code) {
298 __ Unreachable();
299 }
300
301 __ Bind(&not_identical);
302}
303
304
305// See call site for description.
306static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
307 Register left,
308 Register right,
309 Register left_type,
310 Register right_type,
311 Register scratch) {
312 DCHECK(!AreAliased(left, right, left_type, right_type, scratch));
313
314 if (masm->emit_debug_code()) {
315 // We assume that the arguments are not identical.
316 __ Cmp(left, right);
317 __ Assert(ne, kExpectedNonIdenticalObjects);
318 }
319
320 // If either operand is a JS object or an oddball value, then they are not
321 // equal since their pointers are different.
322 // There is no test for undetectability in strict equality.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000323 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000324 Label right_non_object;
325
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000326 __ Cmp(right_type, FIRST_JS_RECEIVER_TYPE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000327 __ B(lt, &right_non_object);
328
329 // Return non-zero - x0 already contains a non-zero pointer.
330 DCHECK(left.is(x0) || right.is(x0));
331 Label return_not_equal;
332 __ Bind(&return_not_equal);
333 __ Ret();
334
335 __ Bind(&right_non_object);
336
337 // Check for oddballs: true, false, null, undefined.
338 __ Cmp(right_type, ODDBALL_TYPE);
339
340 // If right is not ODDBALL, test left. Otherwise, set eq condition.
341 __ Ccmp(left_type, ODDBALL_TYPE, ZFlag, ne);
342
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000343 // If right or left is not ODDBALL, test left >= FIRST_JS_RECEIVER_TYPE.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000344 // Otherwise, right or left is ODDBALL, so set a ge condition.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000345 __ Ccmp(left_type, FIRST_JS_RECEIVER_TYPE, NVFlag, ne);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000346
347 __ B(ge, &return_not_equal);
348
349 // Internalized strings are unique, so they can only be equal if they are the
350 // same object. We have already tested that case, so if left and right are
351 // both internalized strings, they cannot be equal.
352 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
353 __ Orr(scratch, left_type, right_type);
354 __ TestAndBranchIfAllClear(
355 scratch, kIsNotStringMask | kIsNotInternalizedMask, &return_not_equal);
356}
357
358
359// See call site for description.
360static void EmitSmiNonsmiComparison(MacroAssembler* masm,
361 Register left,
362 Register right,
363 FPRegister left_d,
364 FPRegister right_d,
365 Label* slow,
366 bool strict) {
367 DCHECK(!AreAliased(left_d, right_d));
368 DCHECK((left.is(x0) && right.is(x1)) ||
369 (right.is(x0) && left.is(x1)));
370 Register result = x0;
371
372 Label right_is_smi, done;
373 __ JumpIfSmi(right, &right_is_smi);
374
375 // Left is the smi. Check whether right is a heap number.
376 if (strict) {
377 // If right is not a number and left is a smi, then strict equality cannot
378 // succeed. Return non-equal.
379 Label is_heap_number;
380 __ JumpIfHeapNumber(right, &is_heap_number);
381 // Register right is a non-zero pointer, which is a valid NOT_EQUAL result.
382 if (!right.is(result)) {
383 __ Mov(result, NOT_EQUAL);
384 }
385 __ Ret();
386 __ Bind(&is_heap_number);
387 } else {
388 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
389 // runtime.
390 __ JumpIfNotHeapNumber(right, slow);
391 }
392
393 // Left is the smi. Right is a heap number. Load right value into right_d, and
394 // convert left smi into double in left_d.
395 __ Ldr(right_d, FieldMemOperand(right, HeapNumber::kValueOffset));
396 __ SmiUntagToDouble(left_d, left);
397 __ B(&done);
398
399 __ Bind(&right_is_smi);
400 // Right is a smi. Check whether the non-smi left is a heap number.
401 if (strict) {
402 // If left is not a number and right is a smi then strict equality cannot
403 // succeed. Return non-equal.
404 Label is_heap_number;
405 __ JumpIfHeapNumber(left, &is_heap_number);
406 // Register left is a non-zero pointer, which is a valid NOT_EQUAL result.
407 if (!left.is(result)) {
408 __ Mov(result, NOT_EQUAL);
409 }
410 __ Ret();
411 __ Bind(&is_heap_number);
412 } else {
413 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
414 // runtime.
415 __ JumpIfNotHeapNumber(left, slow);
416 }
417
418 // Right is the smi. Left is a heap number. Load left value into left_d, and
419 // convert right smi into double in right_d.
420 __ Ldr(left_d, FieldMemOperand(left, HeapNumber::kValueOffset));
421 __ SmiUntagToDouble(right_d, right);
422
423 // Fall through to both_loaded_as_doubles.
424 __ Bind(&done);
425}
426
427
428// Fast negative check for internalized-to-internalized equality.
429// See call site for description.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100430static void EmitCheckForInternalizedStringsOrObjects(
431 MacroAssembler* masm, Register left, Register right, Register left_map,
432 Register right_map, Register left_type, Register right_type,
433 Label* possible_strings, Label* runtime_call) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000434 DCHECK(!AreAliased(left, right, left_map, right_map, left_type, right_type));
435 Register result = x0;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100436 DCHECK(left.is(x0) || right.is(x0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000437
Ben Murdoch097c5b22016-05-18 11:27:45 +0100438 Label object_test, return_unequal, undetectable;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000439 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
440 // TODO(all): reexamine this branch sequence for optimisation wrt branch
441 // prediction.
442 __ Tbnz(right_type, MaskToBit(kIsNotStringMask), &object_test);
443 __ Tbnz(right_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100444 __ Tbnz(left_type, MaskToBit(kIsNotStringMask), runtime_call);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000445 __ Tbnz(left_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
446
Ben Murdoch097c5b22016-05-18 11:27:45 +0100447 // Both are internalized. We already checked they weren't the same pointer so
448 // they are not equal. Return non-equal by returning the non-zero object
449 // pointer in x0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000450 __ Ret();
451
452 __ Bind(&object_test);
453
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000454 Register left_bitfield = left_type;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100455 Register right_bitfield = right_type;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000456 __ Ldrb(right_bitfield, FieldMemOperand(right_map, Map::kBitFieldOffset));
457 __ Ldrb(left_bitfield, FieldMemOperand(left_map, Map::kBitFieldOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100458 __ Tbnz(right_bitfield, MaskToBit(1 << Map::kIsUndetectable), &undetectable);
459 __ Tbnz(left_bitfield, MaskToBit(1 << Map::kIsUndetectable), &return_unequal);
460
461 __ CompareInstanceType(right_map, right_type, FIRST_JS_RECEIVER_TYPE);
462 __ B(lt, runtime_call);
463 __ CompareInstanceType(left_map, left_type, FIRST_JS_RECEIVER_TYPE);
464 __ B(lt, runtime_call);
465
466 __ bind(&return_unequal);
467 // Return non-equal by returning the non-zero object pointer in x0.
468 __ Ret();
469
470 __ bind(&undetectable);
471 __ Tbz(left_bitfield, MaskToBit(1 << Map::kIsUndetectable), &return_unequal);
472 __ Mov(result, EQUAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000473 __ Ret();
474}
475
476
477static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
478 CompareICState::State expected,
479 Label* fail) {
480 Label ok;
481 if (expected == CompareICState::SMI) {
482 __ JumpIfNotSmi(input, fail);
483 } else if (expected == CompareICState::NUMBER) {
484 __ JumpIfSmi(input, &ok);
485 __ JumpIfNotHeapNumber(input, fail);
486 }
487 // We could be strict about internalized/non-internalized here, but as long as
488 // hydrogen doesn't care, the stub doesn't have to care either.
489 __ Bind(&ok);
490}
491
492
493void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
494 Register lhs = x1;
495 Register rhs = x0;
496 Register result = x0;
497 Condition cond = GetCondition();
498
499 Label miss;
500 CompareICStub_CheckInputType(masm, lhs, left(), &miss);
501 CompareICStub_CheckInputType(masm, rhs, right(), &miss);
502
503 Label slow; // Call builtin.
504 Label not_smis, both_loaded_as_doubles;
505 Label not_two_smis, smi_done;
506 __ JumpIfEitherNotSmi(lhs, rhs, &not_two_smis);
507 __ SmiUntag(lhs);
508 __ Sub(result, lhs, Operand::UntagSmi(rhs));
509 __ Ret();
510
511 __ Bind(&not_two_smis);
512
513 // NOTICE! This code is only reached after a smi-fast-case check, so it is
514 // certain that at least one operand isn't a smi.
515
516 // Handle the case where the objects are identical. Either returns the answer
517 // or goes to slow. Only falls through if the objects were not identical.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100518 EmitIdenticalObjectComparison(masm, lhs, rhs, x10, d0, &slow, cond);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000519
520 // If either is a smi (we know that at least one is not a smi), then they can
521 // only be strictly equal if the other is a HeapNumber.
522 __ JumpIfBothNotSmi(lhs, rhs, &not_smis);
523
524 // Exactly one operand is a smi. EmitSmiNonsmiComparison generates code that
525 // can:
526 // 1) Return the answer.
527 // 2) Branch to the slow case.
528 // 3) Fall through to both_loaded_as_doubles.
529 // In case 3, we have found out that we were dealing with a number-number
530 // comparison. The double values of the numbers have been loaded, right into
531 // rhs_d, left into lhs_d.
532 FPRegister rhs_d = d0;
533 FPRegister lhs_d = d1;
534 EmitSmiNonsmiComparison(masm, lhs, rhs, lhs_d, rhs_d, &slow, strict());
535
536 __ Bind(&both_loaded_as_doubles);
537 // The arguments have been converted to doubles and stored in rhs_d and
538 // lhs_d.
539 Label nan;
540 __ Fcmp(lhs_d, rhs_d);
541 __ B(vs, &nan); // Overflow flag set if either is NaN.
542 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
543 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
544 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
545 __ Ret();
546
547 __ Bind(&nan);
548 // Left and/or right is a NaN. Load the result register with whatever makes
549 // the comparison fail, since comparisons with NaN always fail (except ne,
550 // which is filtered out at a higher level.)
551 DCHECK(cond != ne);
552 if ((cond == lt) || (cond == le)) {
553 __ Mov(result, GREATER);
554 } else {
555 __ Mov(result, LESS);
556 }
557 __ Ret();
558
559 __ Bind(&not_smis);
560 // At this point we know we are dealing with two different objects, and
561 // neither of them is a smi. The objects are in rhs_ and lhs_.
562
563 // Load the maps and types of the objects.
564 Register rhs_map = x10;
565 Register rhs_type = x11;
566 Register lhs_map = x12;
567 Register lhs_type = x13;
568 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
569 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
570 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
571 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
572
573 if (strict()) {
574 // This emits a non-equal return sequence for some object types, or falls
575 // through if it was not lucky.
576 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs, lhs_type, rhs_type, x14);
577 }
578
579 Label check_for_internalized_strings;
580 Label flat_string_check;
581 // Check for heap number comparison. Branch to earlier double comparison code
582 // if they are heap numbers, otherwise, branch to internalized string check.
583 __ Cmp(rhs_type, HEAP_NUMBER_TYPE);
584 __ B(ne, &check_for_internalized_strings);
585 __ Cmp(lhs_map, rhs_map);
586
587 // If maps aren't equal, lhs_ and rhs_ are not heap numbers. Branch to flat
588 // string check.
589 __ B(ne, &flat_string_check);
590
591 // Both lhs_ and rhs_ are heap numbers. Load them and branch to the double
592 // comparison code.
593 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
594 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
595 __ B(&both_loaded_as_doubles);
596
597 __ Bind(&check_for_internalized_strings);
598 // In the strict case, the EmitStrictTwoHeapObjectCompare already took care
599 // of internalized strings.
600 if ((cond == eq) && !strict()) {
601 // Returns an answer for two internalized strings or two detectable objects.
602 // Otherwise branches to the string case or not both strings case.
603 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, lhs_map, rhs_map,
604 lhs_type, rhs_type,
605 &flat_string_check, &slow);
606 }
607
608 // Check for both being sequential one-byte strings,
609 // and inline if that is the case.
610 __ Bind(&flat_string_check);
611 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x14,
612 x15, &slow);
613
614 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x10,
615 x11);
616 if (cond == eq) {
617 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
618 x12);
619 } else {
620 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
621 x12, x13);
622 }
623
624 // Never fall through to here.
625 if (FLAG_debug_code) {
626 __ Unreachable();
627 }
628
629 __ Bind(&slow);
630
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000631 if (cond == eq) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100632 {
633 FrameScope scope(masm, StackFrame::INTERNAL);
634 __ Push(lhs, rhs);
635 __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual);
636 }
637 // Turn true into 0 and false into some non-zero value.
638 STATIC_ASSERT(EQUAL == 0);
639 __ LoadRoot(x1, Heap::kTrueValueRootIndex);
640 __ Sub(x0, x0, x1);
641 __ Ret();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000642 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100643 __ Push(lhs, rhs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000644 int ncr; // NaN compare result
645 if ((cond == lt) || (cond == le)) {
646 ncr = GREATER;
647 } else {
648 DCHECK((cond == gt) || (cond == ge)); // remaining cases
649 ncr = LESS;
650 }
651 __ Mov(x10, Smi::FromInt(ncr));
652 __ Push(x10);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000653
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000654 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
655 // tagged as a small integer.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100656 __ TailCallRuntime(Runtime::kCompare);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000657 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000658
659 __ Bind(&miss);
660 GenerateMiss(masm);
661}
662
663
664void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
665 CPURegList saved_regs = kCallerSaved;
666 CPURegList saved_fp_regs = kCallerSavedFP;
667
668 // We don't allow a GC during a store buffer overflow so there is no need to
669 // store the registers in any particular way, but we do have to store and
670 // restore them.
671
672 // We don't care if MacroAssembler scratch registers are corrupted.
673 saved_regs.Remove(*(masm->TmpList()));
674 saved_fp_regs.Remove(*(masm->FPTmpList()));
675
676 __ PushCPURegList(saved_regs);
677 if (save_doubles()) {
678 __ PushCPURegList(saved_fp_regs);
679 }
680
681 AllowExternalCallThatCantCauseGC scope(masm);
682 __ Mov(x0, ExternalReference::isolate_address(isolate()));
683 __ CallCFunction(
684 ExternalReference::store_buffer_overflow_function(isolate()), 1, 0);
685
686 if (save_doubles()) {
687 __ PopCPURegList(saved_fp_regs);
688 }
689 __ PopCPURegList(saved_regs);
690 __ Ret();
691}
692
693
694void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
695 Isolate* isolate) {
696 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
697 stub1.GetCode();
698 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
699 stub2.GetCode();
700}
701
702
703void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
704 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
705 UseScratchRegisterScope temps(masm);
706 Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr());
707 Register return_address = temps.AcquireX();
708 __ Mov(return_address, lr);
709 // Restore lr with the value it had before the call to this stub (the value
710 // which must be pushed).
711 __ Mov(lr, saved_lr);
712 __ PushSafepointRegisters();
713 __ Ret(return_address);
714}
715
716
717void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
718 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
719 UseScratchRegisterScope temps(masm);
720 Register return_address = temps.AcquireX();
721 // Preserve the return address (lr will be clobbered by the pop).
722 __ Mov(return_address, lr);
723 __ PopSafepointRegisters();
724 __ Ret(return_address);
725}
726
727
728void MathPowStub::Generate(MacroAssembler* masm) {
729 // Stack on entry:
730 // jssp[0]: Exponent (as a tagged value).
731 // jssp[1]: Base (as a tagged value).
732 //
733 // The (tagged) result will be returned in x0, as a heap number.
734
735 Register result_tagged = x0;
736 Register base_tagged = x10;
737 Register exponent_tagged = MathPowTaggedDescriptor::exponent();
738 DCHECK(exponent_tagged.is(x11));
739 Register exponent_integer = MathPowIntegerDescriptor::exponent();
740 DCHECK(exponent_integer.is(x12));
741 Register scratch1 = x14;
742 Register scratch0 = x15;
743 Register saved_lr = x19;
744 FPRegister result_double = d0;
745 FPRegister base_double = d0;
746 FPRegister exponent_double = d1;
747 FPRegister base_double_copy = d2;
748 FPRegister scratch1_double = d6;
749 FPRegister scratch0_double = d7;
750
751 // A fast-path for integer exponents.
752 Label exponent_is_smi, exponent_is_integer;
753 // Bail out to runtime.
754 Label call_runtime;
755 // Allocate a heap number for the result, and return it.
756 Label done;
757
758 // Unpack the inputs.
759 if (exponent_type() == ON_STACK) {
760 Label base_is_smi;
761 Label unpack_exponent;
762
763 __ Pop(exponent_tagged, base_tagged);
764
765 __ JumpIfSmi(base_tagged, &base_is_smi);
766 __ JumpIfNotHeapNumber(base_tagged, &call_runtime);
767 // base_tagged is a heap number, so load its double value.
768 __ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset));
769 __ B(&unpack_exponent);
770 __ Bind(&base_is_smi);
771 // base_tagged is a SMI, so untag it and convert it to a double.
772 __ SmiUntagToDouble(base_double, base_tagged);
773
774 __ Bind(&unpack_exponent);
775 // x10 base_tagged The tagged base (input).
776 // x11 exponent_tagged The tagged exponent (input).
777 // d1 base_double The base as a double.
778 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
779 __ JumpIfNotHeapNumber(exponent_tagged, &call_runtime);
780 // exponent_tagged is a heap number, so load its double value.
781 __ Ldr(exponent_double,
782 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
783 } else if (exponent_type() == TAGGED) {
784 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
785 __ Ldr(exponent_double,
786 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
787 }
788
789 // Handle double (heap number) exponents.
790 if (exponent_type() != INTEGER) {
791 // Detect integer exponents stored as doubles and handle those in the
792 // integer fast-path.
793 __ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
794 scratch0_double, &exponent_is_integer);
795
796 if (exponent_type() == ON_STACK) {
797 FPRegister half_double = d3;
798 FPRegister minus_half_double = d4;
799 // Detect square root case. Crankshaft detects constant +/-0.5 at compile
800 // time and uses DoMathPowHalf instead. We then skip this check for
801 // non-constant cases of +/-0.5 as these hardly occur.
802
803 __ Fmov(minus_half_double, -0.5);
804 __ Fmov(half_double, 0.5);
805 __ Fcmp(minus_half_double, exponent_double);
806 __ Fccmp(half_double, exponent_double, NZFlag, ne);
807 // Condition flags at this point:
808 // 0.5; nZCv // Identified by eq && pl
809 // -0.5: NZcv // Identified by eq && mi
810 // other: ?z?? // Identified by ne
811 __ B(ne, &call_runtime);
812
813 // The exponent is 0.5 or -0.5.
814
815 // Given that exponent is known to be either 0.5 or -0.5, the following
816 // special cases could apply (according to ECMA-262 15.8.2.13):
817 //
818 // base.isNaN(): The result is NaN.
819 // (base == +INFINITY) || (base == -INFINITY)
820 // exponent == 0.5: The result is +INFINITY.
821 // exponent == -0.5: The result is +0.
822 // (base == +0) || (base == -0)
823 // exponent == 0.5: The result is +0.
824 // exponent == -0.5: The result is +INFINITY.
825 // (base < 0) && base.isFinite(): The result is NaN.
826 //
827 // Fsqrt (and Fdiv for the -0.5 case) can handle all of those except
828 // where base is -INFINITY or -0.
829
830 // Add +0 to base. This has no effect other than turning -0 into +0.
831 __ Fadd(base_double, base_double, fp_zero);
832 // The operation -0+0 results in +0 in all cases except where the
833 // FPCR rounding mode is 'round towards minus infinity' (RM). The
834 // ARM64 simulator does not currently simulate FPCR (where the rounding
835 // mode is set), so test the operation with some debug code.
836 if (masm->emit_debug_code()) {
837 UseScratchRegisterScope temps(masm);
838 Register temp = temps.AcquireX();
839 __ Fneg(scratch0_double, fp_zero);
840 // Verify that we correctly generated +0.0 and -0.0.
841 // bits(+0.0) = 0x0000000000000000
842 // bits(-0.0) = 0x8000000000000000
843 __ Fmov(temp, fp_zero);
844 __ CheckRegisterIsClear(temp, kCouldNotGenerateZero);
845 __ Fmov(temp, scratch0_double);
846 __ Eor(temp, temp, kDSignMask);
847 __ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero);
848 // Check that -0.0 + 0.0 == +0.0.
849 __ Fadd(scratch0_double, scratch0_double, fp_zero);
850 __ Fmov(temp, scratch0_double);
851 __ CheckRegisterIsClear(temp, kExpectedPositiveZero);
852 }
853
854 // If base is -INFINITY, make it +INFINITY.
855 // * Calculate base - base: All infinities will become NaNs since both
856 // -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64.
857 // * If the result is NaN, calculate abs(base).
858 __ Fsub(scratch0_double, base_double, base_double);
859 __ Fcmp(scratch0_double, 0.0);
860 __ Fabs(scratch1_double, base_double);
861 __ Fcsel(base_double, scratch1_double, base_double, vs);
862
863 // Calculate the square root of base.
864 __ Fsqrt(result_double, base_double);
865 __ Fcmp(exponent_double, 0.0);
866 __ B(ge, &done); // Finish now for exponents of 0.5.
867 // Find the inverse for exponents of -0.5.
868 __ Fmov(scratch0_double, 1.0);
869 __ Fdiv(result_double, scratch0_double, result_double);
870 __ B(&done);
871 }
872
873 {
874 AllowExternalCallThatCantCauseGC scope(masm);
875 __ Mov(saved_lr, lr);
876 __ CallCFunction(
877 ExternalReference::power_double_double_function(isolate()),
878 0, 2);
879 __ Mov(lr, saved_lr);
880 __ B(&done);
881 }
882
883 // Handle SMI exponents.
884 __ Bind(&exponent_is_smi);
885 // x10 base_tagged The tagged base (input).
886 // x11 exponent_tagged The tagged exponent (input).
887 // d1 base_double The base as a double.
888 __ SmiUntag(exponent_integer, exponent_tagged);
889 }
890
891 __ Bind(&exponent_is_integer);
892 // x10 base_tagged The tagged base (input).
893 // x11 exponent_tagged The tagged exponent (input).
894 // x12 exponent_integer The exponent as an integer.
895 // d1 base_double The base as a double.
896
897 // Find abs(exponent). For negative exponents, we can find the inverse later.
898 Register exponent_abs = x13;
899 __ Cmp(exponent_integer, 0);
900 __ Cneg(exponent_abs, exponent_integer, mi);
901 // x13 exponent_abs The value of abs(exponent_integer).
902
903 // Repeatedly multiply to calculate the power.
904 // result = 1.0;
905 // For each bit n (exponent_integer{n}) {
906 // if (exponent_integer{n}) {
907 // result *= base;
908 // }
909 // base *= base;
910 // if (remaining bits in exponent_integer are all zero) {
911 // break;
912 // }
913 // }
914 Label power_loop, power_loop_entry, power_loop_exit;
915 __ Fmov(scratch1_double, base_double);
916 __ Fmov(base_double_copy, base_double);
917 __ Fmov(result_double, 1.0);
918 __ B(&power_loop_entry);
919
920 __ Bind(&power_loop);
921 __ Fmul(scratch1_double, scratch1_double, scratch1_double);
922 __ Lsr(exponent_abs, exponent_abs, 1);
923 __ Cbz(exponent_abs, &power_loop_exit);
924
925 __ Bind(&power_loop_entry);
926 __ Tbz(exponent_abs, 0, &power_loop);
927 __ Fmul(result_double, result_double, scratch1_double);
928 __ B(&power_loop);
929
930 __ Bind(&power_loop_exit);
931
932 // If the exponent was positive, result_double holds the result.
933 __ Tbz(exponent_integer, kXSignBit, &done);
934
935 // The exponent was negative, so find the inverse.
936 __ Fmov(scratch0_double, 1.0);
937 __ Fdiv(result_double, scratch0_double, result_double);
938 // ECMA-262 only requires Math.pow to return an 'implementation-dependent
939 // approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
940 // to calculate the subnormal value 2^-1074. This method of calculating
941 // negative powers doesn't work because 2^1074 overflows to infinity. To
942 // catch this corner-case, we bail out if the result was 0. (This can only
943 // occur if the divisor is infinity or the base is zero.)
944 __ Fcmp(result_double, 0.0);
945 __ B(&done, ne);
946
947 if (exponent_type() == ON_STACK) {
948 // Bail out to runtime code.
949 __ Bind(&call_runtime);
950 // Put the arguments back on the stack.
951 __ Push(base_tagged, exponent_tagged);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000952 __ TailCallRuntime(Runtime::kMathPowRT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000953
954 // Return.
955 __ Bind(&done);
956 __ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1,
957 result_double);
958 DCHECK(result_tagged.is(x0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000959 __ Ret();
960 } else {
961 AllowExternalCallThatCantCauseGC scope(masm);
962 __ Mov(saved_lr, lr);
963 __ Fmov(base_double, base_double_copy);
964 __ Scvtf(exponent_double, exponent_integer);
965 __ CallCFunction(
966 ExternalReference::power_double_double_function(isolate()),
967 0, 2);
968 __ Mov(lr, saved_lr);
969 __ Bind(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000970 __ Ret();
971 }
972}
973
974
975void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
976 // It is important that the following stubs are generated in this order
977 // because pregenerated stubs can only call other pregenerated stubs.
978 // RecordWriteStub uses StoreBufferOverflowStub, which in turn uses
979 // CEntryStub.
980 CEntryStub::GenerateAheadOfTime(isolate);
981 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
982 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
983 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
984 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000985 CreateWeakCellStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000986 BinaryOpICStub::GenerateAheadOfTime(isolate);
987 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
988 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
989 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000990 StoreFastElementStub::GenerateAheadOfTime(isolate);
991 TypeofStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000992}
993
994
995void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
996 StoreRegistersStateStub stub(isolate);
997 stub.GetCode();
998}
999
1000
1001void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1002 RestoreRegistersStateStub stub(isolate);
1003 stub.GetCode();
1004}
1005
1006
1007void CodeStub::GenerateFPStubs(Isolate* isolate) {
1008 // Floating-point code doesn't get special handling in ARM64, so there's
1009 // nothing to do here.
1010 USE(isolate);
1011}
1012
1013
1014bool CEntryStub::NeedsImmovableCode() {
1015 // CEntryStub stores the return address on the stack before calling into
1016 // C++ code. In some cases, the VM accesses this address, but it is not used
1017 // when the C++ code returns to the stub because LR holds the return address
1018 // in AAPCS64. If the stub is moved (perhaps during a GC), we could end up
1019 // returning to dead code.
1020 // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't
1021 // find any comment to confirm this, and I don't hit any crashes whatever
1022 // this function returns. The anaylsis should be properly confirmed.
1023 return true;
1024}
1025
1026
1027void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1028 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1029 stub.GetCode();
1030 CEntryStub stub_fp(isolate, 1, kSaveFPRegs);
1031 stub_fp.GetCode();
1032}
1033
1034
1035void CEntryStub::Generate(MacroAssembler* masm) {
1036 // The Abort mechanism relies on CallRuntime, which in turn relies on
1037 // CEntryStub, so until this stub has been generated, we have to use a
1038 // fall-back Abort mechanism.
1039 //
1040 // Note that this stub must be generated before any use of Abort.
1041 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
1042
1043 ASM_LOCATION("CEntryStub::Generate entry");
1044 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1045
1046 // Register parameters:
1047 // x0: argc (including receiver, untagged)
1048 // x1: target
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001049 // If argv_in_register():
1050 // x11: argv (pointer to first argument)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001051 //
1052 // The stack on entry holds the arguments and the receiver, with the receiver
1053 // at the highest address:
1054 //
1055 // jssp]argc-1]: receiver
1056 // jssp[argc-2]: arg[argc-2]
1057 // ... ...
1058 // jssp[1]: arg[1]
1059 // jssp[0]: arg[0]
1060 //
1061 // The arguments are in reverse order, so that arg[argc-2] is actually the
1062 // first argument to the target function and arg[0] is the last.
1063 DCHECK(jssp.Is(__ StackPointer()));
1064 const Register& argc_input = x0;
1065 const Register& target_input = x1;
1066
1067 // Calculate argv, argc and the target address, and store them in
1068 // callee-saved registers so we can retry the call without having to reload
1069 // these arguments.
1070 // TODO(jbramley): If the first call attempt succeeds in the common case (as
1071 // it should), then we might be better off putting these parameters directly
1072 // into their argument registers, rather than using callee-saved registers and
1073 // preserving them on the stack.
1074 const Register& argv = x21;
1075 const Register& argc = x22;
1076 const Register& target = x23;
1077
1078 // Derive argv from the stack pointer so that it points to the first argument
1079 // (arg[argc-2]), or just below the receiver in case there are no arguments.
1080 // - Adjust for the arg[] array.
1081 Register temp_argv = x11;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001082 if (!argv_in_register()) {
1083 __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
1084 // - Adjust for the receiver.
1085 __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
1086 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001087
Ben Murdoch097c5b22016-05-18 11:27:45 +01001088 // Reserve three slots to preserve x21-x23 callee-saved registers. If the
1089 // result size is too large to be returned in registers then also reserve
1090 // space for the return value.
1091 int extra_stack_space = 3 + (result_size() <= 2 ? 0 : result_size());
1092 // Enter the exit frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001093 FrameScope scope(masm, StackFrame::MANUAL);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001094 __ EnterExitFrame(save_doubles(), x10, extra_stack_space);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001095 DCHECK(csp.Is(__ StackPointer()));
1096
1097 // Poke callee-saved registers into reserved space.
1098 __ Poke(argv, 1 * kPointerSize);
1099 __ Poke(argc, 2 * kPointerSize);
1100 __ Poke(target, 3 * kPointerSize);
1101
Ben Murdoch097c5b22016-05-18 11:27:45 +01001102 if (result_size() > 2) {
1103 // Save the location of the return value into x8 for call.
1104 __ Add(x8, __ StackPointer(), Operand(4 * kPointerSize));
1105 }
1106
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001107 // We normally only keep tagged values in callee-saved registers, as they
1108 // could be pushed onto the stack by called stubs and functions, and on the
1109 // stack they can confuse the GC. However, we're only calling C functions
1110 // which can push arbitrary data onto the stack anyway, and so the GC won't
1111 // examine that part of the stack.
1112 __ Mov(argc, argc_input);
1113 __ Mov(target, target_input);
1114 __ Mov(argv, temp_argv);
1115
1116 // x21 : argv
1117 // x22 : argc
1118 // x23 : call target
1119 //
1120 // The stack (on entry) holds the arguments and the receiver, with the
1121 // receiver at the highest address:
1122 //
1123 // argv[8]: receiver
1124 // argv -> argv[0]: arg[argc-2]
1125 // ... ...
1126 // argv[...]: arg[1]
1127 // argv[...]: arg[0]
1128 //
1129 // Immediately below (after) this is the exit frame, as constructed by
1130 // EnterExitFrame:
1131 // fp[8]: CallerPC (lr)
1132 // fp -> fp[0]: CallerFP (old fp)
1133 // fp[-8]: Space reserved for SPOffset.
1134 // fp[-16]: CodeObject()
1135 // csp[...]: Saved doubles, if saved_doubles is true.
1136 // csp[32]: Alignment padding, if necessary.
1137 // csp[24]: Preserved x23 (used for target).
1138 // csp[16]: Preserved x22 (used for argc).
1139 // csp[8]: Preserved x21 (used for argv).
1140 // csp -> csp[0]: Space reserved for the return address.
1141 //
1142 // After a successful call, the exit frame, preserved registers (x21-x23) and
1143 // the arguments (including the receiver) are dropped or popped as
1144 // appropriate. The stub then returns.
1145 //
1146 // After an unsuccessful call, the exit frame and suchlike are left
1147 // untouched, and the stub either throws an exception by jumping to one of
1148 // the exception_returned label.
1149
1150 DCHECK(csp.Is(__ StackPointer()));
1151
1152 // Prepare AAPCS64 arguments to pass to the builtin.
1153 __ Mov(x0, argc);
1154 __ Mov(x1, argv);
1155 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1156
1157 Label return_location;
1158 __ Adr(x12, &return_location);
1159 __ Poke(x12, 0);
1160
1161 if (__ emit_debug_code()) {
1162 // Verify that the slot below fp[kSPOffset]-8 points to the return location
1163 // (currently in x12).
1164 UseScratchRegisterScope temps(masm);
1165 Register temp = temps.AcquireX();
1166 __ Ldr(temp, MemOperand(fp, ExitFrameConstants::kSPOffset));
1167 __ Ldr(temp, MemOperand(temp, -static_cast<int64_t>(kXRegSize)));
1168 __ Cmp(temp, x12);
1169 __ Check(eq, kReturnAddressNotFoundInFrame);
1170 }
1171
1172 // Call the builtin.
1173 __ Blr(target);
1174 __ Bind(&return_location);
1175
Ben Murdoch097c5b22016-05-18 11:27:45 +01001176 if (result_size() > 2) {
1177 DCHECK_EQ(3, result_size());
1178 // Read result values stored on stack.
1179 __ Ldr(x0, MemOperand(__ StackPointer(), 4 * kPointerSize));
1180 __ Ldr(x1, MemOperand(__ StackPointer(), 5 * kPointerSize));
1181 __ Ldr(x2, MemOperand(__ StackPointer(), 6 * kPointerSize));
1182 }
1183 // Result returned in x0, x1:x0 or x2:x1:x0 - do not destroy these registers!
1184
1185 // x0 result0 The return code from the call.
1186 // x1 result1 For calls which return ObjectPair or ObjectTriple.
1187 // x2 result2 For calls which return ObjectTriple.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001188 // x21 argv
1189 // x22 argc
1190 // x23 target
1191 const Register& result = x0;
1192
1193 // Check result for exception sentinel.
1194 Label exception_returned;
1195 __ CompareRoot(result, Heap::kExceptionRootIndex);
1196 __ B(eq, &exception_returned);
1197
1198 // The call succeeded, so unwind the stack and return.
1199
1200 // Restore callee-saved registers x21-x23.
1201 __ Mov(x11, argc);
1202
1203 __ Peek(argv, 1 * kPointerSize);
1204 __ Peek(argc, 2 * kPointerSize);
1205 __ Peek(target, 3 * kPointerSize);
1206
1207 __ LeaveExitFrame(save_doubles(), x10, true);
1208 DCHECK(jssp.Is(__ StackPointer()));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001209 if (!argv_in_register()) {
1210 // Drop the remaining stack slots and return from the stub.
1211 __ Drop(x11);
1212 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001213 __ AssertFPCRState();
1214 __ Ret();
1215
1216 // The stack pointer is still csp if we aren't returning, and the frame
1217 // hasn't changed (except for the return address).
1218 __ SetStackPointer(csp);
1219
1220 // Handling of exception.
1221 __ Bind(&exception_returned);
1222
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001223 ExternalReference pending_handler_context_address(
1224 Isolate::kPendingHandlerContextAddress, isolate());
1225 ExternalReference pending_handler_code_address(
1226 Isolate::kPendingHandlerCodeAddress, isolate());
1227 ExternalReference pending_handler_offset_address(
1228 Isolate::kPendingHandlerOffsetAddress, isolate());
1229 ExternalReference pending_handler_fp_address(
1230 Isolate::kPendingHandlerFPAddress, isolate());
1231 ExternalReference pending_handler_sp_address(
1232 Isolate::kPendingHandlerSPAddress, isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001233
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001234 // Ask the runtime for help to determine the handler. This will set x0 to
1235 // contain the current pending exception, don't clobber it.
1236 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1237 isolate());
1238 DCHECK(csp.Is(masm->StackPointer()));
1239 {
1240 FrameScope scope(masm, StackFrame::MANUAL);
1241 __ Mov(x0, 0); // argc.
1242 __ Mov(x1, 0); // argv.
1243 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1244 __ CallCFunction(find_handler, 3);
1245 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001246
1247 // We didn't execute a return case, so the stack frame hasn't been updated
1248 // (except for the return address slot). However, we don't need to initialize
1249 // jssp because the throw method will immediately overwrite it when it
1250 // unwinds the stack.
1251 __ SetStackPointer(jssp);
1252
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001253 // Retrieve the handler context, SP and FP.
1254 __ Mov(cp, Operand(pending_handler_context_address));
1255 __ Ldr(cp, MemOperand(cp));
1256 __ Mov(jssp, Operand(pending_handler_sp_address));
1257 __ Ldr(jssp, MemOperand(jssp));
1258 __ Mov(fp, Operand(pending_handler_fp_address));
1259 __ Ldr(fp, MemOperand(fp));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001260
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001261 // If the handler is a JS frame, restore the context to the frame. Note that
1262 // the context will be set to (cp == 0) for non-JS frames.
1263 Label not_js_frame;
1264 __ Cbz(cp, &not_js_frame);
1265 __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1266 __ Bind(&not_js_frame);
1267
1268 // Compute the handler entry address and jump to it.
1269 __ Mov(x10, Operand(pending_handler_code_address));
1270 __ Ldr(x10, MemOperand(x10));
1271 __ Mov(x11, Operand(pending_handler_offset_address));
1272 __ Ldr(x11, MemOperand(x11));
1273 __ Add(x10, x10, Code::kHeaderSize - kHeapObjectTag);
1274 __ Add(x10, x10, x11);
1275 __ Br(x10);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001276}
1277
1278
1279// This is the entry point from C++. 5 arguments are provided in x0-x4.
1280// See use of the CALL_GENERATED_CODE macro for example in src/execution.cc.
1281// Input:
1282// x0: code entry.
1283// x1: function.
1284// x2: receiver.
1285// x3: argc.
1286// x4: argv.
1287// Output:
1288// x0: result.
1289void JSEntryStub::Generate(MacroAssembler* masm) {
1290 DCHECK(jssp.Is(__ StackPointer()));
1291 Register code_entry = x0;
1292
1293 // Enable instruction instrumentation. This only works on the simulator, and
1294 // will have no effect on the model or real hardware.
1295 __ EnableInstrumentation();
1296
1297 Label invoke, handler_entry, exit;
1298
1299 // Push callee-saved registers and synchronize the system stack pointer (csp)
1300 // and the JavaScript stack pointer (jssp).
1301 //
1302 // We must not write to jssp until after the PushCalleeSavedRegisters()
1303 // call, since jssp is itself a callee-saved register.
1304 __ SetStackPointer(csp);
1305 __ PushCalleeSavedRegisters();
1306 __ Mov(jssp, csp);
1307 __ SetStackPointer(jssp);
1308
1309 // Configure the FPCR. We don't restore it, so this is technically not allowed
1310 // according to AAPCS64. However, we only set default-NaN mode and this will
1311 // be harmless for most C code. Also, it works for ARM.
1312 __ ConfigureFPCR();
1313
1314 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1315
1316 // Set up the reserved register for 0.0.
1317 __ Fmov(fp_zero, 0.0);
1318
1319 // Build an entry frame (see layout below).
1320 int marker = type();
1321 int64_t bad_frame_pointer = -1L; // Bad frame pointer to fail if it is used.
1322 __ Mov(x13, bad_frame_pointer);
1323 __ Mov(x12, Smi::FromInt(marker));
1324 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1325 __ Ldr(x10, MemOperand(x11));
1326
1327 __ Push(x13, xzr, x12, x10);
1328 // Set up fp.
1329 __ Sub(fp, jssp, EntryFrameConstants::kCallerFPOffset);
1330
1331 // Push the JS entry frame marker. Also set js_entry_sp if this is the
1332 // outermost JS call.
1333 Label non_outermost_js, done;
1334 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1335 __ Mov(x10, ExternalReference(js_entry_sp));
1336 __ Ldr(x11, MemOperand(x10));
1337 __ Cbnz(x11, &non_outermost_js);
1338 __ Str(fp, MemOperand(x10));
1339 __ Mov(x12, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1340 __ Push(x12);
1341 __ B(&done);
1342 __ Bind(&non_outermost_js);
1343 // We spare one instruction by pushing xzr since the marker is 0.
1344 DCHECK(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME) == NULL);
1345 __ Push(xzr);
1346 __ Bind(&done);
1347
1348 // The frame set up looks like this:
1349 // jssp[0] : JS entry frame marker.
1350 // jssp[1] : C entry FP.
1351 // jssp[2] : stack frame marker.
1352 // jssp[3] : stack frmae marker.
1353 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1354
1355
1356 // Jump to a faked try block that does the invoke, with a faked catch
1357 // block that sets the pending exception.
1358 __ B(&invoke);
1359
1360 // Prevent the constant pool from being emitted between the record of the
1361 // handler_entry position and the first instruction of the sequence here.
1362 // There is no risk because Assembler::Emit() emits the instruction before
1363 // checking for constant pool emission, but we do not want to depend on
1364 // that.
1365 {
1366 Assembler::BlockPoolsScope block_pools(masm);
1367 __ bind(&handler_entry);
1368 handler_offset_ = handler_entry.pos();
1369 // Caught exception: Store result (exception) in the pending exception
1370 // field in the JSEnv and return a failure sentinel. Coming in here the
1371 // fp will be invalid because the PushTryHandler below sets it to 0 to
1372 // signal the existence of the JSEntry frame.
1373 __ Mov(x10, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1374 isolate())));
1375 }
1376 __ Str(code_entry, MemOperand(x10));
1377 __ LoadRoot(x0, Heap::kExceptionRootIndex);
1378 __ B(&exit);
1379
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001380 // Invoke: Link this frame into the handler chain.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001381 __ Bind(&invoke);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001382 __ PushStackHandler();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001383 // If an exception not caught by another handler occurs, this handler
1384 // returns control to the code after the B(&invoke) above, which
1385 // restores all callee-saved registers (including cp and fp) to their
1386 // saved values before returning a failure to C.
1387
1388 // Clear any pending exceptions.
1389 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
1390 __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1391 isolate())));
1392 __ Str(x10, MemOperand(x11));
1393
1394 // Invoke the function by calling through the JS entry trampoline builtin.
1395 // Notice that we cannot store a reference to the trampoline code directly in
1396 // this stub, because runtime stubs are not traversed when doing GC.
1397
1398 // Expected registers by Builtins::JSEntryTrampoline
1399 // x0: code entry.
1400 // x1: function.
1401 // x2: receiver.
1402 // x3: argc.
1403 // x4: argv.
1404 ExternalReference entry(type() == StackFrame::ENTRY_CONSTRUCT
1405 ? Builtins::kJSConstructEntryTrampoline
1406 : Builtins::kJSEntryTrampoline,
1407 isolate());
1408 __ Mov(x10, entry);
1409
1410 // Call the JSEntryTrampoline.
1411 __ Ldr(x11, MemOperand(x10)); // Dereference the address.
1412 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag);
1413 __ Blr(x12);
1414
1415 // Unlink this frame from the handler chain.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001416 __ PopStackHandler();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001417
1418
1419 __ Bind(&exit);
1420 // x0 holds the result.
1421 // The stack pointer points to the top of the entry frame pushed on entry from
1422 // C++ (at the beginning of this stub):
1423 // jssp[0] : JS entry frame marker.
1424 // jssp[1] : C entry FP.
1425 // jssp[2] : stack frame marker.
1426 // jssp[3] : stack frmae marker.
1427 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1428
1429 // Check if the current stack frame is marked as the outermost JS frame.
1430 Label non_outermost_js_2;
1431 __ Pop(x10);
1432 __ Cmp(x10, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1433 __ B(ne, &non_outermost_js_2);
1434 __ Mov(x11, ExternalReference(js_entry_sp));
1435 __ Str(xzr, MemOperand(x11));
1436 __ Bind(&non_outermost_js_2);
1437
1438 // Restore the top frame descriptors from the stack.
1439 __ Pop(x10);
1440 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1441 __ Str(x10, MemOperand(x11));
1442
1443 // Reset the stack to the callee saved registers.
1444 __ Drop(-EntryFrameConstants::kCallerFPOffset, kByteSizeInBytes);
1445 // Restore the callee-saved registers and return.
1446 DCHECK(jssp.Is(__ StackPointer()));
1447 __ Mov(csp, jssp);
1448 __ SetStackPointer(csp);
1449 __ PopCalleeSavedRegisters();
1450 // After this point, we must not modify jssp because it is a callee-saved
1451 // register which we have just restored.
1452 __ Ret();
1453}
1454
1455
1456void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1457 Label miss;
1458 Register receiver = LoadDescriptor::ReceiverRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001459 // Ensure that the vector and slot registers won't be clobbered before
1460 // calling the miss handler.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001461 DCHECK(!AreAliased(x10, x11, LoadWithVectorDescriptor::VectorRegister(),
1462 LoadWithVectorDescriptor::SlotRegister()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001463
1464 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, x10,
1465 x11, &miss);
1466
1467 __ Bind(&miss);
1468 PropertyAccessCompiler::TailCallBuiltin(
1469 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1470}
1471
1472
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001473void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1474 // Return address is in lr.
1475 Label miss;
1476
1477 Register receiver = LoadDescriptor::ReceiverRegister();
1478 Register index = LoadDescriptor::NameRegister();
1479 Register result = x0;
1480 Register scratch = x10;
1481 DCHECK(!scratch.is(receiver) && !scratch.is(index));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001482 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1483 result.is(LoadWithVectorDescriptor::SlotRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001484
1485 // StringCharAtGenerator doesn't use the result register until it's passed
1486 // the different miss possibilities. If it did, we would have a conflict
1487 // when FLAG_vector_ics is true.
1488 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1489 &miss, // When not a string.
1490 &miss, // When not a number.
1491 &miss, // When index out of range.
1492 STRING_INDEX_IS_ARRAY_INDEX,
1493 RECEIVER_IS_STRING);
1494 char_at_generator.GenerateFast(masm);
1495 __ Ret();
1496
1497 StubRuntimeCallHelper call_helper;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001498 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001499
1500 __ Bind(&miss);
1501 PropertyAccessCompiler::TailCallBuiltin(
1502 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1503}
1504
1505
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001506void InstanceOfStub::Generate(MacroAssembler* masm) {
1507 Register const object = x1; // Object (lhs).
1508 Register const function = x0; // Function (rhs).
1509 Register const object_map = x2; // Map of {object}.
1510 Register const function_map = x3; // Map of {function}.
1511 Register const function_prototype = x4; // Prototype of {function}.
1512 Register const scratch = x5;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001513
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001514 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1515 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001516
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001517 // Check if {object} is a smi.
1518 Label object_is_smi;
1519 __ JumpIfSmi(object, &object_is_smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001520
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001521 // Lookup the {function} and the {object} map in the global instanceof cache.
1522 // Note: This is safe because we clear the global instanceof cache whenever
1523 // we change the prototype of any object.
1524 Label fast_case, slow_case;
1525 __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1526 __ JumpIfNotRoot(function, Heap::kInstanceofCacheFunctionRootIndex,
1527 &fast_case);
1528 __ JumpIfNotRoot(object_map, Heap::kInstanceofCacheMapRootIndex, &fast_case);
1529 __ LoadRoot(x0, Heap::kInstanceofCacheAnswerRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001530 __ Ret();
1531
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001532 // If {object} is a smi we can safely return false if {function} is a JS
1533 // function, otherwise we have to miss to the runtime and throw an exception.
1534 __ Bind(&object_is_smi);
1535 __ JumpIfSmi(function, &slow_case);
1536 __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
1537 &slow_case);
1538 __ LoadRoot(x0, Heap::kFalseValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001539 __ Ret();
1540
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001541 // Fast-case: The {function} must be a valid JSFunction.
1542 __ Bind(&fast_case);
1543 __ JumpIfSmi(function, &slow_case);
1544 __ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
1545 &slow_case);
1546
1547 // Ensure that {function} has an instance prototype.
1548 __ Ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1549 __ Tbnz(scratch, Map::kHasNonInstancePrototype, &slow_case);
1550
1551 // Get the "prototype" (or initial map) of the {function}.
1552 __ Ldr(function_prototype,
1553 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1554 __ AssertNotSmi(function_prototype);
1555
1556 // Resolve the prototype if the {function} has an initial map. Afterwards the
1557 // {function_prototype} will be either the JSReceiver prototype object or the
1558 // hole value, which means that no instances of the {function} were created so
1559 // far and hence we should return false.
1560 Label function_prototype_valid;
1561 __ JumpIfNotObjectType(function_prototype, scratch, scratch, MAP_TYPE,
1562 &function_prototype_valid);
1563 __ Ldr(function_prototype,
1564 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1565 __ Bind(&function_prototype_valid);
1566 __ AssertNotSmi(function_prototype);
1567
1568 // Update the global instanceof cache with the current {object} map and
1569 // {function}. The cached answer will be set when it is known below.
1570 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1571 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1572
1573 // Loop through the prototype chain looking for the {function} prototype.
1574 // Assume true, and change to false if not found.
1575 Register const object_instance_type = function_map;
1576 Register const map_bit_field = function_map;
1577 Register const null = scratch;
1578 Register const result = x0;
1579
1580 Label done, loop, fast_runtime_fallback;
1581 __ LoadRoot(result, Heap::kTrueValueRootIndex);
1582 __ LoadRoot(null, Heap::kNullValueRootIndex);
1583 __ Bind(&loop);
1584
1585 // Check if the object needs to be access checked.
1586 __ Ldrb(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset));
1587 __ TestAndBranchIfAnySet(map_bit_field, 1 << Map::kIsAccessCheckNeeded,
1588 &fast_runtime_fallback);
1589 // Check if the current object is a Proxy.
1590 __ CompareInstanceType(object_map, object_instance_type, JS_PROXY_TYPE);
1591 __ B(eq, &fast_runtime_fallback);
1592
1593 __ Ldr(object, FieldMemOperand(object_map, Map::kPrototypeOffset));
1594 __ Cmp(object, function_prototype);
1595 __ B(eq, &done);
1596 __ Cmp(object, null);
1597 __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1598 __ B(ne, &loop);
1599 __ LoadRoot(result, Heap::kFalseValueRootIndex);
1600 __ Bind(&done);
1601 __ StoreRoot(result, Heap::kInstanceofCacheAnswerRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001602 __ Ret();
1603
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001604 // Found Proxy or access check needed: Call the runtime
1605 __ Bind(&fast_runtime_fallback);
1606 __ Push(object, function_prototype);
1607 // Invalidate the instanceof cache.
1608 __ Move(scratch, Smi::FromInt(0));
1609 __ StoreRoot(scratch, Heap::kInstanceofCacheFunctionRootIndex);
1610 __ TailCallRuntime(Runtime::kHasInPrototypeChain);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001611
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001612 // Slow-case: Call the %InstanceOf runtime function.
1613 __ bind(&slow_case);
1614 __ Push(object, function);
1615 __ TailCallRuntime(Runtime::kInstanceOf);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001616}
1617
1618
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001619void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1620 // Return address is in lr.
1621 Label slow;
1622
1623 Register receiver = LoadDescriptor::ReceiverRegister();
1624 Register key = LoadDescriptor::NameRegister();
1625
1626 // Check that the key is an array index, that is Uint32.
1627 __ TestAndBranchIfAnySet(key, kSmiTagMask | kSmiSignMask, &slow);
1628
1629 // Everything is fine, call runtime.
1630 __ Push(receiver, key);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001631 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001632
1633 __ Bind(&slow);
1634 PropertyAccessCompiler::TailCallBuiltin(
1635 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1636}
1637
1638
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001639void RegExpExecStub::Generate(MacroAssembler* masm) {
1640#ifdef V8_INTERPRETED_REGEXP
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001641 __ TailCallRuntime(Runtime::kRegExpExec);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001642#else // V8_INTERPRETED_REGEXP
1643
1644 // Stack frame on entry.
1645 // jssp[0]: last_match_info (expected JSArray)
1646 // jssp[8]: previous index
1647 // jssp[16]: subject string
1648 // jssp[24]: JSRegExp object
1649 Label runtime;
1650
1651 // Use of registers for this function.
1652
1653 // Variable registers:
1654 // x10-x13 used as scratch registers
1655 // w0 string_type type of subject string
1656 // x2 jsstring_length subject string length
1657 // x3 jsregexp_object JSRegExp object
1658 // w4 string_encoding Latin1 or UC16
1659 // w5 sliced_string_offset if the string is a SlicedString
1660 // offset to the underlying string
1661 // w6 string_representation groups attributes of the string:
1662 // - is a string
1663 // - type of the string
1664 // - is a short external string
1665 Register string_type = w0;
1666 Register jsstring_length = x2;
1667 Register jsregexp_object = x3;
1668 Register string_encoding = w4;
1669 Register sliced_string_offset = w5;
1670 Register string_representation = w6;
1671
1672 // These are in callee save registers and will be preserved by the call
1673 // to the native RegExp code, as this code is called using the normal
1674 // C calling convention. When calling directly from generated code the
1675 // native RegExp code will not do a GC and therefore the content of
1676 // these registers are safe to use after the call.
1677
1678 // x19 subject subject string
1679 // x20 regexp_data RegExp data (FixedArray)
1680 // x21 last_match_info_elements info relative to the last match
1681 // (FixedArray)
1682 // x22 code_object generated regexp code
1683 Register subject = x19;
1684 Register regexp_data = x20;
1685 Register last_match_info_elements = x21;
1686 Register code_object = x22;
1687
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001688 // Stack frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001689 // jssp[00]: last_match_info (JSArray)
1690 // jssp[08]: previous index
1691 // jssp[16]: subject string
1692 // jssp[24]: JSRegExp object
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001693
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001694 const int kLastMatchInfoOffset = 0 * kPointerSize;
1695 const int kPreviousIndexOffset = 1 * kPointerSize;
1696 const int kSubjectOffset = 2 * kPointerSize;
1697 const int kJSRegExpOffset = 3 * kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001698
1699 // Ensure that a RegExp stack is allocated.
1700 ExternalReference address_of_regexp_stack_memory_address =
1701 ExternalReference::address_of_regexp_stack_memory_address(isolate());
1702 ExternalReference address_of_regexp_stack_memory_size =
1703 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1704 __ Mov(x10, address_of_regexp_stack_memory_size);
1705 __ Ldr(x10, MemOperand(x10));
1706 __ Cbz(x10, &runtime);
1707
1708 // Check that the first argument is a JSRegExp object.
1709 DCHECK(jssp.Is(__ StackPointer()));
1710 __ Peek(jsregexp_object, kJSRegExpOffset);
1711 __ JumpIfSmi(jsregexp_object, &runtime);
1712 __ JumpIfNotObjectType(jsregexp_object, x10, x10, JS_REGEXP_TYPE, &runtime);
1713
1714 // Check that the RegExp has been compiled (data contains a fixed array).
1715 __ Ldr(regexp_data, FieldMemOperand(jsregexp_object, JSRegExp::kDataOffset));
1716 if (FLAG_debug_code) {
1717 STATIC_ASSERT(kSmiTag == 0);
1718 __ Tst(regexp_data, kSmiTagMask);
1719 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1720 __ CompareObjectType(regexp_data, x10, x10, FIXED_ARRAY_TYPE);
1721 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
1722 }
1723
1724 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1725 __ Ldr(x10, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1726 __ Cmp(x10, Smi::FromInt(JSRegExp::IRREGEXP));
1727 __ B(ne, &runtime);
1728
1729 // Check that the number of captures fit in the static offsets vector buffer.
1730 // We have always at least one capture for the whole match, plus additional
1731 // ones due to capturing parentheses. A capture takes 2 registers.
1732 // The number of capture registers then is (number_of_captures + 1) * 2.
1733 __ Ldrsw(x10,
1734 UntagSmiFieldMemOperand(regexp_data,
1735 JSRegExp::kIrregexpCaptureCountOffset));
1736 // Check (number_of_captures + 1) * 2 <= offsets vector size
1737 // number_of_captures * 2 <= offsets vector size - 2
1738 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1739 __ Add(x10, x10, x10);
1740 __ Cmp(x10, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
1741 __ B(hi, &runtime);
1742
1743 // Initialize offset for possibly sliced string.
1744 __ Mov(sliced_string_offset, 0);
1745
1746 DCHECK(jssp.Is(__ StackPointer()));
1747 __ Peek(subject, kSubjectOffset);
1748 __ JumpIfSmi(subject, &runtime);
1749
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001750 __ Ldr(jsstring_length, FieldMemOperand(subject, String::kLengthOffset));
1751
1752 // Handle subject string according to its encoding and representation:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001753 // (1) Sequential string? If yes, go to (4).
1754 // (2) Sequential or cons? If not, go to (5).
1755 // (3) Cons string. If the string is flat, replace subject with first string
1756 // and go to (1). Otherwise bail out to runtime.
1757 // (4) Sequential string. Load regexp code according to encoding.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001758 // (E) Carry on.
1759 /// [...]
1760
1761 // Deferred code at the end of the stub:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001762 // (5) Long external string? If not, go to (7).
1763 // (6) External string. Make it, offset-wise, look like a sequential string.
1764 // Go to (4).
1765 // (7) Short external string or not a string? If yes, bail out to runtime.
1766 // (8) Sliced string. Replace subject with parent. Go to (1).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001767
Ben Murdoch097c5b22016-05-18 11:27:45 +01001768 Label check_underlying; // (1)
1769 Label seq_string; // (4)
1770 Label not_seq_nor_cons; // (5)
1771 Label external_string; // (6)
1772 Label not_long_external; // (7)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001773
Ben Murdoch097c5b22016-05-18 11:27:45 +01001774 __ Bind(&check_underlying);
1775 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
1776 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
1777
1778 // (1) Sequential string? If yes, go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001779 __ And(string_representation,
1780 string_type,
1781 kIsNotStringMask |
1782 kStringRepresentationMask |
1783 kShortExternalStringMask);
1784 // We depend on the fact that Strings of type
1785 // SeqString and not ShortExternalString are defined
1786 // by the following pattern:
1787 // string_type: 0XX0 XX00
1788 // ^ ^ ^^
1789 // | | ||
1790 // | | is a SeqString
1791 // | is not a short external String
1792 // is a String
1793 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
1794 STATIC_ASSERT(kShortExternalStringTag != 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001795 __ Cbz(string_representation, &seq_string); // Go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001796
Ben Murdoch097c5b22016-05-18 11:27:45 +01001797 // (2) Sequential or cons? If not, go to (5).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001798 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1799 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
1800 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1801 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
1802 __ Cmp(string_representation, kExternalStringTag);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001803 __ B(ge, &not_seq_nor_cons); // Go to (5).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001804
1805 // (3) Cons string. Check that it's flat.
1806 __ Ldr(x10, FieldMemOperand(subject, ConsString::kSecondOffset));
1807 __ JumpIfNotRoot(x10, Heap::kempty_stringRootIndex, &runtime);
1808 // Replace subject with first string.
1809 __ Ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001810 __ B(&check_underlying);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001811
Ben Murdoch097c5b22016-05-18 11:27:45 +01001812 // (4) Sequential string. Load regexp code according to encoding.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001813 __ Bind(&seq_string);
1814
1815 // Check that the third argument is a positive smi less than the subject
1816 // string length. A negative value will be greater (unsigned comparison).
1817 DCHECK(jssp.Is(__ StackPointer()));
1818 __ Peek(x10, kPreviousIndexOffset);
1819 __ JumpIfNotSmi(x10, &runtime);
1820 __ Cmp(jsstring_length, x10);
1821 __ B(ls, &runtime);
1822
1823 // Argument 2 (x1): We need to load argument 2 (the previous index) into x1
1824 // before entering the exit frame.
1825 __ SmiUntag(x1, x10);
1826
1827 // The third bit determines the string encoding in string_type.
1828 STATIC_ASSERT(kOneByteStringTag == 0x04);
1829 STATIC_ASSERT(kTwoByteStringTag == 0x00);
1830 STATIC_ASSERT(kStringEncodingMask == 0x04);
1831
1832 // Find the code object based on the assumptions above.
1833 // kDataOneByteCodeOffset and kDataUC16CodeOffset are adjacent, adds an offset
1834 // of kPointerSize to reach the latter.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001835 STATIC_ASSERT(JSRegExp::kDataOneByteCodeOffset + kPointerSize ==
1836 JSRegExp::kDataUC16CodeOffset);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001837 __ Mov(x10, kPointerSize);
1838 // We will need the encoding later: Latin1 = 0x04
1839 // UC16 = 0x00
1840 __ Ands(string_encoding, string_type, kStringEncodingMask);
1841 __ CzeroX(x10, ne);
1842 __ Add(x10, regexp_data, x10);
1843 __ Ldr(code_object, FieldMemOperand(x10, JSRegExp::kDataOneByteCodeOffset));
1844
1845 // (E) Carry on. String handling is done.
1846
1847 // Check that the irregexp code has been generated for the actual string
1848 // encoding. If it has, the field contains a code object otherwise it contains
1849 // a smi (code flushing support).
1850 __ JumpIfSmi(code_object, &runtime);
1851
1852 // All checks done. Now push arguments for native regexp code.
1853 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1,
1854 x10,
1855 x11);
1856
1857 // Isolates: note we add an additional parameter here (isolate pointer).
1858 __ EnterExitFrame(false, x10, 1);
1859 DCHECK(csp.Is(__ StackPointer()));
1860
1861 // We have 9 arguments to pass to the regexp code, therefore we have to pass
1862 // one on the stack and the rest as registers.
1863
1864 // Note that the placement of the argument on the stack isn't standard
1865 // AAPCS64:
1866 // csp[0]: Space for the return address placed by DirectCEntryStub.
1867 // csp[8]: Argument 9, the current isolate address.
1868
1869 __ Mov(x10, ExternalReference::isolate_address(isolate()));
1870 __ Poke(x10, kPointerSize);
1871
1872 Register length = w11;
1873 Register previous_index_in_bytes = w12;
1874 Register start = x13;
1875
1876 // Load start of the subject string.
1877 __ Add(start, subject, SeqString::kHeaderSize - kHeapObjectTag);
1878 // Load the length from the original subject string from the previous stack
1879 // frame. Therefore we have to use fp, which points exactly to two pointer
1880 // sizes below the previous sp. (Because creating a new stack frame pushes
1881 // the previous fp onto the stack and decrements sp by 2 * kPointerSize.)
1882 __ Ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
1883 __ Ldr(length, UntagSmiFieldMemOperand(subject, String::kLengthOffset));
1884
1885 // Handle UC16 encoding, two bytes make one character.
1886 // string_encoding: if Latin1: 0x04
1887 // if UC16: 0x00
1888 STATIC_ASSERT(kStringEncodingMask == 0x04);
1889 __ Ubfx(string_encoding, string_encoding, 2, 1);
1890 __ Eor(string_encoding, string_encoding, 1);
1891 // string_encoding: if Latin1: 0
1892 // if UC16: 1
1893
1894 // Convert string positions from characters to bytes.
1895 // Previous index is in x1.
1896 __ Lsl(previous_index_in_bytes, w1, string_encoding);
1897 __ Lsl(length, length, string_encoding);
1898 __ Lsl(sliced_string_offset, sliced_string_offset, string_encoding);
1899
1900 // Argument 1 (x0): Subject string.
1901 __ Mov(x0, subject);
1902
1903 // Argument 2 (x1): Previous index, already there.
1904
1905 // Argument 3 (x2): Get the start of input.
1906 // Start of input = start of string + previous index + substring offset
1907 // (0 if the string
1908 // is not sliced).
1909 __ Add(w10, previous_index_in_bytes, sliced_string_offset);
1910 __ Add(x2, start, Operand(w10, UXTW));
1911
1912 // Argument 4 (x3):
1913 // End of input = start of input + (length of input - previous index)
1914 __ Sub(w10, length, previous_index_in_bytes);
1915 __ Add(x3, x2, Operand(w10, UXTW));
1916
1917 // Argument 5 (x4): static offsets vector buffer.
1918 __ Mov(x4, ExternalReference::address_of_static_offsets_vector(isolate()));
1919
1920 // Argument 6 (x5): Set the number of capture registers to zero to force
1921 // global regexps to behave as non-global. This stub is not used for global
1922 // regexps.
1923 __ Mov(x5, 0);
1924
1925 // Argument 7 (x6): Start (high end) of backtracking stack memory area.
1926 __ Mov(x10, address_of_regexp_stack_memory_address);
1927 __ Ldr(x10, MemOperand(x10));
1928 __ Mov(x11, address_of_regexp_stack_memory_size);
1929 __ Ldr(x11, MemOperand(x11));
1930 __ Add(x6, x10, x11);
1931
1932 // Argument 8 (x7): Indicate that this is a direct call from JavaScript.
1933 __ Mov(x7, 1);
1934
1935 // Locate the code entry and call it.
1936 __ Add(code_object, code_object, Code::kHeaderSize - kHeapObjectTag);
1937 DirectCEntryStub stub(isolate());
1938 stub.GenerateCall(masm, code_object);
1939
1940 __ LeaveExitFrame(false, x10, true);
1941
1942 // The generated regexp code returns an int32 in w0.
1943 Label failure, exception;
1944 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::FAILURE, eq, &failure);
1945 __ CompareAndBranch(w0,
1946 NativeRegExpMacroAssembler::EXCEPTION,
1947 eq,
1948 &exception);
1949 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::RETRY, eq, &runtime);
1950
1951 // Success: process the result from the native regexp code.
1952 Register number_of_capture_registers = x12;
1953
1954 // Calculate number of capture registers (number_of_captures + 1) * 2
1955 // and store it in the last match info.
1956 __ Ldrsw(x10,
1957 UntagSmiFieldMemOperand(regexp_data,
1958 JSRegExp::kIrregexpCaptureCountOffset));
1959 __ Add(x10, x10, x10);
1960 __ Add(number_of_capture_registers, x10, 2);
1961
1962 // Check that the fourth object is a JSArray object.
1963 DCHECK(jssp.Is(__ StackPointer()));
1964 __ Peek(x10, kLastMatchInfoOffset);
1965 __ JumpIfSmi(x10, &runtime);
1966 __ JumpIfNotObjectType(x10, x11, x11, JS_ARRAY_TYPE, &runtime);
1967
1968 // Check that the JSArray is the fast case.
1969 __ Ldr(last_match_info_elements,
1970 FieldMemOperand(x10, JSArray::kElementsOffset));
1971 __ Ldr(x10,
1972 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
1973 __ JumpIfNotRoot(x10, Heap::kFixedArrayMapRootIndex, &runtime);
1974
1975 // Check that the last match info has space for the capture registers and the
1976 // additional information (overhead).
1977 // (number_of_captures + 1) * 2 + overhead <= last match info size
1978 // (number_of_captures * 2) + 2 + overhead <= last match info size
1979 // number_of_capture_registers + overhead <= last match info size
1980 __ Ldrsw(x10,
1981 UntagSmiFieldMemOperand(last_match_info_elements,
1982 FixedArray::kLengthOffset));
1983 __ Add(x11, number_of_capture_registers, RegExpImpl::kLastMatchOverhead);
1984 __ Cmp(x11, x10);
1985 __ B(gt, &runtime);
1986
1987 // Store the capture count.
1988 __ SmiTag(x10, number_of_capture_registers);
1989 __ Str(x10,
1990 FieldMemOperand(last_match_info_elements,
1991 RegExpImpl::kLastCaptureCountOffset));
1992 // Store last subject and last input.
1993 __ Str(subject,
1994 FieldMemOperand(last_match_info_elements,
1995 RegExpImpl::kLastSubjectOffset));
1996 // Use x10 as the subject string in order to only need
1997 // one RecordWriteStub.
1998 __ Mov(x10, subject);
1999 __ RecordWriteField(last_match_info_elements,
2000 RegExpImpl::kLastSubjectOffset,
2001 x10,
2002 x11,
2003 kLRHasNotBeenSaved,
2004 kDontSaveFPRegs);
2005 __ Str(subject,
2006 FieldMemOperand(last_match_info_elements,
2007 RegExpImpl::kLastInputOffset));
2008 __ Mov(x10, subject);
2009 __ RecordWriteField(last_match_info_elements,
2010 RegExpImpl::kLastInputOffset,
2011 x10,
2012 x11,
2013 kLRHasNotBeenSaved,
2014 kDontSaveFPRegs);
2015
2016 Register last_match_offsets = x13;
2017 Register offsets_vector_index = x14;
2018 Register current_offset = x15;
2019
2020 // Get the static offsets vector filled by the native regexp code
2021 // and fill the last match info.
2022 ExternalReference address_of_static_offsets_vector =
2023 ExternalReference::address_of_static_offsets_vector(isolate());
2024 __ Mov(offsets_vector_index, address_of_static_offsets_vector);
2025
2026 Label next_capture, done;
2027 // Capture register counter starts from number of capture registers and
2028 // iterates down to zero (inclusive).
2029 __ Add(last_match_offsets,
2030 last_match_info_elements,
2031 RegExpImpl::kFirstCaptureOffset - kHeapObjectTag);
2032 __ Bind(&next_capture);
2033 __ Subs(number_of_capture_registers, number_of_capture_registers, 2);
2034 __ B(mi, &done);
2035 // Read two 32 bit values from the static offsets vector buffer into
2036 // an X register
2037 __ Ldr(current_offset,
2038 MemOperand(offsets_vector_index, kWRegSize * 2, PostIndex));
2039 // Store the smi values in the last match info.
2040 __ SmiTag(x10, current_offset);
2041 // Clearing the 32 bottom bits gives us a Smi.
2042 STATIC_ASSERT(kSmiTag == 0);
2043 __ Bic(x11, current_offset, kSmiShiftMask);
2044 __ Stp(x10,
2045 x11,
2046 MemOperand(last_match_offsets, kXRegSize * 2, PostIndex));
2047 __ B(&next_capture);
2048 __ Bind(&done);
2049
2050 // Return last match info.
2051 __ Peek(x0, kLastMatchInfoOffset);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002052 // Drop the 4 arguments of the stub from the stack.
2053 __ Drop(4);
2054 __ Ret();
2055
2056 __ Bind(&exception);
2057 Register exception_value = x0;
2058 // A stack overflow (on the backtrack stack) may have occured
2059 // in the RegExp code but no exception has been created yet.
2060 // If there is no pending exception, handle that in the runtime system.
2061 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
2062 __ Mov(x11,
2063 Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2064 isolate())));
2065 __ Ldr(exception_value, MemOperand(x11));
2066 __ Cmp(x10, exception_value);
2067 __ B(eq, &runtime);
2068
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002069 // For exception, throw the exception again.
2070 __ TailCallRuntime(Runtime::kRegExpExecReThrow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002071
2072 __ Bind(&failure);
2073 __ Mov(x0, Operand(isolate()->factory()->null_value()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002074 // Drop the 4 arguments of the stub from the stack.
2075 __ Drop(4);
2076 __ Ret();
2077
2078 __ Bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002079 __ TailCallRuntime(Runtime::kRegExpExec);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002080
2081 // Deferred code for string handling.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002082 // (5) Long external string? If not, go to (7).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002083 __ Bind(&not_seq_nor_cons);
2084 // Compare flags are still set.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002085 __ B(ne, &not_long_external); // Go to (7).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002086
Ben Murdoch097c5b22016-05-18 11:27:45 +01002087 // (6) External string. Make it, offset-wise, look like a sequential string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002088 __ Bind(&external_string);
2089 if (masm->emit_debug_code()) {
2090 // Assert that we do not have a cons or slice (indirect strings) here.
2091 // Sequential strings have already been ruled out.
2092 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2093 __ Ldrb(x10, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2094 __ Tst(x10, kIsIndirectStringMask);
2095 __ Check(eq, kExternalStringExpectedButNotFound);
2096 __ And(x10, x10, kStringRepresentationMask);
2097 __ Cmp(x10, 0);
2098 __ Check(ne, kExternalStringExpectedButNotFound);
2099 }
2100 __ Ldr(subject,
2101 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2102 // Move the pointer so that offset-wise, it looks like a sequential string.
2103 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2104 __ Sub(subject, subject, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002105 __ B(&seq_string); // Go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002106
Ben Murdoch097c5b22016-05-18 11:27:45 +01002107 // (7) If this is a short external string or not a string, bail out to
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002108 // runtime.
2109 __ Bind(&not_long_external);
2110 STATIC_ASSERT(kShortExternalStringTag != 0);
2111 __ TestAndBranchIfAnySet(string_representation,
2112 kShortExternalStringMask | kIsNotStringMask,
2113 &runtime);
2114
Ben Murdoch097c5b22016-05-18 11:27:45 +01002115 // (8) Sliced string. Replace subject with parent.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002116 __ Ldr(sliced_string_offset,
2117 UntagSmiFieldMemOperand(subject, SlicedString::kOffsetOffset));
2118 __ Ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002119 __ B(&check_underlying); // Go to (1).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002120#endif
2121}
2122
2123
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002124static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2125 Register argc, Register function,
2126 Register feedback_vector, Register index,
2127 Register new_target) {
2128 FrameScope scope(masm, StackFrame::INTERNAL);
2129
2130 // Number-of-arguments register must be smi-tagged to call out.
2131 __ SmiTag(argc);
2132 __ Push(argc, function, feedback_vector, index);
2133
2134 DCHECK(feedback_vector.Is(x2) && index.Is(x3));
2135 __ CallStub(stub);
2136
2137 __ Pop(index, feedback_vector, function, argc);
2138 __ SmiUntag(argc);
2139}
2140
2141
2142static void GenerateRecordCallTarget(MacroAssembler* masm, Register argc,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002143 Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002144 Register feedback_vector, Register index,
2145 Register new_target, Register scratch1,
2146 Register scratch2, Register scratch3) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002147 ASM_LOCATION("GenerateRecordCallTarget");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002148 DCHECK(!AreAliased(scratch1, scratch2, scratch3, argc, function,
2149 feedback_vector, index, new_target));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002150 // Cache the called function in a feedback vector slot. Cache states are
2151 // uninitialized, monomorphic (indicated by a JSFunction), and megamorphic.
2152 // argc : number of arguments to the construct function
2153 // function : the function to call
2154 // feedback_vector : the feedback vector
2155 // index : slot in feedback vector (smi)
2156 Label initialize, done, miss, megamorphic, not_array_function;
2157
2158 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2159 masm->isolate()->heap()->megamorphic_symbol());
2160 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2161 masm->isolate()->heap()->uninitialized_symbol());
2162
2163 // Load the cache state.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002164 Register feedback = scratch1;
2165 Register feedback_map = scratch2;
2166 Register feedback_value = scratch3;
2167 __ Add(feedback, feedback_vector,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002168 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002169 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002170
2171 // A monomorphic cache hit or an already megamorphic state: invoke the
2172 // function without changing the state.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002173 // We don't know if feedback value is a WeakCell or a Symbol, but it's
2174 // harmless to read at this position in a symbol (see static asserts in
2175 // type-feedback-vector.h).
2176 Label check_allocation_site;
2177 __ Ldr(feedback_value, FieldMemOperand(feedback, WeakCell::kValueOffset));
2178 __ Cmp(function, feedback_value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002179 __ B(eq, &done);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002180 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
2181 __ B(eq, &done);
2182 __ Ldr(feedback_map, FieldMemOperand(feedback, HeapObject::kMapOffset));
2183 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2184 __ B(ne, &check_allocation_site);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002185
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002186 // If the weak cell is cleared, we have a new chance to become monomorphic.
2187 __ JumpIfSmi(feedback_value, &initialize);
2188 __ B(&megamorphic);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002189
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002190 __ bind(&check_allocation_site);
2191 // If we came here, we need to see if we are the array function.
2192 // If we didn't have a matching function, and we didn't find the megamorph
2193 // sentinel, then we have in the slot either some other function or an
2194 // AllocationSite.
2195 __ JumpIfNotRoot(feedback_map, Heap::kAllocationSiteMapRootIndex, &miss);
2196
2197 // Make sure the function is the Array() function
2198 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, scratch1);
2199 __ Cmp(function, scratch1);
2200 __ B(ne, &megamorphic);
2201 __ B(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002202
2203 __ Bind(&miss);
2204
2205 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2206 // megamorphic.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002207 __ JumpIfRoot(scratch1, Heap::kuninitialized_symbolRootIndex, &initialize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002208 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2209 // write-barrier is needed.
2210 __ Bind(&megamorphic);
2211 __ Add(scratch1, feedback_vector,
2212 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002213 __ LoadRoot(scratch2, Heap::kmegamorphic_symbolRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002214 __ Str(scratch2, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
2215 __ B(&done);
2216
2217 // An uninitialized cache is patched with the function or sentinel to
2218 // indicate the ElementsKind if function is the Array constructor.
2219 __ Bind(&initialize);
2220
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002221 // Make sure the function is the Array() function
2222 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, scratch1);
2223 __ Cmp(function, scratch1);
2224 __ B(ne, &not_array_function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002225
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002226 // The target function is the Array constructor,
2227 // Create an AllocationSite if we don't already have it, store it in the
2228 // slot.
2229 CreateAllocationSiteStub create_stub(masm->isolate());
2230 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2231 feedback_vector, index, new_target);
2232 __ B(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002233
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002234 __ Bind(&not_array_function);
2235 CreateWeakCellStub weak_cell_stub(masm->isolate());
2236 CallStubInRecordCallTarget(masm, &weak_cell_stub, argc, function,
2237 feedback_vector, index, new_target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002238 __ Bind(&done);
2239}
2240
2241
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002242void CallConstructStub::Generate(MacroAssembler* masm) {
2243 ASM_LOCATION("CallConstructStub::Generate");
2244 // x0 : number of arguments
2245 // x1 : the function to call
2246 // x2 : feedback vector
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002247 // x3 : slot in feedback vector (Smi, for RecordCallTarget)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002248 Register function = x1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002249
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002250 Label non_function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002251 // Check that the function is not a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002252 __ JumpIfSmi(function, &non_function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002253 // Check that the function is a JSFunction.
2254 Register object_type = x10;
2255 __ JumpIfNotObjectType(function, object_type, object_type, JS_FUNCTION_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002256 &non_function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002257
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002258 GenerateRecordCallTarget(masm, x0, function, x2, x3, x4, x5, x11, x12);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002259
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002260 __ Add(x5, x2, Operand::UntagSmiAndScale(x3, kPointerSizeLog2));
2261 Label feedback_register_initialized;
2262 // Put the AllocationSite from the feedback vector into x2, or undefined.
2263 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize));
2264 __ Ldr(x5, FieldMemOperand(x2, AllocationSite::kMapOffset));
2265 __ JumpIfRoot(x5, Heap::kAllocationSiteMapRootIndex,
2266 &feedback_register_initialized);
2267 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
2268 __ bind(&feedback_register_initialized);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002269
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002270 __ AssertUndefinedOrAllocationSite(x2, x5);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002271
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002272 __ Mov(x3, function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002273
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002274 // Tail call to the function-specific construct stub (still in the caller
2275 // context at this point).
2276 __ Ldr(x4, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
2277 __ Ldr(x4, FieldMemOperand(x4, SharedFunctionInfo::kConstructStubOffset));
2278 __ Add(x4, x4, Code::kHeaderSize - kHeapObjectTag);
2279 __ Br(x4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002280
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002281 __ Bind(&non_function);
2282 __ Mov(x3, function);
2283 __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002284}
2285
2286
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002287void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002288 // x1 - function
2289 // x3 - slot id
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002290 // x2 - vector
2291 // x4 - allocation site (loaded from vector[slot])
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002292 Register function = x1;
2293 Register feedback_vector = x2;
2294 Register index = x3;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002295 Register allocation_site = x4;
2296 Register scratch = x5;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002297
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002298 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002299 __ Cmp(function, scratch);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002300 __ B(ne, miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002301
2302 __ Mov(x0, Operand(arg_count()));
2303
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002304 // Increment the call count for monomorphic function calls.
2305 __ Add(feedback_vector, feedback_vector,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002306 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002307 __ Add(feedback_vector, feedback_vector,
2308 Operand(FixedArray::kHeaderSize + kPointerSize));
2309 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
2310 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2311 __ Str(index, FieldMemOperand(feedback_vector, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002312
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002313 // Set up arguments for the array constructor stub.
2314 Register allocation_site_arg = feedback_vector;
2315 Register new_target_arg = index;
2316 __ Mov(allocation_site_arg, allocation_site);
2317 __ Mov(new_target_arg, function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002318 ArrayConstructorStub stub(masm->isolate(), arg_count());
2319 __ TailCallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002320}
2321
2322
2323void CallICStub::Generate(MacroAssembler* masm) {
2324 ASM_LOCATION("CallICStub");
2325
2326 // x1 - function
2327 // x3 - slot id (Smi)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002328 // x2 - vector
2329 Label extra_checks_or_miss, call, call_function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002330 int argc = arg_count();
2331 ParameterCount actual(argc);
2332
2333 Register function = x1;
2334 Register feedback_vector = x2;
2335 Register index = x3;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002336
2337 // The checks. First, does x1 match the recorded monomorphic target?
2338 __ Add(x4, feedback_vector,
2339 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2340 __ Ldr(x4, FieldMemOperand(x4, FixedArray::kHeaderSize));
2341
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002342 // We don't know that we have a weak cell. We might have a private symbol
2343 // or an AllocationSite, but the memory is safe to examine.
2344 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2345 // FixedArray.
2346 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2347 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2348 // computed, meaning that it can't appear to be a pointer. If the low bit is
2349 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2350 // to be a pointer.
2351 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2352 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2353 WeakCell::kValueOffset &&
2354 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2355
2356 __ Ldr(x5, FieldMemOperand(x4, WeakCell::kValueOffset));
2357 __ Cmp(x5, function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002358 __ B(ne, &extra_checks_or_miss);
2359
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002360 // The compare above could have been a SMI/SMI comparison. Guard against this
2361 // convincing us that we have a monomorphic JSFunction.
2362 __ JumpIfSmi(function, &extra_checks_or_miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002363
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002364 // Increment the call count for monomorphic function calls.
2365 __ Add(feedback_vector, feedback_vector,
2366 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2367 __ Add(feedback_vector, feedback_vector,
2368 Operand(FixedArray::kHeaderSize + kPointerSize));
2369 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
2370 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2371 __ Str(index, FieldMemOperand(feedback_vector, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002372
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002373 __ Bind(&call_function);
2374 __ Mov(x0, argc);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002375 __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(),
2376 tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002377 RelocInfo::CODE_TARGET);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002378
2379 __ bind(&extra_checks_or_miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002380 Label uninitialized, miss, not_allocation_site;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002381
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002382 __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &call);
2383
2384 __ Ldr(x5, FieldMemOperand(x4, HeapObject::kMapOffset));
2385 __ JumpIfNotRoot(x5, Heap::kAllocationSiteMapRootIndex, &not_allocation_site);
2386
2387 HandleArrayCase(masm, &miss);
2388
2389 __ bind(&not_allocation_site);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002390
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002391 // The following cases attempt to handle MISS cases without going to the
2392 // runtime.
2393 if (FLAG_trace_ic) {
2394 __ jmp(&miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002395 }
2396
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002397 __ JumpIfRoot(x4, Heap::kuninitialized_symbolRootIndex, &miss);
2398
2399 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2400 // to handle it here. More complex cases are dealt with in the runtime.
2401 __ AssertNotSmi(x4);
2402 __ JumpIfNotObjectType(x4, x5, x5, JS_FUNCTION_TYPE, &miss);
2403 __ Add(x4, feedback_vector,
2404 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2405 __ LoadRoot(x5, Heap::kmegamorphic_symbolRootIndex);
2406 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002407
2408 __ Bind(&call);
2409 __ Mov(x0, argc);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002410 __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002411 RelocInfo::CODE_TARGET);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002412
2413 __ bind(&uninitialized);
2414
2415 // We are going monomorphic, provided we actually have a JSFunction.
2416 __ JumpIfSmi(function, &miss);
2417
2418 // Goto miss case if we do not have a function.
2419 __ JumpIfNotObjectType(function, x5, x5, JS_FUNCTION_TYPE, &miss);
2420
2421 // Make sure the function is not the Array() function, which requires special
2422 // behavior on MISS.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002423 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, x5);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002424 __ Cmp(function, x5);
2425 __ B(eq, &miss);
2426
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002427 // Make sure the function belongs to the same native context.
2428 __ Ldr(x4, FieldMemOperand(function, JSFunction::kContextOffset));
2429 __ Ldr(x4, ContextMemOperand(x4, Context::NATIVE_CONTEXT_INDEX));
2430 __ Ldr(x5, NativeContextMemOperand());
2431 __ Cmp(x4, x5);
2432 __ B(ne, &miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002433
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002434 // Initialize the call counter.
2435 __ Mov(x5, Smi::FromInt(CallICNexus::kCallCountIncrement));
2436 __ Adds(x4, feedback_vector,
2437 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2438 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize + kPointerSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002439
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002440 // Store the function. Use a stub since we need a frame for allocation.
2441 // x2 - vector
2442 // x3 - slot
2443 // x1 - function
2444 {
2445 FrameScope scope(masm, StackFrame::INTERNAL);
2446 CreateWeakCellStub create_stub(masm->isolate());
2447 __ Push(function);
2448 __ CallStub(&create_stub);
2449 __ Pop(function);
2450 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002451
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002452 __ B(&call_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002453
2454 // We are here because tracing is on or we encountered a MISS case we can't
2455 // handle here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002456 __ bind(&miss);
2457 GenerateMiss(masm);
2458
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002459 __ B(&call);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002460}
2461
2462
2463void CallICStub::GenerateMiss(MacroAssembler* masm) {
2464 ASM_LOCATION("CallICStub[Miss]");
2465
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002466 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002467
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002468 // Push the receiver and the function and feedback info.
2469 __ Push(x1, x2, x3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002470
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002471 // Call the entry.
2472 __ CallRuntime(Runtime::kCallIC_Miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002473
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002474 // Move result to edi and exit the internal frame.
2475 __ Mov(x1, x0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002476}
2477
2478
2479void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2480 // If the receiver is a smi trigger the non-string case.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002481 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2482 __ JumpIfSmi(object_, receiver_not_string_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002483
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002484 // Fetch the instance type of the receiver into result register.
2485 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2486 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002487
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002488 // If the receiver is not a string trigger the non-string case.
2489 __ TestAndBranchIfAnySet(result_, kIsNotStringMask, receiver_not_string_);
2490 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002491
2492 // If the index is non-smi trigger the non-smi case.
2493 __ JumpIfNotSmi(index_, &index_not_smi_);
2494
2495 __ Bind(&got_smi_index_);
2496 // Check for index out of range.
2497 __ Ldrsw(result_, UntagSmiFieldMemOperand(object_, String::kLengthOffset));
2498 __ Cmp(result_, Operand::UntagSmi(index_));
2499 __ B(ls, index_out_of_range_);
2500
2501 __ SmiUntag(index_);
2502
2503 StringCharLoadGenerator::Generate(masm,
2504 object_,
2505 index_.W(),
2506 result_,
2507 &call_runtime_);
2508 __ SmiTag(result_);
2509 __ Bind(&exit_);
2510}
2511
2512
2513void StringCharCodeAtGenerator::GenerateSlow(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002514 MacroAssembler* masm, EmbedMode embed_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002515 const RuntimeCallHelper& call_helper) {
2516 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2517
2518 __ Bind(&index_not_smi_);
2519 // If index is a heap number, try converting it to an integer.
2520 __ JumpIfNotHeapNumber(index_, index_not_number_);
2521 call_helper.BeforeCall(masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002522 if (embed_mode == PART_OF_IC_HANDLER) {
2523 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2524 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2525 } else {
2526 // Save object_ on the stack and pass index_ as argument for runtime call.
2527 __ Push(object_, index_);
2528 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002529 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002530 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002531 } else {
2532 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2533 // NumberToSmi discards numbers that are not exact integers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002534 __ CallRuntime(Runtime::kNumberToSmi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002535 }
2536 // Save the conversion result before the pop instructions below
2537 // have a chance to overwrite it.
2538 __ Mov(index_, x0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002539 if (embed_mode == PART_OF_IC_HANDLER) {
2540 __ Pop(object_, LoadWithVectorDescriptor::SlotRegister(),
2541 LoadWithVectorDescriptor::VectorRegister());
2542 } else {
2543 __ Pop(object_);
2544 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002545 // Reload the instance type.
2546 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2547 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2548 call_helper.AfterCall(masm);
2549
2550 // If index is still not a smi, it must be out of range.
2551 __ JumpIfNotSmi(index_, index_out_of_range_);
2552 // Otherwise, return to the fast path.
2553 __ B(&got_smi_index_);
2554
2555 // Call runtime. We get here when the receiver is a string and the
2556 // index is a number, but the code of getting the actual character
2557 // is too complex (e.g., when the string needs to be flattened).
2558 __ Bind(&call_runtime_);
2559 call_helper.BeforeCall(masm);
2560 __ SmiTag(index_);
2561 __ Push(object_, index_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002562 __ CallRuntime(Runtime::kStringCharCodeAtRT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002563 __ Mov(result_, x0);
2564 call_helper.AfterCall(masm);
2565 __ B(&exit_);
2566
2567 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2568}
2569
2570
2571void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2572 __ JumpIfNotSmi(code_, &slow_case_);
2573 __ Cmp(code_, Smi::FromInt(String::kMaxOneByteCharCode));
2574 __ B(hi, &slow_case_);
2575
2576 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2577 // At this point code register contains smi tagged one-byte char code.
2578 __ Add(result_, result_, Operand::UntagSmiAndScale(code_, kPointerSizeLog2));
2579 __ Ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
2580 __ JumpIfRoot(result_, Heap::kUndefinedValueRootIndex, &slow_case_);
2581 __ Bind(&exit_);
2582}
2583
2584
2585void StringCharFromCodeGenerator::GenerateSlow(
2586 MacroAssembler* masm,
2587 const RuntimeCallHelper& call_helper) {
2588 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2589
2590 __ Bind(&slow_case_);
2591 call_helper.BeforeCall(masm);
2592 __ Push(code_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002593 __ CallRuntime(Runtime::kStringCharFromCode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002594 __ Mov(result_, x0);
2595 call_helper.AfterCall(masm);
2596 __ B(&exit_);
2597
2598 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2599}
2600
2601
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002602void CompareICStub::GenerateBooleans(MacroAssembler* masm) {
2603 // Inputs are in x0 (lhs) and x1 (rhs).
2604 DCHECK_EQ(CompareICState::BOOLEAN, state());
2605 ASM_LOCATION("CompareICStub[Booleans]");
2606 Label miss;
2607
2608 __ CheckMap(x1, x2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
2609 __ CheckMap(x0, x3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002610 if (!Token::IsEqualityOp(op())) {
2611 __ Ldr(x1, FieldMemOperand(x1, Oddball::kToNumberOffset));
2612 __ AssertSmi(x1);
2613 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
2614 __ AssertSmi(x0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002615 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002616 __ Sub(x0, x1, x0);
2617 __ Ret();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002618
2619 __ Bind(&miss);
2620 GenerateMiss(masm);
2621}
2622
2623
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002624void CompareICStub::GenerateSmis(MacroAssembler* masm) {
2625 // Inputs are in x0 (lhs) and x1 (rhs).
2626 DCHECK(state() == CompareICState::SMI);
2627 ASM_LOCATION("CompareICStub[Smis]");
2628 Label miss;
2629 // Bail out (to 'miss') unless both x0 and x1 are smis.
2630 __ JumpIfEitherNotSmi(x0, x1, &miss);
2631
2632 if (GetCondition() == eq) {
2633 // For equality we do not care about the sign of the result.
2634 __ Sub(x0, x0, x1);
2635 } else {
2636 // Untag before subtracting to avoid handling overflow.
2637 __ SmiUntag(x1);
2638 __ Sub(x0, x1, Operand::UntagSmi(x0));
2639 }
2640 __ Ret();
2641
2642 __ Bind(&miss);
2643 GenerateMiss(masm);
2644}
2645
2646
2647void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
2648 DCHECK(state() == CompareICState::NUMBER);
2649 ASM_LOCATION("CompareICStub[HeapNumbers]");
2650
2651 Label unordered, maybe_undefined1, maybe_undefined2;
2652 Label miss, handle_lhs, values_in_d_regs;
2653 Label untag_rhs, untag_lhs;
2654
2655 Register result = x0;
2656 Register rhs = x0;
2657 Register lhs = x1;
2658 FPRegister rhs_d = d0;
2659 FPRegister lhs_d = d1;
2660
2661 if (left() == CompareICState::SMI) {
2662 __ JumpIfNotSmi(lhs, &miss);
2663 }
2664 if (right() == CompareICState::SMI) {
2665 __ JumpIfNotSmi(rhs, &miss);
2666 }
2667
2668 __ SmiUntagToDouble(rhs_d, rhs, kSpeculativeUntag);
2669 __ SmiUntagToDouble(lhs_d, lhs, kSpeculativeUntag);
2670
2671 // Load rhs if it's a heap number.
2672 __ JumpIfSmi(rhs, &handle_lhs);
2673 __ JumpIfNotHeapNumber(rhs, &maybe_undefined1);
2674 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
2675
2676 // Load lhs if it's a heap number.
2677 __ Bind(&handle_lhs);
2678 __ JumpIfSmi(lhs, &values_in_d_regs);
2679 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
2680 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
2681
2682 __ Bind(&values_in_d_regs);
2683 __ Fcmp(lhs_d, rhs_d);
2684 __ B(vs, &unordered); // Overflow flag set if either is NaN.
2685 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
2686 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
2687 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
2688 __ Ret();
2689
2690 __ Bind(&unordered);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002691 CompareICStub stub(isolate(), op(), CompareICState::GENERIC,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002692 CompareICState::GENERIC, CompareICState::GENERIC);
2693 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
2694
2695 __ Bind(&maybe_undefined1);
2696 if (Token::IsOrderedRelationalCompareOp(op())) {
2697 __ JumpIfNotRoot(rhs, Heap::kUndefinedValueRootIndex, &miss);
2698 __ JumpIfSmi(lhs, &unordered);
2699 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
2700 __ B(&unordered);
2701 }
2702
2703 __ Bind(&maybe_undefined2);
2704 if (Token::IsOrderedRelationalCompareOp(op())) {
2705 __ JumpIfRoot(lhs, Heap::kUndefinedValueRootIndex, &unordered);
2706 }
2707
2708 __ Bind(&miss);
2709 GenerateMiss(masm);
2710}
2711
2712
2713void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
2714 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
2715 ASM_LOCATION("CompareICStub[InternalizedStrings]");
2716 Label miss;
2717
2718 Register result = x0;
2719 Register rhs = x0;
2720 Register lhs = x1;
2721
2722 // Check that both operands are heap objects.
2723 __ JumpIfEitherSmi(lhs, rhs, &miss);
2724
2725 // Check that both operands are internalized strings.
2726 Register rhs_map = x10;
2727 Register lhs_map = x11;
2728 Register rhs_type = x10;
2729 Register lhs_type = x11;
2730 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
2731 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
2732 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
2733 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
2734
2735 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
2736 __ Orr(x12, lhs_type, rhs_type);
2737 __ TestAndBranchIfAnySet(
2738 x12, kIsNotStringMask | kIsNotInternalizedMask, &miss);
2739
2740 // Internalized strings are compared by identity.
2741 STATIC_ASSERT(EQUAL == 0);
2742 __ Cmp(lhs, rhs);
2743 __ Cset(result, ne);
2744 __ Ret();
2745
2746 __ Bind(&miss);
2747 GenerateMiss(masm);
2748}
2749
2750
2751void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
2752 DCHECK(state() == CompareICState::UNIQUE_NAME);
2753 ASM_LOCATION("CompareICStub[UniqueNames]");
2754 DCHECK(GetCondition() == eq);
2755 Label miss;
2756
2757 Register result = x0;
2758 Register rhs = x0;
2759 Register lhs = x1;
2760
2761 Register lhs_instance_type = w2;
2762 Register rhs_instance_type = w3;
2763
2764 // Check that both operands are heap objects.
2765 __ JumpIfEitherSmi(lhs, rhs, &miss);
2766
2767 // Check that both operands are unique names. This leaves the instance
2768 // types loaded in tmp1 and tmp2.
2769 __ Ldr(x10, FieldMemOperand(lhs, HeapObject::kMapOffset));
2770 __ Ldr(x11, FieldMemOperand(rhs, HeapObject::kMapOffset));
2771 __ Ldrb(lhs_instance_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2772 __ Ldrb(rhs_instance_type, FieldMemOperand(x11, Map::kInstanceTypeOffset));
2773
2774 // To avoid a miss, each instance type should be either SYMBOL_TYPE or it
2775 // should have kInternalizedTag set.
2776 __ JumpIfNotUniqueNameInstanceType(lhs_instance_type, &miss);
2777 __ JumpIfNotUniqueNameInstanceType(rhs_instance_type, &miss);
2778
2779 // Unique names are compared by identity.
2780 STATIC_ASSERT(EQUAL == 0);
2781 __ Cmp(lhs, rhs);
2782 __ Cset(result, ne);
2783 __ Ret();
2784
2785 __ Bind(&miss);
2786 GenerateMiss(masm);
2787}
2788
2789
2790void CompareICStub::GenerateStrings(MacroAssembler* masm) {
2791 DCHECK(state() == CompareICState::STRING);
2792 ASM_LOCATION("CompareICStub[Strings]");
2793
2794 Label miss;
2795
2796 bool equality = Token::IsEqualityOp(op());
2797
2798 Register result = x0;
2799 Register rhs = x0;
2800 Register lhs = x1;
2801
2802 // Check that both operands are heap objects.
2803 __ JumpIfEitherSmi(rhs, lhs, &miss);
2804
2805 // Check that both operands are strings.
2806 Register rhs_map = x10;
2807 Register lhs_map = x11;
2808 Register rhs_type = x10;
2809 Register lhs_type = x11;
2810 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
2811 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
2812 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
2813 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
2814 STATIC_ASSERT(kNotStringTag != 0);
2815 __ Orr(x12, lhs_type, rhs_type);
2816 __ Tbnz(x12, MaskToBit(kIsNotStringMask), &miss);
2817
2818 // Fast check for identical strings.
2819 Label not_equal;
2820 __ Cmp(lhs, rhs);
2821 __ B(ne, &not_equal);
2822 __ Mov(result, EQUAL);
2823 __ Ret();
2824
2825 __ Bind(&not_equal);
2826 // Handle not identical strings
2827
2828 // Check that both strings are internalized strings. If they are, we're done
2829 // because we already know they are not identical. We know they are both
2830 // strings.
2831 if (equality) {
2832 DCHECK(GetCondition() == eq);
2833 STATIC_ASSERT(kInternalizedTag == 0);
2834 Label not_internalized_strings;
2835 __ Orr(x12, lhs_type, rhs_type);
2836 __ TestAndBranchIfAnySet(
2837 x12, kIsNotInternalizedMask, &not_internalized_strings);
2838 // Result is in rhs (x0), and not EQUAL, as rhs is not a smi.
2839 __ Ret();
2840 __ Bind(&not_internalized_strings);
2841 }
2842
2843 // Check that both strings are sequential one-byte.
2844 Label runtime;
2845 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x12,
2846 x13, &runtime);
2847
2848 // Compare flat one-byte strings. Returns when done.
2849 if (equality) {
2850 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
2851 x12);
2852 } else {
2853 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
2854 x12, x13);
2855 }
2856
2857 // Handle more complex cases in runtime.
2858 __ Bind(&runtime);
2859 __ Push(lhs, rhs);
2860 if (equality) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002861 __ TailCallRuntime(Runtime::kStringEquals);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002862 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002863 __ TailCallRuntime(Runtime::kStringCompare);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002864 }
2865
2866 __ Bind(&miss);
2867 GenerateMiss(masm);
2868}
2869
2870
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002871void CompareICStub::GenerateReceivers(MacroAssembler* masm) {
2872 DCHECK_EQ(CompareICState::RECEIVER, state());
2873 ASM_LOCATION("CompareICStub[Receivers]");
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002874
2875 Label miss;
2876
2877 Register result = x0;
2878 Register rhs = x0;
2879 Register lhs = x1;
2880
2881 __ JumpIfEitherSmi(rhs, lhs, &miss);
2882
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002883 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
2884 __ JumpIfObjectType(rhs, x10, x10, FIRST_JS_RECEIVER_TYPE, &miss, lt);
2885 __ JumpIfObjectType(lhs, x10, x10, FIRST_JS_RECEIVER_TYPE, &miss, lt);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002886
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002887 DCHECK_EQ(eq, GetCondition());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002888 __ Sub(result, rhs, lhs);
2889 __ Ret();
2890
2891 __ Bind(&miss);
2892 GenerateMiss(masm);
2893}
2894
2895
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002896void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) {
2897 ASM_LOCATION("CompareICStub[KnownReceivers]");
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002898
2899 Label miss;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002900 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002901
2902 Register result = x0;
2903 Register rhs = x0;
2904 Register lhs = x1;
2905
2906 __ JumpIfEitherSmi(rhs, lhs, &miss);
2907
2908 Register rhs_map = x10;
2909 Register lhs_map = x11;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002910 Register map = x12;
2911 __ GetWeakValue(map, cell);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002912 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
2913 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002914 __ Cmp(rhs_map, map);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002915 __ B(ne, &miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002916 __ Cmp(lhs_map, map);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002917 __ B(ne, &miss);
2918
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002919 if (Token::IsEqualityOp(op())) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002920 __ Sub(result, rhs, lhs);
2921 __ Ret();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002922 } else {
2923 Register ncr = x2;
2924 if (op() == Token::LT || op() == Token::LTE) {
2925 __ Mov(ncr, Smi::FromInt(GREATER));
2926 } else {
2927 __ Mov(ncr, Smi::FromInt(LESS));
2928 }
2929 __ Push(lhs, rhs, ncr);
2930 __ TailCallRuntime(Runtime::kCompare);
2931 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002932
2933 __ Bind(&miss);
2934 GenerateMiss(masm);
2935}
2936
2937
2938// This method handles the case where a compare stub had the wrong
2939// implementation. It calls a miss handler, which re-writes the stub. All other
2940// CompareICStub::Generate* methods should fall back into this one if their
2941// operands were not the expected types.
2942void CompareICStub::GenerateMiss(MacroAssembler* masm) {
2943 ASM_LOCATION("CompareICStub[Miss]");
2944
2945 Register stub_entry = x11;
2946 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002947 FrameScope scope(masm, StackFrame::INTERNAL);
2948 Register op = x10;
2949 Register left = x1;
2950 Register right = x0;
2951 // Preserve some caller-saved registers.
2952 __ Push(x1, x0, lr);
2953 // Push the arguments.
2954 __ Mov(op, Smi::FromInt(this->op()));
2955 __ Push(left, right, op);
2956
2957 // Call the miss handler. This also pops the arguments.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002958 __ CallRuntime(Runtime::kCompareIC_Miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002959
2960 // Compute the entry point of the rewritten stub.
2961 __ Add(stub_entry, x0, Code::kHeaderSize - kHeapObjectTag);
2962 // Restore caller-saved registers.
2963 __ Pop(lr, x0, x1);
2964 }
2965
2966 // Tail-call to the new stub.
2967 __ Jump(stub_entry);
2968}
2969
2970
2971void SubStringStub::Generate(MacroAssembler* masm) {
2972 ASM_LOCATION("SubStringStub::Generate");
2973 Label runtime;
2974
2975 // Stack frame on entry.
2976 // lr: return address
2977 // jssp[0]: substring "to" offset
2978 // jssp[8]: substring "from" offset
2979 // jssp[16]: pointer to string object
2980
2981 // This stub is called from the native-call %_SubString(...), so
2982 // nothing can be assumed about the arguments. It is tested that:
2983 // "string" is a sequential string,
2984 // both "from" and "to" are smis, and
2985 // 0 <= from <= to <= string.length (in debug mode.)
2986 // If any of these assumptions fail, we call the runtime system.
2987
2988 static const int kToOffset = 0 * kPointerSize;
2989 static const int kFromOffset = 1 * kPointerSize;
2990 static const int kStringOffset = 2 * kPointerSize;
2991
2992 Register to = x0;
2993 Register from = x15;
2994 Register input_string = x10;
2995 Register input_length = x11;
2996 Register input_type = x12;
2997 Register result_string = x0;
2998 Register result_length = x1;
2999 Register temp = x3;
3000
3001 __ Peek(to, kToOffset);
3002 __ Peek(from, kFromOffset);
3003
3004 // Check that both from and to are smis. If not, jump to runtime.
3005 __ JumpIfEitherNotSmi(from, to, &runtime);
3006 __ SmiUntag(from);
3007 __ SmiUntag(to);
3008
3009 // Calculate difference between from and to. If to < from, branch to runtime.
3010 __ Subs(result_length, to, from);
3011 __ B(mi, &runtime);
3012
3013 // Check from is positive.
3014 __ Tbnz(from, kWSignBit, &runtime);
3015
3016 // Make sure first argument is a string.
3017 __ Peek(input_string, kStringOffset);
3018 __ JumpIfSmi(input_string, &runtime);
3019 __ IsObjectJSStringType(input_string, input_type, &runtime);
3020
3021 Label single_char;
3022 __ Cmp(result_length, 1);
3023 __ B(eq, &single_char);
3024
3025 // Short-cut for the case of trivial substring.
3026 Label return_x0;
3027 __ Ldrsw(input_length,
3028 UntagSmiFieldMemOperand(input_string, String::kLengthOffset));
3029
3030 __ Cmp(result_length, input_length);
3031 __ CmovX(x0, input_string, eq);
3032 // Return original string.
3033 __ B(eq, &return_x0);
3034
3035 // Longer than original string's length or negative: unsafe arguments.
3036 __ B(hi, &runtime);
3037
3038 // Shorter than original string's length: an actual substring.
3039
3040 // x0 to substring end character offset
3041 // x1 result_length length of substring result
3042 // x10 input_string pointer to input string object
3043 // x10 unpacked_string pointer to unpacked string object
3044 // x11 input_length length of input string
3045 // x12 input_type instance type of input string
3046 // x15 from substring start character offset
3047
3048 // Deal with different string types: update the index if necessary and put
3049 // the underlying string into register unpacked_string.
3050 Label underlying_unpacked, sliced_string, seq_or_external_string;
3051 Label update_instance_type;
3052 // If the string is not indirect, it can only be sequential or external.
3053 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3054 STATIC_ASSERT(kIsIndirectStringMask != 0);
3055
3056 // Test for string types, and branch/fall through to appropriate unpacking
3057 // code.
3058 __ Tst(input_type, kIsIndirectStringMask);
3059 __ B(eq, &seq_or_external_string);
3060 __ Tst(input_type, kSlicedNotConsMask);
3061 __ B(ne, &sliced_string);
3062
3063 Register unpacked_string = input_string;
3064
3065 // Cons string. Check whether it is flat, then fetch first part.
3066 __ Ldr(temp, FieldMemOperand(input_string, ConsString::kSecondOffset));
3067 __ JumpIfNotRoot(temp, Heap::kempty_stringRootIndex, &runtime);
3068 __ Ldr(unpacked_string,
3069 FieldMemOperand(input_string, ConsString::kFirstOffset));
3070 __ B(&update_instance_type);
3071
3072 __ Bind(&sliced_string);
3073 // Sliced string. Fetch parent and correct start index by offset.
3074 __ Ldrsw(temp,
3075 UntagSmiFieldMemOperand(input_string, SlicedString::kOffsetOffset));
3076 __ Add(from, from, temp);
3077 __ Ldr(unpacked_string,
3078 FieldMemOperand(input_string, SlicedString::kParentOffset));
3079
3080 __ Bind(&update_instance_type);
3081 __ Ldr(temp, FieldMemOperand(unpacked_string, HeapObject::kMapOffset));
3082 __ Ldrb(input_type, FieldMemOperand(temp, Map::kInstanceTypeOffset));
3083 // Now control must go to &underlying_unpacked. Since the no code is generated
3084 // before then we fall through instead of generating a useless branch.
3085
3086 __ Bind(&seq_or_external_string);
3087 // Sequential or external string. Registers unpacked_string and input_string
3088 // alias, so there's nothing to do here.
3089 // Note that if code is added here, the above code must be updated.
3090
3091 // x0 result_string pointer to result string object (uninit)
3092 // x1 result_length length of substring result
3093 // x10 unpacked_string pointer to unpacked string object
3094 // x11 input_length length of input string
3095 // x12 input_type instance type of input string
3096 // x15 from substring start character offset
3097 __ Bind(&underlying_unpacked);
3098
3099 if (FLAG_string_slices) {
3100 Label copy_routine;
3101 __ Cmp(result_length, SlicedString::kMinLength);
3102 // Short slice. Copy instead of slicing.
3103 __ B(lt, &copy_routine);
3104 // Allocate new sliced string. At this point we do not reload the instance
3105 // type including the string encoding because we simply rely on the info
3106 // provided by the original string. It does not matter if the original
3107 // string's encoding is wrong because we always have to recheck encoding of
3108 // the newly created string's parent anyway due to externalized strings.
3109 Label two_byte_slice, set_slice_header;
3110 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3111 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3112 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_slice);
3113 __ AllocateOneByteSlicedString(result_string, result_length, x3, x4,
3114 &runtime);
3115 __ B(&set_slice_header);
3116
3117 __ Bind(&two_byte_slice);
3118 __ AllocateTwoByteSlicedString(result_string, result_length, x3, x4,
3119 &runtime);
3120
3121 __ Bind(&set_slice_header);
3122 __ SmiTag(from);
3123 __ Str(from, FieldMemOperand(result_string, SlicedString::kOffsetOffset));
3124 __ Str(unpacked_string,
3125 FieldMemOperand(result_string, SlicedString::kParentOffset));
3126 __ B(&return_x0);
3127
3128 __ Bind(&copy_routine);
3129 }
3130
3131 // x0 result_string pointer to result string object (uninit)
3132 // x1 result_length length of substring result
3133 // x10 unpacked_string pointer to unpacked string object
3134 // x11 input_length length of input string
3135 // x12 input_type instance type of input string
3136 // x13 unpacked_char0 pointer to first char of unpacked string (uninit)
3137 // x13 substring_char0 pointer to first char of substring (uninit)
3138 // x14 result_char0 pointer to first char of result (uninit)
3139 // x15 from substring start character offset
3140 Register unpacked_char0 = x13;
3141 Register substring_char0 = x13;
3142 Register result_char0 = x14;
3143 Label two_byte_sequential, sequential_string, allocate_result;
3144 STATIC_ASSERT(kExternalStringTag != 0);
3145 STATIC_ASSERT(kSeqStringTag == 0);
3146
3147 __ Tst(input_type, kExternalStringTag);
3148 __ B(eq, &sequential_string);
3149
3150 __ Tst(input_type, kShortExternalStringTag);
3151 __ B(ne, &runtime);
3152 __ Ldr(unpacked_char0,
3153 FieldMemOperand(unpacked_string, ExternalString::kResourceDataOffset));
3154 // unpacked_char0 points to the first character of the underlying string.
3155 __ B(&allocate_result);
3156
3157 __ Bind(&sequential_string);
3158 // Locate first character of underlying subject string.
3159 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3160 __ Add(unpacked_char0, unpacked_string,
3161 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3162
3163 __ Bind(&allocate_result);
3164 // Sequential one-byte string. Allocate the result.
3165 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3166 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_sequential);
3167
3168 // Allocate and copy the resulting one-byte string.
3169 __ AllocateOneByteString(result_string, result_length, x3, x4, x5, &runtime);
3170
3171 // Locate first character of substring to copy.
3172 __ Add(substring_char0, unpacked_char0, from);
3173
3174 // Locate first character of result.
3175 __ Add(result_char0, result_string,
3176 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3177
3178 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3179 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3180 __ B(&return_x0);
3181
3182 // Allocate and copy the resulting two-byte string.
3183 __ Bind(&two_byte_sequential);
3184 __ AllocateTwoByteString(result_string, result_length, x3, x4, x5, &runtime);
3185
3186 // Locate first character of substring to copy.
3187 __ Add(substring_char0, unpacked_char0, Operand(from, LSL, 1));
3188
3189 // Locate first character of result.
3190 __ Add(result_char0, result_string,
3191 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
3192
3193 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3194 __ Add(result_length, result_length, result_length);
3195 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3196
3197 __ Bind(&return_x0);
3198 Counters* counters = isolate()->counters();
3199 __ IncrementCounter(counters->sub_string_native(), 1, x3, x4);
3200 __ Drop(3);
3201 __ Ret();
3202
3203 __ Bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003204 __ TailCallRuntime(Runtime::kSubString);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003205
3206 __ bind(&single_char);
3207 // x1: result_length
3208 // x10: input_string
3209 // x12: input_type
3210 // x15: from (untagged)
3211 __ SmiTag(from);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003212 StringCharAtGenerator generator(input_string, from, result_length, x0,
3213 &runtime, &runtime, &runtime,
3214 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003215 generator.GenerateFast(masm);
3216 __ Drop(3);
3217 __ Ret();
3218 generator.SkipSlow(masm, &runtime);
3219}
3220
3221
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003222void ToNumberStub::Generate(MacroAssembler* masm) {
3223 // The ToNumber stub takes one argument in x0.
3224 Label not_smi;
3225 __ JumpIfNotSmi(x0, &not_smi);
3226 __ Ret();
3227 __ Bind(&not_smi);
3228
3229 Label not_heap_number;
3230 __ Ldr(x1, FieldMemOperand(x0, HeapObject::kMapOffset));
3231 __ Ldrb(x1, FieldMemOperand(x1, Map::kInstanceTypeOffset));
3232 // x0: object
3233 // x1: instance type
3234 __ Cmp(x1, HEAP_NUMBER_TYPE);
3235 __ B(ne, &not_heap_number);
3236 __ Ret();
3237 __ Bind(&not_heap_number);
3238
3239 Label not_string, slow_string;
3240 __ Cmp(x1, FIRST_NONSTRING_TYPE);
3241 __ B(hs, &not_string);
3242 // Check if string has a cached array index.
3243 __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset));
3244 __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask));
3245 __ B(ne, &slow_string);
3246 __ IndexFromHash(x2, x0);
3247 __ Ret();
3248 __ Bind(&slow_string);
3249 __ Push(x0); // Push argument.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003250 __ TailCallRuntime(Runtime::kStringToNumber);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003251 __ Bind(&not_string);
3252
3253 Label not_oddball;
3254 __ Cmp(x1, ODDBALL_TYPE);
3255 __ B(ne, &not_oddball);
3256 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
3257 __ Ret();
3258 __ Bind(&not_oddball);
3259
3260 __ Push(x0); // Push argument.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003261 __ TailCallRuntime(Runtime::kToNumber);
3262}
3263
3264
3265void ToLengthStub::Generate(MacroAssembler* masm) {
3266 // The ToLength stub takes one argument in x0.
3267 Label not_smi;
3268 __ JumpIfNotSmi(x0, &not_smi);
3269 STATIC_ASSERT(kSmiTag == 0);
3270 __ Tst(x0, x0);
3271 __ Csel(x0, x0, Operand(0), ge);
3272 __ Ret();
3273 __ Bind(&not_smi);
3274
3275 __ Push(x0); // Push argument.
3276 __ TailCallRuntime(Runtime::kToLength);
3277}
3278
3279
3280void ToStringStub::Generate(MacroAssembler* masm) {
3281 // The ToString stub takes one argument in x0.
3282 Label is_number;
3283 __ JumpIfSmi(x0, &is_number);
3284
3285 Label not_string;
3286 __ JumpIfObjectType(x0, x1, x1, FIRST_NONSTRING_TYPE, &not_string, hs);
3287 // x0: receiver
3288 // x1: receiver instance type
3289 __ Ret();
3290 __ Bind(&not_string);
3291
3292 Label not_heap_number;
3293 __ Cmp(x1, HEAP_NUMBER_TYPE);
3294 __ B(ne, &not_heap_number);
3295 __ Bind(&is_number);
3296 NumberToStringStub stub(isolate());
3297 __ TailCallStub(&stub);
3298 __ Bind(&not_heap_number);
3299
3300 Label not_oddball;
3301 __ Cmp(x1, ODDBALL_TYPE);
3302 __ B(ne, &not_oddball);
3303 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToStringOffset));
3304 __ Ret();
3305 __ Bind(&not_oddball);
3306
3307 __ Push(x0); // Push argument.
3308 __ TailCallRuntime(Runtime::kToString);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003309}
3310
3311
Ben Murdoch097c5b22016-05-18 11:27:45 +01003312void ToNameStub::Generate(MacroAssembler* masm) {
3313 // The ToName stub takes one argument in x0.
3314 Label is_number;
3315 __ JumpIfSmi(x0, &is_number);
3316
3317 Label not_name;
3318 STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
3319 __ JumpIfObjectType(x0, x1, x1, LAST_NAME_TYPE, &not_name, hi);
3320 // x0: receiver
3321 // x1: receiver instance type
3322 __ Ret();
3323 __ Bind(&not_name);
3324
3325 Label not_heap_number;
3326 __ Cmp(x1, HEAP_NUMBER_TYPE);
3327 __ B(ne, &not_heap_number);
3328 __ Bind(&is_number);
3329 NumberToStringStub stub(isolate());
3330 __ TailCallStub(&stub);
3331 __ Bind(&not_heap_number);
3332
3333 Label not_oddball;
3334 __ Cmp(x1, ODDBALL_TYPE);
3335 __ B(ne, &not_oddball);
3336 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToStringOffset));
3337 __ Ret();
3338 __ Bind(&not_oddball);
3339
3340 __ Push(x0); // Push argument.
3341 __ TailCallRuntime(Runtime::kToName);
3342}
3343
3344
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003345void StringHelper::GenerateFlatOneByteStringEquals(
3346 MacroAssembler* masm, Register left, Register right, Register scratch1,
3347 Register scratch2, Register scratch3) {
3348 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3));
3349 Register result = x0;
3350 Register left_length = scratch1;
3351 Register right_length = scratch2;
3352
3353 // Compare lengths. If lengths differ, strings can't be equal. Lengths are
3354 // smis, and don't need to be untagged.
3355 Label strings_not_equal, check_zero_length;
3356 __ Ldr(left_length, FieldMemOperand(left, String::kLengthOffset));
3357 __ Ldr(right_length, FieldMemOperand(right, String::kLengthOffset));
3358 __ Cmp(left_length, right_length);
3359 __ B(eq, &check_zero_length);
3360
3361 __ Bind(&strings_not_equal);
3362 __ Mov(result, Smi::FromInt(NOT_EQUAL));
3363 __ Ret();
3364
3365 // Check if the length is zero. If so, the strings must be equal (and empty.)
3366 Label compare_chars;
3367 __ Bind(&check_zero_length);
3368 STATIC_ASSERT(kSmiTag == 0);
3369 __ Cbnz(left_length, &compare_chars);
3370 __ Mov(result, Smi::FromInt(EQUAL));
3371 __ Ret();
3372
3373 // Compare characters. Falls through if all characters are equal.
3374 __ Bind(&compare_chars);
3375 GenerateOneByteCharsCompareLoop(masm, left, right, left_length, scratch2,
3376 scratch3, &strings_not_equal);
3377
3378 // Characters in strings are equal.
3379 __ Mov(result, Smi::FromInt(EQUAL));
3380 __ Ret();
3381}
3382
3383
3384void StringHelper::GenerateCompareFlatOneByteStrings(
3385 MacroAssembler* masm, Register left, Register right, Register scratch1,
3386 Register scratch2, Register scratch3, Register scratch4) {
3387 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3, scratch4));
3388 Label result_not_equal, compare_lengths;
3389
3390 // Find minimum length and length difference.
3391 Register length_delta = scratch3;
3392 __ Ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3393 __ Ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3394 __ Subs(length_delta, scratch1, scratch2);
3395
3396 Register min_length = scratch1;
3397 __ Csel(min_length, scratch2, scratch1, gt);
3398 __ Cbz(min_length, &compare_lengths);
3399
3400 // Compare loop.
3401 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3402 scratch4, &result_not_equal);
3403
3404 // Compare lengths - strings up to min-length are equal.
3405 __ Bind(&compare_lengths);
3406
3407 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3408
3409 // Use length_delta as result if it's zero.
3410 Register result = x0;
3411 __ Subs(result, length_delta, 0);
3412
3413 __ Bind(&result_not_equal);
3414 Register greater = x10;
3415 Register less = x11;
3416 __ Mov(greater, Smi::FromInt(GREATER));
3417 __ Mov(less, Smi::FromInt(LESS));
3418 __ CmovX(result, greater, gt);
3419 __ CmovX(result, less, lt);
3420 __ Ret();
3421}
3422
3423
3424void StringHelper::GenerateOneByteCharsCompareLoop(
3425 MacroAssembler* masm, Register left, Register right, Register length,
3426 Register scratch1, Register scratch2, Label* chars_not_equal) {
3427 DCHECK(!AreAliased(left, right, length, scratch1, scratch2));
3428
3429 // Change index to run from -length to -1 by adding length to string
3430 // start. This means that loop ends when index reaches zero, which
3431 // doesn't need an additional compare.
3432 __ SmiUntag(length);
3433 __ Add(scratch1, length, SeqOneByteString::kHeaderSize - kHeapObjectTag);
3434 __ Add(left, left, scratch1);
3435 __ Add(right, right, scratch1);
3436
3437 Register index = length;
3438 __ Neg(index, length); // index = -length;
3439
3440 // Compare loop
3441 Label loop;
3442 __ Bind(&loop);
3443 __ Ldrb(scratch1, MemOperand(left, index));
3444 __ Ldrb(scratch2, MemOperand(right, index));
3445 __ Cmp(scratch1, scratch2);
3446 __ B(ne, chars_not_equal);
3447 __ Add(index, index, 1);
3448 __ Cbnz(index, &loop);
3449}
3450
3451
3452void StringCompareStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003453 // ----------- S t a t e -------------
3454 // -- x1 : left
3455 // -- x0 : right
3456 // -- lr : return address
3457 // -----------------------------------
3458 __ AssertString(x1);
3459 __ AssertString(x0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003460
3461 Label not_same;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003462 __ Cmp(x0, x1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003463 __ B(ne, &not_same);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003464 __ Mov(x0, Smi::FromInt(EQUAL));
3465 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x3,
3466 x4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003467 __ Ret();
3468
3469 __ Bind(&not_same);
3470
3471 // Check that both objects are sequential one-byte strings.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003472 Label runtime;
3473 __ JumpIfEitherIsNotSequentialOneByteStrings(x1, x0, x12, x13, &runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003474
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003475 // Compare flat one-byte strings natively.
3476 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x3,
3477 x4);
3478 StringHelper::GenerateCompareFlatOneByteStrings(masm, x1, x0, x12, x13, x14,
3479 x15);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003480
3481 // Call the runtime.
3482 // Returns -1 (less), 0 (equal), or 1 (greater) tagged as a small integer.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003483 __ Bind(&runtime);
3484 __ Push(x1, x0);
3485 __ TailCallRuntime(Runtime::kStringCompare);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003486}
3487
3488
3489void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3490 // ----------- S t a t e -------------
3491 // -- x1 : left
3492 // -- x0 : right
3493 // -- lr : return address
3494 // -----------------------------------
3495
3496 // Load x2 with the allocation site. We stick an undefined dummy value here
3497 // and replace it with the real allocation site later when we instantiate this
3498 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3499 __ LoadObject(x2, handle(isolate()->heap()->undefined_value()));
3500
3501 // Make sure that we actually patched the allocation site.
3502 if (FLAG_debug_code) {
3503 __ AssertNotSmi(x2, kExpectedAllocationSite);
3504 __ Ldr(x10, FieldMemOperand(x2, HeapObject::kMapOffset));
3505 __ AssertRegisterIsRoot(x10, Heap::kAllocationSiteMapRootIndex,
3506 kExpectedAllocationSite);
3507 }
3508
3509 // Tail call into the stub that handles binary operations with allocation
3510 // sites.
3511 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3512 __ TailCallStub(&stub);
3513}
3514
3515
3516void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3517 // We need some extra registers for this stub, they have been allocated
3518 // but we need to save them before using them.
3519 regs_.Save(masm);
3520
3521 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3522 Label dont_need_remembered_set;
3523
3524 Register val = regs_.scratch0();
3525 __ Ldr(val, MemOperand(regs_.address()));
3526 __ JumpIfNotInNewSpace(val, &dont_need_remembered_set);
3527
Ben Murdoch097c5b22016-05-18 11:27:45 +01003528 __ JumpIfInNewSpace(regs_.object(), &dont_need_remembered_set);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003529
3530 // First notify the incremental marker if necessary, then update the
3531 // remembered set.
3532 CheckNeedsToInformIncrementalMarker(
3533 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
3534 InformIncrementalMarker(masm);
3535 regs_.Restore(masm); // Restore the extra scratch registers we used.
3536
3537 __ RememberedSetHelper(object(), address(),
3538 value(), // scratch1
3539 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
3540
3541 __ Bind(&dont_need_remembered_set);
3542 }
3543
3544 CheckNeedsToInformIncrementalMarker(
3545 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
3546 InformIncrementalMarker(masm);
3547 regs_.Restore(masm); // Restore the extra scratch registers we used.
3548 __ Ret();
3549}
3550
3551
3552void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
3553 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
3554 Register address =
3555 x0.Is(regs_.address()) ? regs_.scratch0() : regs_.address();
3556 DCHECK(!address.Is(regs_.object()));
3557 DCHECK(!address.Is(x0));
3558 __ Mov(address, regs_.address());
3559 __ Mov(x0, regs_.object());
3560 __ Mov(x1, address);
3561 __ Mov(x2, ExternalReference::isolate_address(isolate()));
3562
3563 AllowExternalCallThatCantCauseGC scope(masm);
3564 ExternalReference function =
3565 ExternalReference::incremental_marking_record_write_function(
3566 isolate());
3567 __ CallCFunction(function, 3, 0);
3568
3569 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
3570}
3571
3572
3573void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
3574 MacroAssembler* masm,
3575 OnNoNeedToInformIncrementalMarker on_no_need,
3576 Mode mode) {
3577 Label on_black;
3578 Label need_incremental;
3579 Label need_incremental_pop_scratch;
3580
3581 Register mem_chunk = regs_.scratch0();
3582 Register counter = regs_.scratch1();
3583 __ Bic(mem_chunk, regs_.object(), Page::kPageAlignmentMask);
3584 __ Ldr(counter,
3585 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
3586 __ Subs(counter, counter, 1);
3587 __ Str(counter,
3588 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
3589 __ B(mi, &need_incremental);
3590
3591 // If the object is not black we don't have to inform the incremental marker.
3592 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
3593
3594 regs_.Restore(masm); // Restore the extra scratch registers we used.
3595 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
3596 __ RememberedSetHelper(object(), address(),
3597 value(), // scratch1
3598 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
3599 } else {
3600 __ Ret();
3601 }
3602
3603 __ Bind(&on_black);
3604 // Get the value from the slot.
3605 Register val = regs_.scratch0();
3606 __ Ldr(val, MemOperand(regs_.address()));
3607
3608 if (mode == INCREMENTAL_COMPACTION) {
3609 Label ensure_not_white;
3610
3611 __ CheckPageFlagClear(val, regs_.scratch1(),
3612 MemoryChunk::kEvacuationCandidateMask,
3613 &ensure_not_white);
3614
3615 __ CheckPageFlagClear(regs_.object(),
3616 regs_.scratch1(),
3617 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
3618 &need_incremental);
3619
3620 __ Bind(&ensure_not_white);
3621 }
3622
3623 // We need extra registers for this, so we push the object and the address
3624 // register temporarily.
3625 __ Push(regs_.address(), regs_.object());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003626 __ JumpIfWhite(val,
3627 regs_.scratch1(), // Scratch.
3628 regs_.object(), // Scratch.
3629 regs_.address(), // Scratch.
3630 regs_.scratch2(), // Scratch.
3631 &need_incremental_pop_scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003632 __ Pop(regs_.object(), regs_.address());
3633
3634 regs_.Restore(masm); // Restore the extra scratch registers we used.
3635 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
3636 __ RememberedSetHelper(object(), address(),
3637 value(), // scratch1
3638 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
3639 } else {
3640 __ Ret();
3641 }
3642
3643 __ Bind(&need_incremental_pop_scratch);
3644 __ Pop(regs_.object(), regs_.address());
3645
3646 __ Bind(&need_incremental);
3647 // Fall through when we need to inform the incremental marker.
3648}
3649
3650
3651void RecordWriteStub::Generate(MacroAssembler* masm) {
3652 Label skip_to_incremental_noncompacting;
3653 Label skip_to_incremental_compacting;
3654
3655 // We patch these two first instructions back and forth between a nop and
3656 // real branch when we start and stop incremental heap marking.
3657 // Initially the stub is expected to be in STORE_BUFFER_ONLY mode, so 2 nops
3658 // are generated.
3659 // See RecordWriteStub::Patch for details.
3660 {
3661 InstructionAccurateScope scope(masm, 2);
3662 __ adr(xzr, &skip_to_incremental_noncompacting);
3663 __ adr(xzr, &skip_to_incremental_compacting);
3664 }
3665
3666 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3667 __ RememberedSetHelper(object(), address(),
3668 value(), // scratch1
3669 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
3670 }
3671 __ Ret();
3672
3673 __ Bind(&skip_to_incremental_noncompacting);
3674 GenerateIncremental(masm, INCREMENTAL);
3675
3676 __ Bind(&skip_to_incremental_compacting);
3677 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3678}
3679
3680
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003681void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
3682 CEntryStub ces(isolate(), 1, kSaveFPRegs);
3683 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
3684 int parameter_count_offset =
3685 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
3686 __ Ldr(x1, MemOperand(fp, parameter_count_offset));
3687 if (function_mode() == JS_FUNCTION_STUB_MODE) {
3688 __ Add(x1, x1, 1);
3689 }
3690 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
3691 __ Drop(x1);
3692 // Return to IC Miss stub, continuation still on stack.
3693 __ Ret();
3694}
3695
3696
3697void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003698 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3699 LoadICStub stub(isolate(), state());
3700 stub.GenerateForTrampoline(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003701}
3702
3703
3704void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003705 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3706 KeyedLoadICStub stub(isolate(), state());
3707 stub.GenerateForTrampoline(masm);
3708}
3709
3710
3711void CallICTrampolineStub::Generate(MacroAssembler* masm) {
3712 __ EmitLoadTypeFeedbackVector(x2);
3713 CallICStub stub(isolate(), state());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003714 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3715}
3716
3717
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003718void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
3719
3720
3721void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3722 GenerateImpl(masm, true);
3723}
3724
3725
3726static void HandleArrayCases(MacroAssembler* masm, Register feedback,
3727 Register receiver_map, Register scratch1,
3728 Register scratch2, bool is_polymorphic,
3729 Label* miss) {
3730 // feedback initially contains the feedback array
3731 Label next_loop, prepare_next;
3732 Label load_smi_map, compare_map;
3733 Label start_polymorphic;
3734
3735 Register cached_map = scratch1;
3736
3737 __ Ldr(cached_map,
3738 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
3739 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3740 __ Cmp(receiver_map, cached_map);
3741 __ B(ne, &start_polymorphic);
3742 // found, now call handler.
3743 Register handler = feedback;
3744 __ Ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
3745 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
3746 __ Jump(feedback);
3747
3748 Register length = scratch2;
3749 __ Bind(&start_polymorphic);
3750 __ Ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
3751 if (!is_polymorphic) {
3752 __ Cmp(length, Operand(Smi::FromInt(2)));
3753 __ B(eq, miss);
3754 }
3755
3756 Register too_far = length;
3757 Register pointer_reg = feedback;
3758
3759 // +-----+------+------+-----+-----+ ... ----+
3760 // | map | len | wm0 | h0 | wm1 | hN |
3761 // +-----+------+------+-----+-----+ ... ----+
3762 // 0 1 2 len-1
3763 // ^ ^
3764 // | |
3765 // pointer_reg too_far
3766 // aka feedback scratch2
3767 // also need receiver_map
3768 // use cached_map (scratch1) to look in the weak map values.
3769 __ Add(too_far, feedback,
3770 Operand::UntagSmiAndScale(length, kPointerSizeLog2));
3771 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
3772 __ Add(pointer_reg, feedback,
3773 FixedArray::OffsetOfElementAt(2) - kHeapObjectTag);
3774
3775 __ Bind(&next_loop);
3776 __ Ldr(cached_map, MemOperand(pointer_reg));
3777 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3778 __ Cmp(receiver_map, cached_map);
3779 __ B(ne, &prepare_next);
3780 __ Ldr(handler, MemOperand(pointer_reg, kPointerSize));
3781 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
3782 __ Jump(handler);
3783
3784 __ Bind(&prepare_next);
3785 __ Add(pointer_reg, pointer_reg, kPointerSize * 2);
3786 __ Cmp(pointer_reg, too_far);
3787 __ B(lt, &next_loop);
3788
3789 // We exhausted our array of map handler pairs.
3790 __ jmp(miss);
3791}
3792
3793
3794static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
3795 Register receiver_map, Register feedback,
3796 Register vector, Register slot,
3797 Register scratch, Label* compare_map,
3798 Label* load_smi_map, Label* try_array) {
3799 __ JumpIfSmi(receiver, load_smi_map);
3800 __ Ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
3801 __ bind(compare_map);
3802 Register cached_map = scratch;
3803 // Move the weak map into the weak_cell register.
3804 __ Ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
3805 __ Cmp(cached_map, receiver_map);
3806 __ B(ne, try_array);
3807
3808 Register handler = feedback;
3809 __ Add(handler, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
3810 __ Ldr(handler,
3811 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
3812 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
3813 __ Jump(handler);
3814}
3815
3816
3817void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3818 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
3819 Register name = LoadWithVectorDescriptor::NameRegister(); // x2
3820 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
3821 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
3822 Register feedback = x4;
3823 Register receiver_map = x5;
3824 Register scratch1 = x6;
3825
3826 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
3827 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3828
3829 // Try to quickly handle the monomorphic case without knowing for sure
3830 // if we have a weak cell in feedback. We do know it's safe to look
3831 // at WeakCell::kValueOffset.
3832 Label try_array, load_smi_map, compare_map;
3833 Label not_array, miss;
3834 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3835 scratch1, &compare_map, &load_smi_map, &try_array);
3836
3837 // Is it a fixed array?
3838 __ Bind(&try_array);
3839 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3840 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, &not_array);
3841 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, true, &miss);
3842
3843 __ Bind(&not_array);
3844 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
3845 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
3846 Code::ComputeHandlerFlags(Code::LOAD_IC));
3847 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
3848 receiver, name, feedback,
3849 receiver_map, scratch1, x7);
3850
3851 __ Bind(&miss);
3852 LoadIC::GenerateMiss(masm);
3853
3854 __ Bind(&load_smi_map);
3855 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3856 __ jmp(&compare_map);
3857}
3858
3859
3860void KeyedLoadICStub::Generate(MacroAssembler* masm) {
3861 GenerateImpl(masm, false);
3862}
3863
3864
3865void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3866 GenerateImpl(masm, true);
3867}
3868
3869
3870void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3871 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
3872 Register key = LoadWithVectorDescriptor::NameRegister(); // x2
3873 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
3874 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
3875 Register feedback = x4;
3876 Register receiver_map = x5;
3877 Register scratch1 = x6;
3878
3879 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
3880 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3881
3882 // Try to quickly handle the monomorphic case without knowing for sure
3883 // if we have a weak cell in feedback. We do know it's safe to look
3884 // at WeakCell::kValueOffset.
3885 Label try_array, load_smi_map, compare_map;
3886 Label not_array, miss;
3887 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3888 scratch1, &compare_map, &load_smi_map, &try_array);
3889
3890 __ Bind(&try_array);
3891 // Is it a fixed array?
3892 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3893 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, &not_array);
3894
3895 // We have a polymorphic element handler.
3896 Label polymorphic, try_poly_name;
3897 __ Bind(&polymorphic);
3898 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, true, &miss);
3899
3900 __ Bind(&not_array);
3901 // Is it generic?
3902 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
3903 &try_poly_name);
3904 Handle<Code> megamorphic_stub =
3905 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
3906 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
3907
3908 __ Bind(&try_poly_name);
3909 // We might have a name in feedback, and a fixed array in the next slot.
3910 __ Cmp(key, feedback);
3911 __ B(ne, &miss);
3912 // If the name comparison succeeded, we know we have a fixed array with
3913 // at least one map/handler pair.
3914 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
3915 __ Ldr(feedback,
3916 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
3917 HandleArrayCases(masm, feedback, receiver_map, scratch1, x7, false, &miss);
3918
3919 __ Bind(&miss);
3920 KeyedLoadIC::GenerateMiss(masm);
3921
3922 __ Bind(&load_smi_map);
3923 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3924 __ jmp(&compare_map);
3925}
3926
3927
3928void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
3929 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
3930 VectorStoreICStub stub(isolate(), state());
3931 stub.GenerateForTrampoline(masm);
3932}
3933
3934
3935void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
3936 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
3937 VectorKeyedStoreICStub stub(isolate(), state());
3938 stub.GenerateForTrampoline(masm);
3939}
3940
3941
3942void VectorStoreICStub::Generate(MacroAssembler* masm) {
3943 GenerateImpl(masm, false);
3944}
3945
3946
3947void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
3948 GenerateImpl(masm, true);
3949}
3950
3951
3952void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3953 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // x1
3954 Register key = VectorStoreICDescriptor::NameRegister(); // x2
3955 Register vector = VectorStoreICDescriptor::VectorRegister(); // x3
3956 Register slot = VectorStoreICDescriptor::SlotRegister(); // x4
3957 DCHECK(VectorStoreICDescriptor::ValueRegister().is(x0)); // x0
3958 Register feedback = x5;
3959 Register receiver_map = x6;
3960 Register scratch1 = x7;
3961
3962 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
3963 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3964
3965 // Try to quickly handle the monomorphic case without knowing for sure
3966 // if we have a weak cell in feedback. We do know it's safe to look
3967 // at WeakCell::kValueOffset.
3968 Label try_array, load_smi_map, compare_map;
3969 Label not_array, miss;
3970 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3971 scratch1, &compare_map, &load_smi_map, &try_array);
3972
3973 // Is it a fixed array?
3974 __ Bind(&try_array);
3975 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3976 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, &not_array);
3977 HandleArrayCases(masm, feedback, receiver_map, scratch1, x8, true, &miss);
3978
3979 __ Bind(&not_array);
3980 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
3981 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
3982 Code::ComputeHandlerFlags(Code::STORE_IC));
3983 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags,
3984 receiver, key, feedback,
3985 receiver_map, scratch1, x8);
3986
3987 __ Bind(&miss);
3988 StoreIC::GenerateMiss(masm);
3989
3990 __ Bind(&load_smi_map);
3991 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3992 __ jmp(&compare_map);
3993}
3994
3995
3996void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
3997 GenerateImpl(masm, false);
3998}
3999
4000
4001void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4002 GenerateImpl(masm, true);
4003}
4004
4005
4006static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4007 Register receiver_map, Register scratch1,
4008 Register scratch2, Label* miss) {
4009 // feedback initially contains the feedback array
4010 Label next_loop, prepare_next;
4011 Label start_polymorphic;
4012 Label transition_call;
4013
4014 Register cached_map = scratch1;
4015 Register too_far = scratch2;
4016 Register pointer_reg = feedback;
4017
4018 __ Ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4019
4020 // +-----+------+------+-----+-----+-----+ ... ----+
4021 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4022 // +-----+------+------+-----+-----+ ----+ ... ----+
4023 // 0 1 2 len-1
4024 // ^ ^
4025 // | |
4026 // pointer_reg too_far
4027 // aka feedback scratch2
4028 // also need receiver_map
4029 // use cached_map (scratch1) to look in the weak map values.
4030 __ Add(too_far, feedback,
4031 Operand::UntagSmiAndScale(too_far, kPointerSizeLog2));
4032 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
4033 __ Add(pointer_reg, feedback,
4034 FixedArray::OffsetOfElementAt(0) - kHeapObjectTag);
4035
4036 __ Bind(&next_loop);
4037 __ Ldr(cached_map, MemOperand(pointer_reg));
4038 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4039 __ Cmp(receiver_map, cached_map);
4040 __ B(ne, &prepare_next);
4041 // Is it a transitioning store?
4042 __ Ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4043 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4044 __ B(ne, &transition_call);
4045
4046 __ Ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4047 __ Add(pointer_reg, pointer_reg, Code::kHeaderSize - kHeapObjectTag);
4048 __ Jump(pointer_reg);
4049
4050 __ Bind(&transition_call);
4051 __ Ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4052 __ JumpIfSmi(too_far, miss);
4053
4054 __ Ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4055 // Load the map into the correct register.
4056 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4057 __ mov(feedback, too_far);
4058 __ Add(receiver_map, receiver_map, Code::kHeaderSize - kHeapObjectTag);
4059 __ Jump(receiver_map);
4060
4061 __ Bind(&prepare_next);
4062 __ Add(pointer_reg, pointer_reg, kPointerSize * 3);
4063 __ Cmp(pointer_reg, too_far);
4064 __ B(lt, &next_loop);
4065
4066 // We exhausted our array of map handler pairs.
4067 __ jmp(miss);
4068}
4069
4070
4071void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4072 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // x1
4073 Register key = VectorStoreICDescriptor::NameRegister(); // x2
4074 Register vector = VectorStoreICDescriptor::VectorRegister(); // x3
4075 Register slot = VectorStoreICDescriptor::SlotRegister(); // x4
4076 DCHECK(VectorStoreICDescriptor::ValueRegister().is(x0)); // x0
4077 Register feedback = x5;
4078 Register receiver_map = x6;
4079 Register scratch1 = x7;
4080
4081 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4082 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4083
4084 // Try to quickly handle the monomorphic case without knowing for sure
4085 // if we have a weak cell in feedback. We do know it's safe to look
4086 // at WeakCell::kValueOffset.
4087 Label try_array, load_smi_map, compare_map;
4088 Label not_array, miss;
4089 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4090 scratch1, &compare_map, &load_smi_map, &try_array);
4091
4092 __ Bind(&try_array);
4093 // Is it a fixed array?
4094 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4095 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, &not_array);
4096
4097 // We have a polymorphic element handler.
4098 Label try_poly_name;
4099 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, x8, &miss);
4100
4101 __ Bind(&not_array);
4102 // Is it generic?
4103 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
4104 &try_poly_name);
4105 Handle<Code> megamorphic_stub =
4106 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4107 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4108
4109 __ Bind(&try_poly_name);
4110 // We might have a name in feedback, and a fixed array in the next slot.
4111 __ Cmp(key, feedback);
4112 __ B(ne, &miss);
4113 // If the name comparison succeeded, we know we have a fixed array with
4114 // at least one map/handler pair.
4115 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4116 __ Ldr(feedback,
4117 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4118 HandleArrayCases(masm, feedback, receiver_map, scratch1, x8, false, &miss);
4119
4120 __ Bind(&miss);
4121 KeyedStoreIC::GenerateMiss(masm);
4122
4123 __ Bind(&load_smi_map);
4124 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4125 __ jmp(&compare_map);
4126}
4127
4128
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004129// The entry hook is a "BumpSystemStackPointer" instruction (sub), followed by
4130// a "Push lr" instruction, followed by a call.
4131static const unsigned int kProfileEntryHookCallSize =
4132 Assembler::kCallSizeWithRelocation + (2 * kInstructionSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004133
4134
4135void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4136 if (masm->isolate()->function_entry_hook() != NULL) {
4137 ProfileEntryHookStub stub(masm->isolate());
4138 Assembler::BlockConstPoolScope no_const_pools(masm);
4139 DontEmitDebugCodeScope no_debug_code(masm);
4140 Label entry_hook_call_start;
4141 __ Bind(&entry_hook_call_start);
4142 __ Push(lr);
4143 __ CallStub(&stub);
4144 DCHECK(masm->SizeOfCodeGeneratedSince(&entry_hook_call_start) ==
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004145 kProfileEntryHookCallSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004146
4147 __ Pop(lr);
4148 }
4149}
4150
4151
4152void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4153 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
4154
4155 // Save all kCallerSaved registers (including lr), since this can be called
4156 // from anywhere.
4157 // TODO(jbramley): What about FP registers?
4158 __ PushCPURegList(kCallerSaved);
4159 DCHECK(kCallerSaved.IncludesAliasOf(lr));
4160 const int kNumSavedRegs = kCallerSaved.Count();
4161
4162 // Compute the function's address as the first argument.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004163 __ Sub(x0, lr, kProfileEntryHookCallSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004164
4165#if V8_HOST_ARCH_ARM64
4166 uintptr_t entry_hook =
4167 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
4168 __ Mov(x10, entry_hook);
4169#else
4170 // Under the simulator we need to indirect the entry hook through a trampoline
4171 // function at a known address.
4172 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4173 __ Mov(x10, Operand(ExternalReference(&dispatcher,
4174 ExternalReference::BUILTIN_CALL,
4175 isolate())));
4176 // It additionally takes an isolate as a third parameter
4177 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4178#endif
4179
4180 // The caller's return address is above the saved temporaries.
4181 // Grab its location for the second argument to the hook.
4182 __ Add(x1, __ StackPointer(), kNumSavedRegs * kPointerSize);
4183
4184 {
4185 // Create a dummy frame, as CallCFunction requires this.
4186 FrameScope frame(masm, StackFrame::MANUAL);
4187 __ CallCFunction(x10, 2, 0);
4188 }
4189
4190 __ PopCPURegList(kCallerSaved);
4191 __ Ret();
4192}
4193
4194
4195void DirectCEntryStub::Generate(MacroAssembler* masm) {
4196 // When calling into C++ code the stack pointer must be csp.
4197 // Therefore this code must use csp for peek/poke operations when the
4198 // stub is generated. When the stub is called
4199 // (via DirectCEntryStub::GenerateCall), the caller must setup an ExitFrame
4200 // and configure the stack pointer *before* doing the call.
4201 const Register old_stack_pointer = __ StackPointer();
4202 __ SetStackPointer(csp);
4203
4204 // Put return address on the stack (accessible to GC through exit frame pc).
4205 __ Poke(lr, 0);
4206 // Call the C++ function.
4207 __ Blr(x10);
4208 // Return to calling code.
4209 __ Peek(lr, 0);
4210 __ AssertFPCRState();
4211 __ Ret();
4212
4213 __ SetStackPointer(old_stack_pointer);
4214}
4215
4216void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4217 Register target) {
4218 // Make sure the caller configured the stack pointer (see comment in
4219 // DirectCEntryStub::Generate).
4220 DCHECK(csp.Is(__ StackPointer()));
4221
4222 intptr_t code =
4223 reinterpret_cast<intptr_t>(GetCode().location());
4224 __ Mov(lr, Operand(code, RelocInfo::CODE_TARGET));
4225 __ Mov(x10, target);
4226 // Branch to the stub.
4227 __ Blr(lr);
4228}
4229
4230
4231// Probe the name dictionary in the 'elements' register.
4232// Jump to the 'done' label if a property with the given name is found.
4233// Jump to the 'miss' label otherwise.
4234//
4235// If lookup was successful 'scratch2' will be equal to elements + 4 * index.
4236// 'elements' and 'name' registers are preserved on miss.
4237void NameDictionaryLookupStub::GeneratePositiveLookup(
4238 MacroAssembler* masm,
4239 Label* miss,
4240 Label* done,
4241 Register elements,
4242 Register name,
4243 Register scratch1,
4244 Register scratch2) {
4245 DCHECK(!AreAliased(elements, name, scratch1, scratch2));
4246
4247 // Assert that name contains a string.
4248 __ AssertName(name);
4249
4250 // Compute the capacity mask.
4251 __ Ldrsw(scratch1, UntagSmiFieldMemOperand(elements, kCapacityOffset));
4252 __ Sub(scratch1, scratch1, 1);
4253
4254 // Generate an unrolled loop that performs a few probes before giving up.
4255 for (int i = 0; i < kInlinedProbes; i++) {
4256 // Compute the masked index: (hash + i + i * i) & mask.
4257 __ Ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4258 if (i > 0) {
4259 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4260 // the hash in a separate instruction. The value hash + i + i * i is right
4261 // shifted in the following and instruction.
4262 DCHECK(NameDictionary::GetProbeOffset(i) <
4263 1 << (32 - Name::kHashFieldOffset));
4264 __ Add(scratch2, scratch2, Operand(
4265 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4266 }
4267 __ And(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
4268
4269 // Scale the index by multiplying by the element size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004270 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004271 __ Add(scratch2, scratch2, Operand(scratch2, LSL, 1));
4272
4273 // Check if the key is identical to the name.
4274 UseScratchRegisterScope temps(masm);
4275 Register scratch3 = temps.AcquireX();
4276 __ Add(scratch2, elements, Operand(scratch2, LSL, kPointerSizeLog2));
4277 __ Ldr(scratch3, FieldMemOperand(scratch2, kElementsStartOffset));
4278 __ Cmp(name, scratch3);
4279 __ B(eq, done);
4280 }
4281
4282 // The inlined probes didn't find the entry.
4283 // Call the complete stub to scan the whole dictionary.
4284
4285 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4286 spill_list.Combine(lr);
4287 spill_list.Remove(scratch1);
4288 spill_list.Remove(scratch2);
4289
4290 __ PushCPURegList(spill_list);
4291
4292 if (name.is(x0)) {
4293 DCHECK(!elements.is(x1));
4294 __ Mov(x1, name);
4295 __ Mov(x0, elements);
4296 } else {
4297 __ Mov(x0, elements);
4298 __ Mov(x1, name);
4299 }
4300
4301 Label not_found;
4302 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4303 __ CallStub(&stub);
4304 __ Cbz(x0, &not_found);
4305 __ Mov(scratch2, x2); // Move entry index into scratch2.
4306 __ PopCPURegList(spill_list);
4307 __ B(done);
4308
4309 __ Bind(&not_found);
4310 __ PopCPURegList(spill_list);
4311 __ B(miss);
4312}
4313
4314
4315void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4316 Label* miss,
4317 Label* done,
4318 Register receiver,
4319 Register properties,
4320 Handle<Name> name,
4321 Register scratch0) {
4322 DCHECK(!AreAliased(receiver, properties, scratch0));
4323 DCHECK(name->IsUniqueName());
4324 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4325 // not equal to the name and kProbes-th slot is not used (its name is the
4326 // undefined value), it guarantees the hash table doesn't contain the
4327 // property. It's true even if some slots represent deleted properties
4328 // (their names are the hole value).
4329 for (int i = 0; i < kInlinedProbes; i++) {
4330 // scratch0 points to properties hash.
4331 // Compute the masked index: (hash + i + i * i) & mask.
4332 Register index = scratch0;
4333 // Capacity is smi 2^n.
4334 __ Ldrsw(index, UntagSmiFieldMemOperand(properties, kCapacityOffset));
4335 __ Sub(index, index, 1);
4336 __ And(index, index, name->Hash() + NameDictionary::GetProbeOffset(i));
4337
4338 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004339 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004340 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
4341
4342 Register entity_name = scratch0;
4343 // Having undefined at this place means the name is not contained.
4344 Register tmp = index;
4345 __ Add(tmp, properties, Operand(index, LSL, kPointerSizeLog2));
4346 __ Ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4347
4348 __ JumpIfRoot(entity_name, Heap::kUndefinedValueRootIndex, done);
4349
4350 // Stop if found the property.
4351 __ Cmp(entity_name, Operand(name));
4352 __ B(eq, miss);
4353
4354 Label good;
4355 __ JumpIfRoot(entity_name, Heap::kTheHoleValueRootIndex, &good);
4356
4357 // Check if the entry name is not a unique name.
4358 __ Ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4359 __ Ldrb(entity_name,
4360 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4361 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4362 __ Bind(&good);
4363 }
4364
4365 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4366 spill_list.Combine(lr);
4367 spill_list.Remove(scratch0); // Scratch registers don't need to be preserved.
4368
4369 __ PushCPURegList(spill_list);
4370
4371 __ Ldr(x0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4372 __ Mov(x1, Operand(name));
4373 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4374 __ CallStub(&stub);
4375 // Move stub return value to scratch0. Note that scratch0 is not included in
4376 // spill_list and won't be clobbered by PopCPURegList.
4377 __ Mov(scratch0, x0);
4378 __ PopCPURegList(spill_list);
4379
4380 __ Cbz(scratch0, done);
4381 __ B(miss);
4382}
4383
4384
4385void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4386 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4387 // we cannot call anything that could cause a GC from this stub.
4388 //
4389 // Arguments are in x0 and x1:
4390 // x0: property dictionary.
4391 // x1: the name of the property we are looking for.
4392 //
4393 // Return value is in x0 and is zero if lookup failed, non zero otherwise.
4394 // If the lookup is successful, x2 will contains the index of the entry.
4395
4396 Register result = x0;
4397 Register dictionary = x0;
4398 Register key = x1;
4399 Register index = x2;
4400 Register mask = x3;
4401 Register hash = x4;
4402 Register undefined = x5;
4403 Register entry_key = x6;
4404
4405 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4406
4407 __ Ldrsw(mask, UntagSmiFieldMemOperand(dictionary, kCapacityOffset));
4408 __ Sub(mask, mask, 1);
4409
4410 __ Ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4411 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4412
4413 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4414 // Compute the masked index: (hash + i + i * i) & mask.
4415 // Capacity is smi 2^n.
4416 if (i > 0) {
4417 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4418 // the hash in a separate instruction. The value hash + i + i * i is right
4419 // shifted in the following and instruction.
4420 DCHECK(NameDictionary::GetProbeOffset(i) <
4421 1 << (32 - Name::kHashFieldOffset));
4422 __ Add(index, hash,
4423 NameDictionary::GetProbeOffset(i) << Name::kHashShift);
4424 } else {
4425 __ Mov(index, hash);
4426 }
4427 __ And(index, mask, Operand(index, LSR, Name::kHashShift));
4428
4429 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004430 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004431 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
4432
4433 __ Add(index, dictionary, Operand(index, LSL, kPointerSizeLog2));
4434 __ Ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
4435
4436 // Having undefined at this place means the name is not contained.
4437 __ Cmp(entry_key, undefined);
4438 __ B(eq, &not_in_dictionary);
4439
4440 // Stop if found the property.
4441 __ Cmp(entry_key, key);
4442 __ B(eq, &in_dictionary);
4443
4444 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4445 // Check if the entry name is not a unique name.
4446 __ Ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4447 __ Ldrb(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4448 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4449 }
4450 }
4451
4452 __ Bind(&maybe_in_dictionary);
4453 // If we are doing negative lookup then probing failure should be
4454 // treated as a lookup success. For positive lookup, probing failure
4455 // should be treated as lookup failure.
4456 if (mode() == POSITIVE_LOOKUP) {
4457 __ Mov(result, 0);
4458 __ Ret();
4459 }
4460
4461 __ Bind(&in_dictionary);
4462 __ Mov(result, 1);
4463 __ Ret();
4464
4465 __ Bind(&not_in_dictionary);
4466 __ Mov(result, 0);
4467 __ Ret();
4468}
4469
4470
4471template<class T>
4472static void CreateArrayDispatch(MacroAssembler* masm,
4473 AllocationSiteOverrideMode mode) {
4474 ASM_LOCATION("CreateArrayDispatch");
4475 if (mode == DISABLE_ALLOCATION_SITES) {
4476 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4477 __ TailCallStub(&stub);
4478
4479 } else if (mode == DONT_OVERRIDE) {
4480 Register kind = x3;
4481 int last_index =
4482 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
4483 for (int i = 0; i <= last_index; ++i) {
4484 Label next;
4485 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
4486 // TODO(jbramley): Is this the best way to handle this? Can we make the
4487 // tail calls conditional, rather than hopping over each one?
4488 __ CompareAndBranch(kind, candidate_kind, ne, &next);
4489 T stub(masm->isolate(), candidate_kind);
4490 __ TailCallStub(&stub);
4491 __ Bind(&next);
4492 }
4493
4494 // If we reached this point there is a problem.
4495 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4496
4497 } else {
4498 UNREACHABLE();
4499 }
4500}
4501
4502
4503// TODO(jbramley): If this needs to be a special case, make it a proper template
4504// specialization, and not a separate function.
4505static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4506 AllocationSiteOverrideMode mode) {
4507 ASM_LOCATION("CreateArrayDispatchOneArgument");
4508 // x0 - argc
4509 // x1 - constructor?
4510 // x2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4511 // x3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4512 // sp[0] - last argument
4513
4514 Register allocation_site = x2;
4515 Register kind = x3;
4516
4517 Label normal_sequence;
4518 if (mode == DONT_OVERRIDE) {
4519 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4520 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4521 STATIC_ASSERT(FAST_ELEMENTS == 2);
4522 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4523 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4524 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4525
4526 // Is the low bit set? If so, the array is holey.
4527 __ Tbnz(kind, 0, &normal_sequence);
4528 }
4529
4530 // Look at the last argument.
4531 // TODO(jbramley): What does a 0 argument represent?
4532 __ Peek(x10, 0);
4533 __ Cbz(x10, &normal_sequence);
4534
4535 if (mode == DISABLE_ALLOCATION_SITES) {
4536 ElementsKind initial = GetInitialFastElementsKind();
4537 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4538
4539 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4540 holey_initial,
4541 DISABLE_ALLOCATION_SITES);
4542 __ TailCallStub(&stub_holey);
4543
4544 __ Bind(&normal_sequence);
4545 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4546 initial,
4547 DISABLE_ALLOCATION_SITES);
4548 __ TailCallStub(&stub);
4549 } else if (mode == DONT_OVERRIDE) {
4550 // We are going to create a holey array, but our kind is non-holey.
4551 // Fix kind and retry (only if we have an allocation site in the slot).
4552 __ Orr(kind, kind, 1);
4553
4554 if (FLAG_debug_code) {
4555 __ Ldr(x10, FieldMemOperand(allocation_site, 0));
4556 __ JumpIfNotRoot(x10, Heap::kAllocationSiteMapRootIndex,
4557 &normal_sequence);
4558 __ Assert(eq, kExpectedAllocationSite);
4559 }
4560
4561 // Save the resulting elements kind in type info. We can't just store 'kind'
4562 // in the AllocationSite::transition_info field because elements kind is
4563 // restricted to a portion of the field; upper bits need to be left alone.
4564 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4565 __ Ldr(x11, FieldMemOperand(allocation_site,
4566 AllocationSite::kTransitionInfoOffset));
4567 __ Add(x11, x11, Smi::FromInt(kFastElementsKindPackedToHoley));
4568 __ Str(x11, FieldMemOperand(allocation_site,
4569 AllocationSite::kTransitionInfoOffset));
4570
4571 __ Bind(&normal_sequence);
4572 int last_index =
4573 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
4574 for (int i = 0; i <= last_index; ++i) {
4575 Label next;
4576 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
4577 __ CompareAndBranch(kind, candidate_kind, ne, &next);
4578 ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind);
4579 __ TailCallStub(&stub);
4580 __ Bind(&next);
4581 }
4582
4583 // If we reached this point there is a problem.
4584 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4585 } else {
4586 UNREACHABLE();
4587 }
4588}
4589
4590
4591template<class T>
4592static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4593 int to_index = GetSequenceIndexFromFastElementsKind(
4594 TERMINAL_FAST_ELEMENTS_KIND);
4595 for (int i = 0; i <= to_index; ++i) {
4596 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4597 T stub(isolate, kind);
4598 stub.GetCode();
4599 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4600 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4601 stub1.GetCode();
4602 }
4603 }
4604}
4605
4606
4607void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4608 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4609 isolate);
4610 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4611 isolate);
4612 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4613 isolate);
4614}
4615
4616
4617void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4618 Isolate* isolate) {
4619 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4620 for (int i = 0; i < 2; i++) {
4621 // For internal arrays we only need a few things
4622 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4623 stubh1.GetCode();
4624 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4625 stubh2.GetCode();
4626 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4627 stubh3.GetCode();
4628 }
4629}
4630
4631
4632void ArrayConstructorStub::GenerateDispatchToArrayStub(
4633 MacroAssembler* masm,
4634 AllocationSiteOverrideMode mode) {
4635 Register argc = x0;
4636 if (argument_count() == ANY) {
4637 Label zero_case, n_case;
4638 __ Cbz(argc, &zero_case);
4639 __ Cmp(argc, 1);
4640 __ B(ne, &n_case);
4641
4642 // One argument.
4643 CreateArrayDispatchOneArgument(masm, mode);
4644
4645 __ Bind(&zero_case);
4646 // No arguments.
4647 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4648
4649 __ Bind(&n_case);
4650 // N arguments.
4651 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4652
4653 } else if (argument_count() == NONE) {
4654 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4655 } else if (argument_count() == ONE) {
4656 CreateArrayDispatchOneArgument(masm, mode);
4657 } else if (argument_count() == MORE_THAN_ONE) {
4658 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4659 } else {
4660 UNREACHABLE();
4661 }
4662}
4663
4664
4665void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4666 ASM_LOCATION("ArrayConstructorStub::Generate");
4667 // ----------- S t a t e -------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004668 // -- x0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004669 // -- x1 : constructor
4670 // -- x2 : AllocationSite or undefined
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004671 // -- x3 : new target
4672 // -- sp[0] : last argument
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004673 // -----------------------------------
4674 Register constructor = x1;
4675 Register allocation_site = x2;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004676 Register new_target = x3;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004677
4678 if (FLAG_debug_code) {
4679 // The array construct code is only set for the global and natives
4680 // builtin Array functions which always have maps.
4681
4682 Label unexpected_map, map_ok;
4683 // Initial map for the builtin Array function should be a map.
4684 __ Ldr(x10, FieldMemOperand(constructor,
4685 JSFunction::kPrototypeOrInitialMapOffset));
4686 // Will both indicate a NULL and a Smi.
4687 __ JumpIfSmi(x10, &unexpected_map);
4688 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
4689 __ Bind(&unexpected_map);
4690 __ Abort(kUnexpectedInitialMapForArrayFunction);
4691 __ Bind(&map_ok);
4692
4693 // We should either have undefined in the allocation_site register or a
4694 // valid AllocationSite.
4695 __ AssertUndefinedOrAllocationSite(allocation_site, x10);
4696 }
4697
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004698 // Enter the context of the Array function.
4699 __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
4700
4701 Label subclassing;
4702 __ Cmp(new_target, constructor);
4703 __ B(ne, &subclassing);
4704
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004705 Register kind = x3;
4706 Label no_info;
4707 // Get the elements kind and case on that.
4708 __ JumpIfRoot(allocation_site, Heap::kUndefinedValueRootIndex, &no_info);
4709
4710 __ Ldrsw(kind,
4711 UntagSmiFieldMemOperand(allocation_site,
4712 AllocationSite::kTransitionInfoOffset));
4713 __ And(kind, kind, AllocationSite::ElementsKindBits::kMask);
4714 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4715
4716 __ Bind(&no_info);
4717 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004718
4719 // Subclassing support.
4720 __ Bind(&subclassing);
4721 switch (argument_count()) {
4722 case ANY:
4723 case MORE_THAN_ONE:
4724 __ Poke(constructor, Operand(x0, LSL, kPointerSizeLog2));
4725 __ Add(x0, x0, Operand(3));
4726 break;
4727 case NONE:
4728 __ Poke(constructor, 0 * kPointerSize);
4729 __ Mov(x0, Operand(3));
4730 break;
4731 case ONE:
4732 __ Poke(constructor, 1 * kPointerSize);
4733 __ Mov(x0, Operand(4));
4734 break;
4735 }
4736 __ Push(new_target, allocation_site);
4737 __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004738}
4739
4740
4741void InternalArrayConstructorStub::GenerateCase(
4742 MacroAssembler* masm, ElementsKind kind) {
4743 Label zero_case, n_case;
4744 Register argc = x0;
4745
4746 __ Cbz(argc, &zero_case);
4747 __ CompareAndBranch(argc, 1, ne, &n_case);
4748
4749 // One argument.
4750 if (IsFastPackedElementsKind(kind)) {
4751 Label packed_case;
4752
4753 // We might need to create a holey array; look at the first argument.
4754 __ Peek(x10, 0);
4755 __ Cbz(x10, &packed_case);
4756
4757 InternalArraySingleArgumentConstructorStub
4758 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4759 __ TailCallStub(&stub1_holey);
4760
4761 __ Bind(&packed_case);
4762 }
4763 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4764 __ TailCallStub(&stub1);
4765
4766 __ Bind(&zero_case);
4767 // No arguments.
4768 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4769 __ TailCallStub(&stub0);
4770
4771 __ Bind(&n_case);
4772 // N arguments.
4773 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4774 __ TailCallStub(&stubN);
4775}
4776
4777
4778void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4779 // ----------- S t a t e -------------
4780 // -- x0 : argc
4781 // -- x1 : constructor
4782 // -- sp[0] : return address
4783 // -- sp[4] : last argument
4784 // -----------------------------------
4785
4786 Register constructor = x1;
4787
4788 if (FLAG_debug_code) {
4789 // The array construct code is only set for the global and natives
4790 // builtin Array functions which always have maps.
4791
4792 Label unexpected_map, map_ok;
4793 // Initial map for the builtin Array function should be a map.
4794 __ Ldr(x10, FieldMemOperand(constructor,
4795 JSFunction::kPrototypeOrInitialMapOffset));
4796 // Will both indicate a NULL and a Smi.
4797 __ JumpIfSmi(x10, &unexpected_map);
4798 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
4799 __ Bind(&unexpected_map);
4800 __ Abort(kUnexpectedInitialMapForArrayFunction);
4801 __ Bind(&map_ok);
4802 }
4803
4804 Register kind = w3;
4805 // Figure out the right elements kind
4806 __ Ldr(x10, FieldMemOperand(constructor,
4807 JSFunction::kPrototypeOrInitialMapOffset));
4808
4809 // Retrieve elements_kind from map.
4810 __ LoadElementsKindFromMap(kind, x10);
4811
4812 if (FLAG_debug_code) {
4813 Label done;
4814 __ Cmp(x3, FAST_ELEMENTS);
4815 __ Ccmp(x3, FAST_HOLEY_ELEMENTS, ZFlag, ne);
4816 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
4817 }
4818
4819 Label fast_elements_case;
4820 __ CompareAndBranch(kind, FAST_ELEMENTS, eq, &fast_elements_case);
4821 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4822
4823 __ Bind(&fast_elements_case);
4824 GenerateCase(masm, FAST_ELEMENTS);
4825}
4826
4827
Ben Murdoch097c5b22016-05-18 11:27:45 +01004828void FastNewObjectStub::Generate(MacroAssembler* masm) {
4829 // ----------- S t a t e -------------
4830 // -- x1 : target
4831 // -- x3 : new target
4832 // -- cp : context
4833 // -- lr : return address
4834 // -----------------------------------
4835 __ AssertFunction(x1);
4836 __ AssertReceiver(x3);
4837
4838 // Verify that the new target is a JSFunction.
4839 Label new_object;
4840 __ JumpIfNotObjectType(x3, x2, x2, JS_FUNCTION_TYPE, &new_object);
4841
4842 // Load the initial map and verify that it's in fact a map.
4843 __ Ldr(x2, FieldMemOperand(x3, JSFunction::kPrototypeOrInitialMapOffset));
4844 __ JumpIfSmi(x2, &new_object);
4845 __ JumpIfNotObjectType(x2, x0, x0, MAP_TYPE, &new_object);
4846
4847 // Fall back to runtime if the target differs from the new target's
4848 // initial map constructor.
4849 __ Ldr(x0, FieldMemOperand(x2, Map::kConstructorOrBackPointerOffset));
4850 __ CompareAndBranch(x0, x1, ne, &new_object);
4851
4852 // Allocate the JSObject on the heap.
4853 Label allocate, done_allocate;
4854 __ Ldrb(x4, FieldMemOperand(x2, Map::kInstanceSizeOffset));
4855 __ Allocate(x4, x0, x5, x6, &allocate, SIZE_IN_WORDS);
4856 __ Bind(&done_allocate);
4857
4858 // Initialize the JSObject fields.
4859 __ Mov(x1, x0);
4860 STATIC_ASSERT(JSObject::kMapOffset == 0 * kPointerSize);
4861 __ Str(x2, MemOperand(x1, kPointerSize, PostIndex));
4862 __ LoadRoot(x3, Heap::kEmptyFixedArrayRootIndex);
4863 STATIC_ASSERT(JSObject::kPropertiesOffset == 1 * kPointerSize);
4864 STATIC_ASSERT(JSObject::kElementsOffset == 2 * kPointerSize);
4865 __ Stp(x3, x3, MemOperand(x1, 2 * kPointerSize, PostIndex));
4866 STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize);
4867
4868 // ----------- S t a t e -------------
4869 // -- x0 : result (untagged)
4870 // -- x1 : result fields (untagged)
4871 // -- x5 : result end (untagged)
4872 // -- x2 : initial map
4873 // -- cp : context
4874 // -- lr : return address
4875 // -----------------------------------
4876
4877 // Perform in-object slack tracking if requested.
4878 Label slack_tracking;
4879 STATIC_ASSERT(Map::kNoSlackTracking == 0);
4880 __ LoadRoot(x6, Heap::kUndefinedValueRootIndex);
4881 __ Ldr(w3, FieldMemOperand(x2, Map::kBitField3Offset));
4882 __ TestAndBranchIfAnySet(w3, Map::ConstructionCounter::kMask,
4883 &slack_tracking);
4884 {
4885 // Initialize all in-object fields with undefined.
4886 __ InitializeFieldsWithFiller(x1, x5, x6);
4887
4888 // Add the object tag to make the JSObject real.
4889 STATIC_ASSERT(kHeapObjectTag == 1);
4890 __ Add(x0, x0, kHeapObjectTag);
4891 __ Ret();
4892 }
4893 __ Bind(&slack_tracking);
4894 {
4895 // Decrease generous allocation count.
4896 STATIC_ASSERT(Map::ConstructionCounter::kNext == 32);
4897 __ Sub(w3, w3, 1 << Map::ConstructionCounter::kShift);
4898 __ Str(w3, FieldMemOperand(x2, Map::kBitField3Offset));
4899
4900 // Initialize the in-object fields with undefined.
4901 __ Ldrb(x4, FieldMemOperand(x2, Map::kUnusedPropertyFieldsOffset));
4902 __ Sub(x4, x5, Operand(x4, LSL, kPointerSizeLog2));
4903 __ InitializeFieldsWithFiller(x1, x4, x6);
4904
4905 // Initialize the remaining (reserved) fields with one pointer filler map.
4906 __ LoadRoot(x6, Heap::kOnePointerFillerMapRootIndex);
4907 __ InitializeFieldsWithFiller(x1, x5, x6);
4908
4909 // Add the object tag to make the JSObject real.
4910 STATIC_ASSERT(kHeapObjectTag == 1);
4911 __ Add(x0, x0, kHeapObjectTag);
4912
4913 // Check if we can finalize the instance size.
4914 Label finalize;
4915 STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1);
4916 __ TestAndBranchIfAllClear(w3, Map::ConstructionCounter::kMask, &finalize);
4917 __ Ret();
4918
4919 // Finalize the instance size.
4920 __ Bind(&finalize);
4921 {
4922 FrameScope scope(masm, StackFrame::INTERNAL);
4923 __ Push(x0, x2);
4924 __ CallRuntime(Runtime::kFinalizeInstanceSize);
4925 __ Pop(x0);
4926 }
4927 __ Ret();
4928 }
4929
4930 // Fall back to %AllocateInNewSpace.
4931 __ Bind(&allocate);
4932 {
4933 FrameScope scope(masm, StackFrame::INTERNAL);
4934 STATIC_ASSERT(kSmiTag == 0);
4935 STATIC_ASSERT(kSmiTagSize == 1);
4936 __ Mov(x4,
4937 Operand(x4, LSL, kPointerSizeLog2 + kSmiTagSize + kSmiShiftSize));
4938 __ Push(x2, x4);
4939 __ CallRuntime(Runtime::kAllocateInNewSpace);
4940 __ Pop(x2);
4941 }
4942 STATIC_ASSERT(kHeapObjectTag == 1);
4943 __ Sub(x0, x0, kHeapObjectTag);
4944 __ Ldrb(x5, FieldMemOperand(x2, Map::kInstanceSizeOffset));
4945 __ Add(x5, x0, Operand(x5, LSL, kPointerSizeLog2));
4946 __ B(&done_allocate);
4947
4948 // Fall back to %NewObject.
4949 __ Bind(&new_object);
4950 __ Push(x1, x3);
4951 __ TailCallRuntime(Runtime::kNewObject);
4952}
4953
4954
4955void FastNewRestParameterStub::Generate(MacroAssembler* masm) {
4956 // ----------- S t a t e -------------
4957 // -- x1 : function
4958 // -- cp : context
4959 // -- fp : frame pointer
4960 // -- lr : return address
4961 // -----------------------------------
4962 __ AssertFunction(x1);
4963
4964 // For Ignition we need to skip all possible handler/stub frames until
4965 // we reach the JavaScript frame for the function (similar to what the
4966 // runtime fallback implementation does). So make x2 point to that
4967 // JavaScript frame.
4968 {
4969 Label loop, loop_entry;
4970 __ Mov(x2, fp);
4971 __ B(&loop_entry);
4972 __ Bind(&loop);
4973 __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset));
4974 __ Bind(&loop_entry);
4975 __ Ldr(x3, MemOperand(x2, StandardFrameConstants::kMarkerOffset));
4976 __ Cmp(x3, x1);
4977 __ B(ne, &loop);
4978 }
4979
4980 // Check if we have rest parameters (only possible if we have an
4981 // arguments adaptor frame below the function frame).
4982 Label no_rest_parameters;
4983 __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset));
4984 __ Ldr(x3, MemOperand(x2, StandardFrameConstants::kContextOffset));
4985 __ Cmp(x3, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
4986 __ B(ne, &no_rest_parameters);
4987
4988 // Check if the arguments adaptor frame contains more arguments than
4989 // specified by the function's internal formal parameter count.
4990 Label rest_parameters;
4991 __ Ldrsw(x0, UntagSmiMemOperand(
4992 x2, ArgumentsAdaptorFrameConstants::kLengthOffset));
4993 __ Ldr(x1, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
4994 __ Ldrsw(
4995 x1, FieldMemOperand(x1, SharedFunctionInfo::kFormalParameterCountOffset));
4996 __ Subs(x0, x0, x1);
4997 __ B(gt, &rest_parameters);
4998
4999 // Return an empty rest parameter array.
5000 __ Bind(&no_rest_parameters);
5001 {
5002 // ----------- S t a t e -------------
5003 // -- cp : context
5004 // -- lr : return address
5005 // -----------------------------------
5006
5007 // Allocate an empty rest parameter array.
5008 Label allocate, done_allocate;
5009 __ Allocate(JSArray::kSize, x0, x1, x2, &allocate, TAG_OBJECT);
5010 __ Bind(&done_allocate);
5011
5012 // Setup the rest parameter array in x0.
5013 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, x1);
5014 __ Str(x1, FieldMemOperand(x0, JSArray::kMapOffset));
5015 __ LoadRoot(x1, Heap::kEmptyFixedArrayRootIndex);
5016 __ Str(x1, FieldMemOperand(x0, JSArray::kPropertiesOffset));
5017 __ Str(x1, FieldMemOperand(x0, JSArray::kElementsOffset));
5018 __ Mov(x1, Smi::FromInt(0));
5019 __ Str(x1, FieldMemOperand(x0, JSArray::kLengthOffset));
5020 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
5021 __ Ret();
5022
5023 // Fall back to %AllocateInNewSpace.
5024 __ Bind(&allocate);
5025 {
5026 FrameScope scope(masm, StackFrame::INTERNAL);
5027 __ Push(Smi::FromInt(JSArray::kSize));
5028 __ CallRuntime(Runtime::kAllocateInNewSpace);
5029 }
5030 __ B(&done_allocate);
5031 }
5032
5033 __ Bind(&rest_parameters);
5034 {
5035 // Compute the pointer to the first rest parameter (skippping the receiver).
5036 __ Add(x2, x2, Operand(x0, LSL, kPointerSizeLog2));
5037 __ Add(x2, x2, StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize);
5038
5039 // ----------- S t a t e -------------
5040 // -- cp : context
5041 // -- x0 : number of rest parameters
5042 // -- x2 : pointer to first rest parameters
5043 // -- lr : return address
5044 // -----------------------------------
5045
5046 // Allocate space for the rest parameter array plus the backing store.
5047 Label allocate, done_allocate;
5048 __ Mov(x1, JSArray::kSize + FixedArray::kHeaderSize);
5049 __ Add(x1, x1, Operand(x0, LSL, kPointerSizeLog2));
5050 __ Allocate(x1, x3, x4, x5, &allocate, TAG_OBJECT);
5051 __ Bind(&done_allocate);
5052
5053 // Compute arguments.length in x6.
5054 __ SmiTag(x6, x0);
5055
5056 // Setup the elements array in x3.
5057 __ LoadRoot(x1, Heap::kFixedArrayMapRootIndex);
5058 __ Str(x1, FieldMemOperand(x3, FixedArray::kMapOffset));
5059 __ Str(x6, FieldMemOperand(x3, FixedArray::kLengthOffset));
5060 __ Add(x4, x3, FixedArray::kHeaderSize);
5061 {
5062 Label loop, done_loop;
5063 __ Add(x0, x4, Operand(x0, LSL, kPointerSizeLog2));
5064 __ Bind(&loop);
5065 __ Cmp(x4, x0);
5066 __ B(eq, &done_loop);
5067 __ Ldr(x5, MemOperand(x2, 0 * kPointerSize));
5068 __ Str(x5, FieldMemOperand(x4, 0 * kPointerSize));
5069 __ Sub(x2, x2, Operand(1 * kPointerSize));
5070 __ Add(x4, x4, Operand(1 * kPointerSize));
5071 __ B(&loop);
5072 __ Bind(&done_loop);
5073 }
5074
5075 // Setup the rest parameter array in x0.
5076 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, x1);
5077 __ Str(x1, FieldMemOperand(x0, JSArray::kMapOffset));
5078 __ LoadRoot(x1, Heap::kEmptyFixedArrayRootIndex);
5079 __ Str(x1, FieldMemOperand(x0, JSArray::kPropertiesOffset));
5080 __ Str(x3, FieldMemOperand(x0, JSArray::kElementsOffset));
5081 __ Str(x6, FieldMemOperand(x0, JSArray::kLengthOffset));
5082 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
5083 __ Ret();
5084
5085 // Fall back to %AllocateInNewSpace.
5086 __ Bind(&allocate);
5087 {
5088 FrameScope scope(masm, StackFrame::INTERNAL);
5089 __ SmiTag(x0);
5090 __ SmiTag(x1);
5091 __ Push(x0, x2, x1);
5092 __ CallRuntime(Runtime::kAllocateInNewSpace);
5093 __ Mov(x3, x0);
5094 __ Pop(x2, x0);
5095 __ SmiUntag(x0);
5096 }
5097 __ B(&done_allocate);
5098 }
5099}
5100
5101
5102void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) {
5103 // ----------- S t a t e -------------
5104 // -- x1 : function
5105 // -- cp : context
5106 // -- fp : frame pointer
5107 // -- lr : return address
5108 // -----------------------------------
5109 __ AssertFunction(x1);
5110
5111 // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub.
5112 __ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
5113 __ Ldrsw(
5114 x2, FieldMemOperand(x2, SharedFunctionInfo::kFormalParameterCountOffset));
5115 __ Add(x3, fp, Operand(x2, LSL, kPointerSizeLog2));
5116 __ Add(x3, x3, Operand(StandardFrameConstants::kCallerSPOffset));
5117 __ SmiTag(x2);
5118
5119 // x1 : function
5120 // x2 : number of parameters (tagged)
5121 // x3 : parameters pointer
5122 //
5123 // Returns pointer to result object in x0.
5124
5125 // Make an untagged copy of the parameter count.
5126 // Note: arg_count_smi is an alias of param_count_smi.
5127 Register function = x1;
5128 Register arg_count_smi = x2;
5129 Register param_count_smi = x2;
5130 Register recv_arg = x3;
5131 Register param_count = x7;
5132 __ SmiUntag(param_count, param_count_smi);
5133
5134 // Check if the calling frame is an arguments adaptor frame.
5135 Register caller_fp = x11;
5136 Register caller_ctx = x12;
5137 Label runtime;
5138 Label adaptor_frame, try_allocate;
5139 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
5140 __ Ldr(caller_ctx, MemOperand(caller_fp,
5141 StandardFrameConstants::kContextOffset));
5142 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
5143 __ B(eq, &adaptor_frame);
5144
5145 // No adaptor, parameter count = argument count.
5146
5147 // x1 function function pointer
5148 // x2 arg_count_smi number of function arguments (smi)
5149 // x3 recv_arg pointer to receiver arguments
5150 // x4 mapped_params number of mapped params, min(params, args) (uninit)
5151 // x7 param_count number of function parameters
5152 // x11 caller_fp caller's frame pointer
5153 // x14 arg_count number of function arguments (uninit)
5154
5155 Register arg_count = x14;
5156 Register mapped_params = x4;
5157 __ Mov(arg_count, param_count);
5158 __ Mov(mapped_params, param_count);
5159 __ B(&try_allocate);
5160
5161 // We have an adaptor frame. Patch the parameters pointer.
5162 __ Bind(&adaptor_frame);
5163 __ Ldr(arg_count_smi,
5164 MemOperand(caller_fp,
5165 ArgumentsAdaptorFrameConstants::kLengthOffset));
5166 __ SmiUntag(arg_count, arg_count_smi);
5167 __ Add(x10, caller_fp, Operand(arg_count, LSL, kPointerSizeLog2));
5168 __ Add(recv_arg, x10, StandardFrameConstants::kCallerSPOffset);
5169
5170 // Compute the mapped parameter count = min(param_count, arg_count)
5171 __ Cmp(param_count, arg_count);
5172 __ Csel(mapped_params, param_count, arg_count, lt);
5173
5174 __ Bind(&try_allocate);
5175
5176 // x0 alloc_obj pointer to allocated objects: param map, backing
5177 // store, arguments (uninit)
5178 // x1 function function pointer
5179 // x2 arg_count_smi number of function arguments (smi)
5180 // x3 recv_arg pointer to receiver arguments
5181 // x4 mapped_params number of mapped parameters, min(params, args)
5182 // x7 param_count number of function parameters
5183 // x10 size size of objects to allocate (uninit)
5184 // x14 arg_count number of function arguments
5185
5186 // Compute the size of backing store, parameter map, and arguments object.
5187 // 1. Parameter map, has two extra words containing context and backing
5188 // store.
5189 const int kParameterMapHeaderSize =
5190 FixedArray::kHeaderSize + 2 * kPointerSize;
5191
5192 // Calculate the parameter map size, assuming it exists.
5193 Register size = x10;
5194 __ Mov(size, Operand(mapped_params, LSL, kPointerSizeLog2));
5195 __ Add(size, size, kParameterMapHeaderSize);
5196
5197 // If there are no mapped parameters, set the running size total to zero.
5198 // Otherwise, use the parameter map size calculated earlier.
5199 __ Cmp(mapped_params, 0);
5200 __ CzeroX(size, eq);
5201
5202 // 2. Add the size of the backing store and arguments object.
5203 __ Add(size, size, Operand(arg_count, LSL, kPointerSizeLog2));
5204 __ Add(size, size, FixedArray::kHeaderSize + JSSloppyArgumentsObject::kSize);
5205
5206 // Do the allocation of all three objects in one go. Assign this to x0, as it
5207 // will be returned to the caller.
5208 Register alloc_obj = x0;
5209 __ Allocate(size, alloc_obj, x11, x12, &runtime, TAG_OBJECT);
5210
5211 // Get the arguments boilerplate from the current (global) context.
5212
5213 // x0 alloc_obj pointer to allocated objects (param map, backing
5214 // store, arguments)
5215 // x1 function function pointer
5216 // x2 arg_count_smi number of function arguments (smi)
5217 // x3 recv_arg pointer to receiver arguments
5218 // x4 mapped_params number of mapped parameters, min(params, args)
5219 // x7 param_count number of function parameters
5220 // x11 sloppy_args_map offset to args (or aliased args) map (uninit)
5221 // x14 arg_count number of function arguments
5222
5223 Register global_ctx = x10;
5224 Register sloppy_args_map = x11;
5225 Register aliased_args_map = x10;
5226 __ Ldr(global_ctx, NativeContextMemOperand());
5227
5228 __ Ldr(sloppy_args_map,
5229 ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
5230 __ Ldr(
5231 aliased_args_map,
5232 ContextMemOperand(global_ctx, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX));
5233 __ Cmp(mapped_params, 0);
5234 __ CmovX(sloppy_args_map, aliased_args_map, ne);
5235
5236 // Copy the JS object part.
5237 __ Str(sloppy_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
5238 __ LoadRoot(x10, Heap::kEmptyFixedArrayRootIndex);
5239 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
5240 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
5241
5242 // Set up the callee in-object property.
5243 __ AssertNotSmi(function);
5244 __ Str(function,
5245 FieldMemOperand(alloc_obj, JSSloppyArgumentsObject::kCalleeOffset));
5246
5247 // Use the length and set that as an in-object property.
5248 __ Str(arg_count_smi,
5249 FieldMemOperand(alloc_obj, JSSloppyArgumentsObject::kLengthOffset));
5250
5251 // Set up the elements pointer in the allocated arguments object.
5252 // If we allocated a parameter map, "elements" will point there, otherwise
5253 // it will point to the backing store.
5254
5255 // x0 alloc_obj pointer to allocated objects (param map, backing
5256 // store, arguments)
5257 // x1 function function pointer
5258 // x2 arg_count_smi number of function arguments (smi)
5259 // x3 recv_arg pointer to receiver arguments
5260 // x4 mapped_params number of mapped parameters, min(params, args)
5261 // x5 elements pointer to parameter map or backing store (uninit)
5262 // x6 backing_store pointer to backing store (uninit)
5263 // x7 param_count number of function parameters
5264 // x14 arg_count number of function arguments
5265
5266 Register elements = x5;
5267 __ Add(elements, alloc_obj, JSSloppyArgumentsObject::kSize);
5268 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
5269
5270 // Initialize parameter map. If there are no mapped arguments, we're done.
5271 Label skip_parameter_map;
5272 __ Cmp(mapped_params, 0);
5273 // Set up backing store address, because it is needed later for filling in
5274 // the unmapped arguments.
5275 Register backing_store = x6;
5276 __ CmovX(backing_store, elements, eq);
5277 __ B(eq, &skip_parameter_map);
5278
5279 __ LoadRoot(x10, Heap::kSloppyArgumentsElementsMapRootIndex);
5280 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
5281 __ Add(x10, mapped_params, 2);
5282 __ SmiTag(x10);
5283 __ Str(x10, FieldMemOperand(elements, FixedArray::kLengthOffset));
5284 __ Str(cp, FieldMemOperand(elements,
5285 FixedArray::kHeaderSize + 0 * kPointerSize));
5286 __ Add(x10, elements, Operand(mapped_params, LSL, kPointerSizeLog2));
5287 __ Add(x10, x10, kParameterMapHeaderSize);
5288 __ Str(x10, FieldMemOperand(elements,
5289 FixedArray::kHeaderSize + 1 * kPointerSize));
5290
5291 // Copy the parameter slots and the holes in the arguments.
5292 // We need to fill in mapped_parameter_count slots. Then index the context,
5293 // where parameters are stored in reverse order, at:
5294 //
5295 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS + parameter_count - 1
5296 //
5297 // The mapped parameter thus needs to get indices:
5298 //
5299 // MIN_CONTEXT_SLOTS + parameter_count - 1 ..
5300 // MIN_CONTEXT_SLOTS + parameter_count - mapped_parameter_count
5301 //
5302 // We loop from right to left.
5303
5304 // x0 alloc_obj pointer to allocated objects (param map, backing
5305 // store, arguments)
5306 // x1 function function pointer
5307 // x2 arg_count_smi number of function arguments (smi)
5308 // x3 recv_arg pointer to receiver arguments
5309 // x4 mapped_params number of mapped parameters, min(params, args)
5310 // x5 elements pointer to parameter map or backing store (uninit)
5311 // x6 backing_store pointer to backing store (uninit)
5312 // x7 param_count number of function parameters
5313 // x11 loop_count parameter loop counter (uninit)
5314 // x12 index parameter index (smi, uninit)
5315 // x13 the_hole hole value (uninit)
5316 // x14 arg_count number of function arguments
5317
5318 Register loop_count = x11;
5319 Register index = x12;
5320 Register the_hole = x13;
5321 Label parameters_loop, parameters_test;
5322 __ Mov(loop_count, mapped_params);
5323 __ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS));
5324 __ Sub(index, index, mapped_params);
5325 __ SmiTag(index);
5326 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
5327 __ Add(backing_store, elements, Operand(loop_count, LSL, kPointerSizeLog2));
5328 __ Add(backing_store, backing_store, kParameterMapHeaderSize);
5329
5330 __ B(&parameters_test);
5331
5332 __ Bind(&parameters_loop);
5333 __ Sub(loop_count, loop_count, 1);
5334 __ Mov(x10, Operand(loop_count, LSL, kPointerSizeLog2));
5335 __ Add(x10, x10, kParameterMapHeaderSize - kHeapObjectTag);
5336 __ Str(index, MemOperand(elements, x10));
5337 __ Sub(x10, x10, kParameterMapHeaderSize - FixedArray::kHeaderSize);
5338 __ Str(the_hole, MemOperand(backing_store, x10));
5339 __ Add(index, index, Smi::FromInt(1));
5340 __ Bind(&parameters_test);
5341 __ Cbnz(loop_count, &parameters_loop);
5342
5343 __ Bind(&skip_parameter_map);
5344 // Copy arguments header and remaining slots (if there are any.)
5345 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
5346 __ Str(x10, FieldMemOperand(backing_store, FixedArray::kMapOffset));
5347 __ Str(arg_count_smi, FieldMemOperand(backing_store,
5348 FixedArray::kLengthOffset));
5349
5350 // x0 alloc_obj pointer to allocated objects (param map, backing
5351 // store, arguments)
5352 // x1 function function pointer
5353 // x2 arg_count_smi number of function arguments (smi)
5354 // x3 recv_arg pointer to receiver arguments
5355 // x4 mapped_params number of mapped parameters, min(params, args)
5356 // x6 backing_store pointer to backing store (uninit)
5357 // x14 arg_count number of function arguments
5358
5359 Label arguments_loop, arguments_test;
5360 __ Mov(x10, mapped_params);
5361 __ Sub(recv_arg, recv_arg, Operand(x10, LSL, kPointerSizeLog2));
5362 __ B(&arguments_test);
5363
5364 __ Bind(&arguments_loop);
5365 __ Sub(recv_arg, recv_arg, kPointerSize);
5366 __ Ldr(x11, MemOperand(recv_arg));
5367 __ Add(x12, backing_store, Operand(x10, LSL, kPointerSizeLog2));
5368 __ Str(x11, FieldMemOperand(x12, FixedArray::kHeaderSize));
5369 __ Add(x10, x10, 1);
5370
5371 __ Bind(&arguments_test);
5372 __ Cmp(x10, arg_count);
5373 __ B(lt, &arguments_loop);
5374
5375 __ Ret();
5376
5377 // Do the runtime call to allocate the arguments object.
5378 __ Bind(&runtime);
5379 __ Push(function, recv_arg, arg_count_smi);
5380 __ TailCallRuntime(Runtime::kNewSloppyArguments);
5381}
5382
5383
5384void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) {
5385 // ----------- S t a t e -------------
5386 // -- x1 : function
5387 // -- cp : context
5388 // -- fp : frame pointer
5389 // -- lr : return address
5390 // -----------------------------------
5391 __ AssertFunction(x1);
5392
5393 // For Ignition we need to skip all possible handler/stub frames until
5394 // we reach the JavaScript frame for the function (similar to what the
5395 // runtime fallback implementation does). So make x2 point to that
5396 // JavaScript frame.
5397 {
5398 Label loop, loop_entry;
5399 __ Mov(x2, fp);
5400 __ B(&loop_entry);
5401 __ Bind(&loop);
5402 __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset));
5403 __ Bind(&loop_entry);
5404 __ Ldr(x3, MemOperand(x2, StandardFrameConstants::kMarkerOffset));
5405 __ Cmp(x3, x1);
5406 __ B(ne, &loop);
5407 }
5408
5409 // Check if we have an arguments adaptor frame below the function frame.
5410 Label arguments_adaptor, arguments_done;
5411 __ Ldr(x3, MemOperand(x2, StandardFrameConstants::kCallerFPOffset));
5412 __ Ldr(x4, MemOperand(x3, StandardFrameConstants::kContextOffset));
5413 __ Cmp(x4, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
5414 __ B(eq, &arguments_adaptor);
5415 {
5416 __ Ldr(x1, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
5417 __ Ldrsw(x0, FieldMemOperand(
5418 x1, SharedFunctionInfo::kFormalParameterCountOffset));
5419 __ Add(x2, x2, Operand(x0, LSL, kPointerSizeLog2));
5420 __ Add(x2, x2, StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize);
5421 }
5422 __ B(&arguments_done);
5423 __ Bind(&arguments_adaptor);
5424 {
5425 __ Ldrsw(x0, UntagSmiMemOperand(
5426 x3, ArgumentsAdaptorFrameConstants::kLengthOffset));
5427 __ Add(x2, x3, Operand(x0, LSL, kPointerSizeLog2));
5428 __ Add(x2, x2, StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize);
5429 }
5430 __ Bind(&arguments_done);
5431
5432 // ----------- S t a t e -------------
5433 // -- cp : context
5434 // -- x0 : number of rest parameters
5435 // -- x2 : pointer to first rest parameters
5436 // -- lr : return address
5437 // -----------------------------------
5438
5439 // Allocate space for the strict arguments object plus the backing store.
5440 Label allocate, done_allocate;
5441 __ Mov(x1, JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize);
5442 __ Add(x1, x1, Operand(x0, LSL, kPointerSizeLog2));
5443 __ Allocate(x1, x3, x4, x5, &allocate, TAG_OBJECT);
5444 __ Bind(&done_allocate);
5445
5446 // Compute arguments.length in x6.
5447 __ SmiTag(x6, x0);
5448
5449 // Setup the elements array in x3.
5450 __ LoadRoot(x1, Heap::kFixedArrayMapRootIndex);
5451 __ Str(x1, FieldMemOperand(x3, FixedArray::kMapOffset));
5452 __ Str(x6, FieldMemOperand(x3, FixedArray::kLengthOffset));
5453 __ Add(x4, x3, FixedArray::kHeaderSize);
5454 {
5455 Label loop, done_loop;
5456 __ Add(x0, x4, Operand(x0, LSL, kPointerSizeLog2));
5457 __ Bind(&loop);
5458 __ Cmp(x4, x0);
5459 __ B(eq, &done_loop);
5460 __ Ldr(x5, MemOperand(x2, 0 * kPointerSize));
5461 __ Str(x5, FieldMemOperand(x4, 0 * kPointerSize));
5462 __ Sub(x2, x2, Operand(1 * kPointerSize));
5463 __ Add(x4, x4, Operand(1 * kPointerSize));
5464 __ B(&loop);
5465 __ Bind(&done_loop);
5466 }
5467
5468 // Setup the strict arguments object in x0.
5469 __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, x1);
5470 __ Str(x1, FieldMemOperand(x0, JSStrictArgumentsObject::kMapOffset));
5471 __ LoadRoot(x1, Heap::kEmptyFixedArrayRootIndex);
5472 __ Str(x1, FieldMemOperand(x0, JSStrictArgumentsObject::kPropertiesOffset));
5473 __ Str(x3, FieldMemOperand(x0, JSStrictArgumentsObject::kElementsOffset));
5474 __ Str(x6, FieldMemOperand(x0, JSStrictArgumentsObject::kLengthOffset));
5475 STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize);
5476 __ Ret();
5477
5478 // Fall back to %AllocateInNewSpace.
5479 __ Bind(&allocate);
5480 {
5481 FrameScope scope(masm, StackFrame::INTERNAL);
5482 __ SmiTag(x0);
5483 __ SmiTag(x1);
5484 __ Push(x0, x2, x1);
5485 __ CallRuntime(Runtime::kAllocateInNewSpace);
5486 __ Mov(x3, x0);
5487 __ Pop(x2, x0);
5488 __ SmiUntag(x0);
5489 }
5490 __ B(&done_allocate);
5491}
5492
5493
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005494void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5495 Register context = cp;
5496 Register result = x0;
5497 Register slot = x2;
5498 Label slow_case;
5499
5500 // Go up the context chain to the script context.
5501 for (int i = 0; i < depth(); ++i) {
5502 __ Ldr(result, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5503 context = result;
5504 }
5505
5506 // Load the PropertyCell value at the specified slot.
5507 __ Add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5508 __ Ldr(result, ContextMemOperand(result));
5509 __ Ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5510
5511 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5512 __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &slow_case);
5513 __ Ret();
5514
5515 // Fallback to runtime.
5516 __ Bind(&slow_case);
5517 __ SmiTag(slot);
5518 __ Push(slot);
5519 __ TailCallRuntime(Runtime::kLoadGlobalViaContext);
5520}
5521
5522
5523void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5524 Register context = cp;
5525 Register value = x0;
5526 Register slot = x2;
5527 Register context_temp = x10;
5528 Register cell = x10;
5529 Register cell_details = x11;
5530 Register cell_value = x12;
5531 Register cell_value_map = x13;
5532 Register value_map = x14;
5533 Label fast_heapobject_case, fast_smi_case, slow_case;
5534
5535 if (FLAG_debug_code) {
5536 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5537 __ Check(ne, kUnexpectedValue);
5538 }
5539
5540 // Go up the context chain to the script context.
5541 for (int i = 0; i < depth(); i++) {
5542 __ Ldr(context_temp, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5543 context = context_temp;
5544 }
5545
5546 // Load the PropertyCell at the specified slot.
5547 __ Add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5548 __ Ldr(cell, ContextMemOperand(cell));
5549
5550 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5551 __ Ldr(cell_details,
5552 UntagSmiFieldMemOperand(cell, PropertyCell::kDetailsOffset));
5553 __ And(cell_details, cell_details,
5554 PropertyDetails::PropertyCellTypeField::kMask |
5555 PropertyDetails::KindField::kMask |
5556 PropertyDetails::kAttributesReadOnlyMask);
5557
5558 // Check if PropertyCell holds mutable data.
5559 Label not_mutable_data;
5560 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5561 PropertyCellType::kMutable) |
5562 PropertyDetails::KindField::encode(kData));
5563 __ B(ne, &not_mutable_data);
5564 __ JumpIfSmi(value, &fast_smi_case);
5565 __ Bind(&fast_heapobject_case);
5566 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5567 // RecordWriteField clobbers the value register, so we copy it before the
5568 // call.
5569 __ Mov(x11, value);
5570 __ RecordWriteField(cell, PropertyCell::kValueOffset, x11, x12,
5571 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5572 OMIT_SMI_CHECK);
5573 __ Ret();
5574
5575 __ Bind(&not_mutable_data);
5576 // Check if PropertyCell value matches the new value (relevant for Constant,
5577 // ConstantType and Undefined cells).
5578 Label not_same_value;
5579 __ Ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5580 __ Cmp(cell_value, value);
5581 __ B(ne, &not_same_value);
5582
5583 // Make sure the PropertyCell is not marked READ_ONLY.
5584 __ Tst(cell_details, PropertyDetails::kAttributesReadOnlyMask);
5585 __ B(ne, &slow_case);
5586
5587 if (FLAG_debug_code) {
5588 Label done;
5589 // This can only be true for Constant, ConstantType and Undefined cells,
5590 // because we never store the_hole via this stub.
5591 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5592 PropertyCellType::kConstant) |
5593 PropertyDetails::KindField::encode(kData));
5594 __ B(eq, &done);
5595 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5596 PropertyCellType::kConstantType) |
5597 PropertyDetails::KindField::encode(kData));
5598 __ B(eq, &done);
5599 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5600 PropertyCellType::kUndefined) |
5601 PropertyDetails::KindField::encode(kData));
5602 __ Check(eq, kUnexpectedValue);
5603 __ Bind(&done);
5604 }
5605 __ Ret();
5606 __ Bind(&not_same_value);
5607
5608 // Check if PropertyCell contains data with constant type (and is not
5609 // READ_ONLY).
5610 __ Cmp(cell_details, PropertyDetails::PropertyCellTypeField::encode(
5611 PropertyCellType::kConstantType) |
5612 PropertyDetails::KindField::encode(kData));
5613 __ B(ne, &slow_case);
5614
5615 // Now either both old and new values must be smis or both must be heap
5616 // objects with same map.
5617 Label value_is_heap_object;
5618 __ JumpIfNotSmi(value, &value_is_heap_object);
5619 __ JumpIfNotSmi(cell_value, &slow_case);
5620 // Old and new values are smis, no need for a write barrier here.
5621 __ Bind(&fast_smi_case);
5622 __ Str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5623 __ Ret();
5624
5625 __ Bind(&value_is_heap_object);
5626 __ JumpIfSmi(cell_value, &slow_case);
5627
5628 __ Ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5629 __ Ldr(value_map, FieldMemOperand(value, HeapObject::kMapOffset));
5630 __ Cmp(cell_value_map, value_map);
5631 __ B(eq, &fast_heapobject_case);
5632
5633 // Fall back to the runtime.
5634 __ Bind(&slow_case);
5635 __ SmiTag(slot);
5636 __ Push(slot, value);
5637 __ TailCallRuntime(is_strict(language_mode())
5638 ? Runtime::kStoreGlobalViaContext_Strict
5639 : Runtime::kStoreGlobalViaContext_Sloppy);
5640}
5641
5642
5643// The number of register that CallApiFunctionAndReturn will need to save on
5644// the stack. The space for these registers need to be allocated in the
5645// ExitFrame before calling CallApiFunctionAndReturn.
5646static const int kCallApiFunctionSpillSpace = 4;
5647
5648
5649static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5650 return static_cast<int>(ref0.address() - ref1.address());
5651}
5652
5653
5654// Calls an API function. Allocates HandleScope, extracts returned value
5655// from handle and propagates exceptions.
5656// 'stack_space' is the space to be unwound on exit (includes the call JS
5657// arguments space and the additional space allocated for the fast call).
5658// 'spill_offset' is the offset from the stack pointer where
5659// CallApiFunctionAndReturn can spill registers.
5660static void CallApiFunctionAndReturn(
5661 MacroAssembler* masm, Register function_address,
5662 ExternalReference thunk_ref, int stack_space,
5663 MemOperand* stack_space_operand, int spill_offset,
5664 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5665 ASM_LOCATION("CallApiFunctionAndReturn");
5666 Isolate* isolate = masm->isolate();
5667 ExternalReference next_address =
5668 ExternalReference::handle_scope_next_address(isolate);
5669 const int kNextOffset = 0;
5670 const int kLimitOffset = AddressOffset(
5671 ExternalReference::handle_scope_limit_address(isolate), next_address);
5672 const int kLevelOffset = AddressOffset(
5673 ExternalReference::handle_scope_level_address(isolate), next_address);
5674
5675 DCHECK(function_address.is(x1) || function_address.is(x2));
5676
5677 Label profiler_disabled;
5678 Label end_profiler_check;
5679 __ Mov(x10, ExternalReference::is_profiling_address(isolate));
5680 __ Ldrb(w10, MemOperand(x10));
5681 __ Cbz(w10, &profiler_disabled);
5682 __ Mov(x3, thunk_ref);
5683 __ B(&end_profiler_check);
5684
5685 __ Bind(&profiler_disabled);
5686 __ Mov(x3, function_address);
5687 __ Bind(&end_profiler_check);
5688
5689 // Save the callee-save registers we are going to use.
5690 // TODO(all): Is this necessary? ARM doesn't do it.
5691 STATIC_ASSERT(kCallApiFunctionSpillSpace == 4);
5692 __ Poke(x19, (spill_offset + 0) * kXRegSize);
5693 __ Poke(x20, (spill_offset + 1) * kXRegSize);
5694 __ Poke(x21, (spill_offset + 2) * kXRegSize);
5695 __ Poke(x22, (spill_offset + 3) * kXRegSize);
5696
5697 // Allocate HandleScope in callee-save registers.
5698 // We will need to restore the HandleScope after the call to the API function,
5699 // by allocating it in callee-save registers they will be preserved by C code.
5700 Register handle_scope_base = x22;
5701 Register next_address_reg = x19;
5702 Register limit_reg = x20;
5703 Register level_reg = w21;
5704
5705 __ Mov(handle_scope_base, next_address);
5706 __ Ldr(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5707 __ Ldr(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5708 __ Ldr(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5709 __ Add(level_reg, level_reg, 1);
5710 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5711
5712 if (FLAG_log_timer_events) {
5713 FrameScope frame(masm, StackFrame::MANUAL);
5714 __ PushSafepointRegisters();
5715 __ Mov(x0, ExternalReference::isolate_address(isolate));
5716 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5717 1);
5718 __ PopSafepointRegisters();
5719 }
5720
5721 // Native call returns to the DirectCEntry stub which redirects to the
5722 // return address pushed on stack (could have moved after GC).
5723 // DirectCEntry stub itself is generated early and never moves.
5724 DirectCEntryStub stub(isolate);
5725 stub.GenerateCall(masm, x3);
5726
5727 if (FLAG_log_timer_events) {
5728 FrameScope frame(masm, StackFrame::MANUAL);
5729 __ PushSafepointRegisters();
5730 __ Mov(x0, ExternalReference::isolate_address(isolate));
5731 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5732 1);
5733 __ PopSafepointRegisters();
5734 }
5735
5736 Label promote_scheduled_exception;
5737 Label delete_allocated_handles;
5738 Label leave_exit_frame;
5739 Label return_value_loaded;
5740
5741 // Load value from ReturnValue.
5742 __ Ldr(x0, return_value_operand);
5743 __ Bind(&return_value_loaded);
5744 // No more valid handles (the result handle was the last one). Restore
5745 // previous handle scope.
5746 __ Str(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5747 if (__ emit_debug_code()) {
5748 __ Ldr(w1, MemOperand(handle_scope_base, kLevelOffset));
5749 __ Cmp(w1, level_reg);
5750 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5751 }
5752 __ Sub(level_reg, level_reg, 1);
5753 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5754 __ Ldr(x1, MemOperand(handle_scope_base, kLimitOffset));
5755 __ Cmp(limit_reg, x1);
5756 __ B(ne, &delete_allocated_handles);
5757
5758 // Leave the API exit frame.
5759 __ Bind(&leave_exit_frame);
5760 // Restore callee-saved registers.
5761 __ Peek(x19, (spill_offset + 0) * kXRegSize);
5762 __ Peek(x20, (spill_offset + 1) * kXRegSize);
5763 __ Peek(x21, (spill_offset + 2) * kXRegSize);
5764 __ Peek(x22, (spill_offset + 3) * kXRegSize);
5765
5766 bool restore_context = context_restore_operand != NULL;
5767 if (restore_context) {
5768 __ Ldr(cp, *context_restore_operand);
5769 }
5770
5771 if (stack_space_operand != NULL) {
5772 __ Ldr(w2, *stack_space_operand);
5773 }
5774
5775 __ LeaveExitFrame(false, x1, !restore_context);
5776
5777 // Check if the function scheduled an exception.
5778 __ Mov(x5, ExternalReference::scheduled_exception_address(isolate));
5779 __ Ldr(x5, MemOperand(x5));
5780 __ JumpIfNotRoot(x5, Heap::kTheHoleValueRootIndex,
5781 &promote_scheduled_exception);
5782
5783 if (stack_space_operand != NULL) {
5784 __ Drop(x2, 1);
5785 } else {
5786 __ Drop(stack_space);
5787 }
5788 __ Ret();
5789
5790 // Re-throw by promoting a scheduled exception.
5791 __ Bind(&promote_scheduled_exception);
5792 __ TailCallRuntime(Runtime::kPromoteScheduledException);
5793
5794 // HandleScope limit has changed. Delete allocated extensions.
5795 __ Bind(&delete_allocated_handles);
5796 __ Str(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5797 // Save the return value in a callee-save register.
5798 Register saved_result = x19;
5799 __ Mov(saved_result, x0);
5800 __ Mov(x0, ExternalReference::isolate_address(isolate));
5801 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5802 1);
5803 __ Mov(x0, saved_result);
5804 __ B(&leave_exit_frame);
5805}
5806
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005807static void CallApiFunctionStubHelper(MacroAssembler* masm,
5808 const ParameterCount& argc,
5809 bool return_first_arg,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005810 bool call_data_undefined, bool is_lazy) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005811 // ----------- S t a t e -------------
5812 // -- x0 : callee
5813 // -- x4 : call_data
5814 // -- x2 : holder
5815 // -- x1 : api_function_address
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005816 // -- x3 : number of arguments if argc is a register
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005817 // -- cp : context
5818 // --
5819 // -- sp[0] : last argument
5820 // -- ...
5821 // -- sp[(argc - 1) * 8] : first argument
5822 // -- sp[argc * 8] : receiver
5823 // -----------------------------------
5824
5825 Register callee = x0;
5826 Register call_data = x4;
5827 Register holder = x2;
5828 Register api_function_address = x1;
5829 Register context = cp;
5830
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005831 typedef FunctionCallbackArguments FCA;
5832
5833 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5834 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5835 STATIC_ASSERT(FCA::kDataIndex == 4);
5836 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5837 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5838 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5839 STATIC_ASSERT(FCA::kHolderIndex == 0);
5840 STATIC_ASSERT(FCA::kArgsLength == 7);
5841
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005842 DCHECK(argc.is_immediate() || x3.is(argc.reg()));
5843
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005844 // FunctionCallbackArguments: context, callee and call data.
5845 __ Push(context, callee, call_data);
5846
Ben Murdoch097c5b22016-05-18 11:27:45 +01005847 if (!is_lazy) {
5848 // Load context from callee
5849 __ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5850 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005851
5852 if (!call_data_undefined) {
5853 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
5854 }
5855 Register isolate_reg = x5;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005856 __ Mov(isolate_reg, ExternalReference::isolate_address(masm->isolate()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005857
5858 // FunctionCallbackArguments:
5859 // return value, return value default, isolate, holder.
5860 __ Push(call_data, call_data, isolate_reg, holder);
5861
5862 // Prepare arguments.
5863 Register args = x6;
5864 __ Mov(args, masm->StackPointer());
5865
5866 // Allocate the v8::Arguments structure in the arguments' space, since it's
5867 // not controlled by GC.
5868 const int kApiStackSpace = 4;
5869
5870 // Allocate space for CallApiFunctionAndReturn can store some scratch
5871 // registeres on the stack.
5872 const int kCallApiFunctionSpillSpace = 4;
5873
5874 FrameScope frame_scope(masm, StackFrame::MANUAL);
5875 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5876
5877 DCHECK(!AreAliased(x0, api_function_address));
5878 // x0 = FunctionCallbackInfo&
5879 // Arguments is after the return address.
5880 __ Add(x0, masm->StackPointer(), 1 * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005881 if (argc.is_immediate()) {
5882 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5883 __ Add(x10, args,
5884 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5885 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5886 // FunctionCallbackInfo::length_ = argc and
5887 // FunctionCallbackInfo::is_construct_call = 0
5888 __ Mov(x10, argc.immediate());
5889 __ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize));
5890 } else {
5891 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5892 __ Add(x10, args, Operand(argc.reg(), LSL, kPointerSizeLog2));
5893 __ Add(x10, x10, (FCA::kArgsLength - 1) * kPointerSize);
5894 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5895 // FunctionCallbackInfo::length_ = argc and
5896 // FunctionCallbackInfo::is_construct_call
5897 __ Add(x10, argc.reg(), FCA::kArgsLength + 1);
5898 __ Mov(x10, Operand(x10, LSL, kPointerSizeLog2));
5899 __ Stp(argc.reg(), x10, MemOperand(x0, 2 * kPointerSize));
5900 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005901
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005902 ExternalReference thunk_ref =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005903 ExternalReference::invoke_function_callback(masm->isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005904
5905 AllowExternalCallThatCantCauseGC scope(masm);
5906 MemOperand context_restore_operand(
5907 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5908 // Stores return the first js argument
5909 int return_value_offset = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005910 if (return_first_arg) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005911 return_value_offset = 2 + FCA::kArgsLength;
5912 } else {
5913 return_value_offset = 2 + FCA::kReturnValueOffset;
5914 }
5915 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005916 int stack_space = 0;
5917 MemOperand is_construct_call_operand =
5918 MemOperand(masm->StackPointer(), 4 * kPointerSize);
5919 MemOperand* stack_space_operand = &is_construct_call_operand;
5920 if (argc.is_immediate()) {
5921 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5922 stack_space_operand = NULL;
5923 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005924
5925 const int spill_offset = 1 + kApiStackSpace;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005926 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5927 stack_space_operand, spill_offset,
5928 return_value_operand, &context_restore_operand);
5929}
5930
5931
5932void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5933 bool call_data_undefined = this->call_data_undefined();
5934 CallApiFunctionStubHelper(masm, ParameterCount(x3), false,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005935 call_data_undefined, false);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005936}
5937
5938
5939void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5940 bool is_store = this->is_store();
5941 int argc = this->argc();
5942 bool call_data_undefined = this->call_data_undefined();
Ben Murdoch097c5b22016-05-18 11:27:45 +01005943 bool is_lazy = this->is_lazy();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005944 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005945 call_data_undefined, is_lazy);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005946}
5947
5948
5949void CallApiGetterStub::Generate(MacroAssembler* masm) {
5950 // ----------- S t a t e -------------
Ben Murdoch097c5b22016-05-18 11:27:45 +01005951 // -- sp[0] : name
5952 // -- sp[8 .. (8 + kArgsLength*8)] : v8::PropertyCallbackInfo::args_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005953 // -- ...
Ben Murdoch097c5b22016-05-18 11:27:45 +01005954 // -- x2 : api_function_address
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005955 // -----------------------------------
5956
5957 Register api_function_address = ApiGetterDescriptor::function_address();
5958 DCHECK(api_function_address.is(x2));
5959
Ben Murdoch097c5b22016-05-18 11:27:45 +01005960 // v8::PropertyCallbackInfo::args_ array and name handle.
5961 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5962
5963 // Load address of v8::PropertyAccessorInfo::args_ array and name handle.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005964 __ Mov(x0, masm->StackPointer()); // x0 = Handle<Name>
Ben Murdoch097c5b22016-05-18 11:27:45 +01005965 __ Add(x1, x0, 1 * kPointerSize); // x1 = v8::PCI::args_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005966
5967 const int kApiStackSpace = 1;
5968
5969 // Allocate space for CallApiFunctionAndReturn can store some scratch
5970 // registeres on the stack.
5971 const int kCallApiFunctionSpillSpace = 4;
5972
5973 FrameScope frame_scope(masm, StackFrame::MANUAL);
5974 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5975
Ben Murdoch097c5b22016-05-18 11:27:45 +01005976 // Create v8::PropertyCallbackInfo object on the stack and initialize
5977 // it's args_ field.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005978 __ Poke(x1, 1 * kPointerSize);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005979 __ Add(x1, masm->StackPointer(), 1 * kPointerSize);
5980 // x1 = v8::PropertyCallbackInfo&
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005981
5982 ExternalReference thunk_ref =
5983 ExternalReference::invoke_accessor_getter_callback(isolate());
5984
5985 const int spill_offset = 1 + kApiStackSpace;
Ben Murdoch097c5b22016-05-18 11:27:45 +01005986 // +3 is to skip prolog, return address and name handle.
5987 MemOperand return_value_operand(
5988 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005989 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5990 kStackUnwindSpace, NULL, spill_offset,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005991 return_value_operand, NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005992}
5993
5994
5995#undef __
5996
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005997} // namespace internal
5998} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005999
6000#endif // V8_TARGET_ARCH_ARM64